1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Utilities for scoring payment channels.
11 //! [`ProbabilisticScorer`] may be given to [`find_route`] to score payment channels during path
12 //! finding when a custom [`Score`] implementation is not needed.
17 //! # extern crate bitcoin;
19 //! # use lightning::routing::gossip::NetworkGraph;
20 //! # use lightning::routing::router::{RouteParameters, find_route};
21 //! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
22 //! # use lightning::chain::keysinterface::{KeysManager, KeysInterface};
23 //! # use lightning::util::logger::{Logger, Record};
24 //! # use bitcoin::secp256k1::PublicKey;
26 //! # struct FakeLogger {};
27 //! # impl Logger for FakeLogger {
28 //! # fn log(&self, record: &Record) { unimplemented!() }
30 //! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph<&FakeLogger>) {
31 //! # let logger = FakeLogger {};
33 //! // Use the default channel penalties.
34 //! let params = ProbabilisticScoringParameters::default();
35 //! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
37 //! // Or use custom channel penalties.
38 //! let params = ProbabilisticScoringParameters {
39 //! liquidity_penalty_multiplier_msat: 2 * 1000,
40 //! ..ProbabilisticScoringParameters::default()
42 //! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
43 //! # let random_seed_bytes = [42u8; 32];
45 //! let route = find_route(&payer, &route_params, &network_graph, None, &logger, &scorer, &random_seed_bytes);
51 //! Persisting when built with feature `no-std` and restoring without it, or vice versa, uses
52 //! different types and thus is undefined.
54 //! [`find_route`]: crate::routing::router::find_route
56 use alloc::str::FromStr;
57 use core::ffi::c_void;
58 use core::convert::Infallible;
59 use bitcoin::hashes::Hash;
60 use crate::c_types::*;
61 #[cfg(feature="no-std")]
62 use alloc::{vec::Vec, boxed::Box};
64 /// An interface used to score payment channels for path finding.
66 ///\tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
69 /// An opaque pointer which is passed to your function implementations as an argument.
70 /// This has no meaning in the LDK, and can be NULL or any other value.
71 pub this_arg: *mut c_void,
72 /// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
73 /// given channel in the direction from `source` to `target`.
75 /// The channel's capacity (less any other MPP parts that are also being considered for use in
76 /// the same payment) is given by `capacity_msat`. It may be determined from various sources
77 /// such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
78 /// [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
79 /// Thus, implementations should be overflow-safe.
81 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,
82 /// Handles updating channel penalties after failing to route through a channel.
83 pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64),
84 /// Handles updating channel penalties after successfully routing along a path.
85 pub payment_path_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ),
86 /// Serialize the object into a byte array
87 pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
88 /// Frees any resources associated with this object given its this_arg pointer.
89 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
90 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
92 unsafe impl Send for Score {}
93 unsafe impl Sync for Score {}
95 pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score {
97 this_arg: orig.this_arg,
98 channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat),
99 payment_path_failed: Clone::clone(&orig.payment_path_failed),
100 payment_path_successful: Clone::clone(&orig.payment_path_successful),
101 write: Clone::clone(&orig.write),
102 free: Clone::clone(&orig.free),
105 impl lightning::util::ser::Writeable for Score {
106 fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
107 let vec = (self.write)(self.this_arg);
108 w.write_all(vec.as_slice())
112 use lightning::routing::scoring::Score as rustScore;
113 impl rustScore for Score {
114 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 {
115 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 });
118 fn payment_path_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) {
119 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 } }); };
120 (self.payment_path_failed)(self.this_arg, local_path.into(), short_channel_id)
122 fn payment_path_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) {
123 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 } }); };
124 (self.payment_path_successful)(self.this_arg, local_path.into())
128 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
129 // directly as a Deref trait in higher-level structs:
130 impl core::ops::Deref for Score {
132 fn deref(&self) -> &Self {
136 /// Calls the free function if one is set
138 pub extern "C" fn Score_free(this_ptr: Score) { }
139 impl Drop for Score {
141 if let Some(f) = self.free {
146 /// A scorer that is accessed under a lock.
148 /// Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while
149 /// having shared ownership of a scorer but without requiring internal locking in [`Score`]
150 /// implementations. Internal locking would be detrimental to route finding performance and could
151 /// result in [`Score::channel_penalty_msat`] returning a different value for the same channel.
153 /// [`find_route`]: crate::routing::router::find_route
155 pub struct LockableScore {
156 /// An opaque pointer which is passed to your function implementations as an argument.
157 /// This has no meaning in the LDK, and can be NULL or any other value.
158 pub this_arg: *mut c_void,
159 /// Returns the locked scorer.
161 pub lock: extern "C" fn (this_arg: *const c_void) -> crate::lightning::routing::scoring::Score,
162 /// Frees any resources associated with this object given its this_arg pointer.
163 /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
164 pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
166 unsafe impl Send for LockableScore {}
167 unsafe impl Sync for LockableScore {}
169 pub(crate) extern "C" fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore {
171 this_arg: orig.this_arg,
172 lock: Clone::clone(&orig.lock),
173 free: Clone::clone(&orig.free),
177 use lightning::routing::scoring::LockableScore as rustLockableScore;
178 impl<'a> rustLockableScore<'a> for LockableScore {
179 type Locked = crate::lightning::routing::scoring::Score;
180 fn lock(&'a self) -> crate::lightning::routing::scoring::Score {
181 let mut ret = (self.lock)(self.this_arg);
186 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
187 // directly as a Deref trait in higher-level structs:
188 impl core::ops::Deref for LockableScore {
190 fn deref(&self) -> &Self {
194 /// Calls the free function if one is set
196 pub extern "C" fn LockableScore_free(this_ptr: LockableScore) { }
197 impl Drop for LockableScore {
199 if let Some(f) = self.free {
205 use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport;
206 pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport<crate::lightning::routing::scoring::Score>;
208 /// A concrete implementation of [`LockableScore`] which supports multi-threading.
211 pub struct MultiThreadedLockableScore {
212 /// A pointer to the opaque Rust object.
214 /// Nearly everywhere, inner must be non-null, however in places where
215 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
216 pub inner: *mut nativeMultiThreadedLockableScore,
217 /// Indicates that this is the only struct which contains the same pointer.
219 /// Rust functions which take ownership of an object provided via an argument require
220 /// this to be true and invalidate the object pointed to by inner.
224 impl Drop for MultiThreadedLockableScore {
226 if self.is_owned && !<*mut nativeMultiThreadedLockableScore>::is_null(self.inner) {
227 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
231 /// Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL.
233 pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockableScore) { }
235 /// Used only if an object of this type is returned as a trait impl by a method
236 pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) {
237 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore); }
240 impl MultiThreadedLockableScore {
241 pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedLockableScore {
242 unsafe { &*ObjOps::untweak_ptr(self.inner) }
244 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedLockableScore {
245 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
247 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
248 pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedLockableScore {
249 assert!(self.is_owned);
250 let ret = ObjOps::untweak_ptr(self.inner);
251 self.inner = core::ptr::null_mut();
256 /// Serialize the MultiThreadedLockableScore object into a byte array which can be read by MultiThreadedLockableScore_read
257 pub extern "C" fn MultiThreadedLockableScore_write(obj: &crate::lightning::routing::scoring::MultiThreadedLockableScore) -> crate::c_types::derived::CVec_u8Z {
258 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
261 pub(crate) extern "C" fn MultiThreadedLockableScore_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
262 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedLockableScore) })
264 /// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
267 pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> crate::lightning::routing::scoring::MultiThreadedLockableScore {
268 let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score);
269 crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true }
273 use lightning::routing::scoring::ChannelUsage as nativeChannelUsageImport;
274 pub(crate) type nativeChannelUsage = nativeChannelUsageImport;
276 /// Proposed use of a channel passed as a parameter to [`Score::channel_penalty_msat`].
279 pub struct ChannelUsage {
280 /// A pointer to the opaque Rust object.
282 /// Nearly everywhere, inner must be non-null, however in places where
283 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
284 pub inner: *mut nativeChannelUsage,
285 /// Indicates that this is the only struct which contains the same pointer.
287 /// Rust functions which take ownership of an object provided via an argument require
288 /// this to be true and invalidate the object pointed to by inner.
292 impl Drop for ChannelUsage {
294 if self.is_owned && !<*mut nativeChannelUsage>::is_null(self.inner) {
295 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
299 /// Frees any resources used by the ChannelUsage, if is_owned is set and inner is non-NULL.
301 pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { }
303 /// Used only if an object of this type is returned as a trait impl by a method
304 pub(crate) extern "C" fn ChannelUsage_free_void(this_ptr: *mut c_void) {
305 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUsage); }
309 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUsage {
310 unsafe { &*ObjOps::untweak_ptr(self.inner) }
312 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUsage {
313 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
315 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
316 pub(crate) fn take_inner(mut self) -> *mut nativeChannelUsage {
317 assert!(self.is_owned);
318 let ret = ObjOps::untweak_ptr(self.inner);
319 self.inner = core::ptr::null_mut();
323 /// The amount to send through the channel, denominated in millisatoshis.
325 pub extern "C" fn ChannelUsage_get_amount_msat(this_ptr: &ChannelUsage) -> u64 {
326 let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
329 /// The amount to send through the channel, denominated in millisatoshis.
331 pub extern "C" fn ChannelUsage_set_amount_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
332 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
334 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
335 /// as part of a multi-path payment.
337 pub extern "C" fn ChannelUsage_get_inflight_htlc_msat(this_ptr: &ChannelUsage) -> u64 {
338 let mut inner_val = &mut this_ptr.get_native_mut_ref().inflight_htlc_msat;
341 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
342 /// as part of a multi-path payment.
344 pub extern "C" fn ChannelUsage_set_inflight_htlc_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
345 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inflight_htlc_msat = val;
347 /// The effective capacity of the channel.
349 pub extern "C" fn ChannelUsage_get_effective_capacity(this_ptr: &ChannelUsage) -> crate::lightning::routing::gossip::EffectiveCapacity {
350 let mut inner_val = &mut this_ptr.get_native_mut_ref().effective_capacity;
351 crate::lightning::routing::gossip::EffectiveCapacity::from_native(inner_val)
353 /// The effective capacity of the channel.
355 pub extern "C" fn ChannelUsage_set_effective_capacity(this_ptr: &mut ChannelUsage, mut val: crate::lightning::routing::gossip::EffectiveCapacity) {
356 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.effective_capacity = val.into_native();
358 /// Constructs a new ChannelUsage given each field
361 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 {
362 ChannelUsage { inner: ObjOps::heap_alloc(nativeChannelUsage {
363 amount_msat: amount_msat_arg,
364 inflight_htlc_msat: inflight_htlc_msat_arg,
365 effective_capacity: effective_capacity_arg.into_native(),
368 impl Clone for ChannelUsage {
369 fn clone(&self) -> Self {
371 inner: if <*mut nativeChannelUsage>::is_null(self.inner) { core::ptr::null_mut() } else {
372 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
378 /// Used only if an object of this type is returned as a trait impl by a method
379 pub(crate) extern "C" fn ChannelUsage_clone_void(this_ptr: *const c_void) -> *mut c_void {
380 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUsage)).clone() })) as *mut c_void
383 /// Creates a copy of the ChannelUsage
384 pub extern "C" fn ChannelUsage_clone(orig: &ChannelUsage) -> ChannelUsage {
388 use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport;
389 pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport;
391 /// [`Score`] implementation that uses a fixed penalty.
394 pub struct FixedPenaltyScorer {
395 /// A pointer to the opaque Rust object.
397 /// Nearly everywhere, inner must be non-null, however in places where
398 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
399 pub inner: *mut nativeFixedPenaltyScorer,
400 /// Indicates that this is the only struct which contains the same pointer.
402 /// Rust functions which take ownership of an object provided via an argument require
403 /// this to be true and invalidate the object pointed to by inner.
407 impl Drop for FixedPenaltyScorer {
409 if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) {
410 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
414 /// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL.
416 pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { }
418 /// Used only if an object of this type is returned as a trait impl by a method
419 pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) {
420 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer); }
423 impl FixedPenaltyScorer {
424 pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer {
425 unsafe { &*ObjOps::untweak_ptr(self.inner) }
427 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer {
428 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
430 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
431 pub(crate) fn take_inner(mut self) -> *mut nativeFixedPenaltyScorer {
432 assert!(self.is_owned);
433 let ret = ObjOps::untweak_ptr(self.inner);
434 self.inner = core::ptr::null_mut();
438 impl Clone for FixedPenaltyScorer {
439 fn clone(&self) -> Self {
441 inner: if <*mut nativeFixedPenaltyScorer>::is_null(self.inner) { core::ptr::null_mut() } else {
442 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
448 /// Used only if an object of this type is returned as a trait impl by a method
449 pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void {
450 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void
453 /// Creates a copy of the FixedPenaltyScorer
454 pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer {
457 /// Creates a new scorer using `penalty_msat`.
460 pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> crate::lightning::routing::scoring::FixedPenaltyScorer {
461 let mut ret = lightning::routing::scoring::FixedPenaltyScorer::with_penalty(penalty_msat);
462 crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
465 impl From<nativeFixedPenaltyScorer> for crate::lightning::routing::scoring::Score {
466 fn from(obj: nativeFixedPenaltyScorer) -> Self {
467 let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
468 let mut ret = FixedPenaltyScorer_as_Score(&rust_obj);
469 // 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
470 rust_obj.inner = core::ptr::null_mut();
471 ret.free = Some(FixedPenaltyScorer_free_void);
475 /// Constructs a new Score which calls the relevant methods on this_arg.
476 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
478 pub extern "C" fn FixedPenaltyScorer_as_Score(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::Score {
479 crate::lightning::routing::scoring::Score {
480 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
482 channel_penalty_msat: FixedPenaltyScorer_Score_channel_penalty_msat,
483 payment_path_failed: FixedPenaltyScorer_Score_payment_path_failed,
484 payment_path_successful: FixedPenaltyScorer_Score_payment_path_successful,
485 write: FixedPenaltyScorer_write_void,
490 extern "C" fn FixedPenaltyScorer_Score_channel_penalty_msat(this_arg: *const c_void, unused_0: u64, unused_1: &crate::lightning::routing::gossip::NodeId, unused_2: &crate::lightning::routing::gossip::NodeId, unused_3: crate::lightning::routing::scoring::ChannelUsage) -> u64 {
491 let mut ret = <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, unused_0, unused_1.get_native_ref(), unused_2.get_native_ref(), *unsafe { Box::from_raw(unused_3.take_inner()) });
494 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) {
495 let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); };
496 <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..], _short_channel_id)
498 extern "C" fn FixedPenaltyScorer_Score_payment_path_successful(this_arg: *mut c_void, mut _path: crate::c_types::derived::CVec_RouteHopZ) {
499 let mut local__path = Vec::new(); for mut item in _path.as_slice().iter() { local__path.push( { item.get_native_ref() }); };
500 <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local__path[..])
504 /// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read
505 pub extern "C" fn FixedPenaltyScorer_write(obj: &crate::lightning::routing::scoring::FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z {
506 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
509 pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
510 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) })
513 /// Read a FixedPenaltyScorer from a byte array, created by FixedPenaltyScorer_write
514 pub extern "C" fn FixedPenaltyScorer_read(ser: crate::c_types::u8slice, arg: u64) -> crate::c_types::derived::CResult_FixedPenaltyScorerDecodeErrorZ {
516 let res: Result<lightning::routing::scoring::FixedPenaltyScorer, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
517 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() };
521 use lightning::routing::scoring::ProbabilisticScorer as nativeProbabilisticScorerImport;
522 pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger>;
524 /// [`Score`] implementation using channel success probability distributions.
526 /// Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
527 /// and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability
528 /// distributions are defined based on knowledge learned from successful and unsuccessful attempts.
529 /// Then the negative `log10` of the success probability is used to determine the cost of routing a
530 /// specific HTLC amount through a channel.
532 /// Knowledge about channel liquidity balances takes the form of upper and lower bounds on the
533 /// possible liquidity. Certainty of the bounds is decreased over time using a decay function. See
534 /// [`ProbabilisticScoringParameters`] for details.
536 /// Since the scorer aims to learn the current channel liquidity balances, it works best for nodes
537 /// with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment
538 /// volume are more likely to experience failed payment paths, which would need to be retried.
542 /// Mixing the `no-std` feature between serialization and deserialization results in undefined
545 /// [1]: https://arxiv.org/abs/2107.05322
548 pub struct ProbabilisticScorer {
549 /// A pointer to the opaque Rust object.
551 /// Nearly everywhere, inner must be non-null, however in places where
552 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
553 pub inner: *mut nativeProbabilisticScorer,
554 /// Indicates that this is the only struct which contains the same pointer.
556 /// Rust functions which take ownership of an object provided via an argument require
557 /// this to be true and invalidate the object pointed to by inner.
561 impl Drop for ProbabilisticScorer {
563 if self.is_owned && !<*mut nativeProbabilisticScorer>::is_null(self.inner) {
564 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
568 /// Frees any resources used by the ProbabilisticScorer, if is_owned is set and inner is non-NULL.
570 pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { }
572 /// Used only if an object of this type is returned as a trait impl by a method
573 pub(crate) extern "C" fn ProbabilisticScorer_free_void(this_ptr: *mut c_void) {
574 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScorer); }
577 impl ProbabilisticScorer {
578 pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScorer {
579 unsafe { &*ObjOps::untweak_ptr(self.inner) }
581 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScorer {
582 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
584 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
585 pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScorer {
586 assert!(self.is_owned);
587 let ret = ObjOps::untweak_ptr(self.inner);
588 self.inner = core::ptr::null_mut();
593 use lightning::routing::scoring::ProbabilisticScoringParameters as nativeProbabilisticScoringParametersImport;
594 pub(crate) type nativeProbabilisticScoringParameters = nativeProbabilisticScoringParametersImport;
596 /// Parameters for configuring [`ProbabilisticScorer`].
598 /// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
599 /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
602 pub struct ProbabilisticScoringParameters {
603 /// A pointer to the opaque Rust object.
605 /// Nearly everywhere, inner must be non-null, however in places where
606 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
607 pub inner: *mut nativeProbabilisticScoringParameters,
608 /// Indicates that this is the only struct which contains the same pointer.
610 /// Rust functions which take ownership of an object provided via an argument require
611 /// this to be true and invalidate the object pointed to by inner.
615 impl Drop for ProbabilisticScoringParameters {
617 if self.is_owned && !<*mut nativeProbabilisticScoringParameters>::is_null(self.inner) {
618 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
622 /// Frees any resources used by the ProbabilisticScoringParameters, if is_owned is set and inner is non-NULL.
624 pub extern "C" fn ProbabilisticScoringParameters_free(this_obj: ProbabilisticScoringParameters) { }
626 /// Used only if an object of this type is returned as a trait impl by a method
627 pub(crate) extern "C" fn ProbabilisticScoringParameters_free_void(this_ptr: *mut c_void) {
628 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters); }
631 impl ProbabilisticScoringParameters {
632 pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScoringParameters {
633 unsafe { &*ObjOps::untweak_ptr(self.inner) }
635 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScoringParameters {
636 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
638 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
639 pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScoringParameters {
640 assert!(self.is_owned);
641 let ret = ObjOps::untweak_ptr(self.inner);
642 self.inner = core::ptr::null_mut();
646 /// A fixed penalty in msats to apply to each channel.
648 /// Default value: 500 msat
650 pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
651 let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat;
654 /// A fixed penalty in msats to apply to each channel.
656 /// Default value: 500 msat
658 pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
659 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val;
661 /// A multiplier used in conjunction with the negative `log10` of the channel's success
662 /// probability for a payment to determine the liquidity penalty.
664 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
665 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
666 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
667 /// lower bounding the success probability to `0.01`) when the amount falls within the
668 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
669 /// result in a `u64::max_value` penalty, however.
671 /// Default value: 40,000 msat
673 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
675 pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
676 let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_multiplier_msat;
679 /// A multiplier used in conjunction with the negative `log10` of the channel's success
680 /// probability for a payment to determine the liquidity penalty.
682 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
683 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
684 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
685 /// lower bounding the success probability to `0.01`) when the amount falls within the
686 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
687 /// result in a `u64::max_value` penalty, however.
689 /// Default value: 40,000 msat
691 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
693 pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
694 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_multiplier_msat = val;
696 /// The time required to elapse before any knowledge learned about channel liquidity balances is
699 /// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets
700 /// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases
701 /// the certainty of the channel liquidity balance.
703 /// Default value: 1 hour
707 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
708 /// liquidity knowledge will never decay except when the bounds cross.
710 pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_offset_half_life(this_ptr: &ProbabilisticScoringParameters) -> u64 {
711 let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_offset_half_life;
714 /// The time required to elapse before any knowledge learned about channel liquidity balances is
717 /// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets
718 /// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases
719 /// the certainty of the channel liquidity balance.
721 /// Default value: 1 hour
725 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
726 /// liquidity knowledge will never decay except when the bounds cross.
728 pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
729 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_offset_half_life = core::time::Duration::from_secs(val);
731 /// A multiplier used in conjunction with a payment amount and the negative `log10` of the
732 /// channel's success probability for the payment to determine the amount penalty.
734 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
735 /// fees plus penalty) for large payments. The penalty is computed as the product of this
736 /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the
737 /// success probability.
739 /// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20`
741 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
742 /// the amount will result in a penalty of the multiplier. And, as the success probability
743 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
744 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
747 /// Default value: 256 msat
749 pub extern "C" fn ProbabilisticScoringParameters_get_amount_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
750 let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_penalty_multiplier_msat;
753 /// A multiplier used in conjunction with a payment amount and the negative `log10` of the
754 /// channel's success probability for the payment to determine the amount penalty.
756 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
757 /// fees plus penalty) for large payments. The penalty is computed as the product of this
758 /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the
759 /// success probability.
761 /// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20`
763 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
764 /// the amount will result in a penalty of the multiplier. And, as the success probability
765 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
766 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
769 /// Default value: 256 msat
771 pub extern "C" fn ProbabilisticScoringParameters_set_amount_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
772 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_penalty_multiplier_msat = val;
774 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
775 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
776 /// treat such nodes preferentially as this makes balance discovery attacks harder to execute,
777 /// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy.
779 /// Default value: 250 msat
781 pub extern "C" fn ProbabilisticScoringParameters_get_anti_probing_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
782 let mut inner_val = &mut this_ptr.get_native_mut_ref().anti_probing_penalty_msat;
785 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
786 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
787 /// treat such nodes preferentially as this makes balance discovery attacks harder to execute,
788 /// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy.
790 /// Default value: 250 msat
792 pub extern "C" fn ProbabilisticScoringParameters_set_anti_probing_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
793 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.anti_probing_penalty_msat = val;
795 impl Clone for ProbabilisticScoringParameters {
796 fn clone(&self) -> Self {
798 inner: if <*mut nativeProbabilisticScoringParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
799 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
805 /// Used only if an object of this type is returned as a trait impl by a method
806 pub(crate) extern "C" fn ProbabilisticScoringParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
807 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringParameters)).clone() })) as *mut c_void
810 /// Creates a copy of the ProbabilisticScoringParameters
811 pub extern "C" fn ProbabilisticScoringParameters_clone(orig: &ProbabilisticScoringParameters) -> ProbabilisticScoringParameters {
814 /// Creates a new scorer using the given scoring parameters for sending payments from a node
815 /// through a network graph.
818 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 {
819 let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(params.take_inner()) }, network_graph.get_native_ref(), logger);
820 crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
823 /// Dump the contents of this scorer into the configured logger.
825 /// Note that this writes roughly one line per channel for which we have a liquidity estimate,
826 /// which may be a substantial amount of log output.
828 pub extern "C" fn ProbabilisticScorer_debug_log_liquidity_stats(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer) {
829 unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.debug_log_liquidity_stats()
832 /// Query the estimated minimum and maximum liquidity available for sending a payment over the
833 /// channel with `scid` towards the given `target` node.
836 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 {
837 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.estimated_channel_liquidity_range(scid, target.get_native_ref());
838 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 }) };
842 /// Marks the node with the given `node_id` as banned, i.e.,
843 /// it will be avoided during path finding.
845 pub extern "C" fn ProbabilisticScorer_add_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) {
846 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.add_banned(node_id.get_native_ref())
849 /// Removes the node with the given `node_id` from the list of nodes to avoid.
851 pub extern "C" fn ProbabilisticScorer_remove_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) {
852 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_banned(node_id.get_native_ref())
855 /// Clears the list of nodes that are avoided during path finding.
857 pub extern "C" fn ProbabilisticScorer_clear_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer) {
858 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.clear_banned()
861 /// Marks all nodes in the given list as banned, i.e.,
862 /// they will be avoided during path finding.
864 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) {
865 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()) } }); };
866 unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringParameters)) }.add_banned_from_list(local_node_ids)
869 /// Creates a "default" ProbabilisticScoringParameters. See struct and individual field documentaiton for details on which values are used.
872 pub extern "C" fn ProbabilisticScoringParameters_default() -> ProbabilisticScoringParameters {
873 ProbabilisticScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
875 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::Score {
876 fn from(obj: nativeProbabilisticScorer) -> Self {
877 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
878 let mut ret = ProbabilisticScorer_as_Score(&rust_obj);
879 // 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
880 rust_obj.inner = core::ptr::null_mut();
881 ret.free = Some(ProbabilisticScorer_free_void);
885 /// Constructs a new Score which calls the relevant methods on this_arg.
886 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
888 pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::Score {
889 crate::lightning::routing::scoring::Score {
890 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
892 channel_penalty_msat: ProbabilisticScorer_Score_channel_penalty_msat,
893 payment_path_failed: ProbabilisticScorer_Score_payment_path_failed,
894 payment_path_successful: ProbabilisticScorer_Score_payment_path_successful,
895 write: ProbabilisticScorer_write_void,
900 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 {
901 let mut ret = <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::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()) });
904 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) {
905 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
906 <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id)
908 extern "C" fn ProbabilisticScorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
909 let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
910 <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..])
915 use alloc::str::FromStr;
916 use core::ffi::c_void;
917 use core::convert::Infallible;
918 use bitcoin::hashes::Hash;
919 use crate::c_types::*;
920 #[cfg(feature="no-std")]
921 use alloc::{vec::Vec, boxed::Box};
925 /// Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
926 pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z {
927 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
930 pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
931 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeProbabilisticScorer) })
934 /// Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
935 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 {
936 let arg_a_conv = *unsafe { Box::from_raw(arg_a.take_inner()) };
937 let arg_b_conv = arg_b.get_native_ref();
938 let arg_c_conv = arg_c;
939 let arg_conv = (arg_a_conv, arg_b_conv, arg_c_conv);
940 let res: Result<lightning::routing::scoring::ProbabilisticScorer<&lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger>, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
941 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() };