Skip to content

Commit dff695b

Browse files
committed
sweep: make sure defaultDeadline is derived from the mature height
1 parent c2149c0 commit dff695b

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

sweep/sweeper.go

+44-10
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (s *UtxoSweeper) SweepInput(inp input.Input,
526526
}
527527

528528
absoluteTimeLock, _ := inp.RequiredLockTime()
529-
log.Infof("Sweep request received: out_point=%v, witness_type=%v, "+
529+
log.Debugf("Sweep request received: out_point=%v, witness_type=%v, "+
530530
"relative_time_lock=%v, absolute_time_lock=%v, amount=%v, "+
531531
"parent=(%v), params=(%v)", inp.OutPoint(), inp.WitnessType(),
532532
inp.BlocksToMaturity(), absoluteTimeLock,
@@ -732,7 +732,18 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
732732
inputs := s.updateSweeperInputs()
733733

734734
log.Debugf("Received new block: height=%v, attempt "+
735-
"sweeping %d inputs", epoch.Height, len(inputs))
735+
"sweeping %d inputs:\n%s",
736+
epoch.Height, len(inputs),
737+
lnutils.NewLogClosure(func() string {
738+
inps := make(
739+
[]input.Input, 0, len(inputs),
740+
)
741+
for _, in := range inputs {
742+
inps = append(inps, in)
743+
}
744+
745+
return inputTypeSummary(inps)
746+
}))
736747

737748
// Attempt to sweep any pending inputs.
738749
s.sweepPendingInputs(inputs)
@@ -1203,13 +1214,29 @@ func (s *UtxoSweeper) mempoolLookup(op wire.OutPoint) fn.Option[wire.MsgTx] {
12031214
return s.cfg.Mempool.LookupInputMempoolSpend(op)
12041215
}
12051216

1206-
// handleNewInput processes a new input by registering spend notification and
1207-
// scheduling sweeping for it.
1208-
func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
1217+
// calculateDefaultDeadline calculates the default deadline height for a sweep
1218+
// request that has no deadline height specified.
1219+
func (s *UtxoSweeper) calculateDefaultDeadline(pi *SweeperInput) int32 {
12091220
// Create a default deadline height, which will be used when there's no
12101221
// DeadlineHeight specified for a given input.
12111222
defaultDeadline := s.currentHeight + int32(s.cfg.NoDeadlineConfTarget)
12121223

1224+
// If the input is immature and has a locktime, we'll use the locktime
1225+
// height as the starting height.
1226+
matured, locktime := pi.isMature(uint32(s.currentHeight))
1227+
if !matured {
1228+
defaultDeadline = int32(locktime + s.cfg.NoDeadlineConfTarget)
1229+
log.Debugf("Input %v is immature, using locktime=%v instead "+
1230+
"of current height=%d", pi.OutPoint(), locktime,
1231+
s.currentHeight)
1232+
}
1233+
1234+
return defaultDeadline
1235+
}
1236+
1237+
// handleNewInput processes a new input by registering spend notification and
1238+
// scheduling sweeping for it.
1239+
func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
12131240
outpoint := input.input.OutPoint()
12141241
pi, pending := s.inputs[outpoint]
12151242
if pending {
@@ -1234,15 +1261,22 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
12341261
Input: input.input,
12351262
params: input.params,
12361263
rbf: rbfInfo,
1237-
// Set the acutal deadline height.
1238-
DeadlineHeight: input.params.DeadlineHeight.UnwrapOr(
1239-
defaultDeadline,
1240-
),
12411264
}
12421265

1266+
// Set the acutal deadline height.
1267+
pi.DeadlineHeight = input.params.DeadlineHeight.UnwrapOr(
1268+
s.calculateDefaultDeadline(pi),
1269+
)
1270+
12431271
s.inputs[outpoint] = pi
12441272
log.Tracef("input %v, state=%v, added to inputs", outpoint, pi.state)
12451273

1274+
log.Infof("Registered sweep request at block %d: out_point=%v, "+
1275+
"witness_type=%v, amount=%v, deadline=%d, params=(%v)",
1276+
s.currentHeight, pi.OutPoint(), pi.WitnessType(),
1277+
btcutil.Amount(pi.SignDesc().Output.Value), pi.DeadlineHeight,
1278+
pi.params)
1279+
12461280
// Start watching for spend of this input, either by us or the remote
12471281
// party.
12481282
cancel, err := s.monitorSpend(
@@ -1656,7 +1690,7 @@ func (s *UtxoSweeper) handleBumpEventTxFailed(resp *bumpResp) {
16561690
r := resp.result
16571691
tx, err := r.Tx, r.Err
16581692

1659-
log.Errorf("Fee bump attempt failed for tx=%v: %v", tx.TxHash(), err)
1693+
log.Warnf("Fee bump attempt failed for tx=%v: %v", tx.TxHash(), err)
16601694

16611695
// NOTE: When marking the inputs as failed, we are using the input set
16621696
// instead of the inputs found in the tx. This is fine for current

sweep/sweeper_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ func TestHandleBumpEventTxFailed(t *testing.T) {
739739

740740
// Call the method under test.
741741
err := s.handleBumpEvent(resp)
742-
require.ErrorIs(t, err, errDummy)
742+
require.NoError(t, err)
743743

744744
// Assert the states of the first two inputs are updated.
745745
require.Equal(t, PublishFailed, s.inputs[op1].state)

0 commit comments

Comments
 (0)