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

@ -10,10 +10,6 @@ import (
litecoinWire "github.com/ltcsuite/ltcd/wire" litecoinWire "github.com/ltcsuite/ltcd/wire"
) )
// activeNetParams is a pointer to the parameters specific to the currently
// active bitcoin network.
var activeNetParams = bitcoinTestNetParams
// bitcoinNetParams couples the p2p parameters of a network with the // bitcoinNetParams couples the p2p parameters of a network with the
// corresponding RPC port of a daemon running on the particular network. // corresponding RPC port of a daemon running on the particular network.
type bitcoinNetParams struct { type bitcoinNetParams struct {

View File

@ -212,8 +212,8 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
Birthday: birthday, Birthday: birthday,
RecoveryWindow: recoveryWindow, RecoveryWindow: recoveryWindow,
DataDir: homeChainConfig.ChainDir, DataDir: homeChainConfig.ChainDir,
NetParams: activeNetParams.Params, NetParams: cfg.ActiveNetParams.Params,
CoinType: activeNetParams.CoinType, CoinType: cfg.ActiveNetParams.CoinType,
Wallet: wallet, Wallet: wallet,
} }
@ -267,7 +267,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
} }
walletConfig.ChainSource = chain.NewNeutrinoClient( walletConfig.ChainSource = chain.NewNeutrinoClient(
activeNetParams.Params, neutrinoCS, cfg.ActiveNetParams.Params, neutrinoCS,
) )
case "bitcoind", "litecoind": case "bitcoind", "litecoind":
@ -291,7 +291,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// btcd, which picks a different port so that btcwallet // btcd, which picks a different port so that btcwallet
// can use the same RPC port as bitcoind. We convert // can use the same RPC port as bitcoind. We convert
// this back to the btcwallet/bitcoind port. // this back to the btcwallet/bitcoind port.
rpcPort, err := strconv.Atoi(activeNetParams.rpcPort) rpcPort, err := strconv.Atoi(cfg.ActiveNetParams.rpcPort)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -319,7 +319,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// Establish the connection to bitcoind and create the clients // Establish the connection to bitcoind and create the clients
// required for our relevant subsystems. // required for our relevant subsystems.
bitcoindConn, err := chain.NewBitcoindConn( bitcoindConn, err := chain.NewBitcoindConn(
activeNetParams.Params, bitcoindHost, cfg.ActiveNetParams.Params, bitcoindHost,
bitcoindMode.RPCUser, bitcoindMode.RPCPass, bitcoindMode.RPCUser, bitcoindMode.RPCPass,
bitcoindMode.ZMQPubRawBlock, bitcoindMode.ZMQPubRawTx, bitcoindMode.ZMQPubRawBlock, bitcoindMode.ZMQPubRawTx,
5*time.Second, 5*time.Second,
@ -334,7 +334,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
} }
cc.chainNotifier = bitcoindnotify.New( cc.chainNotifier = bitcoindnotify.New(
bitcoindConn, activeNetParams.Params, hintCache, hintCache, bitcoindConn, cfg.ActiveNetParams.Params, hintCache, hintCache,
) )
cc.chainView = chainview.NewBitcoindFilteredChainView(bitcoindConn) cc.chainView = chainview.NewBitcoindFilteredChainView(bitcoindConn)
walletConfig.ChainSource = bitcoindConn.NewBitcoindClient() walletConfig.ChainSource = bitcoindConn.NewBitcoindClient()
@ -432,7 +432,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
btcdHost = btcdMode.RPCHost btcdHost = btcdMode.RPCHost
} else { } else {
btcdHost = fmt.Sprintf("%v:%v", btcdMode.RPCHost, btcdHost = fmt.Sprintf("%v:%v", btcdMode.RPCHost,
activeNetParams.rpcPort) cfg.ActiveNetParams.rpcPort)
} }
btcdUser := btcdMode.RPCUser btcdUser := btcdMode.RPCUser
@ -448,7 +448,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
DisableAutoReconnect: false, DisableAutoReconnect: false,
} }
cc.chainNotifier, err = btcdnotify.New( cc.chainNotifier, err = btcdnotify.New(
rpcConfig, activeNetParams.Params, hintCache, hintCache, rpcConfig, cfg.ActiveNetParams.Params, hintCache, hintCache,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -464,7 +464,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// Create a special websockets rpc client for btcd which will be used // Create a special websockets rpc client for btcd which will be used
// by the wallet for notifications, calls, etc. // by the wallet for notifications, calls, etc.
chainRPC, err := chain.NewRPCClient(activeNetParams.Params, btcdHost, chainRPC, err := chain.NewRPCClient(cfg.ActiveNetParams.Params, btcdHost,
btcdUser, btcdPass, rpcCert, false, 20) btcdUser, btcdPass, rpcCert, false, 20)
if err != nil { if err != nil {
return nil, err return nil, err
@ -517,7 +517,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
} }
keyRing := keychain.NewBtcWalletKeyRing( keyRing := keychain.NewBtcWalletKeyRing(
wc.InternalWallet(), activeNetParams.CoinType, wc.InternalWallet(), cfg.ActiveNetParams.CoinType,
) )
cc.keyRing = keyRing cc.keyRing = keyRing
@ -532,7 +532,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
SecretKeyRing: keyRing, SecretKeyRing: keyRing,
ChainIO: cc.chainIO, ChainIO: cc.chainIO,
DefaultConstraints: channelConstraints, DefaultConstraints: channelConstraints,
NetParams: *activeNetParams.Params, NetParams: *cfg.ActiveNetParams.Params,
} }
lnWallet, err := lnwallet.NewLightningWallet(walletCfg) lnWallet, err := lnwallet.NewLightningWallet(walletCfg)
if err != nil { if err != nil {
@ -734,7 +734,7 @@ func initNeutrinoBackend(cfg *Config, chainDir string) (*neutrino.ChainService,
// match the behavior of btcwallet. // match the behavior of btcwallet.
dbPath := filepath.Join( dbPath := filepath.Join(
chainDir, chainDir,
normalizeNetwork(activeNetParams.Name), normalizeNetwork(cfg.ActiveNetParams.Name),
) )
// Ensure that the neutrino db path exists. // Ensure that the neutrino db path exists.
@ -763,7 +763,7 @@ func initNeutrinoBackend(cfg *Config, chainDir string) (*neutrino.ChainService,
config := neutrino.Config{ config := neutrino.Config{
DataDir: dbPath, DataDir: dbPath,
Database: db, Database: db,
ChainParams: *activeNetParams.Params, ChainParams: *cfg.ActiveNetParams.Params,
AddPeers: cfg.NeutrinoMode.AddPeers, AddPeers: cfg.NeutrinoMode.AddPeers,
ConnectPeers: cfg.NeutrinoMode.ConnectPeers, ConnectPeers: cfg.NeutrinoMode.ConnectPeers,
Dialer: func(addr net.Addr) (net.Conn, error) { Dialer: func(addr net.Addr) (net.Conn, error) {

View File

@ -274,6 +274,9 @@ type Config struct {
// network. This path will hold the files related to each different // network. This path will hold the files related to each different
// network. // network.
networkDir string networkDir string
// ActiveNetParams contains parameters of the target chain.
ActiveNetParams bitcoinNetParams
} }
// DefaultConfig returns all default values for the Config struct. // DefaultConfig returns all default values for the Config struct.
@ -380,6 +383,7 @@ func DefaultConfig() Config {
LogWriter: build.NewRotatingLogWriter(), LogWriter: build.NewRotatingLogWriter(),
DB: lncfg.DefaultDB(), DB: lncfg.DefaultDB(),
registeredChains: newChainRegistry(), registeredChains: newChainRegistry(),
ActiveNetParams: bitcoinTestNetParams,
} }
} }
@ -736,12 +740,12 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// throughout the codebase we required chaincfg.Params. So as a // throughout the codebase we required chaincfg.Params. So as a
// temporary hack, we'll mutate the default net params for // temporary hack, we'll mutate the default net params for
// bitcoin with the litecoin specific information. // bitcoin with the litecoin specific information.
applyLitecoinParams(&activeNetParams, &ltcParams) applyLitecoinParams(&cfg.ActiveNetParams, &ltcParams)
switch cfg.Litecoin.Node { switch cfg.Litecoin.Node {
case "ltcd": case "ltcd":
err := parseRPCParams(cfg.Litecoin, cfg.LtcdMode, err := parseRPCParams(cfg.Litecoin, cfg.LtcdMode,
litecoinChain, funcName) litecoinChain, funcName, cfg.ActiveNetParams)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
"credentials for ltcd: %v", err) "credentials for ltcd: %v", err)
@ -753,7 +757,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
"support simnet", funcName) "support simnet", funcName)
} }
err := parseRPCParams(cfg.Litecoin, cfg.LitecoindMode, err := parseRPCParams(cfg.Litecoin, cfg.LitecoindMode,
litecoinChain, funcName) litecoinChain, funcName, cfg.ActiveNetParams)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
"credentials for litecoind: %v", err) "credentials for litecoind: %v", err)
@ -781,19 +785,19 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
numNets := 0 numNets := 0
if cfg.Bitcoin.MainNet { if cfg.Bitcoin.MainNet {
numNets++ numNets++
activeNetParams = bitcoinMainNetParams cfg.ActiveNetParams = bitcoinMainNetParams
} }
if cfg.Bitcoin.TestNet3 { if cfg.Bitcoin.TestNet3 {
numNets++ numNets++
activeNetParams = bitcoinTestNetParams cfg.ActiveNetParams = bitcoinTestNetParams
} }
if cfg.Bitcoin.RegTest { if cfg.Bitcoin.RegTest {
numNets++ numNets++
activeNetParams = bitcoinRegTestNetParams cfg.ActiveNetParams = bitcoinRegTestNetParams
} }
if cfg.Bitcoin.SimNet { if cfg.Bitcoin.SimNet {
numNets++ numNets++
activeNetParams = bitcoinSimNetParams cfg.ActiveNetParams = bitcoinSimNetParams
} }
if numNets > 1 { if numNets > 1 {
str := "%s: The mainnet, testnet, regtest, and " + str := "%s: The mainnet, testnet, regtest, and " +
@ -822,6 +826,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
case "btcd": case "btcd":
err := parseRPCParams( err := parseRPCParams(
cfg.Bitcoin, cfg.BtcdMode, bitcoinChain, funcName, cfg.Bitcoin, cfg.BtcdMode, bitcoinChain, funcName,
cfg.ActiveNetParams,
) )
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
@ -836,6 +841,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
err := parseRPCParams( err := parseRPCParams(
cfg.Bitcoin, cfg.BitcoindMode, bitcoinChain, funcName, cfg.Bitcoin, cfg.BitcoindMode, bitcoinChain, funcName,
cfg.ActiveNetParams,
) )
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
@ -913,7 +919,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.networkDir = filepath.Join( cfg.networkDir = filepath.Join(
cfg.DataDir, defaultChainSubDirname, cfg.DataDir, defaultChainSubDirname,
cfg.registeredChains.PrimaryChain().String(), cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name), normalizeNetwork(cfg.ActiveNetParams.Name),
) )
// If a custom macaroon directory wasn't specified and the data // If a custom macaroon directory wasn't specified and the data
@ -947,7 +953,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// per network in the same fashion as the data directory. // per network in the same fashion as the data directory.
cfg.LogDir = filepath.Join(cfg.LogDir, cfg.LogDir = filepath.Join(cfg.LogDir,
cfg.registeredChains.PrimaryChain().String(), cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name)) normalizeNetwork(cfg.ActiveNetParams.Name))
// A log writer must be passed in, otherwise we can't function and would // A log writer must be passed in, otherwise we can't function and would
// run into a panic later on. // run into a panic later on.
@ -1135,11 +1141,11 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
func (c *Config) localDatabaseDir() string { func (c *Config) localDatabaseDir() string {
return filepath.Join(c.DataDir, return filepath.Join(c.DataDir,
defaultGraphSubDirname, defaultGraphSubDirname,
normalizeNetwork(activeNetParams.Name)) normalizeNetwork(c.ActiveNetParams.Name))
} }
func (c *Config) networkName() string { func (c *Config) networkName() string {
return normalizeNetwork(activeNetParams.Name) return normalizeNetwork(c.ActiveNetParams.Name)
} }
// CleanAndExpandPath expands environment variables and leading ~ in the // CleanAndExpandPath expands environment variables and leading ~ in the
@ -1169,7 +1175,7 @@ func CleanAndExpandPath(path string) string {
} }
func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, net chainCode, func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, net chainCode,
funcName string) error { // nolint:unparam funcName string, netParams bitcoinNetParams) error { // nolint:unparam
// First, we'll check our node config to make sure the RPC parameters // First, we'll check our node config to make sure the RPC parameters
// were set correctly. We'll also determine the path to the conf file // were set correctly. We'll also determine the path to the conf file
@ -1279,7 +1285,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, net chainCode,
case "bitcoind", "litecoind": case "bitcoind", "litecoind":
nConf := nodeConfig.(*lncfg.Bitcoind) nConf := nodeConfig.(*lncfg.Bitcoind)
rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err := rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err :=
extractBitcoindRPCParams(confFile) extractBitcoindRPCParams(netParams.Params.Name, confFile)
if err != nil { if err != nil {
return fmt.Errorf("unable to extract RPC credentials:"+ return fmt.Errorf("unable to extract RPC credentials:"+
" %v, cannot start w/o RPC connection", " %v, cannot start w/o RPC connection",
@ -1339,13 +1345,13 @@ func extractBtcdRPCParams(btcdConfigPath string) (string, string, error) {
return string(userSubmatches[1]), string(passSubmatches[1]), nil return string(userSubmatches[1]), string(passSubmatches[1]), nil
} }
// extractBitcoindParams attempts to extract the RPC credentials for an // extractBitcoindRPCParams attempts to extract the RPC credentials for an
// existing bitcoind node instance. The passed path is expected to be the // existing bitcoind node instance. The passed path is expected to be the
// location of bitcoind's bitcoin.conf on the target system. The routine looks // location of bitcoind's bitcoin.conf on the target system. The routine looks
// for a cookie first, optionally following the datadir configuration option in // for a cookie first, optionally following the datadir configuration option in
// the bitcoin.conf. If it doesn't find one, it looks for rpcuser/rpcpassword. // the bitcoin.conf. If it doesn't find one, it looks for rpcuser/rpcpassword.
func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string, func extractBitcoindRPCParams(networkName string,
string, error) { bitcoindConfigPath string) (string, string, string, string, error) {
// First, we'll open up the bitcoind configuration file found at the // First, we'll open up the bitcoind configuration file found at the
// target destination. // target destination.
@ -1403,7 +1409,7 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
} }
chainDir := "/" chainDir := "/"
switch activeNetParams.Params.Name { switch networkName {
case "testnet3": case "testnet3":
chainDir = "/testnet3/" chainDir = "/testnet3/"
case "testnet4": case "testnet4":

View File

@ -99,6 +99,8 @@ var (
} }
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10) _, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10) _, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
fundingNetParams = bitcoinTestNetParams
) )
type mockNotifier struct { type mockNotifier struct {
@ -282,7 +284,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
addr *lnwire.NetAddress, tempTestDir string, addr *lnwire.NetAddress, tempTestDir string,
options ...cfgOption) (*testNode, error) { options ...cfgOption) (*testNode, error) {
netParams := activeNetParams.Params netParams := fundingNetParams.Params
estimator := chainfee.NewStaticEstimator(62500, 0) estimator := chainfee.NewStaticEstimator(62500, 0)
chainNotifier := &mockNotifier{ chainNotifier := &mockNotifier{
@ -643,7 +645,7 @@ func fundChannel(t *testing.T, alice, bob *testNode, localFundingAmt,
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
subtractFees: subtractFees, subtractFees: subtractFees,
localFundingAmt: localFundingAmt, localFundingAmt: localFundingAmt,
pushAmt: lnwire.NewMSatFromSatoshis(pushAmt), pushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
@ -1567,7 +1569,7 @@ func TestFundingManagerPeerTimeoutAfterInitFunding(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000, localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
@ -1629,7 +1631,7 @@ func TestFundingManagerPeerTimeoutAfterFundingOpen(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000, localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
@ -1700,7 +1702,7 @@ func TestFundingManagerPeerTimeoutAfterFundingAccept(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000, localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
@ -2424,7 +2426,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: localAmt, localFundingAmt: localAmt,
pushAmt: lnwire.NewMSatFromSatoshis(pushAmt), pushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
private: false, private: false,
@ -2709,7 +2711,7 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 5000000, localFundingAmt: 5000000,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,
@ -2879,7 +2881,7 @@ func TestFundingManagerRejectPush(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000, localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(10), pushAmt: lnwire.NewMSatFromSatoshis(10),
private: true, private: true,
@ -2936,7 +2938,7 @@ func TestFundingManagerMaxConfs(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000, localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(10), pushAmt: lnwire.NewMSatFromSatoshis(10),
private: false, private: false,
@ -3218,7 +3220,7 @@ func TestWumboChannelConfig(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
initReq := &openChanReq{ initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(), targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash, chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: MaxFundingAmount, localFundingAmt: MaxFundingAmount,
pushAmt: lnwire.NewMSatFromSatoshis(0), pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false, private: false,

12
lnd.go
View File

@ -514,7 +514,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
towerDBDir := filepath.Join( towerDBDir := filepath.Join(
cfg.Watchtower.TowerDir, cfg.Watchtower.TowerDir,
cfg.registeredChains.PrimaryChain().String(), cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name), normalizeNetwork(cfg.ActiveNetParams.Name),
) )
towerDB, err := wtdb.OpenTowerDB(towerDBDir) towerDB, err := wtdb.OpenTowerDB(towerDBDir)
@ -552,7 +552,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
towerKeyDesc, activeChainControl.keyRing, towerKeyDesc, activeChainControl.keyRing,
), ),
PublishTx: activeChainControl.wallet.PublishTransaction, PublishTx: activeChainControl.wallet.PublishTransaction,
ChainHash: *activeNetParams.GenesisHash, ChainHash: *cfg.ActiveNetParams.GenesisHash,
} }
// If there is a tor controller (user wants auto hidden services), then // If there is a tor controller (user wants auto hidden services), then
@ -604,7 +604,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
// Set up an autopilot manager from the current config. This will be // Set up an autopilot manager from the current config. This will be
// used to manage the underlying autopilot agent, starting and stopping // used to manage the underlying autopilot agent, starting and stopping
// it at will. // it at will.
atplCfg, err := initAutoPilot(server, cfg.Autopilot, mainChain) atplCfg, err := initAutoPilot(server, cfg.Autopilot, mainChain, cfg.ActiveNetParams)
if err != nil { if err != nil {
err := fmt.Errorf("unable to initialize autopilot: %v", err) err := fmt.Errorf("unable to initialize autopilot: %v", err)
ltndLog.Error(err) ltndLog.Error(err)
@ -974,7 +974,7 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr,
cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath, cfg.AdminMacPath, cfg.ReadMacPath, cfg.InvoiceMacPath,
} }
pwService := walletunlocker.New( pwService := walletunlocker.New(
chainConfig.ChainDir, activeNetParams.Params, !cfg.SyncFreelist, chainConfig.ChainDir, cfg.ActiveNetParams.Params, !cfg.SyncFreelist,
macaroonFiles, macaroonFiles,
) )
lnrpc.RegisterWalletUnlockerServer(grpcServer, pwService) lnrpc.RegisterWalletUnlockerServer(grpcServer, pwService)
@ -1069,10 +1069,10 @@ func waitForWalletPassword(cfg *Config, restEndpoints []net.Addr,
} }
netDir := btcwallet.NetworkDir( netDir := btcwallet.NetworkDir(
chainConfig.ChainDir, activeNetParams.Params, chainConfig.ChainDir, cfg.ActiveNetParams.Params,
) )
loader := wallet.NewLoader( loader := wallet.NewLoader(
activeNetParams.Params, netDir, !cfg.SyncFreelist, cfg.ActiveNetParams.Params, netDir, !cfg.SyncFreelist,
recoveryWindow, recoveryWindow,
) )

View File

@ -219,7 +219,7 @@ type mockChainIO struct {
var _ lnwallet.BlockChainIO = (*mockChainIO)(nil) var _ lnwallet.BlockChainIO = (*mockChainIO)(nil)
func (m *mockChainIO) GetBestBlock() (*chainhash.Hash, int32, error) { func (m *mockChainIO) GetBestBlock() (*chainhash.Hash, int32, error) {
return activeNetParams.GenesisHash, m.bestHeight, nil return chaincfg.TestNet3Params.GenesisHash, m.bestHeight, nil
} }
func (*mockChainIO) GetUtxo(op *wire.OutPoint, _ []byte, func (*mockChainIO) GetUtxo(op *wire.OutPoint, _ []byte,

View File

@ -76,6 +76,7 @@ type chanController struct {
minConfs int32 minConfs int32
confTarget uint32 confTarget uint32
chanMinHtlcIn lnwire.MilliSatoshi chanMinHtlcIn lnwire.MilliSatoshi
netParams bitcoinNetParams
} }
// OpenChannel opens a channel to a target peer, with a capacity of the // OpenChannel opens a channel to a target peer, with a capacity of the
@ -97,7 +98,7 @@ func (c *chanController) OpenChannel(target *btcec.PublicKey,
// the funding workflow. // the funding workflow.
req := &openChanReq{ req := &openChanReq{
targetPubkey: target, targetPubkey: target,
chainHash: *activeNetParams.GenesisHash, chainHash: *c.netParams.GenesisHash,
subtractFees: true, subtractFees: true,
localFundingAmt: amt, localFundingAmt: amt,
pushAmt: 0, pushAmt: 0,
@ -141,7 +142,8 @@ var _ autopilot.ChannelController = (*chanController)(nil)
// interfaces needed to drive it won't be launched before the Manager's // interfaces needed to drive it won't be launched before the Manager's
// StartAgent method is called. // StartAgent method is called.
func initAutoPilot(svr *server, cfg *lncfg.AutoPilot, func initAutoPilot(svr *server, cfg *lncfg.AutoPilot,
chainCfg *lncfg.Chain) (*autopilot.ManagerCfg, error) { chainCfg *lncfg.Chain, netParams bitcoinNetParams) (*autopilot.ManagerCfg,
error) {
atplLog.Infof("Instantiating autopilot with active=%v, "+ atplLog.Infof("Instantiating autopilot with active=%v, "+
"max_channels=%d, allocation=%f, min_chan_size=%d, "+ "max_channels=%d, allocation=%f, min_chan_size=%d, "+
@ -181,6 +183,7 @@ func initAutoPilot(svr *server, cfg *lncfg.AutoPilot,
minConfs: cfg.MinConfs, minConfs: cfg.MinConfs,
confTarget: cfg.ConfTarget, confTarget: cfg.ConfTarget,
chanMinHtlcIn: chainCfg.MinHTLCIn, chanMinHtlcIn: chainCfg.MinHTLCIn,
netParams: netParams,
}, },
WalletBalance: func() (btcutil.Amount, error) { WalletBalance: func() (btcutil.Amount, error) {
return svr.cc.wallet.ConfirmedBalance(cfg.MinConfs) return svr.cc.wallet.ConfirmedBalance(cfg.MinConfs)
@ -206,7 +209,7 @@ func initAutoPilot(svr *server, cfg *lncfg.AutoPilot,
lnAddr := &lnwire.NetAddress{ lnAddr := &lnwire.NetAddress{
IdentityKey: target, IdentityKey: target,
ChainNet: activeNetParams.Net, ChainNet: netParams.Net,
} }
// We'll attempt to successively connect to each of the // We'll attempt to successively connect to each of the

View File

@ -556,7 +556,7 @@ func newRPCServer(cfg *Config, s *server, macService *macaroons.Service,
}, },
FindRoute: s.chanRouter.FindRoute, FindRoute: s.chanRouter.FindRoute,
MissionControl: s.missionControl, MissionControl: s.missionControl,
ActiveNetParams: activeNetParams.Params, ActiveNetParams: cfg.ActiveNetParams.Params,
Tower: s.controlTower, Tower: s.controlTower,
MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry, MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry,
DefaultFinalCltvDelta: uint16(cfg.Bitcoin.TimeLockDelta), DefaultFinalCltvDelta: uint16(cfg.Bitcoin.TimeLockDelta),
@ -580,7 +580,7 @@ func newRPCServer(cfg *Config, s *server, macService *macaroons.Service,
// TODO(roasbeef): extend sub-sever config to have both (local vs remote) DB // TODO(roasbeef): extend sub-sever config to have both (local vs remote) DB
err = subServerCgs.PopulateDependencies( err = subServerCgs.PopulateDependencies(
cfg, s.cc, cfg.networkDir, macService, atpl, invoiceRegistry, cfg, s.cc, cfg.networkDir, macService, atpl, invoiceRegistry,
s.htlcSwitch, activeNetParams.Params, s.chanRouter, s.htlcSwitch, cfg.ActiveNetParams.Params, s.chanRouter,
routerBackend, s.nodeSigner, s.remoteChanDB, s.sweeper, tower, routerBackend, s.nodeSigner, s.remoteChanDB, s.sweeper, tower,
s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures, s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures,
rpcsLog, rpcsLog,
@ -918,10 +918,12 @@ func (r *rpcServer) Stop() error {
// the outputs themselves. The passed map pairs up an address, to a desired // the outputs themselves. The passed map pairs up an address, to a desired
// output value amount. Each address is converted to its corresponding pkScript // output value amount. Each address is converted to its corresponding pkScript
// to be used within the constructed output(s). // to be used within the constructed output(s).
func addrPairsToOutputs(addrPairs map[string]int64) ([]*wire.TxOut, error) { func addrPairsToOutputs(addrPairs map[string]int64,
params *chaincfg.Params) ([]*wire.TxOut, error) {
outputs := make([]*wire.TxOut, 0, len(addrPairs)) outputs := make([]*wire.TxOut, 0, len(addrPairs))
for addr, amt := range addrPairs { for addr, amt := range addrPairs {
addr, err := btcutil.DecodeAddress(addr, activeNetParams.Params) addr, err := btcutil.DecodeAddress(addr, params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -989,7 +991,7 @@ func allowCORS(handler http.Handler, origins []string) http.Handler {
func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64, func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
feeRate chainfee.SatPerKWeight, label string) (*chainhash.Hash, error) { feeRate chainfee.SatPerKWeight, label string) (*chainhash.Hash, error) {
outputs, err := addrPairsToOutputs(paymentMap) outputs, err := addrPairsToOutputs(paymentMap, r.cfg.ActiveNetParams.Params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1036,7 +1038,7 @@ func (r *rpcServer) ListUnspent(ctx context.Context,
return nil, err return nil, err
} }
rpcUtxos, err := lnrpc.MarshalUtxos(utxos, activeNetParams.Params) rpcUtxos, err := lnrpc.MarshalUtxos(utxos, r.cfg.ActiveNetParams.Params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1060,7 +1062,7 @@ func (r *rpcServer) EstimateFee(ctx context.Context,
in *lnrpc.EstimateFeeRequest) (*lnrpc.EstimateFeeResponse, error) { in *lnrpc.EstimateFeeRequest) (*lnrpc.EstimateFeeResponse, error) {
// Create the list of outputs we are spending to. // Create the list of outputs we are spending to.
outputs, err := addrPairsToOutputs(in.AddrToAmount) outputs, err := addrPairsToOutputs(in.AddrToAmount, r.cfg.ActiveNetParams.Params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1131,16 +1133,18 @@ func (r *rpcServer) SendCoins(ctx context.Context,
// Decode the address receiving the coins, we need to check whether the // Decode the address receiving the coins, we need to check whether the
// address is valid for this network. // address is valid for this network.
targetAddr, err := btcutil.DecodeAddress(in.Addr, activeNetParams.Params) targetAddr, err := btcutil.DecodeAddress(
in.Addr, r.cfg.ActiveNetParams.Params,
)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Make the check on the decoded address according to the active network. // Make the check on the decoded address according to the active network.
if !targetAddr.IsForNet(activeNetParams.Params) { if !targetAddr.IsForNet(r.cfg.ActiveNetParams.Params) {
return nil, fmt.Errorf("address: %v is not valid for this "+ return nil, fmt.Errorf("address: %v is not valid for this "+
"network: %v", targetAddr.String(), "network: %v", targetAddr.String(),
activeNetParams.Params.Name) r.cfg.ActiveNetParams.Params.Name)
} }
// If the destination address parses to a valid pubkey, we assume the user // If the destination address parses to a valid pubkey, we assume the user
@ -1449,7 +1453,7 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
peerAddr := &lnwire.NetAddress{ peerAddr := &lnwire.NetAddress{
IdentityKey: pubKey, IdentityKey: pubKey,
Address: addr, Address: addr,
ChainNet: activeNetParams.Net, ChainNet: r.cfg.ActiveNetParams.Net,
} }
rpcsLog.Debugf("[connectpeer] requested connection to %x@%s", rpcsLog.Debugf("[connectpeer] requested connection to %x@%s",
@ -1812,7 +1816,9 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for funding tx", rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for funding tx",
int64(feeRate)) int64(feeRate))
script, err := parseUpfrontShutdownAddress(in.CloseAddress) script, err := parseUpfrontShutdownAddress(
in.CloseAddress, r.cfg.ActiveNetParams.Params,
)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing upfront shutdown: %v", return nil, fmt.Errorf("error parsing upfront shutdown: %v",
err) err)
@ -1823,7 +1829,7 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
// be used to consume updates of the state of the pending channel. // be used to consume updates of the state of the pending channel.
return &openChanReq{ return &openChanReq{
targetPubkey: nodePubKey, targetPubkey: nodePubKey,
chainHash: *activeNetParams.GenesisHash, chainHash: *r.cfg.ActiveNetParams.GenesisHash,
localFundingAmt: localFundingAmt, localFundingAmt: localFundingAmt,
pushAmt: lnwire.NewMSatFromSatoshis(remoteInitialBalance), pushAmt: lnwire.NewMSatFromSatoshis(remoteInitialBalance),
minHtlcIn: minHtlcIn, minHtlcIn: minHtlcIn,
@ -1986,13 +1992,15 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
// parseUpfrontShutdownScript attempts to parse an upfront shutdown address. // parseUpfrontShutdownScript attempts to parse an upfront shutdown address.
// If the address is empty, it returns nil. If it successfully decoded the // If the address is empty, it returns nil. If it successfully decoded the
// address, it returns a script that pays out to the address. // address, it returns a script that pays out to the address.
func parseUpfrontShutdownAddress(address string) (lnwire.DeliveryAddress, error) { func parseUpfrontShutdownAddress(address string,
params *chaincfg.Params) (lnwire.DeliveryAddress, error) {
if len(address) == 0 { if len(address) == 0 {
return nil, nil return nil, nil
} }
addr, err := btcutil.DecodeAddress( addr, err := btcutil.DecodeAddress(
address, activeNetParams.Params, address, params,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid address: %v", err) return nil, fmt.Errorf("invalid address: %v", err)
@ -2196,7 +2204,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
if len(in.DeliveryAddress) > 0 { if len(in.DeliveryAddress) > 0 {
// Decode the address provided. // Decode the address provided.
addr, err := btcutil.DecodeAddress( addr, err := btcutil.DecodeAddress(
in.DeliveryAddress, activeNetParams.Params, in.DeliveryAddress, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return fmt.Errorf("invalid delivery address: %v", err) return fmt.Errorf("invalid delivery address: %v", err)
@ -2437,7 +2445,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
"with current best block in the main chain: %v", err) "with current best block in the main chain: %v", err)
} }
network := normalizeNetwork(activeNetParams.Name) network := normalizeNetwork(r.cfg.ActiveNetParams.Name)
activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains()) activeChains := make([]*lnrpc.Chain, r.cfg.registeredChains.NumActiveChains())
for i, chain := range r.cfg.registeredChains.ActiveChains() { for i, chain := range r.cfg.registeredChains.ActiveChains() {
activeChains[i] = &lnrpc.Chain{ activeChains[i] = &lnrpc.Chain{
@ -2488,7 +2496,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
BlockHeight: uint32(bestHeight), BlockHeight: uint32(bestHeight),
BlockHash: bestHash.String(), BlockHash: bestHash.String(),
SyncedToChain: isSynced, SyncedToChain: isSynced,
Testnet: isTestnet(&activeNetParams), Testnet: isTestnet(&r.cfg.ActiveNetParams),
Chains: activeChains, Chains: activeChains,
Uris: uris, Uris: uris,
Alias: nodeAnn.Alias.String(), Alias: nodeAnn.Alias.String(),
@ -3432,7 +3440,7 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
if len(dbChannel.LocalShutdownScript) > 0 { if len(dbChannel.LocalShutdownScript) > 0 {
_, addresses, _, err := txscript.ExtractPkScriptAddrs( _, addresses, _, err := txscript.ExtractPkScriptAddrs(
dbChannel.LocalShutdownScript, activeNetParams.Params, dbChannel.LocalShutdownScript, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -3552,8 +3560,7 @@ func (r *rpcServer) createRPCClosedChannel(
} }
reports, err := r.server.remoteChanDB.FetchChannelReports( reports, err := r.server.remoteChanDB.FetchChannelReports(
*r.cfg.ActiveNetParams.GenesisHash, &dbChannel.ChanPoint,
*activeNetParams.GenesisHash, &dbChannel.ChanPoint,
) )
switch err { switch err {
// If the channel does not have its resolver outcomes stored, // If the channel does not have its resolver outcomes stored,
@ -4009,7 +4016,7 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
// attempt to decode it, populating the payment accordingly. // attempt to decode it, populating the payment accordingly.
if rpcPayReq.PaymentRequest != "" { if rpcPayReq.PaymentRequest != "" {
payReq, err := zpay32.Decode( payReq, err := zpay32.Decode(
rpcPayReq.PaymentRequest, activeNetParams.Params, rpcPayReq.PaymentRequest, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return payIntent, err return payIntent, err
@ -4526,7 +4533,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
addInvoiceCfg := &invoicesrpc.AddInvoiceConfig{ addInvoiceCfg := &invoicesrpc.AddInvoiceConfig{
AddInvoice: r.server.invoices.AddInvoice, AddInvoice: r.server.invoices.AddInvoice,
IsChannelActive: r.server.htlcSwitch.HasActiveLink, IsChannelActive: r.server.htlcSwitch.HasActiveLink,
ChainParams: activeNetParams.Params, ChainParams: r.cfg.ActiveNetParams.Params,
NodeSigner: r.server.nodeSigner, NodeSigner: r.server.nodeSigner,
DefaultCLTVExpiry: defaultDelta, DefaultCLTVExpiry: defaultDelta,
ChanDB: r.server.remoteChanDB, ChanDB: r.server.remoteChanDB,
@ -4615,7 +4622,7 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
})) }))
rpcInvoice, err := invoicesrpc.CreateRPCInvoice( rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
&invoice, activeNetParams.Params, &invoice, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -4656,8 +4663,9 @@ func (r *rpcServer) ListInvoices(ctx context.Context,
LastIndexOffset: invoiceSlice.LastIndexOffset, LastIndexOffset: invoiceSlice.LastIndexOffset,
} }
for i, invoice := range invoiceSlice.Invoices { for i, invoice := range invoiceSlice.Invoices {
invoice := invoice
resp.Invoices[i], err = invoicesrpc.CreateRPCInvoice( resp.Invoices[i], err = invoicesrpc.CreateRPCInvoice(
&invoice, activeNetParams.Params, &invoice, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -4684,7 +4692,7 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
select { select {
case newInvoice := <-invoiceClient.NewInvoices: case newInvoice := <-invoiceClient.NewInvoices:
rpcInvoice, err := invoicesrpc.CreateRPCInvoice( rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
newInvoice, activeNetParams.Params, newInvoice, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return err return err
@ -4696,7 +4704,7 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
case settledInvoice := <-invoiceClient.SettledInvoices: case settledInvoice := <-invoiceClient.SettledInvoices:
rpcInvoice, err := invoicesrpc.CreateRPCInvoice( rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
settledInvoice, activeNetParams.Params, settledInvoice, r.cfg.ActiveNetParams.Params,
) )
if err != nil { if err != nil {
return err return err
@ -5463,7 +5471,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
// Fist we'll attempt to decode the payment request string, if the // Fist we'll attempt to decode the payment request string, if the
// request is invalid or the checksum doesn't match, then we'll exit // request is invalid or the checksum doesn't match, then we'll exit
// here with an error. // here with an error.
payReq, err := zpay32.Decode(req.PayReq, activeNetParams.Params) payReq, err := zpay32.Decode(req.PayReq, r.cfg.ActiveNetParams.Params)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

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