Skip to content

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

Merged
wpaulino merged 2 commits into
lightningdevkit:mainfrom
optout21:funding-fee-estimation
Feb 13, 2025
Merged

Include base input fee in fee, in calculate_our_funding_satoshis()#3558
wpaulino merged 2 commits into
lightningdevkit:mainfrom
optout21:funding-fee-estimation

Conversation

@optout21

@optout21optout21 commented Jan 24, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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

@optout21
optout21force-pushed the funding-fee-estimation branch 2 times, most recently from 4a4ae72 to 27784d9CompareJanuary 24, 2025 21:28
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated

@dunxendunxen left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/channel.rs Outdated
@optout21
optout21force-pushed the funding-fee-estimation branch 3 times, most recently from 085455d to 61131beCompareJanuary 30, 2025 14:17
@optout21optout21 added the weekly goal Someone wants to land this this week label Jan 30, 2025
@optout21

Copy link
Copy Markdown
ContributorAuthor

Please consider for merging.

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadlightning/src/ln/channel.rs Outdated
@optout21
optout21force-pushed the funding-fee-estimation branch from 61131be to 95f1e9cCompareJanuary 30, 2025 17:59
@optout21

Copy link
Copy Markdown
ContributorAuthor

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

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please update PR description.

@wpaulinowpaulino left a comment

Copy link
Copy Markdown
Contributor

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).

Comment threadlightning/src/ln/channel.rs
@optout21

optout21 commented Jan 30, 2025

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

@optout21optout21 mentioned this pull request Jan 31, 2025
4 tasks
@optout21

optout21 commented Jan 31, 2025

Copy link
Copy Markdown
ContributorAuthor

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.

@codecov

codecovBot commented Jan 31, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 83.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.98%. Comparing base (2c3f11d) to head (2bb7aa2).
Report is 75 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channel.rs81.48%10 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #3558 +/- ##
==========================================
+ Coverage 88.53% 89.98% +1.44% 
==========================================
Files 149 149 Lines 114985 130021 +15036 Branches 114985 130021 +15036 ==========================================
+ Hits 101803 116998 +15195 + Misses 10693 10619 -74 + Partials 2489 2404 -85 

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

@optout21
optout21force-pushed the funding-fee-estimation branch from c3354b7 to f43c7c2CompareJanuary 31, 2025 14:54
@jkczyz

jkczyz commented Jan 31, 2025

Copy link
Copy Markdown
Contributor

Should this say #3407?

@optout21

optout21 commented Jan 31, 2025

Copy link
Copy Markdown
ContributorAuthor

Should this say #3407?

Of course, my bad, corrected

@jkczyz

Copy link
Copy Markdown
Contributor

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

@wpaulino

Copy link
Copy Markdown
Contributor

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

@optout21
optout21force-pushed the funding-fee-estimation branch from f43c7c2 to 05c38eeCompareFebruary 5, 2025 20:43
@optout21

Copy link
Copy Markdown
ContributorAuthor

Squashed into the two commits.

@wpaulinowpaulino left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadlightning/src/ln/channel.rs Outdated
@optout21
optout21force-pushed the funding-fee-estimation branch from 05c38ee to 45776d3CompareFebruary 6, 2025 18:07
@optout21optout21 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
optout21force-pushed the funding-fee-estimation branch from 45776d3 to f61cdbeCompareFebruary 7, 2025 07:25
@optout21optout21 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
optout21force-pushed the funding-fee-estimation branch from f61cdbe to d4de817CompareFebruary 7, 2025 07:30
@optout21

Copy link
Copy Markdown
ContributorAuthor

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.

@jkczyz

Copy link
Copy Markdown
Contributor

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.

LGTM, but looks like the commit descriptions are still over 72 characters. Could you re-wrap? FYI, we should use these guidelines: https://cbea.ms/git-commit/.

The base input fee was missing in calculate_our_funding_satoshis(),
it is added now; also add unit test.
@optout21
optout21force-pushed the funding-fee-estimation branch from 6be2e8a to 2bb7aa2CompareFebruary 11, 2025 08:35
@optout21

Copy link
Copy Markdown
ContributorAuthor

LGTM, but looks like the commit descriptions are still over 72 characters. Could you re-wrap? FYI, we should use these guidelines: https://cbea.ms/git-commit/.

Commit msgs adjusted!

Comment threadlightning/src/ln/channel.rs Outdated
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
optout21force-pushed the funding-fee-estimation branch from 2bb7aa2 to c29ec0fCompareFebruary 12, 2025 06:36
@wpaulino
wpaulino merged commit 7cf95e1 into lightningdevkit:mainFeb 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

weekly goalSomeone wants to land this this week

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@optout21@wpaulino@jkczyz@dunxen