Skip to content

Correct handling of added OP_RETURN outputs #3285

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

Merged
merged 5 commits into from
Sep 3, 2024

Conversation

TheBlueMatt
Copy link
Collaborator

This fixes two bugs in handling of coin selections that don't contain change, both of them pretty minor (in part cause we'll always re-select soon anyway and that selection might well contain change) but also important.

@TheBlueMatt TheBlueMatt added this to the 0.0.124 milestone Sep 3, 2024
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 93.00000% with 14 lines in your changes missing coverage. Please review.

Project coverage is 89.82%. Comparing base (7e513f9) to head (5f5c275).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/events/bump_transaction.rs 92.13% 4 Missing and 10 partials ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #3285    +/-   ##
========================================
  Coverage   89.82%   89.82%            
========================================
  Files         126      126            
  Lines      103134   103449   +315     
  Branches   103134   103449   +315     
========================================
+ Hits        92643    92926   +283     
- Misses       7772     7800    +28     
- Partials     2719     2723     +4     

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

While these are consensus-valid, they have been nonstandard for
quite some time and will not relay nor confirm.
When we do coin selection for channel close anchor spends, we may
do coin selection targeting exactly the input values we need.
However, if coin selection does not include a change output, we may
add an OP_RETURN output, which may cause us to end up with less
fee than we wanted on the resulting package.

Here we address this issue by running coin selection twice - first
without seeking the extra weight of the OP_RETURN output, and again
if we find that we under-selected.
We should always select at least as many coins as is required to
meet the feerate target, but its perfectly fine if we overshoot.
Specifically, we may overshoot deliberately if we choose to burn
change to fee instead.
This adds a single test for coin selection which exercises the
issues fixed in the past three commits.
dunxen
dunxen previously approved these changes Sep 3, 2024
`ANCHOR_INPUT_WITNESS_WEIGHT` is too high by two weight units,
likely it was calculated to include the SegWit marker bytes, but
it is used to describe an `Input::satisfaction_weight`, which does
not expect the marker bytes.

This corrects that oversight, reducing the constant by two and
adding the marker bytes back in our own internal weight
calculations. It also fixes a second issue where the constant was
too low by one when `grind_signatures` is not set, as that may
result in a signature being one byte longer than we expect.
Copy link
Contributor

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

LGMT

@TheBlueMatt
Copy link
Collaborator Author

Ugh, build failed with grind_signatures unset, pushed another commit to fix it :/

@TheBlueMatt
Copy link
Collaborator Author

Note that I assume there is a similar bug in HTLC_SUCCESS_INPUT_ANCHOR_WITNESS_WEIGHT as is fixed in the last commit, but its not preventing a test from passing and it just results in us overpaying fees by 2 weight units per input, which is ~harmless. If people think the last commit here is right I'll open an issue to track it.

@TheBlueMatt TheBlueMatt merged commit 187a2cb into lightningdevkit:main Sep 3, 2024
18 of 20 checks passed
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.

4 participants