Skip to content

Commit 9d04b0c

Browse files
authored
Merge pull request #6868 from yyforyongyu/sweepr-config
sever+lncfg: add sweepr config
2 parents b208642 + 50487c6 commit 9d04b0c

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/lightningnetwork/lnd/lnwallet"
4242
"github.com/lightningnetwork/lnd/routing"
4343
"github.com/lightningnetwork/lnd/signal"
44+
"github.com/lightningnetwork/lnd/sweep"
4445
"github.com/lightningnetwork/lnd/tor"
4546
)
4647

@@ -439,6 +440,8 @@ type Config struct {
439440

440441
RemoteSigner *lncfg.RemoteSigner `group:"remotesigner" namespace:"remotesigner"`
441442

443+
Sweeper *lncfg.Sweeper `group:"sweeper" namespace:"sweeper"`
444+
442445
// LogWriter is the root logger that all of the daemon's subloggers are
443446
// hooked up to.
444447
LogWriter *build.RotatingLogWriter
@@ -635,6 +638,9 @@ func DefaultConfig() Config {
635638
RemoteSigner: &lncfg.RemoteSigner{
636639
Timeout: lncfg.DefaultRemoteSignerRPCTimeout,
637640
},
641+
Sweeper: &lncfg.Sweeper{
642+
BatchWindowDuration: sweep.DefaultBatchWindowDuration,
643+
},
638644
}
639645
}
640646

@@ -1651,6 +1657,7 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
16511657
cfg.HealthChecks,
16521658
cfg.RPCMiddleware,
16531659
cfg.RemoteSigner,
1660+
cfg.Sweeper,
16541661
)
16551662
if err != nil {
16561663
return nil, err

docs/release-notes/release-notes-0.16.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ minimum version needed to build the project.
6060
* [Fix](https://github.com/lightningnetwork/lnd/pull/6875) mapslice cap out of
6161
range error that occurs if the number of profiles is zero.
6262

63+
* [A new config option, `batchwindowduration` has been added to
64+
`sweeper`](https://github.com/lightningnetwork/lnd/pull/6868) to allow
65+
customize sweeper batch duration.
66+
6367
## Code Health
6468

6569
* [test: use `T.TempDir` to create temporary test

lncfg/sweeper.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package lncfg
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
type Sweeper struct {
9+
BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."`
10+
}
11+
12+
// Validate checks the values configured for the sweeper.
13+
func (s *Sweeper) Validate() error {
14+
if s.BatchWindowDuration < 0 {
15+
return fmt.Errorf("batchwindowduration must be positive")
16+
}
17+
18+
return nil
19+
}

sample-lnd.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,3 +1415,10 @@ litecoin.node=ltcd
14151415
; for neutrino nodes as it means they'll only maintain edges where both nodes are
14161416
; seen as being live from it's PoV.
14171417
; routing.strictgraphpruning=true
1418+
1419+
[sweeper]
1420+
1421+
; Duration of the sweep batch window. The sweep is held back during the batch
1422+
; window to allow more inputs to be added and thereby lower the fee per input.
1423+
; sweeper.batchwindowduration=30s
1424+

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
10041004
Signer: cc.Wallet.Cfg.Signer,
10051005
Wallet: cc.Wallet,
10061006
NewBatchTimer: func() <-chan time.Time {
1007-
return time.NewTimer(sweep.DefaultBatchWindowDuration).C
1007+
return time.NewTimer(cfg.Sweeper.BatchWindowDuration).C
10081008
},
10091009
Notifier: cc.ChainNotifier,
10101010
Store: sweeperStore,

sweep/sweeper.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
654654
params: input.params,
655655
}
656656
s.pendingInputs[outpoint] = pendInput
657+
log.Tracef("input %v added to pendingInputs", outpoint)
657658

658659
// Start watching for spend of this input, either by us
659660
// or the remote party.
@@ -674,6 +675,7 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
674675
if err := s.scheduleSweep(bestHeight); err != nil {
675676
log.Errorf("schedule sweep: %v", err)
676677
}
678+
log.Tracef("input %v scheduled", outpoint)
677679

678680
// A spend of one of our inputs is detected. Signal sweep
679681
// results to the caller(s).
@@ -1145,7 +1147,7 @@ func (s *UtxoSweeper) scheduleSweep(currentHeight int32) error {
11451147
// The timer is already ticking, no action needed for the sweep to
11461148
// happen.
11471149
if s.timer != nil {
1148-
log.Debugf("Timer still ticking")
1150+
log.Debugf("Timer still ticking at height=%v", currentHeight)
11491151
return nil
11501152
}
11511153

@@ -1338,9 +1340,14 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight,
13381340
return fmt.Errorf("publish tx: %v", err)
13391341
}
13401342

1341-
// Keep the output script in case of an error, so that it can be reused
1342-
// for the next transaction and causes no address inflation.
1343-
if err == nil {
1343+
// Otherwise log the error.
1344+
if err != nil {
1345+
log.Errorf("Publish sweep tx %v got error: %v", tx.TxHash(),
1346+
err)
1347+
} else {
1348+
// If there's no error, remove the output script. Otherwise
1349+
// keep it so that it can be reused for the next transaction
1350+
// and causes no address inflation.
13441351
s.currentOutputScript = nil
13451352
}
13461353

@@ -1375,6 +1382,11 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight,
13751382
nextAttemptDelta)
13761383

13771384
if pi.publishAttempts >= s.cfg.MaxSweepAttempts {
1385+
log.Warnf("input %v: publishAttempts(%v) exceeds "+
1386+
"MaxSweepAttempts(%v), removed",
1387+
input.PreviousOutPoint, pi.publishAttempts,
1388+
s.cfg.MaxSweepAttempts)
1389+
13781390
// Signal result channels sweep result.
13791391
s.signalAndRemove(&input.PreviousOutPoint, Result{
13801392
Err: ErrTooManyAttempts,
@@ -1390,7 +1402,8 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight,
13901402
func (s *UtxoSweeper) waitForSpend(outpoint wire.OutPoint,
13911403
script []byte, heightHint uint32) (func(), error) {
13921404

1393-
log.Debugf("Wait for spend of %v", outpoint)
1405+
log.Tracef("Wait for spend of %v at heightHint=%v",
1406+
outpoint, heightHint)
13941407

13951408
spendEvent, err := s.cfg.Notifier.RegisterSpendNtfn(
13961409
&outpoint, script, heightHint,

0 commit comments

Comments
 (0)