@@ -25,7 +25,7 @@ use chain;
25
25
use chain:: Access ;
26
26
use ln:: features:: { ChannelFeatures , NodeFeatures } ;
27
27
use ln:: msgs:: { DecodeError , ErrorAction , Init , LightningError , RoutingMessageHandler , NetAddress , MAX_VALUE_MSAT } ;
28
- use ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , OptionalField } ;
28
+ use ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , OptionalField , GossipTimestampFilter } ;
29
29
use ln:: msgs:: { QueryChannelRange , ReplyChannelRange , QueryShortChannelIds , ReplyShortChannelIdsEnd } ;
30
30
use ln:: msgs;
31
31
use util:: ser:: { Writeable , Readable , Writer } ;
@@ -395,13 +395,28 @@ where C::Target: chain::Access, L::Target: Logger
395
395
/// to request gossip messages for each channel. The sync is considered complete
396
396
/// when the final reply_scids_end message is received, though we are not
397
397
/// tracking this directly.
398
- fn sync_routing_table ( & self , their_node_id : & PublicKey , init_msg : & Init ) {
399
-
398
+ fn peer_connected ( & self , their_node_id : & PublicKey , init_msg : & Init ) {
400
399
// We will only perform a sync with peers that support gossip_queries.
401
400
if !init_msg. features . supports_gossip_queries ( ) {
402
401
return ( ) ;
403
402
}
404
403
404
+ // Send a gossip_timestamp_filter to enable gossip message receipt. Note that we have to
405
+ // use a "all timestamps" filter as sending the current timestamp would result in missing
406
+ // gossip messages that are simply sent late. We could calculate the intended filter time
407
+ // by looking at the current time and subtracting two weeks (before which we'll reject
408
+ // messages), but there's not a lot of reason to bother - our peers should be discarding
409
+ // the same messages.
410
+ let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
411
+ pending_events. push ( MessageSendEvent :: SendGossipTimestampFilter {
412
+ node_id : their_node_id. clone ( ) ,
413
+ msg : GossipTimestampFilter {
414
+ chain_hash : self . network_graph . genesis_hash ,
415
+ first_timestamp : 0 ,
416
+ timestamp_range : u32:: max_value ( ) ,
417
+ } ,
418
+ } ) ;
419
+
405
420
// Check if we need to perform a full synchronization with this peer
406
421
if !self . should_request_full_sync ( & their_node_id) {
407
422
return ( ) ;
@@ -410,7 +425,6 @@ where C::Target: chain::Access, L::Target: Logger
410
425
let first_blocknum = 0 ;
411
426
let number_of_blocks = 0xffffffff ;
412
427
log_debug ! ( self . logger, "Sending query_channel_range peer={}, first_blocknum={}, number_of_blocks={}" , log_pubkey!( their_node_id) , first_blocknum, number_of_blocks) ;
413
- let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
414
428
pending_events. push ( MessageSendEvent :: SendChannelRangeQuery {
415
429
node_id : their_node_id. clone ( ) ,
416
430
msg : QueryChannelRange {
@@ -2271,18 +2285,27 @@ mod tests {
2271
2285
// It should ignore if gossip_queries feature is not enabled
2272
2286
{
2273
2287
let init_msg = Init { features : InitFeatures :: known ( ) . clear_gossip_queries ( ) } ;
2274
- net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
2288
+ net_graph_msg_handler. peer_connected ( & node_id_1, & init_msg) ;
2275
2289
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2276
2290
assert_eq ! ( events. len( ) , 0 ) ;
2277
2291
}
2278
2292
2279
2293
// It should send a query_channel_message with the correct information
2280
2294
{
2281
2295
let init_msg = Init { features : InitFeatures :: known ( ) } ;
2282
- net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
2296
+ net_graph_msg_handler. peer_connected ( & node_id_1, & init_msg) ;
2283
2297
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2284
- assert_eq ! ( events. len( ) , 1 ) ;
2298
+ assert_eq ! ( events. len( ) , 2 ) ;
2285
2299
match & events[ 0 ] {
2300
+ MessageSendEvent :: SendGossipTimestampFilter { node_id, msg } => {
2301
+ assert_eq ! ( node_id, & node_id_1) ;
2302
+ assert_eq ! ( msg. chain_hash, chain_hash) ;
2303
+ assert_eq ! ( msg. first_timestamp, 0 ) ;
2304
+ assert_eq ! ( msg. timestamp_range, u32 :: max_value( ) ) ;
2305
+ } ,
2306
+ _ => panic ! ( "Expected MessageSendEvent::SendChannelRangeQuery" )
2307
+ } ;
2308
+ match & events[ 1 ] {
2286
2309
MessageSendEvent :: SendChannelRangeQuery { node_id, msg } => {
2287
2310
assert_eq ! ( node_id, & node_id_1) ;
2288
2311
assert_eq ! ( msg. chain_hash, chain_hash) ;
@@ -2303,12 +2326,14 @@ mod tests {
2303
2326
for n in 1 ..7 {
2304
2327
let node_privkey = & SecretKey :: from_slice ( & [ n; 32 ] ) . unwrap ( ) ;
2305
2328
let node_id = PublicKey :: from_secret_key ( & secp_ctx, node_privkey) ;
2306
- net_graph_msg_handler. sync_routing_table ( & node_id, & init_msg) ;
2329
+ net_graph_msg_handler. peer_connected ( & node_id, & init_msg) ;
2307
2330
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2308
2331
if n <= 5 {
2309
- assert_eq ! ( events. len( ) , 1 ) ;
2332
+ assert_eq ! ( events. len( ) , 2 ) ;
2310
2333
} else {
2311
- assert_eq ! ( events. len( ) , 0 ) ;
2334
+ // Even after the we stop sending the explicit query, we should still send a
2335
+ // gossip_timestamp_filter on each new connection.
2336
+ assert_eq ! ( events. len( ) , 1 ) ;
2312
2337
}
2313
2338
2314
2339
}
0 commit comments