chainreg: add Config, move chainparams.go

Creates a Config that initializes the chainregistry struct in the
lnd package. Also moves all of chainparams.go to the chainreg
package.
This commit is contained in:
Eugene 2020-09-29 10:00:19 -07:00 committed by eugene
parent 933b959aa8
commit f4fe76aaf1
8 changed files with 189 additions and 93 deletions

View File

@ -1,4 +1,4 @@
package lnd package chainreg
import ( import (
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"
@ -10,91 +10,93 @@ import (
litecoinWire "github.com/ltcsuite/ltcd/wire" litecoinWire "github.com/ltcsuite/ltcd/wire"
) )
// 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 {
*bitcoinCfg.Params *bitcoinCfg.Params
rpcPort string RPCPort string
CoinType uint32 CoinType uint32
} }
// litecoinNetParams couples the p2p parameters of a network with the // LitecoinNetParams 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 litecoinNetParams struct { type LitecoinNetParams struct {
*litecoinCfg.Params *litecoinCfg.Params
rpcPort string RPCPort string
CoinType uint32 CoinType uint32
} }
// bitcoinTestNetParams contains parameters specific to the 3rd version of the // BitcoinTestNetParams contains parameters specific to the 3rd version of the
// test network. // test network.
var bitcoinTestNetParams = bitcoinNetParams{ var BitcoinTestNetParams = BitcoinNetParams{
Params: &bitcoinCfg.TestNet3Params, Params: &bitcoinCfg.TestNet3Params,
rpcPort: "18334", RPCPort: "18334",
CoinType: keychain.CoinTypeTestnet, CoinType: keychain.CoinTypeTestnet,
} }
// bitcoinMainNetParams contains parameters specific to the current Bitcoin // BitcoinMainNetParams contains parameters specific to the current Bitcoin
// mainnet. // mainnet.
var bitcoinMainNetParams = bitcoinNetParams{ var BitcoinMainNetParams = BitcoinNetParams{
Params: &bitcoinCfg.MainNetParams, Params: &bitcoinCfg.MainNetParams,
rpcPort: "8334", RPCPort: "8334",
CoinType: keychain.CoinTypeBitcoin, CoinType: keychain.CoinTypeBitcoin,
} }
// bitcoinSimNetParams contains parameters specific to the simulation test // BitcoinSimNetParams contains parameters specific to the simulation test
// network. // network.
var bitcoinSimNetParams = bitcoinNetParams{ var BitcoinSimNetParams = BitcoinNetParams{
Params: &bitcoinCfg.SimNetParams, Params: &bitcoinCfg.SimNetParams,
rpcPort: "18556", RPCPort: "18556",
CoinType: keychain.CoinTypeTestnet, CoinType: keychain.CoinTypeTestnet,
} }
// litecoinSimNetParams contains parameters specific to the simulation test // LitecoinSimNetParams contains parameters specific to the simulation test
// network. // network.
var litecoinSimNetParams = litecoinNetParams{ var LitecoinSimNetParams = LitecoinNetParams{
Params: &litecoinCfg.SimNetParams,
rpcPort: "18556",
CoinType: keychain.CoinTypeTestnet,
}
// litecoinTestNetParams contains parameters specific to the 4th version of the
// test network.
var litecoinTestNetParams = litecoinNetParams{
Params: &litecoinCfg.TestNet4Params, Params: &litecoinCfg.TestNet4Params,
rpcPort: "19334", RPCPort: "18556",
CoinType: keychain.CoinTypeTestnet, CoinType: keychain.CoinTypeTestnet,
} }
// litecoinMainNetParams contains the parameters specific to the current // LitecoinTestNetParams contains parameters specific to the 4th version of the
// test network.
var LitecoinTestNetParams = LitecoinNetParams{
Params: &litecoinCfg.TestNet4Params,
RPCPort: "19334",
CoinType: keychain.CoinTypeTestnet,
}
// LitecoinMainNetParams contains the parameters specific to the current
// Litecoin mainnet. // Litecoin mainnet.
var litecoinMainNetParams = litecoinNetParams{ var LitecoinMainNetParams = LitecoinNetParams{
Params: &litecoinCfg.MainNetParams, Params: &litecoinCfg.MainNetParams,
rpcPort: "9334", RPCPort: "9334",
CoinType: keychain.CoinTypeLitecoin, CoinType: keychain.CoinTypeLitecoin,
} }
// litecoinRegTestNetParams contains parameters specific to a local litecoin // LitecoinRegTestNetParams contains parameters specific to a local litecoin
// regtest network. // regtest network.
var litecoinRegTestNetParams = litecoinNetParams{ var LitecoinRegTestNetParams = LitecoinNetParams{
Params: &litecoinCfg.RegressionNetParams, Params: &litecoinCfg.RegressionNetParams,
rpcPort: "18334", RPCPort: "18334",
CoinType: keychain.CoinTypeTestnet, CoinType: keychain.CoinTypeTestnet,
} }
// bitcoinRegTestNetParams contains parameters specific to a local bitcoin // BitcoinRegTestNetParams contains parameters specific to a local bitcoin
// regtest network. // regtest network.
var bitcoinRegTestNetParams = bitcoinNetParams{ var BitcoinRegTestNetParams = BitcoinNetParams{
Params: &bitcoinCfg.RegressionNetParams, Params: &bitcoinCfg.RegressionNetParams,
rpcPort: "18334", RPCPort: "18334",
CoinType: keychain.CoinTypeTestnet, CoinType: keychain.CoinTypeTestnet,
} }
// applyLitecoinParams applies the relevant chain configuration parameters that // ApplyLitecoinParams applies the relevant chain configuration parameters that
// differ for litecoin to the chain parameters typed for btcsuite derivation. // differ for litecoin to the chain parameters typed for btcsuite derivation.
// This function is used in place of using something like interface{} to // This function is used in place of using something like interface{} to
// abstract over _which_ chain (or fork) the parameters are for. // abstract over _which_ chain (or fork) the parameters are for.
func applyLitecoinParams(params *bitcoinNetParams, litecoinParams *litecoinNetParams) { func ApplyLitecoinParams(params *BitcoinNetParams,
litecoinParams *LitecoinNetParams) {
params.Name = litecoinParams.Name params.Name = litecoinParams.Name
params.Net = bitcoinWire.BitcoinNet(litecoinParams.Net) params.Net = bitcoinWire.BitcoinNet(litecoinParams.Net)
params.DefaultPort = litecoinParams.DefaultPort params.DefaultPort = litecoinParams.DefaultPort
@ -127,13 +129,13 @@ func applyLitecoinParams(params *bitcoinNetParams, litecoinParams *litecoinNetPa
} }
params.Checkpoints = checkPoints params.Checkpoints = checkPoints
params.rpcPort = litecoinParams.rpcPort params.RPCPort = litecoinParams.RPCPort
params.CoinType = litecoinParams.CoinType params.CoinType = litecoinParams.CoinType
} }
// isTestnet tests if the given params correspond to a testnet // IsTestnet tests if the givern params correspond to a testnet
// parameter configuration. // parameter configuration.
func isTestnet(params *bitcoinNetParams) bool { func IsTestnet(params *BitcoinNetParams) bool {
switch params.Params.Net { switch params.Params.Net {
case bitcoinWire.TestNet3, bitcoinWire.BitcoinNet(litecoinWire.TestNet4): case bitcoinWire.TestNet3, bitcoinWire.BitcoinNet(litecoinWire.TestNet4):
return true return true

78
chainreg/chainregistry.go Normal file
View File

@ -0,0 +1,78 @@
package chainreg
import (
"time"
"github.com/btcsuite/btcwallet/wallet"
"github.com/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lncfg"
)
// Config houses necessary fields that a chainControl instance needs to
// function.
type Config struct {
// Bitcoin defines settings for the Bitcoin chain.
Bitcoin *lncfg.Chain
// Litecoin defines settings for the Litecoin chain.
Litecoin *lncfg.Chain
// PrimaryChain is a function that returns our primary chain via its
// ChainCode.
PrimaryChain func() ChainCode
// HeightHintCacheQueryDisable is a boolean that disables height hint
// queries if true.
HeightHintCacheQueryDisable bool
// NeutrinoMode defines settings for connecting to a neutrino light-client.
NeutrinoMode *lncfg.Neutrino
// BitcoindMode defines settings for connecting to a bitcoind node.
BitcoindMode *lncfg.Bitcoind
// LitecoindMode defines settings for connecting to a litecoind node.
LitecoindMode *lncfg.Bitcoind
// BtcdMode defines settings for connecting to a btcd node.
BtcdMode *lncfg.Btcd
// LtcdMode defines settings for connecting to an ltcd node.
LtcdMode *lncfg.Btcd
// LocalChanDB is a pointer to the local backing channel database.
LocalChanDB *channeldb.DB
// RemoteChanDB is a pointer to the remote backing channel database.
RemoteChanDB *channeldb.DB
// PrivateWalletPw is the private wallet password to the underlying
// btcwallet instance.
PrivateWalletPw []byte
// PublicWalletPw is the public wallet password to the underlying btcwallet
// instance.
PublicWalletPw []byte
// Birthday specifies the time the wallet was initially created.
Birthday time.Time
// RecoveryWindow specifies the address look-ahead for which to scan when
// restoring a wallet.
RecoveryWindow uint32
// Wallet is a pointer to the backing wallet instance.
Wallet *wallet.Wallet
// NeutrinoCS is a pointer to a neutrino ChainService. Must be non-nil if
// using neutrino.
NeutrinoCS *neutrino.ChainService
// ActiveNetParams details the current chain we are on.
ActiveNetParams BitcoinNetParams
// FeeURL defines the URL for fee estimation we will use. This field is
// optional.
FeeURL string
}

View File

@ -16,8 +16,6 @@ import (
"github.com/btcsuite/btcd/rpcclient" "github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwallet/chain" "github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/wallet"
"github.com/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify" "github.com/lightningnetwork/lnd/chainntnfs/bitcoindnotify"
"github.com/lightningnetwork/lnd/chainntnfs/btcdnotify" "github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
@ -130,29 +128,26 @@ type chainControl struct {
minHtlcIn lnwire.MilliSatoshi minHtlcIn lnwire.MilliSatoshi
} }
// newChainControlFromConfig attempts to create a chainControl instance // newChainControl attempts to create a chainControl instance according
// according to the parameters in the passed lnd configuration. Currently three // to the parameters in the passed configuration. Currently three
// branches of chainControl instances exist: one backed by a running btcd // branches of chainControl instances exist: one backed by a running btcd
// full-node, another backed by a running bitcoind full-node, and the other // full-node, another backed by a running bitcoind full-node, and the other
// backed by a running neutrino light client instance. When running with a // backed by a running neutrino light client instance. When running with a
// neutrino light client instance, `neutrinoCS` must be non-nil. // neutrino light client instance, `neutrinoCS` must be non-nil.
func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB, func newChainControl(cfg *chainreg.Config) (*chainControl, error) {
privateWalletPw, publicWalletPw []byte, birthday time.Time,
recoveryWindow uint32, wallet *wallet.Wallet,
neutrinoCS *neutrino.ChainService) (*chainControl, error) {
// Set the RPC config from the "home" chain. Multi-chain isn't yet // Set the RPC config from the "home" chain. Multi-chain isn't yet
// active, so we'll restrict usage to a particular chain for now. // active, so we'll restrict usage to a particular chain for now.
homeChainConfig := cfg.Bitcoin homeChainConfig := cfg.Bitcoin
if cfg.registeredChains.PrimaryChain() == chainreg.LitecoinChain { if cfg.PrimaryChain() == chainreg.LitecoinChain {
homeChainConfig = cfg.Litecoin homeChainConfig = cfg.Litecoin
} }
ltndLog.Infof("Primary chain is set to: %v", ltndLog.Infof("Primary chain is set to: %v",
cfg.registeredChains.PrimaryChain()) cfg.PrimaryChain())
cc := &chainControl{} cc := &chainControl{}
switch cfg.registeredChains.PrimaryChain() { switch cfg.PrimaryChain() {
case chainreg.BitcoinChain: case chainreg.BitcoinChain:
cc.routingPolicy = htlcswitch.ForwardingPolicy{ cc.routingPolicy = htlcswitch.ForwardingPolicy{
MinHTLCOut: cfg.Bitcoin.MinHTLCOut, MinHTLCOut: cfg.Bitcoin.MinHTLCOut,
@ -178,18 +173,18 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
) )
default: default:
return nil, fmt.Errorf("default routing policy for chain %v is "+ return nil, fmt.Errorf("default routing policy for chain %v is "+
"unknown", cfg.registeredChains.PrimaryChain()) "unknown", cfg.PrimaryChain())
} }
walletConfig := &btcwallet.Config{ walletConfig := &btcwallet.Config{
PrivatePass: privateWalletPw, PrivatePass: cfg.PrivateWalletPw,
PublicPass: publicWalletPw, PublicPass: cfg.PublicWalletPw,
Birthday: birthday, Birthday: cfg.Birthday,
RecoveryWindow: recoveryWindow, RecoveryWindow: cfg.RecoveryWindow,
DataDir: homeChainConfig.ChainDir, DataDir: homeChainConfig.ChainDir,
NetParams: cfg.ActiveNetParams.Params, NetParams: cfg.ActiveNetParams.Params,
CoinType: cfg.ActiveNetParams.CoinType, CoinType: cfg.ActiveNetParams.CoinType,
Wallet: wallet, Wallet: cfg.Wallet,
} }
var err error var err error
@ -202,7 +197,9 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
} }
// Initialize the height hint cache within the chain directory. // Initialize the height hint cache within the chain directory.
hintCache, err := chainntnfs.NewHeightHintCache(heightHintCacheConfig, localDB) hintCache, err := chainntnfs.NewHeightHintCache(
heightHintCacheConfig, cfg.LocalChanDB,
)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to initialize height hint "+ return nil, fmt.Errorf("unable to initialize height hint "+
"cache: %v", err) "cache: %v", err)
@ -217,9 +214,9 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// along with the wallet's ChainSource, which are all backed by // along with the wallet's ChainSource, which are all backed by
// the neutrino light client. // the neutrino light client.
cc.chainNotifier = neutrinonotify.New( cc.chainNotifier = neutrinonotify.New(
neutrinoCS, hintCache, hintCache, cfg.NeutrinoCS, hintCache, hintCache,
) )
cc.chainView, err = chainview.NewCfFilteredChainView(neutrinoCS) cc.chainView, err = chainview.NewCfFilteredChainView(cfg.NeutrinoCS)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -236,7 +233,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
} }
walletConfig.ChainSource = chain.NewNeutrinoClient( walletConfig.ChainSource = chain.NewNeutrinoClient(
cfg.ActiveNetParams.Params, neutrinoCS, cfg.ActiveNetParams.Params, cfg.NeutrinoCS,
) )
case "bitcoind", "litecoind": case "bitcoind", "litecoind":
@ -260,7 +257,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(cfg.ActiveNetParams.rpcPort) rpcPort, err := strconv.Atoi(cfg.ActiveNetParams.RPCPort)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -395,7 +392,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,
cfg.ActiveNetParams.rpcPort) cfg.ActiveNetParams.RPCPort)
} }
btcdUser := btcdMode.RPCUser btcdUser := btcdMode.RPCUser
@ -494,7 +491,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// Select the default channel constraints for the primary chain. // Select the default channel constraints for the primary chain.
channelConstraints := defaultBtcChannelConstraints channelConstraints := defaultBtcChannelConstraints
if cfg.registeredChains.PrimaryChain() == chainreg.LitecoinChain { if cfg.PrimaryChain() == chainreg.LitecoinChain {
channelConstraints = defaultLtcChannelConstraints channelConstraints = defaultLtcChannelConstraints
} }
@ -506,7 +503,7 @@ func newChainControlFromConfig(cfg *Config, localDB, remoteDB *channeldb.DB,
// Create, and start the lnwallet, which handles the core payment // Create, and start the lnwallet, which handles the core payment
// channel logic, and exposes control via proxy state machines. // channel logic, and exposes control via proxy state machines.
walletCfg := lnwallet.Config{ walletCfg := lnwallet.Config{
Database: remoteDB, Database: cfg.RemoteChanDB,
Notifier: cc.chainNotifier, Notifier: cc.chainNotifier,
WalletController: wc, WalletController: wc,
Signer: cc.signer, Signer: cc.signer,
@ -622,7 +619,7 @@ type chainRegistry struct {
sync.RWMutex sync.RWMutex
activeChains map[chainreg.ChainCode]*chainControl activeChains map[chainreg.ChainCode]*chainControl
netParams map[chainreg.ChainCode]*bitcoinNetParams netParams map[chainreg.ChainCode]*chainreg.BitcoinNetParams
primaryChain chainreg.ChainCode primaryChain chainreg.ChainCode
} }
@ -631,7 +628,7 @@ type chainRegistry struct {
func newChainRegistry() *chainRegistry { func newChainRegistry() *chainRegistry {
return &chainRegistry{ return &chainRegistry{
activeChains: make(map[chainreg.ChainCode]*chainControl), activeChains: make(map[chainreg.ChainCode]*chainControl),
netParams: make(map[chainreg.ChainCode]*bitcoinNetParams), netParams: make(map[chainreg.ChainCode]*chainreg.BitcoinNetParams),
} }
} }

View File

@ -320,7 +320,7 @@ type Config struct {
networkDir string networkDir string
// ActiveNetParams contains parameters of the target chain. // ActiveNetParams contains parameters of the target chain.
ActiveNetParams bitcoinNetParams ActiveNetParams chainreg.BitcoinNetParams
} }
// DefaultConfig returns all default values for the Config struct. // DefaultConfig returns all default values for the Config struct.
@ -453,7 +453,7 @@ func DefaultConfig() Config {
LogWriter: build.NewRotatingLogWriter(), LogWriter: build.NewRotatingLogWriter(),
DB: lncfg.DefaultDB(), DB: lncfg.DefaultDB(),
registeredChains: newChainRegistry(), registeredChains: newChainRegistry(),
ActiveNetParams: bitcoinTestNetParams, ActiveNetParams: chainreg.BitcoinTestNetParams,
} }
} }
@ -830,22 +830,22 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
// number of network flags passed; assign active network params // number of network flags passed; assign active network params
// while we're at it. // while we're at it.
numNets := 0 numNets := 0
var ltcParams litecoinNetParams var ltcParams chainreg.LitecoinNetParams
if cfg.Litecoin.MainNet { if cfg.Litecoin.MainNet {
numNets++ numNets++
ltcParams = litecoinMainNetParams ltcParams = chainreg.LitecoinMainNetParams
} }
if cfg.Litecoin.TestNet3 { if cfg.Litecoin.TestNet3 {
numNets++ numNets++
ltcParams = litecoinTestNetParams ltcParams = chainreg.LitecoinTestNetParams
} }
if cfg.Litecoin.RegTest { if cfg.Litecoin.RegTest {
numNets++ numNets++
ltcParams = litecoinRegTestNetParams ltcParams = chainreg.LitecoinRegTestNetParams
} }
if cfg.Litecoin.SimNet { if cfg.Litecoin.SimNet {
numNets++ numNets++
ltcParams = litecoinSimNetParams ltcParams = chainreg.LitecoinSimNetParams
} }
if numNets > 1 { if numNets > 1 {
@ -869,7 +869,7 @@ 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(&cfg.ActiveNetParams, &ltcParams) chainreg.ApplyLitecoinParams(&cfg.ActiveNetParams, &ltcParams)
switch cfg.Litecoin.Node { switch cfg.Litecoin.Node {
case "ltcd": case "ltcd":
@ -914,19 +914,19 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
numNets := 0 numNets := 0
if cfg.Bitcoin.MainNet { if cfg.Bitcoin.MainNet {
numNets++ numNets++
cfg.ActiveNetParams = bitcoinMainNetParams cfg.ActiveNetParams = chainreg.BitcoinMainNetParams
} }
if cfg.Bitcoin.TestNet3 { if cfg.Bitcoin.TestNet3 {
numNets++ numNets++
cfg.ActiveNetParams = bitcoinTestNetParams cfg.ActiveNetParams = chainreg.BitcoinTestNetParams
} }
if cfg.Bitcoin.RegTest { if cfg.Bitcoin.RegTest {
numNets++ numNets++
cfg.ActiveNetParams = bitcoinRegTestNetParams cfg.ActiveNetParams = chainreg.BitcoinRegTestNetParams
} }
if cfg.Bitcoin.SimNet { if cfg.Bitcoin.SimNet {
numNets++ numNets++
cfg.ActiveNetParams = bitcoinSimNetParams cfg.ActiveNetParams = chainreg.BitcoinSimNetParams
} }
if numNets > 1 { if numNets > 1 {
str := "%s: The mainnet, testnet, regtest, and " + str := "%s: The mainnet, testnet, regtest, and " +
@ -1315,7 +1315,7 @@ func CleanAndExpandPath(path string) string {
func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{},
net chainreg.ChainCode, funcName string, net chainreg.ChainCode, funcName string,
netParams bitcoinNetParams) error { // nolint:unparam netParams chainreg.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

View File

@ -21,9 +21,8 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/chanacceptor" "github.com/lightningnetwork/lnd/chanacceptor"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/channelnotifier"
@ -31,6 +30,7 @@ import (
"github.com/lightningnetwork/lnd/htlcswitch" "github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest/mock" "github.com/lightningnetwork/lnd/lntest/mock"
@ -104,7 +104,7 @@ var (
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10) _, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10) _, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
fundingNetParams = bitcoinTestNetParams fundingNetParams = chainreg.BitcoinTestNetParams
) )
type mockNotifier struct { type mockNotifier struct {

28
lnd.go
View File

@ -450,11 +450,29 @@ func Main(cfg *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) error {
// When we create the chain control, we need storage for the height // When we create the chain control, we need storage for the height
// hints and also the wallet itself, for these two we want them to be // hints and also the wallet itself, for these two we want them to be
// replicated, so we'll pass in the remote channel DB instance. // replicated, so we'll pass in the remote channel DB instance.
activeChainControl, err := newChainControlFromConfig( chainControlCfg := &chainreg.Config{
cfg, localChanDB, remoteChanDB, privateWalletPw, publicWalletPw, Bitcoin: cfg.Bitcoin,
walletInitParams.Birthday, walletInitParams.RecoveryWindow, Litecoin: cfg.Litecoin,
walletInitParams.Wallet, neutrinoCS, PrimaryChain: cfg.registeredChains.PrimaryChain,
) HeightHintCacheQueryDisable: cfg.HeightHintCacheQueryDisable,
NeutrinoMode: cfg.NeutrinoMode,
BitcoindMode: cfg.BitcoindMode,
LitecoindMode: cfg.LitecoindMode,
BtcdMode: cfg.BtcdMode,
LtcdMode: cfg.LtcdMode,
LocalChanDB: localChanDB,
RemoteChanDB: remoteChanDB,
PrivateWalletPw: privateWalletPw,
PublicWalletPw: publicWalletPw,
Birthday: walletInitParams.Birthday,
RecoveryWindow: walletInitParams.RecoveryWindow,
Wallet: walletInitParams.Wallet,
NeutrinoCS: neutrinoCS,
ActiveNetParams: cfg.ActiveNetParams,
FeeURL: cfg.FeeURL,
}
activeChainControl, err := newChainControl(chainControlCfg)
if err != nil { if err != nil {
err := fmt.Errorf("unable to create chain control: %v", err) err := fmt.Errorf("unable to create chain control: %v", err)
ltndLog.Error(err) ltndLog.Error(err)

View File

@ -9,6 +9,7 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/tor" "github.com/lightningnetwork/lnd/tor"
@ -76,7 +77,7 @@ type chanController struct {
minConfs int32 minConfs int32
confTarget uint32 confTarget uint32
chanMinHtlcIn lnwire.MilliSatoshi chanMinHtlcIn lnwire.MilliSatoshi
netParams bitcoinNetParams netParams chainreg.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
@ -134,8 +135,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, netParams bitcoinNetParams) (*autopilot.ManagerCfg, chainCfg *lncfg.Chain, netParams chainreg.BitcoinNetParams) (
error) { *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, "+

View File

@ -2584,7 +2584,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(&r.cfg.ActiveNetParams), Testnet: chainreg.IsTestnet(&r.cfg.ActiveNetParams),
Chains: activeChains, Chains: activeChains,
Uris: uris, Uris: uris,
Alias: nodeAnn.Alias.String(), Alias: nodeAnn.Alias.String(),