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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9295,7 +9295,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
},
channel_type,
is_announced,
params: common_fields.channel_parameters(),
params: match msg {
OpenChannelMessageRef::V1(msg) => msg.channel_parameters(),
OpenChannelMessageRef::V2(msg) => msg.channel_parameters(),
},
}, None));
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
open_channel_msg: match msg {
Expand Down
50 changes: 36 additions & 14 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,6 @@ pub struct CommonOpenChannelFields {
pub channel_type: Option<ChannelTypeFeatures>,
}

impl CommonOpenChannelFields {
/// The [`ChannelParameters`] for this channel.
pub fn channel_parameters(&self) -> ChannelParameters {
ChannelParameters {
dust_limit_satoshis: self.dust_limit_satoshis,
max_htlc_value_in_flight_msat: self.max_htlc_value_in_flight_msat,
htlc_minimum_msat: self.htlc_minimum_msat,
commitment_feerate_sat_per_1000_weight: self.commitment_feerate_sat_per_1000_weight,
to_self_delay: self.to_self_delay,
max_accepted_htlcs: self.max_accepted_htlcs,
}
}
}

/// A subset of [`CommonOpenChannelFields`], containing various parameters which are set by the
/// channel initiator and which are not part of the channel funding transaction.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
Expand All @@ -280,6 +266,8 @@ pub struct ChannelParameters {
pub to_self_delay: u16,
/// The maximum number of pending HTLCs towards the channel initiator.
pub max_accepted_htlcs: u16,
/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
pub channel_reserve_satoshis: Option<u64>,
}

/// An [`open_channel`] message to be sent to or received from a peer.
Expand All @@ -297,6 +285,23 @@ pub struct OpenChannel {
pub channel_reserve_satoshis: u64,
}

impl OpenChannel {
/// The [`ChannelParameters`] for this V1 channel.
pub fn channel_parameters(&self) -> ChannelParameters {
ChannelParameters {
dust_limit_satoshis: self.common_fields.dust_limit_satoshis,
max_htlc_value_in_flight_msat: self.common_fields.max_htlc_value_in_flight_msat,
htlc_minimum_msat: self.common_fields.htlc_minimum_msat,
commitment_feerate_sat_per_1000_weight: self
.common_fields
.commitment_feerate_sat_per_1000_weight,
to_self_delay: self.common_fields.to_self_delay,
max_accepted_htlcs: self.common_fields.max_accepted_htlcs,
channel_reserve_satoshis: Some(self.channel_reserve_satoshis),
}
}
}

/// An [`open_channel2`] message to be sent by or received from the channel initiator.
///
/// Used in V2 channel establishment
Expand All @@ -316,6 +321,23 @@ pub struct OpenChannelV2 {
pub require_confirmed_inputs: Option<()>,
}

impl OpenChannelV2 {
/// The [`ChannelParameters`] for this V2 channel.
pub fn channel_parameters(&self) -> ChannelParameters {
ChannelParameters {
dust_limit_satoshis: self.common_fields.dust_limit_satoshis,
max_htlc_value_in_flight_msat: self.common_fields.max_htlc_value_in_flight_msat,
htlc_minimum_msat: self.common_fields.htlc_minimum_msat,
commitment_feerate_sat_per_1000_weight: self
.common_fields
.commitment_feerate_sat_per_1000_weight,
to_self_delay: self.common_fields.to_self_delay,
max_accepted_htlcs: self.common_fields.max_accepted_htlcs,
channel_reserve_satoshis: None, // V2 doesn't have this field
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think this is confusing, as there will be a channel reserve, albeit a hard-coded one. I think we'd need to calculate that 1% value here, no?

Copy link
Contributor

@dunxen dunxen Aug 4, 2025

Choose a reason for hiding this comment

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

Note that this would only be calculable once we know the acceptor's funding_satoshis as it is based off the combined initiator and acceptor funding_satoshis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I might be missing something . I have a few questions on this.

  1. initiator sends OpenChannelV2 and then Acceptor sends AcceptChannelv2. If this is the case , we would never know the acceptor's funding_satoshis and hence this will always be a None (meaning we dont know yet instead of it does not exist for OpenChannelV2).
  2. both the handle functions for the channels (open/accept) says that dual-funding is not supported. Even if I get the value of acceptor's funding_satoshis , I am not getting a expected response but an error ?

}
}
}

/// Contains fields that are both common to [`accept_channel`] and [`accept_channel2`] messages.
///
/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message
Expand Down
Loading