mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
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
e742894492
, 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.
This commit is contained in:
parent
950ccc4340
commit
06cb48afd4
5 changed files with 29 additions and 3 deletions
|
@ -582,6 +582,7 @@ mod tests {
|
|||
fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
|
||||
fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
|
||||
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
|
||||
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() }
|
||||
}
|
||||
impl ChannelMessageHandler for MsgHandler {
|
||||
fn handle_open_channel(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, _msg: &OpenChannel) {}
|
||||
|
|
|
@ -956,6 +956,14 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider {
|
|||
/// Handles when a peer asks us to send routing gossip messages for a
|
||||
/// list of short_channel_ids.
|
||||
fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>;
|
||||
|
||||
// Handler information:
|
||||
/// Gets the init feature flags which should be sent to the given peer. All available handlers
|
||||
/// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
|
||||
/// which are sent in our [`Init`] message.
|
||||
///
|
||||
/// Note that this method is called before [`Self::peer_connected`].
|
||||
fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures;
|
||||
}
|
||||
|
||||
/// A trait to describe an object that can receive onion messages.
|
||||
|
|
|
@ -77,6 +77,9 @@ impl RoutingMessageHandler for IgnoringMessageHandler {
|
|||
fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
|
||||
fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
|
||||
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
|
||||
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
|
||||
InitFeatures::empty()
|
||||
}
|
||||
}
|
||||
impl OnionMessageProvider for IgnoringMessageHandler {
|
||||
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
|
|||
|
||||
peer.their_node_id = Some(their_node_id);
|
||||
insert_node_id!();
|
||||
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
|
||||
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
|
||||
.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
|
||||
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
|
||||
self.enqueue_message(peer, &resp);
|
||||
peer.awaiting_pong_timer_tick_intervals = 0;
|
||||
|
@ -1065,7 +1069,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
|
|||
peer.pending_read_is_header = true;
|
||||
peer.their_node_id = Some(their_node_id);
|
||||
insert_node_id!();
|
||||
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id);
|
||||
let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
|
||||
.or(self.message_handler.route_handler.provided_init_features(&their_node_id));
|
||||
let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
|
||||
self.enqueue_message(peer, &resp);
|
||||
peer.awaiting_pong_timer_tick_intervals = 0;
|
||||
|
|
|
@ -22,7 +22,7 @@ use bitcoin::hash_types::BlockHash;
|
|||
use chain;
|
||||
use chain::Access;
|
||||
use ln::chan_utils::make_funding_redeemscript;
|
||||
use ln::features::{ChannelFeatures, NodeFeatures};
|
||||
use ln::features::{ChannelFeatures, NodeFeatures, InitFeatures};
|
||||
use ln::msgs::{DecodeError, ErrorAction, Init, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
|
||||
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, GossipTimestampFilter};
|
||||
use ln::msgs::{QueryChannelRange, ReplyChannelRange, QueryShortChannelIds, ReplyShortChannelIdsEnd};
|
||||
|
@ -570,6 +570,12 @@ where C::Target: chain::Access, L::Target: Logger
|
|||
action: ErrorAction::IgnoreError,
|
||||
})
|
||||
}
|
||||
|
||||
fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
|
||||
let mut features = InitFeatures::empty();
|
||||
features.set_gossip_queries_optional();
|
||||
features
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: Deref<Target=NetworkGraph<L>>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L>
|
||||
|
|
|
@ -510,6 +510,12 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
|
|||
fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), msgs::LightningError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
|
||||
let mut features = InitFeatures::empty();
|
||||
features.set_gossip_queries_optional();
|
||||
features
|
||||
}
|
||||
}
|
||||
|
||||
impl events::MessageSendEventsProvider for TestRoutingMessageHandler {
|
||||
|
|
Loading…
Add table
Reference in a new issue