Skip to content

Commit 769dee4

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 caf0b25 commit 769dee4

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/event.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,11 +1452,14 @@ where
14521452
counterparty_node_id,
14531453
);
14541454

1455+
let former_temporary_channel_id = former_temporary_channel_id.expect(
1456+
"LDK Node has only ever persisted ChannelPending events from rust-lightning 0.0.115 or later",
1457+
);
1458+
14551459
let event = Event::ChannelPending {
14561460
channel_id,
14571461
user_channel_id: UserChannelId(user_channel_id),
1458-
former_temporary_channel_id: former_temporary_channel_id
1459-
.expect("former temporary channel id should be set"),
1462+
former_temporary_channel_id,
14601463
counterparty_node_id,
14611464
funding_txo,
14621465
};

src/types.rs

Lines changed: 10 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("value is set for objects serialized with LDK 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,14 @@ 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
616+
.inbound_htlc_minimum_msat
617+
.expect("value is set for objects serialized with LDK v0.0.107+"),
618618
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(),
619+
config: value
620+
.config
621+
.map(|c| c.into())
622+
.expect("value is set for objects serialized with LDK v0.0.109+"),
621623
channel_shutdown_state: value.channel_shutdown_state,
622624
}
623625
}

0 commit comments

Comments
 (0)