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 e6566df commit ed39ccb
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions itest/lnd_remote_graph_test.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit ed39ccb

Please sign in to comment.