Skip to content

Commit

Permalink
itest: bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Nov 18, 2024
1 parent c55185f commit 7968f06
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,8 @@ var allTestCases = []*lntest.TestCase{
Name: "remote graph",
TestFunc: testRemoteGraph,
},
{
Name: "remote graph peer bootstrap",
TestFunc: testRemoteGraphPeerBootstrap,
},
}
82 changes: 82 additions & 0 deletions itest/lnd_remote_graph_test.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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)
}

0 comments on commit 7968f06

Please sign in to comment.