@@ -24,7 +24,7 @@ use chain;
24
24
use chain:: Access ;
25
25
use ln:: features:: { ChannelFeatures , NodeFeatures } ;
26
26
use ln:: msgs:: { DecodeError , ErrorAction , Init , LightningError , RoutingMessageHandler , NetAddress , MAX_VALUE_MSAT } ;
27
- use ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , OptionalField } ;
27
+ use ln:: msgs:: { ChannelAnnouncement , ChannelUpdate , NodeAnnouncement , OptionalField , SUPPORTED_GOSSIP_ENCODINGS } ;
28
28
use ln:: msgs:: { QueryChannelRange , ReplyChannelRange , QueryShortChannelIds , ReplyShortChannelIdsEnd } ;
29
29
use ln:: msgs;
30
30
use util:: ser:: { Writeable , Readable , Writer } ;
@@ -251,12 +251,18 @@ impl<C: Deref , L: Deref > RoutingMessageHandler for NetGraphMsgHandler<C, L> wh
251
251
/// when the final reply_scids_end message is received, though we are not
252
252
/// tracking this directly.
253
253
fn sync_routing_table ( & self , their_node_id : & PublicKey , init_msg : & Init ) {
254
-
255
254
// We will only perform a sync with peers that support gossip_queries.
256
255
if !init_msg. features . supports_gossip_queries ( ) {
257
256
return ( ) ;
258
257
}
259
258
259
+ // We will only perform a sync with peers that support our encodings (if they specify their
260
+ // encodings)
261
+ if !init_msg. gossip_compression_encodings . is_empty ( ) &&
262
+ !init_msg. gossip_compression_encodings . iter ( ) . any ( |e| SUPPORTED_GOSSIP_ENCODINGS . contains ( e) ) {
263
+ return ( ) ;
264
+ }
265
+
260
266
// Check if we need to perform a full synchronization with this peer
261
267
if !self . should_request_full_sync ( their_node_id) {
262
268
return ( ) ;
@@ -1067,7 +1073,8 @@ mod tests {
1067
1073
use routing:: network_graph:: { NetGraphMsgHandler , NetworkGraph , MAX_EXCESS_BYTES_FOR_RELAY } ;
1068
1074
use ln:: msgs:: { Init , OptionalField , RoutingMessageHandler , UnsignedNodeAnnouncement , NodeAnnouncement ,
1069
1075
UnsignedChannelAnnouncement , ChannelAnnouncement , UnsignedChannelUpdate , ChannelUpdate , HTLCFailChannelUpdate ,
1070
- ReplyChannelRange , ReplyShortChannelIdsEnd , QueryChannelRange , QueryShortChannelIds , MAX_VALUE_MSAT } ;
1076
+ ReplyChannelRange , ReplyShortChannelIdsEnd , QueryChannelRange , QueryShortChannelIds , MAX_VALUE_MSAT ,
1077
+ SUPPORTED_GOSSIP_ENCODINGS , GossipEncodingType } ;
1071
1078
use util:: test_utils;
1072
1079
use util:: logger:: Logger ;
1073
1080
use util:: ser:: { Readable , Writeable } ;
@@ -2011,13 +2018,39 @@ mod tests {
2011
2018
2012
2019
// It should ignore if gossip_queries feature is not enabled
2013
2020
{
2014
- let init_msg = Init { features : InitFeatures :: known ( ) . clear_gossip_queries ( ) , gossip_compression_encodings : Vec :: new ( ) } ;
2021
+ let init_msg = Init { features : InitFeatures :: known ( ) . clear_gossip_queries ( ) , gossip_compression_encodings : SUPPORTED_GOSSIP_ENCODINGS . iter ( ) . map ( |e| * e) . collect ( ) } ;
2022
+ net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
2023
+ let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2024
+ assert_eq ! ( events. len( ) , 0 ) ;
2025
+ }
2026
+
2027
+ // It should ignore if available encodings do not match ours
2028
+ {
2029
+ let init_msg = Init { features : InitFeatures :: known ( ) . clear_gossip_queries ( ) , gossip_compression_encodings : vec ! [ GossipEncodingType :: Zlib ] } ;
2015
2030
net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
2016
2031
let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2017
2032
assert_eq ! ( events. len( ) , 0 ) ;
2018
2033
}
2019
2034
2020
2035
// It should send a query_channel_message with the correct information
2036
+ {
2037
+ let init_msg = Init { features : InitFeatures :: known ( ) , gossip_compression_encodings : SUPPORTED_GOSSIP_ENCODINGS . iter ( ) . map ( |e| * e) . collect ( ) } ;
2038
+ net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
2039
+ let events = net_graph_msg_handler. get_and_clear_pending_msg_events ( ) ;
2040
+ assert_eq ! ( events. len( ) , 1 ) ;
2041
+ match & events[ 0 ] {
2042
+ MessageSendEvent :: SendChannelRangeQuery { node_id, msg } => {
2043
+ assert_eq ! ( node_id, & node_id_1) ;
2044
+ assert_eq ! ( msg. chain_hash, chain_hash) ;
2045
+ assert_eq ! ( msg. first_blocknum, first_blocknum) ;
2046
+ assert_eq ! ( msg. number_of_blocks, number_of_blocks) ;
2047
+ } ,
2048
+ _ => panic ! ( "Expected MessageSendEvent::SendChannelRangeQuery" )
2049
+ } ;
2050
+ }
2051
+
2052
+ // It should send a query_channel_message with the correct information if the peer was old
2053
+ // and didn't send its supported encodings
2021
2054
{
2022
2055
let init_msg = Init { features : InitFeatures :: known ( ) , gossip_compression_encodings : Vec :: new ( ) } ;
2023
2056
net_graph_msg_handler. sync_routing_table ( & node_id_1, & init_msg) ;
@@ -2039,7 +2072,7 @@ mod tests {
2039
2072
// which should_request_full_sync will return false
2040
2073
{
2041
2074
let ( secp_ctx, net_graph_msg_handler) = create_net_graph_msg_handler ( ) ;
2042
- let init_msg = Init { features : InitFeatures :: known ( ) , gossip_compression_encodings : Vec :: new ( ) } ;
2075
+ let init_msg = Init { features : InitFeatures :: known ( ) , gossip_compression_encodings : SUPPORTED_GOSSIP_ENCODINGS . iter ( ) . map ( |e| * e ) . collect ( ) } ;
2043
2076
for n in 1 ..7 {
2044
2077
let node_privkey = & SecretKey :: from_slice ( & [ n; 32 ] ) . unwrap ( ) ;
2045
2078
let node_id = PublicKey :: from_secret_key ( & secp_ctx, node_privkey) ;
0 commit comments