lnd: removing activeNetParams global, passed around instead via configs

This commit removes the activeNetParams global in chainparams.go. This
is necessary to isolate code from the lnd package so we can import it
for use in tests, other projects, etc.
This commit is contained in:
nsa
2020-08-04 14:56:31 -04:00
committed by eugene
parent 37a29b4869
commit 3791c9efcb
9 changed files with 105 additions and 92 deletions

View File

@@ -370,7 +370,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
)
replayLog := htlcswitch.NewDecayedLog(sharedSecretPath, cc.chainNotifier)
sphinxRouter := sphinx.NewRouter(
nodeKeyECDH, activeNetParams.Params, replayLog,
nodeKeyECDH, cfg.ActiveNetParams.Params, replayLog,
)
writeBufferPool := pool.NewWriteBuffer(
@@ -773,7 +773,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
s.authGossiper = discovery.New(discovery.Config{
Router: s.chanRouter,
Notifier: s.cc.chainNotifier,
ChainHash: *activeNetParams.GenesisHash,
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
Broadcast: s.BroadcastMessage,
ChanSeries: chanSeries,
NotifyWhenOnline: s.NotifyWhenOnline,
@@ -805,9 +805,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
FetchChannel: s.remoteChanDB.FetchChannel,
}
utxnStore, err := newNurseryStore(
activeNetParams.GenesisHash, remoteChanDB,
)
utxnStore, err := newNurseryStore(s.cfg.ActiveNetParams.GenesisHash, remoteChanDB)
if err != nil {
srvrLog.Errorf("unable to create nursery store: %v", err)
return nil, err
@@ -817,7 +815,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
sweep.DefaultBatchWindowDuration)
sweeperStore, err := sweep.NewSweeperStore(
remoteChanDB, activeNetParams.GenesisHash,
remoteChanDB, s.cfg.ActiveNetParams.GenesisHash,
)
if err != nil {
srvrLog.Errorf("unable to create sweeper store: %v", err)
@@ -869,7 +867,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
contractBreaches := make(chan *ContractBreachEvent, 1)
s.chainArb = contractcourt.NewChainArbitrator(contractcourt.ChainArbitratorConfig{
ChainHash: *activeNetParams.GenesisHash,
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
IncomingBroadcastDelta: lncfg.DefaultIncomingBroadcastDelta,
OutgoingBroadcastDelta: lncfg.DefaultOutgoingBroadcastDelta,
NewSweepAddr: newSweepPkScriptGen(cc.wallet),
@@ -1221,7 +1219,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
AuthDial: wtclient.AuthDial,
DB: towerClientDB,
Policy: policy,
ChainHash: *activeNetParams.GenesisHash,
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
MinBackoff: 10 * time.Second,
MaxBackoff: 5 * time.Minute,
ForceQuitDelay: wtclient.DefaultForceQuitDelay,
@@ -1751,7 +1749,7 @@ func initNetworkBootstrappers(s *server) ([]discovery.NetworkPeerBootstrapper, e
// If this isn't simnet mode, then one of our additional bootstrapping
// sources will be the set of running DNS seeds.
if !s.cfg.Bitcoin.SimNet || !s.cfg.Litecoin.SimNet {
dnsSeeds, ok := chainDNSSeeds[*activeNetParams.GenesisHash]
dnsSeeds, ok := chainDNSSeeds[*s.cfg.ActiveNetParams.GenesisHash]
// If we have a set of DNS seeds for this chain, then we'll add
// it as an additional bootstrapping source.
@@ -2812,7 +2810,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
peerAddr := &lnwire.NetAddress{
IdentityKey: pubKey,
Address: addr,
ChainNet: activeNetParams.Net,
ChainNet: s.cfg.ActiveNetParams.Net,
}
// With the brontide connection established, we'll now craft the feature