From 6b1696c4f2200e2d46131c748fe7ec76835cb180 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 23 Jul 2021 16:50:45 -0700 Subject: [PATCH 1/3] server: disable DNS boostrap for SigNet nodes In this commit, we fix a bug that would cause nodes attempting to run using the signet chain, to waste CPU as they attempted to boostrap to a non-existent DNS seed. We fix this by ignoring the DNS boostrapper is signet is active. Along the way, we refactor the conditional sightly to be more readable, and easily extensible. --- server.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index b21c71a47..0ab1abaaf 100644 --- a/server.go +++ b/server.go @@ -1788,10 +1788,11 @@ func (s *server) Start() error { // configure the set of active bootstrappers, and launch a // dedicated goroutine to maintain a set of persistent // connections. - if !s.cfg.NoNetBootstrap && - !(s.cfg.Bitcoin.SimNet || s.cfg.Litecoin.SimNet) && - !(s.cfg.Bitcoin.RegTest || s.cfg.Litecoin.RegTest) { - + isSimnet := (s.cfg.Bitcoin.SimNet || s.cfg.Litecoin.SimNet) + isSignet := (s.cfg.Bitcoin.SigNet || s.cfg.Litecoin.SigNet) + isRegtest := (s.cfg.Bitcoin.RegTest || s.cfg.Litecoin.RegTest) + isDevNetwork := isSimnet || isSignet || isRegtest + if !s.cfg.NoNetBootstrap && !isDevNetwork { bootstrappers, err := initNetworkBootstrappers(s) if err != nil { startErr = err From 673acd781d6bd193e1815cc218dcf4e9e70a8eac Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 4 Aug 2021 18:27:27 -0700 Subject: [PATCH 2/3] server: extract bootstrap logic into new function w/ unit test --- server.go | 18 ++++++++--- server_test.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 0ab1abaaf..358e4f70a 100644 --- a/server.go +++ b/server.go @@ -1788,11 +1788,7 @@ func (s *server) Start() error { // configure the set of active bootstrappers, and launch a // dedicated goroutine to maintain a set of persistent // connections. - isSimnet := (s.cfg.Bitcoin.SimNet || s.cfg.Litecoin.SimNet) - isSignet := (s.cfg.Bitcoin.SigNet || s.cfg.Litecoin.SigNet) - isRegtest := (s.cfg.Bitcoin.RegTest || s.cfg.Litecoin.RegTest) - isDevNetwork := isSimnet || isSignet || isRegtest - if !s.cfg.NoNetBootstrap && !isDevNetwork { + if shouldPeerBootstrap(s.cfg) { bootstrappers, err := initNetworkBootstrappers(s) if err != nil { startErr = err @@ -3964,3 +3960,15 @@ func newSweepPkScriptGen( return txscript.PayToAddrScript(sweepAddr) } } + +// shouldPeerBootstrap returns true if we should attempt to perform peer +// boostrapping to actively seek our peers using the set of active network +// bootsrappers. +func shouldPeerBootstrap(cfg *Config) bool { + isSimnet := (cfg.Bitcoin.SimNet || cfg.Litecoin.SimNet) + isSignet := (cfg.Bitcoin.SigNet || cfg.Litecoin.SigNet) + isRegtest := (cfg.Bitcoin.RegTest || cfg.Litecoin.RegTest) + isDevNetwork := isSimnet || isSignet || isRegtest + + return !cfg.NoNetBootstrap && !isDevNetwork +} diff --git a/server_test.go b/server_test.go index 5e8683f8f..7bcecbc06 100644 --- a/server_test.go +++ b/server_test.go @@ -17,6 +17,8 @@ import ( "os" "testing" "time" + + "github.com/lightningnetwork/lnd/lncfg" ) func TestParseHexColor(t *testing.T) { @@ -203,3 +205,84 @@ func genExpiredCertPair(t *testing.T, certDirPath string) ([]byte, []byte) { return certDerBytes, keyBytes } + +// TestShouldPeerBootstrap tests that we properly skip network bootstrap for +// the developer networks, and also if bootstrapping is explicitly disabled. +func TestShouldPeerBootstrap(t *testing.T) { + t.Parallel() + + testCases := []struct { + cfg *Config + shouldBoostrap bool + }{ + // Simnet active, no bootstrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + SimNet: true, + }, + Litecoin: &lncfg.Chain{}, + }, + }, + + // Regtest active, no bootstrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + RegTest: true, + }, + Litecoin: &lncfg.Chain{}, + }, + }, + + // Signet active, no bootstrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + SigNet: true, + }, + Litecoin: &lncfg.Chain{}, + }, + }, + + // Mainnet active, but boostrap disabled, no boostrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + MainNet: true, + }, + Litecoin: &lncfg.Chain{}, + NoNetBootstrap: true, + }, + }, + + // Mainnet active, should boostrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + MainNet: true, + }, + Litecoin: &lncfg.Chain{}, + }, + shouldBoostrap: true, + }, + + // Testnet active, should boostrap. + { + cfg: &Config{ + Bitcoin: &lncfg.Chain{ + TestNet3: true, + }, + Litecoin: &lncfg.Chain{}, + }, + shouldBoostrap: true, + }, + } + for i, testCase := range testCases { + bootstrapped := shouldPeerBootstrap(testCase.cfg) + if bootstrapped != testCase.shouldBoostrap { + t.Fatalf("#%v: expected bootstrap=%v, got bootstrap=%v", + i, testCase.shouldBoostrap, bootstrapped) + } + } +} From 98b29a69678ef11a72bbf0faa6d1c53e1ea3367d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 4 Aug 2021 18:31:23 -0700 Subject: [PATCH 3/3] docs/release-notes: update release notes for signet DNS fix --- docs/release-notes/release-notes-0.14.0.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index 80a8c80d6..268f3dc6c 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -106,6 +106,12 @@ you. * [Update MC store in blocks](https://github.com/lightningnetwork/lnd/pull/5515) to make payment throughput better when using etcd. +## Bug Fixes + +A bug has been fixed that would cause `lnd` to [try to bootstrap using the +currnet DNS seeds when in SigNet +mode](https://github.com/lightningnetwork/lnd/pull/5564). + # Contributors (Alphabetical Order) * ErikEk * Martin Habovstiak