Skip to content

Commit d52cb88

Browse files
committed
expose CSR in ChannelParameters
exposes CSR in ChannelParameters and moves CommonOpenChannelFields::channel_parameters() to OpenChannelV1/V2::channel_parameters()
1 parent 61e5819 commit d52cb88

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8158,7 +8158,8 @@ where
81588158
ComplFunc: FnOnce(
81598159
Option<u64>,
81608160
bool,
8161-
) -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8161+
)
8162+
-> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
81628163
>(
81638164
&self, prev_hop: HTLCPreviousHopData, payment_preimage: PaymentPreimage,
81648165
payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
@@ -8188,7 +8189,8 @@ where
81888189
ComplFunc: FnOnce(
81898190
Option<u64>,
81908191
bool,
8191-
) -> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
8192+
)
8193+
-> (Option<MonitorUpdateCompletionAction>, Option<RAAMonitorUpdateBlockingAction>),
81928194
>(
81938195
&self, prev_hop: HTLCClaimSource, payment_preimage: PaymentPreimage,
81948196
payment_info: Option<PaymentClaimDetails>, attribution_data: Option<AttributionData>,
@@ -9295,7 +9297,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
92959297
},
92969298
channel_type,
92979299
is_announced,
9298-
params: common_fields.channel_parameters(),
9300+
params: match msg {
9301+
OpenChannelMessageRef::V1(msg) => msg.channel_parameters(),
9302+
OpenChannelMessageRef::V2(msg) => msg.channel_parameters(),
9303+
},
92999304
}, None));
93009305
peer_state.inbound_channel_request_by_id.insert(channel_id, InboundChannelRequest {
93019306
open_channel_msg: match msg {

lightning/src/ln/msgs.rs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,6 @@ pub struct CommonOpenChannelFields {
247247
pub channel_type: Option<ChannelTypeFeatures>,
248248
}
249249

250-
impl CommonOpenChannelFields {
251-
/// The [`ChannelParameters`] for this channel.
252-
pub fn channel_parameters(&self) -> ChannelParameters {
253-
ChannelParameters {
254-
dust_limit_satoshis: self.dust_limit_satoshis,
255-
max_htlc_value_in_flight_msat: self.max_htlc_value_in_flight_msat,
256-
htlc_minimum_msat: self.htlc_minimum_msat,
257-
commitment_feerate_sat_per_1000_weight: self.commitment_feerate_sat_per_1000_weight,
258-
to_self_delay: self.to_self_delay,
259-
max_accepted_htlcs: self.max_accepted_htlcs,
260-
}
261-
}
262-
}
263-
264250
/// A subset of [`CommonOpenChannelFields`], containing various parameters which are set by the
265251
/// channel initiator and which are not part of the channel funding transaction.
266252
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
@@ -280,6 +266,8 @@ pub struct ChannelParameters {
280266
pub to_self_delay: u16,
281267
/// The maximum number of pending HTLCs towards the channel initiator.
282268
pub max_accepted_htlcs: u16,
269+
/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel
270+
pub channel_reserve_satoshis: Option<u64>,
283271
}
284272

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

288+
impl OpenChannel {
289+
/// The [`ChannelParameters`] for this V1 channel.
290+
pub fn channel_parameters(&self) -> ChannelParameters {
291+
ChannelParameters {
292+
dust_limit_satoshis: self.common_fields.dust_limit_satoshis,
293+
max_htlc_value_in_flight_msat: self.common_fields.max_htlc_value_in_flight_msat,
294+
htlc_minimum_msat: self.common_fields.htlc_minimum_msat,
295+
commitment_feerate_sat_per_1000_weight: self
296+
.common_fields
297+
.commitment_feerate_sat_per_1000_weight,
298+
to_self_delay: self.common_fields.to_self_delay,
299+
max_accepted_htlcs: self.common_fields.max_accepted_htlcs,
300+
channel_reserve_satoshis: Some(self.channel_reserve_satoshis),
301+
}
302+
}
303+
}
304+
300305
/// An [`open_channel2`] message to be sent by or received from the channel initiator.
301306
///
302307
/// Used in V2 channel establishment
@@ -316,6 +321,23 @@ pub struct OpenChannelV2 {
316321
pub require_confirmed_inputs: Option<()>,
317322
}
318323

324+
impl OpenChannelV2 {
325+
/// The [`ChannelParameters`] for this V2 channel.
326+
pub fn channel_parameters(&self) -> ChannelParameters {
327+
ChannelParameters {
328+
dust_limit_satoshis: self.common_fields.dust_limit_satoshis,
329+
max_htlc_value_in_flight_msat: self.common_fields.max_htlc_value_in_flight_msat,
330+
htlc_minimum_msat: self.common_fields.htlc_minimum_msat,
331+
commitment_feerate_sat_per_1000_weight: self
332+
.common_fields
333+
.commitment_feerate_sat_per_1000_weight,
334+
to_self_delay: self.common_fields.to_self_delay,
335+
max_accepted_htlcs: self.common_fields.max_accepted_htlcs,
336+
channel_reserve_satoshis: None, // V2 doesn't have this field
337+
}
338+
}
339+
}
340+
319341
/// Contains fields that are both common to [`accept_channel`] and [`accept_channel2`] messages.
320342
///
321343
/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message
@@ -3531,7 +3553,8 @@ where
35313553
}),
35323554
} => {
35333555
if amt.is_some()
3534-
|| cltv_value.is_some() || total_msat.is_some()
3556+
|| cltv_value.is_some()
3557+
|| total_msat.is_some()
35353558
|| keysend_preimage.is_some()
35363559
|| invoice_request.is_some()
35373560
{
@@ -3681,7 +3704,8 @@ where
36813704
}),
36823705
} => {
36833706
if amt.is_some()
3684-
|| cltv_value.is_some() || total_msat.is_some()
3707+
|| cltv_value.is_some()
3708+
|| total_msat.is_some()
36853709
|| keysend_preimage.is_some()
36863710
|| invoice_request.is_some()
36873711
{

0 commit comments

Comments
 (0)