Skip to content

Commit 06cb48a

Browse files
committed
OR InitFeatures from both Channel and Routing message handlers
When we go to send an Init message to new peers, the features we support are really a combination of all the various features our different handlers support. This commit captures this concept by OR'ing our InitFeatures across both our Channel and Routing handlers. Note that this also disables setting the `initial_routing_sync` flag in init messages, as was intended in e742894, per the comment added on `clear_initial_routing_sync`, though this should not be a behavior change in practice as nodes which support gossip queries ignore the initial routing sync flag.
1 parent 950ccc4 commit 06cb48a

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ mod tests {
582582
fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
583583
fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
584584
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
585+
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() }
585586
}
586587
impl ChannelMessageHandler for MsgHandler {
587588
fn handle_open_channel(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, _msg: &OpenChannel) {}

lightning/src/ln/msgs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,14 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider {
956956
/// Handles when a peer asks us to send routing gossip messages for a
957957
/// list of short_channel_ids.
958958
fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>;
959+
960+
// Handler information:
961+
/// Gets the init feature flags which should be sent to the given peer. All available handlers
962+
/// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
963+
/// which are sent in our [`Init`] message.
964+
///
965+
/// Note that this method is called before [`Self::peer_connected`].
966+
fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures;
959967
}
960968

961969
/// A trait to describe an object that can receive onion messages.

lightning/src/ln/peer_handler.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ impl RoutingMessageHandler for IgnoringMessageHandler {
7777
fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
7878
fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
7979
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
80+
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
81+
InitFeatures::empty()
82+
}
8083
}
8184
impl OnionMessageProvider for IgnoringMessageHandler {
8285
fn next_onion_message_for_peer(&self, _peer_node_id: PublicKey) -> Option<msgs::OnionMessage> { None }
@@ -1053,7 +1056,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10531056

10541057
peer.their_node_id = Some(their_node_id);
10551058
insert_node_id!();
1056-
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1059+
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
1060+
.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
10571061
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
10581062
self.enqueue_message(peer, &resp);
10591063
peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1065,7 +1069,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10651069
peer.pending_read_is_header = true;
10661070
peer.their_node_id = Some(their_node_id);
10671071
insert_node_id!();
1068-
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1072+
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
1073+
.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
10691074
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
10701075
self.enqueue_message(peer, &resp);
10711076
peer.awaiting_pong_timer_tick_intervals = 0;

lightning/src/routing/gossip.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use bitcoin::hash_types::BlockHash;
2222
use chain;
2323
use chain::Access;
2424
use ln::chan_utils::make_funding_redeemscript;
25-
use ln::features::{ChannelFeatures, NodeFeatures};
25+
use ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
2626
use ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
2727
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
2828
use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
@@ -570,6 +570,12 @@ where C::Target: chain::Access, L::Target: Logger
570570
action: ErrorAction::IgnoreError,
571571
})
572572
}
573+
574+
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
575+
let mut features = InitFeatures::empty();
576+
features.set_gossip_queries_optional();
577+
features
578+
}
573579
}
574580

575581
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L>

lightning/src/util/test_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,12 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
510510
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), msgs::LightningError> {
511511
Ok(())
512512
}
513+
514+
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
515+
let mut features = InitFeatures::empty();
516+
features.set_gossip_queries_optional();
517+
features
518+
}
513519
}
514520

515521
impl events::MessageSendEventsProvider for TestRoutingMessageHandler {

0 commit comments

Comments
 (0)