Skip to content

Commit 0af8ddb

Browse files
committed
Mark a few TLVs as required when reading Channels
e23d32d removed support for reading ancient `Channel`s but left a bit of cleanup for later. Here we mark a few TLVs as `required` which were always written in 0.0.113.
1 parent bd11796 commit 0af8ddb

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10296,13 +10296,13 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1029610296
}
1029710297
}
1029810298

10299-
impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c ChannelTypeFeatures)> for FundedChannel<SP>
10299+
impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c ChannelTypeFeatures)> for FundedChannel<SP>
1030010300
where
1030110301
ES::Target: EntropySource,
1030210302
SP::Target: SignerProvider
1030310303
{
10304-
fn read<R : io::Read>(reader: &mut R, args: (&'a ES, &'b SP, u32, &'c ChannelTypeFeatures)) -> Result<Self, DecodeError> {
10305-
let (entropy_source, signer_provider, serialized_height, our_supported_features) = args;
10304+
fn read<R : io::Read>(reader: &mut R, args: (&'a ES, &'b SP, &'c ChannelTypeFeatures)) -> Result<Self, DecodeError> {
10305+
let (entropy_source, signer_provider, our_supported_features) = args;
1030610306
let ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
1030710307

1030810308
if ver <= 2 {
@@ -10537,20 +10537,20 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1053710537
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
1053810538
// only, so we default to that if none was written.
1053910539
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
10540-
let mut channel_creation_height = Some(serialized_height);
10540+
let mut channel_creation_height = 0u32;
1054110541
let mut preimages_opt: Option<Vec<Option<PaymentPreimage>>> = None;
1054210542

1054310543
// If we read an old Channel, for simplicity we just treat it as "we never sent an
1054410544
// AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
10545-
let mut announcement_sigs_state = Some(AnnouncementSigsState::NotSent);
10545+
let mut announcement_sigs_state = AnnouncementSigsState::NotSent;
1054610546
let mut latest_inbound_scid_alias = None;
10547-
let mut outbound_scid_alias = None;
10547+
let mut outbound_scid_alias = 0u64;
1054810548
let mut channel_pending_event_emitted = None;
1054910549
let mut channel_ready_event_emitted = None;
1055010550
let mut funding_tx_broadcast_safe_event_emitted = None;
1055110551

1055210552
let mut user_id_high_opt: Option<u64> = None;
10553-
let mut channel_keys_id: Option<[u8; 32]> = None;
10553+
let mut channel_keys_id = [0u8; 32];
1055410554
let mut temporary_channel_id: Option<ChannelId> = None;
1055510555
let mut holder_max_accepted_htlcs: Option<u16> = None;
1055610556

@@ -10573,29 +10573,29 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1057310573
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
1057410574
let mut is_manual_broadcast = None;
1057510575

10576-
let mut config = Some(LegacyChannelConfig::default());
10576+
let mut config = LegacyChannelConfig::default();
1057710577

1057810578
read_tlv_fields!(reader, {
1057910579
(0, announcement_sigs, option),
1058010580
(1, minimum_depth, option),
1058110581
(2, channel_type, option),
1058210582
(3, counterparty_selected_channel_reserve_satoshis, option),
1058310583
(4, holder_selected_channel_reserve_satoshis, option),
10584-
(5, config, option), // Note that if none is provided we will *not* overwrite the existing one.
10584+
(5, config, required),
1058510585
(6, holder_max_htlc_value_in_flight_msat, option),
1058610586
(7, shutdown_scriptpubkey, option),
1058710587
(8, blocked_monitor_updates, optional_vec),
1058810588
(9, target_closing_feerate_sats_per_kw, option),
1058910589
(10, monitor_pending_update_adds, option), // Added in 0.0.122
1059010590
(11, monitor_pending_finalized_fulfills, optional_vec),
10591-
(13, channel_creation_height, option),
10591+
(13, channel_creation_height, required),
1059210592
(15, preimages_opt, optional_vec),
10593-
(17, announcement_sigs_state, option),
10593+
(17, announcement_sigs_state, required),
1059410594
(19, latest_inbound_scid_alias, option),
10595-
(21, outbound_scid_alias, option),
10595+
(21, outbound_scid_alias, required),
1059610596
(23, channel_ready_event_emitted, option),
1059710597
(25, user_id_high_opt, option),
10598-
(27, channel_keys_id, option),
10598+
(27, channel_keys_id, required),
1059910599
(28, holder_max_accepted_htlcs, option),
1060010600
(29, temporary_channel_id, option),
1060110601
(31, channel_pending_event_emitted, option),
@@ -10612,12 +10612,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1061210612
(53, funding_tx_broadcast_safe_event_emitted, option),
1061310613
});
1061410614

10615-
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
10616-
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
10617-
(channel_keys_id, holder_signer)
10618-
} else {
10619-
return Err(DecodeError::InvalidValue);
10620-
};
10615+
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
1062110616

1062210617
if let Some(preimages) = preimages_opt {
1062310618
let mut iter = preimages.into_iter();
@@ -10761,7 +10756,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1076110756
context: ChannelContext {
1076210757
user_id,
1076310758

10764-
config: config.unwrap(),
10759+
config,
1076510760

1076610761
prev_config: None,
1076710762

@@ -10772,7 +10767,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1077210767
channel_id,
1077310768
temporary_channel_id,
1077410769
channel_state,
10775-
announcement_sigs_state: announcement_sigs_state.unwrap(),
10770+
announcement_sigs_state,
1077610771
secp_ctx,
1077710772

1077810773
latest_monitor_update_id,
@@ -10822,7 +10817,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1082210817
funding_tx_confirmed_in,
1082310818
funding_tx_confirmation_height,
1082410819
short_channel_id,
10825-
channel_creation_height: channel_creation_height.unwrap(),
10820+
channel_creation_height,
1082610821

1082710822
counterparty_dust_limit_satoshis,
1082810823
holder_dust_limit_satoshis,
@@ -10855,7 +10850,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1085510850

1085610851
latest_inbound_scid_alias,
1085710852
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
10858-
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
10853+
outbound_scid_alias,
1085910854

1086010855
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
1086110856
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
@@ -11564,7 +11559,7 @@ mod tests {
1156411559
let mut s = crate::io::Cursor::new(&encoded_chan);
1156511560
let mut reader = crate::util::ser::FixedLengthReader::new(&mut s, encoded_chan.len() as u64);
1156611561
let features = channelmanager::provided_channel_type_features(&config);
11567-
let decoded_chan = FundedChannel::read(&mut reader, (&&keys_provider, &&keys_provider, 0, &features)).unwrap();
11562+
let decoded_chan = FundedChannel::read(&mut reader, (&&keys_provider, &&keys_provider, &features)).unwrap();
1156811563
assert_eq!(decoded_chan.context.pending_outbound_htlcs, pending_outbound_htlcs);
1156911564
assert_eq!(decoded_chan.context.holding_cell_htlc_updates, holding_cell_htlc_updates);
1157011565
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13634,7 +13634,7 @@ where
1363413634
let mut close_background_events = Vec::new();
1363513635
for _ in 0..channel_count {
1363613636
let mut channel: FundedChannel<SP> = FundedChannel::read(reader, (
13637-
&args.entropy_source, &args.signer_provider, best_block_height, &provided_channel_type_features(&args.default_config)
13637+
&args.entropy_source, &args.signer_provider, &provided_channel_type_features(&args.default_config)
1363813638
))?;
1363913639
let logger = WithChannelContext::from(&args.logger, &channel.context, None);
1364013640
let channel_id = channel.context.channel_id();

0 commit comments

Comments
 (0)