Skip to content

Commit 0660024

Browse files
Add a Metadata type into the ChannelScorer trait
This allows a user to pass the data they are tracking to the trait's functions and update them whenever NetworkGraph makes changes. By default, NetworkGraph has a placeholder type of u8.
1 parent f0ec4d7 commit 0660024

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,15 @@ impl Readable for NodeInfo {
435435
/// objects can call into them to update the metadata and retrieve a minimum fee penalty when doing the
436436
/// route-finding algorithm.
437437
pub trait ChannelScorer {
438+
/// Holds information about a given channel that is to be updated when the user wishes to update
439+
/// the metadata they are tracking (eg metrics for reliability, uptime, floppiness, etc.)
440+
type Metadata;
438441
/// Returns penalty fee for a given channel ID based on user's channel metadata
439-
fn calculate_minimum_fee_penalty(&self, _channel_id: u64) {}
442+
fn calculate_minimum_fee_penalty(&self, _channel_id: u64) -> Option<u64> { None }
440443
/// Optional: allows user to count PaymentSent events for channels
441-
fn score_payment_success(&self, _route: Vec<Vec<RouteHop>>) {}
444+
fn score_payment_success(&self, _route: Vec<Vec<RouteHop>>, _metadata: Vec<Self::Metadata>) {}
442445
/// Optional: allows user to count PaymentFailed events for channels
443-
fn score_payment_failure(&self, _route: Vec<Vec<RouteHop>>, _faulty_nodes: Vec<PublicKey>) {}
446+
fn score_payment_failure(&self, _route: Vec<Vec<RouteHop>>, _faulty_nodes: Vec<PublicKey>, _metadata: Vec<Self::Metadata>) {}
444447
}
445448

446449
/// Represents the network as nodes and channels between them
@@ -503,7 +506,12 @@ impl std::fmt::Display for NetworkGraph {
503506
}
504507
}
505508

506-
impl ChannelScorer for NetworkGraph {}
509+
/// By default, just do nothing when scoring channels. A user is free to extend these
510+
/// definitions to meet their needs.
511+
impl ChannelScorer for NetworkGraph {
512+
/// The default type for Metadata is just a placeholder.
513+
type Metadata = Option<u8>;
514+
}
507515

508516
impl NetworkGraph {
509517
/// Returns all known valid channels' short ids along with announced channel info.

0 commit comments

Comments
 (0)