Skip to content

Commit 3a78f60

Browse files
committed
Also test decoding of legacy ChannelInfo
1 parent 331996b commit 3a78f60

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lightning/src/routing/gossip.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ impl MaybeReadable for ChannelUpdateInfoDeserWrapper {
784784
match ::util::ser::Readable::read(reader) {
785785
Ok(channel_update_option) => Ok(Some(Self(channel_update_option))),
786786
Err(DecodeError::ShortRead) => Ok(None),
787+
Err(DecodeError::InvalidValue) => Ok(None),
787788
Err(err) => Err(err),
788789
}
789790
}
@@ -2953,6 +2954,7 @@ mod tests {
29532954
let node_chanmgrs = ::ln::functional_test_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None, None, None]);
29542955
let nodes = ::ln::functional_test_utils::create_network(2, &node_cfgs, &node_chanmgrs);
29552956

2957+
// 1. Test encoding/decoding of ChannelUpdateInfo
29562958
let chan_update_info = ChannelUpdateInfo {
29572959
last_update: 23,
29582960
enabled: true,
@@ -2971,14 +2973,15 @@ mod tests {
29712973
assert_eq!(chan_update_info, read_chan_update_info);
29722974

29732975
// Check the serialization hasn't changed.
2974-
let old_chan_update_info_with_some: Vec<u8> = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
2975-
assert_eq!(encoded_chan_update_info, old_chan_update_info_with_some);
2976+
let legacy_chan_update_info_with_some: Vec<u8> = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap();
2977+
assert_eq!(encoded_chan_update_info, legacy_chan_update_info_with_some);
29762978

29772979
// Check we fail if htlc_maximum_msat is not present.
2978-
let old_chan_update_info_with_none: Vec<u8> = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
2979-
let read_chan_update_info_res: Result<ChannelUpdateInfo, ::ln::msgs::DecodeError> = ::util::ser::Readable::read(&mut old_chan_update_info_with_none.as_slice());
2980+
let legacy_chan_update_info_with_none: Vec<u8> = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap();
2981+
let read_chan_update_info_res: Result<ChannelUpdateInfo, ::ln::msgs::DecodeError> = ::util::ser::Readable::read(&mut legacy_chan_update_info_with_none.as_slice());
29802982
assert!(read_chan_update_info_res.is_err());
29812983

2984+
// 2. Test encoding/decoding of ChannelInfo
29822985
// Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
29832986
let chan_info_none_updates = ChannelInfo {
29842987
features: ChannelFeatures::known(),
@@ -2997,7 +3000,7 @@ mod tests {
29973000
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
29983001
assert_eq!(chan_info_none_updates, read_chan_info);
29993002

3000-
// Finally check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present.
3003+
// Check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present.
30013004
let chan_info_some_updates = ChannelInfo {
30023005
features: ChannelFeatures::known(),
30033006
node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
@@ -3014,6 +3017,18 @@ mod tests {
30143017

30153018
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap();
30163019
assert_eq!(chan_info_some_updates, read_chan_info);
3020+
3021+
// Check the serialization hasn't changed.
3022+
let legacy_chan_info_with_some: Vec<u8> = hex::decode("ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88043636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23083636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
3023+
assert_eq!(encoded_chan_info, legacy_chan_info_with_some);
3024+
3025+
// Check we can decode legacy ChannelInfo, even if the `two_to_one`/`one_to_two` fields
3026+
// fail to decode.
3027+
let legacy_chan_info_with_none: Vec<u8> = hex::decode("ba00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88042e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23082e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c01000a01000c0100").unwrap();
3028+
let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut legacy_chan_info_with_none.as_slice()).unwrap();
3029+
assert_eq!(read_chan_info.announcement_received_time, 87654);
3030+
assert_eq!(read_chan_info.one_to_two, None);
3031+
assert_eq!(read_chan_info.two_to_one, None);
30173032
}
30183033
}
30193034

0 commit comments

Comments
 (0)