1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Utilities for scoring payment channels.
12 //! [`Scorer`] may be given to [`get_route`] to score payment channels during path finding when a
13 //! custom [`routing::Score`] implementation is not needed.
18 //! # extern crate secp256k1;
20 //! # use lightning::routing::network_graph::NetworkGraph;
21 //! # use lightning::routing::router::get_route;
22 //! # use lightning::routing::scorer::Scorer;
23 //! # use lightning::util::logger::{Logger, Record};
24 //! # use secp256k1::key::PublicKey;
26 //! # struct FakeLogger {};
27 //! # impl Logger for FakeLogger {
28 //! # fn log(&self, record: &Record) { unimplemented!() }
30 //! # fn find_scored_route(payer: PublicKey, payee: PublicKey, network_graph: NetworkGraph) {
31 //! # let logger = FakeLogger {};
33 //! // Use the default channel penalty.
34 //! let scorer = Scorer::default();
36 //! // Or use a custom channel penalty.
37 //! let scorer = Scorer::new(1_000);
39 //! let route = get_route(&payer, &network_graph, &payee, None, None, &vec![], 1_000, 42, &logger, &scorer);
43 //! [`get_route`]: crate::routing::router::get_route
47 use routing::network_graph::NodeId;
49 /// [`routing::Score`] implementation that provides reasonable default behavior.
51 /// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with
52 /// slightly higher fees are available.
54 /// See [module-level documentation] for usage.
56 /// [module-level documentation]: crate::routing::scorer
58 base_penalty_msat: u64,
62 /// Creates a new scorer using `base_penalty_msat` as the channel penalty.
63 pub fn new(base_penalty_msat: u64) -> Self {
64 Self { base_penalty_msat }
68 impl Default for Scorer {
69 /// Creates a new scorer using 500 msat as the channel penalty.
70 fn default() -> Self {
75 impl routing::Score for Scorer {
76 fn channel_penalty_msat(
77 &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
79 self.base_penalty_msat