diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 9c6570c59cd..ec53eb43bd0 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -784,6 +784,7 @@ impl MaybeReadable for ChannelUpdateInfoDeserWrapper { match ::util::ser::Readable::read(reader) { Ok(channel_update_option) => Ok(Some(Self(channel_update_option))), Err(DecodeError::ShortRead) => Ok(None), + Err(DecodeError::InvalidValue) => Ok(None), Err(err) => Err(err), } } @@ -2953,6 +2954,7 @@ mod tests { let node_chanmgrs = ::ln::functional_test_utils::create_node_chanmgrs(2, &node_cfgs, &[None, None, None, None]); let nodes = ::ln::functional_test_utils::create_network(2, &node_cfgs, &node_chanmgrs); + // 1. Test encoding/decoding of ChannelUpdateInfo let chan_update_info = ChannelUpdateInfo { last_update: 23, enabled: true, @@ -2971,14 +2973,15 @@ mod tests { assert_eq!(chan_update_info, read_chan_update_info); // Check the serialization hasn't changed. - let old_chan_update_info_with_some: Vec = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap(); - assert_eq!(encoded_chan_update_info, old_chan_update_info_with_some); + let legacy_chan_update_info_with_some: Vec = hex::decode("340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c0100").unwrap(); + assert_eq!(encoded_chan_update_info, legacy_chan_update_info_with_some); // Check we fail if htlc_maximum_msat is not present. - let old_chan_update_info_with_none: Vec = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap(); - let read_chan_update_info_res: Result = ::util::ser::Readable::read(&mut old_chan_update_info_with_none.as_slice()); + let legacy_chan_update_info_with_none: Vec = hex::decode("2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c0100").unwrap(); + let read_chan_update_info_res: Result = ::util::ser::Readable::read(&mut legacy_chan_update_info_with_none.as_slice()); assert!(read_chan_update_info_res.is_err()); + // 2. Test encoding/decoding of ChannelInfo // Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present. let chan_info_none_updates = ChannelInfo { features: ChannelFeatures::known(), @@ -2997,7 +3000,7 @@ mod tests { let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap(); assert_eq!(chan_info_none_updates, read_chan_info); - // Finally check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present. + // Check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present. let chan_info_some_updates = ChannelInfo { features: ChannelFeatures::known(), node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()), @@ -3014,6 +3017,18 @@ mod tests { let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut encoded_chan_info.as_slice()).unwrap(); assert_eq!(chan_info_some_updates, read_chan_info); + + // Check the serialization hasn't changed. + let legacy_chan_info_with_some: Vec = hex::decode("ca00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88043636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23083636340004000000170201010402002a060800000000000004d2080909000000000000162e0a0d0c00040000000902040000000a0c01000a01000c0100").unwrap(); + assert_eq!(encoded_chan_info, legacy_chan_info_with_some); + + // Check we can decode legacy ChannelInfo, even if the `two_to_one`/`one_to_two` fields + // fail to decode. + let legacy_chan_info_with_none: Vec = hex::decode("ba00020000010800000000000156660221027f921585f2ac0c7c70e36110adecfd8fd14b8a99bfb3d000a283fcac358fce88042e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c010006210355f8d2238a322d16b602bd0ceaad5b01019fb055971eaadcc9b29226a4da6c23082e2e2c0004000000170201010402002a060800000000000004d20801000a0d0c00040000000902040000000a0c01000a01000c0100").unwrap(); + let read_chan_info: ChannelInfo = ::util::ser::Readable::read(&mut legacy_chan_info_with_none.as_slice()).unwrap(); + assert_eq!(read_chan_info.announcement_received_time, 87654); + assert_eq!(read_chan_info.one_to_two, None); + assert_eq!(read_chan_info.two_to_one, None); } }