Skip to content

Commit 2a42595

Browse files
committed
Enable removal of OnionPayload::Invoice::_legacy_hop_data later
In fc77c57 we stopped using the `FinalOnionHopData` in `OnionPayload::Invoice` directly and renamed it `_legacy_hop_data` with the intent of removing it in a few versions. However, we continue to check that it was included in the serialized data, meaning we would not be able to remove it without breaking ability to serialize full `ChannelManager`s. This fixes that by making the `_legacy_hop_data` an `Option` which we will happily handle just fine if its `None`.
1 parent 36817e0 commit 2a42595

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ enum OnionPayload {
164164
Invoice {
165165
/// This is only here for backwards-compatibility in serialization, in the future it can be
166166
/// removed, breaking clients running 0.0.106 and earlier.
167-
_legacy_hop_data: msgs::FinalOnionHopData,
167+
_legacy_hop_data: Option<msgs::FinalOnionHopData>,
168168
},
169169
/// Contains the payer-provided preimage.
170170
Spontaneous(PaymentPreimage),
@@ -3098,7 +3098,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
30983098
prev_funding_outpoint } => {
30993099
let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
31003100
PendingHTLCRouting::Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
3101-
let _legacy_hop_data = payment_data.clone();
3101+
let _legacy_hop_data = Some(payment_data.clone());
31023102
(incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data }, Some(payment_data), phantom_shared_secret)
31033103
},
31043104
PendingHTLCRouting::ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
@@ -6061,13 +6061,9 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
60616061

60626062
impl Writeable for ClaimableHTLC {
60636063
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
6064-
let payment_data = match &self.onion_payload {
6065-
OnionPayload::Invoice { _legacy_hop_data } => Some(_legacy_hop_data),
6066-
_ => None,
6067-
};
6068-
let keysend_preimage = match self.onion_payload {
6069-
OnionPayload::Invoice { .. } => None,
6070-
OnionPayload::Spontaneous(preimage) => Some(preimage.clone()),
6064+
let (payment_data, keysend_preimage) = match &self.onion_payload {
6065+
OnionPayload::Invoice { _legacy_hop_data } => (_legacy_hop_data.as_ref(), None),
6066+
OnionPayload::Spontaneous(preimage) => (None, Some(preimage)),
60716067
};
60726068
write_tlv_fields!(writer, {
60736069
(0, self.prev_hop, required),
@@ -6108,13 +6104,13 @@ impl Readable for ClaimableHTLC {
61086104
OnionPayload::Spontaneous(p)
61096105
},
61106106
None => {
6111-
if payment_data.is_none() {
6112-
return Err(DecodeError::InvalidValue)
6113-
}
61146107
if total_msat.is_none() {
6108+
if payment_data.is_none() {
6109+
return Err(DecodeError::InvalidValue)
6110+
}
61156111
total_msat = Some(payment_data.as_ref().unwrap().total_msat);
61166112
}
6117-
OnionPayload::Invoice { _legacy_hop_data: payment_data.unwrap() }
6113+
OnionPayload::Invoice { _legacy_hop_data: payment_data }
61186114
},
61196115
};
61206116
Ok(Self {

0 commit comments

Comments
 (0)