@@ -23,7 +23,7 @@ use bitcoin::hash_types::BlockHash;
23
23
use chain;
24
24
use chain:: Access ;
25
25
use ln:: features:: { ChannelFeatures , NodeFeatures } ;
26
- use ln:: msgs:: { DecodeError , ErrorAction , LightningError , RoutingMessageHandler , NetAddress , MAX_VALUE_MSAT } ;
26
+ use ln:: msgs:: { DecodeError , ErrorAction , Init , LightningError , RoutingMessageHandler , NetAddress , MAX_VALUE_MSAT } ;
27
27
use ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , OptionalField } ;
28
28
use ln:: msgs:: { QueryChannelRange , ReplyChannelRange , QueryShortChannelIds , ReplyShortChannelIdsEnd } ;
29
29
use ln:: msgs;
@@ -226,7 +226,10 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
226
226
/// gossip messages for each channel. The sync is considered complete when
227
227
/// the final reply_scids_end message is received, though we are not
228
228
/// tracking this directly.
229
- fn sync_routing_table ( & self , their_node_id : & PublicKey ) {
229
+ fn sync_routing_table ( & self , their_node_id : & PublicKey , init_msg : & Init ) {
230
+ if !init_msg. features . supports_gossip_queries ( ) {
231
+ return ( ) ;
232
+ }
230
233
let first_blocknum = 0 ;
231
234
let number_of_blocks = 0xffffffff ;
232
235
log_debug ! ( self . logger, "Sending query_channel_range peer={}, first_blocknum={}, number_of_blocks={}" , log_pubkey!( their_node_id) , first_blocknum, number_of_blocks) ;
@@ -996,9 +999,9 @@ impl NetworkGraph {
996
999
#[ cfg( test) ]
997
1000
mod tests {
998
1001
use chain;
999
- use ln:: features:: { ChannelFeatures , NodeFeatures } ;
1002
+ use ln:: features:: { ChannelFeatures , InitFeatures , NodeFeatures } ;
1000
1003
use routing:: network_graph:: { NetGraphMsgHandler , NetworkGraph } ;
1001
- use ln:: msgs:: { OptionalField , RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
1004
+ use ln:: msgs:: { Init , OptionalField , RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
1002
1005
UnsignedChannelAnnouncement , ChannelAnnouncement , UnsignedChannelUpdate , ChannelUpdate , HTLCFailChannelUpdate ,
1003
1006
ReplyChannelRange , ReplyShortChannelIdsEnd , QueryChannelRange , QueryShortChannelIds , MAX_VALUE_MSAT } ;
1004
1007
use util:: test_utils;
@@ -1939,20 +1942,31 @@ mod tests {
1939
1942
let chain_hash = genesis_block ( Network :: Testnet ) . header . block_hash ( ) ;
1940
1943
let first_blocknum = 0 ;
1941
1944
let number_of_blocks = 0xffff_ffff ;
1942
- net_graph_msg_handler. sync_routing_table ( & node_id_1) ;
1945
+
1946
+ // It should ignore if gossip_queries feature is not enabled
1947
+ {
1948
+ let init_msg = Init { features : InitFeatures :: known ( ) . clear_gossip_queries ( ) } ;
1949
+ net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
1950
+ let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
1951
+ assert_eq ! ( events. len( ) , 0 ) ;
1952
+ }
1943
1953
1944
1954
// It should send a query_channel_message with the correct information
1945
- let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
1946
- assert_eq ! ( events. len( ) , 1 ) ;
1947
- match & events[ 0 ] {
1948
- MessageSendEvent :: SendChannelRangeQuery { node_id, msg } => {
1949
- assert_eq ! ( node_id, & node_id_1) ;
1950
- assert_eq ! ( msg. chain_hash, chain_hash) ;
1951
- assert_eq ! ( msg. first_blocknum, first_blocknum) ;
1952
- assert_eq ! ( msg. number_of_blocks, number_of_blocks) ;
1953
- } ,
1954
- _ => panic ! ( "Expected MessageSendEvent::SendChannelRangeQuery" )
1955
- } ;
1955
+ {
1956
+ let init_msg = Init { features : InitFeatures :: known ( ) } ;
1957
+ net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
1958
+ let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
1959
+ assert_eq ! ( events. len( ) , 1 ) ;
1960
+ match & events[ 0 ] {
1961
+ MessageSendEvent :: SendChannelRangeQuery { node_id, msg } => {
1962
+ assert_eq ! ( node_id, & node_id_1) ;
1963
+ assert_eq ! ( msg. chain_hash, chain_hash) ;
1964
+ assert_eq ! ( msg. first_blocknum, first_blocknum) ;
1965
+ assert_eq ! ( msg. number_of_blocks, number_of_blocks) ;
1966
+ } ,
1967
+ _ => panic ! ( "Expected MessageSendEvent::SendChannelRangeQuery" )
1968
+ } ;
1969
+ }
1956
1970
}
1957
1971
1958
1972
#[ test]
0 commit comments