]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Correct excess-data handling in ChannelUpdate
authorMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 20:01:07 +0000 (16:01 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 22:01:15 +0000 (18:01 -0400)
src/ln/channelmanager.rs
src/ln/msgs.rs

index 073ba792ac156b59d838dade0c9291948fbf7a8d..dc7ac2a816106a1bd2919cc8587615d6237c7245 100644 (file)
@@ -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()[..]);
index 00095cd15ab2ea2badc9941e7b7f84453b9b0be5..eb96fdf225dd035855e8b27f86c1ec9d1547856c 100644 (file)
@@ -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<u8>,
 }
 #[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<u8> {
-               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
        }
 }