X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fmod.rs;h=9e6d8e2afd2f763f90ccff2e2eab517d1f30a573;hb=ae0d825d89ca0ac2489737d1b413e778650b093c;hp=91478bafc0468254a4fa13e8882258b549923bed;hpb=8dc7cfab3af7e26cddd8c65a913d5ee021907442;p=rust-lightning diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs index 91478baf..9e6d8e2a 100644 --- a/lightning/src/routing/mod.rs +++ b/lightning/src/routing/mod.rs @@ -9,77 +9,9 @@ //! Structs and impls for receiving messages about the network and storing the topology live here. -pub mod network_graph; +pub mod utxo; +pub mod gossip; pub mod router; -pub mod scorer; - -use routing::network_graph::NodeId; -use routing::router::RouteHop; - -use core::cell::{RefCell, RefMut}; -use core::ops::DerefMut; -use sync::{Mutex, MutexGuard}; - -/// An interface used to score payment channels for path finding. -/// -/// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel. -pub trait Score { - /// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the - /// given channel in the direction from `source` to `target`. - /// - /// The channel's capacity (less any other MPP parts which are also being considered for use in - /// the same payment) is given by `channel_capacity_msat`. It may be guessed from various - /// sources or assumed from no data at all. - /// - /// For hints provided in the invoice, we assume the channel has sufficient capacity to accept - /// the invoice's full amount, and provide a `channel_capacity_msat` of `None`. In all other - /// cases it is set to `Some`, even if we're guessing at the channel value. - /// - /// Your code should be overflow-safe through a `channel_capacity_msat` of 21 million BTC. - fn channel_penalty_msat(&self, short_channel_id: u64, send_amt_msat: u64, channel_capacity_msat: Option, source: &NodeId, target: &NodeId) -> u64; - - /// Handles updating channel penalties after failing to route through a channel. - fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64); -} - -/// A scorer that is accessed under a lock. -/// -/// Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while -/// having shared ownership of a scorer but without requiring internal locking in [`Score`] -/// implementations. Internal locking would be detrimental to route finding performance and could -/// result in [`Score::channel_penalty_msat`] returning a different value for the same channel. -/// -/// [`find_route`]: crate::routing::router::find_route -pub trait LockableScore<'a> { - /// The locked [`Score`] type. - type Locked: 'a + Score; - - /// Returns the locked scorer. - fn lock(&'a self) -> Self::Locked; -} - -impl<'a, T: 'a + Score> LockableScore<'a> for Mutex { - type Locked = MutexGuard<'a, T>; - - fn lock(&'a self) -> MutexGuard<'a, T> { - Mutex::lock(self).unwrap() - } -} - -impl<'a, T: 'a + Score> LockableScore<'a> for RefCell { - type Locked = RefMut<'a, T>; - - fn lock(&'a self) -> RefMut<'a, T> { - self.borrow_mut() - } -} - -impl> Score for T { - fn channel_penalty_msat(&self, short_channel_id: u64, send_amt_msat: u64, channel_capacity_msat: Option, source: &NodeId, target: &NodeId) -> u64 { - self.deref().channel_penalty_msat(short_channel_id, send_amt_msat, channel_capacity_msat, source, target) - } - - fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { - self.deref_mut().payment_path_failed(path, short_channel_id) - } -} +pub mod scoring; +#[cfg(test)] +pub(crate) mod test_utils;