pub struct P2PGossipSync<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> where
C::Target: Access,
L::Target: Logger, { /* private fields */ }
Expand description
Receives and validates network updates from peers, stores authentic and relevant data as a network graph. This network graph is then used for routing payments. Provides interface to help with initial routing sync by serving historical announcements.
Serves as an EventHandler
for applying updates from Event::PaymentPathFailed
to the
NetworkGraph
.
Implementations
sourceimpl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
impl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
sourcepub fn new(network_graph: G, chain_access: Option<C>, logger: L) -> Self
pub fn new(network_graph: G, chain_access: Option<C>, logger: L) -> Self
Creates a new tracker of the actual state of the network of channels and nodes, assuming an existing Network Graph. Chain monitor is used to make sure announced channels exist on-chain, channel data is correct, and that the announcement is signed with channel owners’ keys.
sourcepub fn add_chain_access(&mut self, chain_access: Option<C>)
pub fn add_chain_access(&mut self, chain_access: Option<C>)
Adds a provider used to check new announcements. Does not affect existing announcements unless they are updated. Add, update or remove the provider would replace the current one.
sourcepub fn network_graph(&self) -> &G
pub fn network_graph(&self) -> &G
Gets a reference to the underlying NetworkGraph
which was provided in
P2PGossipSync::new
.
(C-not exported) as bindings don’t support a reference-to-a-reference yet
Trait Implementations
sourceimpl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
impl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
sourceimpl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
impl<G: Deref<Target = NetworkGraph<L>>, C: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync<G, C, L> where
C::Target: Access,
L::Target: Logger,
sourcefn peer_connected(&self, their_node_id: &PublicKey, init_msg: &Init)
fn peer_connected(&self, their_node_id: &PublicKey, init_msg: &Init)
Initiates a stateless sync of routing gossip information with a peer using gossip_queries. The default strategy used by this implementation is to sync the full block range with several peers.
We should expect one or more reply_channel_range messages in response to our query_channel_range. Each reply will enqueue a query_scid message to request gossip messages for each channel. The sync is considered complete when the final reply_scids_end message is received, though we are not tracking this directly.
sourcefn handle_query_channel_range(
&self,
their_node_id: &PublicKey,
msg: QueryChannelRange
) -> Result<(), LightningError>
fn handle_query_channel_range(
&self,
their_node_id: &PublicKey,
msg: QueryChannelRange
) -> Result<(), LightningError>
Processes a query from a peer by finding announced/public channels whose funding UTXOs are in the specified block range. Due to message size limits, large range queries may result in several reply messages. This implementation enqueues all reply messages into pending events. Each message will allocate just under 65KiB. A full sync of the public routing table with 128k channels will generated 16 messages and allocate ~1MB. Logic can be changed to reduce allocation if/when a full sync of the routing table impacts memory constrained systems.
sourcefn handle_node_announcement(
&self,
msg: &NodeAnnouncement
) -> Result<bool, LightningError>
fn handle_node_announcement(
&self,
msg: &NodeAnnouncement
) -> Result<bool, LightningError>
Handle an incoming node_announcement message, returning true if it should be forwarded on, false or returning an Err otherwise. Read more
sourcefn handle_channel_announcement(
&self,
msg: &ChannelAnnouncement
) -> Result<bool, LightningError>
fn handle_channel_announcement(
&self,
msg: &ChannelAnnouncement
) -> Result<bool, LightningError>
Handle a channel_announcement message, returning true if it should be forwarded on, false or returning an Err otherwise. Read more
sourcefn handle_channel_update(
&self,
msg: &ChannelUpdate
) -> Result<bool, LightningError>
fn handle_channel_update(
&self,
msg: &ChannelUpdate
) -> Result<bool, LightningError>
Handle an incoming channel_update message, returning true if it should be forwarded on, false or returning an Err otherwise. Read more
sourcefn get_next_channel_announcements(
&self,
starting_point: u64,
batch_amount: u8
) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn get_next_channel_announcements(
&self,
starting_point: u64,
batch_amount: u8
) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Gets a subset of the channel announcements and updates required to dump our routing table to a remote node, starting at the short_channel_id indicated by starting_point and including the batch_amount entries immediately higher in numerical value than starting_point. Read more
sourcefn get_next_node_announcements(
&self,
starting_point: Option<&PublicKey>,
batch_amount: u8
) -> Vec<NodeAnnouncement>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn get_next_node_announcements(
&self,
starting_point: Option<&PublicKey>,
batch_amount: u8
) -> Vec<NodeAnnouncement>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Gets a subset of the node announcements required to dump our routing table to a remote node,
starting at the node after the provided publickey and including batch_amount entries
immediately higher (as defined by
sourcefn handle_reply_channel_range(
&self,
_their_node_id: &PublicKey,
_msg: ReplyChannelRange
) -> Result<(), LightningError>
fn handle_reply_channel_range(
&self,
_their_node_id: &PublicKey,
_msg: ReplyChannelRange
) -> Result<(), LightningError>
Handles the reply of a query we initiated to learn about channels for a given range of blocks. We can expect to receive one or more replies to a single query. Read more
sourcefn handle_reply_short_channel_ids_end(
&self,
_their_node_id: &PublicKey,
_msg: ReplyShortChannelIdsEnd
) -> Result<(), LightningError>
fn handle_reply_short_channel_ids_end(
&self,
_their_node_id: &PublicKey,
_msg: ReplyShortChannelIdsEnd
) -> Result<(), LightningError>
Handles the reply of a query we initiated asking for routing gossip messages for a list of channels. We should receive this message when a node has completed its best effort to send us the pertaining routing gossip messages. Read more
sourcefn handle_query_short_channel_ids(
&self,
_their_node_id: &PublicKey,
_msg: QueryShortChannelIds
) -> Result<(), LightningError>
fn handle_query_short_channel_ids(
&self,
_their_node_id: &PublicKey,
_msg: QueryShortChannelIds
) -> Result<(), LightningError>
Handles when a peer asks us to send routing gossip messages for a list of short_channel_ids. Read more
Auto Trait Implementations
impl<G, C, L> RefUnwindSafe for P2PGossipSync<G, C, L> where
C: RefUnwindSafe,
G: RefUnwindSafe,
L: RefUnwindSafe,
impl<G, C, L> Send for P2PGossipSync<G, C, L> where
C: Send,
G: Send,
L: Send,
impl<G, C, L> Sync for P2PGossipSync<G, C, L> where
C: Sync,
G: Sync,
L: Sync,
impl<G, C, L> Unpin for P2PGossipSync<G, C, L> where
C: Unpin,
G: Unpin,
L: Unpin,
impl<G, C, L> UnwindSafe for P2PGossipSync<G, C, L> where
C: UnwindSafe,
G: UnwindSafe,
L: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more