From: Matt Corallo Date: Sun, 31 Oct 2021 18:21:46 +0000 (+0000) Subject: Make payment_path_failed path type bindings-mappable X-Git-Tag: v0.0.103~1^2~3 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=51d146c56641b42ae1b1c3d89a2d3ce5033f5578;p=rust-lightning Make payment_path_failed path type bindings-mappable The bindings don't currently support passing `Vec`s of objects which it mappes as "opaque types". This is because it will require clones to convert its own list of references to Rust's list of objects. In the near future we should resolve this limitation, allowing us to revert this (and make `find_route`'s method signature similarly cleaner), but for now we must avoid `Vec`. --- diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index b29fe18f5..075559bfd 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -71,7 +71,7 @@ //! # fn channel_penalty_msat( //! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId //! # ) -> u64 { 0 } -//! # fn payment_path_failed(&mut self, _path: &Vec, _short_channel_id: u64) {} +//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} //! # } //! # //! # struct FakeLogger {}; @@ -415,7 +415,8 @@ where all_paths_failed, payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, .. } => { if let Some(short_channel_id) = short_channel_id { - self.scorer.lock().payment_path_failed(path, *short_channel_id); + let t = path.iter().collect::>(); + self.scorer.lock().payment_path_failed(&t, *short_channel_id); } if *rejected_by_dest { @@ -1099,7 +1100,7 @@ mod tests { &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId ) -> u64 { 0 } - fn payment_path_failed(&mut self, _path: &Vec, short_channel_id: u64) { + fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) { if let Some(expected_short_channel_id) = self.expectations.pop_front() { assert_eq!(short_channel_id, expected_short_channel_id); } diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs index d6c016468..a2454f6a3 100644 --- a/lightning/src/routing/mod.rs +++ b/lightning/src/routing/mod.rs @@ -30,7 +30,7 @@ pub trait Score { fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId, target: &NodeId) -> u64; /// Handles updating channel penalties after failing to route through a channel. - fn payment_path_failed(&mut self, path: &Vec, short_channel_id: u64); + fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64); } /// A scorer that is accessed under a lock. @@ -70,7 +70,7 @@ impl> Score for T { self.deref().channel_penalty_msat(short_channel_id, source, target) } - fn payment_path_failed(&mut self, path: &Vec, short_channel_id: u64) { + fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) { self.deref_mut().payment_path_failed(path, short_channel_id) } } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 724765a18..6caba6778 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -4552,7 +4552,7 @@ mod tests { if short_channel_id == self.short_channel_id { u64::max_value() } else { 0 } } - fn payment_path_failed(&mut self, _path: &Vec, _short_channel_id: u64) {} + fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} } struct BadNodeScorer { @@ -4564,7 +4564,7 @@ mod tests { if *target == self.node_id { u64::max_value() } else { 0 } } - fn payment_path_failed(&mut self, _path: &Vec, _short_channel_id: u64) {} + fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {} } #[test] diff --git a/lightning/src/routing/scorer.rs b/lightning/src/routing/scorer.rs index 2aa0b4c14..956b09a54 100644 --- a/lightning/src/routing/scorer.rs +++ b/lightning/src/routing/scorer.rs @@ -220,7 +220,7 @@ impl routing::Score for ScorerUsingTime { self.params.base_penalty_msat + failure_penalty_msat } - fn payment_path_failed(&mut self, _path: &Vec, short_channel_id: u64) { + fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) { let failure_penalty_msat = self.params.failure_penalty_msat; let half_life = self.params.failure_penalty_half_life; self.channel_failures