pub struct NetworkGraph<L: Deref>where
    L::Target: Logger,{ /* private fields */ }
Expand description

Represents the network as nodes and channels between them

Implementations§

source§

impl<L: Deref> NetworkGraph<L>where L::Target: Logger,

source

pub fn handle_network_update(&self, network_update: &NetworkUpdate)

Handles any network updates originating from Events.

source§

impl<L: Deref> NetworkGraph<L>where L::Target: Logger,

source

pub fn new(network: Network, logger: L) -> NetworkGraph<L>

Creates a new, empty, network graph.

source

pub fn read_only(&self) -> ReadOnlyNetworkGraph<'_>

Returns a read-only view of the network graph.

source

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.

source

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.

source

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.

source

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.

source

pub fn update_channel_from_announcement<U: Deref>( &self, msg: &ChannelAnnouncement, utxo_lookup: &Option<U> ) -> Result<(), LightningError>where U::Target: UtxoLookup,

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.

source

pub fn update_channel_from_unsigned_announcement<U: Deref>( &self, msg: &UnsignedChannelAnnouncement, utxo_lookup: &Option<U> ) -> Result<(), LightningError>where U::Target: UtxoLookup,

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.

source

pub fn add_channel_from_partial_announcement( &self, short_channel_id: u64, timestamp: u64, features: ChannelFeatures, 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.

source

pub fn channel_failed(&self, short_channel_id: u64, is_permanent: bool)

Marks a channel in the graph as failed if a corresponding HTLC fail was sent. If permanent, removes a channel from the local storage. May cause the removal of nodes too, if this was their last channel. If not permanent, makes channels unavailable for routing.

source

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.

source

pub fn remove_stale_channels_and_tracking(&self)

Available on crate feature std only.

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl<L: Deref> Display for NetworkGraph<L>where L::Target: Logger,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<L: Deref> PartialEq<NetworkGraph<L>> for NetworkGraph<L>where L::Target: Logger,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<L: Deref> ReadableArgs<L> for NetworkGraph<L>where L::Target: Logger,

source§

fn read<R: Read>( reader: &mut R, logger: L ) -> Result<NetworkGraph<L>, DecodeError>

Reads a Self in from the given Read.
source§

impl<L: Deref> Writeable for NetworkGraph<L>where L::Target: Logger,

source§

fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>

Writes self out to the given Writer.
source§

fn encode(&self) -> Vec<u8>

Writes self out to a Vec<u8>.
source§

fn serialized_length(&self) -> usize

Gets the length of this object after it has been serialized. This can be overridden to optimize cases where we prepend an object with its length.
source§

impl<L: Deref> Eq for NetworkGraph<L>where L::Target: Logger,

Auto Trait Implementations§

§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.