multi: move global registeredChains to cfg
This commit is contained in:
parent
a7e78112b7
commit
85d5cdfbfd
@ -169,15 +169,15 @@ func newChainControlFromConfig(cfg *Config, chanDB *channeldb.DB,
|
||||
// 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.
|
||||
homeChainConfig := cfg.Bitcoin
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
homeChainConfig = cfg.Litecoin
|
||||
}
|
||||
ltndLog.Infof("Primary chain is set to: %v",
|
||||
registeredChains.PrimaryChain())
|
||||
cfg.registeredChains.PrimaryChain())
|
||||
|
||||
cc := &chainControl{}
|
||||
|
||||
switch registeredChains.PrimaryChain() {
|
||||
switch cfg.registeredChains.PrimaryChain() {
|
||||
case bitcoinChain:
|
||||
cc.routingPolicy = htlcswitch.ForwardingPolicy{
|
||||
MinHTLCOut: cfg.Bitcoin.MinHTLCOut,
|
||||
@ -203,7 +203,7 @@ func newChainControlFromConfig(cfg *Config, chanDB *channeldb.DB,
|
||||
)
|
||||
default:
|
||||
return nil, fmt.Errorf("default routing policy for chain %v is "+
|
||||
"unknown", registeredChains.PrimaryChain())
|
||||
"unknown", cfg.registeredChains.PrimaryChain())
|
||||
}
|
||||
|
||||
walletConfig := &btcwallet.Config{
|
||||
@ -505,7 +505,7 @@ func newChainControlFromConfig(cfg *Config, chanDB *channeldb.DB,
|
||||
|
||||
// Select the default channel constraints for the primary chain.
|
||||
channelConstraints := defaultBtcChannelConstraints
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
channelConstraints = defaultLtcChannelConstraints
|
||||
}
|
||||
|
||||
|
13
config.go
13
config.go
@ -247,6 +247,10 @@ type Config struct {
|
||||
ProtocolOptions *lncfg.ProtocolOptions `group:"protocol" namespace:"protocol"`
|
||||
|
||||
AllowCircularRoute bool `long:"allow-circular-route" description:"If true, our node will allow htlc forwards that arrive and depart on the same channel."`
|
||||
|
||||
// registeredChains keeps track of all chains that have been registered
|
||||
// with the daemon.
|
||||
registeredChains *chainRegistry
|
||||
}
|
||||
|
||||
// DefaultConfig returns all default values for the Config struct.
|
||||
@ -349,6 +353,7 @@ func DefaultConfig() Config {
|
||||
},
|
||||
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
|
||||
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
|
||||
registeredChains: newChainRegistry(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -736,7 +741,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
|
||||
// Finally we'll register the litecoin chain as our current
|
||||
// primary chain.
|
||||
registeredChains.RegisterPrimaryChain(litecoinChain)
|
||||
cfg.registeredChains.RegisterPrimaryChain(litecoinChain)
|
||||
MaxFundingAmount = maxLtcFundingAmount
|
||||
MaxPaymentMSat = maxLtcPaymentMSat
|
||||
|
||||
@ -823,7 +828,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
|
||||
// Finally we'll register the bitcoin chain as our current
|
||||
// primary chain.
|
||||
registeredChains.RegisterPrimaryChain(bitcoinChain)
|
||||
cfg.registeredChains.RegisterPrimaryChain(bitcoinChain)
|
||||
}
|
||||
|
||||
// Ensure that the user didn't attempt to specify negative values for
|
||||
@ -878,7 +883,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
// store all the data specific to this chain/network.
|
||||
networkDir = filepath.Join(
|
||||
cfg.DataDir, defaultChainSubDirname,
|
||||
registeredChains.PrimaryChain().String(),
|
||||
cfg.registeredChains.PrimaryChain().String(),
|
||||
normalizeNetwork(activeNetParams.Name),
|
||||
)
|
||||
|
||||
@ -912,7 +917,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
||||
// Append the network type to the log directory so it is "namespaced"
|
||||
// per network in the same fashion as the data directory.
|
||||
cfg.LogDir = filepath.Join(cfg.LogDir,
|
||||
registeredChains.PrimaryChain().String(),
|
||||
cfg.registeredChains.PrimaryChain().String(),
|
||||
normalizeNetwork(activeNetParams.Name))
|
||||
|
||||
// Special show command to list supported subsystems and exit.
|
||||
|
@ -3030,7 +3030,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
||||
|
||||
// We'll determine our dust limit depending on which chain is active.
|
||||
var ourDustLimit btcutil.Amount
|
||||
switch registeredChains.PrimaryChain() {
|
||||
switch cfg.registeredChains.PrimaryChain() {
|
||||
case bitcoinChain:
|
||||
ourDustLimit = lnwallet.DefaultDustLimit()
|
||||
case litecoinChain:
|
||||
|
15
lnd.go
15
lnd.go
@ -52,8 +52,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *Config
|
||||
registeredChains = newChainRegistry()
|
||||
cfg *Config
|
||||
|
||||
// networkDir is the path to the directory of the currently active
|
||||
// network. This path will hold the files related to each different
|
||||
@ -229,7 +228,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
|
||||
}
|
||||
|
||||
ltndLog.Infof("Active chain: %v (network=%v)",
|
||||
strings.Title(registeredChains.PrimaryChain().String()),
|
||||
strings.Title(cfg.registeredChains.PrimaryChain().String()),
|
||||
network,
|
||||
)
|
||||
|
||||
@ -324,7 +323,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
|
||||
// light client instance, if enabled, in order to allow it to sync
|
||||
// while the rest of the daemon continues startup.
|
||||
mainChain := cfg.Bitcoin
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
mainChain = cfg.Litecoin
|
||||
}
|
||||
var neutrinoCS *neutrino.ChainService
|
||||
@ -481,8 +480,8 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
|
||||
// Finally before we start the server, we'll register the "holy
|
||||
// trinity" of interface for our current "home chain" with the active
|
||||
// chainRegistry interface.
|
||||
primaryChain := registeredChains.PrimaryChain()
|
||||
registeredChains.RegisterChain(primaryChain, activeChainControl)
|
||||
primaryChain := cfg.registeredChains.PrimaryChain()
|
||||
cfg.registeredChains.RegisterChain(primaryChain, activeChainControl)
|
||||
|
||||
// TODO(roasbeef): add rotation
|
||||
idPrivKey, err := activeChainControl.wallet.DerivePrivKey(keychain.KeyDescriptor{
|
||||
@ -546,7 +545,7 @@ func Main(config *Config, lisCfg ListenerCfg, shutdownChan <-chan struct{}) erro
|
||||
// Segment the watchtower directory by chain and network.
|
||||
towerDBDir := filepath.Join(
|
||||
cfg.Watchtower.TowerDir,
|
||||
registeredChains.PrimaryChain().String(),
|
||||
cfg.registeredChains.PrimaryChain().String(),
|
||||
normalizeNetwork(activeNetParams.Name),
|
||||
)
|
||||
|
||||
@ -992,7 +991,7 @@ func waitForWalletPassword(restEndpoints []net.Addr,
|
||||
defer grpcServer.GracefulStop()
|
||||
|
||||
chainConfig := cfg.Bitcoin
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
chainConfig = cfg.Litecoin
|
||||
}
|
||||
|
||||
|
@ -2404,8 +2404,8 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
||||
}
|
||||
|
||||
network := normalizeNetwork(activeNetParams.Name)
|
||||
activeChains := make([]*lnrpc.Chain, registeredChains.NumActiveChains())
|
||||
for i, chain := range registeredChains.ActiveChains() {
|
||||
activeChains := make([]*lnrpc.Chain, cfg.registeredChains.NumActiveChains())
|
||||
for i, chain := range cfg.registeredChains.ActiveChains() {
|
||||
activeChains[i] = &lnrpc.Chain{
|
||||
Chain: chain.String(),
|
||||
Network: network,
|
||||
@ -4365,7 +4365,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
|
||||
invoice *lnrpc.Invoice) (*lnrpc.AddInvoiceResponse, error) {
|
||||
|
||||
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
defaultDelta = cfg.Litecoin.TimeLockDelta
|
||||
}
|
||||
|
||||
|
@ -959,7 +959,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
|
||||
// Select the configuration and furnding parameters for Bitcoin or
|
||||
// Litecoin, depending on the primary registered chain.
|
||||
primaryChain := registeredChains.PrimaryChain()
|
||||
primaryChain := cfg.registeredChains.PrimaryChain()
|
||||
chainCfg := cfg.Bitcoin
|
||||
minRemoteDelay := minBtcRemoteDelay
|
||||
maxRemoteDelay := maxBtcRemoteDelay
|
||||
|
@ -203,7 +203,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
|
||||
reflect.ValueOf(nodeSigner),
|
||||
)
|
||||
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
||||
if registeredChains.PrimaryChain() == litecoinChain {
|
||||
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||
defaultDelta = cfg.Litecoin.TimeLockDelta
|
||||
}
|
||||
subCfgValue.FieldByName("DefaultCLTVExpiry").Set(
|
||||
|
Loading…
Reference in New Issue
Block a user