Convert some `vec_type` TLVs to `required_vec`
authorMatt Corallo <git@bluematt.me>
Fri, 7 Jul 2023 18:44:24 +0000 (18:44 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 7 Jul 2023 21:07:06 +0000 (21:07 +0000)
This converts some required TLVs to `required_vec` which are, in
fact, required (and have been written forever).

* `HTLCFailReason` hasn't changed since many structs were converted
  to TLVs in 66784e32fe454e9a5b2080b85fc4d8816ac5e436.
* `NodeInfo::channels` has been written since `NetworkGraph`
  structs were converted to TLVs in 321b19c4d96a49b39b5583d0f12fea.
* Several test-only TLV writes were converted.

lightning/src/ln/msgs.rs
lightning/src/ln/onion_utils.rs
lightning/src/onion_message/packet.rs
lightning/src/routing/gossip.rs
lightning/src/util/chacha20poly1305rfc.rs

index 672c6ae6e96e8387cd840ae97f19080a5d4d8016..a514f4923268ce8639bafbb5065c43e6e1a7ea3d 100644 (file)
@@ -3760,7 +3760,7 @@ mod tests {
                let test_bytes = vec![42u8; 1000];
                if let OnionHopDataFormat::NonFinalNode { short_channel_id } = payload.format {
                        _encode_varint_length_prefixed_tlv!(&mut encoded_payload, {
-                               (1, test_bytes, vec_type),
+                               (1, test_bytes, required_vec),
                                (2, HighZeroBytesDroppedBigSize(payload.amt_to_forward), required),
                                (4, HighZeroBytesDroppedBigSize(payload.outgoing_cltv_value), required),
                                (6, short_channel_id, required)
index 3b62c856334596b85bf58b8ee96b1a0eed8f36f6..52eb7bcb54298a7cc8e8fc418f77d4de66babd69 100644 (file)
@@ -645,7 +645,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
        },
        (1, Reason) => {
                (0, failure_code, required),
-               (2, data, vec_type),
+               (2, data, required_vec),
        },
 ;);
 
index 1c3595c3712526191e0e5f1707dfa51d82ca7505..8a5628f164ca358dd8df1d7aec5e58730247c67e 100644 (file)
@@ -169,7 +169,7 @@ impl<T: CustomOnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
                match &self.0 {
                        Payload::Forward(ForwardControlTlvs::Blinded(encrypted_bytes)) => {
                                _encode_varint_length_prefixed_tlv!(w, {
-                                       (4, *encrypted_bytes, vec_type)
+                                       (4, *encrypted_bytes, required_vec)
                                })
                        },
                        Payload::Receive {
@@ -177,7 +177,7 @@ impl<T: CustomOnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
                        } => {
                                _encode_varint_length_prefixed_tlv!(w, {
                                        (2, reply_path, option),
-                                       (4, *encrypted_bytes, vec_type),
+                                       (4, *encrypted_bytes, required_vec),
                                        (message.tlv_type(), message, required)
                                })
                        },
index 40969b180af9d6904d79eb29d8cdf05b3c624bc9..644772b81498bdcbc94251f067b4740176531471 100644 (file)
@@ -1120,26 +1120,26 @@ impl Writeable for NodeAnnouncementInfo {
                        (4, self.rgb, required),
                        (6, self.alias, required),
                        (8, self.announcement_message, option),
-                       (10, empty_addresses, vec_type), // Versions prior to 0.0.115 require this field
+                       (10, empty_addresses, required_vec), // Versions prior to 0.0.115 require this field
                });
                Ok(())
        }
 }
 
 impl Readable for NodeAnnouncementInfo {
-    fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+       fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                _init_and_read_tlv_fields!(reader, {
                        (0, features, required),
                        (2, last_update, required),
                        (4, rgb, required),
                        (6, alias, required),
                        (8, announcement_message, option),
-                       (10, _addresses, vec_type), // deprecated, not used anymore
+                       (10, _addresses, optional_vec), // deprecated, not used anymore
                });
                let _: Option<Vec<NetAddress>> = _addresses;
                Ok(Self { features: features.0.unwrap(), last_update: last_update.0.unwrap(), rgb: rgb.0.unwrap(),
                        alias: alias.0.unwrap(), announcement_message })
-    }
+       }
 }
 
 /// A user-defined name for a node, which may be used when displaying the node in a graph.
@@ -1205,7 +1205,7 @@ impl Writeable for NodeInfo {
                write_tlv_fields!(writer, {
                        // Note that older versions of LDK wrote the lowest inbound fees here at type 0
                        (2, self.announcement_info, option),
-                       (4, self.channels, vec_type),
+                       (4, self.channels, required_vec),
                });
                Ok(())
        }
@@ -1236,19 +1236,17 @@ impl Readable for NodeInfo {
                // with zero inbound fees, causing that heuristic to provide little gain. Worse, because it
                // requires additional complexity and lookups during routing, it ends up being a
                // performance loss. Thus, we simply ignore the old field here and no longer track it.
-               let mut _lowest_inbound_channel_fees: Option<RoutingFees> = None;
-               let mut announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrapper> = None;
-               _init_tlv_field_var!(channels, vec_type);
-
-               read_tlv_fields!(reader, {
+               _init_and_read_tlv_fields!(reader, {
                        (0, _lowest_inbound_channel_fees, option),
                        (2, announcement_info_wrap, upgradable_option),
-                       (4, channels, vec_type),
+                       (4, channels, required_vec),
                });
+               let _: Option<RoutingFees> = _lowest_inbound_channel_fees;
+               let announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrapper> = announcement_info_wrap;
 
                Ok(NodeInfo {
                        announcement_info: announcement_info_wrap.map(|w| w.0),
-                       channels: _init_tlv_based_struct_field!(channels, vec_type),
+                       channels,
                })
        }
 }
index 052968377a5e58fe6a4236c0812718a236eaab54..a5bec2c82b8cf00da2a597d3c68026aa7e87152f 100644 (file)
@@ -341,9 +341,9 @@ mod tests {
                field3: Vec<u8>,
        }
        impl_writeable_tlv_based!(TestWriteable, {
-               (1, field1, vec_type),
-               (2, field2, vec_type),
-               (3, field3, vec_type),
+               (1, field1, required_vec),
+               (2, field2, required_vec),
+               (3, field3, required_vec),
        });
 
        #[test]