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

Anchor outputs fee fixes #2587

Merged
merged 3 commits into from
Sep 19, 2023
Merged

Conversation

wpaulino
Copy link
Contributor

This PR attempts to address a few bugs discovered by @TheBlueMatt while using anchor outputs channels.

Fixes #2586.

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2023

Codecov Report

Patch coverage: 94.11% and project coverage change: -1.85% ⚠️

Comparison is base (36af1f0) 90.61% compared to head (9736c70) 88.77%.
Report is 4 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2587      +/-   ##
==========================================
- Coverage   90.61%   88.77%   -1.85%     
==========================================
  Files         113      113              
  Lines       59251    84489   +25238     
  Branches    59251    84489   +25238     
==========================================
+ Hits        53693    75007   +21314     
- Misses       5558     7256    +1698     
- Partials        0     2226    +2226     
Files Changed Coverage Δ
lightning/src/chain/package.rs 86.00% <50.00%> (-6.00%) ⬇️
lightning/src/events/bump_transaction.rs 82.33% <100.00%> (+4.78%) ⬆️

... and 111 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TheBlueMatt TheBlueMatt added this to the 0.0.117 milestone Sep 18, 2023
TheBlueMatt
TheBlueMatt previously approved these changes Sep 18, 2023
Since we don't know the total input amount of an external claim (those
which come anchor channels), we can't limit our feerate bumps by the
amount of funds we have available to use. Instead, we choose to limit it
by a margin of the new feerate estimate.
We'd previously ignore the existing amount transactions were already
attempting to spend when deciding whether we should add more inputs
throughout coin selection. This would result in us attaching more inputs
than necessary to satisfy our target amount. In the case of HTLC
transactions, we'd burn the HTLC amount completely, since the pre-signed
transaction has zero fee (input amount == output amount).

Along the way, we also fix the slight overpayment in anchor
transactions. We now properly account for the fees the transaction
already paid for, simply by pretending the fees are part of the anchor
input amount.
We add a few debug assertions to ensure we don't overpay fees by 5% more
than expected.
@TheBlueMatt TheBlueMatt merged commit 7e7e7a0 into lightningdevkit:main Sep 19, 2023
15 checks passed
@wpaulino wpaulino deleted the anchors-fee-fixes branch September 19, 2023 21:01
// estimate.
let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::max_value());
let mut new_feerate = previous_feerate.saturating_add(previous_feerate / 4);
if new_feerate > feerate_estimate * 5 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, the new code now upper bounds our effective new_feeratee to a multiplicand of feerate_estimate. If FeeEstimator is broken or our underlying inbound transaction-relay has been partitioned from the rest of the network and the sat_per_1000_weight we got is 1 sat-per-byte, we might never confirm our transaction ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. There's not really anything else we can do - I hit a case where a commitment transaction didn't get into the mempool because of its low feerate, and the package logic here ended up reaching a feerate of u32::max_value(), which would have spent all available funds on one transaction the second the commitment transaction got into the mempool. Even after package relay a similar issue exists if the user is offline for some time. Trusting the fee estimator sucks, indeed, but spending all available user funds on a single transaction sucks more. We could bump the minimum here to add a constant and ignore the fee estimator if the constant is > feerate_estimate * 5, but that's really the best we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anchor HTLC claims burn the HTLC value
5 participants