Skip to content

Commit 4a76d4b

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.
1 parent 110c861 commit 4a76d4b

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-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 [`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::known()
82+
}
8083
}
8184
impl OnionMessageProvider for IgnoringMessageHandler {
8285
fn next_onion_message_for_peer(&self, _peer_node_id: PublicKey) -> Option<msgs::OnionMessage> { None }
@@ -1050,7 +1053,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10501053

10511054
peer.their_node_id = Some(their_node_id);
10521055
insert_node_id!();
1053-
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1056+
let mut features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1057+
features = features.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
10541058
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
10551059
self.enqueue_message(peer, &resp);
10561060
peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1062,7 +1066,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10621066
peer.pending_read_is_header = true;
10631067
peer.their_node_id = Some(their_node_id);
10641068
insert_node_id!();
1065-
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1069+
let mut features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
1070+
features = features.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
10661071
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
10671072
self.enqueue_message(peer, &resp);
10681073
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ 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+
InitFeatures::empty()
516+
}
513517
}
514518

515519
impl events::MessageSendEventsProvider for TestRoutingMessageHandler {

0 commit comments

Comments
 (0)