Skip to content

feat: expose channel_reserve_satoshis via ChannelParameters #3910

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Prabhat1308
Copy link
Contributor

fixes #3909

exposes channel_reserve_satoshis by adding it to ChannelParameters and CommonAcceptChannelFields for the user to ascertain the value set by the counterparty

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jul 3, 2025

I've assigned @wpaulino as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot ldk-reviews-bot requested a review from wpaulino July 3, 2025 13:38
exposes channel_reserve_satoshis by adding it to CommonAcceptChannelFields for the user to ascertain the value set by the counterparty
Copy link

codecov bot commented Jul 3, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.80%. Comparing base (257ebad) to head (8332a7a).

Files with missing lines Patch % Lines
lightning/src/ln/msgs.rs 25.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3910      +/-   ##
==========================================
- Coverage   88.82%   88.80%   -0.03%     
==========================================
  Files         165      165              
  Lines      119075   119083       +8     
  Branches   119075   119083       +8     
==========================================
- Hits       105774   105749      -25     
- Misses      10981    11006      +25     
- Partials     2320     2328       +8     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -3072,6 +3078,7 @@ impl LengthReadable for OpenChannelV2 {
let dust_limit_satoshis: u64 = Readable::read(r)?;
let max_htlc_value_in_flight_msat: u64 = Readable::read(r)?;
let htlc_minimum_msat: u64 = Readable::read(r)?;
let channel_reserve_satoshis: u64 = Readable::read(r)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't do this, as OpenChannelV2 doesn't have that field, see https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel2-message

It's also not a 'common' field per se as per spec:

Note that open_channel's channel_reserve_satoshi has been omitted. Instead, the channel reserve is fixed at 1% of the total channel balance (open_channel2.funding_satoshis + accept_channel2.funding_satoshis) rounded down to the nearest whole satoshi or the dust_limit_satoshis, whichever is greater.

Copy link
Contributor

Choose a reason for hiding this comment

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

The best bet would be to have a new top-level field in OpenChannelRequest for channel_reserve_satoshis and then set that in channelmanager like:

channel_reserve_satoshis: match msg {
    OpenChannelMessageRef::V1(msg) => msg.channel_reserve_satoshis,
    OpenChannelMessageRef::V2(msg) => get_v2_channel_reserve_satoshis(
        channel_value_satoshis, msg.common_fields.dust_limit_satoshis
    );
},

The get_v2_channel_reserve_satoshis exists in the channel module. You'd need to make that pub(super).

This would be a breaking change and also would need docs and shouldn't be backported.

Copy link
Contributor

@tnull tnull Jul 4, 2025

Choose a reason for hiding this comment

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

The best bet would be to have a new top-level field in OpenChannelRequest

Hmm, while that would be pretty easy, I'm not super happy about exposing such a detail at the top level API, especially if we have sub-structs in-place. can't we reuse ChannelParameters still, but apply above rules for v2 channels? Or, maybe it would be the right time to refactor OpenChannelRequest (or ChannelParameters) to discern between V1 and V2 channels?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah you could reuse ChannelParameters and just have the field there, update the doc comment for it as it currently mentions being a subset of the common fields. It will just need to be initialised as 0 in CommonOpenChannelFields::channel_parameters and then set like above when creating the OpenChannelRequest event. I'm not sure an Option is worth the effort as it'll always end up being Some() when accessed by the user.

Refactoring is fine, but we'd want to still have a single OpenChannelRequest event.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @wpaulino! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

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.

Expose channel_reserve_satoshis via ChannelParameters in OpenChannelRequest
4 participants