mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-12 09:52:14 +02:00
server: extract bootstrap logic into new function w/ unit test
This commit is contained in:
parent
6b1696c4f2
commit
673acd781d
18
server.go
18
server.go
@ -1788,11 +1788,7 @@ func (s *server) Start() error {
|
|||||||
// configure the set of active bootstrappers, and launch a
|
// configure the set of active bootstrappers, and launch a
|
||||||
// dedicated goroutine to maintain a set of persistent
|
// dedicated goroutine to maintain a set of persistent
|
||||||
// connections.
|
// connections.
|
||||||
isSimnet := (s.cfg.Bitcoin.SimNet || s.cfg.Litecoin.SimNet)
|
if shouldPeerBootstrap(s.cfg) {
|
||||||
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)
|
bootstrappers, err := initNetworkBootstrappers(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
startErr = err
|
startErr = err
|
||||||
@ -3964,3 +3960,15 @@ func newSweepPkScriptGen(
|
|||||||
return txscript.PayToAddrScript(sweepAddr)
|
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
|
||||||
|
}
|
||||||
|
@ -17,6 +17,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseHexColor(t *testing.T) {
|
func TestParseHexColor(t *testing.T) {
|
||||||
@ -203,3 +205,84 @@ func genExpiredCertPair(t *testing.T, certDirPath string) ([]byte, []byte) {
|
|||||||
|
|
||||||
return certDerBytes, keyBytes
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user