Skip to content

Commit

Permalink
multi: move global registeredChains to cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed May 14, 2020
1 parent a7e7811 commit 85d5cdf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
10 changes: 5 additions & 5 deletions chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 9 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -349,6 +353,7 @@ func DefaultConfig() Config {
},
MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry,
MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation,
registeredChains: newChainRegistry(),
}
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
)

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion fundingmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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),
)

Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion subrpcserver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 85d5cdf

Please sign in to comment.