From 9902fce5857c6b6b60792f03dea8758437c8fb8b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 29 Aug 2018 16:01:07 -0400 Subject: [PATCH] Correct excess-data handling in ChannelUpdate --- src/ln/channelmanager.rs | 1 + src/ln/msgs.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 073ba792a..dc7ac2a81 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -876,6 +876,7 @@ impl ChannelManager { htlc_minimum_msat: chan.get_our_htlc_minimum_msat(), fee_base_msat: chan.get_our_fee_base_msat(&*self.fee_estimator), fee_proportional_millionths: self.fee_proportional_millionths, + excess_data: Vec::new(), }; let msg_hash = Sha256dHash::from_data(&unsigned.encode()[..]); diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index 00095cd15..eb96fdf22 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -373,6 +373,7 @@ pub struct UnsignedChannelUpdate { pub htlc_minimum_msat: u64, pub fee_base_msat: u32, pub fee_proportional_millionths: u32, + pub excess_data: Vec, } #[derive(PartialEq, Clone)] pub struct ChannelUpdate { @@ -1434,6 +1435,8 @@ impl MsgDecodable for UnsignedChannelUpdate { if v.len() < 32+8+4+2+2+8+4+4 { return Err(DecodeError::ShortRead); } + let mut excess_data = Vec::with_capacity(v.len() - 64); + excess_data.extend_from_slice(&v[64..]); Ok(Self { chain_hash: deserialize(&v[0..32]).unwrap(), short_channel_id: byte_utils::slice_to_be64(&v[32..40]), @@ -1443,12 +1446,13 @@ impl MsgDecodable for UnsignedChannelUpdate { htlc_minimum_msat: byte_utils::slice_to_be64(&v[48..56]), fee_base_msat: byte_utils::slice_to_be32(&v[56..60]), fee_proportional_millionths: byte_utils::slice_to_be32(&v[60..64]), + excess_data }) } } impl MsgEncodable for UnsignedChannelUpdate { fn encode(&self) -> Vec { - let mut res = Vec::with_capacity(64); + let mut res = Vec::with_capacity(64 + self.excess_data.len()); res.extend_from_slice(&self.chain_hash[..]); res.extend_from_slice(&byte_utils::be64_to_array(self.short_channel_id)); res.extend_from_slice(&byte_utils::be32_to_array(self.timestamp)); @@ -1457,6 +1461,7 @@ impl MsgEncodable for UnsignedChannelUpdate { res.extend_from_slice(&byte_utils::be64_to_array(self.htlc_minimum_msat)); res.extend_from_slice(&byte_utils::be32_to_array(self.fee_base_msat)); res.extend_from_slice(&byte_utils::be32_to_array(self.fee_proportional_millionths)); + res.extend_from_slice(&self.excess_data[..]); res } } -- 2.39.5