Skip to content

Commit 715cae9

Browse files
authored
Merge pull request #9967 from ellemouton/peerBootstrapItest
itest: test automatic peer bootstrapping
2 parents 8afe62a + 75a3531 commit 715cae9

File tree

6 files changed

+96
-100
lines changed

6 files changed

+96
-100
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ circuit. The indices are only available for forwarding events saved after v0.20.
125125

126126
## Testing
127127

128+
* Previously, automatic peer bootstrapping was disabled for simnet, signet and
129+
regtest networks even if the `--nobootstrap` flag was not set. This automatic
130+
disabling has now been
131+
[removed](https://github.com/lightningnetwork/lnd/pull/9967) meaning that any
132+
test network scripts that rely on bootstrapping being disabled will need to
133+
explicitly define the `--nobootstrap` flag.
134+
128135
## Database
129136

130137
## Code Health

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,10 @@ var allTestCases = []*lntest.TestCase{
707707
Name: "partially specified route blinded invoice",
708708
TestFunc: testPartiallySpecifiedBlindedPath,
709709
},
710+
{
711+
Name: "peer bootstrapping",
712+
TestFunc: testPeerBootstrapping,
713+
},
710714
}
711715

712716
// appendPrefixed is used to add a prefix to each test name in the subtests

itest/lnd_graph.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package itest
2+
3+
import (
4+
"time"
5+
6+
"github.com/btcsuite/btcd/btcutil"
7+
"github.com/lightningnetwork/lnd/lntest"
8+
"github.com/lightningnetwork/lnd/lntest/wait"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// testPeerBootstrapping tests that a node is able to use persisted node
13+
// announcements to bootstrap its peer connections. This is done by
14+
// connecting a node to a channel network so that it syncs the necessary gossip
15+
// and then:
16+
// 1. Asserting that on a restart where bootstrapping is _disabled_, the node
17+
// does not connect to any peers.
18+
// 2. Asserting that on a restart where bootstrapping is _enabled_, the node
19+
// does connect to peers.
20+
func testPeerBootstrapping(ht *lntest.HarnessTest) {
21+
// 1) Set up the following node/channel network.
22+
// Alice <- Bob <- Charlie
23+
_, nodes := ht.CreateSimpleNetwork(
24+
[][]string{nil, nil, nil}, lntest.OpenChannelParams{
25+
Amt: btcutil.Amount(100000),
26+
},
27+
)
28+
carol, bob, alice := nodes[0], nodes[1], nodes[2]
29+
30+
// Assert that they all know about each other and the channels.
31+
ht.AssertNumEdges(alice, 2, false)
32+
ht.AssertNumEdges(bob, 2, false)
33+
ht.AssertNumEdges(carol, 2, false)
34+
35+
// Spin up a new node, Dave.
36+
dave := ht.NewNode("Dave", nil)
37+
38+
// Explicitly assert that Dave was started with bootstrapping disabled.
39+
require.False(ht, dave.Cfg.WithPeerBootstrap)
40+
41+
// Assert that Dave's current view of the graph is empty.
42+
ht.AssertNumEdges(dave, 0, false)
43+
44+
// Now, connect Dave to Alice and wait for gossip sync to complete.
45+
ht.EnsureConnected(dave, alice)
46+
ht.AssertNumEdges(dave, 2, false)
47+
48+
// Disconnect Dave from Alice and restart Dave. Since Alice and Dave
49+
// did not have channels between them, the nodes should not reconnect
50+
// to each other.
51+
ht.DisconnectNodes(dave, alice)
52+
ht.RestartNode(dave)
53+
54+
// Dave still has bootstrapping disabled and so it should not connect
55+
// to any peers.
56+
err := wait.Invariant(func() bool {
57+
peerResp := dave.RPC.ListPeers()
58+
59+
return len(peerResp.Peers) == 0
60+
}, time.Second*5)
61+
require.NoError(ht, err)
62+
63+
// Dave should still know about the full graph though since it was
64+
// synced previously from Alice.
65+
ht.AssertNumEdges(dave, 2, false)
66+
67+
// Restart Dave again but this time with bootstrapping enabled.
68+
dave.Cfg.WithPeerBootstrap = true
69+
ht.RestartNode(dave)
70+
71+
// Show that Dave now does connect to some peers. The default minimum
72+
// number of peers that will be connected to is 3, so we
73+
// expect Dave to connect to all three nodes in the network.
74+
ht.AssertConnected(dave, alice)
75+
ht.AssertConnected(dave, bob)
76+
ht.AssertConnected(dave, carol)
77+
}

lntest/node/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ type BaseNodeConfig struct {
146146
ReadMacPath string
147147
InvoiceMacPath string
148148

149-
SkipUnlock bool
150-
Password []byte
149+
SkipUnlock bool
150+
Password []byte
151+
WithPeerBootstrap bool
151152

152153
P2PPort int
153154
RPCPort int
@@ -285,7 +286,6 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
285286
args = append(args, backendArgs...)
286287

287288
nodeArgs := []string{
288-
"--nobootstrap",
289289
"--debuglevel=debug",
290290
"--bitcoin.defaultchanconfs=1",
291291
"--accept-keysend",
@@ -326,6 +326,10 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
326326
args = append(args, "--noseedbackup")
327327
}
328328

329+
if !cfg.WithPeerBootstrap {
330+
args = append(args, "--nobootstrap")
331+
}
332+
329333
switch cfg.DBBackend {
330334
case BackendEtcd:
331335
args = append(args, "--db.backend=etcd")

server.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ func (s *server) Start(ctx context.Context) error {
26442644
// configure the set of active bootstrappers, and launch a
26452645
// dedicated goroutine to maintain a set of persistent
26462646
// connections.
2647-
if shouldPeerBootstrap(s.cfg) {
2647+
if !s.cfg.NoNetBootstrap {
26482648
bootstrappers, err := initNetworkBootstrappers(s)
26492649
if err != nil {
26502650
startErr = err
@@ -5378,20 +5378,6 @@ func newSweepPkScriptGen(
53785378
}
53795379
}
53805380

5381-
// shouldPeerBootstrap returns true if we should attempt to perform peer
5382-
// bootstrapping to actively seek our peers using the set of active network
5383-
// bootstrappers.
5384-
func shouldPeerBootstrap(cfg *Config) bool {
5385-
isSimnet := cfg.Bitcoin.SimNet
5386-
isSignet := cfg.Bitcoin.SigNet
5387-
isRegtest := cfg.Bitcoin.RegTest
5388-
isDevNetwork := isSimnet || isSignet || isRegtest
5389-
5390-
// TODO(yy): remove the check on simnet/regtest such that the itest is
5391-
// covering the bootstrapping process.
5392-
return !cfg.NoNetBootstrap && !isDevNetwork
5393-
}
5394-
53955381
// fetchClosedChannelSCIDs returns a set of SCIDs that have their force closing
53965382
// finished.
53975383
func (s *server) fetchClosedChannelSCIDs() map[lnwire.ShortChannelID]struct{} {

server_test.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)