pub struct ChannelGraph {
pub(crate) me: OffchainPublicKey,
pub(crate) inner: Arc<RwLock<InnerGraph>>,
}Expand description
A directed graph representing logical channels between nodes.
The graph is directed, with nodes representing the physical nodes in the network using
their [OffchainPublicKey] as identifier and edges representing the logical channels
between them. Each logical channel aggregates different weighted properties, like
channel capacity (calculated from the on-chain channel balance, ticket price and ticket probability)
and evaluated transport network properties between the nodes.
Interior mutability is provided via an internal [RwLock] so that all trait
methods (which take &self) can safely read and write the graph. In production
code, the graph is expected to be shared behind an Arc<ChannelGraph>.
Fields§
§me: OffchainPublicKey§inner: Arc<RwLock<InnerGraph>>Implementations§
Source§impl ChannelGraph
impl ChannelGraph
Source§impl ChannelGraph
impl ChannelGraph
Sourcepub fn connected_edges(
&self,
) -> Vec<(OffchainPublicKey, OffchainPublicKey, Observations)>
pub fn connected_edges( &self, ) -> Vec<(OffchainPublicKey, OffchainPublicKey, Observations)>
Returns all edges in the graph as (source, destination, observations) triples.
Only nodes that participate in at least one edge appear in the result. Isolated nodes (no incoming or outgoing edges) are omitted.
Sourcepub fn reachable_edges(
&self,
) -> Vec<(OffchainPublicKey, OffchainPublicKey, Observations)>
pub fn reachable_edges( &self, ) -> Vec<(OffchainPublicKey, OffchainPublicKey, Observations)>
Returns edges reachable from self.me via directed BFS.
Only edges where both the source and destination are reachable from our node are included. This filters out disconnected subgraphs that we cannot actually route through.
Trait Implementations§
Source§impl Clone for ChannelGraph
impl Clone for ChannelGraph
Source§fn clone(&self) -> ChannelGraph
fn clone(&self) -> ChannelGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChannelGraph
impl Debug for ChannelGraph
Source§impl NetworkGraphTraverse for ChannelGraph
impl NetworkGraphTraverse for ChannelGraph
Source§type Observed = Observations
type Observed = Observations
Source§fn simple_paths<C: CostFn<Weight = Self::Observed>>(
&self,
source: &Self::NodeId,
destination: &Self::NodeId,
length: usize,
take_count: Option<usize>,
cost_fn: C,
) -> Vec<(Vec<Self::NodeId>, PathId, C::Cost)>
fn simple_paths<C: CostFn<Weight = Self::Observed>>( &self, source: &Self::NodeId, destination: &Self::NodeId, length: usize, take_count: Option<usize>, cost_fn: C, ) -> Vec<(Vec<Self::NodeId>, PathId, C::Cost)>
Source§impl NetworkGraphUpdate for ChannelGraph
impl NetworkGraphUpdate for ChannelGraph
Source§fn record_edge<N, P>(&self, update: MeasurableEdge<N, P>)
fn record_edge<N, P>(&self, update: MeasurableEdge<N, P>)
Source§impl NetworkGraphView for ChannelGraph
impl NetworkGraphView for ChannelGraph
Source§type Observed = Observations
type Observed = Observations
Source§fn node_count(&self) -> usize
fn node_count(&self) -> usize
Source§fn contains_node(&self, key: &OffchainPublicKey) -> bool
fn contains_node(&self, key: &OffchainPublicKey) -> bool
Source§fn nodes(&self) -> BoxStream<'static, Self::NodeId>
fn nodes(&self) -> BoxStream<'static, Self::NodeId>
Source§impl NetworkGraphWrite for ChannelGraph
impl NetworkGraphWrite for ChannelGraph
Source§fn upsert_edge<F>(
&self,
src: &OffchainPublicKey,
dest: &OffchainPublicKey,
f: F,
)where
F: FnOnce(&mut Observations),
fn upsert_edge<F>(
&self,
src: &OffchainPublicKey,
dest: &OffchainPublicKey,
f: F,
)where
F: FnOnce(&mut Observations),
Mutably updates the edge observations between two nodes.
If the edge does not exist, it gets created first.
If the nodes do not exist, they are added as well.
Source§type Error = ChannelGraphError
type Error = ChannelGraphError
Source§type Observed = Observations
type Observed = Observations
Source§fn add_node(&self, key: OffchainPublicKey)
fn add_node(&self, key: OffchainPublicKey)
Source§fn remove_node(&self, key: &OffchainPublicKey)
fn remove_node(&self, key: &OffchainPublicKey)
Source§fn add_edge(
&self,
src: &OffchainPublicKey,
dest: &OffchainPublicKey,
) -> Result<(), ChannelGraphError>
fn add_edge( &self, src: &OffchainPublicKey, dest: &OffchainPublicKey, ) -> Result<(), ChannelGraphError>
Source§fn remove_edge(&self, src: &OffchainPublicKey, dest: &OffchainPublicKey)
fn remove_edge(&self, src: &OffchainPublicKey, dest: &OffchainPublicKey)
Auto Trait Implementations§
impl Freeze for ChannelGraph
impl !RefUnwindSafe for ChannelGraph
impl Send for ChannelGraph
impl Sync for ChannelGraph
impl Unpin for ChannelGraph
impl !UnwindSafe for ChannelGraph
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more