Skip to content

Commit 7e11540

Browse files
committed
Drop vec_type TLV handling entirely
Historically, we used `vec_type` for all TLV Vec reads/writes, but it is asymmetric and thus somewhat confusing - on the write side it always writes a TLV entry, even if there are zero elements. On the read side, it happily accepts a missing TLV, providing a zero-length vector. In 85b573d a new `optional_vec` TLV format was added which was symmetric, but only supports optional vecs. Now that we've migrated entirely to the new `required_vec` TLV type, we can entirely remove the awkward `vec_type`.
1 parent 6d2e6bb commit 7e11540

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ macro_rules! _encode_tlv {
3232
($stream: expr, $type: expr, $field: expr, required_vec) => {
3333
$crate::_encode_tlv!($stream, $type, $crate::util::ser::WithoutLength(&$field), required);
3434
};
35-
($stream: expr, $type: expr, $field: expr, vec_type) => {
36-
$crate::_encode_tlv!($stream, $type, $crate::util::ser::WithoutLength(&$field), required);
37-
};
3835
($stream: expr, $optional_type: expr, $optional_field: expr, option) => {
3936
if let Some(ref field) = $optional_field {
4037
BigSize($optional_type).write($stream)?;
@@ -165,9 +162,6 @@ macro_rules! _get_varint_length_prefixed_tlv_length {
165162
($len: expr, $type: expr, $field: expr, required_vec) => {
166163
$crate::_get_varint_length_prefixed_tlv_length!($len, $type, $crate::util::ser::WithoutLength(&$field), required);
167164
};
168-
($len: expr, $type: expr, $field: expr, vec_type) => {
169-
$crate::_get_varint_length_prefixed_tlv_length!($len, $type, $crate::util::ser::WithoutLength(&$field), required);
170-
};
171165
($len: expr, $optional_type: expr, $optional_field: expr, option) => {
172166
if let Some(ref field) = $optional_field {
173167
BigSize($optional_type).write(&mut $len).expect("No in-memory data may fail to serialize");
@@ -245,9 +239,6 @@ macro_rules! _check_decoded_tlv_order {
245239
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{
246240
$crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
247241
}};
248-
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, vec_type) => {{
249-
// no-op
250-
}};
251242
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, optional_vec) => {{
252243
// no-op
253244
}};
@@ -293,9 +284,6 @@ macro_rules! _check_missing_tlv {
293284
($last_seen_type: expr, $type: expr, $field: ident, required_vec) => {{
294285
$crate::_check_missing_tlv!($last_seen_type, $type, $field, required);
295286
}};
296-
($last_seen_type: expr, $type: expr, $field: ident, vec_type) => {{
297-
// no-op
298-
}};
299287
($last_seen_type: expr, $type: expr, $field: ident, option) => {{
300288
// no-op
301289
}};
@@ -336,15 +324,12 @@ macro_rules! _decode_tlv {
336324
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
337325
$field = f.0;
338326
}};
339-
($reader: expr, $field: ident, vec_type) => {{
340-
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
341-
$field = Some(f.0);
342-
}};
343327
($reader: expr, $field: ident, option) => {{
344328
$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
345329
}};
346330
($reader: expr, $field: ident, optional_vec) => {{
347-
$crate::_decode_tlv!($reader, $field, vec_type);
331+
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
332+
$field = Some(f.0);
348333
}};
349334
// `upgradable_required` indicates we're reading a required TLV that may have been upgraded
350335
// without backwards compat. We'll error if the field is missing, and return `Ok(None)` if the
@@ -713,9 +698,6 @@ macro_rules! _init_tlv_based_struct_field {
713698
($field: ident, required_vec) => {
714699
$field
715700
};
716-
($field: ident, vec_type) => {
717-
$field.unwrap()
718-
};
719701
($field: ident, optional_vec) => {
720702
$field.unwrap()
721703
};
@@ -742,9 +724,6 @@ macro_rules! _init_tlv_field_var {
742724
($field: ident, required_vec) => {
743725
let mut $field = Vec::new();
744726
};
745-
($field: ident, vec_type) => {
746-
let mut $field = Some(Vec::new());
747-
};
748727
($field: ident, option) => {
749728
let mut $field = None;
750729
};

0 commit comments

Comments
 (0)