diff --git a/itest/list_on_test.go b/itest/list_on_test.go index a9b168999ce..81a79ba25be 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -706,4 +706,8 @@ var allTestCases = []*lntest.TestCase{ Name: "remote graph", TestFunc: testRemoteGraph, }, + { + Name: "remote graph peer bootstrap", + TestFunc: testRemoteGraphPeerBootstrap, + }, } diff --git a/itest/lnd_remote_graph_test.go b/itest/lnd_remote_graph_test.go index cd2a1d00bb6..dfb578d32bb 100644 --- a/itest/lnd_remote_graph_test.go +++ b/itest/lnd_remote_graph_test.go @@ -1,12 +1,16 @@ 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/port" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) @@ -157,3 +161,81 @@ func setupNetwork(ht *lntest.HarnessTest, carol *node.HarnessNode) { ht.CloseChannel(ht.Bob, chanPointBob) }) } + +func testRemoteGraphPeerBootstrap(ht *lntest.HarnessTest) { + // Set up a network. Set up a graph node that syncs the network. + // start zane in no-gossip node + remote graph + Allow peer bootstrap. + // show that it connects to peers that it got in graph node DB. + + var ( + //alice = ht.Alice + bob = ht.Bob + ) + + // We derive an extra port for Carol, and we initialise her node with + // the port advertised as `--externalip` arguments. + ip2 := port.NextAvailablePort() + + // Set up a network: + // A <- B <- C + carol := ht.NewNode("Carol", []string{fmt.Sprintf("--externalip=127.0.0.1:%d", ip2)}) + carol.Cfg.P2PPort = ip2 + ht.RestartNode(carol) + + setupNetwork(ht, carol) + + // Create graph provider node, Greg. + greg := ht.NewNode("Greg", nil) + + // Now, connect G to B. Wait for it to sync gossip. It should know about + // the two public channels along with the public nodes and it should + // know Carol's advertised address. + ht.EnsureConnected(greg, bob) + + err := wait.Predicate(func() bool { + info, err := greg.RPC.LN.GetNodeInfo(context.Background(), &lnrpc.NodeInfoRequest{ + PubKey: carol.PubKeyStr, + }) + require.NoError(ht.T, err) + + return len(info.Node.Addresses) > 0 + }, time.Second*5) + require.NoError(ht.T, err) + + // Create a node, Zane, that uses Greg as its graph provider. Zane + // syncs no gossip. + zane := ht.NewNode("Zane", []string{ + "--gossip.no-sync", + "--remotegraph.enable", + fmt.Sprintf( + "--remotegraph.rpchost=localhost:%d", greg.Cfg.RPCPort, + ), + fmt.Sprintf( + "--remotegraph.tlscertpath=%s", greg.Cfg.TLSCertPath, + ), + fmt.Sprintf( + "--remotegraph.macaroonpath=%s", greg.Cfg.AdminMacPath, + ), + }) + + // Show that zane does not automatically connect to Carol via + // bootstrapping. + 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 Carol via bootstrapping. + err = wait.Predicate(func() bool { + peerResp := zane.RPC.ListPeers() + + return len(peerResp.Peers) > 0 + }, time.Second*5) + require.NoError(ht.T, err) +}