-
Notifications
You must be signed in to change notification settings - Fork 432
Expose channel_reserve_satoshis via ChannelParameters
#4319
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
base: main
Are you sure you want to change the base?
Expose channel_reserve_satoshis via ChannelParameters
#4319
Conversation
|
👋 Thanks for assigning @tnull as a reviewer! |
cd475ee to
2f585af
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4319 +/- ##
==========================================
- Coverage 86.08% 86.08% -0.01%
==========================================
Files 156 156
Lines 102428 102433 +5
Branches 102428 102433 +5
==========================================
+ Hits 88179 88183 +4
- Misses 11754 11757 +3
+ Partials 2495 2493 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
🔔 1st Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
1 similar comment
|
🔔 1st Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
1 similar comment
|
🔔 2nd Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
|
@tnull @dunxen @TheBlueMatt please review 🙏 |
|
🔔 3rd Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
1 similar comment
|
🔔 3rd Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
|
🔔 4th Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
1 similar comment
|
🔔 4th Reminder Hey @valentinewallace @tankyleo! This PR has been waiting for your review. |
valentinewallace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically looks good. Probably good if @tankyleo takes a look since he's working on channel reserve stuff
2f585af to
e8cabf3
Compare
Add `channel_reserve_satoshis: Option<u64>` to `ChannelParameters` so users can access the counterparty's channel reserve when handling the `OpenChannelRequest` event. For V1 channels (`open_channel`), this returns `Some(value)` with the explicit reserve from the message. For V2 channels (`open_channel2`), this returns `None` because the reserve is calculated as `max(1% of total_channel_value, dust_limit)` per spec, where total_channel_value includes both parties' funding. Since the acceptor's contribution is unknown at `OpenChannelRequest` time, the final reserve cannot be determined. Move `channel_parameters()` from `CommonOpenChannelFields` to separate implementations on `OpenChannel` and `OpenChannelV2` to handle the V1/V2 difference correctly. Fixes lightningdevkit#3909
e8cabf3 to
48a70a8
Compare
tankyleo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR excuse the delay on my side ! I'll ping tnull as well since he is a consumer of this API and opened the issue in the first place
| pub(super) fn channel_parameters(&self) -> msgs::ChannelParameters { | ||
| let (common_fields, channel_reserve_satoshis) = match self { | ||
| Self::V1(msg) => (&msg.common_fields, Some(msg.channel_reserve_satoshis)), | ||
| Self::V2(msg) => (&msg.common_fields, None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite still passes if I set this to Some(0), let's add coverage for the V2 case.
| // For V1 channels, channel_reserve_satoshis should be Some with the value from the message | ||
| assert_eq!( | ||
| params.channel_reserve_satoshis, | ||
| Some(expected_reserve), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described elsewhere, let's also add coverage for the V2 case
| /// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel. | ||
| /// | ||
| /// For V1 channels (`open_channel`), this is the explicit `channel_reserve_satoshis` value | ||
| /// from the counterparty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described above, this is a subset of CommonOpenChannelFields, and the channel_reserve_satoshis of the OpenChannel message actually sets the minimum value that the non-channel-initiator must keep in the channel, and not the counterparty (as long as we define the counterparty here to be the sender of the OpenChannel message).
| /// the final reserve value cannot be determined at that point. | ||
| /// | ||
| /// [`Event::OpenChannelRequest`]: crate::events::Event::OpenChannelRequest | ||
| pub channel_reserve_satoshis: Option<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question for @tnull : OpenChannelV2 drops both the channel_reserve_satoshis, and push_msat fields. For the push_msats field, we currently handle this transition in the OpenChannelRequest event with an InboundChannelFunds enum, with PushMsat(u64) as the V1 variant, and DualFunded as the V2 variant.
We also note for InboundChannelFunds that it "allows the differentiation between a request for a dual-funded and non-dual-funded channel."
Seems to me now we can also differentiate V1 vs V2 based on the channel_reserve_satohis field.
To keep things consistent, would it be worth moving push_msats to ChannelParameters too, and set it to None in the V2 case, like we are doing here for channel_reserve_satoshis ?
Summary
channel_reserve_satoshis: Option<u64>field toChannelParametersstructSome(value)with the explicit reserve fromopen_channelmessageNonesince reserve is calculated from total channel value (initiator + acceptor funding), which isn't known atOpenChannelRequesttimechannel_parameters()fromCommonOpenChannelFieldsto individualOpenChannelandOpenChannelV2impls to handle V1/V2 difference correctlytest_open_channel_request_channel_reserve_satoshisto verify the implementationFixes #3909
Revives the closed PR #3910 with the approach suggested by reviewers:
Option<u64>instead of trying to read from wire for V2 (which doesn't have this field)channel_parameters()toOpenChannel/OpenChannelV2Test plan
cargo check -p lightningpassescargo test -p lightning --lib)test_open_channel_request_channel_reserve_satoshisvalidates V1 channels correctly populate the fieldchannel_open_testspass🤖 Generated with Claude Code