Struct breez_sdk_core::lightning::routing::gossip::NetworkGraph
pub struct NetworkGraph<L>{ /* private fields */ }
Expand description
Represents the network as nodes and channels between them
Implementations§
§impl<L> NetworkGraph<L>
impl<L> NetworkGraph<L>
pub fn handle_network_update(&self, network_update: &NetworkUpdate)
pub fn handle_network_update(&self, network_update: &NetworkUpdate)
Handles any network updates originating from Event
s.
Note that this will skip applying any NetworkUpdate::ChannelUpdateMessage
to avoid
leaking possibly identifying information of the sender to the public network.
pub fn get_chain_hash(&self) -> ChainHash
pub fn get_chain_hash(&self) -> ChainHash
Gets the chain hash for this network graph.
§impl<L> NetworkGraph<L>
impl<L> NetworkGraph<L>
pub fn new(network: Network, logger: L) -> NetworkGraph<L>
pub fn new(network: Network, logger: L) -> NetworkGraph<L>
Creates a new, empty, network graph.
pub fn read_only(&self) -> ReadOnlyNetworkGraph<'_>
pub fn read_only(&self) -> ReadOnlyNetworkGraph<'_>
Returns a read-only view of the network graph.
pub fn get_last_rapid_gossip_sync_timestamp(&self) -> Option<u32>
pub fn get_last_rapid_gossip_sync_timestamp(&self) -> Option<u32>
The unix timestamp provided by the most recent rapid gossip sync. It will be set by the rapid sync process after every sync completion.
pub fn set_last_rapid_gossip_sync_timestamp(
&self,
last_rapid_gossip_sync_timestamp: u32,
)
pub fn set_last_rapid_gossip_sync_timestamp( &self, last_rapid_gossip_sync_timestamp: u32, )
Update the unix timestamp provided by the most recent rapid gossip sync. This should be done automatically by the rapid sync process after every sync completion.
pub fn update_node_from_announcement(
&self,
msg: &NodeAnnouncement,
) -> Result<(), LightningError>
pub fn update_node_from_announcement( &self, msg: &NodeAnnouncement, ) -> Result<(), LightningError>
For an already known node (from channel announcements), update its stored properties from a given node announcement.
You probably don’t want to call this directly, instead relying on a P2PGossipSync’s RoutingMessageHandler implementation to call it indirectly. This may be useful to accept routing messages from a source using a protocol other than the lightning P2P protocol.
pub fn update_node_from_unsigned_announcement(
&self,
msg: &UnsignedNodeAnnouncement,
) -> Result<(), LightningError>
pub fn update_node_from_unsigned_announcement( &self, msg: &UnsignedNodeAnnouncement, ) -> Result<(), LightningError>
For an already known node (from channel announcements), update its stored properties from a given node announcement without verifying the associated signatures. Because we aren’t given the associated signatures here we cannot relay the node announcement to any of our peers.
pub fn update_channel_from_announcement<U>(
&self,
msg: &ChannelAnnouncement,
utxo_lookup: &Option<U>,
) -> Result<(), LightningError>
pub fn update_channel_from_announcement<U>( &self, msg: &ChannelAnnouncement, utxo_lookup: &Option<U>, ) -> Result<(), LightningError>
Store or update channel info from a channel announcement.
You probably don’t want to call this directly, instead relying on a P2PGossipSync
’s
RoutingMessageHandler
implementation to call it indirectly. This may be useful to accept
routing messages from a source using a protocol other than the lightning P2P protocol.
If a UtxoLookup
object is provided via utxo_lookup
, it will be called to verify
the corresponding UTXO exists on chain and is correctly-formatted.
pub fn update_channel_from_announcement_no_lookup(
&self,
msg: &ChannelAnnouncement,
) -> Result<(), LightningError>
pub fn update_channel_from_announcement_no_lookup( &self, msg: &ChannelAnnouncement, ) -> Result<(), LightningError>
Store or update channel info from a channel announcement.
You probably don’t want to call this directly, instead relying on a P2PGossipSync
’s
RoutingMessageHandler
implementation to call it indirectly. This may be useful to accept
routing messages from a source using a protocol other than the lightning P2P protocol.
This will skip verification of if the channel is actually on-chain.
pub fn update_channel_from_unsigned_announcement<U>(
&self,
msg: &UnsignedChannelAnnouncement,
utxo_lookup: &Option<U>,
) -> Result<(), LightningError>
pub fn update_channel_from_unsigned_announcement<U>( &self, msg: &UnsignedChannelAnnouncement, utxo_lookup: &Option<U>, ) -> Result<(), LightningError>
Store or update channel info from a channel announcement without verifying the associated signatures. Because we aren’t given the associated signatures here we cannot relay the channel announcement to any of our peers.
If a UtxoLookup
object is provided via utxo_lookup
, it will be called to verify
the corresponding UTXO exists on chain and is correctly-formatted.
pub fn add_channel_from_partial_announcement(
&self,
short_channel_id: u64,
timestamp: u64,
features: Features<ChannelContext>,
node_id_1: PublicKey,
node_id_2: PublicKey,
) -> Result<(), LightningError>
pub fn add_channel_from_partial_announcement( &self, short_channel_id: u64, timestamp: u64, features: Features<ChannelContext>, node_id_1: PublicKey, node_id_2: PublicKey, ) -> Result<(), LightningError>
Update channel from partial announcement data received via rapid gossip sync
timestamp: u64
: Timestamp emulating the backdated original announcement receipt (by the
rapid gossip sync server)
All other parameters as used in msgs::UnsignedChannelAnnouncement
fields.
pub fn channel_failed_permanent(&self, short_channel_id: u64)
pub fn channel_failed_permanent(&self, short_channel_id: u64)
Marks a channel in the graph as failed permanently.
The channel and any node for which this was their last channel are removed from the graph.
pub fn node_failed_permanent(&self, node_id: &PublicKey)
pub fn node_failed_permanent(&self, node_id: &PublicKey)
Marks a node in the graph as permanently failed, effectively removing it and its channels from local storage.
pub fn remove_stale_channels_and_tracking(&self)
pub fn remove_stale_channels_and_tracking(&self)
Removes information about channels that we haven’t heard any updates about in some time. This can be used regularly to prune the network graph of channels that likely no longer exist.
While there is no formal requirement that nodes regularly re-broadcast their channel updates every two weeks, the non-normative section of BOLT 7 currently suggests that pruning occur for updates which are at least two weeks old, which we implement here.
Note that for users of the lightning-background-processor
crate this method may be
automatically called regularly for you.
This method will also cause us to stop tracking removed nodes and channels if they have been in the map for a while so that these can be resynced from gossip in the future.
This method is only available with the std
feature. See
NetworkGraph::remove_stale_channels_and_tracking_with_time
for no-std
use.
pub fn remove_stale_channels_and_tracking_with_time(
&self,
current_time_unix: u64,
)
pub fn remove_stale_channels_and_tracking_with_time( &self, current_time_unix: u64, )
Removes information about channels that we haven’t heard any updates about in some time. This can be used regularly to prune the network graph of channels that likely no longer exist.
While there is no formal requirement that nodes regularly re-broadcast their channel updates every two weeks, the non-normative section of BOLT 7 currently suggests that pruning occur for updates which are at least two weeks old, which we implement here.
This method will also cause us to stop tracking removed nodes and channels if they have been in the map for a while so that these can be resynced from gossip in the future.
This function takes the current unix time as an argument. For users with the std
feature
enabled, NetworkGraph::remove_stale_channels_and_tracking
may be preferable.
pub fn update_channel(&self, msg: &ChannelUpdate) -> Result<(), LightningError>
pub fn update_channel(&self, msg: &ChannelUpdate) -> Result<(), LightningError>
For an already known (from announcement) channel, update info about one of the directions of the channel.
You probably don’t want to call this directly, instead relying on a P2PGossipSync
’s
RoutingMessageHandler
implementation to call it indirectly. This may be useful to accept
routing messages from a source using a protocol other than the lightning P2P protocol.
If built with no-std
, any updates with a timestamp more than two weeks in the past or
materially in the future will be rejected.
pub fn update_channel_unsigned(
&self,
msg: &UnsignedChannelUpdate,
) -> Result<(), LightningError>
pub fn update_channel_unsigned( &self, msg: &UnsignedChannelUpdate, ) -> Result<(), LightningError>
For an already known (from announcement) channel, update info about one of the directions of the channel without verifying the associated signatures. Because we aren’t given the associated signatures here we cannot relay the channel update to any of our peers.
If built with no-std
, any updates with a timestamp more than two weeks in the past or
materially in the future will be rejected.
pub fn verify_channel_update(
&self,
msg: &ChannelUpdate,
) -> Result<(), LightningError>
pub fn verify_channel_update( &self, msg: &ChannelUpdate, ) -> Result<(), LightningError>
For an already known (from announcement) channel, verify the given ChannelUpdate
.
This checks whether the update currently is applicable by Self::update_channel
.
If built with no-std
, any updates with a timestamp more than two weeks in the past or
materially in the future will be rejected.
Trait Implementations§
§impl<L> Display for NetworkGraph<L>
impl<L> Display for NetworkGraph<L>
§impl<L> PartialEq for NetworkGraph<L>
impl<L> PartialEq for NetworkGraph<L>
§impl<L> ReadableArgs<L> for NetworkGraph<L>
impl<L> ReadableArgs<L> for NetworkGraph<L>
§fn read<R>(reader: &mut R, logger: L) -> Result<NetworkGraph<L>, DecodeError>where
R: Read,
fn read<R>(reader: &mut R, logger: L) -> Result<NetworkGraph<L>, DecodeError>where
R: Read,
Self
in from the given Read
.§impl<L> Writeable for NetworkGraph<L>
impl<L> Writeable for NetworkGraph<L>
impl<L> Eq for NetworkGraph<L>
Auto Trait Implementations§
impl<L> !Freeze for NetworkGraph<L>
impl<L> RefUnwindSafe for NetworkGraph<L>where
L: RefUnwindSafe,
impl<L> Send for NetworkGraph<L>where
L: Send,
impl<L> Sync for NetworkGraph<L>where
L: Sync,
impl<L> Unpin for NetworkGraph<L>where
L: Unpin,
impl<L> UnwindSafe for NetworkGraph<L>where
L: UnwindSafe,
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request