Skip to content

Commit d09c572

Browse files
committed
Fix reachable unwrap of outbound_htlc_minimum_msat
As the `unwrap` previously was reachable we now expose the field as an `Option`. Additionally, we document the unwrap safety of the other `ChannelDetails` fields where applicable.
1 parent 8b9983a commit d09c572

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ dictionary ChannelDetails {
204204
boolean is_public;
205205
u16? cltv_expiry_delta;
206206
u64 counterparty_unspendable_punishment_reserve;
207-
u64 counterparty_outbound_htlc_minimum_msat;
207+
u64? counterparty_outbound_htlc_minimum_msat;
208208
u64? counterparty_outbound_htlc_maximum_msat;
209209
u32? counterparty_forwarding_info_fee_base_msat;
210210
u32? counterparty_forwarding_info_fee_proportional_millionths;

src/types.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ pub struct ChannelDetails {
210210
/// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
211211
pub counterparty_unspendable_punishment_reserve: u64,
212212
/// The smallest value HTLC (in msat) the remote peer will accept, for this channel.
213-
pub counterparty_outbound_htlc_minimum_msat: u64,
213+
///
214+
/// This field is only `None` before we have received either the `OpenChannel` or
215+
/// `AcceptChannel` message from the remote peer.
216+
pub counterparty_outbound_htlc_minimum_msat: Option<u64>,
214217
/// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
215218
pub counterparty_outbound_htlc_maximum_msat: Option<u64>,
216219
/// Base routing fee in millisatoshis.
@@ -258,6 +261,8 @@ impl From<LdkChannelDetails> for ChannelDetails {
258261
channel_value_sats: value.channel_value_satoshis,
259262
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
260263
user_channel_id: UserChannelId(value.user_channel_id),
264+
// unwrap safety: This value will be `None` for objects serialized with LDK versions
265+
// prior to 0.0.115.
261266
feerate_sat_per_1000_weight: value.feerate_sat_per_1000_weight.unwrap(),
262267
balance_msat: value.balance_msat,
263268
outbound_capacity_msat: value.outbound_capacity_msat,
@@ -272,10 +277,7 @@ impl From<LdkChannelDetails> for ChannelDetails {
272277
counterparty_unspendable_punishment_reserve: value
273278
.counterparty
274279
.unspendable_punishment_reserve,
275-
counterparty_outbound_htlc_minimum_msat: value
276-
.counterparty
277-
.outbound_htlc_minimum_msat
278-
.unwrap(),
280+
counterparty_outbound_htlc_minimum_msat: value.counterparty.outbound_htlc_minimum_msat,
279281
counterparty_outbound_htlc_maximum_msat: value.counterparty.outbound_htlc_maximum_msat,
280282
counterparty_forwarding_info_fee_base_msat: value
281283
.counterparty
@@ -295,8 +297,10 @@ impl From<LdkChannelDetails> for ChannelDetails {
295297
next_outbound_htlc_limit_msat: value.next_outbound_htlc_limit_msat,
296298
next_outbound_htlc_minimum_msat: value.next_outbound_htlc_minimum_msat,
297299
force_close_spend_delay: value.force_close_spend_delay,
298-
inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat.unwrap(),
300+
// unwrap safety: This field is only `None` for objects serialized prior to LDK 0.0.107
301+
inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat.unwrap_or(0),
299302
inbound_htlc_maximum_msat: value.inbound_htlc_maximum_msat,
303+
// unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109.
300304
config: value.config.map(|c| Arc::new(c.into())).unwrap(),
301305
}
302306
}

0 commit comments

Comments
 (0)