X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fscoring.rs;h=4c47aac47b64c2e78df2b39d0e740083023ecadc;hb=e5c988e00c515467e76639b5aac47b02a7f7b4a6;hp=0e04c63903392b8ccfc36d72c3fa87109b86c17b;hpb=f53d13bcb8220b3ce39e51a4d20beb23b3930d1f;p=rust-lightning diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 0e04c639..4c47aac4 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -15,14 +15,14 @@ //! # Example //! //! ``` -//! # extern crate secp256k1; +//! # extern crate bitcoin; //! # //! # use lightning::routing::network_graph::NetworkGraph; //! # use lightning::routing::router::{RouteParameters, find_route}; //! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters, Scorer, ScoringParameters}; //! # use lightning::chain::keysinterface::{KeysManager, KeysInterface}; //! # use lightning::util::logger::{Logger, Record}; -//! # use secp256k1::key::PublicKey; +//! # use bitcoin::secp256k1::PublicKey; //! # //! # struct FakeLogger {}; //! # impl Logger for FakeLogger { @@ -137,6 +137,14 @@ pub trait LockableScore<'a> { fn lock(&'a self) -> Self::Locked; } +/// Refers to a scorer that is accessible under lock and also writeable to disk +/// +/// We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to +/// use the Persister to persist it. +pub trait WriteableScore<'a>: LockableScore<'a> + Writeable {} + +impl<'a, T> WriteableScore<'a> for T where T: LockableScore<'a> + Writeable {} + /// (C-not exported) impl<'a, T: 'a + Score> LockableScore<'a> for Mutex { type Locked = MutexGuard<'a, T>; @@ -623,6 +631,33 @@ impl, L: Deref, T: Time> ProbabilisticScorerUsin assert!(self.channel_liquidities.insert(short_channel_id, liquidity).is_none()); self } + + /// Dump the contents of this scorer into the configured logger. + /// + /// Note that this writes roughly one line per channel for which we have a liquidity estimate, + /// which may be a substantial amount of log output. + pub fn debug_log_liquidity_stats(&self) { + let graph = self.network_graph.read_only(); + for (scid, liq) in self.channel_liquidities.iter() { + if let Some(chan_debug) = graph.channels().get(scid) { + let log_direction = |source, target| { + if let Some((directed_info, _)) = chan_debug.as_directed_to(target) { + let amt = directed_info.effective_capacity().as_msat(); + let dir_liq = liq.as_directed(source, target, amt, self.params.liquidity_offset_half_life); + log_debug!(self.logger, "Liquidity from {:?} to {:?} via {} is in the range ({}, {})", + source, target, scid, dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat()); + } else { + log_debug!(self.logger, "No amount known for SCID {} from {:?} to {:?}", scid, source, target); + } + }; + + log_direction(&chan_debug.node_one, &chan_debug.node_two); + log_direction(&chan_debug.node_two, &chan_debug.node_one); + } else { + log_debug!(self.logger, "No network graph entry for SCID {}", scid); + } + } + } } impl ProbabilisticScoringParameters { @@ -1778,10 +1813,10 @@ mod tests { }; let msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]); let signed_announcement = ChannelAnnouncement { - node_signature_1: secp_ctx.sign(&msghash, &node_1_key), - node_signature_2: secp_ctx.sign(&msghash, &node_2_key), - bitcoin_signature_1: secp_ctx.sign(&msghash, &node_1_secret), - bitcoin_signature_2: secp_ctx.sign(&msghash, &node_2_secret), + node_signature_1: secp_ctx.sign_ecdsa(&msghash, &node_1_key), + node_signature_2: secp_ctx.sign_ecdsa(&msghash, &node_2_key), + bitcoin_signature_1: secp_ctx.sign_ecdsa(&msghash, &node_1_secret), + bitcoin_signature_2: secp_ctx.sign_ecdsa(&msghash, &node_2_secret), contents: unsigned_announcement, }; let chain_source: Option<&::util::test_utils::TestChainSource> = None; @@ -1810,7 +1845,7 @@ mod tests { }; let msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_update.encode()[..])[..]); let signed_update = ChannelUpdate { - signature: secp_ctx.sign(&msghash, &node_key), + signature: secp_ctx.sign_ecdsa(&msghash, &node_key), contents: unsigned_update, }; network_graph.update_channel(&signed_update, &secp_ctx).unwrap();