mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 14:12:27 +02:00
chainreg+lnd: split chain control initialization
As a preparation for extracting the wallet related initialization code, we first need to separate the purely configuration related chain control initialization from the wallet related code. We do that by splitting the chain control into a partial and full struct that is initialized in two parts. This also allows us to create the wallet configuration itself outside of the chain control package and we need to thread through fewer parameters through the chain control config.
This commit is contained in:
43
lnd.go
43
lnd.go
@ -718,36 +718,59 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
||||
LtcdMode: cfg.LtcdMode,
|
||||
HeightHintDB: dbs.heightHintDB,
|
||||
ChanStateDB: dbs.chanStateDB.ChannelStateDB(),
|
||||
PrivateWalletPw: privateWalletPw,
|
||||
PublicWalletPw: publicWalletPw,
|
||||
Birthday: walletInitParams.Birthday,
|
||||
RecoveryWindow: walletInitParams.RecoveryWindow,
|
||||
Wallet: walletInitParams.Wallet,
|
||||
NeutrinoCS: neutrinoCS,
|
||||
ActiveNetParams: cfg.ActiveNetParams,
|
||||
FeeURL: cfg.FeeURL,
|
||||
Dialer: func(addr string) (net.Conn, error) {
|
||||
return cfg.net.Dial("tcp", addr, cfg.ConnectionTimeout)
|
||||
},
|
||||
BlockCache: blockCache,
|
||||
LoaderOptions: []btcwallet.LoaderOption{dbs.walletDB},
|
||||
BlockCache: blockCache,
|
||||
}
|
||||
|
||||
// Let's go ahead and create the partial chain control now that is only
|
||||
// dependent on our configuration and doesn't require any wallet
|
||||
// specific information.
|
||||
partialChainControl, cleanup, err := chainreg.NewPartialChainControl(
|
||||
chainControlCfg,
|
||||
)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
}
|
||||
if err != nil {
|
||||
err := fmt.Errorf("unable to create partial chain control: %v",
|
||||
err)
|
||||
ltndLog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
walletConfig := &btcwallet.Config{
|
||||
PrivatePass: privateWalletPw,
|
||||
PublicPass: publicWalletPw,
|
||||
Birthday: walletInitParams.Birthday,
|
||||
RecoveryWindow: walletInitParams.RecoveryWindow,
|
||||
NetParams: cfg.ActiveNetParams.Params,
|
||||
CoinType: cfg.ActiveNetParams.CoinType,
|
||||
Wallet: walletInitParams.Wallet,
|
||||
LoaderOptions: []btcwallet.LoaderOption{dbs.walletDB},
|
||||
}
|
||||
|
||||
// Parse coin selection strategy.
|
||||
switch cfg.CoinSelectionStrategy {
|
||||
case "largest":
|
||||
chainControlCfg.CoinSelectionStrategy = wallet.CoinSelectionLargest
|
||||
walletConfig.CoinSelectionStrategy = wallet.CoinSelectionLargest
|
||||
|
||||
case "random":
|
||||
chainControlCfg.CoinSelectionStrategy = wallet.CoinSelectionRandom
|
||||
walletConfig.CoinSelectionStrategy = wallet.CoinSelectionRandom
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown coin selection strategy %v",
|
||||
cfg.CoinSelectionStrategy)
|
||||
}
|
||||
|
||||
// We've created the wallet configuration now, so we can finish
|
||||
// initializing the main chain control.
|
||||
activeChainControl, cleanup, err := chainreg.NewChainControl(
|
||||
chainControlCfg,
|
||||
walletConfig, partialChainControl,
|
||||
)
|
||||
if cleanup != nil {
|
||||
defer cleanup()
|
||||
|
Reference in New Issue
Block a user