@@ -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 unix timestamp in UTC 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,17 @@ 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
+ read_tlv_fields ! ( reader, {
1026
+ ( 1 , last_rapid_gossip_sync_timestamp, option) ,
1027
+ } ) ;
1018
1028
1019
1029
Ok ( NetworkGraph {
1020
1030
genesis_hash,
1021
1031
channels : RwLock :: new ( channels) ,
1022
1032
nodes : RwLock :: new ( nodes) ,
1033
+ last_rapid_gossip_sync_timestamp,
1023
1034
} )
1024
1035
}
1025
1036
}
@@ -1053,6 +1064,7 @@ impl NetworkGraph {
1053
1064
genesis_hash,
1054
1065
channels : RwLock :: new ( BTreeMap :: new ( ) ) ,
1055
1066
nodes : RwLock :: new ( BTreeMap :: new ( ) ) ,
1067
+ last_rapid_gossip_sync_timestamp : None ,
1056
1068
}
1057
1069
}
1058
1070
@@ -2359,6 +2371,18 @@ mod tests {
2359
2371
assert ! ( <NetworkGraph >:: read( & mut io:: Cursor :: new( & w. 0 ) ) . unwrap( ) == network_graph) ;
2360
2372
}
2361
2373
2374
+ #[ test]
2375
+ fn network_graph_tlv_serialization ( ) {
2376
+ let mut network_graph = create_network_graph ( ) ;
2377
+ network_graph. last_rapid_gossip_sync_timestamp . replace ( 42 ) ;
2378
+
2379
+ let mut w = test_utils:: TestVecWriter ( Vec :: new ( ) ) ;
2380
+ network_graph. write ( & mut w) . unwrap ( ) ;
2381
+ let reassembled_network_graph: NetworkGraph = Readable :: read ( & mut io:: Cursor :: new ( & w. 0 ) ) . unwrap ( ) ;
2382
+ assert ! ( reassembled_network_graph == network_graph) ;
2383
+ assert_eq ! ( reassembled_network_graph. last_rapid_gossip_sync_timestamp. unwrap( ) , 42 ) ;
2384
+ }
2385
+
2362
2386
#[ test]
2363
2387
#[ cfg( feature = "std" ) ]
2364
2388
fn calling_sync_routing_table ( ) {
0 commit comments