Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: sweep: LinearFeeFunction off by one #8741

Closed
morehouse opened this issue May 8, 2024 · 6 comments · Fixed by #8751
Closed

[bug]: sweep: LinearFeeFunction off by one #8741

morehouse opened this issue May 8, 2024 · 6 comments · Fixed by #8751
Assignees
Labels
bug Unintended code behaviour fees Related to the fees paid for transactions (both LN and funding/commitment transactions) P1 MUST be fixed or reviewed utxo sweeping
Milestone

Comments

@morehouse
Copy link
Collaborator

LinearFeeFunction doesn't return the max fee rate until after the deadline has been missed.

Example

Current block height is H. An incoming HTLC has a cltv_expiry of H + 10, so the contractcourt sets deadline := H + 10 for the HTLC input.

We need to confirm our HTLC-Preimage no later than block H + 10, or else we'll get into a bidding war with the channel peer since they can spend the timeout path after block H + 10 confirms.

LinearFeeFunction should max out its fee rate after block H + 9 confirms since this is the last shot at meeting the deadline. Instead, LinearFeeFunction waits to max out the fee rate until block H + 10.

Severity

For typical deadlines 10+ blocks away, this is a minor problem. But in the extreme case of a next-block deadline, LinearFeeFunction will return the min feerate instead of the max, which is quite bad.

@morehouse morehouse added bug Unintended code behaviour fees Related to the fees paid for transactions (both LN and funding/commitment transactions) utxo sweeping needs triage labels May 8, 2024
@Crypt-iQ
Copy link
Collaborator

Crypt-iQ commented May 9, 2024

@saubyk add to 18.0?

@saubyk saubyk added this to the v0.18.0 milestone May 9, 2024
@saubyk saubyk added the P1 MUST be fixed or reviewed label May 9, 2024
@saubyk
Copy link
Collaborator

saubyk commented May 9, 2024

@saubyk add to 18.0?

makes sense. added.

@saubyk
Copy link
Collaborator

saubyk commented May 9, 2024

cc: @yyforyongyu

@yyforyongyu
Copy link
Collaborator

But in the extreme case of a next-block deadline, LinearFeeFunction will return the min feerate instead of the max, which is quite bad.

What do you mean by saying next-block deadline? That we only have 1 block left till it times out? What is this min feerate?

@morehouse
Copy link
Collaborator Author

What do you mean by saying next-block deadline? That we only have 1 block left till it times out? What is this min feerate?

Here's an example graph of the LinearFeeFunction. The min feerate is the starting feerate. The max feerate is the ending feerate.

image

Now imagine we call SweepInput with a deadline 1 block away. The fee function will be initialized with a width of 1 and starting feerate at the minimum of the feerate line. After 1 block (i.e. deadline missed), the feerate will be immediately bumped to the maximum of the feerate line.

But for this next-block deadline case, we really don't want a sloped line at all -- we want to start right at the maximum.

@perrytheveganancap
Copy link

func (l *LinearFeeFunction) feeRateAtPosition(p uint32) chainfee.SatPerKWeight {
if p >= l.width - 1 {
return l.endingFeeRate
}
...
}
does this suggestion fix the issue located in /sweep/fee_function.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unintended code behaviour fees Related to the fees paid for transactions (both LN and funding/commitment transactions) P1 MUST be fixed or reviewed utxo sweeping
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants