]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add version and TLV suffix for more user-facing "major" structs
authorMatt Corallo <git@bluematt.me>
Fri, 7 May 2021 22:36:45 +0000 (22:36 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 24 May 2021 22:05:41 +0000 (22:05 +0000)
lightning/src/chain/keysinterface.rs
lightning/src/routing/network_graph.rs
lightning/src/routing/router.rs
lightning/src/util/enforcing_trait_impls.rs

index 114ceec211cd254fb22d14f64ac379960237f59b..d6fea17d430583b977fd724559e7b1d32857b095 100644 (file)
@@ -704,10 +704,15 @@ impl BaseSign for InMemorySigner {
        }
 }
 
+const SERIALIZATION_VERSION: u8 = 1;
+const MIN_SERIALIZATION_VERSION: u8 = 1;
+
 impl Sign for InMemorySigner {}
 
 impl Writeable for InMemorySigner {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
+               write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
+
                self.funding_key.write(writer)?;
                self.revocation_base_key.write(writer)?;
                self.payment_key.write(writer)?;
@@ -718,12 +723,16 @@ impl Writeable for InMemorySigner {
                self.channel_value_satoshis.write(writer)?;
                self.channel_keys_id.write(writer)?;
 
+               write_tlv_fields!(writer, {}, {});
+
                Ok(())
        }
 }
 
 impl Readable for InMemorySigner {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+               let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
+
                let funding_key = Readable::read(reader)?;
                let revocation_base_key = Readable::read(reader)?;
                let payment_key = Readable::read(reader)?;
@@ -739,6 +748,8 @@ impl Readable for InMemorySigner {
                                                             &htlc_base_key);
                let keys_id = Readable::read(reader)?;
 
+               read_tlv_fields!(reader, {}, {});
+
                Ok(InMemorySigner {
                        funding_key,
                        revocation_base_key,
index ee73dc0e88e3c4e5308776b9c1dac0908602bc29..16e0a978a91802c24dbb9ed1db49f960b5be0725 100644 (file)
@@ -660,8 +660,13 @@ impl Readable for NodeInfo {
        }
 }
 
+const SERIALIZATION_VERSION: u8 = 1;
+const MIN_SERIALIZATION_VERSION: u8 = 1;
+
 impl Writeable for NetworkGraph {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
+               write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
+
                self.genesis_hash.write(writer)?;
                (self.channels.len() as u64).write(writer)?;
                for (ref chan_id, ref chan_info) in self.channels.iter() {
@@ -673,12 +678,16 @@ impl Writeable for NetworkGraph {
                        node_id.write(writer)?;
                        node_info.write(writer)?;
                }
+
+               write_tlv_fields!(writer, {}, {});
                Ok(())
        }
 }
 
 impl Readable for NetworkGraph {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError> {
+               let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
+
                let genesis_hash: BlockHash = Readable::read(reader)?;
                let channels_count: u64 = Readable::read(reader)?;
                let mut channels = BTreeMap::new();
@@ -694,6 +703,8 @@ impl Readable for NetworkGraph {
                        let node_info = Readable::read(reader)?;
                        nodes.insert(node_id, node_info);
                }
+               read_tlv_fields!(reader, {}, {});
+
                Ok(NetworkGraph {
                        genesis_hash,
                        channels,
index ba964d734c670e4cfbbc4d12eca1ea9e71f37491..489b900605384a52423547964d89db3113883d0b 100644 (file)
@@ -95,23 +95,30 @@ pub struct Route {
        pub paths: Vec<Vec<RouteHop>>,
 }
 
+const SERIALIZATION_VERSION: u8 = 1;
+const MIN_SERIALIZATION_VERSION: u8 = 1;
+
 impl Writeable for Route {
        fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
+               write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
                (self.paths.len() as u64).write(writer)?;
                for hops in self.paths.iter() {
                        hops.write(writer)?;
                }
+               write_tlv_fields!(writer, {}, {});
                Ok(())
        }
 }
 
 impl Readable for Route {
        fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Route, DecodeError> {
+               let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
                let path_count: u64 = Readable::read(reader)?;
                let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize);
                for _ in 0..path_count {
                        paths.push(Readable::read(reader)?);
                }
+               read_tlv_fields!(reader, {}, {});
                Ok(Route { paths })
        }
 }
index 32c17af64dd877efcd8c07a7698e0049bdc739bd..55e45d309454dd286a8b357a65dbd61b9fccfe9c 100644 (file)
@@ -38,6 +38,9 @@ pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48;
 ///
 /// Eventually we will probably want to expose a variant of this which would essentially
 /// be what you'd want to run on a hardware wallet.
+///
+/// Note that before we do so we should ensure its serialization format has backwards- and
+/// forwards-compatibility prefix/suffixes!
 #[derive(Clone)]
 pub struct EnforcingSigner {
        pub inner: InMemorySigner,