X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fscoring.rs;h=3030c930818e631aae705e785dfa6afdfb56fa70;hb=5d0deacc3debd8ab22216266030265816bf4e29e;hp=a3d970715872433d40572d98301b0309419876ab;hpb=990e34679828ed4eca7bc8e179869f497b5dcc98;p=rust-lightning diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index a3d97071..3030c930 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -188,12 +188,39 @@ pub struct MultiThreadedLockableScore { score: Mutex, } #[cfg(c_bindings)] -/// (C-not exported) +/// A locked `MultiThreadedLockableScore`. +pub struct MultiThreadedScoreLock<'a, S: Score>(MutexGuard<'a, S>); +#[cfg(c_bindings)] +impl<'a, T: Score + 'a> Score for MultiThreadedScoreLock<'a, T> { + fn channel_penalty_msat(&self, scid: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage) -> u64 { + self.0.channel_penalty_msat(scid, source, target, usage) + } + fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { + self.0.payment_path_failed(path, short_channel_id) + } + fn payment_path_successful(&mut self, path: &[&RouteHop]) { + self.0.payment_path_successful(path) + } + fn probe_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { + self.0.probe_failed(path, short_channel_id) + } + fn probe_successful(&mut self, path: &[&RouteHop]) { + self.0.probe_successful(path) + } +} +#[cfg(c_bindings)] +impl<'a, T: Score + 'a> Writeable for MultiThreadedScoreLock<'a, T> { + fn write(&self, writer: &mut W) -> Result<(), io::Error> { + self.0.write(writer) + } +} + +#[cfg(c_bindings)] impl<'a, T: Score + 'a> LockableScore<'a> for MultiThreadedLockableScore { - type Locked = MutexGuard<'a, T>; + type Locked = MultiThreadedScoreLock<'a, T>; - fn lock(&'a self) -> MutexGuard<'a, T> { - Mutex::lock(&self.score).unwrap() + fn lock(&'a self) -> MultiThreadedScoreLock<'a, T> { + MultiThreadedScoreLock(Mutex::lock(&self.score).unwrap()) } } @@ -726,21 +753,25 @@ impl, T: Time, U: Deref> DirectedChannelLiqui impl, T: Time, U: DerefMut> DirectedChannelLiquidity { /// Adjusts the channel liquidity balance bounds when failing to route `amount_msat`. fn failed_at_channel(&mut self, amount_msat: u64, chan_descr: fmt::Arguments, logger: &Log) where Log::Target: Logger { - if amount_msat < self.max_liquidity_msat() { - log_debug!(logger, "Setting max liquidity of {} to {}", chan_descr, amount_msat); + let existing_max_msat = self.max_liquidity_msat(); + if amount_msat < existing_max_msat { + log_debug!(logger, "Setting max liquidity of {} from {} to {}", chan_descr, existing_max_msat, amount_msat); self.set_max_liquidity_msat(amount_msat); } else { - log_trace!(logger, "Max liquidity of {} already more than {}", chan_descr, amount_msat); + log_trace!(logger, "Max liquidity of {} is {} (already less than or equal to {})", + chan_descr, existing_max_msat, amount_msat); } } /// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream. fn failed_downstream(&mut self, amount_msat: u64, chan_descr: fmt::Arguments, logger: &Log) where Log::Target: Logger { - if amount_msat > self.min_liquidity_msat() { - log_debug!(logger, "Setting min liquidity of {} to {}", chan_descr, amount_msat); + let existing_min_msat = self.min_liquidity_msat(); + if amount_msat > existing_min_msat { + log_debug!(logger, "Setting min liquidity of {} from {} to {}", existing_min_msat, chan_descr, amount_msat); self.set_min_liquidity_msat(amount_msat); } else { - log_trace!(logger, "Min liquidity of {} already less than {}", chan_descr, amount_msat); + log_trace!(logger, "Min liquidity of {} is {} (already greater than or equal to {})", + chan_descr, existing_min_msat, amount_msat); } } @@ -1281,7 +1312,7 @@ mod tests { use util::time::Time; use util::time::tests::SinceEpoch; - use ln::features::{ChannelFeatures, NodeFeatures}; + use ln::channelmanager; use ln::msgs::{ChannelAnnouncement, ChannelUpdate, UnsignedChannelAnnouncement, UnsignedChannelUpdate}; use routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId}; use routing::router::RouteHop; @@ -1372,7 +1403,7 @@ mod tests { let node_2_secret = &SecretKey::from_slice(&[40; 32]).unwrap(); let secp_ctx = Secp256k1::new(); let unsigned_announcement = UnsignedChannelAnnouncement { - features: ChannelFeatures::known(), + features: channelmanager::provided_channel_features(), chain_hash: genesis_hash, short_channel_id, node_id_1: PublicKey::from_secret_key(&secp_ctx, &node_1_key), @@ -1426,25 +1457,25 @@ mod tests { vec![ RouteHop { pubkey: source_pubkey(), - node_features: NodeFeatures::known(), + node_features: channelmanager::provided_node_features(), short_channel_id: 41, - channel_features: ChannelFeatures::known(), + channel_features: channelmanager::provided_channel_features(), fee_msat: 1, cltv_expiry_delta: 18, }, RouteHop { pubkey: target_pubkey(), - node_features: NodeFeatures::known(), + node_features: channelmanager::provided_node_features(), short_channel_id: 42, - channel_features: ChannelFeatures::known(), + channel_features: channelmanager::provided_channel_features(), fee_msat: 2, cltv_expiry_delta: 18, }, RouteHop { pubkey: recipient_pubkey(), - node_features: NodeFeatures::known(), + node_features: channelmanager::provided_node_features(), short_channel_id: 43, - channel_features: ChannelFeatures::known(), + channel_features: channelmanager::provided_channel_features(), fee_msat: amount_msat, cltv_expiry_delta: 18, },