sweep+lnd: move ticker creation into sweeper

This commit is contained in:
yyforyongyu
2023-10-12 18:03:34 +08:00
parent 62b5869f87
commit 4ba09098d1
3 changed files with 17 additions and 22 deletions

View File

@@ -1059,14 +1059,12 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
} }
s.sweeper = sweep.New(&sweep.UtxoSweeperConfig{ s.sweeper = sweep.New(&sweep.UtxoSweeperConfig{
FeeEstimator: cc.FeeEstimator, FeeEstimator: cc.FeeEstimator,
DetermineFeePerKw: sweep.DetermineFeePerKw, DetermineFeePerKw: sweep.DetermineFeePerKw,
GenSweepScript: newSweepPkScriptGen(cc.Wallet), GenSweepScript: newSweepPkScriptGen(cc.Wallet),
Signer: cc.Wallet.Cfg.Signer, Signer: cc.Wallet.Cfg.Signer,
Wallet: newSweeperWallet(cc.Wallet), Wallet: newSweeperWallet(cc.Wallet),
NewBatchTimer: func() <-chan time.Time { TickerDuration: cfg.Sweeper.BatchWindowDuration,
return time.NewTimer(cfg.Sweeper.BatchWindowDuration).C
},
Notifier: cc.ChainNotifier, Notifier: cc.ChainNotifier,
Store: sweeperStore, Store: sweeperStore,
MaxInputsPerTx: sweep.DefaultMaxInputsPerTx, MaxInputsPerTx: sweep.DefaultMaxInputsPerTx,

View File

@@ -264,10 +264,11 @@ type UtxoSweeperConfig struct {
// Wallet contains the wallet functions that sweeper requires. // Wallet contains the wallet functions that sweeper requires.
Wallet Wallet Wallet Wallet
// NewBatchTimer creates a channel that will be sent on when a certain // TickerDuration is used to create a channel that will be sent on when
// time window has passed. During this time window, new inputs can still // a certain time window has passed. During this time window, new
// be added to the sweep tx that is about to be generated. // inputs can still be added to the sweep tx that is about to be
NewBatchTimer func() <-chan time.Time // generated.
TickerDuration time.Duration
// Notifier is an instance of a chain notifier we'll use to watch for // Notifier is an instance of a chain notifier we'll use to watch for
// certain on-chain events. // certain on-chain events.
@@ -1019,7 +1020,7 @@ func (s *UtxoSweeper) scheduleSweep(currentHeight int32) error {
// Start sweep timer to create opportunity for more inputs to be added // Start sweep timer to create opportunity for more inputs to be added
// before a tx is constructed. // before a tx is constructed.
s.timer = s.cfg.NewBatchTimer() s.timer = time.NewTicker(s.cfg.TickerDuration).C
log.Debugf("Sweep timer started") log.Debugf("Sweep timer started")

View File

@@ -127,15 +127,11 @@ func createSweeperTestContext(t *testing.T) *sweeperTestContext {
} }
ctx.sweeper = New(&UtxoSweeperConfig{ ctx.sweeper = New(&UtxoSweeperConfig{
Notifier: notifier, Notifier: notifier,
Wallet: backend, Wallet: backend,
NewBatchTimer: func() <-chan time.Time { TickerDuration: 100 * time.Millisecond,
c := make(chan time.Time, 1) Store: store,
ctx.timeoutChan <- c Signer: &mock.DummySigner{},
return c
},
Store: store,
Signer: &mock.DummySigner{},
GenSweepScript: func() ([]byte, error) { GenSweepScript: func() ([]byte, error) {
script := make([]byte, input.P2WPKHSize) script := make([]byte, input.P2WPKHSize)
script[0] = 0 script[0] = 0