Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / scoring.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Utilities for scoring payment channels.
10 //!
11 //! [`ProbabilisticScorer`] may be given to [`find_route`] to score payment channels during path
12 //! finding when a custom [`Score`] implementation is not needed.
13 //!
14 //! # Example
15 //!
16 //! ```
17 //! # extern crate bitcoin;
18 //! #
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;
25 //! #
26 //! # struct FakeLogger {};
27 //! # impl Logger for FakeLogger {
28 //! #     fn log(&self, record: &Record) { unimplemented!() }
29 //! # }
30 //! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph<&FakeLogger>) {
31 //! # let logger = FakeLogger {};
32 //! #
33 //! // Use the default channel penalties.
34 //! let params = ProbabilisticScoringParameters::default();
35 //! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
36 //!
37 //! // Or use custom channel penalties.
38 //! let params = ProbabilisticScoringParameters {
39 //!     liquidity_penalty_multiplier_msat: 2 * 1000,
40 //!     ..ProbabilisticScoringParameters::default()
41 //! };
42 //! let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
43 //! # let random_seed_bytes = [42u8; 32];
44 //!
45 //! let route = find_route(&payer, &route_params, &network_graph.read_only(), None, &logger, &scorer, &random_seed_bytes);
46 //! # }
47 //! ```
48 //!
49 //! # Note
50 //!
51 //! Persisting when built with feature `no-std` and restoring without it, or vice versa, uses
52 //! different types and thus is undefined.
53 //!
54 //! [`find_route`]: crate::routing::router::find_route
55
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};
63
64 /// An interface used to score payment channels for path finding.
65 ///
66 ///\tScoring is in terms of fees willing to be paid in order to avoid routing through a channel.
67 #[repr(C)]
68 pub struct Score {
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`.
74         ///
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.
80         #[must_use]
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)>,
91 }
92 unsafe impl Send for Score {}
93 unsafe impl Sync for Score {}
94 #[no_mangle]
95 pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score {
96         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),
103         }
104 }
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())
109         }
110 }
111
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 });
116                 ret
117         }
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)
121         }
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())
125         }
126 }
127
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 {
131         type Target = Self;
132         fn deref(&self) -> &Self {
133                 self
134         }
135 }
136 /// Calls the free function if one is set
137 #[no_mangle]
138 pub extern "C" fn Score_free(this_ptr: Score) { }
139 impl Drop for Score {
140         fn drop(&mut self) {
141                 if let Some(f) = self.free {
142                         f(self.this_arg);
143                 }
144         }
145 }
146 /// A scorer that is accessed under a lock.
147 ///
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.
152 ///
153 /// [`find_route`]: crate::routing::router::find_route
154 #[repr(C)]
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.
160         #[must_use]
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)>,
165 }
166 unsafe impl Send for LockableScore {}
167 unsafe impl Sync for LockableScore {}
168 #[no_mangle]
169 pub(crate) extern "C" fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore {
170         LockableScore {
171                 this_arg: orig.this_arg,
172                 lock: Clone::clone(&orig.lock),
173                 free: Clone::clone(&orig.free),
174         }
175 }
176
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);
182                 ret
183         }
184 }
185
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 {
189         type Target = Self;
190         fn deref(&self) -> &Self {
191                 self
192         }
193 }
194 /// Calls the free function if one is set
195 #[no_mangle]
196 pub extern "C" fn LockableScore_free(this_ptr: LockableScore) { }
197 impl Drop for LockableScore {
198         fn drop(&mut self) {
199                 if let Some(f) = self.free {
200                         f(self.this_arg);
201                 }
202         }
203 }
204
205 use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport;
206 pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport<crate::lightning::routing::scoring::Score>;
207
208 /// A concrete implementation of [`LockableScore`] which supports multi-threading.
209 #[must_use]
210 #[repr(C)]
211 pub struct MultiThreadedLockableScore {
212         /// A pointer to the opaque Rust object.
213
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.
218
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.
221         pub is_owned: bool,
222 }
223
224 impl Drop for MultiThreadedLockableScore {
225         fn drop(&mut self) {
226                 if self.is_owned && !<*mut nativeMultiThreadedLockableScore>::is_null(self.inner) {
227                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
228                 }
229         }
230 }
231 /// Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL.
232 #[no_mangle]
233 pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockableScore) { }
234 #[allow(unused)]
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); }
238 }
239 #[allow(unused)]
240 impl MultiThreadedLockableScore {
241         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedLockableScore {
242                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
243         }
244         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedLockableScore {
245                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
246         }
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();
252                 ret
253         }
254 }
255 #[no_mangle]
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())
259 }
260 #[no_mangle]
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) })
263 }
264 /// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
265 #[must_use]
266 #[no_mangle]
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 }
270 }
271
272
273 use lightning::routing::scoring::ChannelUsage as nativeChannelUsageImport;
274 pub(crate) type nativeChannelUsage = nativeChannelUsageImport;
275
276 /// Proposed use of a channel passed as a parameter to [`Score::channel_penalty_msat`].
277 #[must_use]
278 #[repr(C)]
279 pub struct ChannelUsage {
280         /// A pointer to the opaque Rust object.
281
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.
286
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.
289         pub is_owned: bool,
290 }
291
292 impl Drop for ChannelUsage {
293         fn drop(&mut self) {
294                 if self.is_owned && !<*mut nativeChannelUsage>::is_null(self.inner) {
295                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
296                 }
297         }
298 }
299 /// Frees any resources used by the ChannelUsage, if is_owned is set and inner is non-NULL.
300 #[no_mangle]
301 pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { }
302 #[allow(unused)]
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); }
306 }
307 #[allow(unused)]
308 impl ChannelUsage {
309         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUsage {
310                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
311         }
312         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUsage {
313                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
314         }
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();
320                 ret
321         }
322 }
323 /// The amount to send through the channel, denominated in millisatoshis.
324 #[no_mangle]
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;
327         *inner_val
328 }
329 /// The amount to send through the channel, denominated in millisatoshis.
330 #[no_mangle]
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;
333 }
334 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
335 /// as part of a multi-path payment.
336 #[no_mangle]
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;
339         *inner_val
340 }
341 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
342 /// as part of a multi-path payment.
343 #[no_mangle]
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;
346 }
347 /// The effective capacity of the channel.
348 #[no_mangle]
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)
352 }
353 /// The effective capacity of the channel.
354 #[no_mangle]
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();
357 }
358 /// Constructs a new ChannelUsage given each field
359 #[must_use]
360 #[no_mangle]
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(),
366         }), is_owned: true }
367 }
368 impl Clone for ChannelUsage {
369         fn clone(&self) -> Self {
370                 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()) },
373                         is_owned: true,
374                 }
375         }
376 }
377 #[allow(unused)]
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
381 }
382 #[no_mangle]
383 /// Creates a copy of the ChannelUsage
384 pub extern "C" fn ChannelUsage_clone(orig: &ChannelUsage) -> ChannelUsage {
385         orig.clone()
386 }
387
388 use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport;
389 pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport;
390
391 /// [`Score`] implementation that uses a fixed penalty.
392 #[must_use]
393 #[repr(C)]
394 pub struct FixedPenaltyScorer {
395         /// A pointer to the opaque Rust object.
396
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.
401
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.
404         pub is_owned: bool,
405 }
406
407 impl Drop for FixedPenaltyScorer {
408         fn drop(&mut self) {
409                 if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) {
410                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
411                 }
412         }
413 }
414 /// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL.
415 #[no_mangle]
416 pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { }
417 #[allow(unused)]
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); }
421 }
422 #[allow(unused)]
423 impl FixedPenaltyScorer {
424         pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer {
425                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
426         }
427         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer {
428                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
429         }
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();
435                 ret
436         }
437 }
438 impl Clone for FixedPenaltyScorer {
439         fn clone(&self) -> Self {
440                 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()) },
443                         is_owned: true,
444                 }
445         }
446 }
447 #[allow(unused)]
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
451 }
452 #[no_mangle]
453 /// Creates a copy of the FixedPenaltyScorer
454 pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer {
455         orig.clone()
456 }
457 /// Creates a new scorer using `penalty_msat`.
458 #[must_use]
459 #[no_mangle]
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 }
463 }
464
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);
472                 ret
473         }
474 }
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
477 #[no_mangle]
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 },
481                 free: None,
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,
486         }
487 }
488
489 #[must_use]
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()) });
492         ret
493 }
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)
497 }
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[..])
501 }
502
503 #[no_mangle]
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())
507 }
508 #[no_mangle]
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) })
511 }
512 #[no_mangle]
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 {
515         let arg_conv = arg;
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() };
518         local_res
519 }
520
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>;
523
524 /// [`Score`] implementation using channel success probability distributions.
525 ///
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.
531 ///
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.
535 ///
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.
539 ///
540 /// # Note
541 ///
542 /// Mixing the `no-std` feature between serialization and deserialization results in undefined
543 /// behavior.
544 ///
545 /// [1]: https://arxiv.org/abs/2107.05322
546 #[must_use]
547 #[repr(C)]
548 pub struct ProbabilisticScorer {
549         /// A pointer to the opaque Rust object.
550
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.
555
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.
558         pub is_owned: bool,
559 }
560
561 impl Drop for ProbabilisticScorer {
562         fn drop(&mut self) {
563                 if self.is_owned && !<*mut nativeProbabilisticScorer>::is_null(self.inner) {
564                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
565                 }
566         }
567 }
568 /// Frees any resources used by the ProbabilisticScorer, if is_owned is set and inner is non-NULL.
569 #[no_mangle]
570 pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { }
571 #[allow(unused)]
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); }
575 }
576 #[allow(unused)]
577 impl ProbabilisticScorer {
578         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScorer {
579                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
580         }
581         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScorer {
582                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
583         }
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();
589                 ret
590         }
591 }
592
593 use lightning::routing::scoring::ProbabilisticScoringParameters as nativeProbabilisticScoringParametersImport;
594 pub(crate) type nativeProbabilisticScoringParameters = nativeProbabilisticScoringParametersImport;
595
596 /// Parameters for configuring [`ProbabilisticScorer`].
597 ///
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).
600 #[must_use]
601 #[repr(C)]
602 pub struct ProbabilisticScoringParameters {
603         /// A pointer to the opaque Rust object.
604
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.
609
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.
612         pub is_owned: bool,
613 }
614
615 impl Drop for ProbabilisticScoringParameters {
616         fn drop(&mut self) {
617                 if self.is_owned && !<*mut nativeProbabilisticScoringParameters>::is_null(self.inner) {
618                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
619                 }
620         }
621 }
622 /// Frees any resources used by the ProbabilisticScoringParameters, if is_owned is set and inner is non-NULL.
623 #[no_mangle]
624 pub extern "C" fn ProbabilisticScoringParameters_free(this_obj: ProbabilisticScoringParameters) { }
625 #[allow(unused)]
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); }
629 }
630 #[allow(unused)]
631 impl ProbabilisticScoringParameters {
632         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScoringParameters {
633                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
634         }
635         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScoringParameters {
636                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
637         }
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();
643                 ret
644         }
645 }
646 /// A fixed penalty in msats to apply to each channel.
647 ///
648 /// Default value: 500 msat
649 #[no_mangle]
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;
652         *inner_val
653 }
654 /// A fixed penalty in msats to apply to each channel.
655 ///
656 /// Default value: 500 msat
657 #[no_mangle]
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;
660 }
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.
663 ///
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.
670 ///
671 /// Default value: 40,000 msat
672 ///
673 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
674 #[no_mangle]
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;
677         *inner_val
678 }
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.
681 ///
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.
688 ///
689 /// Default value: 40,000 msat
690 ///
691 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
692 #[no_mangle]
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;
695 }
696 /// The time required to elapse before any knowledge learned about channel liquidity balances is
697 /// cut in half.
698 ///
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.
702 ///
703 /// Default value: 1 hour
704 ///
705 /// # Note
706 ///
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.
709 #[no_mangle]
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;
712         inner_val.as_secs()
713 }
714 /// The time required to elapse before any knowledge learned about channel liquidity balances is
715 /// cut in half.
716 ///
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.
720 ///
721 /// Default value: 1 hour
722 ///
723 /// # Note
724 ///
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.
727 #[no_mangle]
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);
730 }
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.
733 ///
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.
738 ///
739 /// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20`
740 ///
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
745 /// fall below `1`.
746 ///
747 /// Default value: 256 msat
748 #[no_mangle]
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;
751         *inner_val
752 }
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.
755 ///
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.
760 ///
761 /// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20`
762 ///
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
767 /// fall below `1`.
768 ///
769 /// Default value: 256 msat
770 #[no_mangle]
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;
773 }
774 /// Constructs a new ProbabilisticScoringParameters given each field
775 #[must_use]
776 #[no_mangle]
777 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 {
778         ProbabilisticScoringParameters { inner: ObjOps::heap_alloc(nativeProbabilisticScoringParameters {
779                 base_penalty_msat: base_penalty_msat_arg,
780                 liquidity_penalty_multiplier_msat: liquidity_penalty_multiplier_msat_arg,
781                 liquidity_offset_half_life: core::time::Duration::from_secs(liquidity_offset_half_life_arg),
782                 amount_penalty_multiplier_msat: amount_penalty_multiplier_msat_arg,
783         }), is_owned: true }
784 }
785 impl Clone for ProbabilisticScoringParameters {
786         fn clone(&self) -> Self {
787                 Self {
788                         inner: if <*mut nativeProbabilisticScoringParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
789                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
790                         is_owned: true,
791                 }
792         }
793 }
794 #[allow(unused)]
795 /// Used only if an object of this type is returned as a trait impl by a method
796 pub(crate) extern "C" fn ProbabilisticScoringParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
797         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringParameters)).clone() })) as *mut c_void
798 }
799 #[no_mangle]
800 /// Creates a copy of the ProbabilisticScoringParameters
801 pub extern "C" fn ProbabilisticScoringParameters_clone(orig: &ProbabilisticScoringParameters) -> ProbabilisticScoringParameters {
802         orig.clone()
803 }
804 /// Creates a new scorer using the given scoring parameters for sending payments from a node
805 /// through a network graph.
806 #[must_use]
807 #[no_mangle]
808 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 {
809         let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(params.take_inner()) }, network_graph.get_native_ref(), logger);
810         crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
811 }
812
813 /// Dump the contents of this scorer into the configured logger.
814 ///
815 /// Note that this writes roughly one line per channel for which we have a liquidity estimate,
816 /// which may be a substantial amount of log output.
817 #[no_mangle]
818 pub extern "C" fn ProbabilisticScorer_debug_log_liquidity_stats(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer) {
819         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.debug_log_liquidity_stats()
820 }
821
822 /// Creates a "default" ProbabilisticScoringParameters. See struct and individual field documentaiton for details on which values are used.
823 #[must_use]
824 #[no_mangle]
825 pub extern "C" fn ProbabilisticScoringParameters_default() -> ProbabilisticScoringParameters {
826         ProbabilisticScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
827 }
828 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::Score {
829         fn from(obj: nativeProbabilisticScorer) -> Self {
830                 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
831                 let mut ret = ProbabilisticScorer_as_Score(&rust_obj);
832                 // 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
833                 rust_obj.inner = core::ptr::null_mut();
834                 ret.free = Some(ProbabilisticScorer_free_void);
835                 ret
836         }
837 }
838 /// Constructs a new Score which calls the relevant methods on this_arg.
839 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
840 #[no_mangle]
841 pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::Score {
842         crate::lightning::routing::scoring::Score {
843                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
844                 free: None,
845                 channel_penalty_msat: ProbabilisticScorer_Score_channel_penalty_msat,
846                 payment_path_failed: ProbabilisticScorer_Score_payment_path_failed,
847                 payment_path_successful: ProbabilisticScorer_Score_payment_path_successful,
848                 write: ProbabilisticScorer_write_void,
849         }
850 }
851
852 #[must_use]
853 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 {
854         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()) });
855         ret
856 }
857 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) {
858         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
859         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id)
860 }
861 extern "C" fn ProbabilisticScorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
862         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
863         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..])
864 }
865
866 mod approx {
867
868 use alloc::str::FromStr;
869 use core::ffi::c_void;
870 use core::convert::Infallible;
871 use bitcoin::hashes::Hash;
872 use crate::c_types::*;
873 #[cfg(feature="no-std")]
874 use alloc::{vec::Vec, boxed::Box};
875
876 }
877 #[no_mangle]
878 /// Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
879 pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z {
880         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
881 }
882 #[no_mangle]
883 pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
884         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeProbabilisticScorer) })
885 }
886 #[no_mangle]
887 /// Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
888 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 {
889         let arg_a_conv = *unsafe { Box::from_raw(arg_a.take_inner()) };
890         let arg_b_conv = arg_b.get_native_ref();
891         let arg_c_conv = arg_c;
892         let arg_conv = (arg_a_conv, arg_b_conv, arg_c_conv);
893         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);
894         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() };
895         local_res
896 }