@@ -123,6 +123,9 @@ impl Readable for NodeId {
123
123
124
124
/// Represents the network as nodes and channels between them
125
125
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 > ,
126
129
genesis_hash : BlockHash ,
127
130
// Lock order: channels -> nodes
128
131
channels : RwLock < BTreeMap < u64 , ChannelInfo > > ,
@@ -137,6 +140,7 @@ impl Clone for NetworkGraph {
137
140
genesis_hash : self . genesis_hash . clone ( ) ,
138
141
channels : RwLock :: new ( channels. clone ( ) ) ,
139
142
nodes : RwLock :: new ( nodes. clone ( ) ) ,
143
+ last_rapid_gossip_sync_timestamp : self . last_rapid_gossip_sync_timestamp . clone ( ) ,
140
144
}
141
145
}
142
146
}
@@ -990,7 +994,9 @@ impl Writeable for NetworkGraph {
990
994
node_info. write ( writer) ?;
991
995
}
992
996
993
- write_tlv_fields ! ( writer, { } ) ;
997
+ write_tlv_fields ! ( writer, {
998
+ ( 1 , self . last_rapid_gossip_sync_timestamp, option) ,
999
+ } ) ;
994
1000
Ok ( ( ) )
995
1001
}
996
1002
}
@@ -1014,12 +1020,18 @@ impl Readable for NetworkGraph {
1014
1020
let node_info = Readable :: read ( reader) ?;
1015
1021
nodes. insert ( node_id, node_info) ;
1016
1022
}
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
+ } ) ;
1018
1029
1019
1030
Ok ( NetworkGraph {
1020
1031
genesis_hash,
1021
1032
channels : RwLock :: new ( channels) ,
1022
1033
nodes : RwLock :: new ( nodes) ,
1034
+ last_rapid_gossip_sync_timestamp,
1023
1035
} )
1024
1036
}
1025
1037
}
@@ -1053,6 +1065,7 @@ impl NetworkGraph {
1053
1065
genesis_hash,
1054
1066
channels : RwLock :: new ( BTreeMap :: new ( ) ) ,
1055
1067
nodes : RwLock :: new ( BTreeMap :: new ( ) ) ,
1068
+ last_rapid_gossip_sync_timestamp : None ,
1056
1069
}
1057
1070
}
1058
1071
@@ -2359,6 +2372,18 @@ mod tests {
2359
2372
assert ! ( <NetworkGraph >:: read( & mut io:: Cursor :: new( & w. 0 ) ) . unwrap( ) == network_graph) ;
2360
2373
}
2361
2374
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
+
2362
2387
#[ test]
2363
2388
#[ cfg( feature = "std" ) ]
2364
2389
fn calling_sync_routing_table ( ) {
0 commit comments