From ed39ccb7b44f22f86bb893fccc3554f646b5b0e1 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 18 Nov 2024 14:01:04 +0200 Subject: [PATCH] itest: bootstrap --- itest/lnd_remote_graph_test.go | 50 ++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/itest/lnd_remote_graph_test.go b/itest/lnd_remote_graph_test.go index cd2a1d00bb6..8fa204b7f45 100644 --- a/itest/lnd_remote_graph_test.go +++ b/itest/lnd_remote_graph_test.go @@ -1,23 +1,28 @@ package itest import ( + "context" "fmt" + "time" "github.com/btcsuite/btcd/btcutil" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/node" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) func testRemoteGraph(ht *lntest.HarnessTest) { var ( + ctx = context.Background() alice = ht.Alice bob = ht.Bob descGraphReq = &lnrpc.ChannelGraphRequest{ IncludeUnannounced: true, } ) + // Set up a network: // A <- B <- C carol := ht.NewNode("Carol", nil) @@ -91,9 +96,6 @@ func testRemoteGraph(ht *lntest.HarnessTest) { Amt: btcutil.Amount(100000), }, ) - ht.T.Cleanup(func() { - ht.CloseChannel(zane, chanPointZane) - }) // Now, Zane should know about Zane, Greg, and Carol along with a single // channel. @@ -103,6 +105,15 @@ func testRemoteGraph(ht *lntest.HarnessTest) { // about everything G knows about. G doesn't know about Z's private // channel. ht.EnsureConnected(greg, bob) + err := wait.Predicate(func() bool { + info, err := greg.RPC.LN.GetNodeInfo(ctx, &lnrpc.NodeInfoRequest{ + PubKey: carol.PubKeyStr, + }) + require.NoError(ht.T, err) + + return len(info.Node.Addresses) > 0 + }, time.Second*5) + require.NoError(ht.T, err) // Greg should know about the two public channels along with the public // nodes. It does not know about Zane since Zane's channel connecting it @@ -119,6 +130,39 @@ func testRemoteGraph(ht *lntest.HarnessTest) { // Zane should be able to settle the invoice. ht.CompletePaymentRequests(zane, []string{invoice.PaymentRequest}) + + // Close Zane's channel and mine some blocks so that both peers no + // longer see the other as a link node. + ht.CloseChannel(zane, chanPointZane) + ht.MineBlocks(6) + + // Disconnect Zane from Carol to ensure that Carol does not reconnect + // to zane when zane restarts. + ht.DisconnectNodes(carol, zane) + + // Restart Zane and assert that it does not connect to any peers since + // it has no channels with any peers and because network bootstrapping + // is disabled. + ht.RestartNode(zane) + err = wait.Invariant(func() bool { + peerResp := zane.RPC.ListPeers() + + return len(peerResp.Peers) == 0 + }, time.Second*5) + require.NoError(ht.T, err) + + // Now restart zane but this time allow peer bootstrap. + zane.Cfg.WithPeerBootstrap = true + ht.RestartNode(zane) + + // Show that zane now does connect to peers via bootstrapping using the + // graph data it queries from the Graph node. + err = wait.Predicate(func() bool { + peerResp := zane.RPC.ListPeers() + + return len(peerResp.Peers) > 0 + }, time.Second*5) + require.NoError(ht.T, err) } func setupNetwork(ht *lntest.HarnessTest, carol *node.HarnessNode) {