From: bmancini55 Date: Thu, 22 Oct 2020 12:47:24 +0000 (-0400) Subject: Add send message events for gossip_queries X-Git-Tag: v0.0.13~50^2~9 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=34271fb75037372ff6063594d7a537c07670c863;p=rust-lightning Add send message events for gossip_queries This change enables initiating gossip queries with a peer using the SendMessageEvent enum. Specifically we add an event for sending query_channel_range to discover the existance of channels and an event for sending query_short_channel_ids to request routing gossip messages for a set of channels. These events are handled inside the process_events method of PeerManager which sends the serialized message to the peer. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 0f5e7f8ad..c39eef3ea 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3404,6 +3404,8 @@ impl true, &events::MessageSendEvent::HandleError { ref node_id, .. } => node_id != counterparty_node_id, &events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => true, + &events::MessageSendEvent::SendChannelRangeQuery { .. } => false, + &events::MessageSendEvent::SendShortIdsQuery { .. } => false, } }); } diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 195856161..b318e5031 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -1131,6 +1131,16 @@ impl PeerManager { + let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {}); + peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); + self.do_attempt_write_data(&mut descriptor, peer); + }, + MessageSendEvent::SendShortIdsQuery { ref node_id, ref msg } => { + let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {}); + peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg))); + self.do_attempt_write_data(&mut descriptor, peer); } } } diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 3eeacdc73..6f6f32dae 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -346,7 +346,22 @@ pub enum MessageSendEvent { PaymentFailureNetworkUpdate { /// The channel/node update which should be sent to NetGraphMsgHandler update: msgs::HTLCFailChannelUpdate, - } + }, + /// Query a peer for channels with funding transaction UTXOs in a block range. + SendChannelRangeQuery { + /// The node_id of this message recipient + node_id: PublicKey, + /// The query_channel_range which should be sent. + msg: msgs::QueryChannelRange, + }, + /// Request routing gossip messages from a peer for a list of channels identified by + /// their short_channel_ids. + SendShortIdsQuery { + /// The node_id of this message recipient + node_id: PublicKey, + /// The query_short_channel_ids which should be sent. + msg: msgs::QueryShortChannelIds, + }, } /// A trait indicating an object may generate message send events