@@ -10296,28 +10296,25 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10296
10296
}
10297
10297
}
10298
10298
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>
10300
10300
where
10301
10301
ES::Target: EntropySource,
10302
10302
SP::Target: SignerProvider
10303
10303
{
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;
10306
10306
let ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
10307
+ if ver <= 2 {
10308
+ return Err(DecodeError::UnknownVersion);
10309
+ }
10307
10310
10308
10311
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
10309
10312
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. We read
10310
10313
// the low bytes now and the high bytes later.
10311
10314
let user_id_low: u64 = Readable::read(reader)?;
10312
10315
10313
- let mut config = Some(LegacyChannelConfig::default());
10314
- if ver == 1 {
10315
- // Read the old serialization of the ChannelConfig from version 0.0.98.
10316
- config.as_mut().unwrap().options.forwarding_fee_proportional_millionths = Readable::read(reader)?;
10317
- config.as_mut().unwrap().options.cltv_expiry_delta = Readable::read(reader)?;
10318
- config.as_mut().unwrap().announce_for_forwarding = Readable::read(reader)?;
10319
- config.as_mut().unwrap().commit_upfront_shutdown_pubkey = Readable::read(reader)?;
10320
- } else {
10316
+ let mut config = LegacyChannelConfig::default();
10317
+ {
10321
10318
// Read the 8 bytes of backwards-compatibility ChannelConfig data.
10322
10319
let mut _val: u64 = Readable::read(reader)?;
10323
10320
}
@@ -10481,23 +10478,17 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10481
10478
let holder_dust_limit_satoshis = Readable::read(reader)?;
10482
10479
let counterparty_max_htlc_value_in_flight_msat = Readable::read(reader)?;
10483
10480
let mut counterparty_selected_channel_reserve_satoshis = None;
10484
- if ver == 1 {
10485
- // Read the old serialization from version 0.0.98.
10486
- counterparty_selected_channel_reserve_satoshis = Some(Readable::read(reader)?);
10487
- } else {
10488
- // Read the 8 bytes of backwards-compatibility data.
10481
+ {
10482
+ // Read the 8 bytes of backwards-compatibility counterparty_selected_channel_reserve_satoshis data.
10489
10483
let _dummy: u64 = Readable::read(reader)?;
10490
10484
}
10491
10485
let counterparty_htlc_minimum_msat = Readable::read(reader)?;
10492
10486
let holder_htlc_minimum_msat = Readable::read(reader)?;
10493
10487
let counterparty_max_accepted_htlcs = Readable::read(reader)?;
10494
10488
10495
10489
let mut minimum_depth = None;
10496
- if ver == 1 {
10497
- // Read the old serialization from version 0.0.98.
10498
- minimum_depth = Some(Readable::read(reader)?);
10499
- } else {
10500
- // Read the 4 bytes of backwards-compatibility data.
10490
+ {
10491
+ // Read the 4 bytes of backwards-compatibility minimum_depth data.
10501
10492
let _dummy: u32 = Readable::read(reader)?;
10502
10493
}
10503
10494
@@ -10542,20 +10533,20 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10542
10533
// Prior to supporting channel type negotiation, all of our channels were static_remotekey
10543
10534
// only, so we default to that if none was written.
10544
10535
let mut channel_type = Some(ChannelTypeFeatures::only_static_remote_key());
10545
- let mut channel_creation_height = Some(serialized_height) ;
10536
+ let mut channel_creation_height = 0u32 ;
10546
10537
let mut preimages_opt: Option<Vec<Option<PaymentPreimage>>> = None;
10547
10538
10548
10539
// If we read an old Channel, for simplicity we just treat it as "we never sent an
10549
10540
// AnnouncementSignatures" which implies we'll re-send it on reconnect, but that's fine.
10550
- let mut announcement_sigs_state = Some( AnnouncementSigsState::NotSent) ;
10541
+ let mut announcement_sigs_state = AnnouncementSigsState::NotSent;
10551
10542
let mut latest_inbound_scid_alias = None;
10552
- let mut outbound_scid_alias = None ;
10543
+ let mut outbound_scid_alias = 0u64 ;
10553
10544
let mut channel_pending_event_emitted = None;
10554
10545
let mut channel_ready_event_emitted = None;
10555
10546
let mut funding_tx_broadcast_safe_event_emitted = None;
10556
10547
10557
10548
let mut user_id_high_opt: Option<u64> = None;
10558
- let mut channel_keys_id: Option<[u8 ; 32]> = None ;
10549
+ let mut channel_keys_id = [0u8 ; 32];
10559
10550
let mut temporary_channel_id: Option<ChannelId> = None;
10560
10551
let mut holder_max_accepted_htlcs: Option<u16> = None;
10561
10552
@@ -10584,21 +10575,21 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10584
10575
(2, channel_type, option),
10585
10576
(3, counterparty_selected_channel_reserve_satoshis, option),
10586
10577
(4, holder_selected_channel_reserve_satoshis, option),
10587
- (5, config, option), // Note that if none is provided we will *not* overwrite the existing one.
10578
+ (5, config, required),
10588
10579
(6, holder_max_htlc_value_in_flight_msat, option),
10589
10580
(7, shutdown_scriptpubkey, option),
10590
10581
(8, blocked_monitor_updates, optional_vec),
10591
10582
(9, target_closing_feerate_sats_per_kw, option),
10592
10583
(10, monitor_pending_update_adds, option), // Added in 0.0.122
10593
10584
(11, monitor_pending_finalized_fulfills, optional_vec),
10594
- (13, channel_creation_height, option ),
10585
+ (13, channel_creation_height, required ),
10595
10586
(15, preimages_opt, optional_vec),
10596
- (17, announcement_sigs_state, option ),
10587
+ (17, announcement_sigs_state, required ),
10597
10588
(19, latest_inbound_scid_alias, option),
10598
- (21, outbound_scid_alias, option ),
10589
+ (21, outbound_scid_alias, required ),
10599
10590
(23, channel_ready_event_emitted, option),
10600
10591
(25, user_id_high_opt, option),
10601
- (27, channel_keys_id, option ),
10592
+ (27, channel_keys_id, required ),
10602
10593
(28, holder_max_accepted_htlcs, option),
10603
10594
(29, temporary_channel_id, option),
10604
10595
(31, channel_pending_event_emitted, option),
@@ -10615,12 +10606,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10615
10606
(53, funding_tx_broadcast_safe_event_emitted, option),
10616
10607
});
10617
10608
10618
- let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
10619
- let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
10620
- (channel_keys_id, holder_signer)
10621
- } else {
10622
- return Err(DecodeError::InvalidValue);
10623
- };
10609
+ let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
10624
10610
10625
10611
if let Some(preimages) = preimages_opt {
10626
10612
let mut iter = preimages.into_iter();
@@ -10651,8 +10637,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10651
10637
// ChannelTransactionParameters may have had an empty features set upon deserialization.
10652
10638
// To account for that, we're proactively setting/overriding the field here.
10653
10639
channel_parameters.channel_type_features = chan_features.clone();
10654
- // ChannelTransactionParameters::channel_value_satoshis defaults to 0 prior to version 0.2.
10655
- channel_parameters.channel_value_satoshis = channel_value_satoshis;
10656
10640
10657
10641
let mut secp_ctx = Secp256k1::new();
10658
10642
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
@@ -10764,7 +10748,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10764
10748
context: ChannelContext {
10765
10749
user_id,
10766
10750
10767
- config: config.unwrap() ,
10751
+ config,
10768
10752
10769
10753
prev_config: None,
10770
10754
@@ -10775,7 +10759,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10775
10759
channel_id,
10776
10760
temporary_channel_id,
10777
10761
channel_state,
10778
- announcement_sigs_state: announcement_sigs_state.unwrap() ,
10762
+ announcement_sigs_state,
10779
10763
secp_ctx,
10780
10764
10781
10765
latest_monitor_update_id,
@@ -10825,7 +10809,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10825
10809
funding_tx_confirmed_in,
10826
10810
funding_tx_confirmation_height,
10827
10811
short_channel_id,
10828
- channel_creation_height: channel_creation_height.unwrap() ,
10812
+ channel_creation_height,
10829
10813
10830
10814
counterparty_dust_limit_satoshis,
10831
10815
holder_dust_limit_satoshis,
@@ -10858,7 +10842,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10858
10842
10859
10843
latest_inbound_scid_alias,
10860
10844
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
10861
- outbound_scid_alias: outbound_scid_alias.unwrap_or(0) ,
10845
+ outbound_scid_alias,
10862
10846
10863
10847
funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
10864
10848
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
@@ -11567,7 +11551,7 @@ mod tests {
11567
11551
let mut s = crate::io::Cursor::new(&encoded_chan);
11568
11552
let mut reader = crate::util::ser::FixedLengthReader::new(&mut s, encoded_chan.len() as u64);
11569
11553
let features = channelmanager::provided_channel_type_features(&config);
11570
- let decoded_chan = FundedChannel::read(&mut reader, (&&keys_provider, &&keys_provider, 0, &features)).unwrap();
11554
+ let decoded_chan = FundedChannel::read(&mut reader, (&&keys_provider, &&keys_provider, &features)).unwrap();
11571
11555
assert_eq!(decoded_chan.context.pending_outbound_htlcs, pending_outbound_htlcs);
11572
11556
assert_eq!(decoded_chan.context.holding_cell_htlc_updates, holding_cell_htlc_updates);
11573
11557
}
0 commit comments