lnd: properly initialize LightningWallet with new config

This commit is contained in:
Olaoluwa Osuntokun 2017-07-30 16:01:44 -07:00
parent 522712b9a6
commit a73589f3e9
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
3 changed files with 34 additions and 14 deletions

View File

@ -43,6 +43,15 @@ var defaultLitecoinForwardingPolicy = htlcswitch.ForwardingPolicy{
TimeLockDelta: 1,
}
// defaultChannelConstraints is the default set of channel constraints that are
// meant to be used when initially funding a channel.
//
// TODO(roasbeef): have one for both chains
var defaultChannelConstraints = channeldb.ChannelConstraints{
DustLimit: lnwallet.DefaultDustLimit(),
MaxAcceptedHtlcs: lnwallet.MaxHTLCNumber / 2,
}
// chainCode is an enum-like structure for keeping track of the chains currently
// supported within lnd.
type chainCode uint32
@ -266,8 +275,17 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB) (*chainControl
// Create, and start the lnwallet, which handles the core payment
// channel logic, and exposes control via proxy state machines.
wallet, err := lnwallet.NewLightningWallet(chanDB, cc.chainNotifier, wc,
cc.signer, cc.chainIO, cc.feeEstimator, activeNetParams.Params)
walletCfg := lnwallet.Config{
Database: chanDB,
Notifier: cc.chainNotifier,
WalletController: wc,
Signer: cc.signer,
FeeEstimator: cc.feeEstimator,
ChainIO: cc.chainIO,
DefaultConstraints: defaultChannelConstraints,
NetParams: *activeNetParams.Params,
}
wallet, err := lnwallet.NewLightningWallet(walletCfg)
if err != nil {
fmt.Printf("unable to create wallet: %v\n", err)
return nil, nil, err

3
lnd.go
View File

@ -22,6 +22,7 @@ import (
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcutil"
)
var (
@ -145,7 +146,7 @@ func lndMain() error {
}
for _, channel := range dbChannels {
if chanID.IsChanPoint(channel.ChanID) {
if chanID.IsChanPoint(&channel.FundingOutpoint) {
return lnwallet.NewLightningChannel(
activeChainControl.signer,
activeChainControl.chainNotifier,

23
log.go
View File

@ -36,20 +36,21 @@ func (logWriter) Write(p []byte) (n int, err error) {
// subsystemLoggers map.
//
// Loggers can not be used before the log rotator has been initialized with a
// log file. This must be performed early during application startup by calling
// initLogRotator.
// log file. This must be performed early during application startup by
// calling initLogRotator.
var (
// backendLog is the logging backend used to create all subsystem loggers.
// The backend must not be used before the log rotator has been initialized,
// or data races and/or nil pointer dereferences will occur.
// backendLog is the logging backend used to create all subsystem
// loggers. The backend must not be used before the log rotator has
// been initialized, or data races and/or nil pointer dereferences will
// occur.
backendLog = btclog.NewBackend(logWriter{})
// logRotator is one of the logging outputs. It should be closed on
// application shutdown.
logRotator *rotator.Rotator
// logRotatorPipe is the write-end pipe for writing to the log rotator. It
// is written to by the Write method of the logWriter type.
// logRotatorPipe is the write-end pipe for writing to the log rotator.
// It is written to by the Write method of the logWriter type.
logRotatorPipe *io.PipeWriter
ltndLog = backendLog.Logger("LTND")
@ -100,9 +101,9 @@ var subsystemLoggers = map[string]btclog.Logger{
"BTCN": btcnLog,
}
// initLogRotator initializes the logging rotater to write logs to logFile and
// initLogRotator initializes the logging rotator to write logs to logFile and
// create roll files in the same directory. It must be called before the
// package-global log rotater variables are used.
// package-global log rotator variables are used.
func initLogRotator(logFile string) {
logDir, _ := filepath.Split(logFile)
err := os.MkdirAll(logDir, 0700)
@ -149,8 +150,8 @@ func setLogLevels(logLevel string) {
}
}
// logClosure is used to provide a closure over expensive logging operations
// so don't have to be performed when the logging level doesn't warrant it.
// logClosure is used to provide a closure over expensive logging operations so
// don't have to be performed when the logging level doesn't warrant it.
type logClosure func() string
// String invokes the underlying function and returns the result.