Skip to content

Commit 09d51ea

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 12405a1 commit 09d51ea

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

lightning/src/ln/channel.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -4844,20 +4844,25 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48444844
let counterparty_dust_limit_satoshis = Readable::read(reader)?;
48454845
let holder_dust_limit_satoshis = Readable::read(reader)?;
48464846
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;
4847+
let mut counterparty_selected_channel_reserve_satoshis = None;
4848+
if ver == 1 {
4849+
// Read the old serialization from version 0.0.98.
4850+
counterparty_selected_channel_reserve_satoshis = Some(Readable::read(reader)?);
4851+
} else {
4852+
// Read the 8 bytes of backwards-compatibility data.
4853+
let _dummy: u64 = Readable::read(reader)?;
48524854
}
48534855
let counterparty_htlc_minimum_msat = Readable::read(reader)?;
48544856
let holder_htlc_minimum_msat = Readable::read(reader)?;
48554857
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;
4858+
4859+
let mut minimum_depth = None;
4860+
if ver == 1 {
4861+
// Read the old serialization from version 0.0.98.
4862+
minimum_depth = Some(Readable::read(reader)?);
4863+
} else {
4864+
// Read the 4 bytes of backwards-compatibility data.
4865+
let _dummy: u32 = Readable::read(reader)?;
48614866
}
48624867

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

0 commit comments

Comments
 (0)