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

Include base input fee in fee, in calculate_our_funding_satoshis() #3558

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

optout21
Copy link
Contributor

@optout21 optout21 commented Jan 24, 2025

It was found that the (still-unused) calculate_our_funding_satoshis() method doesn't take into account the base weight of the inputs in the fee estimation.
It was also found that this method also misses the intended funding amount.

This change:

  • Adds the base weight for inputs to the fee estimation, and adds a unit test
  • Breaks up calculate_our_funding_satoshis() into two, estimate_funding_transaction_fee(), and the output calculation. This is to allow using funding tx fee estimation, needed also by splicing (see [Splicing] Partial, handle splice_init & splice_ack messages #3407).
  • Cleans up calculate_our_funding_satoshis(), as it's not used and misses the intended funding amount.

Note: this was triggered by work on splicing (#3407),

@optout21
Copy link
Contributor Author

Note: #3407 also include this change, I will take care of merge if needed regardless of which PR is merged first.

@optout21 optout21 force-pushed the funding-fee-estimation branch 2 times, most recently from 4a4ae72 to 27784d9 Compare January 24, 2025 21:28
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Basically LGTM, modulo Jeff's remaining comments.

lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@optout21 optout21 force-pushed the funding-fee-estimation branch 3 times, most recently from 085455d to 61131be Compare January 30, 2025 14:17
@optout21 optout21 added the weekly goal Someone wants to land this this week label Jan 30, 2025
@optout21
Copy link
Contributor Author

Please consider for merging.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

Could you re-organize the commits a bit? Let's do two commits where the first one contains the the base input fee fix and the new test. The second commit can contain the refactor and related test changes.

lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@optout21 optout21 force-pushed the funding-fee-estimation branch from 61131be to 95f1e9c Compare January 30, 2025 17:59
@optout21
Copy link
Contributor Author

Let's do two commits where the first one contains the the base input fee fix and the new test. The second commit can contain the refactor and related test changes.

Commits reorganized

jkczyz
jkczyz previously approved these changes Jan 30, 2025
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

Please update PR description.

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

I had a look at how calculate_our_funding_satoshis is used and I'm a bit confused. For an inbound channel, we should have the user provide us the amount they want to contribute, along with the inputs, and we should make sure the inputs provided can cover their intended contribution amount after fees, etc. We shouldn't assume the user always wants to contribute as much as possible from their inputs (e.g., like send-all in an onchain wallet). So we basically want two modes: ContributeAll(inputs) and ContributeAmount(amount, inputs, change_address).

lightning/src/ln/channel.rs Show resolved Hide resolved
@optout21
Copy link
Contributor Author

optout21 commented Jan 30, 2025

I had a look at how calculate_our_funding_satoshis is used and I'm a bit confused. ...

I'm also a bit confused.
The calculate_our_funding_satoshis is currently used in dual funding channel open, on the acceptor side only. Moreover, currently the provided inputs are hardcoded to be none, so this method is not effectively used.

The method computes the contributed inputs minus the proportional fees, that is, how much we could contribute to the funding with these inputs. If that's below dust, it means these inputs make no economic sense (BTW the error message is not very specific).
But indeed, I don't see here the distinction between the amount we contribute in the inputs and the amount we intend to contribute. Also, there is no information about eventual change (destination).

As currently there is no way to specify contributing inputs on the acceptor side, this logic is currently irrelevant. V2 opening as initiator is still missing entirely (still only in PR).

I made this spin-off to separate just the one-liner estimation fix.

@wpaulino
Copy link
Contributor

Let's just delete calculate_our_funding_satoshis then? We probably want to think more about how the data we need from the user is given to us, and the method will have to change a good bit by then anyway.

@optout21
Copy link
Contributor Author

optout21 commented Jan 31, 2025

Here's my conclusion:

  • calculate_our_funding_satoshis is conceptually unclear, as check should take into account intended funding amount as well. Besides, it's not used in the current form, so it's better to remove it now (to avoid confusion).
  • As contribution from acceptor is not supported, it's better to clean up the hardcoded empty values and the parameters in the level above.
  • estimate_v2_funding_transaction_fee: This is not used either, but since it's to be used soon ([Splicing] Partial, handle splice_init & splice_ack messages #3407), and it has unit tests, I would keep it as done here.

Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 80.43478% with 9 lines in your changes missing coverage. Please review.

Project coverage is 88.92%. Comparing base (b1fc7d8) to head (f43c7c2).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 78.57% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3558      +/-   ##
==========================================
+ Coverage   88.53%   88.92%   +0.39%     
==========================================
  Files         149      149              
  Lines      114475   116677    +2202     
  Branches   114475   116677    +2202     
==========================================
+ Hits       101347   103757    +2410     
+ Misses      10634    10453     -181     
+ Partials     2494     2467      -27     

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

@optout21 optout21 force-pushed the funding-fee-estimation branch from c3354b7 to f43c7c2 Compare January 31, 2025 14:54
@jkczyz
Copy link
Contributor

jkczyz commented Jan 31, 2025

Should this say #3407?

@optout21
Copy link
Contributor Author

optout21 commented Jan 31, 2025

Should this say #3407?

Of course, my bad, corrected

@jkczyz
Copy link
Contributor

jkczyz commented Jan 31, 2025

@wpaulino If you're ok with this then I'd say we just squash this PR into one commit.

@wpaulino
Copy link
Contributor

wpaulino commented Feb 4, 2025

Yeah looks good, let's keep two commits though: one removing the dead code, and another with the bug fix.

@optout21 optout21 force-pushed the funding-fee-estimation branch from f43c7c2 to 05c38ee Compare February 5, 2025 20:43
@optout21
Copy link
Contributor Author

optout21 commented Feb 5, 2025

Squashed into the two commits.

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Sorry, last few nits: please keep commit messages to 72 characters max and include the rationale behind dropping calculate_our_funding_satoshis in the commit message

lightning/src/ln/channel.rs Outdated Show resolved Hide resolved
@optout21 optout21 force-pushed the funding-fee-estimation branch from 05c38ee to 45776d3 Compare February 6, 2025 18:07
@optout21 optout21 changed the title Include base input fee in fee, in calculate_our_funding_satoshis() Include base input fee in fee in calculate_our_funding_satoshis() Feb 7, 2025
@optout21 optout21 force-pushed the funding-fee-estimation branch from 45776d3 to f61cdbe Compare February 7, 2025 07:25
@optout21 optout21 changed the title Include base input fee in fee in calculate_our_funding_satoshis() Include base input fee in fee, in calculate_our_funding_satoshis() Feb 7, 2025
This method does not take into the intended funding amount, and it's not currently used,
therefore it's removed now. Its fee estimation part is kept (estimate_v2_funding_transaction_fee).
@optout21 optout21 force-pushed the funding-fee-estimation branch from f61cdbe to d4de817 Compare February 7, 2025 07:30
@optout21
Copy link
Contributor Author

optout21 commented Feb 7, 2025

Sorry, last few nits: please keep commit messages to 72 characters max and include the rationale behind dropping calculate_our_funding_satoshis in the commit message

Noted, commit msg/desc adjusted.

@optout21 optout21 requested a review from wpaulino February 7, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
weekly goal Someone wants to land this this week
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants