Skip to content

Commit 7576a9b

Browse files
committed
Document ChannelPending temporary id invariant
Replace the pending-channel unwrap with an expect that records why supported LDK Node state should always include the former temporary channel id. Older rust-lightning state could omit it, but LDK Node never shipped before that field existed. Co-Authored-By: HAL 9000 Signed-off-by: Elias Rohrer <dev@tnull.de>
1 parent fef6177 commit 7576a9b

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/event.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,9 @@ where
14531453
counterparty_node_id,
14541454
);
14551455

1456-
#[allow(clippy::unwrap_used)]
1457-
let former_temporary_channel_id = former_temporary_channel_id.unwrap();
1456+
let former_temporary_channel_id = former_temporary_channel_id.expect(
1457+
"LDK Node has only ever persisted ChannelPending events from rust-lightning 0.0.115 or later",
1458+
);
14581459

14591460
let event = Event::ChannelPending {
14601461
channel_id,

src/types.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ pub struct ChannelDetails {
565565
}
566566

567567
impl From<LdkChannelDetails> for ChannelDetails {
568-
#[allow(clippy::unwrap_used)]
569568
fn from(value: LdkChannelDetails) -> Self {
570569
ChannelDetails {
571570
channel_id: value.channel_id,
@@ -578,9 +577,9 @@ impl From<LdkChannelDetails> for ChannelDetails {
578577
channel_value_sats: value.channel_value_satoshis,
579578
unspendable_punishment_reserve: value.unspendable_punishment_reserve,
580579
user_channel_id: UserChannelId(value.user_channel_id),
581-
// unwrap safety: This value will be `None` for objects serialized with LDK versions
582-
// prior to 0.0.115.
583-
feerate_sat_per_1000_weight: value.feerate_sat_per_1000_weight.unwrap(),
580+
feerate_sat_per_1000_weight: value
581+
.feerate_sat_per_1000_weight
582+
.expect("LDK objects that are serialized on v0.0.115+ (as ldk-node v0.1 already depended on v0.0.115)"),
584583
outbound_capacity_msat: value.outbound_capacity_msat,
585584
inbound_capacity_msat: value.inbound_capacity_msat,
586585
confirmations_required: value.confirmations_required,
@@ -613,11 +612,13 @@ impl From<LdkChannelDetails> for ChannelDetails {
613612
next_outbound_htlc_limit_msat: value.next_outbound_htlc_limit_msat,
614613
next_outbound_htlc_minimum_msat: value.next_outbound_htlc_minimum_msat,
615614
force_close_spend_delay: value.force_close_spend_delay,
616-
// unwrap safety: This field is only `None` for objects serialized prior to LDK 0.0.107
617-
inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat.unwrap_or(0),
615+
inbound_htlc_minimum_msat: value.inbound_htlc_minimum_msat
616+
.expect("LDK objects that are serialized on v0.0.107+ (as ldk-node v0.1 already depended on v0.0.115)"),
618617
inbound_htlc_maximum_msat: value.inbound_htlc_maximum_msat,
619-
// unwrap safety: `config` is only `None` for LDK objects serialized prior to 0.0.109.
620-
config: value.config.map(|c| c.into()).unwrap(),
618+
config: value
619+
.config
620+
.map(|c| c.into())
621+
.expect("LDK objects that are serialized on v0.0.109+ (as ldk-node v0.1 already depended on v0.0.115)"),
621622
channel_shutdown_state: value.channel_shutdown_state,
622623
}
623624
}

0 commit comments

Comments
 (0)