Struct lightning::routing::network_graph::NetworkGraph
source · [−]pub struct NetworkGraph { /* private fields */ }
Expand description
Represents the network as nodes and channels between them
Implementations
sourceimpl NetworkGraph
impl NetworkGraph
sourcepub fn new(genesis_hash: BlockHash) -> NetworkGraph
pub fn new(genesis_hash: BlockHash) -> NetworkGraph
Creates a new, empty, network graph.
sourcepub fn read_only(&self) -> ReadOnlyNetworkGraph<'_>
pub fn read_only(&self) -> ReadOnlyNetworkGraph<'_>
Returns a read-only view of the network graph.
sourcepub fn update_node_from_announcement<T: Verification>(
&self,
msg: &NodeAnnouncement,
secp_ctx: &Secp256k1<T>
) -> Result<(), LightningError>
pub fn update_node_from_announcement<T: Verification>(
&self,
msg: &NodeAnnouncement,
secp_ctx: &Secp256k1<T>
) -> 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 NetGraphMsgHandler’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.
sourcepub 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.
sourcepub fn update_channel_from_announcement<T: Verification, C: Deref>(
&self,
msg: &ChannelAnnouncement,
chain_access: &Option<C>,
secp_ctx: &Secp256k1<T>
) -> Result<(), LightningError> where
C::Target: Access,
pub fn update_channel_from_announcement<T: Verification, C: Deref>(
&self,
msg: &ChannelAnnouncement,
chain_access: &Option<C>,
secp_ctx: &Secp256k1<T>
) -> Result<(), LightningError> where
C::Target: Access,
Store or update channel info from a channel announcement.
You probably don’t want to call this directly, instead relying on a NetGraphMsgHandler’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 chain::Access
object is provided via chain_access
, it will be called to verify
the corresponding UTXO exists on chain and is correctly-formatted.
sourcepub fn update_channel_from_unsigned_announcement<C: Deref>(
&self,
msg: &UnsignedChannelAnnouncement,
chain_access: &Option<C>
) -> Result<(), LightningError> where
C::Target: Access,
pub fn update_channel_from_unsigned_announcement<C: Deref>(
&self,
msg: &UnsignedChannelAnnouncement,
chain_access: &Option<C>
) -> Result<(), LightningError> where
C::Target: Access,
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 chain::Access
object is provided via chain_access
, it will be called to verify
the corresponding UTXO exists on chain and is correctly-formatted.
sourcepub fn close_channel_from_update(
&self,
short_channel_id: u64,
is_permanent: bool
)
pub fn close_channel_from_update(
&self,
short_channel_id: u64,
is_permanent: bool
)
Close a channel 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.
sourcepub fn fail_node(&self, _node_id: &PublicKey, is_permanent: bool)
pub fn fail_node(&self, _node_id: &PublicKey, is_permanent: bool)
Marks a node in the graph as failed.
sourcepub fn remove_stale_channels(&self)
This is supported on crate feature std
only.
pub fn remove_stale_channels(&self)
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 is only available with the std
feature. See
NetworkGraph::remove_stale_channels_with_time
for no-std
use.
sourcepub fn remove_stale_channels_with_time(&self, current_time_unix: u64)
pub fn remove_stale_channels_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 function takes the current unix time as an argument. For users with the std
feature
enabled, NetworkGraph::remove_stale_channels
may be preferable.
sourcepub fn update_channel<T: Verification>(
&self,
msg: &ChannelUpdate,
secp_ctx: &Secp256k1<T>
) -> Result<(), LightningError>
pub fn update_channel<T: Verification>(
&self,
msg: &ChannelUpdate,
secp_ctx: &Secp256k1<T>
) -> 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 NetGraphMsgHandler’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.
sourcepub 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.
Trait Implementations
sourceimpl Clone for NetworkGraph
impl Clone for NetworkGraph
sourceimpl Display for NetworkGraph
impl Display for NetworkGraph
sourceimpl PartialEq<NetworkGraph> for NetworkGraph
impl PartialEq<NetworkGraph> for NetworkGraph
sourceimpl Readable for NetworkGraph
impl Readable for NetworkGraph
sourcefn read<R: Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError>
fn read<R: Read>(reader: &mut R) -> Result<NetworkGraph, DecodeError>
Reads a Self in from the given Read
sourceimpl Writeable for NetworkGraph
impl Writeable for NetworkGraph
sourcefn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>
Writes self out to the given Writer
sourcefn encode(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
fn encode(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Writes self out to a Vec
sourcefn serialized_length(&self) -> usize
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. Read more
Auto Trait Implementations
impl RefUnwindSafe for NetworkGraph
impl Send for NetworkGraph
impl Sync for NetworkGraph
impl Unpin for NetworkGraph
impl UnwindSafe for NetworkGraph
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
sourceimpl<T> MaybeReadable for T where
T: Readable,
impl<T> MaybeReadable for T where
T: Readable,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more