X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fscoring.rs;h=b02b61fa9f6c0381fe9fd7ffcad4eedd23656be5;hb=a1fedeaec2c551ac4bb3cb2362daef3d81f9e765;hp=9f3b7806a991681259deb4ae8655cc060a730382;hpb=2e730cdc9c4eeec3d514ccbe6cb5976f0d8fa40f;p=rust-lightning diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 9f3b7806..b02b61fa 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -189,6 +189,32 @@ impl<'a, S: Writeable> Writeable for MutexGuard<'a, S> { } } +/// [`Score`] implementation that uses a fixed penalty. +pub struct FixedPenaltyScorer { + penalty_msat: u64, +} + +impl_writeable_tlv_based!(FixedPenaltyScorer, { + (0, penalty_msat, required), +}); + +impl FixedPenaltyScorer { + /// Creates a new scorer using `penalty_msat`. + pub fn with_penalty(penalty_msat: u64) -> Self { + Self { penalty_msat } + } +} + +impl Score for FixedPenaltyScorer { + fn channel_penalty_msat(&self, _: u64, _: u64, _: u64, _: &NodeId, _: &NodeId) -> u64 { + self.penalty_msat + } + + fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} + + fn payment_path_successful(&mut self, _path: &[&RouteHop]) {} +} + /// [`Score`] implementation that provides reasonable default behavior. /// /// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with @@ -202,6 +228,10 @@ impl<'a, S: Writeable> Writeable for MutexGuard<'a, S> { /// behavior. /// /// [module-level documentation]: crate::routing::scoring +#[deprecated( + since = "0.0.105", + note = "ProbabilisticScorer should be used instead of Scorer.", +)] pub type Scorer = ScorerUsingTime::; #[cfg(not(feature = "no-std"))] @@ -301,18 +331,6 @@ impl ScorerUsingTime { channel_failures: HashMap::new(), } } - - /// Creates a new scorer using `penalty_msat` as a fixed channel penalty. - #[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] - pub fn with_fixed_penalty(penalty_msat: u64) -> Self { - Self::new(ScoringParameters { - base_penalty_msat: penalty_msat, - failure_penalty_msat: 0, - failure_penalty_half_life: Duration::from_secs(0), - overuse_penalty_start_1024th: 1024, - overuse_penalty_msat_per_1024th: 0, - }) - } } impl ChannelFailure {