diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 904d9941349..71fc1cb6f06 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -262,7 +262,7 @@ impl_writeable_tlv_based!(HolderSignedTx, { (8, delayed_payment_key, required), (10, per_commitment_point, required), (12, feerate_per_kw, required), - (14, htlc_outputs, vec_type) + (14, htlc_outputs, required_vec) }); impl HolderSignedTx { @@ -538,15 +538,15 @@ impl ChannelMonitorUpdateStep { impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep, (0, LatestHolderCommitmentTXInfo) => { (0, commitment_tx, required), - (1, claimed_htlcs, vec_type), - (2, htlc_outputs, vec_type), + (1, claimed_htlcs, optional_vec), + (2, htlc_outputs, required_vec), (4, nondust_htlc_sources, optional_vec), }, (1, LatestCounterpartyCommitmentTXInfo) => { (0, commitment_txid, required), (2, commitment_number, required), (4, their_per_commitment_point, required), - (6, htlc_outputs, vec_type), + (6, htlc_outputs, required_vec), }, (2, PaymentPreimage) => { (0, payment_preimage, required), @@ -1075,12 +1075,12 @@ impl Writeable for ChannelMonitorImpl ReadableArgs<(&'a ES, &'b SP let mut counterparty_fulfilled_htlcs = Some(HashMap::new()); read_tlv_fields!(reader, { (1, funding_spend_confirmed, option), - (3, htlcs_resolved_on_chain, vec_type), - (5, pending_monitor_events, vec_type), + (3, htlcs_resolved_on_chain, optional_vec), + (5, pending_monitor_events, optional_vec), (7, funding_spend_seen, option), (9, counterparty_node_id, option), (11, confirmed_commitment_tx_counterparty_output, option), - (13, spendable_txids_confirmed, vec_type), + (13, spendable_txids_confirmed, optional_vec), (15, counterparty_fulfilled_htlcs, option), }); diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index a6601e4d99c..a5a20e7d42b 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -909,7 +909,7 @@ impl Writeable for Event { (2, payment_failed_permanently, required), (3, false, required), // all_paths_failed in LDK versions prior to 0.0.114 (4, path.blinded_tail, option), - (5, path.hops, vec_type), + (5, path.hops, required_vec), (7, short_channel_id, option), (9, None::, option), // retry in LDK versions prior to 0.0.115 (11, payment_id, option), @@ -977,7 +977,7 @@ impl Writeable for Event { write_tlv_fields!(writer, { (0, payment_id, required), (2, payment_hash, option), - (4, path.hops, vec_type), + (4, path.hops, required_vec), (6, path.blinded_tail, option), }) }, @@ -1008,7 +1008,7 @@ impl Writeable for Event { write_tlv_fields!(writer, { (0, payment_id, required), (2, payment_hash, required), - (4, path.hops, vec_type), + (4, path.hops, required_vec), (6, path.blinded_tail, option), }) }, @@ -1017,7 +1017,7 @@ impl Writeable for Event { write_tlv_fields!(writer, { (0, payment_id, required), (2, payment_hash, required), - (4, path.hops, vec_type), + (4, path.hops, required_vec), (6, short_channel_id, option), (8, path.blinded_tail, option), }) @@ -1162,7 +1162,9 @@ impl MaybeReadable for Event { (1, network_update, upgradable_option), (2, payment_failed_permanently, required), (4, blinded_tail, option), - (5, path, vec_type), + // Added as a part of LDK 0.0.101 and always filled in since. + // Defaults to an empty Vec, though likely should have been `Option`al. + (5, path, optional_vec), (7, short_channel_id, option), (11, payment_id, option), (13, failure_opt, upgradable_option), @@ -1279,13 +1281,13 @@ impl MaybeReadable for Event { _init_and_read_tlv_fields!(reader, { (0, payment_id, required), (2, payment_hash, option), - (4, path, vec_type), + (4, path, required_vec), (6, blinded_tail, option), }); Ok(Some(Event::PaymentPathSuccessful { payment_id: payment_id.0.unwrap(), payment_hash, - path: Path { hops: path.unwrap(), blinded_tail }, + path: Path { hops: path, blinded_tail }, })) }; f() @@ -1338,13 +1340,13 @@ impl MaybeReadable for Event { _init_and_read_tlv_fields!(reader, { (0, payment_id, required), (2, payment_hash, required), - (4, path, vec_type), + (4, path, required_vec), (6, blinded_tail, option), }); Ok(Some(Event::ProbeSuccessful { payment_id: payment_id.0.unwrap(), payment_hash: payment_hash.0.unwrap(), - path: Path { hops: path.unwrap(), blinded_tail }, + path: Path { hops: path, blinded_tail }, })) }; f() @@ -1354,14 +1356,14 @@ impl MaybeReadable for Event { _init_and_read_tlv_fields!(reader, { (0, payment_id, required), (2, payment_hash, required), - (4, path, vec_type), + (4, path, required_vec), (6, short_channel_id, option), (8, blinded_tail, option), }); Ok(Some(Event::ProbeFailed { payment_id: payment_id.0.unwrap(), payment_hash: payment_hash.0.unwrap(), - path: Path { hops: path.unwrap(), blinded_tail }, + path: Path { hops: path, blinded_tail }, short_channel_id, })) }; diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index fd27d230866..85490afaec1 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -1056,7 +1056,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, { (0, inner, required), (2, counterparty_sig, required), (4, holder_sig_first, required), - (6, counterparty_htlc_sigs, vec_type), + (6, counterparty_htlc_sigs, required_vec), }); impl HolderCommitmentTransaction { @@ -1346,7 +1346,7 @@ impl Writeable for CommitmentTransaction { (6, self.feerate_per_kw, required), (8, self.keys, required), (10, self.built, required), - (12, self.htlcs, vec_type), + (12, self.htlcs, required_vec), (14, legacy_deserialization_prevention_marker, option), (15, self.channel_type_features, required), }); @@ -1356,24 +1356,14 @@ impl Writeable for CommitmentTransaction { impl Readable for CommitmentTransaction { fn read(reader: &mut R) -> Result { - let mut commitment_number = RequiredWrapper(None); - let mut to_broadcaster_value_sat = RequiredWrapper(None); - let mut to_countersignatory_value_sat = RequiredWrapper(None); - let mut feerate_per_kw = RequiredWrapper(None); - let mut keys = RequiredWrapper(None); - let mut built = RequiredWrapper(None); - _init_tlv_field_var!(htlcs, vec_type); - let mut _legacy_deserialization_prevention_marker: Option<()> = None; - let mut channel_type_features = None; - - read_tlv_fields!(reader, { + _init_and_read_tlv_fields!(reader, { (0, commitment_number, required), (2, to_broadcaster_value_sat, required), (4, to_countersignatory_value_sat, required), (6, feerate_per_kw, required), (8, keys, required), (10, built, required), - (12, htlcs, vec_type), + (12, htlcs, required_vec), (14, _legacy_deserialization_prevention_marker, option), (15, channel_type_features, option), }); @@ -1389,7 +1379,7 @@ impl Readable for CommitmentTransaction { feerate_per_kw: feerate_per_kw.0.unwrap(), keys: keys.0.unwrap(), built: built.0.unwrap(), - htlcs: _init_tlv_based_struct_field!(htlcs, vec_type), + htlcs, channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key()) }) } diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 30280f0b1f1..95409fa1e5c 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -6781,11 +6781,11 @@ impl Writeable for Channel { (5, self.context.config, required), (6, serialized_holder_htlc_max_in_flight, option), (7, self.context.shutdown_scriptpubkey, option), - (8, self.context.blocked_monitor_updates, vec_type), + (8, self.context.blocked_monitor_updates, optional_vec), (9, self.context.target_closing_feerate_sats_per_kw, option), - (11, self.context.monitor_pending_finalized_fulfills, vec_type), + (11, self.context.monitor_pending_finalized_fulfills, required_vec), (13, self.context.channel_creation_height, required), - (15, preimages, vec_type), + (15, preimages, required_vec), (17, self.context.announcement_sigs_state, required), (19, self.context.latest_inbound_scid_alias, option), (21, self.context.outbound_scid_alias, required), @@ -7089,11 +7089,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch (5, config, option), // Note that if none is provided we will *not* overwrite the existing one. (6, holder_max_htlc_value_in_flight_msat, option), (7, shutdown_scriptpubkey, option), - (8, blocked_monitor_updates, vec_type), + (8, blocked_monitor_updates, optional_vec), (9, target_closing_feerate_sats_per_kw, option), - (11, monitor_pending_finalized_fulfills, vec_type), + (11, monitor_pending_finalized_fulfills, optional_vec), (13, channel_creation_height, option), - (15, preimages_opt, vec_type), + (15, preimages_opt, optional_vec), (17, announcement_sigs_state, option), (19, latest_inbound_scid_alias, option), (21, outbound_scid_alias, option), diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 980616770c8..b4b1d64acb1 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -45,7 +45,7 @@ use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, No #[cfg(any(feature = "_test_utils", test))] use crate::ln::features::InvoiceFeatures; use crate::routing::gossip::NetworkGraph; -use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteHop, RouteParameters, Router}; +use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router}; use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters}; use crate::ln::msgs; use crate::ln::onion_utils; @@ -3170,6 +3170,7 @@ where /// irrevocably committed to on our end. In such a case, do NOT retry the payment with a /// different route unless you intend to pay twice! /// + /// [`RouteHop`]: crate::routing::router::RouteHop /// [`Event::PaymentSent`]: events::Event::PaymentSent /// [`Event::PaymentFailed`]: events::Event::PaymentFailed /// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs @@ -7442,7 +7443,7 @@ impl Readable for ChannelDetails { } impl_writeable_tlv_based!(PhantomRouteHints, { - (2, channels, vec_type), + (2, channels, required_vec), (4, phantom_scid, required), (6, real_node_pubkey, required), }); @@ -7634,7 +7635,7 @@ impl Readable for HTLCSource { 0 => { let mut session_priv: crate::util::ser::RequiredWrapper = crate::util::ser::RequiredWrapper(None); let mut first_hop_htlc_msat: u64 = 0; - let mut path_hops: Option> = Some(Vec::new()); + let mut path_hops = Vec::new(); let mut payment_id = None; let mut payment_params: Option = None; let mut blinded_tail: Option = None; @@ -7642,7 +7643,7 @@ impl Readable for HTLCSource { (0, session_priv, required), (1, payment_id, option), (2, first_hop_htlc_msat, required), - (4, path_hops, vec_type), + (4, path_hops, required_vec), (5, payment_params, (option: ReadableArgs, 0)), (6, blinded_tail, option), }); @@ -7651,7 +7652,7 @@ impl Readable for HTLCSource { // instead. payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref())); } - let path = Path { hops: path_hops.ok_or(DecodeError::InvalidValue)?, blinded_tail }; + let path = Path { hops: path_hops, blinded_tail }; if path.hops.len() == 0 { return Err(DecodeError::InvalidValue); } @@ -7686,7 +7687,7 @@ impl Writeable for HTLCSource { (1, payment_id_opt, option), (2, first_hop_htlc_msat, required), // 3 was previously used to write a PaymentSecret for the payment. - (4, path.hops, vec_type), + (4, path.hops, required_vec), (5, None::, option), // payment_params in LDK versions prior to 0.0.115 (6, path.blinded_tail, option), }); @@ -7936,7 +7937,7 @@ where (6, monitor_update_blocked_actions_per_peer, option), (7, self.fake_scid_rand_bytes, required), (8, if events_not_backwards_compatible { Some(&*events) } else { None }, option), - (9, htlc_purposes, vec_type), + (9, htlc_purposes, required_vec), (10, in_flight_monitor_updates, option), (11, self.probing_cookie_secret, required), (13, htlc_onion_fields, optional_vec), @@ -8375,7 +8376,7 @@ where (6, monitor_update_blocked_actions_per_peer, option), (7, fake_scid_rand_bytes, option), (8, events_override, option), - (9, claimable_htlc_purposes, vec_type), + (9, claimable_htlc_purposes, optional_vec), (10, in_flight_monitor_updates, option), (11, probing_cookie_secret, option), (13, claimable_htlc_onion_fields, optional_vec), diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 672c6ae6e96..a514f492326 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -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) diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 3b62c856334..52eb7bcb542 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -645,7 +645,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr, }, (1, Reason) => { (0, failure_code, required), - (2, data, vec_type), + (2, data, required_vec), }, ;); diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 1c3595c3712..8a5628f164c 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -169,7 +169,7 @@ impl Writeable for (Payload, [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 Writeable for (Payload, [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) }) }, diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 40969b180af..644772b8149 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -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(reader: &mut R) -> Result { + fn read(reader: &mut R) -> Result { _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> = _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 = None; - let mut announcement_info_wrap: Option = 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 = _lowest_inbound_channel_fees; + let announcement_info_wrap: Option = announcement_info_wrap; Ok(NodeInfo { announcement_info: announcement_info_wrap.map(|w| w.0), - channels: _init_tlv_based_struct_field!(channels, vec_type), + channels, }) } } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index ed5b772edad..8c00df99a7e 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -283,7 +283,7 @@ pub struct BlindedTail { } impl_writeable_tlv_based!(BlindedTail, { - (0, hops, vec_type), + (0, hops, required_vec), (2, blinding_point, required), (4, excess_final_cltv_expiry_delta, required), (6, final_value_msat, required), @@ -550,10 +550,10 @@ impl Writeable for PaymentParameters { (1, self.max_total_cltv_expiry_delta, required), (2, self.payee.features(), option), (3, self.max_path_count, required), - (4, *clear_hints, vec_type), + (4, *clear_hints, required_vec), (5, self.max_channel_saturation_power_of_half, required), (6, self.expiry_time, option), - (7, self.previously_failed_channels, vec_type), + (7, self.previously_failed_channels, required_vec), (8, *blinded_hints, optional_vec), (9, self.payee.final_cltv_expiry_delta(), option), }); @@ -568,14 +568,13 @@ impl ReadableArgs for PaymentParameters { (1, max_total_cltv_expiry_delta, (default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA)), (2, features, (option: ReadableArgs, payee_pubkey.is_some())), (3, max_path_count, (default_value, DEFAULT_MAX_PATH_COUNT)), - (4, route_hints, vec_type), + (4, clear_route_hints, required_vec), (5, max_channel_saturation_power_of_half, (default_value, DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF)), (6, expiry_time, option), - (7, previously_failed_channels, vec_type), + (7, previously_failed_channels, optional_vec), (8, blinded_route_hints, optional_vec), (9, final_cltv_expiry_delta, (default_value, default_final_cltv_expiry_delta)), }); - let clear_route_hints = route_hints.unwrap_or(vec![]); let blinded_route_hints = blinded_route_hints.unwrap_or(vec![]); let payee = if blinded_route_hints.len() != 0 { if clear_route_hints.len() != 0 || payee_pubkey.is_some() { return Err(DecodeError::InvalidValue) } diff --git a/lightning/src/util/chacha20poly1305rfc.rs b/lightning/src/util/chacha20poly1305rfc.rs index 052968377a5..a5bec2c82b8 100644 --- a/lightning/src/util/chacha20poly1305rfc.rs +++ b/lightning/src/util/chacha20poly1305rfc.rs @@ -341,9 +341,9 @@ mod tests { field3: Vec, } 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] diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 8ffcec6d175..710085e2bbd 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -13,6 +13,21 @@ //! [`Readable`]: crate::util::ser::Readable //! [`Writeable`]: crate::util::ser::Writeable +// There are quite a few TLV serialization "types" which behave differently. We currently only +// publicly document the `optional` and `required` types, not supporting anything else publicly and +// changing them at will. +// +// Some of the other types include: +// * (default_value, $default) - reads optionally, reading $default if no TLV is present +// * (static_value, $value) - ignores any TLVs, always using $value +// * required_vec - reads into a Vec without a length prefix, failing if no TLV is present. +// * optional_vec - reads into an Option without a length prefix, continuing if no TLV is +// present. Writes from a Vec directly, only if any elements are present. Note +// that the struct deserialization macros return a Vec, not an Option. +// * upgradable_option - reads via MaybeReadable. +// * upgradable_required - reads via MaybeReadable, requiring a TLV be present but may return None +// if MaybeReadable::read() returns None. + /// Implements serialization for a single TLV record. /// This is exported for use by other exported macros, do not use directly. #[doc(hidden)] @@ -29,7 +44,7 @@ macro_rules! _encode_tlv { BigSize($field.serialized_length() as u64).write($stream)?; $field.write($stream)?; }; - ($stream: expr, $type: expr, $field: expr, vec_type) => { + ($stream: expr, $type: expr, $field: expr, required_vec) => { $crate::_encode_tlv!($stream, $type, $crate::util::ser::WithoutLength(&$field), required); }; ($stream: expr, $optional_type: expr, $optional_field: expr, option) => { @@ -41,7 +56,7 @@ macro_rules! _encode_tlv { }; ($stream: expr, $type: expr, $field: expr, optional_vec) => { if !$field.is_empty() { - $crate::_encode_tlv!($stream, $type, $field, vec_type); + $crate::_encode_tlv!($stream, $type, $field, required_vec); } }; ($stream: expr, $type: expr, $field: expr, upgradable_required) => { @@ -159,7 +174,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length { BigSize(field_len as u64).write(&mut $len).expect("No in-memory data may fail to serialize"); $len.0 += field_len; }; - ($len: expr, $type: expr, $field: expr, vec_type) => { + ($len: expr, $type: expr, $field: expr, required_vec) => { $crate::_get_varint_length_prefixed_tlv_length!($len, $type, $crate::util::ser::WithoutLength(&$field), required); }; ($len: expr, $optional_type: expr, $optional_field: expr, option) => { @@ -172,7 +187,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length { }; ($len: expr, $type: expr, $field: expr, optional_vec) => { if !$field.is_empty() { - $crate::_get_varint_length_prefixed_tlv_length!($len, $type, $field, vec_type); + $crate::_get_varint_length_prefixed_tlv_length!($len, $type, $field, required_vec); } }; ($len: expr, $type: expr, $field: expr, (option: $trait: ident $(, $read_arg: expr)?)) => { @@ -236,8 +251,8 @@ macro_rules! _check_decoded_tlv_order { ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, option) => {{ // no-op }}; - ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, vec_type) => {{ - // no-op + ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{ + $crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required); }}; ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, optional_vec) => {{ // no-op @@ -281,8 +296,8 @@ macro_rules! _check_missing_tlv { ($last_seen_type: expr, $type: expr, $field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {{ $crate::_check_missing_tlv!($last_seen_type, $type, $field, required); }}; - ($last_seen_type: expr, $type: expr, $field: ident, vec_type) => {{ - // no-op + ($last_seen_type: expr, $type: expr, $field: ident, required_vec) => {{ + $crate::_check_missing_tlv!($last_seen_type, $type, $field, required); }}; ($last_seen_type: expr, $type: expr, $field: ident, option) => {{ // no-op @@ -320,15 +335,16 @@ macro_rules! _decode_tlv { ($reader: expr, $field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => {{ $field = $trait::read(&mut $reader $(, $read_arg)*)?; }}; - ($reader: expr, $field: ident, vec_type) => {{ + ($reader: expr, $field: ident, required_vec) => {{ let f: $crate::util::ser::WithoutLength> = $crate::util::ser::Readable::read(&mut $reader)?; - $field = Some(f.0); + $field = f.0; }}; ($reader: expr, $field: ident, option) => {{ $field = Some($crate::util::ser::Readable::read(&mut $reader)?); }}; ($reader: expr, $field: ident, optional_vec) => {{ - $crate::_decode_tlv!($reader, $field, vec_type); + let f: $crate::util::ser::WithoutLength> = $crate::util::ser::Readable::read(&mut $reader)?; + $field = Some(f.0); }}; // `upgradable_required` indicates we're reading a required TLV that may have been upgraded // without backwards compat. We'll error if the field is missing, and return `Ok(None)` if the @@ -694,8 +710,8 @@ macro_rules! _init_tlv_based_struct_field { ($field: ident, required) => { $field.0.unwrap() }; - ($field: ident, vec_type) => { - $field.unwrap() + ($field: ident, required_vec) => { + $field }; ($field: ident, optional_vec) => { $field.unwrap() @@ -720,8 +736,8 @@ macro_rules! _init_tlv_field_var { ($field: ident, (required: $trait: ident $(, $read_arg: expr)?)) => { $crate::_init_tlv_field_var!($field, required); }; - ($field: ident, vec_type) => { - let mut $field = Some(Vec::new()); + ($field: ident, required_vec) => { + let mut $field = Vec::new(); }; ($field: ident, option) => { let mut $field = None;