utxonursery: connect to time-based sweeper
Previously, nursery generated and published its own sweep txes. It stored the sweep tx in nursery_store to prevent a new tx with a new sweep address from being generated on restart. In this commit, sweep generation and publication is removed from nursery and delegated to the sweeper. Also the confirmation notification is received from the sweeper.
This commit is contained in:
8 files changed
+365
-954
No files matched your search
@@ -17,8 +17,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/connmgr"
|
||||
@@ -40,6 +38,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/nat"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/sweep"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
"github.com/lightningnetwork/lnd/tor"
|
||||
)
|
||||
@@ -156,6 +155,8 @@ type server struct {
|
||||
|
||||
utxoNursery *utxoNursery
|
||||
|
||||
sweeper *sweep.UtxoSweeper
|
||||
|
||||
chainArb *contractcourt.ChainArbitrator
|
||||
|
||||
sphinx *htlcswitch.OnionProcessor
|
||||
@@ -597,24 +598,45 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sweeper := sweep.New(&sweep.UtxoSweeperConfig{
|
||||
srvrLog.Tracef("Sweeper batch window duration: %v",
|
||||
sweep.DefaultBatchWindowDuration)
|
||||
|
||||
sweeperStore, err := sweep.NewSweeperStore(
|
||||
chanDB, activeNetParams.GenesisHash,
|
||||
)
|
||||
if err != nil {
|
||||
srvrLog.Errorf("unable to create sweeper store: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.sweeper = sweep.New(&sweep.UtxoSweeperConfig{
|
||||
Estimator: cc.feeEstimator,
|
||||
GenSweepScript: func() ([]byte, error) {
|
||||
return newSweepPkScript(cc.wallet)
|
||||
},
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
Signer: cc.wallet.Cfg.Signer,
|
||||
PublishTransaction: cc.wallet.PublishTransaction,
|
||||
NewBatchTimer: func() <-chan time.Time {
|
||||
return time.NewTimer(sweep.DefaultBatchWindowDuration).C
|
||||
},
|
||||
SweepTxConfTarget: 6,
|
||||
Notifier: cc.chainNotifier,
|
||||
ChainIO: cc.chainIO,
|
||||
Store: sweeperStore,
|
||||
MaxInputsPerTx: sweep.DefaultMaxInputsPerTx,
|
||||
MaxSweepAttempts: sweep.DefaultMaxSweepAttempts,
|
||||
NextAttemptDeltaFunc: sweep.DefaultNextAttemptDeltaFunc,
|
||||
})
|
||||
|
||||
s.utxoNursery = newUtxoNursery(&NurseryConfig{
|
||||
ChainIO: cc.chainIO,
|
||||
ConfDepth: 1,
|
||||
SweepTxConfTarget: 6,
|
||||
FetchClosedChannels: chanDB.FetchClosedChannels,
|
||||
FetchClosedChannel: chanDB.FetchClosedChannel,
|
||||
Notifier: cc.chainNotifier,
|
||||
PublishTransaction: cc.wallet.PublishTransaction,
|
||||
Store: utxnStore,
|
||||
Sweeper: sweeper,
|
||||
Sweeper: s.sweeper,
|
||||
})
|
||||
|
||||
// Construct a closure that wraps the htlcswitch's CloseLink method.
|
||||
@@ -706,7 +728,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
||||
DisableChannel: func(op wire.OutPoint) error {
|
||||
return s.announceChanStatus(op, true)
|
||||
},
|
||||
Sweeper: sweeper,
|
||||
Sweeper: s.sweeper,
|
||||
}, chanDB)
|
||||
|
||||
s.breachArbiter = newBreachArbiter(&BreachConfig{
|
||||
@@ -963,6 +985,9 @@ func (s *server) Start() error {
|
||||
if err := s.htlcSwitch.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.sweeper.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.utxoNursery.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1050,6 +1075,7 @@ func (s *server) Stop() error {
|
||||
s.breachArbiter.Stop()
|
||||
s.authGossiper.Stop()
|
||||
s.chainArb.Stop()
|
||||
s.sweeper.Stop()
|
||||
s.cc.wallet.Shutdown()
|
||||
s.cc.chainView.Stop()
|
||||
s.connMgr.Stop()
|
||||
|
||||
Reference in new issue
Block a user