mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 03:01:52 +01:00
sweep: make sure defaultDeadline is derived from the mature height
This commit is contained in:
parent
afc08c6623
commit
7545bbfa92
@ -530,7 +530,7 @@ func (s *UtxoSweeper) SweepInput(inp input.Input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
absoluteTimeLock, _ := inp.RequiredLockTime()
|
absoluteTimeLock, _ := inp.RequiredLockTime()
|
||||||
log.Infof("Sweep request received: out_point=%v, witness_type=%v, "+
|
log.Debugf("Sweep request received: out_point=%v, witness_type=%v, "+
|
||||||
"relative_time_lock=%v, absolute_time_lock=%v, amount=%v, "+
|
"relative_time_lock=%v, absolute_time_lock=%v, amount=%v, "+
|
||||||
"parent=(%v), params=(%v)", inp.OutPoint(), inp.WitnessType(),
|
"parent=(%v), params=(%v)", inp.OutPoint(), inp.WitnessType(),
|
||||||
inp.BlocksToMaturity(), absoluteTimeLock,
|
inp.BlocksToMaturity(), absoluteTimeLock,
|
||||||
@ -736,7 +736,18 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) {
|
|||||||
inputs := s.updateSweeperInputs()
|
inputs := s.updateSweeperInputs()
|
||||||
|
|
||||||
log.Debugf("Received new block: height=%v, attempt "+
|
log.Debugf("Received new block: height=%v, attempt "+
|
||||||
"sweeping %d inputs", epoch.Height, len(inputs))
|
"sweeping %d inputs:\n%s",
|
||||||
|
epoch.Height, len(inputs),
|
||||||
|
lnutils.NewLogClosure(func() string {
|
||||||
|
inps := make(
|
||||||
|
[]input.Input, 0, len(inputs),
|
||||||
|
)
|
||||||
|
for _, in := range inputs {
|
||||||
|
inps = append(inps, in)
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputTypeSummary(inps)
|
||||||
|
}))
|
||||||
|
|
||||||
// Attempt to sweep any pending inputs.
|
// Attempt to sweep any pending inputs.
|
||||||
s.sweepPendingInputs(inputs)
|
s.sweepPendingInputs(inputs)
|
||||||
@ -1207,13 +1218,29 @@ func (s *UtxoSweeper) mempoolLookup(op wire.OutPoint) fn.Option[wire.MsgTx] {
|
|||||||
return s.cfg.Mempool.LookupInputMempoolSpend(op)
|
return s.cfg.Mempool.LookupInputMempoolSpend(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleNewInput processes a new input by registering spend notification and
|
// calculateDefaultDeadline calculates the default deadline height for a sweep
|
||||||
// scheduling sweeping for it.
|
// request that has no deadline height specified.
|
||||||
func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
|
func (s *UtxoSweeper) calculateDefaultDeadline(pi *SweeperInput) int32 {
|
||||||
// Create a default deadline height, which will be used when there's no
|
// Create a default deadline height, which will be used when there's no
|
||||||
// DeadlineHeight specified for a given input.
|
// DeadlineHeight specified for a given input.
|
||||||
defaultDeadline := s.currentHeight + int32(s.cfg.NoDeadlineConfTarget)
|
defaultDeadline := s.currentHeight + int32(s.cfg.NoDeadlineConfTarget)
|
||||||
|
|
||||||
|
// If the input is immature and has a locktime, we'll use the locktime
|
||||||
|
// height as the starting height.
|
||||||
|
matured, locktime := pi.isMature(uint32(s.currentHeight))
|
||||||
|
if !matured {
|
||||||
|
defaultDeadline = int32(locktime + s.cfg.NoDeadlineConfTarget)
|
||||||
|
log.Debugf("Input %v is immature, using locktime=%v instead "+
|
||||||
|
"of current height=%d", pi.OutPoint(), locktime,
|
||||||
|
s.currentHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultDeadline
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleNewInput processes a new input by registering spend notification and
|
||||||
|
// scheduling sweeping for it.
|
||||||
|
func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
|
||||||
outpoint := input.input.OutPoint()
|
outpoint := input.input.OutPoint()
|
||||||
pi, pending := s.inputs[outpoint]
|
pi, pending := s.inputs[outpoint]
|
||||||
if pending {
|
if pending {
|
||||||
@ -1238,15 +1265,22 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
|
|||||||
Input: input.input,
|
Input: input.input,
|
||||||
params: input.params,
|
params: input.params,
|
||||||
rbf: rbfInfo,
|
rbf: rbfInfo,
|
||||||
// Set the acutal deadline height.
|
|
||||||
DeadlineHeight: input.params.DeadlineHeight.UnwrapOr(
|
|
||||||
defaultDeadline,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the acutal deadline height.
|
||||||
|
pi.DeadlineHeight = input.params.DeadlineHeight.UnwrapOr(
|
||||||
|
s.calculateDefaultDeadline(pi),
|
||||||
|
)
|
||||||
|
|
||||||
s.inputs[outpoint] = pi
|
s.inputs[outpoint] = pi
|
||||||
log.Tracef("input %v, state=%v, added to inputs", outpoint, pi.state)
|
log.Tracef("input %v, state=%v, added to inputs", outpoint, pi.state)
|
||||||
|
|
||||||
|
log.Infof("Registered sweep request at block %d: out_point=%v, "+
|
||||||
|
"witness_type=%v, amount=%v, deadline=%d, params=(%v)",
|
||||||
|
s.currentHeight, pi.OutPoint(), pi.WitnessType(),
|
||||||
|
btcutil.Amount(pi.SignDesc().Output.Value), pi.DeadlineHeight,
|
||||||
|
pi.params)
|
||||||
|
|
||||||
// Start watching for spend of this input, either by us or the remote
|
// Start watching for spend of this input, either by us or the remote
|
||||||
// party.
|
// party.
|
||||||
cancel, err := s.monitorSpend(
|
cancel, err := s.monitorSpend(
|
||||||
@ -1660,7 +1694,7 @@ func (s *UtxoSweeper) handleBumpEventTxFailed(resp *bumpResp) {
|
|||||||
r := resp.result
|
r := resp.result
|
||||||
tx, err := r.Tx, r.Err
|
tx, err := r.Tx, r.Err
|
||||||
|
|
||||||
log.Errorf("Fee bump attempt failed for tx=%v: %v", tx.TxHash(), err)
|
log.Warnf("Fee bump attempt failed for tx=%v: %v", tx.TxHash(), err)
|
||||||
|
|
||||||
// NOTE: When marking the inputs as failed, we are using the input set
|
// NOTE: When marking the inputs as failed, we are using the input set
|
||||||
// instead of the inputs found in the tx. This is fine for current
|
// instead of the inputs found in the tx. This is fine for current
|
||||||
|
@ -739,7 +739,7 @@ func TestHandleBumpEventTxFailed(t *testing.T) {
|
|||||||
|
|
||||||
// Call the method under test.
|
// Call the method under test.
|
||||||
err := s.handleBumpEvent(resp)
|
err := s.handleBumpEvent(resp)
|
||||||
require.ErrorIs(t, err, errDummy)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assert the states of the first two inputs are updated.
|
// Assert the states of the first two inputs are updated.
|
||||||
require.Equal(t, PublishFailed, s.inputs[op1].state)
|
require.Equal(t, PublishFailed, s.inputs[op1].state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user