Skip to content

Commit 7a4a29f

Browse files
committed
Pass Init message to sync_routing_table method
This commit modifies sync_routing_table in RoutingMessageHandler to accept a reference to the Init message received by the peer. This allows the method to use the Peer's features to drive the operations of the gossip_queries routing table sync.
1 parent 7e1e0ac commit 7a4a29f

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ mod tests {
536536
fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)> { Vec::new() }
537537
fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<NodeAnnouncement> { Vec::new() }
538538
fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { false }
539-
fn sync_routing_table(&self, _their_node_id: &PublicKey) { }
539+
fn sync_routing_table(&self, _their_node_id: &PublicKey, _init_msg: &Init) { }
540540
fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: ReplyChannelRange) -> Result<(), LightningError> { Ok(()) }
541541
fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
542542
fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: QueryChannelRange) -> Result<(), LightningError> { Ok(()) }

lightning/src/ln/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ pub trait RoutingMessageHandler : Send + Sync + events::MessageSendEventsProvide
830830
/// Initiates routing gossip sync by querying a peer to discover channels
831831
/// and their associated routing gossip messages. This method will use a
832832
/// sync strategy defined by the implementor.
833-
fn sync_routing_table(&self, their_node_id: &PublicKey);
833+
fn sync_routing_table(&self, their_node_id: &PublicKey, init: &Init);
834834
/// Handles the reply of a query we initiated to learn about channels
835835
/// for a given range of blocks. We can expect to receive one or more
836836
/// replies to a single query.

lightning/src/routing/network_graph.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bitcoin::hash_types::BlockHash;
2323
use chain;
2424
use chain::Access;
2525
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};
2727
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, OptionalField};
2828
use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
2929
use ln::msgs;
@@ -226,7 +226,10 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
226226
/// gossip messages for each channel. The sync is considered complete when
227227
/// the final reply_scids_end message is received, though we are not
228228
/// 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+
}
230233
let first_blocknum = 0;
231234
let number_of_blocks = 0xffffffff;
232235
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 {
996999
#[cfg(test)]
9971000
mod tests {
9981001
use chain;
999-
use ln::features::{ChannelFeatures, NodeFeatures};
1002+
use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
10001003
use routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
1001-
use ln::msgs::{OptionalField, RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement,
1004+
use ln::msgs::{Init, OptionalField, RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement,
10021005
UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate, HTLCFailChannelUpdate,
10031006
ReplyChannelRange, ReplyShortChannelIdsEnd, QueryChannelRange, QueryShortChannelIds, MAX_VALUE_MSAT};
10041007
use util::test_utils;
@@ -1939,20 +1942,31 @@ mod tests {
19391942
let chain_hash = genesis_block(Network::Testnet).header.block_hash();
19401943
let first_blocknum = 0;
19411944
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+
}
19431953

19441954
// 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+
}
19561970
}
19571971

19581972
#[test]

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
320320
self.request_full_sync.load(Ordering::Acquire)
321321
}
322322

323-
fn sync_routing_table(&self, _their_node_id: &PublicKey) {}
323+
fn sync_routing_table(&self, _their_node_id: &PublicKey, _init_msg: &msgs::Init) {}
324324

325325
fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), msgs::LightningError> {
326326
Ok(())

0 commit comments

Comments
 (0)