Merge pull request #4505 from Crypt-iQ/activeNet_cleanup_0803

lnd: removing activeNetParams global, passed around instead via configs
This commit is contained in:
Conner Fromknecht 2020-08-20 12:59:15 -07:00 committed by GitHub
commit d04df11c44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 105 additions and 92 deletions

@ -10,10 +10,6 @@ import (
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
// corresponding RPC port of a daemon running on the particular network.
type bitcoinNetParams struct {

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

@ -274,6 +274,9 @@ type Config struct {
// network. This path will hold the files related to each different
// network.
networkDir string
// ActiveNetParams contains parameters of the target chain.
ActiveNetParams bitcoinNetParams
}
// DefaultConfig returns all default values for the Config struct.
@ -380,6 +383,7 @@ func DefaultConfig() Config {
LogWriter: build.NewRotatingLogWriter(),
DB: lncfg.DefaultDB(),
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
// temporary hack, we'll mutate the default net params for
// bitcoin with the litecoin specific information.
applyLitecoinParams(&activeNetParams, &ltcParams)
applyLitecoinParams(&cfg.ActiveNetParams, &ltcParams)
switch cfg.Litecoin.Node {
case "ltcd":
err := parseRPCParams(cfg.Litecoin, cfg.LtcdMode,
litecoinChain, funcName)
litecoinChain, funcName, cfg.ActiveNetParams)
if err != nil {
err := fmt.Errorf("unable to load RPC "+
"credentials for ltcd: %v", err)
@ -753,7 +757,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
"support simnet", funcName)
}
err := parseRPCParams(cfg.Litecoin, cfg.LitecoindMode,
litecoinChain, funcName)
litecoinChain, funcName, cfg.ActiveNetParams)
if err != nil {
err := fmt.Errorf("unable to load RPC "+
"credentials for litecoind: %v", err)
@ -781,19 +785,19 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
numNets := 0
if cfg.Bitcoin.MainNet {
numNets++
activeNetParams = bitcoinMainNetParams
cfg.ActiveNetParams = bitcoinMainNetParams
}
if cfg.Bitcoin.TestNet3 {
numNets++
activeNetParams = bitcoinTestNetParams
cfg.ActiveNetParams = bitcoinTestNetParams
}
if cfg.Bitcoin.RegTest {
numNets++
activeNetParams = bitcoinRegTestNetParams
cfg.ActiveNetParams = bitcoinRegTestNetParams
}
if cfg.Bitcoin.SimNet {
numNets++
activeNetParams = bitcoinSimNetParams
cfg.ActiveNetParams = bitcoinSimNetParams
}
if numNets > 1 {
str := "%s: The mainnet, testnet, regtest, and " +
@ -822,6 +826,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
case "btcd":
err := parseRPCParams(
cfg.Bitcoin, cfg.BtcdMode, bitcoinChain, funcName,
cfg.ActiveNetParams,
)
if err != nil {
err := fmt.Errorf("unable to load RPC "+
@ -836,6 +841,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
err := parseRPCParams(
cfg.Bitcoin, cfg.BitcoindMode, bitcoinChain, funcName,
cfg.ActiveNetParams,
)
if err != nil {
err := fmt.Errorf("unable to load RPC "+
@ -913,7 +919,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
cfg.networkDir = filepath.Join(
cfg.DataDir, defaultChainSubDirname,
cfg.registeredChains.PrimaryChain().String(),
normalizeNetwork(activeNetParams.Name),
normalizeNetwork(cfg.ActiveNetParams.Name),
)
// 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.
cfg.LogDir = filepath.Join(cfg.LogDir,
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
// run into a panic later on.
@ -1135,11 +1141,11 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
func (c *Config) localDatabaseDir() string {
return filepath.Join(c.DataDir,
defaultGraphSubDirname,
normalizeNetwork(activeNetParams.Name))
normalizeNetwork(c.ActiveNetParams.Name))
}
func (c *Config) networkName() string {
return normalizeNetwork(activeNetParams.Name)
return normalizeNetwork(c.ActiveNetParams.Name)
}
// 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,
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
// 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":
nConf := nodeConfig.(*lncfg.Bitcoind)
rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err :=
extractBitcoindRPCParams(confFile)
extractBitcoindRPCParams(netParams.Params.Name, confFile)
if err != nil {
return fmt.Errorf("unable to extract RPC credentials:"+
" %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
}
// 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
// location of bitcoind's bitcoin.conf on the target system. The routine looks
// 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.
func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string,
string, error) {
func extractBitcoindRPCParams(networkName string,
bitcoindConfigPath string) (string, string, string, string, error) {
// First, we'll open up the bitcoind configuration file found at the
// target destination.
@ -1403,7 +1409,7 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
}
chainDir := "/"
switch activeNetParams.Params.Name {
switch networkName {
case "testnet3":
chainDir = "/testnet3/"
case "testnet4":

@ -99,6 +99,8 @@ var (
}
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
fundingNetParams = bitcoinTestNetParams
)
type mockNotifier struct {
@ -282,7 +284,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
addr *lnwire.NetAddress, tempTestDir string,
options ...cfgOption) (*testNode, error) {
netParams := activeNetParams.Params
netParams := fundingNetParams.Params
estimator := chainfee.NewStaticEstimator(62500, 0)
chainNotifier := &mockNotifier{
@ -649,7 +651,7 @@ func fundChannel(t *testing.T, alice, bob *testNode, localFundingAmt,
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
subtractFees: subtractFees,
localFundingAmt: localFundingAmt,
pushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
@ -1573,7 +1575,7 @@ func TestFundingManagerPeerTimeoutAfterInitFunding(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false,
@ -1635,7 +1637,7 @@ func TestFundingManagerPeerTimeoutAfterFundingOpen(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false,
@ -1706,7 +1708,7 @@ func TestFundingManagerPeerTimeoutAfterFundingAccept(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false,
@ -2430,7 +2432,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: localAmt,
pushAmt: lnwire.NewMSatFromSatoshis(pushAmt),
private: false,
@ -2715,7 +2717,7 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 5000000,
pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false,
@ -2885,7 +2887,7 @@ func TestFundingManagerRejectPush(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(10),
private: true,
@ -2942,7 +2944,7 @@ func TestFundingManagerMaxConfs(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: 500000,
pushAmt: lnwire.NewMSatFromSatoshis(10),
private: false,
@ -3224,7 +3226,7 @@ func TestWumboChannelConfig(t *testing.T) {
errChan := make(chan error, 1)
initReq := &openChanReq{
targetPubkey: bob.privKey.PubKey(),
chainHash: *activeNetParams.GenesisHash,
chainHash: *fundingNetParams.GenesisHash,
localFundingAmt: MaxFundingAmount,
pushAmt: lnwire.NewMSatFromSatoshis(0),
private: false,

12
lnd.go

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

@ -219,7 +219,7 @@ type mockChainIO struct {
var _ lnwallet.BlockChainIO = (*mockChainIO)(nil)
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,

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

@ -556,7 +556,7 @@ func newRPCServer(cfg *Config, s *server, macService *macaroons.Service,
},
FindRoute: s.chanRouter.FindRoute,
MissionControl: s.missionControl,
ActiveNetParams: activeNetParams.Params,
ActiveNetParams: cfg.ActiveNetParams.Params,
Tower: s.controlTower,
MaxTotalTimelock: cfg.MaxOutgoingCltvExpiry,
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
err = subServerCgs.PopulateDependencies(
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,
s.towerClient, cfg.net.ResolveTCPAddr, genInvoiceFeatures,
rpcsLog,
@ -918,10 +918,12 @@ func (r *rpcServer) Stop() error {
// the outputs themselves. The passed map pairs up an address, to a desired
// output value amount. Each address is converted to its corresponding pkScript
// 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))
for addr, amt := range addrPairs {
addr, err := btcutil.DecodeAddress(addr, activeNetParams.Params)
addr, err := btcutil.DecodeAddress(addr, params)
if err != nil {
return nil, err
}
@ -989,7 +991,7 @@ func allowCORS(handler http.Handler, origins []string) http.Handler {
func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64,
feeRate chainfee.SatPerKWeight, label string) (*chainhash.Hash, error) {
outputs, err := addrPairsToOutputs(paymentMap)
outputs, err := addrPairsToOutputs(paymentMap, r.cfg.ActiveNetParams.Params)
if err != nil {
return nil, err
}
@ -1036,7 +1038,7 @@ func (r *rpcServer) ListUnspent(ctx context.Context,
return nil, err
}
rpcUtxos, err := lnrpc.MarshalUtxos(utxos, activeNetParams.Params)
rpcUtxos, err := lnrpc.MarshalUtxos(utxos, r.cfg.ActiveNetParams.Params)
if err != nil {
return nil, err
}
@ -1060,7 +1062,7 @@ func (r *rpcServer) EstimateFee(ctx context.Context,
in *lnrpc.EstimateFeeRequest) (*lnrpc.EstimateFeeResponse, error) {
// 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 {
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
// 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 {
return nil, err
}
// 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 "+
"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
@ -1449,7 +1453,7 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
peerAddr := &lnwire.NetAddress{
IdentityKey: pubKey,
Address: addr,
ChainNet: activeNetParams.Net,
ChainNet: r.cfg.ActiveNetParams.Net,
}
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",
int64(feeRate))
script, err := parseUpfrontShutdownAddress(in.CloseAddress)
script, err := parseUpfrontShutdownAddress(
in.CloseAddress, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return nil, fmt.Errorf("error parsing upfront shutdown: %v",
err)
@ -1823,7 +1829,7 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
// be used to consume updates of the state of the pending channel.
return &openChanReq{
targetPubkey: nodePubKey,
chainHash: *activeNetParams.GenesisHash,
chainHash: *r.cfg.ActiveNetParams.GenesisHash,
localFundingAmt: localFundingAmt,
pushAmt: lnwire.NewMSatFromSatoshis(remoteInitialBalance),
minHtlcIn: minHtlcIn,
@ -1986,13 +1992,15 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
// parseUpfrontShutdownScript attempts to parse an upfront shutdown address.
// If the address is empty, it returns nil. If it successfully decoded the
// 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 {
return nil, nil
}
addr, err := btcutil.DecodeAddress(
address, activeNetParams.Params,
address, params,
)
if err != nil {
return nil, fmt.Errorf("invalid address: %v", err)
@ -2209,7 +2217,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
if len(in.DeliveryAddress) > 0 {
// Decode the address provided.
addr, err := btcutil.DecodeAddress(
in.DeliveryAddress, activeNetParams.Params,
in.DeliveryAddress, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return fmt.Errorf("invalid delivery address: %v", err)
@ -2450,7 +2458,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
"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())
for i, chain := range r.cfg.registeredChains.ActiveChains() {
activeChains[i] = &lnrpc.Chain{
@ -2501,7 +2509,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
BlockHeight: uint32(bestHeight),
BlockHash: bestHash.String(),
SyncedToChain: isSynced,
Testnet: isTestnet(&activeNetParams),
Testnet: isTestnet(&r.cfg.ActiveNetParams),
Chains: activeChains,
Uris: uris,
Alias: nodeAnn.Alias.String(),
@ -3445,7 +3453,7 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph,
if len(dbChannel.LocalShutdownScript) > 0 {
_, addresses, _, err := txscript.ExtractPkScriptAddrs(
dbChannel.LocalShutdownScript, activeNetParams.Params,
dbChannel.LocalShutdownScript, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return nil, err
@ -3565,8 +3573,7 @@ func (r *rpcServer) createRPCClosedChannel(
}
reports, err := r.server.remoteChanDB.FetchChannelReports(
*activeNetParams.GenesisHash, &dbChannel.ChanPoint,
*r.cfg.ActiveNetParams.GenesisHash, &dbChannel.ChanPoint,
)
switch err {
// If the channel does not have its resolver outcomes stored,
@ -4022,7 +4029,7 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
// attempt to decode it, populating the payment accordingly.
if rpcPayReq.PaymentRequest != "" {
payReq, err := zpay32.Decode(
rpcPayReq.PaymentRequest, activeNetParams.Params,
rpcPayReq.PaymentRequest, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return payIntent, err
@ -4539,7 +4546,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
addInvoiceCfg := &invoicesrpc.AddInvoiceConfig{
AddInvoice: r.server.invoices.AddInvoice,
IsChannelActive: r.server.htlcSwitch.HasActiveLink,
ChainParams: activeNetParams.Params,
ChainParams: r.cfg.ActiveNetParams.Params,
NodeSigner: r.server.nodeSigner,
DefaultCLTVExpiry: defaultDelta,
ChanDB: r.server.remoteChanDB,
@ -4628,7 +4635,7 @@ func (r *rpcServer) LookupInvoice(ctx context.Context,
}))
rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
&invoice, activeNetParams.Params,
&invoice, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return nil, err
@ -4669,8 +4676,9 @@ func (r *rpcServer) ListInvoices(ctx context.Context,
LastIndexOffset: invoiceSlice.LastIndexOffset,
}
for i, invoice := range invoiceSlice.Invoices {
invoice := invoice
resp.Invoices[i], err = invoicesrpc.CreateRPCInvoice(
&invoice, activeNetParams.Params,
&invoice, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return nil, err
@ -4697,7 +4705,7 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
select {
case newInvoice := <-invoiceClient.NewInvoices:
rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
newInvoice, activeNetParams.Params,
newInvoice, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return err
@ -4709,7 +4717,7 @@ func (r *rpcServer) SubscribeInvoices(req *lnrpc.InvoiceSubscription,
case settledInvoice := <-invoiceClient.SettledInvoices:
rpcInvoice, err := invoicesrpc.CreateRPCInvoice(
settledInvoice, activeNetParams.Params,
settledInvoice, r.cfg.ActiveNetParams.Params,
)
if err != nil {
return err
@ -5476,7 +5484,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
// 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
// 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 {
return nil, err
}

@ -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),
@ -1224,7 +1222,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,
@ -1754,7 +1752,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.
@ -2815,7 +2813,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