Rename ser macro
authorValentine Wallace <vwallace@protonmail.com>
Mon, 14 Aug 2023 23:54:31 +0000 (19:54 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 22 Aug 2023 17:26:12 +0000 (13:26 -0400)
We want a similar macro for reading TLV streams without a length prefix, so
rename this one to disambiguate.

lightning/src/events/mod.rs
lightning/src/ln/chan_utils.rs
lightning/src/ln/channelmanager.rs
lightning/src/offers/invoice_error.rs
lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/util/ser_macros.rs

index 567096b9852c77cd0fa6a2d2ff53f662f6082182..a40a09fe512f4b25ca5ca530c909021adee9df7b 100644 (file)
@@ -821,12 +821,12 @@ pub enum Event {
                user_channel_id: u128,
                /// The reason the channel was closed.
                reason: ClosureReason,
-               /// Counterparty in the closed channel. 
-               /// 
+               /// Counterparty in the closed channel.
+               ///
                /// This field will be `None` for objects serialized prior to LDK 0.0.117.
                counterparty_node_id: Option<PublicKey>,
-               /// Channel capacity of the closing channel (sats). 
-               /// 
+               /// Channel capacity of the closing channel (sats).
+               ///
                /// This field will be `None` for objects serialized prior to LDK 0.0.117.
                channel_capacity_sats: Option<u64>,
        },
@@ -1030,8 +1030,8 @@ impl Writeable for Event {
                                        (5, outbound_amount_forwarded_msat, option),
                                });
                        },
-                       &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason, 
-                               ref counterparty_node_id, ref channel_capacity_sats 
+                       &Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
+                               ref counterparty_node_id, ref channel_capacity_sats
                        } => {
                                9u8.write(writer)?;
                                // `user_channel_id` used to be a single u64 value. In order to remain backwards
@@ -1368,7 +1368,7 @@ impl MaybeReadable for Event {
                        },
                        13u8 => {
                                let f = || {
-                                       _init_and_read_tlv_fields!(reader, {
+                                       _init_and_read_len_prefixed_tlv_fields!(reader, {
                                                (0, payment_id, required),
                                                (2, payment_hash, option),
                                                (4, path, required_vec),
@@ -1433,7 +1433,7 @@ impl MaybeReadable for Event {
                        },
                        21u8 => {
                                let f = || {
-                                       _init_and_read_tlv_fields!(reader, {
+                                       _init_and_read_len_prefixed_tlv_fields!(reader, {
                                                (0, payment_id, required),
                                                (2, payment_hash, required),
                                                (4, path, required_vec),
@@ -1449,7 +1449,7 @@ impl MaybeReadable for Event {
                        },
                        23u8 => {
                                let f = || {
-                                       _init_and_read_tlv_fields!(reader, {
+                                       _init_and_read_len_prefixed_tlv_fields!(reader, {
                                                (0, payment_id, required),
                                                (2, payment_hash, required),
                                                (4, path, required_vec),
index 85490afaec1292bf792d245c18b13c3b54d78b0a..9ee564df59d99e7679b244101bab4c0c5742ff68 100644 (file)
@@ -1356,7 +1356,7 @@ impl Writeable for CommitmentTransaction {
 
 impl Readable for CommitmentTransaction {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, commitment_number, required),
                        (2, to_broadcaster_value_sat, required),
                        (4, to_countersignatory_value_sat, required),
index bd5b8e11212397bc7321f6425c71a643128fbc2a..eb13f6b4aa1901620596a49af90abd3efbdf3603 100644 (file)
@@ -7809,7 +7809,7 @@ impl Writeable for ChannelDetails {
 
 impl Readable for ChannelDetails {
        fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (1, inbound_scid_alias, option),
                        (2, channel_id, required),
                        (3, channel_type, option),
@@ -8023,7 +8023,7 @@ impl Writeable for ClaimableHTLC {
 
 impl Readable for ClaimableHTLC {
        fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, prev_hop, required),
                        (1, total_msat, option),
                        (2, value_ser, required),
index 122049b9295438b0147224a76c6efbc75455146c..f587b271d12d84e97031391044025f91df0dab65 100644 (file)
@@ -70,7 +70,7 @@ impl Writeable for InvoiceError {
 
 impl Readable for InvoiceError {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (1, erroneous_field, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
                        (3, suggested_value, (option, encoding: (Vec<u8>, WithoutLength))),
                        (5, error, (option, encoding: (UntrustedString, WithoutLength))),
index 64dbb45888b338177f54f662efc0647e620a7c49..434e4fe313db1862d530521f07920f92a7e81973 100644 (file)
@@ -1151,7 +1151,7 @@ impl Writeable for NodeAnnouncementInfo {
 
 impl Readable for NodeAnnouncementInfo {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, features, required),
                        (2, last_update, required),
                        (4, rgb, required),
@@ -1259,7 +1259,7 @@ 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.
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, _lowest_inbound_channel_fees, option),
                        (2, announcement_info_wrap, upgradable_option),
                        (4, channels, required_vec),
index 04fc9927bb7a9446437d12d8633cc99d39a13434..891757a5b086ae8fe1293e015518bd7de7d104e8 100644 (file)
@@ -425,7 +425,7 @@ impl Readable for Route {
                                cmp::min(min_final_cltv_expiry_delta, hops.last().unwrap().cltv_expiry_delta);
                        paths.push(Path { hops, blinded_tail: None });
                }
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (1, payment_params, (option: ReadableArgs, min_final_cltv_expiry_delta)),
                        (2, blinded_tails, optional_vec),
                });
@@ -467,7 +467,7 @@ impl Writeable for RouteParameters {
 
 impl Readable for RouteParameters {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, payment_params, (required: ReadableArgs, 0)),
                        (2, final_value_msat, required),
                        (4, final_cltv_delta, option),
@@ -575,7 +575,7 @@ impl Writeable for PaymentParameters {
 
 impl ReadableArgs<u32> for PaymentParameters {
        fn read<R: io::Read>(reader: &mut R, default_final_cltv_expiry_delta: u32) -> Result<Self, DecodeError> {
-               _init_and_read_tlv_fields!(reader, {
+               _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, payee_pubkey, option),
                        (1, max_total_cltv_expiry_delta, (default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA)),
                        (2, features, (option: ReadableArgs, payee_pubkey.is_some())),
index 2626509f34e6a48cacab50013451a6e454a1a9fe..50451f7775c5bbc340e9492631098e58190398a2 100644 (file)
@@ -794,7 +794,7 @@ macro_rules! _init_tlv_field_var {
 /// This is exported for use by other exported macros, do not use directly.
 #[doc(hidden)]
 #[macro_export]
-macro_rules! _init_and_read_tlv_fields {
+macro_rules! _init_and_read_len_prefixed_tlv_fields {
        ($reader: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
                $(
                        $crate::_init_tlv_field_var!($field, $fieldty);
@@ -863,7 +863,7 @@ macro_rules! impl_writeable_tlv_based {
 
                impl $crate::util::ser::Readable for $st {
                        fn read<R: $crate::io::Read>(reader: &mut R) -> Result<Self, $crate::ln::msgs::DecodeError> {
-                               $crate::_init_and_read_tlv_fields!(reader, {
+                               $crate::_init_and_read_len_prefixed_tlv_fields!(reader, {
                                        $(($type, $field, $fieldty)),*
                                });
                                Ok(Self {
@@ -1015,7 +1015,7 @@ macro_rules! impl_writeable_tlv_based_enum {
                                                // Because read_tlv_fields creates a labeled loop, we cannot call it twice
                                                // in the same function body. Instead, we define a closure and call it.
                                                let f = || {
-                                                       $crate::_init_and_read_tlv_fields!(reader, {
+                                                       $crate::_init_and_read_len_prefixed_tlv_fields!(reader, {
                                                                $(($type, $field, $fieldty)),*
                                                        });
                                                        Ok($st::$variant_name {
@@ -1069,7 +1069,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable {
                                                // Because read_tlv_fields creates a labeled loop, we cannot call it twice
                                                // in the same function body. Instead, we define a closure and call it.
                                                let f = || {
-                                                       $crate::_init_and_read_tlv_fields!(reader, {
+                                                       $crate::_init_and_read_len_prefixed_tlv_fields!(reader, {
                                                                $(($type, $field, $fieldty)),*
                                                        });
                                                        Ok(Some($st::$variant_name {