11db1982d834c4f7d8655ebbc9c4da4e2d0e3d44
[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, 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         /// Handles updating channel penalties after a probe over the given path failed.
87         pub probe_failed: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ, short_channel_id: u64),
88         /// Handles updating channel penalties after a probe over the given path succeeded.
89         pub probe_successful: extern "C" fn (this_arg: *mut c_void, path: crate::c_types::derived::CVec_RouteHopZ),
90         /// Serialize the object into a byte array
91         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
92         /// Frees any resources associated with this object given its this_arg pointer.
93         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
94         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
95 }
96 unsafe impl Send for Score {}
97 unsafe impl Sync for Score {}
98 #[no_mangle]
99 pub(crate) extern "C" fn Score_clone_fields(orig: &Score) -> Score {
100         Score {
101                 this_arg: orig.this_arg,
102                 channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat),
103                 payment_path_failed: Clone::clone(&orig.payment_path_failed),
104                 payment_path_successful: Clone::clone(&orig.payment_path_successful),
105                 probe_failed: Clone::clone(&orig.probe_failed),
106                 probe_successful: Clone::clone(&orig.probe_successful),
107                 write: Clone::clone(&orig.write),
108                 free: Clone::clone(&orig.free),
109         }
110 }
111 impl lightning::util::ser::Writeable for Score {
112         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
113                 let vec = (self.write)(self.this_arg);
114                 w.write_all(vec.as_slice())
115         }
116 }
117
118 use lightning::routing::scoring::Score as rustScore;
119 impl rustScore for Score {
120         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 {
121                 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 });
122                 ret
123         }
124         fn payment_path_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) {
125                 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 } }); };
126                 (self.payment_path_failed)(self.this_arg, local_path.into(), short_channel_id)
127         }
128         fn payment_path_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) {
129                 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 } }); };
130                 (self.payment_path_successful)(self.this_arg, local_path.into())
131         }
132         fn probe_failed(&mut self, mut path: &[&lightning::routing::router::RouteHop], mut short_channel_id: u64) {
133                 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 } }); };
134                 (self.probe_failed)(self.this_arg, local_path.into(), short_channel_id)
135         }
136         fn probe_successful(&mut self, mut path: &[&lightning::routing::router::RouteHop]) {
137                 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 } }); };
138                 (self.probe_successful)(self.this_arg, local_path.into())
139         }
140 }
141
142 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
143 // directly as a Deref trait in higher-level structs:
144 impl core::ops::Deref for Score {
145         type Target = Self;
146         fn deref(&self) -> &Self {
147                 self
148         }
149 }
150 /// Calls the free function if one is set
151 #[no_mangle]
152 pub extern "C" fn Score_free(this_ptr: Score) { }
153 impl Drop for Score {
154         fn drop(&mut self) {
155                 if let Some(f) = self.free {
156                         f(self.this_arg);
157                 }
158         }
159 }
160 /// A scorer that is accessed under a lock.
161 ///
162 /// Needed so that calls to [`Score::channel_penalty_msat`] in [`find_route`] can be made while
163 /// having shared ownership of a scorer but without requiring internal locking in [`Score`]
164 /// implementations. Internal locking would be detrimental to route finding performance and could
165 /// result in [`Score::channel_penalty_msat`] returning a different value for the same channel.
166 ///
167 /// [`find_route`]: crate::routing::router::find_route
168 #[repr(C)]
169 pub struct LockableScore {
170         /// An opaque pointer which is passed to your function implementations as an argument.
171         /// This has no meaning in the LDK, and can be NULL or any other value.
172         pub this_arg: *mut c_void,
173         /// Returns the locked scorer.
174         #[must_use]
175         pub lock: extern "C" fn (this_arg: *const c_void) -> crate::lightning::routing::scoring::Score,
176         /// Frees any resources associated with this object given its this_arg pointer.
177         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
178         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
179 }
180 unsafe impl Send for LockableScore {}
181 unsafe impl Sync for LockableScore {}
182 #[no_mangle]
183 pub(crate) extern "C" fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore {
184         LockableScore {
185                 this_arg: orig.this_arg,
186                 lock: Clone::clone(&orig.lock),
187                 free: Clone::clone(&orig.free),
188         }
189 }
190
191 use lightning::routing::scoring::LockableScore as rustLockableScore;
192 impl<'a> rustLockableScore<'a> for LockableScore {
193         type Locked = crate::lightning::routing::scoring::Score;
194         fn lock(&'a self) -> crate::lightning::routing::scoring::Score {
195                 let mut ret = (self.lock)(self.this_arg);
196                 ret
197         }
198 }
199
200 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
201 // directly as a Deref trait in higher-level structs:
202 impl core::ops::Deref for LockableScore {
203         type Target = Self;
204         fn deref(&self) -> &Self {
205                 self
206         }
207 }
208 /// Calls the free function if one is set
209 #[no_mangle]
210 pub extern "C" fn LockableScore_free(this_ptr: LockableScore) { }
211 impl Drop for LockableScore {
212         fn drop(&mut self) {
213                 if let Some(f) = self.free {
214                         f(self.this_arg);
215                 }
216         }
217 }
218 /// Refers to a scorer that is accessible under lock and also writeable to disk
219 ///
220 /// We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to
221 /// use the Persister to persist it.
222 #[repr(C)]
223 pub struct WriteableScore {
224         /// An opaque pointer which is passed to your function implementations as an argument.
225         /// This has no meaning in the LDK, and can be NULL or any other value.
226         pub this_arg: *mut c_void,
227         /// Implementation of LockableScore for this object.
228         pub LockableScore: crate::lightning::routing::scoring::LockableScore,
229         /// Serialize the object into a byte array
230         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
231         /// Frees any resources associated with this object given its this_arg pointer.
232         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
233         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
234 }
235 unsafe impl Send for WriteableScore {}
236 unsafe impl Sync for WriteableScore {}
237 #[no_mangle]
238 pub(crate) extern "C" fn WriteableScore_clone_fields(orig: &WriteableScore) -> WriteableScore {
239         WriteableScore {
240                 this_arg: orig.this_arg,
241                 LockableScore: crate::lightning::routing::scoring::LockableScore_clone_fields(&orig.LockableScore),
242                 write: Clone::clone(&orig.write),
243                 free: Clone::clone(&orig.free),
244         }
245 }
246 impl<'a> lightning::routing::scoring::LockableScore<'a> for WriteableScore {
247         type Locked = crate::lightning::routing::scoring::Score;
248         fn lock(&'a self) -> crate::lightning::routing::scoring::Score {
249                 let mut ret = (self.LockableScore.lock)(self.LockableScore.this_arg);
250                 ret
251         }
252 }
253 impl lightning::util::ser::Writeable for WriteableScore {
254         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
255                 let vec = (self.write)(self.this_arg);
256                 w.write_all(vec.as_slice())
257         }
258 }
259
260 use lightning::routing::scoring::WriteableScore as rustWriteableScore;
261 impl<'a> rustWriteableScore<'a> for WriteableScore {
262 }
263
264 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
265 // directly as a Deref trait in higher-level structs:
266 impl core::ops::Deref for WriteableScore {
267         type Target = Self;
268         fn deref(&self) -> &Self {
269                 self
270         }
271 }
272 /// Calls the free function if one is set
273 #[no_mangle]
274 pub extern "C" fn WriteableScore_free(this_ptr: WriteableScore) { }
275 impl Drop for WriteableScore {
276         fn drop(&mut self) {
277                 if let Some(f) = self.free {
278                         f(self.this_arg);
279                 }
280         }
281 }
282
283 use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport;
284 pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport<crate::lightning::routing::scoring::Score>;
285
286 /// A concrete implementation of [`LockableScore`] which supports multi-threading.
287 #[must_use]
288 #[repr(C)]
289 pub struct MultiThreadedLockableScore {
290         /// A pointer to the opaque Rust object.
291
292         /// Nearly everywhere, inner must be non-null, however in places where
293         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
294         pub inner: *mut nativeMultiThreadedLockableScore,
295         /// Indicates that this is the only struct which contains the same pointer.
296
297         /// Rust functions which take ownership of an object provided via an argument require
298         /// this to be true and invalidate the object pointed to by inner.
299         pub is_owned: bool,
300 }
301
302 impl Drop for MultiThreadedLockableScore {
303         fn drop(&mut self) {
304                 if self.is_owned && !<*mut nativeMultiThreadedLockableScore>::is_null(self.inner) {
305                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
306                 }
307         }
308 }
309 /// Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL.
310 #[no_mangle]
311 pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockableScore) { }
312 #[allow(unused)]
313 /// Used only if an object of this type is returned as a trait impl by a method
314 pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) {
315         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore); }
316 }
317 #[allow(unused)]
318 impl MultiThreadedLockableScore {
319         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedLockableScore {
320                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
321         }
322         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedLockableScore {
323                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
324         }
325         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
326         pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedLockableScore {
327                 assert!(self.is_owned);
328                 let ret = ObjOps::untweak_ptr(self.inner);
329                 self.inner = core::ptr::null_mut();
330                 ret
331         }
332 }
333
334 use lightning::routing::scoring::MultiThreadedScoreLock as nativeMultiThreadedScoreLockImport;
335 pub(crate) type nativeMultiThreadedScoreLock = nativeMultiThreadedScoreLockImport<'static, crate::lightning::routing::scoring::Score>;
336
337 /// A locked `MultiThreadedLockableScore`.
338 #[must_use]
339 #[repr(C)]
340 pub struct MultiThreadedScoreLock {
341         /// A pointer to the opaque Rust object.
342
343         /// Nearly everywhere, inner must be non-null, however in places where
344         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
345         pub inner: *mut nativeMultiThreadedScoreLock,
346         /// Indicates that this is the only struct which contains the same pointer.
347
348         /// Rust functions which take ownership of an object provided via an argument require
349         /// this to be true and invalidate the object pointed to by inner.
350         pub is_owned: bool,
351 }
352
353 impl Drop for MultiThreadedScoreLock {
354         fn drop(&mut self) {
355                 if self.is_owned && !<*mut nativeMultiThreadedScoreLock>::is_null(self.inner) {
356                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
357                 }
358         }
359 }
360 /// Frees any resources used by the MultiThreadedScoreLock, if is_owned is set and inner is non-NULL.
361 #[no_mangle]
362 pub extern "C" fn MultiThreadedScoreLock_free(this_obj: MultiThreadedScoreLock) { }
363 #[allow(unused)]
364 /// Used only if an object of this type is returned as a trait impl by a method
365 pub(crate) extern "C" fn MultiThreadedScoreLock_free_void(this_ptr: *mut c_void) {
366         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLock); }
367 }
368 #[allow(unused)]
369 impl MultiThreadedScoreLock {
370         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedScoreLock {
371                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
372         }
373         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedScoreLock {
374                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
375         }
376         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
377         pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedScoreLock {
378                 assert!(self.is_owned);
379                 let ret = ObjOps::untweak_ptr(self.inner);
380                 self.inner = core::ptr::null_mut();
381                 ret
382         }
383 }
384 impl From<nativeMultiThreadedScoreLock> for crate::lightning::routing::scoring::Score {
385         fn from(obj: nativeMultiThreadedScoreLock) -> Self {
386                 let mut rust_obj = MultiThreadedScoreLock { inner: ObjOps::heap_alloc(obj), is_owned: true };
387                 let mut ret = MultiThreadedScoreLock_as_Score(&rust_obj);
388                 // 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
389                 rust_obj.inner = core::ptr::null_mut();
390                 ret.free = Some(MultiThreadedScoreLock_free_void);
391                 ret
392         }
393 }
394 /// Constructs a new Score which calls the relevant methods on this_arg.
395 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
396 #[no_mangle]
397 pub extern "C" fn MultiThreadedScoreLock_as_Score(this_arg: &MultiThreadedScoreLock) -> crate::lightning::routing::scoring::Score {
398         crate::lightning::routing::scoring::Score {
399                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
400                 free: None,
401                 channel_penalty_msat: MultiThreadedScoreLock_Score_channel_penalty_msat,
402                 payment_path_failed: MultiThreadedScoreLock_Score_payment_path_failed,
403                 payment_path_successful: MultiThreadedScoreLock_Score_payment_path_successful,
404                 probe_failed: MultiThreadedScoreLock_Score_probe_failed,
405                 probe_successful: MultiThreadedScoreLock_Score_probe_successful,
406                 write: MultiThreadedScoreLock_write_void,
407         }
408 }
409
410 #[must_use]
411 extern "C" fn MultiThreadedScoreLock_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 {
412         let mut ret = <nativeMultiThreadedScoreLock as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) });
413         ret
414 }
415 extern "C" fn MultiThreadedScoreLock_Score_payment_path_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
416         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
417         <nativeMultiThreadedScoreLock as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..], short_channel_id)
418 }
419 extern "C" fn MultiThreadedScoreLock_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
420         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
421         <nativeMultiThreadedScoreLock as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..])
422 }
423 extern "C" fn MultiThreadedScoreLock_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
424         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
425         <nativeMultiThreadedScoreLock as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..], short_channel_id)
426 }
427 extern "C" fn MultiThreadedScoreLock_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
428         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
429         <nativeMultiThreadedScoreLock as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLock) }, &local_path[..])
430 }
431
432 #[no_mangle]
433 /// Serialize the MultiThreadedScoreLock object into a byte array which can be read by MultiThreadedScoreLock_read
434 pub extern "C" fn MultiThreadedScoreLock_write(obj: &crate::lightning::routing::scoring::MultiThreadedScoreLock) -> crate::c_types::derived::CVec_u8Z {
435         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
436 }
437 #[no_mangle]
438 pub(crate) extern "C" fn MultiThreadedScoreLock_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
439         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedScoreLock) })
440 }
441 impl From<nativeMultiThreadedLockableScore> for crate::lightning::routing::scoring::LockableScore {
442         fn from(obj: nativeMultiThreadedLockableScore) -> Self {
443                 let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true };
444                 let mut ret = MultiThreadedLockableScore_as_LockableScore(&rust_obj);
445                 // 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
446                 rust_obj.inner = core::ptr::null_mut();
447                 ret.free = Some(MultiThreadedLockableScore_free_void);
448                 ret
449         }
450 }
451 /// Constructs a new LockableScore which calls the relevant methods on this_arg.
452 /// This copies the `inner` pointer in this_arg and thus the returned LockableScore must be freed before this_arg is
453 #[no_mangle]
454 pub extern "C" fn MultiThreadedLockableScore_as_LockableScore(this_arg: &MultiThreadedLockableScore) -> crate::lightning::routing::scoring::LockableScore {
455         crate::lightning::routing::scoring::LockableScore {
456                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
457                 free: None,
458                 lock: MultiThreadedLockableScore_LockableScore_lock,
459         }
460 }
461
462 #[must_use]
463 extern "C" fn MultiThreadedLockableScore_LockableScore_lock(this_arg: *const c_void) -> crate::lightning::routing::scoring::Score {
464         let mut ret = <nativeMultiThreadedLockableScore as lightning::routing::scoring::LockableScore<>>::lock(unsafe { &mut *(this_arg as *mut nativeMultiThreadedLockableScore) }, );
465         Into::into(ret)
466 }
467
468 /// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
469 #[must_use]
470 #[no_mangle]
471 pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> crate::lightning::routing::scoring::MultiThreadedLockableScore {
472         let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score);
473         crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true }
474 }
475
476
477 use lightning::routing::scoring::ChannelUsage as nativeChannelUsageImport;
478 pub(crate) type nativeChannelUsage = nativeChannelUsageImport;
479
480 /// Proposed use of a channel passed as a parameter to [`Score::channel_penalty_msat`].
481 #[must_use]
482 #[repr(C)]
483 pub struct ChannelUsage {
484         /// A pointer to the opaque Rust object.
485
486         /// Nearly everywhere, inner must be non-null, however in places where
487         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
488         pub inner: *mut nativeChannelUsage,
489         /// Indicates that this is the only struct which contains the same pointer.
490
491         /// Rust functions which take ownership of an object provided via an argument require
492         /// this to be true and invalidate the object pointed to by inner.
493         pub is_owned: bool,
494 }
495
496 impl Drop for ChannelUsage {
497         fn drop(&mut self) {
498                 if self.is_owned && !<*mut nativeChannelUsage>::is_null(self.inner) {
499                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
500                 }
501         }
502 }
503 /// Frees any resources used by the ChannelUsage, if is_owned is set and inner is non-NULL.
504 #[no_mangle]
505 pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { }
506 #[allow(unused)]
507 /// Used only if an object of this type is returned as a trait impl by a method
508 pub(crate) extern "C" fn ChannelUsage_free_void(this_ptr: *mut c_void) {
509         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUsage); }
510 }
511 #[allow(unused)]
512 impl ChannelUsage {
513         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUsage {
514                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
515         }
516         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUsage {
517                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
518         }
519         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
520         pub(crate) fn take_inner(mut self) -> *mut nativeChannelUsage {
521                 assert!(self.is_owned);
522                 let ret = ObjOps::untweak_ptr(self.inner);
523                 self.inner = core::ptr::null_mut();
524                 ret
525         }
526 }
527 /// The amount to send through the channel, denominated in millisatoshis.
528 #[no_mangle]
529 pub extern "C" fn ChannelUsage_get_amount_msat(this_ptr: &ChannelUsage) -> u64 {
530         let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
531         *inner_val
532 }
533 /// The amount to send through the channel, denominated in millisatoshis.
534 #[no_mangle]
535 pub extern "C" fn ChannelUsage_set_amount_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
536         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
537 }
538 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
539 /// as part of a multi-path payment.
540 #[no_mangle]
541 pub extern "C" fn ChannelUsage_get_inflight_htlc_msat(this_ptr: &ChannelUsage) -> u64 {
542         let mut inner_val = &mut this_ptr.get_native_mut_ref().inflight_htlc_msat;
543         *inner_val
544 }
545 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
546 /// as part of a multi-path payment.
547 #[no_mangle]
548 pub extern "C" fn ChannelUsage_set_inflight_htlc_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
549         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inflight_htlc_msat = val;
550 }
551 /// The effective capacity of the channel.
552 #[no_mangle]
553 pub extern "C" fn ChannelUsage_get_effective_capacity(this_ptr: &ChannelUsage) -> crate::lightning::routing::gossip::EffectiveCapacity {
554         let mut inner_val = &mut this_ptr.get_native_mut_ref().effective_capacity;
555         crate::lightning::routing::gossip::EffectiveCapacity::from_native(inner_val)
556 }
557 /// The effective capacity of the channel.
558 #[no_mangle]
559 pub extern "C" fn ChannelUsage_set_effective_capacity(this_ptr: &mut ChannelUsage, mut val: crate::lightning::routing::gossip::EffectiveCapacity) {
560         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.effective_capacity = val.into_native();
561 }
562 /// Constructs a new ChannelUsage given each field
563 #[must_use]
564 #[no_mangle]
565 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 {
566         ChannelUsage { inner: ObjOps::heap_alloc(nativeChannelUsage {
567                 amount_msat: amount_msat_arg,
568                 inflight_htlc_msat: inflight_htlc_msat_arg,
569                 effective_capacity: effective_capacity_arg.into_native(),
570         }), is_owned: true }
571 }
572 impl Clone for ChannelUsage {
573         fn clone(&self) -> Self {
574                 Self {
575                         inner: if <*mut nativeChannelUsage>::is_null(self.inner) { core::ptr::null_mut() } else {
576                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
577                         is_owned: true,
578                 }
579         }
580 }
581 #[allow(unused)]
582 /// Used only if an object of this type is returned as a trait impl by a method
583 pub(crate) extern "C" fn ChannelUsage_clone_void(this_ptr: *const c_void) -> *mut c_void {
584         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUsage)).clone() })) as *mut c_void
585 }
586 #[no_mangle]
587 /// Creates a copy of the ChannelUsage
588 pub extern "C" fn ChannelUsage_clone(orig: &ChannelUsage) -> ChannelUsage {
589         orig.clone()
590 }
591
592 use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport;
593 pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport;
594
595 /// [`Score`] implementation that uses a fixed penalty.
596 #[must_use]
597 #[repr(C)]
598 pub struct FixedPenaltyScorer {
599         /// A pointer to the opaque Rust object.
600
601         /// Nearly everywhere, inner must be non-null, however in places where
602         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
603         pub inner: *mut nativeFixedPenaltyScorer,
604         /// Indicates that this is the only struct which contains the same pointer.
605
606         /// Rust functions which take ownership of an object provided via an argument require
607         /// this to be true and invalidate the object pointed to by inner.
608         pub is_owned: bool,
609 }
610
611 impl Drop for FixedPenaltyScorer {
612         fn drop(&mut self) {
613                 if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) {
614                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
615                 }
616         }
617 }
618 /// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL.
619 #[no_mangle]
620 pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { }
621 #[allow(unused)]
622 /// Used only if an object of this type is returned as a trait impl by a method
623 pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) {
624         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer); }
625 }
626 #[allow(unused)]
627 impl FixedPenaltyScorer {
628         pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer {
629                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
630         }
631         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer {
632                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
633         }
634         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
635         pub(crate) fn take_inner(mut self) -> *mut nativeFixedPenaltyScorer {
636                 assert!(self.is_owned);
637                 let ret = ObjOps::untweak_ptr(self.inner);
638                 self.inner = core::ptr::null_mut();
639                 ret
640         }
641 }
642 impl Clone for FixedPenaltyScorer {
643         fn clone(&self) -> Self {
644                 Self {
645                         inner: if <*mut nativeFixedPenaltyScorer>::is_null(self.inner) { core::ptr::null_mut() } else {
646                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
647                         is_owned: true,
648                 }
649         }
650 }
651 #[allow(unused)]
652 /// Used only if an object of this type is returned as a trait impl by a method
653 pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void {
654         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void
655 }
656 #[no_mangle]
657 /// Creates a copy of the FixedPenaltyScorer
658 pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer {
659         orig.clone()
660 }
661 /// Creates a new scorer using `penalty_msat`.
662 #[must_use]
663 #[no_mangle]
664 pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> crate::lightning::routing::scoring::FixedPenaltyScorer {
665         let mut ret = lightning::routing::scoring::FixedPenaltyScorer::with_penalty(penalty_msat);
666         crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
667 }
668
669 impl From<nativeFixedPenaltyScorer> for crate::lightning::routing::scoring::Score {
670         fn from(obj: nativeFixedPenaltyScorer) -> Self {
671                 let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
672                 let mut ret = FixedPenaltyScorer_as_Score(&rust_obj);
673                 // 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
674                 rust_obj.inner = core::ptr::null_mut();
675                 ret.free = Some(FixedPenaltyScorer_free_void);
676                 ret
677         }
678 }
679 /// Constructs a new Score which calls the relevant methods on this_arg.
680 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
681 #[no_mangle]
682 pub extern "C" fn FixedPenaltyScorer_as_Score(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::Score {
683         crate::lightning::routing::scoring::Score {
684                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
685                 free: None,
686                 channel_penalty_msat: FixedPenaltyScorer_Score_channel_penalty_msat,
687                 payment_path_failed: FixedPenaltyScorer_Score_payment_path_failed,
688                 payment_path_successful: FixedPenaltyScorer_Score_payment_path_successful,
689                 probe_failed: FixedPenaltyScorer_Score_probe_failed,
690                 probe_successful: FixedPenaltyScorer_Score_probe_successful,
691                 write: FixedPenaltyScorer_write_void,
692         }
693 }
694
695 #[must_use]
696 extern "C" fn FixedPenaltyScorer_Score_channel_penalty_msat(this_arg: *const c_void, mut short_channel_id: u64, source: &crate::lightning::routing::gossip::NodeId, target: &crate::lightning::routing::gossip::NodeId, mut usage: crate::lightning::routing::scoring::ChannelUsage) -> u64 {
697         let mut ret = <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) });
698         ret
699 }
700 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) {
701         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
702         <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..], short_channel_id)
703 }
704 extern "C" fn FixedPenaltyScorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
705         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
706         <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..])
707 }
708 extern "C" fn FixedPenaltyScorer_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
709         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
710         <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..], short_channel_id)
711 }
712 extern "C" fn FixedPenaltyScorer_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
713         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
714         <nativeFixedPenaltyScorer as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, &local_path[..])
715 }
716
717 #[no_mangle]
718 /// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read
719 pub extern "C" fn FixedPenaltyScorer_write(obj: &crate::lightning::routing::scoring::FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z {
720         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
721 }
722 #[no_mangle]
723 pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
724         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) })
725 }
726 #[no_mangle]
727 /// Read a FixedPenaltyScorer from a byte array, created by FixedPenaltyScorer_write
728 pub extern "C" fn FixedPenaltyScorer_read(ser: crate::c_types::u8slice, arg: u64) -> crate::c_types::derived::CResult_FixedPenaltyScorerDecodeErrorZ {
729         let arg_conv = arg;
730         let res: Result<lightning::routing::scoring::FixedPenaltyScorer, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
731         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() };
732         local_res
733 }
734
735 use lightning::routing::scoring::ProbabilisticScorer as nativeProbabilisticScorerImport;
736 pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger>;
737
738 /// [`Score`] implementation using channel success probability distributions.
739 ///
740 /// Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
741 /// and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability
742 /// distributions are defined based on knowledge learned from successful and unsuccessful attempts.
743 /// Then the negative `log10` of the success probability is used to determine the cost of routing a
744 /// specific HTLC amount through a channel.
745 ///
746 /// Knowledge about channel liquidity balances takes the form of upper and lower bounds on the
747 /// possible liquidity. Certainty of the bounds is decreased over time using a decay function. See
748 /// [`ProbabilisticScoringParameters`] for details.
749 ///
750 /// Since the scorer aims to learn the current channel liquidity balances, it works best for nodes
751 /// with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment
752 /// volume are more likely to experience failed payment paths, which would need to be retried.
753 ///
754 /// # Note
755 ///
756 /// Mixing the `no-std` feature between serialization and deserialization results in undefined
757 /// behavior.
758 ///
759 /// [1]: https://arxiv.org/abs/2107.05322
760 #[must_use]
761 #[repr(C)]
762 pub struct ProbabilisticScorer {
763         /// A pointer to the opaque Rust object.
764
765         /// Nearly everywhere, inner must be non-null, however in places where
766         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
767         pub inner: *mut nativeProbabilisticScorer,
768         /// Indicates that this is the only struct which contains the same pointer.
769
770         /// Rust functions which take ownership of an object provided via an argument require
771         /// this to be true and invalidate the object pointed to by inner.
772         pub is_owned: bool,
773 }
774
775 impl Drop for ProbabilisticScorer {
776         fn drop(&mut self) {
777                 if self.is_owned && !<*mut nativeProbabilisticScorer>::is_null(self.inner) {
778                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
779                 }
780         }
781 }
782 /// Frees any resources used by the ProbabilisticScorer, if is_owned is set and inner is non-NULL.
783 #[no_mangle]
784 pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { }
785 #[allow(unused)]
786 /// Used only if an object of this type is returned as a trait impl by a method
787 pub(crate) extern "C" fn ProbabilisticScorer_free_void(this_ptr: *mut c_void) {
788         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScorer); }
789 }
790 #[allow(unused)]
791 impl ProbabilisticScorer {
792         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScorer {
793                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
794         }
795         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScorer {
796                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
797         }
798         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
799         pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScorer {
800                 assert!(self.is_owned);
801                 let ret = ObjOps::untweak_ptr(self.inner);
802                 self.inner = core::ptr::null_mut();
803                 ret
804         }
805 }
806
807 use lightning::routing::scoring::ProbabilisticScoringParameters as nativeProbabilisticScoringParametersImport;
808 pub(crate) type nativeProbabilisticScoringParameters = nativeProbabilisticScoringParametersImport;
809
810 /// Parameters for configuring [`ProbabilisticScorer`].
811 ///
812 /// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
813 /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
814 ///
815 /// The penalty applied to any channel by the [`ProbabilisticScorer`] is the sum of each of the
816 /// parameters here.
817 #[must_use]
818 #[repr(C)]
819 pub struct ProbabilisticScoringParameters {
820         /// A pointer to the opaque Rust object.
821
822         /// Nearly everywhere, inner must be non-null, however in places where
823         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
824         pub inner: *mut nativeProbabilisticScoringParameters,
825         /// Indicates that this is the only struct which contains the same pointer.
826
827         /// Rust functions which take ownership of an object provided via an argument require
828         /// this to be true and invalidate the object pointed to by inner.
829         pub is_owned: bool,
830 }
831
832 impl Drop for ProbabilisticScoringParameters {
833         fn drop(&mut self) {
834                 if self.is_owned && !<*mut nativeProbabilisticScoringParameters>::is_null(self.inner) {
835                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
836                 }
837         }
838 }
839 /// Frees any resources used by the ProbabilisticScoringParameters, if is_owned is set and inner is non-NULL.
840 #[no_mangle]
841 pub extern "C" fn ProbabilisticScoringParameters_free(this_obj: ProbabilisticScoringParameters) { }
842 #[allow(unused)]
843 /// Used only if an object of this type is returned as a trait impl by a method
844 pub(crate) extern "C" fn ProbabilisticScoringParameters_free_void(this_ptr: *mut c_void) {
845         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters); }
846 }
847 #[allow(unused)]
848 impl ProbabilisticScoringParameters {
849         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScoringParameters {
850                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
851         }
852         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScoringParameters {
853                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
854         }
855         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
856         pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScoringParameters {
857                 assert!(self.is_owned);
858                 let ret = ObjOps::untweak_ptr(self.inner);
859                 self.inner = core::ptr::null_mut();
860                 ret
861         }
862 }
863 /// A fixed penalty in msats to apply to each channel.
864 ///
865 /// Default value: 500 msat
866 #[no_mangle]
867 pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
868         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat;
869         *inner_val
870 }
871 /// A fixed penalty in msats to apply to each channel.
872 ///
873 /// Default value: 500 msat
874 #[no_mangle]
875 pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
876         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val;
877 }
878 /// A multiplier used with the payment amount to calculate a fixed penalty applied to each
879 /// channel, in excess of the [`base_penalty_msat`].
880 ///
881 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
882 /// fees plus penalty) for large payments. The penalty is computed as the product of this
883 /// multiplier and `2^30`ths of the payment amount.
884 ///
885 /// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30`
886 ///
887 /// Default value: 8,192 msat
888 ///
889 /// [`base_penalty_msat`]: Self::base_penalty_msat
890 #[no_mangle]
891 pub extern "C" fn ProbabilisticScoringParameters_get_base_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
892         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_amount_multiplier_msat;
893         *inner_val
894 }
895 /// A multiplier used with the payment amount to calculate a fixed penalty applied to each
896 /// channel, in excess of the [`base_penalty_msat`].
897 ///
898 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
899 /// fees plus penalty) for large payments. The penalty is computed as the product of this
900 /// multiplier and `2^30`ths of the payment amount.
901 ///
902 /// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30`
903 ///
904 /// Default value: 8,192 msat
905 ///
906 /// [`base_penalty_msat`]: Self::base_penalty_msat
907 #[no_mangle]
908 pub extern "C" fn ProbabilisticScoringParameters_set_base_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
909         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_amount_multiplier_msat = val;
910 }
911 /// A multiplier used in conjunction with the negative `log10` of the channel's success
912 /// probability for a payment to determine the liquidity penalty.
913 ///
914 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
915 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
916 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
917 /// lower bounding the success probability to `0.01`) when the amount falls within the
918 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
919 /// result in a `u64::max_value` penalty, however.
920 ///
921 /// Default value: 40,000 msat
922 ///
923 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
924 #[no_mangle]
925 pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
926         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_multiplier_msat;
927         *inner_val
928 }
929 /// A multiplier used in conjunction with the negative `log10` of the channel's success
930 /// probability for a payment to determine the liquidity penalty.
931 ///
932 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
933 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
934 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
935 /// lower bounding the success probability to `0.01`) when the amount falls within the
936 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
937 /// result in a `u64::max_value` penalty, however.
938 ///
939 /// Default value: 40,000 msat
940 ///
941 /// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
942 #[no_mangle]
943 pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
944         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_multiplier_msat = val;
945 }
946 /// The time required to elapse before any knowledge learned about channel liquidity balances is
947 /// cut in half.
948 ///
949 /// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets
950 /// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases
951 /// the certainty of the channel liquidity balance.
952 ///
953 /// Default value: 1 hour
954 ///
955 /// # Note
956 ///
957 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
958 /// liquidity knowledge will never decay except when the bounds cross.
959 #[no_mangle]
960 pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_offset_half_life(this_ptr: &ProbabilisticScoringParameters) -> u64 {
961         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_offset_half_life;
962         inner_val.as_secs()
963 }
964 /// The time required to elapse before any knowledge learned about channel liquidity balances is
965 /// cut in half.
966 ///
967 /// The bounds are defined in terms of offsets and are initially zero. Increasing the offsets
968 /// gives tighter bounds on the channel liquidity balance. Thus, halving the offsets decreases
969 /// the certainty of the channel liquidity balance.
970 ///
971 /// Default value: 1 hour
972 ///
973 /// # Note
974 ///
975 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
976 /// liquidity knowledge will never decay except when the bounds cross.
977 #[no_mangle]
978 pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_offset_half_life(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
979         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_offset_half_life = core::time::Duration::from_secs(val);
980 }
981 /// A multiplier used in conjunction with a payment amount and the negative `log10` of the
982 /// channel's success probability for the payment to determine the amount penalty.
983 ///
984 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
985 /// fees plus penalty) for large payments. The penalty is computed as the product of this
986 /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the
987 /// success probability.
988 ///
989 /// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20`
990 ///
991 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
992 /// the amount will result in a penalty of the multiplier. And, as the success probability
993 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
994 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
995 /// fall below `1`.
996 ///
997 /// Default value: 256 msat
998 #[no_mangle]
999 pub extern "C" fn ProbabilisticScoringParameters_get_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
1000         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_amount_multiplier_msat;
1001         *inner_val
1002 }
1003 /// A multiplier used in conjunction with a payment amount and the negative `log10` of the
1004 /// channel's success probability for the payment to determine the amount penalty.
1005 ///
1006 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
1007 /// fees plus penalty) for large payments. The penalty is computed as the product of this
1008 /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the
1009 /// success probability.
1010 ///
1011 /// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20`
1012 ///
1013 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
1014 /// the amount will result in a penalty of the multiplier. And, as the success probability
1015 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
1016 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
1017 /// fall below `1`.
1018 ///
1019 /// Default value: 256 msat
1020 #[no_mangle]
1021 pub extern "C" fn ProbabilisticScoringParameters_set_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
1022         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_amount_multiplier_msat = val;
1023 }
1024 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
1025 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
1026 /// treat such nodes preferentially as this makes balance discovery attacks harder to execute,
1027 /// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy.
1028 ///
1029 /// Default value: 250 msat
1030 #[no_mangle]
1031 pub extern "C" fn ProbabilisticScoringParameters_get_anti_probing_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
1032         let mut inner_val = &mut this_ptr.get_native_mut_ref().anti_probing_penalty_msat;
1033         *inner_val
1034 }
1035 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
1036 /// channel's capacity, which makes us prefer nodes with a smaller `htlc_maximum_msat`. We
1037 /// treat such nodes preferentially as this makes balance discovery attacks harder to execute,
1038 /// thereby creating an incentive to restrict `htlc_maximum_msat` and improve privacy.
1039 ///
1040 /// Default value: 250 msat
1041 #[no_mangle]
1042 pub extern "C" fn ProbabilisticScoringParameters_set_anti_probing_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
1043         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.anti_probing_penalty_msat = val;
1044 }
1045 /// This penalty is applied when the amount we're attempting to send over a channel exceeds our
1046 /// current estimate of the channel's available liquidity.
1047 ///
1048 /// Note that in this case all other penalties, including the
1049 /// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based
1050 /// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if
1051 /// applicable, are still included in the overall penalty.
1052 ///
1053 /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
1054 /// `u64::max_value()` will guarantee that.
1055 ///
1056 /// Default value: 1_0000_0000_000 msat (1 Bitcoin)
1057 ///
1058 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1059 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1060 /// [`base_penalty_msat`]: Self::base_penalty_msat
1061 /// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat
1062 #[no_mangle]
1063 pub extern "C" fn ProbabilisticScoringParameters_get_considered_impossible_penalty_msat(this_ptr: &ProbabilisticScoringParameters) -> u64 {
1064         let mut inner_val = &mut this_ptr.get_native_mut_ref().considered_impossible_penalty_msat;
1065         *inner_val
1066 }
1067 /// This penalty is applied when the amount we're attempting to send over a channel exceeds our
1068 /// current estimate of the channel's available liquidity.
1069 ///
1070 /// Note that in this case all other penalties, including the
1071 /// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based
1072 /// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if
1073 /// applicable, are still included in the overall penalty.
1074 ///
1075 /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
1076 /// `u64::max_value()` will guarantee that.
1077 ///
1078 /// Default value: 1_0000_0000_000 msat (1 Bitcoin)
1079 ///
1080 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1081 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1082 /// [`base_penalty_msat`]: Self::base_penalty_msat
1083 /// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat
1084 #[no_mangle]
1085 pub extern "C" fn ProbabilisticScoringParameters_set_considered_impossible_penalty_msat(this_ptr: &mut ProbabilisticScoringParameters, mut val: u64) {
1086         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.considered_impossible_penalty_msat = val;
1087 }
1088 impl Clone for ProbabilisticScoringParameters {
1089         fn clone(&self) -> Self {
1090                 Self {
1091                         inner: if <*mut nativeProbabilisticScoringParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1092                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1093                         is_owned: true,
1094                 }
1095         }
1096 }
1097 #[allow(unused)]
1098 /// Used only if an object of this type is returned as a trait impl by a method
1099 pub(crate) extern "C" fn ProbabilisticScoringParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1100         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringParameters)).clone() })) as *mut c_void
1101 }
1102 #[no_mangle]
1103 /// Creates a copy of the ProbabilisticScoringParameters
1104 pub extern "C" fn ProbabilisticScoringParameters_clone(orig: &ProbabilisticScoringParameters) -> ProbabilisticScoringParameters {
1105         orig.clone()
1106 }
1107 /// Creates a new scorer using the given scoring parameters for sending payments from a node
1108 /// through a network graph.
1109 #[must_use]
1110 #[no_mangle]
1111 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 {
1112         let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(params.take_inner()) }, network_graph.get_native_ref(), logger);
1113         crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
1114 }
1115
1116 /// Dump the contents of this scorer into the configured logger.
1117 ///
1118 /// Note that this writes roughly one line per channel for which we have a liquidity estimate,
1119 /// which may be a substantial amount of log output.
1120 #[no_mangle]
1121 pub extern "C" fn ProbabilisticScorer_debug_log_liquidity_stats(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer) {
1122         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.debug_log_liquidity_stats()
1123 }
1124
1125 /// Query the estimated minimum and maximum liquidity available for sending a payment over the
1126 /// channel with `scid` towards the given `target` node.
1127 #[must_use]
1128 #[no_mangle]
1129 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 {
1130         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.estimated_channel_liquidity_range(scid, target.get_native_ref());
1131         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 }) };
1132         local_ret
1133 }
1134
1135 /// Marks the node with the given `node_id` as banned, i.e.,
1136 /// it will be avoided during path finding.
1137 #[no_mangle]
1138 pub extern "C" fn ProbabilisticScorer_add_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) {
1139         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.add_banned(node_id.get_native_ref())
1140 }
1141
1142 /// Removes the node with the given `node_id` from the list of nodes to avoid.
1143 #[no_mangle]
1144 pub extern "C" fn ProbabilisticScorer_remove_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) {
1145         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_banned(node_id.get_native_ref())
1146 }
1147
1148 /// Sets a manual penalty for the given node.
1149 #[no_mangle]
1150 pub extern "C" fn ProbabilisticScorer_set_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId, mut penalty: u64) {
1151         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.set_manual_penalty(node_id.get_native_ref(), penalty)
1152 }
1153
1154 /// Removes the node with the given `node_id` from the list of manual penalties.
1155 #[no_mangle]
1156 pub extern "C" fn ProbabilisticScorer_remove_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer, node_id: &crate::lightning::routing::gossip::NodeId) {
1157         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.remove_manual_penalty(node_id.get_native_ref())
1158 }
1159
1160 /// Clears the list of manual penalties that are applied during path finding.
1161 #[no_mangle]
1162 pub extern "C" fn ProbabilisticScorer_clear_manual_penalties(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScorer) {
1163         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScorer)) }.clear_manual_penalties()
1164 }
1165
1166 /// Marks all nodes in the given list as banned, i.e.,
1167 /// they will be avoided during path finding.
1168 #[no_mangle]
1169 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) {
1170         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()) } }); };
1171         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringParameters)) }.add_banned_from_list(local_node_ids)
1172 }
1173
1174 /// Creates a "default" ProbabilisticScoringParameters. See struct and individual field documentaiton for details on which values are used.
1175 #[must_use]
1176 #[no_mangle]
1177 pub extern "C" fn ProbabilisticScoringParameters_default() -> ProbabilisticScoringParameters {
1178         ProbabilisticScoringParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1179 }
1180 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::Score {
1181         fn from(obj: nativeProbabilisticScorer) -> Self {
1182                 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
1183                 let mut ret = ProbabilisticScorer_as_Score(&rust_obj);
1184                 // 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
1185                 rust_obj.inner = core::ptr::null_mut();
1186                 ret.free = Some(ProbabilisticScorer_free_void);
1187                 ret
1188         }
1189 }
1190 /// Constructs a new Score which calls the relevant methods on this_arg.
1191 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
1192 #[no_mangle]
1193 pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::Score {
1194         crate::lightning::routing::scoring::Score {
1195                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1196                 free: None,
1197                 channel_penalty_msat: ProbabilisticScorer_Score_channel_penalty_msat,
1198                 payment_path_failed: ProbabilisticScorer_Score_payment_path_failed,
1199                 payment_path_successful: ProbabilisticScorer_Score_payment_path_successful,
1200                 probe_failed: ProbabilisticScorer_Score_probe_failed,
1201                 probe_successful: ProbabilisticScorer_Score_probe_successful,
1202                 write: ProbabilisticScorer_write_void,
1203         }
1204 }
1205
1206 #[must_use]
1207 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 {
1208         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()) });
1209         ret
1210 }
1211 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) {
1212         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
1213         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id)
1214 }
1215 extern "C" fn ProbabilisticScorer_Score_payment_path_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
1216         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
1217         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..])
1218 }
1219 extern "C" fn ProbabilisticScorer_Score_probe_failed(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ, mut short_channel_id: u64) {
1220         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
1221         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..], short_channel_id)
1222 }
1223 extern "C" fn ProbabilisticScorer_Score_probe_successful(this_arg: *mut c_void, mut path: crate::c_types::derived::CVec_RouteHopZ) {
1224         let mut local_path = Vec::new(); for mut item in path.as_slice().iter() { local_path.push( { item.get_native_ref() }); };
1225         <nativeProbabilisticScorer as lightning::routing::scoring::Score<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, &local_path[..])
1226 }
1227
1228 mod approx {
1229
1230 use alloc::str::FromStr;
1231 use core::ffi::c_void;
1232 use core::convert::Infallible;
1233 use bitcoin::hashes::Hash;
1234 use crate::c_types::*;
1235 #[cfg(feature="no-std")]
1236 use alloc::{vec::Vec, boxed::Box};
1237
1238 }
1239 #[no_mangle]
1240 /// Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
1241 pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z {
1242         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1243 }
1244 #[no_mangle]
1245 pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1246         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeProbabilisticScorer) })
1247 }
1248 #[no_mangle]
1249 /// Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
1250 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 {
1251         let arg_a_conv = *unsafe { Box::from_raw(arg_a.take_inner()) };
1252         let arg_b_conv = arg_b.get_native_ref();
1253         let arg_c_conv = arg_c;
1254         let arg_conv = (arg_a_conv, arg_b_conv, arg_c_conv);
1255         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);
1256         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() };
1257         local_res
1258 }