Skip to content

Commit ffed82c

Browse files
committed
Add optional last_rapid_gossip_sync_timestamp field to NetworkGraph.
1 parent aac3907 commit ffed82c

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

lightning/src/routing/network_graph.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ impl Readable for NodeId {
123123

124124
/// Represents the network as nodes and channels between them
125125
pub struct NetworkGraph {
126+
/// The timestamp provided by the most recent rapid gossip sync
127+
/// It will be set by the rapid sync process after every sync completion
128+
pub last_rapid_gossip_sync_timestamp: Option<u32>,
126129
genesis_hash: BlockHash,
127130
// Lock order: channels -> nodes
128131
channels: RwLock<BTreeMap<u64, ChannelInfo>>,
@@ -137,6 +140,7 @@ impl Clone for NetworkGraph {
137140
genesis_hash: self.genesis_hash.clone(),
138141
channels: RwLock::new(channels.clone()),
139142
nodes: RwLock::new(nodes.clone()),
143+
last_rapid_gossip_sync_timestamp: self.last_rapid_gossip_sync_timestamp.clone(),
140144
}
141145
}
142146
}
@@ -990,7 +994,9 @@ impl Writeable for NetworkGraph {
990994
node_info.write(writer)?;
991995
}
992996

993-
write_tlv_fields!(writer, {});
997+
write_tlv_fields!(writer, {
998+
(1, self.last_rapid_gossip_sync_timestamp, option),
999+
});
9941000
Ok(())
9951001
}
9961002
}
@@ -1014,12 +1020,18 @@ impl Readable for NetworkGraph {
10141020
let node_info = Readable::read(reader)?;
10151021
nodes.insert(node_id, node_info);
10161022
}
1017-
read_tlv_fields!(reader, {});
1023+
1024+
let mut last_rapid_gossip_sync_timestamp: Option<u32> = None;
1025+
1026+
read_tlv_fields!(reader, {
1027+
(1, last_rapid_gossip_sync_timestamp, option),
1028+
});
10181029

10191030
Ok(NetworkGraph {
10201031
genesis_hash,
10211032
channels: RwLock::new(channels),
10221033
nodes: RwLock::new(nodes),
1034+
last_rapid_gossip_sync_timestamp,
10231035
})
10241036
}
10251037
}
@@ -1053,6 +1065,7 @@ impl NetworkGraph {
10531065
genesis_hash,
10541066
channels: RwLock::new(BTreeMap::new()),
10551067
nodes: RwLock::new(BTreeMap::new()),
1068+
last_rapid_gossip_sync_timestamp: None,
10561069
}
10571070
}
10581071

@@ -2359,6 +2372,18 @@ mod tests {
23592372
assert!(<NetworkGraph>::read(&mut io::Cursor::new(&w.0)).unwrap() == network_graph);
23602373
}
23612374

2375+
#[test]
2376+
fn network_graph_tlv_serialization() {
2377+
let mut network_graph = create_network_graph();
2378+
network_graph.last_rapid_gossip_sync_timestamp.replace(42);
2379+
2380+
let mut w = test_utils::TestVecWriter(Vec::new());
2381+
network_graph.write(&mut w).unwrap();
2382+
let reassembled_network_graph: NetworkGraph = Readable::read(&mut io::Cursor::new(&w.0)).unwrap();
2383+
assert!(reassembled_network_graph == network_graph);
2384+
assert_eq!(reassembled_network_graph.last_rapid_gossip_sync_timestamp.unwrap(), 42);
2385+
}
2386+
23622387
#[test]
23632388
#[cfg(feature = "std")]
23642389
fn calling_sync_routing_table() {

0 commit comments

Comments
 (0)