• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15774978611

20 Jun 2025 08:42AM UTC coverage: 68.259% (+10.2%) from 58.079%
15774978611

Pull #9967

github

web-flow
Merge fd1e84f38 into a3209a5bf
Pull Request #9967: itest: test automatic peer bootstrapping

1 of 89 new or added lines in 3 files covered. (1.12%)

13 existing lines in 4 files now uncovered.

134766 of 197433 relevant lines covered (68.26%)

22105.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/itest/lnd_graph.go
1
package itest
2

3
import (
4
        "time"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
        "github.com/lightningnetwork/lnd/lnrpc"
8
        "github.com/lightningnetwork/lnd/lntest"
9
        "github.com/lightningnetwork/lnd/lntest/node"
10
        "github.com/lightningnetwork/lnd/lntest/wait"
11
        "github.com/stretchr/testify/require"
12
)
13

14
// testPeerBootstrapping tests that a node is able to use persisted node
15
// announcements to bootstrap its peer connections. This is done by
16
// connecting a node to a channel network so that it syncs the necessary gossip
17
// and then:
18
//  1. Asserting that on a restart where bootstrapping is _disabled_, the node
19
//     does not connect to any peers.
20
//  2. Asserting that on a restart where bootstrapping is _enabled_, the node
21
//     does connect to peers.
NEW
22
func testPeerBootstrapping(ht *lntest.HarnessTest) {
×
NEW
23
        var descGraphReq = &lnrpc.ChannelGraphRequest{
×
NEW
24
                IncludeUnannounced: true,
×
NEW
25
        }
×
NEW
26

×
NEW
27
        // assertDescGraph is a helper that we can use to assert that a node
×
NEW
28
        // knows about a certain number of edges and nodes in the graph.
×
NEW
29
        assertDescGraph := func(node *node.HarnessNode, numEdges int,
×
NEW
30
                nodes ...*node.HarnessNode) {
×
NEW
31

×
NEW
32
                descGraphResp := node.RPC.DescribeGraph(descGraphReq)
×
NEW
33

×
NEW
34
                // Assert that the node knows about the expected number of
×
NEW
35
                // edges.
×
NEW
36
                require.Len(ht.T, descGraphResp.Edges, numEdges)
×
NEW
37

×
NEW
38
                // Make a lookup table of known nodes.
×
NEW
39
                knownNodes := map[string]bool{
×
NEW
40
                        // A node will always know about itself.
×
NEW
41
                        node.PubKeyStr: true,
×
NEW
42
                }
×
NEW
43
                for _, n := range descGraphResp.Nodes {
×
NEW
44
                        knownNodes[n.PubKey] = true
×
NEW
45
                }
×
NEW
46
                require.Len(ht.T, knownNodes, len(nodes)+1)
×
NEW
47

×
NEW
48
                // Assert that all the expected nodes are known.
×
NEW
49
                for _, n := range nodes {
×
NEW
50
                        require.True(ht.T, knownNodes[n.PubKeyStr])
×
NEW
51
                }
×
52
        }
53

54
        // 1) Set up the following node/channel network.
55
        //         Alice <- Bob <- Charlie
NEW
56
        _, nodes := ht.CreateSimpleNetwork(
×
NEW
57
                [][]string{nil, nil, nil}, lntest.OpenChannelParams{
×
NEW
58
                        Amt: btcutil.Amount(100000),
×
NEW
59
                },
×
NEW
60
        )
×
NEW
61
        carol, bob, alice := nodes[0], nodes[1], nodes[2]
×
NEW
62

×
NEW
63
        // Assert that they all know about each other and the channels.
×
NEW
64
        assertDescGraph(alice, 2, bob, carol)
×
NEW
65
        assertDescGraph(bob, 2, alice, carol)
×
NEW
66
        assertDescGraph(carol, 2, alice, bob)
×
NEW
67

×
NEW
68
        // Spin up a new node, Dave.
×
NEW
69
        dave := ht.NewNode("Dave", nil)
×
NEW
70

×
NEW
71
        // Explicitly assert that Dave was started with bootstrapping disabled.
×
NEW
72
        require.False(ht.T, dave.Cfg.WithPeerBootstrap)
×
NEW
73

×
NEW
74
        // Assert that Dave's current view of the graph is empty.
×
NEW
75
        assertDescGraph(dave, 0)
×
NEW
76

×
NEW
77
        // Now, connect Dave to Alice and wait for gossip sync to complete.
×
NEW
78
        ht.EnsureConnected(dave, alice)
×
NEW
79
        assertDescGraph(dave, 2, alice, bob, carol)
×
NEW
80

×
NEW
81
        // Disconnect Dave from Alice and restart Dave. Since Alice and Dave
×
NEW
82
        // did not have channels between them, the nodes should not reconnect
×
NEW
83
        // to each other.
×
NEW
84
        ht.DisconnectNodes(dave, alice)
×
NEW
85
        ht.RestartNode(dave)
×
NEW
86

×
NEW
87
        // Dave still has bootstrapping disabled and so it should not connect
×
NEW
88
        // to any peers.
×
NEW
89
        err := wait.Invariant(func() bool {
×
NEW
90
                peerResp := dave.RPC.ListPeers()
×
NEW
91

×
NEW
92
                return len(peerResp.Peers) == 0
×
NEW
93
        }, time.Second*5)
×
NEW
94
        require.NoError(ht.T, err)
×
NEW
95

×
NEW
96
        // Dave should still know about the full graph though since it was
×
NEW
97
        // synced previously from Alice.
×
NEW
98
        assertDescGraph(dave, 2, alice, bob, carol)
×
NEW
99

×
NEW
100
        // Restart Dave again but this time with bootstrapping enabled.
×
NEW
101
        dave.Cfg.WithPeerBootstrap = true
×
NEW
102
        ht.RestartNode(dave)
×
NEW
103

×
NEW
104
        // Show that Dave now does connect to some peers.
×
NEW
105
        err = wait.Predicate(func() bool {
×
NEW
106
                peerResp := dave.RPC.ListPeers()
×
NEW
107

×
NEW
108
                return len(peerResp.Peers) > 0
×
NEW
109
        }, time.Second*5)
×
NEW
110
        require.NoError(ht.T, err)
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc