@@ -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 } ;
@@ -401,6 +401,22 @@ where C::Target: chain::Access, L::Target: Logger
401
401
return ( ) ;
402
402
}
403
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
+
404
420
// Check if we need to perform a full synchronization with this peer
405
421
if !self . should_request_full_sync ( & their_node_id) {
406
422
return ( ) ;
@@ -409,7 +425,6 @@ where C::Target: chain::Access, L::Target: Logger
409
425
let first_blocknum = 0 ;
410
426
let number_of_blocks = 0xffffffff ;
411
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) ;
412
- let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
413
428
pending_events. push ( MessageSendEvent :: SendChannelRangeQuery {
414
429
node_id : their_node_id. clone ( ) ,
415
430
msg : QueryChannelRange {
@@ -2280,8 +2295,17 @@ mod tests {
2280
2295
let init_msg = Init { features : InitFeatures :: known ( ) } ;
2281
2296
net_graph_msg_handler. peer_connected ( & node_id_1, & init_msg) ;
2282
2297
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2283
- assert_eq ! ( events. len( ) , 1 ) ;
2298
+ assert_eq ! ( events. len( ) , 2 ) ;
2284
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 ] {
2285
2309
MessageSendEvent :: SendChannelRangeQuery { node_id, msg } => {
2286
2310
assert_eq ! ( node_id, & node_id_1) ;
2287
2311
assert_eq ! ( msg. chain_hash, chain_hash) ;
@@ -2305,9 +2329,11 @@ mod tests {
2305
2329
net_graph_msg_handler. peer_connected ( & node_id, & init_msg) ;
2306
2330
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2307
2331
if n <= 5 {
2308
- assert_eq ! ( events. len( ) , 1 ) ;
2332
+ assert_eq ! ( events. len( ) , 2 ) ;
2309
2333
} else {
2310
- 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 ) ;
2311
2337
}
2312
2338
2313
2339
}
0 commit comments