Skip to content

Commit 5b59178

Browse files
committed
Add version and TLV suffix for more user-facing "major" structs
1 parent 8ee7d84 commit 5b59178

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,15 @@ impl BaseSign for InMemorySigner {
704704
}
705705
}
706706

707+
const SERIALIZATION_VERSION: u8 = 1;
708+
const MIN_SERIALIZATION_VERSION: u8 = 1;
709+
707710
impl Sign for InMemorySigner {}
708711

709712
impl Writeable for InMemorySigner {
710713
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
714+
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
715+
711716
self.funding_key.write(writer)?;
712717
self.revocation_base_key.write(writer)?;
713718
self.payment_key.write(writer)?;
@@ -718,12 +723,16 @@ impl Writeable for InMemorySigner {
718723
self.channel_value_satoshis.write(writer)?;
719724
self.channel_keys_id.write(writer)?;
720725

726+
write_tlv_fields!(writer, {}, {});
727+
721728
Ok(())
722729
}
723730
}
724731

725732
impl Readable for InMemorySigner {
726733
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
734+
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
735+
727736
let funding_key = Readable::read(reader)?;
728737
let revocation_base_key = Readable::read(reader)?;
729738
let payment_key = Readable::read(reader)?;
@@ -739,6 +748,8 @@ impl Readable for InMemorySigner {
739748
&htlc_base_key);
740749
let keys_id = Readable::read(reader)?;
741750

751+
read_tlv_fields!(reader, {}, {});
752+
742753
Ok(InMemorySigner {
743754
funding_key,
744755
revocation_base_key,

lightning/src/routing/network_graph.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,13 @@ impl Readable for NodeInfo {
660660
}
661661
}
662662

663+
const SERIALIZATION_VERSION: u8 = 1;
664+
const MIN_SERIALIZATION_VERSION: u8 = 1;
665+
663666
impl Writeable for NetworkGraph {
664667
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
668+
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
669+
665670
self.genesis_hash.write(writer)?;
666671
(self.channels.len() as u64).write(writer)?;
667672
for (ref chan_id, ref chan_info) in self.channels.iter() {
@@ -673,12 +678,16 @@ impl Writeable for NetworkGraph {
673678
node_id.write(writer)?;
674679
node_info.write(writer)?;
675680
}
681+
682+
write_tlv_fields!(writer, {}, {});
676683
Ok(())
677684
}
678685
}
679686

680687
impl Readable for NetworkGraph {
681688
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError> {
689+
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
690+
682691
let genesis_hash: BlockHash = Readable::read(reader)?;
683692
let channels_count: u64 = Readable::read(reader)?;
684693
let mut channels = BTreeMap::new();
@@ -694,6 +703,8 @@ impl Readable for NetworkGraph {
694703
let node_info = Readable::read(reader)?;
695704
nodes.insert(node_id, node_info);
696705
}
706+
read_tlv_fields!(reader, {}, {});
707+
697708
Ok(NetworkGraph {
698709
genesis_hash,
699710
channels,

lightning/src/routing/router.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,30 @@ pub struct Route {
9595
pub paths: Vec<Vec<RouteHop>>,
9696
}
9797

98+
const SERIALIZATION_VERSION: u8 = 1;
99+
const MIN_SERIALIZATION_VERSION: u8 = 1;
100+
98101
impl Writeable for Route {
99102
fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
103+
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
100104
(self.paths.len() as u64).write(writer)?;
101105
for hops in self.paths.iter() {
102106
hops.write(writer)?;
103107
}
108+
write_tlv_fields!(writer, {}, {});
104109
Ok(())
105110
}
106111
}
107112

108113
impl Readable for Route {
109114
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Route, DecodeError> {
115+
let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
110116
let path_count: u64 = Readable::read(reader)?;
111117
let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize);
112118
for _ in 0..path_count {
113119
paths.push(Readable::read(reader)?);
114120
}
121+
read_tlv_fields!(reader, {}, {});
115122
Ok(Route { paths })
116123
}
117124
}

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48;
3838
///
3939
/// Eventually we will probably want to expose a variant of this which would essentially
4040
/// be what you'd want to run on a hardware wallet.
41+
///
42+
/// Note that before we do so we should ensure its serialization format has backwards- and
43+
/// forwards-compatibility prefix/suffixes!
4144
#[derive(Clone)]
4245
pub struct EnforcingSigner {
4346
pub inner: InMemorySigner,

0 commit comments

Comments
 (0)