X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Frouting%2Fscoring.rs;h=2c2980a8819bf83c6a60590604332786ab51ca83;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=85def69b662a7b4a379fa73d11e496ecb3225228;hpb=4995ea79aac663f4474048a4059700dc67115dbe;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs index 85def69..2c2980a 100644 --- a/lightning-c-bindings/src/lightning/routing/scoring.rs +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -14,32 +14,32 @@ //! # Example //! //! ``` -//! # extern crate secp256k1; +//! # extern crate bitcoin; //! # -//! # use lightning::routing::network_graph::NetworkGraph; +//! # use lightning::routing::gossip::NetworkGraph; //! # use lightning::routing::router::{RouteParameters, find_route}; -//! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters, Scorer, ScoringParameters}; -//! # use lightning::chain::keysinterface::{KeysManager, KeysInterface}; +//! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters}; +//! # use lightning::chain::keysinterface::KeysManager; //! # use lightning::util::logger::{Logger, Record}; -//! # use secp256k1::key::PublicKey; +//! # use bitcoin::secp256k1::PublicKey; //! # //! # struct FakeLogger {}; //! # impl Logger for FakeLogger { //! # fn log(&self, record: &Record) { unimplemented!() } //! # } -//! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph) { +//! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph<&FakeLogger>) { //! # let logger = FakeLogger {}; //! # //! // Use the default channel penalties. //! let params = ProbabilisticScoringParameters::default(); -//! let scorer = ProbabilisticScorer::new(params, &network_graph); +//! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger); //! //! // Or use custom channel penalties. //! let params = ProbabilisticScoringParameters { //! liquidity_penalty_multiplier_msat: 2 * 1000, //! ..ProbabilisticScoringParameters::default() //! }; -//! let scorer = ProbabilisticScorer::new(params, &network_graph); +//! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger); //! # let random_seed_bytes = [42u8; 32]; //! //! let route = find_route(&payer, &route_params, &network_graph, None, &logger, &scorer, &random_seed_bytes); @@ -78,11 +78,15 @@ pub struct Score { /// [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount. /// Thus, implementations should be overflow-safe. #[must_use] - pub channel_penalty_msat: extern "C" fn (this_arg: *const c_void, short_channel_id: u64, send_amt_msat: u64, capacity_msat: u64, source: &crate::lightning::routing::network_graph::NodeId, target: &crate::lightning::routing::network_graph::NodeId) -> u64, + pub channel_penalty_msat: extern "C" fn (this_arg: *const c_void, short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, usage: crate::lightning::routing::scoring::ChannelUsage) -> u64, /// Handles updating channel penalties after failing to route through a channel. pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), /// Handles updating channel penalties after successfully routing along a path. pub payment_path_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ), + /// Handles updating channel penalties after a probe over the given path failed. + pub probe_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64), + /// Handles updating channel penalties after a probe over the given path succeeded. + pub probe_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ), /// Serialize the object into a byte array pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, /// Frees any resources associated with this object given its this_arg pointer. @@ -98,6 +102,8 @@ pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score { channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat), payment_path_failed: Clone::clone(&orig.payment_path_failed), payment_path_successful: Clone::clone(&orig.payment_path_successful), + probe_failed: Clone::clone(&orig.probe_failed), + probe_successful: Clone::clone(&orig.probe_successful), write: Clone::clone(&orig.write), free: Clone::clone(&orig.free), } @@ -111,8 +117,8 @@ impl lightning::util::ser::Writeable for Score { use lightning::routing::scoring::Score as rustScore; impl rustScore for Score { - fn channel_penalty_msat(&self, mut short_channel_id: u64, mut send_amt_msat: u64, mut capacity_msat: u64, mut source: &lightning::routing::network_graph::NodeId, mut target: &lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, send_amt_msat, capacity_msat, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((source as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }, &crate::lightning::routing::network_graph::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((target as *const lightning::routing::network_graph::NodeId<>) as *mut _) }, is_owned: false }); + fn channel_penalty_msat(&self, mut short_channel_id: u64, mut source: &lightning::routing::gossip::NodeId, mut target: &lightning::routing::gossip::NodeId, mut usage: lightning::routing::scoring::ChannelUsage) -> u64 { + let mut ret = (self.channel_penalty_msat)(self.this_arg, short_channel_id, &crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((source as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }, &crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((target as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false }, crate::lightning::routing::scoring::ChannelUsage { inner: ObjOps::heap_alloc(usage), is_owned: true }); ret } fn payment_path_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) { @@ -123,6 +129,14 @@ impl rustScore for Score { let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; (self.payment_path_successful)(self.this_arg, local_path.into()) } + fn probe_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.probe_failed)(self.this_arg, local_path.into(), short_channel_id) + } + fn probe_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) { + let mut local_path = Vec::new(); for item in path.iter() { local_path.push( { crate::lightning::routing::router::RouteHop { inner: unsafe { ObjOps::nonnull_ptr_to_inner(((*item) as *const lightning::routing::router::RouteHop<>) as *mut _) }, is_owned: false } }); }; + (self.probe_successful)(self.this_arg, local_path.into()) + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -201,6 +215,70 @@ impl Drop for LockableScore { } } } +/// 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. +#[repr(C)] +pub struct WriteableScore { + /// An opaque pointer which is passed to your function implementations as an argument. + /// This has no meaning in the LDK, and can be NULL or any other value. + pub this_arg: *mut c_void, + /// Implementation of LockableScore for this object. + pub LockableScore: crate::lightning::routing::scoring::LockableScore, + /// Serialize the object into a byte array + pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z, + /// Frees any resources associated with this object given its this_arg pointer. + /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. + pub free: Option, +} +unsafe impl Send for WriteableScore {} +unsafe impl Sync for WriteableScore {} +#[no_mangle] +pub(crate) extern "C" fn WriteableScore_clone_fields(orig: &WriteableScore) -> WriteableScore { + WriteableScore { + this_arg: orig.this_arg, + LockableScore: crate::lightning::routing::scoring::LockableScore_clone_fields(&orig.LockableScore), + write: Clone::clone(&orig.write), + free: Clone::clone(&orig.free), + } +} +impl<'a> lightning::routing::scoring::LockableScore<'a> for WriteableScore { + type Locked = crate::lightning::routing::scoring::Score; + fn lock(&'a self) -> crate::lightning::routing::scoring::Score { + let mut ret = (self.LockableScore.lock)(self.LockableScore.this_arg); + ret + } +} +impl lightning::util::ser::Writeable for WriteableScore { + fn write(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> { + let vec = (self.write)(self.this_arg); + w.write_all(vec.as_slice()) + } +} + +use lightning::routing::scoring::WriteableScore as rustWriteableScore; +impl<'a> rustWriteableScore<'a> for WriteableScore { +} + +// We're essentially a pointer already, or at least a set of pointers, so allow us to be used +// directly as a Deref trait in higher-level structs: +impl core::ops::Deref for WriteableScore { + type Target = Self; + fn deref(&self) -> &Self { + self + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn WriteableScore_free(this_ptr: WriteableScore) { } +impl Drop for WriteableScore { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport; pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport; @@ -234,7 +312,7 @@ pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockabl #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore) }; } #[allow(unused)] impl MultiThreadedLockableScore { @@ -252,27 +330,19 @@ impl MultiThreadedLockableScore { ret } } -/// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`]. -#[must_use] -#[no_mangle] -pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> MultiThreadedLockableScore { - let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score); - MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true } -} +use lightning::routing::scoring::MultiThreadedScoreLock as nativeMultiThreadedScoreLockImport; +pub(crate) type nativeMultiThreadedScoreLock = nativeMultiThreadedScoreLockImport<'static, crate::lightning::routing::scoring::Score>; -use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport; -pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport; - -/// [`Score`] implementation that uses a fixed penalty. +/// A locked `MultiThreadedLockableScore`. #[must_use] #[repr(C)] -pub struct FixedPenaltyScorer { +pub struct MultiThreadedScoreLock { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeFixedPenaltyScorer, + pub inner: *mut nativeMultiThreadedScoreLock, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -280,144 +350,178 @@ pub struct FixedPenaltyScorer { pub is_owned: bool, } -impl Drop for FixedPenaltyScorer { +impl Drop for MultiThreadedScoreLock { fn drop(&mut self) { - if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) { + if self.is_owned && !<*mut nativeMultiThreadedScoreLock>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the MultiThreadedScoreLock, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { } +pub extern "C" fn MultiThreadedScoreLock_free(this_obj: MultiThreadedScoreLock) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer); } +pub(crate) extern "C" fn MultiThreadedScoreLock_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLock) }; } #[allow(unused)] -impl FixedPenaltyScorer { - pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer { +impl MultiThreadedScoreLock { + pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedScoreLock { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedScoreLock { unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeFixedPenaltyScorer { + pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedScoreLock { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } } -impl Clone for FixedPenaltyScorer { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeFixedPenaltyScorer>::is_null(self.inner) { core::ptr::null_mut() } else { - ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, - is_owned: true, - } +impl From for crate::lightning::routing::scoring::Score { + fn from(obj: nativeMultiThreadedScoreLock) -> Self { + let mut rust_obj = MultiThreadedScoreLock { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = MultiThreadedScoreLock_as_Score(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = core::ptr::null_mut(); + ret.free = Some(MultiThreadedScoreLock_free_void); + ret } } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void -} +/// Constructs a new Score which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is #[no_mangle] -/// Creates a copy of the FixedPenaltyScorer -pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer { - orig.clone() +pub extern "C" fn MultiThreadedScoreLock_as_Score(this_arg: &MultiThreadedScoreLock) -> crate::lightning::routing::scoring::Score { + crate::lightning::routing::scoring::Score { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + channel_penalty_msat: MultiThreadedScoreLock_Score_channel_penalty_msat, + payment_path_failed: MultiThreadedScoreLock_Score_payment_path_failed, + payment_path_successful: MultiThreadedScoreLock_Score_payment_path_successful, + probe_failed: MultiThreadedScoreLock_Score_probe_failed, + probe_successful: MultiThreadedScoreLock_Score_probe_successful, + write: MultiThreadedScoreLock_write_void, + } } -/// Creates a new scorer using `penalty_msat`. + #[must_use] -#[no_mangle] -pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> FixedPenaltyScorer { - let mut ret = lightning::routing::scoring::FixedPenaltyScorer::with_penalty(penalty_msat); - FixedPenaltyScorer { inner: ObjOps::heap_alloc(ret), is_owned: true } +extern "C" fn MultiThreadedScoreLock_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 { + let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }); + ret +} +extern "C" fn MultiThreadedScoreLock_Score_payment_path_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..], short_channel_id) +} +extern "C" fn MultiThreadedScoreLock_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..]) +} +extern "C" fn MultiThreadedScoreLock_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..], short_channel_id) +} +extern "C" fn MultiThreadedScoreLock_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..]) } -impl From for crate::lightning::routing::scoring::Score { - fn from(obj: nativeFixedPenaltyScorer) -> Self { - let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; - let mut ret = FixedPenaltyScorer_as_Score(&rust_obj); +#[no_mangle] +/// Serialize the MultiThreadedScoreLock object into a byte array which can be read by MultiThreadedScoreLock_read +pub extern "C" fn MultiThreadedScoreLock_write(obj: &crate::lightning::routing::scoring::MultiThreadedScoreLock) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn MultiThreadedScoreLock_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedScoreLock) }) +} +impl From for crate::lightning::routing::scoring::LockableScore { + fn from(obj: nativeMultiThreadedLockableScore) -> Self { + let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = MultiThreadedLockableScore_as_LockableScore(&rust_obj); // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn rust_obj.inner = core::ptr::null_mut(); - ret.free = Some(FixedPenaltyScorer_free_void); + ret.free = Some(MultiThreadedLockableScore_free_void); ret } } -/// Constructs a new Score which calls the relevant methods on this_arg. -/// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is +/// Constructs a new LockableScore which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned LockableScore must be freed before this_arg is #[no_mangle] -pub extern "C" fn FixedPenaltyScorer_as_Score(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::Score { - crate::lightning::routing::scoring::Score { +pub extern "C" fn MultiThreadedLockableScore_as_LockableScore(this_arg: &MultiThreadedLockableScore) -> crate::lightning::routing::scoring::LockableScore { + crate::lightning::routing::scoring::LockableScore { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, - channel_penalty_msat: FixedPenaltyScorer_Score_channel_penalty_msat, - payment_path_failed: FixedPenaltyScorer_Score_payment_path_failed, - payment_path_successful: FixedPenaltyScorer_Score_payment_path_successful, - write: FixedPenaltyScorer_write_void, + lock: MultiThreadedLockableScore_LockableScore_lock, } } #[must_use] -extern "C" fn FixedPenaltyScorer_Score_channel_penalty_msat(this_arg: *const c_void, unused_0: u64, unused_1: u64, unused_2: u64, unused_3: &crate::lightning::routing::network_graph::NodeId, unused_4: &crate::lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, unused_0, unused_1, unused_2, unused_3.get_native_ref(), unused_4.get_native_ref()); - ret -} -extern "C" fn FixedPenaltyScorer_Score_payment_path_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut _short_channel_id: u64) { - let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; - >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..], _short_channel_id) -} -extern "C" fn FixedPenaltyScorer_Score_payment_path_successful(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ) { - let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; - >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..]) +extern "C" fn MultiThreadedLockableScore_LockableScore_lock(this_arg: *const c_void) -> crate::lightning::routing::scoring::Score { + let mut ret = >::lock(unsafe { &mut *(this_arg as *mut nativeMultiThreadedLockableScore) }, ); + Into::into(ret) } #[no_mangle] -/// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read -pub extern "C" fn FixedPenaltyScorer_write(obj: &FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z { +/// Serialize the MultiThreadedLockableScore object into a byte array which can be read by MultiThreadedLockableScore_read +pub extern "C" fn MultiThreadedLockableScore_write(obj: &crate::lightning::routing::scoring::MultiThreadedLockableScore) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] -pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) }) +pub(crate) extern "C" fn MultiThreadedLockableScore_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedLockableScore) }) } +impl From for crate::lightning::routing::scoring::WriteableScore { + fn from(obj: nativeMultiThreadedLockableScore) -> Self { + let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = MultiThreadedLockableScore_as_WriteableScore(&rust_obj); + // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn + rust_obj.inner = core::ptr::null_mut(); + ret.free = Some(MultiThreadedLockableScore_free_void); + ret + } +} +/// Constructs a new WriteableScore which calls the relevant methods on this_arg. +/// This copies the `inner` pointer in this_arg and thus the returned WriteableScore must be freed before this_arg is #[no_mangle] -/// Read a FixedPenaltyScorer from a byte array, created by FixedPenaltyScorer_write -pub extern "C" fn FixedPenaltyScorer_read(ser: crate::c_types::u8slice, arg: u64) -> crate::c_types::derived::CResult_FixedPenaltyScorerDecodeErrorZ { - let arg_conv = arg; - let res: Result = crate::c_types::deserialize_obj_arg(ser, arg_conv); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; - local_res +pub extern "C" fn MultiThreadedLockableScore_as_WriteableScore(this_arg: &MultiThreadedLockableScore) -> crate::lightning::routing::scoring::WriteableScore { + crate::lightning::routing::scoring::WriteableScore { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + LockableScore: crate::lightning::routing::scoring::LockableScore { + this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, + free: None, + lock: MultiThreadedLockableScore_LockableScore_lock, + }, + write: MultiThreadedLockableScore_write_void, + } } -use lightning::routing::scoring::Scorer as nativeScorerImport; -pub(crate) type nativeScorer = nativeScorerImport; -/// [`Score`] implementation that provides reasonable default behavior. -/// -/// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with -/// slightly higher fees are available. Will further penalize channels that fail to relay payments. -/// -/// See [module-level documentation] for usage and [`ScoringParameters`] for customization. -/// -/// # Note -/// -/// Mixing the `no-std` feature between serialization and deserialization results in undefined -/// behavior. -/// -/// [module-level documentation]: crate::routing::scoring +/// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`]. +#[must_use] +#[no_mangle] +pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> crate::lightning::routing::scoring::MultiThreadedLockableScore { + let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score); + crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + + +use lightning::routing::scoring::ChannelUsage as nativeChannelUsageImport; +pub(crate) type nativeChannelUsage = nativeChannelUsageImport; + +/// Proposed use of a channel passed as a parameter to [`Score::channel_penalty_msat`]. #[must_use] #[repr(C)] -pub struct Scorer { +pub struct ChannelUsage { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeScorer, + pub inner: *mut nativeChannelUsage, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -425,50 +529,114 @@ pub struct Scorer { pub is_owned: bool, } -impl Drop for Scorer { +impl Drop for ChannelUsage { fn drop(&mut self) { - if self.is_owned && !<*mut nativeScorer>::is_null(self.inner) { + if self.is_owned && !<*mut nativeChannelUsage>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the Scorer, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the ChannelUsage, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn Scorer_free(this_obj: Scorer) { } +pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn Scorer_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeScorer); } +pub(crate) extern "C" fn ChannelUsage_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUsage) }; } #[allow(unused)] -impl Scorer { - pub(crate) fn get_native_ref(&self) -> &'static nativeScorer { +impl ChannelUsage { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUsage { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScorer { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUsage { unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeScorer { + pub(crate) fn take_inner(mut self) -> *mut nativeChannelUsage { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } } +/// The amount to send through the channel, denominated in millisatoshis. +#[no_mangle] +pub extern "C" fn ChannelUsage_get_amount_msat(this_ptr: &ChannelUsage) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat; + *inner_val +} +/// The amount to send through the channel, denominated in millisatoshis. +#[no_mangle] +pub extern "C" fn ChannelUsage_set_amount_msat(this_ptr: &mut ChannelUsage, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val; +} +/// Total amount, denominated in millisatoshis, already allocated to send through the channel +/// as part of a multi-path payment. +#[no_mangle] +pub extern "C" fn ChannelUsage_get_inflight_htlc_msat(this_ptr: &ChannelUsage) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().inflight_htlc_msat; + *inner_val +} +/// Total amount, denominated in millisatoshis, already allocated to send through the channel +/// as part of a multi-path payment. +#[no_mangle] +pub extern "C" fn ChannelUsage_set_inflight_htlc_msat(this_ptr: &mut ChannelUsage, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inflight_htlc_msat = val; +} +/// The effective capacity of the channel. +#[no_mangle] +pub extern "C" fn ChannelUsage_get_effective_capacity(this_ptr: &ChannelUsage) -> crate::lightning::routing::gossip::EffectiveCapacity { + let mut inner_val = &mut this_ptr.get_native_mut_ref().effective_capacity; + crate::lightning::routing::gossip::EffectiveCapacity::from_native(inner_val) +} +/// The effective capacity of the channel. +#[no_mangle] +pub extern "C" fn ChannelUsage_set_effective_capacity(this_ptr: &mut ChannelUsage, mut val: crate::lightning::routing::gossip::EffectiveCapacity) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.effective_capacity = val.into_native(); +} +/// Constructs a new ChannelUsage given each field +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelUsage_new(mut amount_msat_arg: u64, mut inflight_htlc_msat_arg: u64, mut effective_capacity_arg: crate::lightning::routing::gossip::EffectiveCapacity) -> ChannelUsage { + ChannelUsage { inner: ObjOps::heap_alloc(nativeChannelUsage { + amount_msat: amount_msat_arg, + inflight_htlc_msat: inflight_htlc_msat_arg, + effective_capacity: effective_capacity_arg.into_native(), + }), is_owned: true } +} +impl Clone for ChannelUsage { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelUsage>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelUsage_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUsage)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelUsage +pub extern "C" fn ChannelUsage_clone(orig: &ChannelUsage) -> ChannelUsage { + orig.clone() +} -use lightning::routing::scoring::ScoringParameters as nativeScoringParametersImport; -pub(crate) type nativeScoringParameters = nativeScoringParametersImport; +use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport; +pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport; -/// Parameters for configuring [`Scorer`]. +/// [`Score`] implementation that uses a fixed penalty. #[must_use] #[repr(C)] -pub struct ScoringParameters { +pub struct FixedPenaltyScorer { /// A pointer to the opaque Rust object. /// Nearly everywhere, inner must be non-null, however in places where /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeScoringParameters, + pub inner: *mut nativeFixedPenaltyScorer, /// Indicates that this is the only struct which contains the same pointer. /// Rust functions which take ownership of an object provided via an argument require @@ -476,172 +644,41 @@ pub struct ScoringParameters { pub is_owned: bool, } -impl Drop for ScoringParameters { +impl Drop for FixedPenaltyScorer { fn drop(&mut self) { - if self.is_owned && !<*mut nativeScoringParameters>::is_null(self.inner) { + if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the ScoringParameters, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn ScoringParameters_free(this_obj: ScoringParameters) { } +pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ScoringParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeScoringParameters); } +pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer) }; } #[allow(unused)] -impl ScoringParameters { - pub(crate) fn get_native_ref(&self) -> &'static nativeScoringParameters { +impl FixedPenaltyScorer { + pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeScoringParameters { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer { unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeScoringParameters { + pub(crate) fn take_inner(mut self) -> *mut nativeFixedPenaltyScorer { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } } -/// A fixed penalty in msats to apply to each channel. -/// -/// Default value: 500 msat -#[no_mangle] -pub extern "C" fn ScoringParameters_get_base_penalty_msat(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat; - *inner_val -} -/// A fixed penalty in msats to apply to each channel. -/// -/// Default value: 500 msat -#[no_mangle] -pub extern "C" fn ScoringParameters_set_base_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val; -} -/// A penalty in msats to apply to a channel upon failing to relay a payment. -/// -/// This accumulates for each failure but may be reduced over time based on -/// [`failure_penalty_half_life`] or when successfully routing through a channel. -/// -/// Default value: 1,024,000 msat -/// -/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life -#[no_mangle] -pub extern "C" fn ScoringParameters_get_failure_penalty_msat(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_msat; - *inner_val -} -/// A penalty in msats to apply to a channel upon failing to relay a payment. -/// -/// This accumulates for each failure but may be reduced over time based on -/// [`failure_penalty_half_life`] or when successfully routing through a channel. -/// -/// Default value: 1,024,000 msat -/// -/// [`failure_penalty_half_life`]: Self::failure_penalty_half_life -#[no_mangle] -pub extern "C" fn ScoringParameters_set_failure_penalty_msat(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_msat = val; -} -/// When the amount being sent over a channel is this many 1024ths of the total channel -/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. -/// -/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) -/// -/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th -#[no_mangle] -pub extern "C" fn ScoringParameters_get_overuse_penalty_start_1024th(this_ptr: &ScoringParameters) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_start_1024th; - *inner_val -} -/// When the amount being sent over a channel is this many 1024ths of the total channel -/// capacity, we begin applying [`overuse_penalty_msat_per_1024th`]. -/// -/// Default value: 128 1024ths (i.e. begin penalizing when an HTLC uses 1/8th of a channel) -/// -/// [`overuse_penalty_msat_per_1024th`]: Self::overuse_penalty_msat_per_1024th -#[no_mangle] -pub extern "C" fn ScoringParameters_set_overuse_penalty_start_1024th(this_ptr: &mut ScoringParameters, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_start_1024th = val; -} -/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent -/// over the channel exceeds [`overuse_penalty_start_1024th`] by. -/// -/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty -/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) -/// -/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th -#[no_mangle] -pub extern "C" fn ScoringParameters_get_overuse_penalty_msat_per_1024th(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().overuse_penalty_msat_per_1024th; - *inner_val -} -/// A penalty applied, per whole 1024ths of the channel capacity which the amount being sent -/// over the channel exceeds [`overuse_penalty_start_1024th`] by. -/// -/// Default value: 20 msat (i.e. 2560 msat penalty to use 1/4th of a channel, 7680 msat penalty -/// to use half a channel, and 12,560 msat penalty to use 3/4ths of a channel) -/// -/// [`overuse_penalty_start_1024th`]: Self::overuse_penalty_start_1024th -#[no_mangle] -pub extern "C" fn ScoringParameters_set_overuse_penalty_msat_per_1024th(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.overuse_penalty_msat_per_1024th = val; -} -/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are -/// cut in half. -/// -/// Successfully routing through a channel will immediately cut the penalty in half as well. -/// -/// Default value: 1 hour -/// -/// # Note -/// -/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will -/// never decay. -/// -/// [`failure_penalty_msat`]: Self::failure_penalty_msat -#[no_mangle] -pub extern "C" fn ScoringParameters_get_failure_penalty_half_life(this_ptr: &ScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().failure_penalty_half_life; - inner_val.as_secs() -} -/// The time required to elapse before any accumulated [`failure_penalty_msat`] penalties are -/// cut in half. -/// -/// Successfully routing through a channel will immediately cut the penalty in half as well. -/// -/// Default value: 1 hour -/// -/// # Note -/// -/// When built with the `no-std` feature, time will never elapse. Therefore, this penalty will -/// never decay. -/// -/// [`failure_penalty_msat`]: Self::failure_penalty_msat -#[no_mangle] -pub extern "C" fn ScoringParameters_set_failure_penalty_half_life(this_ptr: &mut ScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.failure_penalty_half_life = core::time::Duration::from_secs(val); -} -/// Constructs a new ScoringParameters given each field -#[must_use] -#[no_mangle] -pub extern "C" fn ScoringParameters_new(mut base_penalty_msat_arg: u64, mut failure_penalty_msat_arg: u64, mut overuse_penalty_start_1024th_arg: u16, mut overuse_penalty_msat_per_1024th_arg: u64, mut failure_penalty_half_life_arg: u64) -> ScoringParameters { - ScoringParameters { inner: ObjOps::heap_alloc(nativeScoringParameters { - base_penalty_msat: base_penalty_msat_arg, - failure_penalty_msat: failure_penalty_msat_arg, - overuse_penalty_start_1024th: overuse_penalty_start_1024th_arg, - overuse_penalty_msat_per_1024th: overuse_penalty_msat_per_1024th_arg, - failure_penalty_half_life: core::time::Duration::from_secs(failure_penalty_half_life_arg), - }), is_owned: true } -} -impl Clone for ScoringParameters { +impl Clone for FixedPenaltyScorer { fn clone(&self) -> Self { Self { - inner: if <*mut nativeScoringParameters>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeFixedPenaltyScorer>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -649,123 +686,115 @@ impl Clone for ScoringParameters { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ScoringParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeScoringParameters)).clone() })) as *mut c_void +pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the ScoringParameters -pub extern "C" fn ScoringParameters_clone(orig: &ScoringParameters) -> ScoringParameters { +/// Creates a copy of the FixedPenaltyScorer +pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer { orig.clone() } -#[no_mangle] -/// Serialize the ScoringParameters object into a byte array which can be read by ScoringParameters_read -pub extern "C" fn ScoringParameters_write(obj: &ScoringParameters) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn ScoringParameters_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScoringParameters) }) -} -#[no_mangle] -/// Read a ScoringParameters from a byte array, created by ScoringParameters_write -pub extern "C" fn ScoringParameters_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScoringParametersDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ScoringParameters { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; - local_res -} -/// Creates a new scorer using the given scoring parameters. +/// Creates a new scorer using `penalty_msat`. #[must_use] #[no_mangle] -pub extern "C" fn Scorer_new(mut params: crate::lightning::routing::scoring::ScoringParameters) -> Scorer { - let mut ret = lightning::routing::scoring::Scorer::new(*unsafe { Box::from_raw(params.take_inner()) }); - Scorer { inner: ObjOps::heap_alloc(ret), is_owned: true } +pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> crate::lightning::routing::scoring::FixedPenaltyScorer { + let mut ret = lightning::routing::scoring::FixedPenaltyScorer::with_penalty(penalty_msat); + crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Creates a "default" Scorer. See struct and individual field documentaiton for details on which values are used. -#[must_use] -#[no_mangle] -pub extern "C" fn Scorer_default() -> Scorer { - Scorer { inner: ObjOps::heap_alloc(Default::default()), is_owned: true } -} -/// Creates a "default" ScoringParameters. See struct and individual field documentaiton for details on which values are used. -#[must_use] -#[no_mangle] -pub extern "C" fn ScoringParameters_default() -> ScoringParameters { - ScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true } -} -impl From for crate::lightning::routing::scoring::Score { - fn from(obj: nativeScorer) -> Self { - let mut rust_obj = Scorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; - let mut ret = Scorer_as_Score(&rust_obj); +impl From for crate::lightning::routing::scoring::Score { + fn from(obj: nativeFixedPenaltyScorer) -> Self { + let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true }; + let mut ret = FixedPenaltyScorer_as_Score(&rust_obj); // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn rust_obj.inner = core::ptr::null_mut(); - ret.free = Some(Scorer_free_void); + ret.free = Some(FixedPenaltyScorer_free_void); ret } } /// Constructs a new Score which calls the relevant methods on this_arg. /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is #[no_mangle] -pub extern "C" fn Scorer_as_Score(this_arg: &Scorer) -> crate::lightning::routing::scoring::Score { +pub extern "C" fn FixedPenaltyScorer_as_Score(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::Score { crate::lightning::routing::scoring::Score { this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void }, free: None, - channel_penalty_msat: Scorer_Score_channel_penalty_msat, - payment_path_failed: Scorer_Score_payment_path_failed, - payment_path_successful: Scorer_Score_payment_path_successful, - write: Scorer_write_void, + channel_penalty_msat: FixedPenaltyScorer_Score_channel_penalty_msat, + payment_path_failed: FixedPenaltyScorer_Score_payment_path_failed, + payment_path_successful: FixedPenaltyScorer_Score_payment_path_successful, + probe_failed: FixedPenaltyScorer_Score_probe_failed, + probe_successful: FixedPenaltyScorer_Score_probe_successful, + write: FixedPenaltyScorer_write_void, } } #[must_use] -extern "C" fn Scorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, mut send_amt_msat: u64, mut capacity_msat: u64, _source: &crate::lightning::routing::network_graph::NodeId, _target: &crate::lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeScorer) }, short_channel_id, send_amt_msat, capacity_msat, _source.get_native_ref(), _target.get_native_ref()); +extern "C" fn FixedPenaltyScorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 { + let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }); ret } -extern "C" fn Scorer_Score_payment_path_failed(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { - let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); }; - >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local__path[..], short_channel_id) +extern "C" fn FixedPenaltyScorer_Score_payment_path_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..], short_channel_id) +} +extern "C" fn FixedPenaltyScorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..]) } -extern "C" fn Scorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { +extern "C" fn FixedPenaltyScorer_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; - >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeScorer) }, &local_path[..]) + >::probe_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..], short_channel_id) +} +extern "C" fn FixedPenaltyScorer_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..]) } #[no_mangle] -/// Serialize the Scorer object into a byte array which can be read by Scorer_read -pub extern "C" fn Scorer_write(obj: &Scorer) -> crate::c_types::derived::CVec_u8Z { +/// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read +pub extern "C" fn FixedPenaltyScorer_write(obj: &crate::lightning::routing::scoring::FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] -pub(crate) extern "C" fn Scorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeScorer) }) +pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) }) } #[no_mangle] -/// Read a Scorer from a byte array, created by Scorer_write -pub extern "C" fn Scorer_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ScorerDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::Scorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; +/// Read a FixedPenaltyScorer from a byte array, created by FixedPenaltyScorer_write +pub extern "C" fn FixedPenaltyScorer_read(ser: crate::c_types::u8slice, arg: u64) -> crate::c_types::derived::CResult_FixedPenaltyScorerDecodeErrorZ { + let arg_conv = arg; + let res: Result = crate::c_types::deserialize_obj_arg(ser, arg_conv); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } use lightning::routing::scoring::ProbabilisticScorer as nativeProbabilisticScorerImport; -pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'static lightning::routing::network_graph::NetworkGraph>; +pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'static lightning::routing::gossip::NetworkGraph, crate::lightning::util::logger::Logger>; /// [`Score`] implementation using channel success probability distributions. /// -/// Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt -/// and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability -/// distributions are defined based on knowledge learned from successful and unsuccessful attempts. -/// Then the negative `log10` of the success probability is used to determine the cost of routing a -/// specific HTLC amount through a channel. +/// Channels are tracked with upper and lower liquidity bounds - when an HTLC fails at a channel, +/// we learn that the upper-bound on the available liquidity is lower than the amount of the HTLC. +/// When a payment is forwarded through a channel (but fails later in the route), we learn the +/// lower-bound on the channel's available liquidity must be at least the value of the HTLC. +/// +/// These bounds are then used to determine a success probability using the formula from +/// *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt +/// and Stefan Richter [[1]] (i.e. `(upper_bound - payment_amount) / (upper_bound - lower_bound)`). +/// +/// This probability is combined with the [`liquidity_penalty_multiplier_msat`] and +/// [`liquidity_penalty_amount_multiplier_msat`] parameters to calculate a concrete penalty in +/// milli-satoshis. The penalties, when added across all hops, have the property of being linear in +/// terms of the entire path's success probability. This allows the router to directly compare +/// penalties for different paths. See the documentation of those parameters for the exact formulas. /// -/// Knowledge about channel liquidity balances takes the form of upper and lower bounds on the -/// possible liquidity. Certainty of the bounds is decreased over time using a decay function. See -/// [`ProbabilisticScoringParameters`] for details. +/// The liquidity bounds are decayed by halving them every [`liquidity_offset_half_life`]. /// -/// Since the scorer aims to learn the current channel liquidity balances, it works best for nodes -/// with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment -/// volume are more likely to experience failed payment paths, which would need to be retried. +/// Further, we track the history of our upper and lower liquidity bounds for each channel, +/// allowing us to assign a second penalty (using [`historical_liquidity_penalty_multiplier_msat`] +/// and [`historical_liquidity_penalty_amount_multiplier_msat`]) based on the same probability +/// formula, but using the history of a channel rather than our latest estimates for the liquidity +/// bounds. /// /// # Note /// @@ -773,6 +802,11 @@ pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'st /// behavior. /// /// [1]: https://arxiv.org/abs/2107.05322 +/// [`liquidity_penalty_multiplier_msat`]: ProbabilisticScoringParameters::liquidity_penalty_multiplier_msat +/// [`liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringParameters::liquidity_penalty_amount_multiplier_msat +/// [`liquidity_offset_half_life`]: ProbabilisticScoringParameters::liquidity_offset_half_life +/// [`historical_liquidity_penalty_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_multiplier_msat +/// [`historical_liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringParameters::historical_liquidity_penalty_amount_multiplier_msat #[must_use] #[repr(C)] pub struct ProbabilisticScorer { @@ -801,7 +835,7 @@ pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScorer_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScorer); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScorer) }; } #[allow(unused)] impl ProbabilisticScorer { @@ -827,6 +861,9 @@ pub(crate) type nativeProbabilisticScoringParameters = nativeProbabilisticScorin /// /// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel). +/// +/// The penalty applied to any channel by the [`ProbabilisticScorer`] is the sum of each of the +/// parameters here. #[must_use] #[repr(C)] pub struct ProbabilisticScoringParameters { @@ -855,7 +892,7 @@ pub extern "C" fn ProbabilisticScoringParameters_free(this_obj: ProbabilisticSco #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScoringParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters) }; } #[allow(unused)] impl ProbabilisticScoringParameters { @@ -888,8 +925,42 @@ pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_msat(this_ptr: pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val; } +/// A multiplier used with the payment amount to calculate a fixed penalty applied to each +/// channel, in excess of the [`base_penalty_msat`]. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., +/// fees plus penalty) for large payments. The penalty is computed as the product of this +/// multiplier and `2^30`ths of the payment amount. +/// +/// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` +/// +/// Default value: 8,192 msat +/// +/// [`base_penalty_msat`]: Self::base_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_amount_multiplier_msat; + *inner_val +} +/// A multiplier used with the payment amount to calculate a fixed penalty applied to each +/// channel, in excess of the [`base_penalty_msat`]. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., +/// fees plus penalty) for large payments. The penalty is computed as the product of this +/// multiplier and `2^30`ths of the payment amount. +/// +/// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30` +/// +/// Default value: 8,192 msat +/// +/// [`base_penalty_msat`]: Self::base_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_amount_multiplier_msat = val; +} /// A multiplier used in conjunction with the negative `log10` of the channel's success -/// probability for a payment to determine the liquidity penalty. +/// probability for a payment, as determined by our latest estimates of the channel's +/// liquidity, to determine the liquidity penalty. /// /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The @@ -898,7 +969,9 @@ pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_msat(this_ptr: /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will /// result in a `u64::max_value` penalty, however. /// -/// Default value: 40,000 msat +/// `-log10(success_probability) * liquidity_penalty_multiplier_msat` +/// +/// Default value: 30,000 msat /// /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life #[no_mangle] @@ -907,7 +980,8 @@ pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_multiplie *inner_val } /// A multiplier used in conjunction with the negative `log10` of the channel's success -/// probability for a payment to determine the liquidity penalty. +/// probability for a payment, as determined by our latest estimates of the channel's +/// liquidity, to determine the liquidity penalty. /// /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The @@ -916,21 +990,29 @@ pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_multiplie /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will /// result in a `u64::max_value` penalty, however. /// -/// Default value: 40,000 msat +/// `-log10(success_probability) * liquidity_penalty_multiplier_msat` +/// +/// Default value: 30,000 msat /// /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life #[no_mangle] pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_multiplier_msat = val; } -/// The time required to elapse before any knowledge learned about channel liquidity balances is -/// cut in half. +/// Whenever this amount of time elapses since the last update to a channel's liquidity bounds, +/// the distance from the bounds to \"zero\" is cut in half. In other words, the lower-bound on +/// the available liquidity is halved and the upper-bound moves half-way to the channel's total +/// capacity. /// -/// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets -/// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases -/// the certainty of the channel liquidity balance. +/// Because halving the liquidity bounds grows the uncertainty on the channel's liquidity, +/// the penalty for an amount within the new bounds may change. See the [`ProbabilisticScorer`] +/// struct documentation for more info on the way the liquidity bounds are used. /// -/// Default value: 1 hour +/// For example, if the channel's capacity is 1 million sats, and the current upper and lower +/// liquidity bounds are 200,000 sats and 600,000 sats, after this amount of time the upper +/// and lower liquidity bounds will be decayed to 100,000 and 800,000 sats. +/// +/// Default value: 6 hours /// /// # Note /// @@ -941,14 +1023,20 @@ pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_offset_half_life( let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_offset_half_life; inner_val.as_secs() } -/// The time required to elapse before any knowledge learned about channel liquidity balances is -/// cut in half. +/// Whenever this amount of time elapses since the last update to a channel's liquidity bounds, +/// the distance from the bounds to \"zero\" is cut in half. In other words, the lower-bound on +/// the available liquidity is halved and the upper-bound moves half-way to the channel's total +/// capacity. +/// +/// Because halving the liquidity bounds grows the uncertainty on the channel's liquidity, +/// the penalty for an amount within the new bounds may change. See the [`ProbabilisticScorer`] +/// struct documentation for more info on the way the liquidity bounds are used. /// -/// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets -/// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases -/// the certainty of the channel liquidity balance. +/// For example, if the channel's capacity is 1 million sats, and the current upper and lower +/// liquidity bounds are 200,000 sats and 600,000 sats, after this amount of time the upper +/// and lower liquidity bounds will be decayed to 100,000 and 800,000 sats. /// -/// Default value: 1 hour +/// Default value: 6 hours /// /// # Note /// @@ -959,14 +1047,15 @@ pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life( unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_offset_half_life = core::time::Duration::from_secs(val); } /// A multiplier used in conjunction with a payment amount and the negative `log10` of the -/// channel's success probability for the payment to determine the amount penalty. +/// channel's success probability for the payment, as determined by our latest estimates of the +/// channel's liquidity, to determine the amount penalty. /// /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., /// fees plus penalty) for large payments. The penalty is computed as the product of this /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the /// success probability. /// -/// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` +/// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` /// /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of /// the amount will result in a penalty of the multiplier. And, as the success probability @@ -974,21 +1063,22 @@ pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life( /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will /// fall below `1`. /// -/// Default value: 256 msat +/// Default value: 192 msat #[no_mangle] -pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_penalty_multiplier_msat; +pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_amount_multiplier_msat; *inner_val } /// A multiplier used in conjunction with a payment amount and the negative `log10` of the -/// channel's success probability for the payment to determine the amount penalty. +/// channel's success probability for the payment, as determined by our latest estimates of the +/// channel's liquidity, to determine the amount penalty. /// /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e., /// fees plus penalty) for large payments. The penalty is computed as the product of this /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the /// success probability. /// -/// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20` +/// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20` /// /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of /// the amount will result in a penalty of the multiplier. And, as the success probability @@ -996,21 +1086,181 @@ pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_m /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will /// fall below `1`. /// -/// Default value: 256 msat +/// Default value: 192 msat #[no_mangle] -pub extern "C" fn ProbabilisticScoringParameters_set_amount_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_penalty_multiplier_msat = val; +pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_amount_multiplier_msat = val; } -/// Constructs a new ProbabilisticScoringParameters given each field -#[must_use] +/// A multiplier used in conjunction with the negative `log10` of the channel's success +/// probability for the payment, as determined based on the history of our estimates of the +/// channel's available liquidity, to determine a penalty. +/// +/// This penalty is similar to [`liquidity_penalty_multiplier_msat`], however, instead of using +/// only our latest estimate for the current liquidity available in the channel, it estimates +/// success probability based on the estimated liquidity available in the channel through +/// history. Specifically, every time we update our liquidity bounds on a given channel, we +/// track which of several buckets those bounds fall into, exponentially decaying the +/// probability of each bucket as new samples are added. +/// +/// Default value: 10,000 msat +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat #[no_mangle] -pub extern "C" fn ProbabilisticScoringParameters_new(mut base_penalty_msat_arg: u64, mut liquidity_penalty_multiplier_msat_arg: u64, mut liquidity_offset_half_life_arg: u64, mut amount_penalty_multiplier_msat_arg: u64) -> ProbabilisticScoringParameters { - ProbabilisticScoringParameters { inner: ObjOps::heap_alloc(nativeProbabilisticScoringParameters { - base_penalty_msat: base_penalty_msat_arg, - liquidity_penalty_multiplier_msat: liquidity_penalty_multiplier_msat_arg, - liquidity_offset_half_life: core::time::Duration::from_secs(liquidity_offset_half_life_arg), - amount_penalty_multiplier_msat: amount_penalty_multiplier_msat_arg, - }), is_owned: true } +pub extern "C" fn ProbabilisticScoringParameters_get_historical_liquidity_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_liquidity_penalty_multiplier_msat; + *inner_val +} +/// A multiplier used in conjunction with the negative `log10` of the channel's success +/// probability for the payment, as determined based on the history of our estimates of the +/// channel's available liquidity, to determine a penalty. +/// +/// This penalty is similar to [`liquidity_penalty_multiplier_msat`], however, instead of using +/// only our latest estimate for the current liquidity available in the channel, it estimates +/// success probability based on the estimated liquidity available in the channel through +/// history. Specifically, every time we update our liquidity bounds on a given channel, we +/// track which of several buckets those bounds fall into, exponentially decaying the +/// probability of each bucket as new samples are added. +/// +/// Default value: 10,000 msat +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_historical_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_liquidity_penalty_multiplier_msat = val; +} +/// A multiplier used in conjunction with the payment amount and the negative `log10` of the +/// channel's success probability for the payment, as determined based on the history of our +/// estimates of the channel's available liquidity, to determine a penalty. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost for +/// large payments. The penalty is computed as the product of this multiplier and the `2^20`ths +/// of the payment amount, weighted by the negative `log10` of the success probability. +/// +/// This penalty is similar to [`liquidity_penalty_amount_multiplier_msat`], however, instead +/// of using only our latest estimate for the current liquidity available in the channel, it +/// estimates success probability based on the estimated liquidity available in the channel +/// through history. Specifically, every time we update our liquidity bounds on a given +/// channel, we track which of several buckets those bounds fall into, exponentially decaying +/// the probability of each bucket as new samples are added. +/// +/// Default value: 64 msat +/// +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_historical_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_liquidity_penalty_amount_multiplier_msat; + *inner_val +} +/// A multiplier used in conjunction with the payment amount and the negative `log10` of the +/// channel's success probability for the payment, as determined based on the history of our +/// estimates of the channel's available liquidity, to determine a penalty. +/// +/// The purpose of the amount penalty is to avoid having fees dominate the channel cost for +/// large payments. The penalty is computed as the product of this multiplier and the `2^20`ths +/// of the payment amount, weighted by the negative `log10` of the success probability. +/// +/// This penalty is similar to [`liquidity_penalty_amount_multiplier_msat`], however, instead +/// of using only our latest estimate for the current liquidity available in the channel, it +/// estimates success probability based on the estimated liquidity available in the channel +/// through history. Specifically, every time we update our liquidity bounds on a given +/// channel, we track which of several buckets those bounds fall into, exponentially decaying +/// the probability of each bucket as new samples are added. +/// +/// Default value: 64 msat +/// +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_historical_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_liquidity_penalty_amount_multiplier_msat = val; +} +/// If we aren't learning any new datapoints for a channel, the historical liquidity bounds +/// tracking can simply live on with increasingly stale data. Instead, when a channel has not +/// seen a liquidity estimate update for this amount of time, the historical datapoints are +/// decayed by half. +/// +/// Note that after 16 or more half lives all historical data will be completely gone. +/// +/// Default value: 14 days +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_historical_no_updates_half_life(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_no_updates_half_life; + inner_val.as_secs() +} +/// If we aren't learning any new datapoints for a channel, the historical liquidity bounds +/// tracking can simply live on with increasingly stale data. Instead, when a channel has not +/// seen a liquidity estimate update for this amount of time, the historical datapoints are +/// decayed by half. +/// +/// Note that after 16 or more half lives all historical data will be completely gone. +/// +/// Default value: 14 days +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_historical_no_updates_half_life(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_no_updates_half_life = core::time::Duration::from_secs(val); +} +/// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the +/// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We +/// treat such nodes preferentially as this makes balance discovery attacks harder to execute, +/// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy. +/// +/// Default value: 250 msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_anti_probing_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().anti_probing_penalty_msat; + *inner_val +} +/// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the +/// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We +/// treat such nodes preferentially as this makes balance discovery attacks harder to execute, +/// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy. +/// +/// Default value: 250 msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_anti_probing_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.anti_probing_penalty_msat = val; +} +/// This penalty is applied when the amount we're attempting to send over a channel exceeds our +/// current estimate of the channel's available liquidity. +/// +/// Note that in this case all other penalties, including the +/// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based +/// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if +/// applicable, are still included in the overall penalty. +/// +/// If you wish to avoid creating paths with such channels entirely, setting this to a value of +/// `u64::max_value()` will guarantee that. +/// +/// Default value: 1_0000_0000_000 msat (1 Bitcoin) +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +/// [`base_penalty_msat`]: Self::base_penalty_msat +/// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_get_considered_impossible_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().considered_impossible_penalty_msat; + *inner_val +} +/// This penalty is applied when the amount we're attempting to send over a channel exceeds our +/// current estimate of the channel's available liquidity. +/// +/// Note that in this case all other penalties, including the +/// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based +/// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if +/// applicable, are still included in the overall penalty. +/// +/// If you wish to avoid creating paths with such channels entirely, setting this to a value of +/// `u64::max_value()` will guarantee that. +/// +/// Default value: 1_0000_0000_000 msat (1 Bitcoin) +/// +/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat +/// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat +/// [`base_penalty_msat`]: Self::base_penalty_msat +/// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_set_considered_impossible_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.considered_impossible_penalty_msat = val; } impl Clone for ProbabilisticScoringParameters { fn clone(&self) -> Self { @@ -1035,9 +1285,96 @@ pub extern "C" fn ProbabilisticScoringParameters_clone(orig: &ProbabilisticScori /// through a network graph. #[must_use] #[no_mangle] -pub extern "C" fn ProbabilisticScorer_new(mut params: crate::lightning::routing::scoring::ProbabilisticScoringParameters, network_graph: &crate::lightning::routing::network_graph::NetworkGraph) -> ProbabilisticScorer { - let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(params.take_inner()) }, network_graph.get_native_ref()); - ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true } +pub extern "C" fn ProbabilisticScorer_new(mut params: crate::lightning::routing::scoring::ProbabilisticScoringParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::scoring::ProbabilisticScorer { + let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(params.take_inner()) }, network_graph.get_native_ref(), logger); + crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true } +} + +/// 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. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_debug_log_liquidity_stats(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer) { + unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.debug_log_liquidity_stats() +} + +/// Query the estimated minimum and maximum liquidity available for sending a payment over the +/// channel with `scid` towards the given `target` node. +#[must_use] +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_estimated_channel_liquidity_range(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer, mut scid: u64, target: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::COption_C2Tuple_u64u64ZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.estimated_channel_liquidity_range(scid, target.get_native_ref()); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C2Tuple_u64u64ZZ::None } else { crate::c_types::derived::COption_C2Tuple_u64u64ZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (ret.unwrap()); let mut local_ret_0 = (orig_ret_0_0, orig_ret_0_1).into(); local_ret_0 }) }; + local_ret +} + +/// Query the historical estimated minimum and maximum liquidity available for sending a +/// payment over the channel with `scid` towards the given `target` node. +/// +/// Returns two sets of 8 buckets. The first set describes the octiles for lower-bound +/// liquidity estimates, the second set describes the octiles for upper-bound liquidity +/// estimates. Each bucket describes the relative frequency at which we've seen a liquidity +/// bound in the octile relative to the channel's total capacity, on an arbitrary scale. +/// Because the values are slowly decayed, more recent data points are weighted more heavily +/// than older datapoints. +/// +/// When scoring, the estimated probability that an upper-/lower-bound lies in a given octile +/// relative to the channel's total capacity is calculated by dividing that bucket's value with +/// the total of all buckets for the given bound. +/// +/// For example, a value of `[0, 0, 0, 0, 0, 0, 32]` indicates that we believe the probability +/// of a bound being in the top octile to be 100%, and have never (recently) seen it in any +/// other octiles. A value of `[31, 0, 0, 0, 0, 0, 0, 32]` indicates we've seen the bound being +/// both in the top and bottom octile, and roughly with similar (recent) frequency. +/// +/// Because the datapoints are decayed slowly over time, values will eventually return to +/// `Some(([0; 8], [0; 8]))`. +#[must_use] +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_historical_estimated_channel_liquidity_probabilities(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer, mut scid: u64, target: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.historical_estimated_channel_liquidity_probabilities(scid, target.get_native_ref()); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ::None } else { crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (ret.unwrap()); let mut local_ret_0 = (crate::c_types::EightU16s { data: orig_ret_0_0 }, crate::c_types::EightU16s { data: orig_ret_0_1 }).into(); local_ret_0 }) }; + local_ret +} + +/// Marks the node with the given `node_id` as banned, i.e., +/// it will be avoided during path finding. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_add_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.add_banned(node_id.get_native_ref()) +} + +/// Removes the node with the given `node_id` from the list of nodes to avoid. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_remove_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_banned(node_id.get_native_ref()) +} + +/// Sets a manual penalty for the given node. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_set_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId, mut penalty: u64) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.set_manual_penalty(node_id.get_native_ref(), penalty) +} + +/// Removes the node with the given `node_id` from the list of manual penalties. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_remove_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_manual_penalty(node_id.get_native_ref()) +} + +/// Clears the list of manual penalties that are applied during path finding. +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_clear_manual_penalties(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer) { + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.clear_manual_penalties() +} + +/// Marks all nodes in the given list as banned, i.e., +/// they will be avoided during path finding. +#[no_mangle] +pub extern "C" fn ProbabilisticScoringParameters_add_banned_from_list(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringParameters, mut node_ids: crate::c_types::derived::CVec_NodeIdZ) { + let mut local_node_ids = Vec::new(); for mut item in node_ids.into_rust().drain(..) { local_node_ids.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringParameters)) }.add_banned_from_list(local_node_ids) } /// Creates a "default" ProbabilisticScoringParameters. See struct and individual field documentaiton for details on which values are used. @@ -1066,13 +1403,15 @@ pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) - channel_penalty_msat: ProbabilisticScorer_Score_channel_penalty_msat, payment_path_failed: ProbabilisticScorer_Score_payment_path_failed, payment_path_successful: ProbabilisticScorer_Score_payment_path_successful, + probe_failed: ProbabilisticScorer_Score_probe_failed, + probe_successful: ProbabilisticScorer_Score_probe_successful, write: ProbabilisticScorer_write_void, } } #[must_use] -extern "C" fn ProbabilisticScorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, mut amount_msat: u64, mut capacity_msat: u64, source: &crate::lightning::routing::network_graph::NodeId, target: &crate::lightning::routing::network_graph::NodeId) -> u64 { - let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, short_channel_id, amount_msat, capacity_msat, source.get_native_ref(), target.get_native_ref()); +extern "C" fn ProbabilisticScorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 { + let mut ret = >::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }); ret } extern "C" fn ProbabilisticScorer_Score_payment_path_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { @@ -1083,6 +1422,14 @@ extern "C" fn ProbabilisticScorer_Score_payment_path_successful(this_arg: *mut c let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; >::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..]) } +extern "C" fn ProbabilisticScorer_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id) +} +extern "C" fn ProbabilisticScorer_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) { + let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); }; + >::probe_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..]) +} mod approx { @@ -1097,7 +1444,7 @@ use alloc::{vec::Vec, boxed::Box}; } #[no_mangle] /// Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read -pub extern "C" fn ProbabilisticScorer_write(obj: &ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z { +pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] @@ -1106,22 +1453,12 @@ pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> c } #[no_mangle] /// Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write -pub extern "C" fn ProbabilisticScorer_read(ser: crate::c_types::u8slice, arg_a: crate::lightning::routing::scoring::ProbabilisticScoringParameters, arg_b: &crate::lightning::routing::network_graph::NetworkGraph) -> crate::c_types::derived::CResult_ProbabilisticScorerDecodeErrorZ { +pub extern "C" fn ProbabilisticScorer_read(ser: crate::c_types::u8slice, arg_a: crate::lightning::routing::scoring::ProbabilisticScoringParameters, arg_b: &crate::lightning::routing::gossip::NetworkGraph, arg_c: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_ProbabilisticScorerDecodeErrorZ { let arg_a_conv = *unsafe { Box::from_raw(arg_a.take_inner()) }; let arg_b_conv = arg_b.get_native_ref(); - let arg_conv = (arg_a_conv, arg_b_conv); - let res: Result, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let arg_c_conv = arg_c; + let arg_conv = (arg_a_conv, arg_b_conv, arg_c_conv); + let res: Result, crate::lightning::util::logger::Logger>, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } -mod time { - -use alloc::str::FromStr; -use core::ffi::c_void; -use core::convert::Infallible; -use bitcoin::hashes::Hash; -use crate::c_types::*; -#[cfg(feature="no-std")] -use alloc::{vec::Vec, boxed::Box}; - -}