]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Require Writeable for all `Score` and impl `Writeable` for `LockedScore` 2021-10-wip-103-c-bindings
authorMatt Corallo <git@bluematt.me>
Tue, 2 Nov 2021 22:33:07 +0000 (22:33 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 3 Nov 2021 17:12:02 +0000 (17:12 +0000)
Ultimately we likely need to wrap the locked `Score` in a struct
that exposes writeable somehow, but because all traits have to be
fully concretized for C bindings we'll still need `Writeable` on
all `Score` in order to expose `Writeable` on the locked score.

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

index e7b162b38f96236472b0de61c7f97446240f8d86..62fea7947ecdebb8caf2488f368de8741e36b5b3 100644 (file)
@@ -67,6 +67,9 @@
 //! # }
 //! #
 //! # struct FakeScorer {};
+//! # impl lightning::util::ser::Writeable for FakeScorer {
+//! #     fn write<W: lightning::util::ser::Writer>(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); }
+//! # }
 //! # impl routing::Score for FakeScorer {
 //! #     fn channel_penalty_msat(
 //! #         &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
@@ -1086,6 +1089,9 @@ mod tests {
                }
        }
 
+       impl lightning::util::ser::Writeable for TestScorer {
+               fn write<W: lightning::util::ser::Writer>(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); }
+       }
        impl routing::Score for TestScorer {
                fn channel_penalty_msat(
                        &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
index 0282ee93e40fc0da619e59225466205a4a5c746e..74cddfad5f482f7a01c4d5cba7d35769b2070061 100644 (file)
@@ -18,10 +18,13 @@ use routing::router::RouteHop;
 
 use sync::{Mutex, MutexGuard};
 
+use util::ser::{Writeable, Writer};
+use io;
+
 /// 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 {
+pub trait Score : Writeable {
        /// Returns the fee in msats willing to be paid to avoid routing through the given channel
        /// in the direction from `source` to `target`.
        fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId, target: &NodeId) -> u64;
@@ -53,3 +56,10 @@ impl<S: Score> LockableScore<S> {
                self.scorer.lock().unwrap()
        }
 }
+
+impl<S: Score> Writeable for LockableScore<S> {
+       #[inline]
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               self.scorer.lock().unwrap().write(w)
+       }
+}
index 974ae74e4960f0c636670f721106aa4cb8d87d53..549278b8098ea8a21aec98f936f8d4ab9fd41097 100644 (file)
@@ -4549,6 +4549,9 @@ mod tests {
                short_channel_id: u64,
        }
 
+       impl Writeable for BadChannelScorer {
+               fn write<W: ::util::ser::Writer>(&self, _: &mut W) -> Result<(), crate::io::Error> { unreachable!(); }
+       }
        impl routing::Score for BadChannelScorer {
                fn channel_penalty_msat(&self, short_channel_id: u64, _source: &NodeId, _target: &NodeId) -> u64 {
                        if short_channel_id == self.short_channel_id { u64::max_value() } else { 0 }
@@ -4561,6 +4564,9 @@ mod tests {
                node_id: NodeId,
        }
 
+       impl Writeable for BadNodeScorer {
+               fn write<W: ::util::ser::Writer>(&self, _: &mut W) -> Result<(), crate::io::Error> { unreachable!(); }
+       }
        impl routing::Score for BadNodeScorer {
                fn channel_penalty_msat(&self, _short_channel_id: u64, _source: &NodeId, target: &NodeId) -> u64 {
                        if *target == self.node_id { u64::max_value() } else { 0 }