]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Enable removal of `OnionPayload::Invoice::_legacy_hop_data` later
authorMatt Corallo <git@bluematt.me>
Wed, 4 May 2022 16:29:29 +0000 (16:29 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 19 May 2022 18:16:53 +0000 (18:16 +0000)
In fc77c57c3c6e165d26cb5c1f5d1afee0ecd02589 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`.

lightning/src/ln/channelmanager.rs

index 8725059c360c47435698c71672f81f545b8bab77..cf716f4853f47e4ae5b2372bc92c937efa23319c 100644 (file)
@@ -164,7 +164,7 @@ enum OnionPayload {
        Invoice {
                /// This is only here for backwards-compatibility in serialization, in the future it can be
                /// removed, breaking clients running 0.0.106 and earlier.
-               _legacy_hop_data: msgs::FinalOnionHopData,
+               _legacy_hop_data: Option<msgs::FinalOnionHopData>,
        },
        /// Contains the payer-provided preimage.
        Spontaneous(PaymentPreimage),
@@ -3098,7 +3098,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                                                        prev_funding_outpoint } => {
                                                                let (cltv_expiry, onion_payload, payment_data, phantom_shared_secret) = match routing {
                                                                        PendingHTLCRouting::Receive { payment_data, incoming_cltv_expiry, phantom_shared_secret } => {
-                                                                               let _legacy_hop_data = payment_data.clone();
+                                                                               let _legacy_hop_data = Some(payment_data.clone());
                                                                                (incoming_cltv_expiry, OnionPayload::Invoice { _legacy_hop_data }, Some(payment_data), phantom_shared_secret)
                                                                        },
                                                                        PendingHTLCRouting::ReceiveKeysend { payment_preimage, incoming_cltv_expiry } =>
@@ -6061,13 +6061,9 @@ impl_writeable_tlv_based!(HTLCPreviousHopData, {
 
 impl Writeable for ClaimableHTLC {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
-               let payment_data = match &self.onion_payload {
-                       OnionPayload::Invoice { _legacy_hop_data } => Some(_legacy_hop_data),
-                       _ => None,
-               };
-               let keysend_preimage = match self.onion_payload {
-                       OnionPayload::Invoice { .. } => None,
-                       OnionPayload::Spontaneous(preimage) => Some(preimage.clone()),
+               let (payment_data, keysend_preimage) = match &self.onion_payload {
+                       OnionPayload::Invoice { _legacy_hop_data } => (_legacy_hop_data.as_ref(), None),
+                       OnionPayload::Spontaneous(preimage) => (None, Some(preimage)),
                };
                write_tlv_fields!(writer, {
                        (0, self.prev_hop, required),
@@ -6108,13 +6104,13 @@ impl Readable for ClaimableHTLC {
                                OnionPayload::Spontaneous(p)
                        },
                        None => {
-                               if payment_data.is_none() {
-                                       return Err(DecodeError::InvalidValue)
-                               }
                                if total_msat.is_none() {
+                                       if payment_data.is_none() {
+                                               return Err(DecodeError::InvalidValue)
+                                       }
                                        total_msat = Some(payment_data.as_ref().unwrap().total_msat);
                                }
-                               OnionPayload::Invoice { _legacy_hop_data: payment_data.unwrap() }
+                               OnionPayload::Invoice { _legacy_hop_data: payment_data }
                        },
                };
                Ok(Self {