From 920eda26fc2e813448347a69b7b7ad238cacc7fb Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 29 Jan 2021 00:14:38 -0800 Subject: [PATCH] lntest/graph_top: test pinned syncers --- lntest/itest/lnd_test.go | 67 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 6ef685f93..f476e2bdd 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -10330,21 +10330,71 @@ func subscribeGraphNotifications(t *harnessTest, ctxb context.Context, } } +func assertSyncType(t *harnessTest, node *lntest.HarnessNode, + peer string, syncType lnrpc.Peer_SyncType) { + + t.t.Helper() + + ctxb := context.Background() + ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) + resp, err := node.ListPeers(ctxt, &lnrpc.ListPeersRequest{}) + require.NoError(t.t, err) + + for _, rpcPeer := range resp.Peers { + if rpcPeer.PubKey != peer { + continue + } + + require.Equal(t.t, syncType, rpcPeer.SyncType) + return + } + + t.t.Fatalf("unable to find peer: %s", peer) +} + func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) { + t.t.Run("pinned", func(t *testing.T) { + ht := newHarnessTest(t, net) + testGraphTopologyNtfns(net, ht, true) + }) + t.t.Run("unpinned", func(t *testing.T) { + ht := newHarnessTest(t, net) + testGraphTopologyNtfns(net, ht, false) + }) +} + +func testGraphTopologyNtfns(net *lntest.NetworkHarness, t *harnessTest, pinned bool) { ctxb := context.Background() const chanAmt = funding.MaxBtcFundingAmount - alice, err := net.NewNode("alice", nil) - require.NoError(t.t, err) - defer shutdownAndAssert(net, t, alice) - + // Spin up Bob first, since we will need to grab his pubkey when + // starting Alice to test pinned syncing. bob, err := net.NewNode("bob", nil) require.NoError(t.t, err) defer shutdownAndAssert(net, t, bob) - // Connect Alice and Bob. ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) + bobInfo, err := bob.GetInfo(ctxt, &lnrpc.GetInfoRequest{}) + require.NoError(t.t, err) + bobPubkey := bobInfo.IdentityPubkey + + // For unpinned syncing, start Alice as usual. Otherwise grab Bob's + // pubkey to include in his pinned syncer set. + var aliceArgs []string + if pinned { + aliceArgs = []string{ + "--numgraphsyncpeers=1", + fmt.Sprintf("--gossip.pinned-syncers=%s", bobPubkey), + } + } + + alice, err := net.NewNode("alice", aliceArgs) + require.NoError(t.t, err) + defer shutdownAndAssert(net, t, alice) + + // Connect Alice and Bob. + ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) err = net.EnsureConnected(ctxt, alice, bob) require.NoError(t.t, err) @@ -10358,6 +10408,13 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) err = net.SendCoins(ctxt, btcutil.SatoshiPerBitcoin, bob) require.NoError(t.t, err) + // Assert that Bob has the correct sync type before proceeeding. + if pinned { + assertSyncType(t, alice, bobPubkey, lnrpc.Peer_PINNED_SYNC) + } else { + assertSyncType(t, alice, bobPubkey, lnrpc.Peer_ACTIVE_SYNC) + } + // Let Alice subscribe to graph notifications. graphSub := subscribeGraphNotifications( t, ctxb, alice,