]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make payment_path_failed path type bindings-mappable
authorMatt Corallo <git@bluematt.me>
Sun, 31 Oct 2021 18:21:46 +0000 (18:21 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 2 Nov 2021 20:50:42 +0000 (20:50 +0000)
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<OpaqueType>`.

lightning-invoice/src/payment.rs
lightning/src/routing/mod.rs
lightning/src/routing/router.rs
lightning/src/routing/scorer.rs

index b29fe18f5bf90159ab48a15e7fe71db5781643bb..075559bfd8ed857878e391fcd2a396ae3742093c 100644 (file)
@@ -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<RouteHop>, _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::<Vec<_>>();
+                                       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<RouteHop>, 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);
                        }
index d6c016468ce79f696483ccafcee03e0269b6267f..a2454f6a3fec0da3dc2e960420750af904dff215 100644 (file)
@@ -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<RouteHop>, 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<S: Score, T: DerefMut<Target=S>> Score for T {
                self.deref().channel_penalty_msat(short_channel_id, source, target)
        }
 
-       fn payment_path_failed(&mut self, path: &Vec<RouteHop>, 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)
        }
 }
index 724765a1856c84758c69682e6f4fcb0f6822fbc5..6caba67785ed9ae1175274469a5aeeb1338b5d4e 100644 (file)
@@ -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<RouteHop>, _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<RouteHop>, _short_channel_id: u64) {}
+               fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
        }
 
        #[test]
index 2aa0b4c145e67ef3c285ec2901d6a92631594ff5..956b09a54211e4dd90b9d6585c5c0aadb43edc47 100644 (file)
@@ -220,7 +220,7 @@ impl<T: Time> routing::Score for ScorerUsingTime<T> {
                self.params.base_penalty_msat + failure_penalty_msat
        }
 
-       fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, 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