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
|
// 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 registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
homeChainConfig = cfg.Litecoin
|
homeChainConfig = cfg.Litecoin
|
||||||
}
|
}
|
||||||
ltndLog.Infof("Primary chain is set to: %v",
|
ltndLog.Infof("Primary chain is set to: %v",
|
||||||
registeredChains.PrimaryChain())
|
cfg.registeredChains.PrimaryChain())
|
||||||
|
|
||||||
cc := &chainControl{}
|
cc := &chainControl{}
|
||||||
|
|
||||||
switch registeredChains.PrimaryChain() {
|
switch cfg.registeredChains.PrimaryChain() {
|
||||||
case bitcoinChain:
|
case bitcoinChain:
|
||||||
cc.routingPolicy = htlcswitch.ForwardingPolicy{
|
cc.routingPolicy = htlcswitch.ForwardingPolicy{
|
||||||
MinHTLCOut: cfg.Bitcoin.MinHTLCOut,
|
MinHTLCOut: cfg.Bitcoin.MinHTLCOut,
|
||||||
@ -203,7 +203,7 @@ func newChainControlFromConfig(cfg *Config, chanDB *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", registeredChains.PrimaryChain())
|
"unknown", cfg.registeredChains.PrimaryChain())
|
||||||
}
|
}
|
||||||
|
|
||||||
walletConfig := &btcwallet.Config{
|
walletConfig := &btcwallet.Config{
|
||||||
@ -505,7 +505,7 @@ func newChainControlFromConfig(cfg *Config, chanDB *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 registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
channelConstraints = defaultLtcChannelConstraints
|
channelConstraints = defaultLtcChannelConstraints
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
config.go
13
config.go
@ -247,6 +247,10 @@ type Config struct {
|
|||||||
ProtocolOptions *lncfg.ProtocolOptions `group:"protocol" namespace:"protocol"`
|
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."`
|
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.
|
// DefaultConfig returns all default values for the Config struct.
|
||||||
@ -349,6 +353,7 @@ func DefaultConfig() Config {
|
|||||||
},
|
},
|
||||||
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
|
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
|
||||||
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
|
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
|
// Finally we'll register the litecoin chain as our current
|
||||||
// primary chain.
|
// primary chain.
|
||||||
registeredChains.RegisterPrimaryChain(litecoinChain)
|
cfg.registeredChains.RegisterPrimaryChain(litecoinChain)
|
||||||
MaxFundingAmount = maxLtcFundingAmount
|
MaxFundingAmount = maxLtcFundingAmount
|
||||||
MaxPaymentMSat = maxLtcPaymentMSat
|
MaxPaymentMSat = maxLtcPaymentMSat
|
||||||
|
|
||||||
@ -823,7 +828,7 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) {
|
|||||||
|
|
||||||
// Finally we'll register the bitcoin chain as our current
|
// Finally we'll register the bitcoin chain as our current
|
||||||
// primary chain.
|
// primary chain.
|
||||||
registeredChains.RegisterPrimaryChain(bitcoinChain)
|
cfg.registeredChains.RegisterPrimaryChain(bitcoinChain)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the user didn't attempt to specify negative values for
|
// 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.
|
// store all the data specific to this chain/network.
|
||||||
networkDir = filepath.Join(
|
networkDir = filepath.Join(
|
||||||
cfg.DataDir, defaultChainSubDirname,
|
cfg.DataDir, defaultChainSubDirname,
|
||||||
registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(activeNetParams.Name),
|
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"
|
// Append the network type to the log directory so it is "namespaced"
|
||||||
// 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,
|
||||||
registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(activeNetParams.Name))
|
normalizeNetwork(activeNetParams.Name))
|
||||||
|
|
||||||
// Special show command to list supported subsystems and exit.
|
// 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.
|
// We'll determine our dust limit depending on which chain is active.
|
||||||
var ourDustLimit btcutil.Amount
|
var ourDustLimit btcutil.Amount
|
||||||
switch registeredChains.PrimaryChain() {
|
switch cfg.registeredChains.PrimaryChain() {
|
||||||
case bitcoinChain:
|
case bitcoinChain:
|
||||||
ourDustLimit = lnwallet.DefaultDustLimit()
|
ourDustLimit = lnwallet.DefaultDustLimit()
|
||||||
case litecoinChain:
|
case litecoinChain:
|
||||||
|
15
lnd.go
15
lnd.go
@ -52,8 +52,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cfg *Config
|
cfg *Config
|
||||||
registeredChains = newChainRegistry()
|
|
||||||
|
|
||||||
// networkDir is the path to the directory of the currently active
|
// networkDir is the path to the directory of the currently active
|
||||||
// network. This path will hold the files related to each different
|
// 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)",
|
ltndLog.Infof("Active chain: %v (network=%v)",
|
||||||
strings.Title(registeredChains.PrimaryChain().String()),
|
strings.Title(cfg.registeredChains.PrimaryChain().String()),
|
||||||
network,
|
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
|
// light client instance, if enabled, in order to allow it to sync
|
||||||
// while the rest of the daemon continues startup.
|
// while the rest of the daemon continues startup.
|
||||||
mainChain := cfg.Bitcoin
|
mainChain := cfg.Bitcoin
|
||||||
if registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
mainChain = cfg.Litecoin
|
mainChain = cfg.Litecoin
|
||||||
}
|
}
|
||||||
var neutrinoCS *neutrino.ChainService
|
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
|
// Finally before we start the server, we'll register the "holy
|
||||||
// trinity" of interface for our current "home chain" with the active
|
// trinity" of interface for our current "home chain" with the active
|
||||||
// chainRegistry interface.
|
// chainRegistry interface.
|
||||||
primaryChain := registeredChains.PrimaryChain()
|
primaryChain := cfg.registeredChains.PrimaryChain()
|
||||||
registeredChains.RegisterChain(primaryChain, activeChainControl)
|
cfg.registeredChains.RegisterChain(primaryChain, activeChainControl)
|
||||||
|
|
||||||
// TODO(roasbeef): add rotation
|
// TODO(roasbeef): add rotation
|
||||||
idPrivKey, err := activeChainControl.wallet.DerivePrivKey(keychain.KeyDescriptor{
|
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.
|
// Segment the watchtower directory by chain and network.
|
||||||
towerDBDir := filepath.Join(
|
towerDBDir := filepath.Join(
|
||||||
cfg.Watchtower.TowerDir,
|
cfg.Watchtower.TowerDir,
|
||||||
registeredChains.PrimaryChain().String(),
|
cfg.registeredChains.PrimaryChain().String(),
|
||||||
normalizeNetwork(activeNetParams.Name),
|
normalizeNetwork(activeNetParams.Name),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -992,7 +991,7 @@ func waitForWalletPassword(restEndpoints []net.Addr,
|
|||||||
defer grpcServer.GracefulStop()
|
defer grpcServer.GracefulStop()
|
||||||
|
|
||||||
chainConfig := cfg.Bitcoin
|
chainConfig := cfg.Bitcoin
|
||||||
if registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
chainConfig = cfg.Litecoin
|
chainConfig = cfg.Litecoin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2404,8 +2404,8 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
network := normalizeNetwork(activeNetParams.Name)
|
network := normalizeNetwork(activeNetParams.Name)
|
||||||
activeChains := make([]*lnrpc.Chain, registeredChains.NumActiveChains())
|
activeChains := make([]*lnrpc.Chain, cfg.registeredChains.NumActiveChains())
|
||||||
for i, chain := range registeredChains.ActiveChains() {
|
for i, chain := range cfg.registeredChains.ActiveChains() {
|
||||||
activeChains[i] = &lnrpc.Chain{
|
activeChains[i] = &lnrpc.Chain{
|
||||||
Chain: chain.String(),
|
Chain: chain.String(),
|
||||||
Network: network,
|
Network: network,
|
||||||
@ -4365,7 +4365,7 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
|
|||||||
invoice *lnrpc.Invoice) (*lnrpc.AddInvoiceResponse, error) {
|
invoice *lnrpc.Invoice) (*lnrpc.AddInvoiceResponse, error) {
|
||||||
|
|
||||||
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
||||||
if registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
defaultDelta = cfg.Litecoin.TimeLockDelta
|
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
|
// Select the configuration and furnding parameters for Bitcoin or
|
||||||
// Litecoin, depending on the primary registered chain.
|
// Litecoin, depending on the primary registered chain.
|
||||||
primaryChain := registeredChains.PrimaryChain()
|
primaryChain := cfg.registeredChains.PrimaryChain()
|
||||||
chainCfg := cfg.Bitcoin
|
chainCfg := cfg.Bitcoin
|
||||||
minRemoteDelay := minBtcRemoteDelay
|
minRemoteDelay := minBtcRemoteDelay
|
||||||
maxRemoteDelay := maxBtcRemoteDelay
|
maxRemoteDelay := maxBtcRemoteDelay
|
||||||
|
@ -203,7 +203,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cc *chainControl,
|
|||||||
reflect.ValueOf(nodeSigner),
|
reflect.ValueOf(nodeSigner),
|
||||||
)
|
)
|
||||||
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
defaultDelta := cfg.Bitcoin.TimeLockDelta
|
||||||
if registeredChains.PrimaryChain() == litecoinChain {
|
if cfg.registeredChains.PrimaryChain() == litecoinChain {
|
||||||
defaultDelta = cfg.Litecoin.TimeLockDelta
|
defaultDelta = cfg.Litecoin.TimeLockDelta
|
||||||
}
|
}
|
||||||
subCfgValue.FieldByName("DefaultCLTVExpiry").Set(
|
subCfgValue.FieldByName("DefaultCLTVExpiry").Set(
|
||||||
|
Loading…
Reference in New Issue
Block a user