Skip to content

Commit

Permalink
Fix reachable unwrap of outbound_htlc_minimum_msat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tnull committed Nov 27, 2023
1 parent 8b9983a commit 492762e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
pub counterparty_outbound_htlc_maximum_msat: Option<u64>,
/// Base routing fee in millisatoshis.
Expand Down Expand Up @@ -258,6 +261,8 @@ impl From<LdkChannelDetails> 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,
Expand All @@ -274,8 +279,7 @@ impl From<LdkChannelDetails> 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
Expand All @@ -295,8 +299,10 @@ impl From<LdkChannelDetails> 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(),
}
}
Expand Down

0 comments on commit 492762e

Please sign in to comment.