From 492762ef559ee6b35042ec8c788c135cca2e30d6 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 27 Nov 2023 13:34:52 +0100 Subject: [PATCH] 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. --- bindings/ldk_node.udl | 2 +- src/types.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bindings/ldk_node.udl b/bindings/ldk_node.udl index adb1f8e34..85f0865f5 100644 --- a/bindings/ldk_node.udl +++ b/bindings/ldk_node.udl @@ -204,7 +204,7 @@ dictionary ChannelDetails { boolean is_public; u16? cltv_expiry_delta; u64 counterparty_unspendable_punishment_reserve; - u64 counterparty_outbound_htlc_minimum_msat; + u64? counterparty_outbound_htlc_minimum_msat; u64? counterparty_outbound_htlc_maximum_msat; u32? counterparty_forwarding_info_fee_base_msat; u32? counterparty_forwarding_info_fee_proportional_millionths; diff --git a/src/types.rs b/src/types.rs index d4b8f6054..b3afe3a4c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -210,7 +210,10 @@ pub struct ChannelDetails { /// [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat pub counterparty_unspendable_punishment_reserve: u64, /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. - pub counterparty_outbound_htlc_minimum_msat: u64, + /// + /// This field is only `None` before we have received either the `OpenChannel` or + /// `AcceptChannel` message from the remote peer. + pub counterparty_outbound_htlc_minimum_msat: Option, /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel. pub counterparty_outbound_htlc_maximum_msat: Option, /// Base routing fee in millisatoshis. @@ -258,6 +261,8 @@ impl From for ChannelDetails { channel_value_sats: value.channel_value_satoshis, unspendable_punishment_reserve: value.unspendable_punishment_reserve, user_channel_id: UserChannelId(value.user_channel_id), + // unwrap safety: This value will be `None` for objects serialized with LDK versions + // prior to 0.0.115. feerate_sat_per_1000_weight: value.feerate_sat_per_1000_weight.unwrap(), balance_msat: value.balance_msat, outbound_capacity_msat: value.outbound_capacity_msat, @@ -274,8 +279,7 @@ impl From for ChannelDetails { .unspendable_punishment_reserve, counterparty_outbound_htlc_minimum_msat: value .counterparty - .outbound_htlc_minimum_msat - .unwrap(), + .outbound_htlc_minimum_msat, counterparty_outbound_htlc_maximum_msat: value.counterparty.outbound_htlc_maximum_msat, counterparty_forwarding_info_fee_base_msat: value .counterparty @@ -295,8 +299,10 @@ impl From for ChannelDetails { next_outbound_htlc_limit_msat: value.next_outbound_htlc_limit_msat, next_outbound_htlc_minimum_msat: value.next_outbound_htlc_minimum_msat, force_close_spend_delay: value.force_close_spend_delay, - inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat.unwrap(), + // unwrap safety: This field is only `None` for objects serialized prior to LDK 0.0.107 + inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat.unwrap_or(0), inbound_htlc_maximum_msat: value.inbound_htlc_maximum_msat, + // unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109. config: value.config.map(|c| Arc::new(c.into())).unwrap(), } }