Skip to content

Commit a04bf84

Browse files
committed
Convert some vec_type TLVs to required_vec
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 66784e3. * `NodeInfo::channels` has been written since `NetworkGraph` structs were converted to TLVs in 321b19c. * Several test-only TLV writes were converted.
1 parent 32846d3 commit a04bf84

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

lightning/src/ln/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@ mod tests {
37603760
let test_bytes = vec![42u8; 1000];
37613761
if let OnionHopDataFormat::NonFinalNode { short_channel_id } = payload.format {
37623762
_encode_varint_length_prefixed_tlv!(&mut encoded_payload, {
3763-
(1, test_bytes, vec_type),
3763+
(1, test_bytes, required_vec),
37643764
(2, HighZeroBytesDroppedBigSize(payload.amt_to_forward), required),
37653765
(4, HighZeroBytesDroppedBigSize(payload.outgoing_cltv_value), required),
37663766
(6, short_channel_id, required)

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
645645
},
646646
(1, Reason) => {
647647
(0, failure_code, required),
648-
(2, data, vec_type),
648+
(2, data, required_vec),
649649
},
650650
;);
651651

lightning/src/onion_message/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ impl<T: CustomOnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
169169
match &self.0 {
170170
Payload::Forward(ForwardControlTlvs::Blinded(encrypted_bytes)) => {
171171
_encode_varint_length_prefixed_tlv!(w, {
172-
(4, *encrypted_bytes, vec_type)
172+
(4, *encrypted_bytes, required_vec)
173173
})
174174
},
175175
Payload::Receive {
176176
control_tlvs: ReceiveControlTlvs::Blinded(encrypted_bytes), reply_path, message,
177177
} => {
178178
_encode_varint_length_prefixed_tlv!(w, {
179179
(2, reply_path, option),
180-
(4, *encrypted_bytes, vec_type),
180+
(4, *encrypted_bytes, required_vec),
181181
(message.tlv_type(), message, required)
182182
})
183183
},

lightning/src/routing/gossip.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,26 +1120,26 @@ impl Writeable for NodeAnnouncementInfo {
11201120
(4, self.rgb, required),
11211121
(6, self.alias, required),
11221122
(8, self.announcement_message, option),
1123-
(10, empty_addresses, vec_type), // Versions prior to 0.0.115 require this field
1123+
(10, empty_addresses, required_vec), // Versions prior to 0.0.115 require this field
11241124
});
11251125
Ok(())
11261126
}
11271127
}
11281128

11291129
impl Readable for NodeAnnouncementInfo {
1130-
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1130+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
11311131
_init_and_read_tlv_fields!(reader, {
11321132
(0, features, required),
11331133
(2, last_update, required),
11341134
(4, rgb, required),
11351135
(6, alias, required),
11361136
(8, announcement_message, option),
1137-
(10, _addresses, vec_type), // deprecated, not used anymore
1137+
(10, _addresses, optional_vec), // deprecated, not used anymore
11381138
});
11391139
let _: Option<Vec<NetAddress>> = _addresses;
11401140
Ok(Self { features: features.0.unwrap(), last_update: last_update.0.unwrap(), rgb: rgb.0.unwrap(),
11411141
alias: alias.0.unwrap(), announcement_message })
1142-
}
1142+
}
11431143
}
11441144

11451145
/// 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 {
12051205
write_tlv_fields!(writer, {
12061206
// Note that older versions of LDK wrote the lowest inbound fees here at type 0
12071207
(2, self.announcement_info, option),
1208-
(4, self.channels, vec_type),
1208+
(4, self.channels, required_vec),
12091209
});
12101210
Ok(())
12111211
}
@@ -1236,19 +1236,17 @@ impl Readable for NodeInfo {
12361236
// with zero inbound fees, causing that heuristic to provide little gain. Worse, because it
12371237
// requires additional complexity and lookups during routing, it ends up being a
12381238
// performance loss. Thus, we simply ignore the old field here and no longer track it.
1239-
let mut _lowest_inbound_channel_fees: Option<RoutingFees> = None;
1240-
let mut announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrapper> = None;
1241-
_init_tlv_field_var!(channels, vec_type);
1242-
1243-
read_tlv_fields!(reader, {
1239+
_init_and_read_tlv_fields!(reader, {
12441240
(0, _lowest_inbound_channel_fees, option),
12451241
(2, announcement_info_wrap, upgradable_option),
1246-
(4, channels, vec_type),
1242+
(4, channels, required_vec),
12471243
});
1244+
let _: Option<RoutingFees> = _lowest_inbound_channel_fees;
1245+
let announcement_info_wrap: Option<NodeAnnouncementInfoDeserWrapper> = announcement_info_wrap;
12481246

12491247
Ok(NodeInfo {
12501248
announcement_info: announcement_info_wrap.map(|w| w.0),
1251-
channels: _init_tlv_based_struct_field!(channels, vec_type),
1249+
channels,
12521250
})
12531251
}
12541252
}

lightning/src/util/chacha20poly1305rfc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ mod tests {
341341
field3: Vec<u8>,
342342
}
343343
impl_writeable_tlv_based!(TestWriteable, {
344-
(1, field1, vec_type),
345-
(2, field2, vec_type),
346-
(3, field3, vec_type),
344+
(1, field1, required_vec),
345+
(2, field2, required_vec),
346+
(3, field3, required_vec),
347347
});
348348

349349
#[test]

0 commit comments

Comments
 (0)