Skip to content

Commit f557df9

Browse files
committed
Change serialization backwards compat in Channel to use new version
Instead of interpreting the backwards compatibility data in Channel serialization, use the serialization version bump present in 0.0.99 as the flag to indicate if a channel should be read in backwards compatibility.
1 parent edc62b6 commit f557df9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4650,10 +4650,15 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
46504650
self.counterparty_dust_limit_satoshis.write(writer)?;
46514651
self.holder_dust_limit_satoshis.write(writer)?;
46524652
self.counterparty_max_htlc_value_in_flight_msat.write(writer)?;
4653+
4654+
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
46534655
self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0).write(writer)?;
4656+
46544657
self.counterparty_htlc_minimum_msat.write(writer)?;
46554658
self.holder_htlc_minimum_msat.write(writer)?;
46564659
self.counterparty_max_accepted_htlcs.write(writer)?;
4660+
4661+
// Note that this field is ignored by 0.0.99+ as the TLV Optional variant is used instead.
46574662
self.minimum_depth.unwrap_or(0).write(writer)?;
46584663

46594664
match &self.counterparty_forwarding_info {
@@ -4844,20 +4849,25 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48444849
let counterparty_dust_limit_satoshis = Readable::read(reader)?;
48454850
let holder_dust_limit_satoshis = Readable::read(reader)?;
48464851
let counterparty_max_htlc_value_in_flight_msat = Readable::read(reader)?;
4847-
let mut counterparty_selected_channel_reserve_satoshis = Some(Readable::read(reader)?);
4848-
if counterparty_selected_channel_reserve_satoshis == Some(0) {
4849-
// Versions up to 0.0.98 had counterparty_selected_channel_reserve_satoshis as a
4850-
// non-option, writing 0 for what we now consider None.
4851-
counterparty_selected_channel_reserve_satoshis = None;
4852+
let mut counterparty_selected_channel_reserve_satoshis = None;
4853+
if ver == 1 {
4854+
// Read the old serialization from version 0.0.98.
4855+
counterparty_selected_channel_reserve_satoshis = Some(Readable::read(reader)?);
4856+
} else {
4857+
// Read the 8 bytes of backwards-compatibility data.
4858+
let _dummy: u64 = Readable::read(reader)?;
48524859
}
48534860
let counterparty_htlc_minimum_msat = Readable::read(reader)?;
48544861
let holder_htlc_minimum_msat = Readable::read(reader)?;
48554862
let counterparty_max_accepted_htlcs = Readable::read(reader)?;
4856-
let mut minimum_depth = Some(Readable::read(reader)?);
4857-
if minimum_depth == Some(0) {
4858-
// Versions up to 0.0.98 had minimum_depth as a non-option, writing 0 for what we now
4859-
// consider None.
4860-
minimum_depth = None;
4863+
4864+
let mut minimum_depth = None;
4865+
if ver == 1 {
4866+
// Read the old serialization from version 0.0.98.
4867+
minimum_depth = Some(Readable::read(reader)?);
4868+
} else {
4869+
// Read the 4 bytes of backwards-compatibility data.
4870+
let _dummy: u32 = Readable::read(reader)?;
48614871
}
48624872

48634873
let counterparty_forwarding_info = match <u8 as Readable>::read(reader)? {

0 commit comments

Comments
 (0)