Skip to content

Commit 65fd2af

Browse files
Add default empty ChannelScorer impl
1 parent 23c7861 commit 65fd2af

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ impl_writeable!(ChannelInfo, 0, {
282282
minimum_fee_penalty
283283
});
284284

285+
/// By default, these methods do nothing. A user may override them to write to their metadata as needed
286+
impl ChannelScorer for ChannelInfo {
287+
fn calculate_minimum_fee_penalty(&self, channel_id: u64) {}
288+
fn score_payment_failure(&self, route: Vec<Vec<RouteHop>>, faulty_nodes: Vec<PublicKey>) {}
289+
fn score_payment_success(&self, route: Vec<Vec<RouteHop>>) {}
290+
}
285291

286292
/// Fees for routing via a given channel or a node
287293
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
@@ -437,7 +443,7 @@ impl Readable for NodeInfo {
437443
/// route-finding algorithm.
438444
pub trait ChannelScorer {
439445
/// Returns penalty fee for a given channel ID based on user's channel metadata
440-
fn calculate_minimum_fee_penalty(&self, channel_id: u64) -> u64;
446+
fn calculate_minimum_fee_penalty(&self, channel_id: u64);
441447
/// Optional: allows user to count PaymentSent events for channels
442448
fn score_payment_success(&self, route: Vec<Vec<RouteHop>>);
443449
/// Optional: allows user to count PaymentFailed events for channels
@@ -504,6 +510,12 @@ impl std::fmt::Display for NetworkGraph {
504510
}
505511
}
506512

513+
impl ChannelScorer for NetworkGraph {
514+
fn calculate_minimum_fee_penalty(&self, channel_id: u64) {}
515+
fn score_payment_success(&self, route: Vec<Vec<RouteHop>>) {}
516+
fn score_payment_failure(&self, route: Vec<Vec<RouteHop>>, faulty_nodes: Vec<PublicKey>) {}
517+
}
518+
507519
impl NetworkGraph {
508520
/// Returns all known valid channels' short ids along with announced channel info.
509521
pub fn get_channels<'a>(&'a self) -> &'a BTreeMap<u64, ChannelInfo> { &self.channels }

0 commit comments

Comments
 (0)