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 [`ScoreLookUp`] 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, ProbabilisticScoringFeeParameters, ProbabilisticScoringDecayParameters};
22 //! # use lightning::sign::KeysManager;
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 = ProbabilisticScoringFeeParameters::default();
35 //! let decay_params = ProbabilisticScoringDecayParameters::default();
36 //! let scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger);
37 //!
38 //! // Or use custom channel penalties.
39 //! let params = ProbabilisticScoringFeeParameters {
40 //! \tliquidity_penalty_multiplier_msat: 2 * 1000,
41 //! \t..ProbabilisticScoringFeeParameters::default()
42 //! };
43 //! let decay_params = ProbabilisticScoringDecayParameters::default();
44 //! let scorer = ProbabilisticScorer::new(decay_params, &network_graph, &logger);
45 //! # let random_seed_bytes = [42u8; 32];
46 //!
47 //! let route = find_route(&payer, &route_params, &network_graph, None, &logger, &scorer, &params, &random_seed_bytes);
48 //! # }
49 //! ```
50 //!
51 //! # Note
52 //!
53 //! Persisting when built with feature `no-std` and restoring without it, or vice versa, uses
54 //! different types and thus is undefined.
55 //!
56 //! [`find_route`]: crate::routing::router::find_route
57
58 use alloc::str::FromStr;
59 use alloc::string::String;
60 use core::ffi::c_void;
61 use core::convert::Infallible;
62 use bitcoin::hashes::Hash;
63 use crate::c_types::*;
64 #[cfg(feature="no-std")]
65 use alloc::{vec::Vec, boxed::Box};
66
67 /// An interface used to score payment channels for path finding.
68 ///
69 /// `ScoreLookUp` is used to determine the penalty for a given channel.
70 ///
71 /// Scoring is in terms of fees willing to be paid in order to avoid routing through a channel.
72 #[repr(C)]
73 pub struct ScoreLookUp {
74         /// An opaque pointer which is passed to your function implementations as an argument.
75         /// This has no meaning in the LDK, and can be NULL or any other value.
76         pub this_arg: *mut c_void,
77         /// Returns the fee in msats willing to be paid to avoid routing `send_amt_msat` through the
78         /// given channel in the direction from `source` to `target`.
79         ///
80         /// The channel's capacity (less any other MPP parts that are also being considered for use in
81         /// the same payment) is given by `capacity_msat`. It may be determined from various sources
82         /// such as a chain data, network gossip, or invoice hints. For invoice hints, a capacity near
83         /// [`u64::max_value`] is given to indicate sufficient capacity for the invoice's full amount.
84         /// Thus, implementations should be overflow-safe.
85         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, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64,
86         /// Frees any resources associated with this object given its this_arg pointer.
87         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
88         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
89 }
90 unsafe impl Send for ScoreLookUp {}
91 unsafe impl Sync for ScoreLookUp {}
92 pub(crate) fn ScoreLookUp_clone_fields(orig: &ScoreLookUp) -> ScoreLookUp {
93         ScoreLookUp {
94                 this_arg: orig.this_arg,
95                 channel_penalty_msat: Clone::clone(&orig.channel_penalty_msat),
96                 free: Clone::clone(&orig.free),
97         }
98 }
99
100 use lightning::routing::scoring::ScoreLookUp as rustScoreLookUp;
101 impl rustScoreLookUp for ScoreLookUp {
102         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, mut score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
103                 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 }, &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((score_params as *const lightning::routing::scoring::ProbabilisticScoringFeeParameters<>) as *mut _) }, is_owned: false });
104                 ret
105         }
106 }
107
108 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
109 // directly as a Deref trait in higher-level structs:
110 impl core::ops::Deref for ScoreLookUp {
111         type Target = Self;
112         fn deref(&self) -> &Self {
113                 self
114         }
115 }
116 impl core::ops::DerefMut for ScoreLookUp {
117         fn deref_mut(&mut self) -> &mut Self {
118                 self
119         }
120 }
121 /// Calls the free function if one is set
122 #[no_mangle]
123 pub extern "C" fn ScoreLookUp_free(this_ptr: ScoreLookUp) { }
124 impl Drop for ScoreLookUp {
125         fn drop(&mut self) {
126                 if let Some(f) = self.free {
127                         f(self.this_arg);
128                 }
129         }
130 }
131 /// `ScoreUpdate` is used to update the scorer's internal state after a payment attempt.
132 #[repr(C)]
133 pub struct ScoreUpdate {
134         /// An opaque pointer which is passed to your function implementations as an argument.
135         /// This has no meaning in the LDK, and can be NULL or any other value.
136         pub this_arg: *mut c_void,
137         /// Handles updating channel penalties after failing to route through a channel.
138         pub payment_path_failed: extern "C" fn (this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, short_channel_id: u64),
139         /// Handles updating channel penalties after successfully routing along a path.
140         pub payment_path_successful: extern "C" fn (this_arg: *mut c_void, path: &crate::lightning::routing::router::Path),
141         /// Handles updating channel penalties after a probe over the given path failed.
142         pub probe_failed: extern "C" fn (this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, short_channel_id: u64),
143         /// Handles updating channel penalties after a probe over the given path succeeded.
144         pub probe_successful: extern "C" fn (this_arg: *mut c_void, path: &crate::lightning::routing::router::Path),
145         /// Frees any resources associated with this object given its this_arg pointer.
146         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
147         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
148 }
149 unsafe impl Send for ScoreUpdate {}
150 unsafe impl Sync for ScoreUpdate {}
151 pub(crate) fn ScoreUpdate_clone_fields(orig: &ScoreUpdate) -> ScoreUpdate {
152         ScoreUpdate {
153                 this_arg: orig.this_arg,
154                 payment_path_failed: Clone::clone(&orig.payment_path_failed),
155                 payment_path_successful: Clone::clone(&orig.payment_path_successful),
156                 probe_failed: Clone::clone(&orig.probe_failed),
157                 probe_successful: Clone::clone(&orig.probe_successful),
158                 free: Clone::clone(&orig.free),
159         }
160 }
161
162 use lightning::routing::scoring::ScoreUpdate as rustScoreUpdate;
163 impl rustScoreUpdate for ScoreUpdate {
164         fn payment_path_failed(&mut self, mut path: &lightning::routing::router::Path, mut short_channel_id: u64) {
165                 (self.payment_path_failed)(self.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false }, short_channel_id)
166         }
167         fn payment_path_successful(&mut self, mut path: &lightning::routing::router::Path) {
168                 (self.payment_path_successful)(self.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false })
169         }
170         fn probe_failed(&mut self, mut path: &lightning::routing::router::Path, mut short_channel_id: u64) {
171                 (self.probe_failed)(self.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false }, short_channel_id)
172         }
173         fn probe_successful(&mut self, mut path: &lightning::routing::router::Path) {
174                 (self.probe_successful)(self.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false })
175         }
176 }
177
178 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
179 // directly as a Deref trait in higher-level structs:
180 impl core::ops::Deref for ScoreUpdate {
181         type Target = Self;
182         fn deref(&self) -> &Self {
183                 self
184         }
185 }
186 impl core::ops::DerefMut for ScoreUpdate {
187         fn deref_mut(&mut self) -> &mut Self {
188                 self
189         }
190 }
191 /// Calls the free function if one is set
192 #[no_mangle]
193 pub extern "C" fn ScoreUpdate_free(this_ptr: ScoreUpdate) { }
194 impl Drop for ScoreUpdate {
195         fn drop(&mut self) {
196                 if let Some(f) = self.free {
197                         f(self.this_arg);
198                 }
199         }
200 }
201 /// A trait which can both lookup and update routing channel penalty scores.
202 ///
203 /// This is used in places where both bounds are required and implemented for all types which
204 /// implement [`ScoreLookUp`] and [`ScoreUpdate`].
205 ///
206 /// Bindings users may need to manually implement this for their custom scoring implementations.
207 #[repr(C)]
208 pub struct Score {
209         /// An opaque pointer which is passed to your function implementations as an argument.
210         /// This has no meaning in the LDK, and can be NULL or any other value.
211         pub this_arg: *mut c_void,
212         /// Implementation of ScoreLookUp for this object.
213         pub ScoreLookUp: crate::lightning::routing::scoring::ScoreLookUp,
214         /// Implementation of ScoreUpdate for this object.
215         pub ScoreUpdate: crate::lightning::routing::scoring::ScoreUpdate,
216         /// Serialize the object into a byte array
217         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
218         /// Frees any resources associated with this object given its this_arg pointer.
219         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
220         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
221 }
222 unsafe impl Send for Score {}
223 unsafe impl Sync for Score {}
224 pub(crate) fn Score_clone_fields(orig: &Score) -> Score {
225         Score {
226                 this_arg: orig.this_arg,
227                 ScoreLookUp: crate::lightning::routing::scoring::ScoreLookUp_clone_fields(&orig.ScoreLookUp),
228                 ScoreUpdate: crate::lightning::routing::scoring::ScoreUpdate_clone_fields(&orig.ScoreUpdate),
229                 write: Clone::clone(&orig.write),
230                 free: Clone::clone(&orig.free),
231         }
232 }
233 impl lightning::routing::scoring::ScoreLookUp for Score {
234         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, mut score_params: &lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
235                 let mut ret = (self.ScoreLookUp.channel_penalty_msat)(self.ScoreLookUp.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 }, &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((score_params as *const lightning::routing::scoring::ProbabilisticScoringFeeParameters<>) as *mut _) }, is_owned: false });
236                 ret
237         }
238 }
239 impl lightning::routing::scoring::ScoreUpdate for Score {
240         fn payment_path_failed(&mut self, mut path: &lightning::routing::router::Path, mut short_channel_id: u64) {
241                 (self.ScoreUpdate.payment_path_failed)(self.ScoreUpdate.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false }, short_channel_id)
242         }
243         fn payment_path_successful(&mut self, mut path: &lightning::routing::router::Path) {
244                 (self.ScoreUpdate.payment_path_successful)(self.ScoreUpdate.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false })
245         }
246         fn probe_failed(&mut self, mut path: &lightning::routing::router::Path, mut short_channel_id: u64) {
247                 (self.ScoreUpdate.probe_failed)(self.ScoreUpdate.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false }, short_channel_id)
248         }
249         fn probe_successful(&mut self, mut path: &lightning::routing::router::Path) {
250                 (self.ScoreUpdate.probe_successful)(self.ScoreUpdate.this_arg, &crate::lightning::routing::router::Path { inner: unsafe { ObjOps::nonnull_ptr_to_inner((path as *const lightning::routing::router::Path<>) as *mut _) }, is_owned: false })
251         }
252 }
253 impl lightning::util::ser::Writeable for Score {
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::Score as rustScore;
261 impl rustScore for Score {
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 Score {
267         type Target = Self;
268         fn deref(&self) -> &Self {
269                 self
270         }
271 }
272 impl core::ops::DerefMut for Score {
273         fn deref_mut(&mut self) -> &mut Self {
274                 self
275         }
276 }
277 /// Calls the free function if one is set
278 #[no_mangle]
279 pub extern "C" fn Score_free(this_ptr: Score) { }
280 impl Drop for Score {
281         fn drop(&mut self) {
282                 if let Some(f) = self.free {
283                         f(self.this_arg);
284                 }
285         }
286 }
287 /// A scorer that is accessed under a lock.
288 ///
289 /// Needed so that calls to [`ScoreLookUp::channel_penalty_msat`] in [`find_route`] can be made while
290 /// having shared ownership of a scorer but without requiring internal locking in [`ScoreUpdate`]
291 /// implementations. Internal locking would be detrimental to route finding performance and could
292 /// result in [`ScoreLookUp::channel_penalty_msat`] returning a different value for the same channel.
293 ///
294 /// [`find_route`]: crate::routing::router::find_route
295 #[repr(C)]
296 pub struct LockableScore {
297         /// An opaque pointer which is passed to your function implementations as an argument.
298         /// This has no meaning in the LDK, and can be NULL or any other value.
299         pub this_arg: *mut c_void,
300         /// Returns read locked scorer.
301         pub read_lock: extern "C" fn (this_arg: *const c_void) -> crate::lightning::routing::scoring::ScoreLookUp,
302         /// Returns write locked scorer.
303         pub write_lock: extern "C" fn (this_arg: *const c_void) -> crate::lightning::routing::scoring::ScoreUpdate,
304         /// Frees any resources associated with this object given its this_arg pointer.
305         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
306         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
307 }
308 unsafe impl Send for LockableScore {}
309 unsafe impl Sync for LockableScore {}
310 pub(crate) fn LockableScore_clone_fields(orig: &LockableScore) -> LockableScore {
311         LockableScore {
312                 this_arg: orig.this_arg,
313                 read_lock: Clone::clone(&orig.read_lock),
314                 write_lock: Clone::clone(&orig.write_lock),
315                 free: Clone::clone(&orig.free),
316         }
317 }
318
319 use lightning::routing::scoring::LockableScore as rustLockableScore;
320 impl<'a> rustLockableScore<'a> for LockableScore {
321         type ScoreUpdate = crate::lightning::routing::scoring::ScoreUpdate;
322         type ScoreLookUp = crate::lightning::routing::scoring::ScoreLookUp;
323         type WriteLocked = crate::lightning::routing::scoring::ScoreUpdate;
324         type ReadLocked = crate::lightning::routing::scoring::ScoreLookUp;
325         fn read_lock(&'a self) -> crate::lightning::routing::scoring::ScoreLookUp {
326                 let mut ret = (self.read_lock)(self.this_arg);
327                 ret
328         }
329         fn write_lock(&'a self) -> crate::lightning::routing::scoring::ScoreUpdate {
330                 let mut ret = (self.write_lock)(self.this_arg);
331                 ret
332         }
333 }
334
335 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
336 // directly as a Deref trait in higher-level structs:
337 impl core::ops::Deref for LockableScore {
338         type Target = Self;
339         fn deref(&self) -> &Self {
340                 self
341         }
342 }
343 impl core::ops::DerefMut for LockableScore {
344         fn deref_mut(&mut self) -> &mut Self {
345                 self
346         }
347 }
348 /// Calls the free function if one is set
349 #[no_mangle]
350 pub extern "C" fn LockableScore_free(this_ptr: LockableScore) { }
351 impl Drop for LockableScore {
352         fn drop(&mut self) {
353                 if let Some(f) = self.free {
354                         f(self.this_arg);
355                 }
356         }
357 }
358 /// Refers to a scorer that is accessible under lock and also writeable to disk
359 ///
360 /// We need this trait to be able to pass in a scorer to `lightning-background-processor` that will enable us to
361 /// use the Persister to persist it.
362 #[repr(C)]
363 pub struct WriteableScore {
364         /// An opaque pointer which is passed to your function implementations as an argument.
365         /// This has no meaning in the LDK, and can be NULL or any other value.
366         pub this_arg: *mut c_void,
367         /// Implementation of LockableScore for this object.
368         pub LockableScore: crate::lightning::routing::scoring::LockableScore,
369         /// Serialize the object into a byte array
370         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
371         /// Frees any resources associated with this object given its this_arg pointer.
372         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
373         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
374 }
375 unsafe impl Send for WriteableScore {}
376 unsafe impl Sync for WriteableScore {}
377 pub(crate) fn WriteableScore_clone_fields(orig: &WriteableScore) -> WriteableScore {
378         WriteableScore {
379                 this_arg: orig.this_arg,
380                 LockableScore: crate::lightning::routing::scoring::LockableScore_clone_fields(&orig.LockableScore),
381                 write: Clone::clone(&orig.write),
382                 free: Clone::clone(&orig.free),
383         }
384 }
385 impl<'a> lightning::routing::scoring::LockableScore<'a> for WriteableScore {
386         type ScoreUpdate = crate::lightning::routing::scoring::ScoreUpdate;
387         type ScoreLookUp = crate::lightning::routing::scoring::ScoreLookUp;
388         type WriteLocked = crate::lightning::routing::scoring::ScoreUpdate;
389         type ReadLocked = crate::lightning::routing::scoring::ScoreLookUp;
390         fn read_lock(&'a self) -> crate::lightning::routing::scoring::ScoreLookUp {
391                 let mut ret = (self.LockableScore.read_lock)(self.LockableScore.this_arg);
392                 ret
393         }
394         fn write_lock(&'a self) -> crate::lightning::routing::scoring::ScoreUpdate {
395                 let mut ret = (self.LockableScore.write_lock)(self.LockableScore.this_arg);
396                 ret
397         }
398 }
399 impl lightning::util::ser::Writeable for WriteableScore {
400         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
401                 let vec = (self.write)(self.this_arg);
402                 w.write_all(vec.as_slice())
403         }
404 }
405
406 use lightning::routing::scoring::WriteableScore as rustWriteableScore;
407 impl<'a> rustWriteableScore<'a> for WriteableScore {
408 }
409
410 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
411 // directly as a Deref trait in higher-level structs:
412 impl core::ops::Deref for WriteableScore {
413         type Target = Self;
414         fn deref(&self) -> &Self {
415                 self
416         }
417 }
418 impl core::ops::DerefMut for WriteableScore {
419         fn deref_mut(&mut self) -> &mut Self {
420                 self
421         }
422 }
423 /// Calls the free function if one is set
424 #[no_mangle]
425 pub extern "C" fn WriteableScore_free(this_ptr: WriteableScore) { }
426 impl Drop for WriteableScore {
427         fn drop(&mut self) {
428                 if let Some(f) = self.free {
429                         f(self.this_arg);
430                 }
431         }
432 }
433
434 use lightning::routing::scoring::MultiThreadedLockableScore as nativeMultiThreadedLockableScoreImport;
435 pub(crate) type nativeMultiThreadedLockableScore = nativeMultiThreadedLockableScoreImport<crate::lightning::routing::scoring::Score>;
436
437 /// A concrete implementation of [`LockableScore`] which supports multi-threading.
438 #[must_use]
439 #[repr(C)]
440 pub struct MultiThreadedLockableScore {
441         /// A pointer to the opaque Rust object.
442
443         /// Nearly everywhere, inner must be non-null, however in places where
444         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
445         pub inner: *mut nativeMultiThreadedLockableScore,
446         /// Indicates that this is the only struct which contains the same pointer.
447
448         /// Rust functions which take ownership of an object provided via an argument require
449         /// this to be true and invalidate the object pointed to by inner.
450         pub is_owned: bool,
451 }
452
453 impl Drop for MultiThreadedLockableScore {
454         fn drop(&mut self) {
455                 if self.is_owned && !<*mut nativeMultiThreadedLockableScore>::is_null(self.inner) {
456                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
457                 }
458         }
459 }
460 /// Frees any resources used by the MultiThreadedLockableScore, if is_owned is set and inner is non-NULL.
461 #[no_mangle]
462 pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockableScore) { }
463 #[allow(unused)]
464 /// Used only if an object of this type is returned as a trait impl by a method
465 pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) {
466         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore) };
467 }
468 #[allow(unused)]
469 impl MultiThreadedLockableScore {
470         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedLockableScore {
471                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
472         }
473         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedLockableScore {
474                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
475         }
476         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
477         pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedLockableScore {
478                 assert!(self.is_owned);
479                 let ret = ObjOps::untweak_ptr(self.inner);
480                 self.inner = core::ptr::null_mut();
481                 ret
482         }
483 }
484 impl From<nativeMultiThreadedLockableScore> for crate::lightning::routing::scoring::LockableScore {
485         fn from(obj: nativeMultiThreadedLockableScore) -> Self {
486                 let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true };
487                 let mut ret = MultiThreadedLockableScore_as_LockableScore(&rust_obj);
488                 // 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
489                 rust_obj.inner = core::ptr::null_mut();
490                 ret.free = Some(MultiThreadedLockableScore_free_void);
491                 ret
492         }
493 }
494 /// Constructs a new LockableScore which calls the relevant methods on this_arg.
495 /// This copies the `inner` pointer in this_arg and thus the returned LockableScore must be freed before this_arg is
496 #[no_mangle]
497 pub extern "C" fn MultiThreadedLockableScore_as_LockableScore(this_arg: &MultiThreadedLockableScore) -> crate::lightning::routing::scoring::LockableScore {
498         crate::lightning::routing::scoring::LockableScore {
499                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
500                 free: None,
501                 read_lock: MultiThreadedLockableScore_LockableScore_read_lock,
502                 write_lock: MultiThreadedLockableScore_LockableScore_write_lock,
503         }
504 }
505
506 #[must_use]
507 extern "C" fn MultiThreadedLockableScore_LockableScore_read_lock(this_arg: *const c_void) -> crate::lightning::routing::scoring::ScoreLookUp {
508         let mut ret = <nativeMultiThreadedLockableScore as lightning::routing::scoring::LockableScore<>>::read_lock(unsafe { &mut *(this_arg as *mut nativeMultiThreadedLockableScore) }, );
509         Into::into(ret)
510 }
511 #[must_use]
512 extern "C" fn MultiThreadedLockableScore_LockableScore_write_lock(this_arg: *const c_void) -> crate::lightning::routing::scoring::ScoreUpdate {
513         let mut ret = <nativeMultiThreadedLockableScore as lightning::routing::scoring::LockableScore<>>::write_lock(unsafe { &mut *(this_arg as *mut nativeMultiThreadedLockableScore) }, );
514         Into::into(ret)
515 }
516
517 #[no_mangle]
518 /// Serialize the MultiThreadedLockableScore object into a byte array which can be read by MultiThreadedLockableScore_read
519 pub extern "C" fn MultiThreadedLockableScore_write(obj: &crate::lightning::routing::scoring::MultiThreadedLockableScore) -> crate::c_types::derived::CVec_u8Z {
520         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
521 }
522 #[no_mangle]
523 pub(crate) extern "C" fn MultiThreadedLockableScore_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
524         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedLockableScore) })
525 }
526 impl From<nativeMultiThreadedLockableScore> for crate::lightning::routing::scoring::WriteableScore {
527         fn from(obj: nativeMultiThreadedLockableScore) -> Self {
528                 let mut rust_obj = MultiThreadedLockableScore { inner: ObjOps::heap_alloc(obj), is_owned: true };
529                 let mut ret = MultiThreadedLockableScore_as_WriteableScore(&rust_obj);
530                 // 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
531                 rust_obj.inner = core::ptr::null_mut();
532                 ret.free = Some(MultiThreadedLockableScore_free_void);
533                 ret
534         }
535 }
536 /// Constructs a new WriteableScore which calls the relevant methods on this_arg.
537 /// This copies the `inner` pointer in this_arg and thus the returned WriteableScore must be freed before this_arg is
538 #[no_mangle]
539 pub extern "C" fn MultiThreadedLockableScore_as_WriteableScore(this_arg: &MultiThreadedLockableScore) -> crate::lightning::routing::scoring::WriteableScore {
540         crate::lightning::routing::scoring::WriteableScore {
541                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
542                 free: None,
543                 LockableScore: crate::lightning::routing::scoring::LockableScore {
544                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
545                         free: None,
546                         read_lock: MultiThreadedLockableScore_LockableScore_read_lock,
547                         write_lock: MultiThreadedLockableScore_LockableScore_write_lock,
548                 },
549                 write: MultiThreadedLockableScore_write_void,
550         }
551 }
552
553
554 /// Creates a new [`MultiThreadedLockableScore`] given an underlying [`Score`].
555 #[must_use]
556 #[no_mangle]
557 pub extern "C" fn MultiThreadedLockableScore_new(mut score: crate::lightning::routing::scoring::Score) -> crate::lightning::routing::scoring::MultiThreadedLockableScore {
558         let mut ret = lightning::routing::scoring::MultiThreadedLockableScore::new(score);
559         crate::lightning::routing::scoring::MultiThreadedLockableScore { inner: ObjOps::heap_alloc(ret), is_owned: true }
560 }
561
562
563 use lightning::routing::scoring::MultiThreadedScoreLockRead as nativeMultiThreadedScoreLockReadImport;
564 pub(crate) type nativeMultiThreadedScoreLockRead = nativeMultiThreadedScoreLockReadImport<'static, crate::lightning::routing::scoring::Score>;
565
566 /// A locked `MultiThreadedLockableScore`.
567 #[must_use]
568 #[repr(C)]
569 pub struct MultiThreadedScoreLockRead {
570         /// A pointer to the opaque Rust object.
571
572         /// Nearly everywhere, inner must be non-null, however in places where
573         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
574         pub inner: *mut nativeMultiThreadedScoreLockRead,
575         /// Indicates that this is the only struct which contains the same pointer.
576
577         /// Rust functions which take ownership of an object provided via an argument require
578         /// this to be true and invalidate the object pointed to by inner.
579         pub is_owned: bool,
580 }
581
582 impl Drop for MultiThreadedScoreLockRead {
583         fn drop(&mut self) {
584                 if self.is_owned && !<*mut nativeMultiThreadedScoreLockRead>::is_null(self.inner) {
585                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
586                 }
587         }
588 }
589 /// Frees any resources used by the MultiThreadedScoreLockRead, if is_owned is set and inner is non-NULL.
590 #[no_mangle]
591 pub extern "C" fn MultiThreadedScoreLockRead_free(this_obj: MultiThreadedScoreLockRead) { }
592 #[allow(unused)]
593 /// Used only if an object of this type is returned as a trait impl by a method
594 pub(crate) extern "C" fn MultiThreadedScoreLockRead_free_void(this_ptr: *mut c_void) {
595         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLockRead) };
596 }
597 #[allow(unused)]
598 impl MultiThreadedScoreLockRead {
599         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedScoreLockRead {
600                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
601         }
602         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedScoreLockRead {
603                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
604         }
605         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
606         pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedScoreLockRead {
607                 assert!(self.is_owned);
608                 let ret = ObjOps::untweak_ptr(self.inner);
609                 self.inner = core::ptr::null_mut();
610                 ret
611         }
612 }
613
614 use lightning::routing::scoring::MultiThreadedScoreLockWrite as nativeMultiThreadedScoreLockWriteImport;
615 pub(crate) type nativeMultiThreadedScoreLockWrite = nativeMultiThreadedScoreLockWriteImport<'static, crate::lightning::routing::scoring::Score>;
616
617 /// A locked `MultiThreadedLockableScore`.
618 #[must_use]
619 #[repr(C)]
620 pub struct MultiThreadedScoreLockWrite {
621         /// A pointer to the opaque Rust object.
622
623         /// Nearly everywhere, inner must be non-null, however in places where
624         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
625         pub inner: *mut nativeMultiThreadedScoreLockWrite,
626         /// Indicates that this is the only struct which contains the same pointer.
627
628         /// Rust functions which take ownership of an object provided via an argument require
629         /// this to be true and invalidate the object pointed to by inner.
630         pub is_owned: bool,
631 }
632
633 impl Drop for MultiThreadedScoreLockWrite {
634         fn drop(&mut self) {
635                 if self.is_owned && !<*mut nativeMultiThreadedScoreLockWrite>::is_null(self.inner) {
636                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
637                 }
638         }
639 }
640 /// Frees any resources used by the MultiThreadedScoreLockWrite, if is_owned is set and inner is non-NULL.
641 #[no_mangle]
642 pub extern "C" fn MultiThreadedScoreLockWrite_free(this_obj: MultiThreadedScoreLockWrite) { }
643 #[allow(unused)]
644 /// Used only if an object of this type is returned as a trait impl by a method
645 pub(crate) extern "C" fn MultiThreadedScoreLockWrite_free_void(this_ptr: *mut c_void) {
646         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLockWrite) };
647 }
648 #[allow(unused)]
649 impl MultiThreadedScoreLockWrite {
650         pub(crate) fn get_native_ref(&self) -> &'static nativeMultiThreadedScoreLockWrite {
651                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
652         }
653         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeMultiThreadedScoreLockWrite {
654                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
655         }
656         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
657         pub(crate) fn take_inner(mut self) -> *mut nativeMultiThreadedScoreLockWrite {
658                 assert!(self.is_owned);
659                 let ret = ObjOps::untweak_ptr(self.inner);
660                 self.inner = core::ptr::null_mut();
661                 ret
662         }
663 }
664 impl From<nativeMultiThreadedScoreLockRead> for crate::lightning::routing::scoring::ScoreLookUp {
665         fn from(obj: nativeMultiThreadedScoreLockRead) -> Self {
666                 let mut rust_obj = MultiThreadedScoreLockRead { inner: ObjOps::heap_alloc(obj), is_owned: true };
667                 let mut ret = MultiThreadedScoreLockRead_as_ScoreLookUp(&rust_obj);
668                 // 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
669                 rust_obj.inner = core::ptr::null_mut();
670                 ret.free = Some(MultiThreadedScoreLockRead_free_void);
671                 ret
672         }
673 }
674 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
675 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
676 #[no_mangle]
677 pub extern "C" fn MultiThreadedScoreLockRead_as_ScoreLookUp(this_arg: &MultiThreadedScoreLockRead) -> crate::lightning::routing::scoring::ScoreLookUp {
678         crate::lightning::routing::scoring::ScoreLookUp {
679                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
680                 free: None,
681                 channel_penalty_msat: MultiThreadedScoreLockRead_ScoreLookUp_channel_penalty_msat,
682         }
683 }
684
685 #[must_use]
686 extern "C" fn MultiThreadedScoreLockRead_ScoreLookUp_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, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
687         let mut ret = <nativeMultiThreadedScoreLockRead as lightning::routing::scoring::ScoreLookUp<>>::channel_penalty_msat(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLockRead) }, short_channel_id, source.get_native_ref(), target.get_native_ref(), *unsafe { Box::from_raw(usage.take_inner()) }, score_params.get_native_ref());
688         ret
689 }
690
691 #[no_mangle]
692 /// Serialize the MultiThreadedScoreLockWrite object into a byte array which can be read by MultiThreadedScoreLockWrite_read
693 pub extern "C" fn MultiThreadedScoreLockWrite_write(obj: &crate::lightning::routing::scoring::MultiThreadedScoreLockWrite) -> crate::c_types::derived::CVec_u8Z {
694         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
695 }
696 #[no_mangle]
697 pub(crate) extern "C" fn MultiThreadedScoreLockWrite_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
698         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeMultiThreadedScoreLockWrite) })
699 }
700 impl From<nativeMultiThreadedScoreLockWrite> for crate::lightning::routing::scoring::ScoreUpdate {
701         fn from(obj: nativeMultiThreadedScoreLockWrite) -> Self {
702                 let mut rust_obj = MultiThreadedScoreLockWrite { inner: ObjOps::heap_alloc(obj), is_owned: true };
703                 let mut ret = MultiThreadedScoreLockWrite_as_ScoreUpdate(&rust_obj);
704                 // 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
705                 rust_obj.inner = core::ptr::null_mut();
706                 ret.free = Some(MultiThreadedScoreLockWrite_free_void);
707                 ret
708         }
709 }
710 /// Constructs a new ScoreUpdate which calls the relevant methods on this_arg.
711 /// This copies the `inner` pointer in this_arg and thus the returned ScoreUpdate must be freed before this_arg is
712 #[no_mangle]
713 pub extern "C" fn MultiThreadedScoreLockWrite_as_ScoreUpdate(this_arg: &MultiThreadedScoreLockWrite) -> crate::lightning::routing::scoring::ScoreUpdate {
714         crate::lightning::routing::scoring::ScoreUpdate {
715                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
716                 free: None,
717                 payment_path_failed: MultiThreadedScoreLockWrite_ScoreUpdate_payment_path_failed,
718                 payment_path_successful: MultiThreadedScoreLockWrite_ScoreUpdate_payment_path_successful,
719                 probe_failed: MultiThreadedScoreLockWrite_ScoreUpdate_probe_failed,
720                 probe_successful: MultiThreadedScoreLockWrite_ScoreUpdate_probe_successful,
721         }
722 }
723
724 extern "C" fn MultiThreadedScoreLockWrite_ScoreUpdate_payment_path_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
725         <nativeMultiThreadedScoreLockWrite as lightning::routing::scoring::ScoreUpdate<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLockWrite) }, path.get_native_ref(), short_channel_id)
726 }
727 extern "C" fn MultiThreadedScoreLockWrite_ScoreUpdate_payment_path_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
728         <nativeMultiThreadedScoreLockWrite as lightning::routing::scoring::ScoreUpdate<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLockWrite) }, path.get_native_ref())
729 }
730 extern "C" fn MultiThreadedScoreLockWrite_ScoreUpdate_probe_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
731         <nativeMultiThreadedScoreLockWrite as lightning::routing::scoring::ScoreUpdate<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLockWrite) }, path.get_native_ref(), short_channel_id)
732 }
733 extern "C" fn MultiThreadedScoreLockWrite_ScoreUpdate_probe_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
734         <nativeMultiThreadedScoreLockWrite as lightning::routing::scoring::ScoreUpdate<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeMultiThreadedScoreLockWrite) }, path.get_native_ref())
735 }
736
737
738 use lightning::routing::scoring::ChannelUsage as nativeChannelUsageImport;
739 pub(crate) type nativeChannelUsage = nativeChannelUsageImport;
740
741 /// Proposed use of a channel passed as a parameter to [`ScoreLookUp::channel_penalty_msat`].
742 #[must_use]
743 #[repr(C)]
744 pub struct ChannelUsage {
745         /// A pointer to the opaque Rust object.
746
747         /// Nearly everywhere, inner must be non-null, however in places where
748         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
749         pub inner: *mut nativeChannelUsage,
750         /// Indicates that this is the only struct which contains the same pointer.
751
752         /// Rust functions which take ownership of an object provided via an argument require
753         /// this to be true and invalidate the object pointed to by inner.
754         pub is_owned: bool,
755 }
756
757 impl Drop for ChannelUsage {
758         fn drop(&mut self) {
759                 if self.is_owned && !<*mut nativeChannelUsage>::is_null(self.inner) {
760                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
761                 }
762         }
763 }
764 /// Frees any resources used by the ChannelUsage, if is_owned is set and inner is non-NULL.
765 #[no_mangle]
766 pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { }
767 #[allow(unused)]
768 /// Used only if an object of this type is returned as a trait impl by a method
769 pub(crate) extern "C" fn ChannelUsage_free_void(this_ptr: *mut c_void) {
770         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUsage) };
771 }
772 #[allow(unused)]
773 impl ChannelUsage {
774         pub(crate) fn get_native_ref(&self) -> &'static nativeChannelUsage {
775                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
776         }
777         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelUsage {
778                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
779         }
780         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
781         pub(crate) fn take_inner(mut self) -> *mut nativeChannelUsage {
782                 assert!(self.is_owned);
783                 let ret = ObjOps::untweak_ptr(self.inner);
784                 self.inner = core::ptr::null_mut();
785                 ret
786         }
787 }
788 /// The amount to send through the channel, denominated in millisatoshis.
789 #[no_mangle]
790 pub extern "C" fn ChannelUsage_get_amount_msat(this_ptr: &ChannelUsage) -> u64 {
791         let mut inner_val = &mut this_ptr.get_native_mut_ref().amount_msat;
792         *inner_val
793 }
794 /// The amount to send through the channel, denominated in millisatoshis.
795 #[no_mangle]
796 pub extern "C" fn ChannelUsage_set_amount_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
797         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.amount_msat = val;
798 }
799 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
800 /// as part of a multi-path payment.
801 #[no_mangle]
802 pub extern "C" fn ChannelUsage_get_inflight_htlc_msat(this_ptr: &ChannelUsage) -> u64 {
803         let mut inner_val = &mut this_ptr.get_native_mut_ref().inflight_htlc_msat;
804         *inner_val
805 }
806 /// Total amount, denominated in millisatoshis, already allocated to send through the channel
807 /// as part of a multi-path payment.
808 #[no_mangle]
809 pub extern "C" fn ChannelUsage_set_inflight_htlc_msat(this_ptr: &mut ChannelUsage, mut val: u64) {
810         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.inflight_htlc_msat = val;
811 }
812 /// The effective capacity of the channel.
813 #[no_mangle]
814 pub extern "C" fn ChannelUsage_get_effective_capacity(this_ptr: &ChannelUsage) -> crate::lightning::routing::gossip::EffectiveCapacity {
815         let mut inner_val = &mut this_ptr.get_native_mut_ref().effective_capacity;
816         crate::lightning::routing::gossip::EffectiveCapacity::from_native(inner_val)
817 }
818 /// The effective capacity of the channel.
819 #[no_mangle]
820 pub extern "C" fn ChannelUsage_set_effective_capacity(this_ptr: &mut ChannelUsage, mut val: crate::lightning::routing::gossip::EffectiveCapacity) {
821         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.effective_capacity = val.into_native();
822 }
823 /// Constructs a new ChannelUsage given each field
824 #[must_use]
825 #[no_mangle]
826 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 {
827         ChannelUsage { inner: ObjOps::heap_alloc(nativeChannelUsage {
828                 amount_msat: amount_msat_arg,
829                 inflight_htlc_msat: inflight_htlc_msat_arg,
830                 effective_capacity: effective_capacity_arg.into_native(),
831         }), is_owned: true }
832 }
833 impl Clone for ChannelUsage {
834         fn clone(&self) -> Self {
835                 Self {
836                         inner: if <*mut nativeChannelUsage>::is_null(self.inner) { core::ptr::null_mut() } else {
837                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
838                         is_owned: true,
839                 }
840         }
841 }
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 ChannelUsage_clone_void(this_ptr: *const c_void) -> *mut c_void {
845         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUsage)).clone() })) as *mut c_void
846 }
847 #[no_mangle]
848 /// Creates a copy of the ChannelUsage
849 pub extern "C" fn ChannelUsage_clone(orig: &ChannelUsage) -> ChannelUsage {
850         orig.clone()
851 }
852
853 use lightning::routing::scoring::FixedPenaltyScorer as nativeFixedPenaltyScorerImport;
854 pub(crate) type nativeFixedPenaltyScorer = nativeFixedPenaltyScorerImport;
855
856 /// [`ScoreLookUp`] implementation that uses a fixed penalty.
857 #[must_use]
858 #[repr(C)]
859 pub struct FixedPenaltyScorer {
860         /// A pointer to the opaque Rust object.
861
862         /// Nearly everywhere, inner must be non-null, however in places where
863         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
864         pub inner: *mut nativeFixedPenaltyScorer,
865         /// Indicates that this is the only struct which contains the same pointer.
866
867         /// Rust functions which take ownership of an object provided via an argument require
868         /// this to be true and invalidate the object pointed to by inner.
869         pub is_owned: bool,
870 }
871
872 impl Drop for FixedPenaltyScorer {
873         fn drop(&mut self) {
874                 if self.is_owned && !<*mut nativeFixedPenaltyScorer>::is_null(self.inner) {
875                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
876                 }
877         }
878 }
879 /// Frees any resources used by the FixedPenaltyScorer, if is_owned is set and inner is non-NULL.
880 #[no_mangle]
881 pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { }
882 #[allow(unused)]
883 /// Used only if an object of this type is returned as a trait impl by a method
884 pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) {
885         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer) };
886 }
887 #[allow(unused)]
888 impl FixedPenaltyScorer {
889         pub(crate) fn get_native_ref(&self) -> &'static nativeFixedPenaltyScorer {
890                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
891         }
892         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFixedPenaltyScorer {
893                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
894         }
895         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
896         pub(crate) fn take_inner(mut self) -> *mut nativeFixedPenaltyScorer {
897                 assert!(self.is_owned);
898                 let ret = ObjOps::untweak_ptr(self.inner);
899                 self.inner = core::ptr::null_mut();
900                 ret
901         }
902 }
903 impl Clone for FixedPenaltyScorer {
904         fn clone(&self) -> Self {
905                 Self {
906                         inner: if <*mut nativeFixedPenaltyScorer>::is_null(self.inner) { core::ptr::null_mut() } else {
907                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
908                         is_owned: true,
909                 }
910         }
911 }
912 #[allow(unused)]
913 /// Used only if an object of this type is returned as a trait impl by a method
914 pub(crate) extern "C" fn FixedPenaltyScorer_clone_void(this_ptr: *const c_void) -> *mut c_void {
915         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFixedPenaltyScorer)).clone() })) as *mut c_void
916 }
917 #[no_mangle]
918 /// Creates a copy of the FixedPenaltyScorer
919 pub extern "C" fn FixedPenaltyScorer_clone(orig: &FixedPenaltyScorer) -> FixedPenaltyScorer {
920         orig.clone()
921 }
922 /// Creates a new scorer using `penalty_msat`.
923 #[must_use]
924 #[no_mangle]
925 pub extern "C" fn FixedPenaltyScorer_with_penalty(mut penalty_msat: u64) -> crate::lightning::routing::scoring::FixedPenaltyScorer {
926         let mut ret = lightning::routing::scoring::FixedPenaltyScorer::with_penalty(penalty_msat);
927         crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
928 }
929
930 impl From<nativeFixedPenaltyScorer> for crate::lightning::routing::scoring::ScoreLookUp {
931         fn from(obj: nativeFixedPenaltyScorer) -> Self {
932                 let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
933                 let mut ret = FixedPenaltyScorer_as_ScoreLookUp(&rust_obj);
934                 // 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
935                 rust_obj.inner = core::ptr::null_mut();
936                 ret.free = Some(FixedPenaltyScorer_free_void);
937                 ret
938         }
939 }
940 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
941 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
942 #[no_mangle]
943 pub extern "C" fn FixedPenaltyScorer_as_ScoreLookUp(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::ScoreLookUp {
944         crate::lightning::routing::scoring::ScoreLookUp {
945                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
946                 free: None,
947                 channel_penalty_msat: FixedPenaltyScorer_ScoreLookUp_channel_penalty_msat,
948         }
949 }
950
951 #[must_use]
952 extern "C" fn FixedPenaltyScorer_ScoreLookUp_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, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
953         let mut ret = <nativeFixedPenaltyScorer as lightning::routing::scoring::ScoreLookUp<>>::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()) }, score_params.get_native_ref());
954         ret
955 }
956
957 impl From<nativeFixedPenaltyScorer> for crate::lightning::routing::scoring::ScoreUpdate {
958         fn from(obj: nativeFixedPenaltyScorer) -> Self {
959                 let mut rust_obj = FixedPenaltyScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
960                 let mut ret = FixedPenaltyScorer_as_ScoreUpdate(&rust_obj);
961                 // 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
962                 rust_obj.inner = core::ptr::null_mut();
963                 ret.free = Some(FixedPenaltyScorer_free_void);
964                 ret
965         }
966 }
967 /// Constructs a new ScoreUpdate which calls the relevant methods on this_arg.
968 /// This copies the `inner` pointer in this_arg and thus the returned ScoreUpdate must be freed before this_arg is
969 #[no_mangle]
970 pub extern "C" fn FixedPenaltyScorer_as_ScoreUpdate(this_arg: &FixedPenaltyScorer) -> crate::lightning::routing::scoring::ScoreUpdate {
971         crate::lightning::routing::scoring::ScoreUpdate {
972                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
973                 free: None,
974                 payment_path_failed: FixedPenaltyScorer_ScoreUpdate_payment_path_failed,
975                 payment_path_successful: FixedPenaltyScorer_ScoreUpdate_payment_path_successful,
976                 probe_failed: FixedPenaltyScorer_ScoreUpdate_probe_failed,
977                 probe_successful: FixedPenaltyScorer_ScoreUpdate_probe_successful,
978         }
979 }
980
981 extern "C" fn FixedPenaltyScorer_ScoreUpdate_payment_path_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
982         <nativeFixedPenaltyScorer as lightning::routing::scoring::ScoreUpdate<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, path.get_native_ref(), short_channel_id)
983 }
984 extern "C" fn FixedPenaltyScorer_ScoreUpdate_payment_path_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
985         <nativeFixedPenaltyScorer as lightning::routing::scoring::ScoreUpdate<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, path.get_native_ref())
986 }
987 extern "C" fn FixedPenaltyScorer_ScoreUpdate_probe_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
988         <nativeFixedPenaltyScorer as lightning::routing::scoring::ScoreUpdate<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, path.get_native_ref(), short_channel_id)
989 }
990 extern "C" fn FixedPenaltyScorer_ScoreUpdate_probe_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
991         <nativeFixedPenaltyScorer as lightning::routing::scoring::ScoreUpdate<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeFixedPenaltyScorer) }, path.get_native_ref())
992 }
993
994 #[no_mangle]
995 /// Serialize the FixedPenaltyScorer object into a byte array which can be read by FixedPenaltyScorer_read
996 pub extern "C" fn FixedPenaltyScorer_write(obj: &crate::lightning::routing::scoring::FixedPenaltyScorer) -> crate::c_types::derived::CVec_u8Z {
997         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
998 }
999 #[no_mangle]
1000 pub(crate) extern "C" fn FixedPenaltyScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1001         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFixedPenaltyScorer) })
1002 }
1003 #[no_mangle]
1004 /// Read a FixedPenaltyScorer from a byte array, created by FixedPenaltyScorer_write
1005 pub extern "C" fn FixedPenaltyScorer_read(ser: crate::c_types::u8slice, arg: u64) -> crate::c_types::derived::CResult_FixedPenaltyScorerDecodeErrorZ {
1006         let arg_conv = arg;
1007         let res: Result<lightning::routing::scoring::FixedPenaltyScorer, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj_arg(ser, arg_conv);
1008         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::FixedPenaltyScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1009         local_res
1010 }
1011
1012 use lightning::routing::scoring::ProbabilisticScorer as nativeProbabilisticScorerImport;
1013 pub(crate) type nativeProbabilisticScorer = nativeProbabilisticScorerImport<&'static lightning::routing::gossip::NetworkGraph<crate::lightning::util::logger::Logger>, crate::lightning::util::logger::Logger>;
1014
1015 /// [`ScoreLookUp`] implementation using channel success probability distributions.
1016 ///
1017 /// Channels are tracked with upper and lower liquidity bounds - when an HTLC fails at a channel,
1018 /// we learn that the upper-bound on the available liquidity is lower than the amount of the HTLC.
1019 /// When a payment is forwarded through a channel (but fails later in the route), we learn the
1020 /// lower-bound on the channel's available liquidity must be at least the value of the HTLC.
1021 ///
1022 /// These bounds are then used to determine a success probability using the formula from
1023 /// *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
1024 /// and Stefan Richter [[1]] (i.e. `(upper_bound - payment_amount) / (upper_bound - lower_bound)`).
1025 ///6762, 1070
1026 /// This probability is combined with the [`liquidity_penalty_multiplier_msat`] and
1027 /// [`liquidity_penalty_amount_multiplier_msat`] parameters to calculate a concrete penalty in
1028 /// milli-satoshis. The penalties, when added across all hops, have the property of being linear in
1029 /// terms of the entire path's success probability. This allows the router to directly compare
1030 /// penalties for different paths. See the documentation of those parameters for the exact formulas.
1031 ///
1032 /// The liquidity bounds are decayed by halving them every [`liquidity_offset_half_life`].
1033 ///
1034 /// Further, we track the history of our upper and lower liquidity bounds for each channel,
1035 /// allowing us to assign a second penalty (using [`historical_liquidity_penalty_multiplier_msat`]
1036 /// and [`historical_liquidity_penalty_amount_multiplier_msat`]) based on the same probability
1037 /// formula, but using the history of a channel rather than our latest estimates for the liquidity
1038 /// bounds.
1039 ///
1040 /// # Note
1041 ///
1042 /// Mixing the `no-std` feature between serialization and deserialization results in undefined
1043 /// behavior.
1044 ///
1045 /// [1]: https://arxiv.org/abs/2107.05322
1046 /// [`liquidity_penalty_multiplier_msat`]: ProbabilisticScoringFeeParameters::liquidity_penalty_multiplier_msat
1047 /// [`liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringFeeParameters::liquidity_penalty_amount_multiplier_msat
1048 /// [`liquidity_offset_half_life`]: ProbabilisticScoringDecayParameters::liquidity_offset_half_life
1049 /// [`historical_liquidity_penalty_multiplier_msat`]: ProbabilisticScoringFeeParameters::historical_liquidity_penalty_multiplier_msat
1050 /// [`historical_liquidity_penalty_amount_multiplier_msat`]: ProbabilisticScoringFeeParameters::historical_liquidity_penalty_amount_multiplier_msat
1051 #[must_use]
1052 #[repr(C)]
1053 pub struct ProbabilisticScorer {
1054         /// A pointer to the opaque Rust object.
1055
1056         /// Nearly everywhere, inner must be non-null, however in places where
1057         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1058         pub inner: *mut nativeProbabilisticScorer,
1059         /// Indicates that this is the only struct which contains the same pointer.
1060
1061         /// Rust functions which take ownership of an object provided via an argument require
1062         /// this to be true and invalidate the object pointed to by inner.
1063         pub is_owned: bool,
1064 }
1065
1066 impl Drop for ProbabilisticScorer {
1067         fn drop(&mut self) {
1068                 if self.is_owned && !<*mut nativeProbabilisticScorer>::is_null(self.inner) {
1069                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1070                 }
1071         }
1072 }
1073 /// Frees any resources used by the ProbabilisticScorer, if is_owned is set and inner is non-NULL.
1074 #[no_mangle]
1075 pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { }
1076 #[allow(unused)]
1077 /// Used only if an object of this type is returned as a trait impl by a method
1078 pub(crate) extern "C" fn ProbabilisticScorer_free_void(this_ptr: *mut c_void) {
1079         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScorer) };
1080 }
1081 #[allow(unused)]
1082 impl ProbabilisticScorer {
1083         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScorer {
1084                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1085         }
1086         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScorer {
1087                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1088         }
1089         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1090         pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScorer {
1091                 assert!(self.is_owned);
1092                 let ret = ObjOps::untweak_ptr(self.inner);
1093                 self.inner = core::ptr::null_mut();
1094                 ret
1095         }
1096 }
1097
1098 use lightning::routing::scoring::ProbabilisticScoringFeeParameters as nativeProbabilisticScoringFeeParametersImport;
1099 pub(crate) type nativeProbabilisticScoringFeeParameters = nativeProbabilisticScoringFeeParametersImport;
1100
1101 /// Parameters for configuring [`ProbabilisticScorer`].
1102 ///
1103 /// Used to configure base, liquidity, and amount penalties, the sum of which comprises the channel
1104 /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
1105 ///
1106 /// The penalty applied to any channel by the [`ProbabilisticScorer`] is the sum of each of the
1107 /// parameters here.
1108 #[must_use]
1109 #[repr(C)]
1110 pub struct ProbabilisticScoringFeeParameters {
1111         /// A pointer to the opaque Rust object.
1112
1113         /// Nearly everywhere, inner must be non-null, however in places where
1114         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1115         pub inner: *mut nativeProbabilisticScoringFeeParameters,
1116         /// Indicates that this is the only struct which contains the same pointer.
1117
1118         /// Rust functions which take ownership of an object provided via an argument require
1119         /// this to be true and invalidate the object pointed to by inner.
1120         pub is_owned: bool,
1121 }
1122
1123 impl Drop for ProbabilisticScoringFeeParameters {
1124         fn drop(&mut self) {
1125                 if self.is_owned && !<*mut nativeProbabilisticScoringFeeParameters>::is_null(self.inner) {
1126                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1127                 }
1128         }
1129 }
1130 /// Frees any resources used by the ProbabilisticScoringFeeParameters, if is_owned is set and inner is non-NULL.
1131 #[no_mangle]
1132 pub extern "C" fn ProbabilisticScoringFeeParameters_free(this_obj: ProbabilisticScoringFeeParameters) { }
1133 #[allow(unused)]
1134 /// Used only if an object of this type is returned as a trait impl by a method
1135 pub(crate) extern "C" fn ProbabilisticScoringFeeParameters_free_void(this_ptr: *mut c_void) {
1136         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScoringFeeParameters) };
1137 }
1138 #[allow(unused)]
1139 impl ProbabilisticScoringFeeParameters {
1140         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScoringFeeParameters {
1141                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1142         }
1143         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScoringFeeParameters {
1144                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1145         }
1146         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1147         pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScoringFeeParameters {
1148                 assert!(self.is_owned);
1149                 let ret = ObjOps::untweak_ptr(self.inner);
1150                 self.inner = core::ptr::null_mut();
1151                 ret
1152         }
1153 }
1154 /// A fixed penalty in msats to apply to each channel.
1155 ///
1156 /// Default value: 500 msat
1157 #[no_mangle]
1158 pub extern "C" fn ProbabilisticScoringFeeParameters_get_base_penalty_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1159         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_msat;
1160         *inner_val
1161 }
1162 /// A fixed penalty in msats to apply to each channel.
1163 ///
1164 /// Default value: 500 msat
1165 #[no_mangle]
1166 pub extern "C" fn ProbabilisticScoringFeeParameters_set_base_penalty_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1167         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_msat = val;
1168 }
1169 /// A multiplier used with the total amount flowing over a channel to calculate a fixed penalty
1170 /// applied to each channel, in excess of the [`base_penalty_msat`].
1171 ///
1172 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
1173 /// fees plus penalty) for large payments. The penalty is computed as the product of this
1174 /// multiplier and `2^30`ths of the total amount flowing over a channel (i.e. the payment
1175 /// amount plus the amount of any other HTLCs flowing we sent over the same channel).
1176 ///
1177 /// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30`
1178 ///
1179 /// Default value: 8,192 msat
1180 ///
1181 /// [`base_penalty_msat`]: Self::base_penalty_msat
1182 #[no_mangle]
1183 pub extern "C" fn ProbabilisticScoringFeeParameters_get_base_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1184         let mut inner_val = &mut this_ptr.get_native_mut_ref().base_penalty_amount_multiplier_msat;
1185         *inner_val
1186 }
1187 /// A multiplier used with the total amount flowing over a channel to calculate a fixed penalty
1188 /// applied to each channel, in excess of the [`base_penalty_msat`].
1189 ///
1190 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
1191 /// fees plus penalty) for large payments. The penalty is computed as the product of this
1192 /// multiplier and `2^30`ths of the total amount flowing over a channel (i.e. the payment
1193 /// amount plus the amount of any other HTLCs flowing we sent over the same channel).
1194 ///
1195 /// ie `base_penalty_amount_multiplier_msat * amount_msat / 2^30`
1196 ///
1197 /// Default value: 8,192 msat
1198 ///
1199 /// [`base_penalty_msat`]: Self::base_penalty_msat
1200 #[no_mangle]
1201 pub extern "C" fn ProbabilisticScoringFeeParameters_set_base_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1202         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.base_penalty_amount_multiplier_msat = val;
1203 }
1204 /// A multiplier used in conjunction with the negative `log10` of the channel's success
1205 /// probability for a payment, as determined by our latest estimates of the channel's
1206 /// liquidity, to determine the liquidity penalty.
1207 ///
1208 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
1209 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
1210 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
1211 /// lower bounding the success probability to `0.01`) when the amount falls within the
1212 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
1213 /// result in a `u64::max_value` penalty, however.
1214 ///
1215 /// `-log10(success_probability) * liquidity_penalty_multiplier_msat`
1216 ///
1217 /// Default value: 30,000 msat
1218 ///
1219 /// [`liquidity_offset_half_life`]: ProbabilisticScoringDecayParameters::liquidity_offset_half_life
1220 #[no_mangle]
1221 pub extern "C" fn ProbabilisticScoringFeeParameters_get_liquidity_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1222         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_multiplier_msat;
1223         *inner_val
1224 }
1225 /// A multiplier used in conjunction with the negative `log10` of the channel's success
1226 /// probability for a payment, as determined by our latest estimates of the channel's
1227 /// liquidity, to determine the liquidity penalty.
1228 ///
1229 /// The penalty is based in part on the knowledge learned from prior successful and unsuccessful
1230 /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
1231 /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
1232 /// lower bounding the success probability to `0.01`) when the amount falls within the
1233 /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
1234 /// result in a `u64::max_value` penalty, however.
1235 ///
1236 /// `-log10(success_probability) * liquidity_penalty_multiplier_msat`
1237 ///
1238 /// Default value: 30,000 msat
1239 ///
1240 /// [`liquidity_offset_half_life`]: ProbabilisticScoringDecayParameters::liquidity_offset_half_life
1241 #[no_mangle]
1242 pub extern "C" fn ProbabilisticScoringFeeParameters_set_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1243         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_multiplier_msat = val;
1244 }
1245 /// A multiplier used in conjunction with the total amount flowing over a channel and the
1246 /// negative `log10` of the channel's success probability for the payment, as determined by our
1247 /// latest estimates of the channel's liquidity, to determine the amount penalty.
1248 ///
1249 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
1250 /// fees plus penalty) for large payments. The penalty is computed as the product of this
1251 /// multiplier and `2^20`ths of the amount flowing over this channel, weighted by the negative
1252 /// `log10` of the success probability.
1253 ///
1254 /// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20`
1255 ///
1256 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
1257 /// the amount will result in a penalty of the multiplier. And, as the success probability
1258 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
1259 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
1260 /// fall below `1`.
1261 ///
1262 /// Default value: 192 msat
1263 #[no_mangle]
1264 pub extern "C" fn ProbabilisticScoringFeeParameters_get_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1265         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_penalty_amount_multiplier_msat;
1266         *inner_val
1267 }
1268 /// A multiplier used in conjunction with the total amount flowing over a channel and the
1269 /// negative `log10` of the channel's success probability for the payment, as determined by our
1270 /// latest estimates of the channel's liquidity, to determine the amount penalty.
1271 ///
1272 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
1273 /// fees plus penalty) for large payments. The penalty is computed as the product of this
1274 /// multiplier and `2^20`ths of the amount flowing over this channel, weighted by the negative
1275 /// `log10` of the success probability.
1276 ///
1277 /// `-log10(success_probability) * liquidity_penalty_amount_multiplier_msat * amount_msat / 2^20`
1278 ///
1279 /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
1280 /// the amount will result in a penalty of the multiplier. And, as the success probability
1281 /// decreases, the negative `log10` weighting will increase dramatically. For higher success
1282 /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
1283 /// fall below `1`.
1284 ///
1285 /// Default value: 192 msat
1286 #[no_mangle]
1287 pub extern "C" fn ProbabilisticScoringFeeParameters_set_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1288         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_penalty_amount_multiplier_msat = val;
1289 }
1290 /// A multiplier used in conjunction with the negative `log10` of the channel's success
1291 /// probability for the payment, as determined based on the history of our estimates of the
1292 /// channel's available liquidity, to determine a penalty.
1293 ///
1294 /// This penalty is similar to [`liquidity_penalty_multiplier_msat`], however, instead of using
1295 /// only our latest estimate for the current liquidity available in the channel, it estimates
1296 /// success probability based on the estimated liquidity available in the channel through
1297 /// history. Specifically, every time we update our liquidity bounds on a given channel, we
1298 /// track which of several buckets those bounds fall into, exponentially decaying the
1299 /// probability of each bucket as new samples are added.
1300 ///
1301 /// Default value: 10,000 msat
1302 ///
1303 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1304 #[no_mangle]
1305 pub extern "C" fn ProbabilisticScoringFeeParameters_get_historical_liquidity_penalty_multiplier_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1306         let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_liquidity_penalty_multiplier_msat;
1307         *inner_val
1308 }
1309 /// A multiplier used in conjunction with the negative `log10` of the channel's success
1310 /// probability for the payment, as determined based on the history of our estimates of the
1311 /// channel's available liquidity, to determine a penalty.
1312 ///
1313 /// This penalty is similar to [`liquidity_penalty_multiplier_msat`], however, instead of using
1314 /// only our latest estimate for the current liquidity available in the channel, it estimates
1315 /// success probability based on the estimated liquidity available in the channel through
1316 /// history. Specifically, every time we update our liquidity bounds on a given channel, we
1317 /// track which of several buckets those bounds fall into, exponentially decaying the
1318 /// probability of each bucket as new samples are added.
1319 ///
1320 /// Default value: 10,000 msat
1321 ///
1322 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1323 #[no_mangle]
1324 pub extern "C" fn ProbabilisticScoringFeeParameters_set_historical_liquidity_penalty_multiplier_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1325         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_liquidity_penalty_multiplier_msat = val;
1326 }
1327 /// A multiplier used in conjunction with the total amount flowing over a channel and the
1328 /// negative `log10` of the channel's success probability for the payment, as determined based
1329 /// on the history of our estimates of the channel's available liquidity, to determine a
1330 /// penalty.
1331 ///
1332 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost for
1333 /// large payments. The penalty is computed as the product of this multiplier and `2^20`ths
1334 /// of the amount flowing over this channel, weighted by the negative `log10` of the success
1335 /// probability.
1336 ///
1337 /// This penalty is similar to [`liquidity_penalty_amount_multiplier_msat`], however, instead
1338 /// of using only our latest estimate for the current liquidity available in the channel, it
1339 /// estimates success probability based on the estimated liquidity available in the channel
1340 /// through history. Specifically, every time we update our liquidity bounds on a given
1341 /// channel, we track which of several buckets those bounds fall into, exponentially decaying
1342 /// the probability of each bucket as new samples are added.
1343 ///
1344 /// Default value: 64 msat
1345 ///
1346 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1347 #[no_mangle]
1348 pub extern "C" fn ProbabilisticScoringFeeParameters_get_historical_liquidity_penalty_amount_multiplier_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1349         let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_liquidity_penalty_amount_multiplier_msat;
1350         *inner_val
1351 }
1352 /// A multiplier used in conjunction with the total amount flowing over a channel and the
1353 /// negative `log10` of the channel's success probability for the payment, as determined based
1354 /// on the history of our estimates of the channel's available liquidity, to determine a
1355 /// penalty.
1356 ///
1357 /// The purpose of the amount penalty is to avoid having fees dominate the channel cost for
1358 /// large payments. The penalty is computed as the product of this multiplier and `2^20`ths
1359 /// of the amount flowing over this channel, weighted by the negative `log10` of the success
1360 /// probability.
1361 ///
1362 /// This penalty is similar to [`liquidity_penalty_amount_multiplier_msat`], however, instead
1363 /// of using only our latest estimate for the current liquidity available in the channel, it
1364 /// estimates success probability based on the estimated liquidity available in the channel
1365 /// through history. Specifically, every time we update our liquidity bounds on a given
1366 /// channel, we track which of several buckets those bounds fall into, exponentially decaying
1367 /// the probability of each bucket as new samples are added.
1368 ///
1369 /// Default value: 64 msat
1370 ///
1371 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1372 #[no_mangle]
1373 pub extern "C" fn ProbabilisticScoringFeeParameters_set_historical_liquidity_penalty_amount_multiplier_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1374         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_liquidity_penalty_amount_multiplier_msat = val;
1375 }
1376 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
1377 /// channel's capacity, (ie. htlc_maximum_msat >= 0.5 * channel_capacity) which makes us
1378 /// prefer nodes with a smaller `htlc_maximum_msat`. We treat such nodes preferentially
1379 /// as this makes balance discovery attacks harder to execute, thereby creating an incentive
1380 /// to restrict `htlc_maximum_msat` and improve privacy.
1381 ///
1382 /// Default value: 250 msat
1383 #[no_mangle]
1384 pub extern "C" fn ProbabilisticScoringFeeParameters_get_anti_probing_penalty_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1385         let mut inner_val = &mut this_ptr.get_native_mut_ref().anti_probing_penalty_msat;
1386         *inner_val
1387 }
1388 /// This penalty is applied when `htlc_maximum_msat` is equal to or larger than half of the
1389 /// channel's capacity, (ie. htlc_maximum_msat >= 0.5 * channel_capacity) which makes us
1390 /// prefer nodes with a smaller `htlc_maximum_msat`. We treat such nodes preferentially
1391 /// as this makes balance discovery attacks harder to execute, thereby creating an incentive
1392 /// to restrict `htlc_maximum_msat` and improve privacy.
1393 ///
1394 /// Default value: 250 msat
1395 #[no_mangle]
1396 pub extern "C" fn ProbabilisticScoringFeeParameters_set_anti_probing_penalty_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1397         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.anti_probing_penalty_msat = val;
1398 }
1399 /// This penalty is applied when the total amount flowing over a channel exceeds our current
1400 /// estimate of the channel's available liquidity. The total amount is the amount of the
1401 /// current HTLC plus any HTLCs which we've sent over the same channel.
1402 ///
1403 /// Note that in this case all other penalties, including the
1404 /// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based
1405 /// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if
1406 /// applicable, are still included in the overall penalty.
1407 ///
1408 /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
1409 /// `u64::max_value()` will guarantee that.
1410 ///
1411 /// Default value: 1_0000_0000_000 msat (1 Bitcoin)
1412 ///
1413 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1414 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1415 /// [`base_penalty_msat`]: Self::base_penalty_msat
1416 /// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat
1417 #[no_mangle]
1418 pub extern "C" fn ProbabilisticScoringFeeParameters_get_considered_impossible_penalty_msat(this_ptr: &ProbabilisticScoringFeeParameters) -> u64 {
1419         let mut inner_val = &mut this_ptr.get_native_mut_ref().considered_impossible_penalty_msat;
1420         *inner_val
1421 }
1422 /// This penalty is applied when the total amount flowing over a channel exceeds our current
1423 /// estimate of the channel's available liquidity. The total amount is the amount of the
1424 /// current HTLC plus any HTLCs which we've sent over the same channel.
1425 ///
1426 /// Note that in this case all other penalties, including the
1427 /// [`liquidity_penalty_multiplier_msat`] and [`liquidity_penalty_amount_multiplier_msat`]-based
1428 /// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if
1429 /// applicable, are still included in the overall penalty.
1430 ///
1431 /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
1432 /// `u64::max_value()` will guarantee that.
1433 ///
1434 /// Default value: 1_0000_0000_000 msat (1 Bitcoin)
1435 ///
1436 /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
1437 /// [`liquidity_penalty_amount_multiplier_msat`]: Self::liquidity_penalty_amount_multiplier_msat
1438 /// [`base_penalty_msat`]: Self::base_penalty_msat
1439 /// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat
1440 #[no_mangle]
1441 pub extern "C" fn ProbabilisticScoringFeeParameters_set_considered_impossible_penalty_msat(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: u64) {
1442         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.considered_impossible_penalty_msat = val;
1443 }
1444 /// In order to calculate most of the scores above, we must first convert a lower and upper
1445 /// bound on the available liquidity in a channel into the probability that we think a payment
1446 /// will succeed. That probability is derived from a Probability Density Function for where we
1447 /// think the liquidity in a channel likely lies, given such bounds.
1448 ///
1449 /// If this flag is set, that PDF is simply a constant - we assume that the actual available
1450 /// liquidity in a channel is just as likely to be at any point between our lower and upper
1451 /// bounds.
1452 ///
1453 /// If this flag is *not* set, that PDF is `(x - 0.5*capacity) ^ 2`. That is, we use an
1454 /// exponential curve which expects the liquidity of a channel to lie \"at the edges\". This
1455 /// matches experimental results - most routing nodes do not aggressively rebalance their
1456 /// channels and flows in the network are often unbalanced, leaving liquidity usually
1457 /// unavailable.
1458 ///
1459 /// Thus, for the \"best\" routes, leave this flag `false`. However, the flag does imply a number
1460 /// of floating-point multiplications in the hottest routing code, which may lead to routing
1461 /// performance degradation on some machines.
1462 ///
1463 /// Default value: false
1464 #[no_mangle]
1465 pub extern "C" fn ProbabilisticScoringFeeParameters_get_linear_success_probability(this_ptr: &ProbabilisticScoringFeeParameters) -> bool {
1466         let mut inner_val = &mut this_ptr.get_native_mut_ref().linear_success_probability;
1467         *inner_val
1468 }
1469 /// In order to calculate most of the scores above, we must first convert a lower and upper
1470 /// bound on the available liquidity in a channel into the probability that we think a payment
1471 /// will succeed. That probability is derived from a Probability Density Function for where we
1472 /// think the liquidity in a channel likely lies, given such bounds.
1473 ///
1474 /// If this flag is set, that PDF is simply a constant - we assume that the actual available
1475 /// liquidity in a channel is just as likely to be at any point between our lower and upper
1476 /// bounds.
1477 ///
1478 /// If this flag is *not* set, that PDF is `(x - 0.5*capacity) ^ 2`. That is, we use an
1479 /// exponential curve which expects the liquidity of a channel to lie \"at the edges\". This
1480 /// matches experimental results - most routing nodes do not aggressively rebalance their
1481 /// channels and flows in the network are often unbalanced, leaving liquidity usually
1482 /// unavailable.
1483 ///
1484 /// Thus, for the \"best\" routes, leave this flag `false`. However, the flag does imply a number
1485 /// of floating-point multiplications in the hottest routing code, which may lead to routing
1486 /// performance degradation on some machines.
1487 ///
1488 /// Default value: false
1489 #[no_mangle]
1490 pub extern "C" fn ProbabilisticScoringFeeParameters_set_linear_success_probability(this_ptr: &mut ProbabilisticScoringFeeParameters, mut val: bool) {
1491         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.linear_success_probability = val;
1492 }
1493 impl Clone for ProbabilisticScoringFeeParameters {
1494         fn clone(&self) -> Self {
1495                 Self {
1496                         inner: if <*mut nativeProbabilisticScoringFeeParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1497                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1498                         is_owned: true,
1499                 }
1500         }
1501 }
1502 #[allow(unused)]
1503 /// Used only if an object of this type is returned as a trait impl by a method
1504 pub(crate) extern "C" fn ProbabilisticScoringFeeParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1505         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringFeeParameters)).clone() })) as *mut c_void
1506 }
1507 #[no_mangle]
1508 /// Creates a copy of the ProbabilisticScoringFeeParameters
1509 pub extern "C" fn ProbabilisticScoringFeeParameters_clone(orig: &ProbabilisticScoringFeeParameters) -> ProbabilisticScoringFeeParameters {
1510         orig.clone()
1511 }
1512 /// Creates a "default" ProbabilisticScoringFeeParameters. See struct and individual field documentaiton for details on which values are used.
1513 #[must_use]
1514 #[no_mangle]
1515 pub extern "C" fn ProbabilisticScoringFeeParameters_default() -> ProbabilisticScoringFeeParameters {
1516         ProbabilisticScoringFeeParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1517 }
1518 /// Marks the node with the given `node_id` as banned,
1519 /// i.e it will be avoided during path finding.
1520 #[no_mangle]
1521 pub extern "C" fn ProbabilisticScoringFeeParameters_add_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, node_id: &crate::lightning::routing::gossip::NodeId) {
1522         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.add_banned(node_id.get_native_ref())
1523 }
1524
1525 /// Marks all nodes in the given list as banned, i.e.,
1526 /// they will be avoided during path finding.
1527 #[no_mangle]
1528 pub extern "C" fn ProbabilisticScoringFeeParameters_add_banned_from_list(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, mut node_ids: crate::c_types::derived::CVec_NodeIdZ) {
1529         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()) } }); };
1530         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.add_banned_from_list(local_node_ids)
1531 }
1532
1533 /// Removes the node with the given `node_id` from the list of nodes to avoid.
1534 #[no_mangle]
1535 pub extern "C" fn ProbabilisticScoringFeeParameters_remove_banned(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, node_id: &crate::lightning::routing::gossip::NodeId) {
1536         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.remove_banned(node_id.get_native_ref())
1537 }
1538
1539 /// Sets a manual penalty for the given node.
1540 #[no_mangle]
1541 pub extern "C" fn ProbabilisticScoringFeeParameters_set_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, node_id: &crate::lightning::routing::gossip::NodeId, mut penalty: u64) {
1542         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.set_manual_penalty(node_id.get_native_ref(), penalty)
1543 }
1544
1545 /// Removes the node with the given `node_id` from the list of manual penalties.
1546 #[no_mangle]
1547 pub extern "C" fn ProbabilisticScoringFeeParameters_remove_manual_penalty(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters, node_id: &crate::lightning::routing::gossip::NodeId) {
1548         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.remove_manual_penalty(node_id.get_native_ref())
1549 }
1550
1551 /// Clears the list of manual penalties that are applied during path finding.
1552 #[no_mangle]
1553 pub extern "C" fn ProbabilisticScoringFeeParameters_clear_manual_penalties(this_arg: &mut crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) {
1554         unsafe { &mut (*ObjOps::untweak_ptr(this_arg.inner as *mut crate::lightning::routing::scoring::nativeProbabilisticScoringFeeParameters)) }.clear_manual_penalties()
1555 }
1556
1557
1558 use lightning::routing::scoring::ProbabilisticScoringDecayParameters as nativeProbabilisticScoringDecayParametersImport;
1559 pub(crate) type nativeProbabilisticScoringDecayParameters = nativeProbabilisticScoringDecayParametersImport;
1560
1561 /// Parameters for configuring [`ProbabilisticScorer`].
1562 ///
1563 /// Used to configure decay parameters that are static throughout the lifetime of the scorer.
1564 /// these decay parameters affect the score of the channel penalty and are not changed on a
1565 /// per-route penalty cost call.
1566 #[must_use]
1567 #[repr(C)]
1568 pub struct ProbabilisticScoringDecayParameters {
1569         /// A pointer to the opaque Rust object.
1570
1571         /// Nearly everywhere, inner must be non-null, however in places where
1572         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1573         pub inner: *mut nativeProbabilisticScoringDecayParameters,
1574         /// Indicates that this is the only struct which contains the same pointer.
1575
1576         /// Rust functions which take ownership of an object provided via an argument require
1577         /// this to be true and invalidate the object pointed to by inner.
1578         pub is_owned: bool,
1579 }
1580
1581 impl Drop for ProbabilisticScoringDecayParameters {
1582         fn drop(&mut self) {
1583                 if self.is_owned && !<*mut nativeProbabilisticScoringDecayParameters>::is_null(self.inner) {
1584                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
1585                 }
1586         }
1587 }
1588 /// Frees any resources used by the ProbabilisticScoringDecayParameters, if is_owned is set and inner is non-NULL.
1589 #[no_mangle]
1590 pub extern "C" fn ProbabilisticScoringDecayParameters_free(this_obj: ProbabilisticScoringDecayParameters) { }
1591 #[allow(unused)]
1592 /// Used only if an object of this type is returned as a trait impl by a method
1593 pub(crate) extern "C" fn ProbabilisticScoringDecayParameters_free_void(this_ptr: *mut c_void) {
1594         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScoringDecayParameters) };
1595 }
1596 #[allow(unused)]
1597 impl ProbabilisticScoringDecayParameters {
1598         pub(crate) fn get_native_ref(&self) -> &'static nativeProbabilisticScoringDecayParameters {
1599                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
1600         }
1601         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeProbabilisticScoringDecayParameters {
1602                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
1603         }
1604         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1605         pub(crate) fn take_inner(mut self) -> *mut nativeProbabilisticScoringDecayParameters {
1606                 assert!(self.is_owned);
1607                 let ret = ObjOps::untweak_ptr(self.inner);
1608                 self.inner = core::ptr::null_mut();
1609                 ret
1610         }
1611 }
1612 /// If we aren't learning any new datapoints for a channel, the historical liquidity bounds
1613 /// tracking can simply live on with increasingly stale data. Instead, when a channel has not
1614 /// seen a liquidity estimate update for this amount of time, the historical datapoints are
1615 /// decayed by half.
1616 /// For an example of historical_no_updates_half_life being used see [`historical_estimated_channel_liquidity_probabilities`]
1617 ///
1618 /// Note that after 16 or more half lives all historical data will be completely gone.
1619 ///
1620 /// Default value: 14 days
1621 ///
1622 /// [`historical_estimated_channel_liquidity_probabilities`]: ProbabilisticScorerUsingTime::historical_estimated_channel_liquidity_probabilities
1623 #[no_mangle]
1624 pub extern "C" fn ProbabilisticScoringDecayParameters_get_historical_no_updates_half_life(this_ptr: &ProbabilisticScoringDecayParameters) -> u64 {
1625         let mut inner_val = &mut this_ptr.get_native_mut_ref().historical_no_updates_half_life;
1626         inner_val.as_secs()
1627 }
1628 /// If we aren't learning any new datapoints for a channel, the historical liquidity bounds
1629 /// tracking can simply live on with increasingly stale data. Instead, when a channel has not
1630 /// seen a liquidity estimate update for this amount of time, the historical datapoints are
1631 /// decayed by half.
1632 /// For an example of historical_no_updates_half_life being used see [`historical_estimated_channel_liquidity_probabilities`]
1633 ///
1634 /// Note that after 16 or more half lives all historical data will be completely gone.
1635 ///
1636 /// Default value: 14 days
1637 ///
1638 /// [`historical_estimated_channel_liquidity_probabilities`]: ProbabilisticScorerUsingTime::historical_estimated_channel_liquidity_probabilities
1639 #[no_mangle]
1640 pub extern "C" fn ProbabilisticScoringDecayParameters_set_historical_no_updates_half_life(this_ptr: &mut ProbabilisticScoringDecayParameters, mut val: u64) {
1641         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.historical_no_updates_half_life = core::time::Duration::from_secs(val);
1642 }
1643 /// Whenever this amount of time elapses since the last update to a channel's liquidity bounds,
1644 /// the distance from the bounds to \"zero\" is cut in half. In other words, the lower-bound on
1645 /// the available liquidity is halved and the upper-bound moves half-way to the channel's total
1646 /// capacity.
1647 ///
1648 /// Because halving the liquidity bounds grows the uncertainty on the channel's liquidity,
1649 /// the penalty for an amount within the new bounds may change. See the [`ProbabilisticScorer`]
1650 /// struct documentation for more info on the way the liquidity bounds are used.
1651 ///
1652 /// For example, if the channel's capacity is 1 million sats, and the current upper and lower
1653 /// liquidity bounds are 200,000 sats and 600,000 sats, after this amount of time the upper
1654 /// and lower liquidity bounds will be decayed to 100,000 and 800,000 sats.
1655 ///
1656 /// Default value: 6 hours
1657 ///
1658 /// # Note
1659 ///
1660 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
1661 /// liquidity knowledge will never decay except when the bounds cross.
1662 #[no_mangle]
1663 pub extern "C" fn ProbabilisticScoringDecayParameters_get_liquidity_offset_half_life(this_ptr: &ProbabilisticScoringDecayParameters) -> u64 {
1664         let mut inner_val = &mut this_ptr.get_native_mut_ref().liquidity_offset_half_life;
1665         inner_val.as_secs()
1666 }
1667 /// Whenever this amount of time elapses since the last update to a channel's liquidity bounds,
1668 /// the distance from the bounds to \"zero\" is cut in half. In other words, the lower-bound on
1669 /// the available liquidity is halved and the upper-bound moves half-way to the channel's total
1670 /// capacity.
1671 ///
1672 /// Because halving the liquidity bounds grows the uncertainty on the channel's liquidity,
1673 /// the penalty for an amount within the new bounds may change. See the [`ProbabilisticScorer`]
1674 /// struct documentation for more info on the way the liquidity bounds are used.
1675 ///
1676 /// For example, if the channel's capacity is 1 million sats, and the current upper and lower
1677 /// liquidity bounds are 200,000 sats and 600,000 sats, after this amount of time the upper
1678 /// and lower liquidity bounds will be decayed to 100,000 and 800,000 sats.
1679 ///
1680 /// Default value: 6 hours
1681 ///
1682 /// # Note
1683 ///
1684 /// When built with the `no-std` feature, time will never elapse. Therefore, the channel
1685 /// liquidity knowledge will never decay except when the bounds cross.
1686 #[no_mangle]
1687 pub extern "C" fn ProbabilisticScoringDecayParameters_set_liquidity_offset_half_life(this_ptr: &mut ProbabilisticScoringDecayParameters, mut val: u64) {
1688         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.liquidity_offset_half_life = core::time::Duration::from_secs(val);
1689 }
1690 /// Constructs a new ProbabilisticScoringDecayParameters given each field
1691 #[must_use]
1692 #[no_mangle]
1693 pub extern "C" fn ProbabilisticScoringDecayParameters_new(mut historical_no_updates_half_life_arg: u64, mut liquidity_offset_half_life_arg: u64) -> ProbabilisticScoringDecayParameters {
1694         ProbabilisticScoringDecayParameters { inner: ObjOps::heap_alloc(nativeProbabilisticScoringDecayParameters {
1695                 historical_no_updates_half_life: core::time::Duration::from_secs(historical_no_updates_half_life_arg),
1696                 liquidity_offset_half_life: core::time::Duration::from_secs(liquidity_offset_half_life_arg),
1697         }), is_owned: true }
1698 }
1699 impl Clone for ProbabilisticScoringDecayParameters {
1700         fn clone(&self) -> Self {
1701                 Self {
1702                         inner: if <*mut nativeProbabilisticScoringDecayParameters>::is_null(self.inner) { core::ptr::null_mut() } else {
1703                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
1704                         is_owned: true,
1705                 }
1706         }
1707 }
1708 #[allow(unused)]
1709 /// Used only if an object of this type is returned as a trait impl by a method
1710 pub(crate) extern "C" fn ProbabilisticScoringDecayParameters_clone_void(this_ptr: *const c_void) -> *mut c_void {
1711         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeProbabilisticScoringDecayParameters)).clone() })) as *mut c_void
1712 }
1713 #[no_mangle]
1714 /// Creates a copy of the ProbabilisticScoringDecayParameters
1715 pub extern "C" fn ProbabilisticScoringDecayParameters_clone(orig: &ProbabilisticScoringDecayParameters) -> ProbabilisticScoringDecayParameters {
1716         orig.clone()
1717 }
1718 /// Creates a "default" ProbabilisticScoringDecayParameters. See struct and individual field documentaiton for details on which values are used.
1719 #[must_use]
1720 #[no_mangle]
1721 pub extern "C" fn ProbabilisticScoringDecayParameters_default() -> ProbabilisticScoringDecayParameters {
1722         ProbabilisticScoringDecayParameters { inner: ObjOps::heap_alloc(Default::default()), is_owned: true }
1723 }
1724 /// Creates a new scorer using the given scoring parameters for sending payments from a node
1725 /// through a network graph.
1726 #[must_use]
1727 #[no_mangle]
1728 pub extern "C" fn ProbabilisticScorer_new(mut decay_params: crate::lightning::routing::scoring::ProbabilisticScoringDecayParameters, network_graph: &crate::lightning::routing::gossip::NetworkGraph, mut logger: crate::lightning::util::logger::Logger) -> crate::lightning::routing::scoring::ProbabilisticScorer {
1729         let mut ret = lightning::routing::scoring::ProbabilisticScorer::new(*unsafe { Box::from_raw(decay_params.take_inner()) }, network_graph.get_native_ref(), logger);
1730         crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(ret), is_owned: true }
1731 }
1732
1733 /// Dump the contents of this scorer into the configured logger.
1734 ///
1735 /// Note that this writes roughly one line per channel for which we have a liquidity estimate,
1736 /// which may be a substantial amount of log output.
1737 #[no_mangle]
1738 pub extern "C" fn ProbabilisticScorer_debug_log_liquidity_stats(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer) {
1739         unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.debug_log_liquidity_stats()
1740 }
1741
1742 /// Query the estimated minimum and maximum liquidity available for sending a payment over the
1743 /// channel with `scid` towards the given `target` node.
1744 #[must_use]
1745 #[no_mangle]
1746 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 {
1747         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.estimated_channel_liquidity_range(scid, target.get_native_ref());
1748         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 }) };
1749         local_ret
1750 }
1751
1752 /// Query the historical estimated minimum and maximum liquidity available for sending a
1753 /// payment over the channel with `scid` towards the given `target` node.
1754 ///
1755 /// Returns two sets of 32 buckets. The first set describes the lower-bound liquidity history,
1756 /// the second set describes the upper-bound liquidity history. Each bucket describes the
1757 /// relative frequency at which we've seen a liquidity bound in the bucket's range relative to
1758 /// the channel's total capacity, on an arbitrary scale. Because the values are slowly decayed,
1759 /// more recent data points are weighted more heavily than older datapoints.
1760 ///
1761 /// Note that the range of each bucket varies by its location to provide more granular results
1762 /// at the edges of a channel's capacity, where it is more likely to sit.
1763 ///
1764 /// When scoring, the estimated probability that an upper-/lower-bound lies in a given bucket
1765 /// is calculated by dividing that bucket's value with the total value of all buckets.
1766 ///
1767 /// For example, using a lower bucket count for illustrative purposes, a value of
1768 /// `[0, 0, 0, ..., 0, 32]` indicates that we believe the probability of a bound being very
1769 /// close to the channel's capacity to be 100%, and have never (recently) seen it in any other
1770 /// bucket. A value of `[31, 0, 0, ..., 0, 0, 32]` indicates we've seen the bound being both
1771 /// in the top and bottom bucket, and roughly with similar (recent) frequency.
1772 ///
1773 /// Because the datapoints are decayed slowly over time, values will eventually return to
1774 /// `Some(([1; 32], [1; 32]))` and then to `None` once no datapoints remain.
1775 ///
1776 /// In order to fetch a single success probability from the buckets provided here, as used in
1777 /// the scoring model, see [`Self::historical_estimated_payment_success_probability`].
1778 #[must_use]
1779 #[no_mangle]
1780 pub extern "C" fn ProbabilisticScorer_historical_estimated_channel_liquidity_probabilities(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer, mut scid: u64, target: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::COption_C2Tuple_ThirtyTwoU16sThirtyTwoU16sZZ {
1781         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.historical_estimated_channel_liquidity_probabilities(scid, target.get_native_ref());
1782         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C2Tuple_ThirtyTwoU16sThirtyTwoU16sZZ::None } else { crate::c_types::derived::COption_C2Tuple_ThirtyTwoU16sThirtyTwoU16sZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (ret.unwrap()); let mut local_ret_0 = (crate::c_types::ThirtyTwoU16s { data: orig_ret_0_0 }, crate::c_types::ThirtyTwoU16s { data: orig_ret_0_1 }).into(); local_ret_0 }) };
1783         local_ret
1784 }
1785
1786 /// Query the probability of payment success sending the given `amount_msat` over the channel
1787 /// with `scid` towards the given `target` node, based on the historical estimated liquidity
1788 /// bounds.
1789 ///
1790 /// These are the same bounds as returned by
1791 /// [`Self::historical_estimated_channel_liquidity_probabilities`] (but not those returned by
1792 /// [`Self::estimated_channel_liquidity_range`]).
1793 #[must_use]
1794 #[no_mangle]
1795 pub extern "C" fn ProbabilisticScorer_historical_estimated_payment_success_probability(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer, mut scid: u64, target: &crate::lightning::routing::gossip::NodeId, mut amount_msat: u64, params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> crate::c_types::derived::COption_f64Z {
1796         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.historical_estimated_payment_success_probability(scid, target.get_native_ref(), amount_msat, params.get_native_ref());
1797         let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_f64Z::None } else { crate::c_types::derived::COption_f64Z::Some( { ret.unwrap() }) };
1798         local_ret
1799 }
1800
1801 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::ScoreLookUp {
1802         fn from(obj: nativeProbabilisticScorer) -> Self {
1803                 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
1804                 let mut ret = ProbabilisticScorer_as_ScoreLookUp(&rust_obj);
1805                 // 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
1806                 rust_obj.inner = core::ptr::null_mut();
1807                 ret.free = Some(ProbabilisticScorer_free_void);
1808                 ret
1809         }
1810 }
1811 /// Constructs a new ScoreLookUp which calls the relevant methods on this_arg.
1812 /// This copies the `inner` pointer in this_arg and thus the returned ScoreLookUp must be freed before this_arg is
1813 #[no_mangle]
1814 pub extern "C" fn ProbabilisticScorer_as_ScoreLookUp(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::ScoreLookUp {
1815         crate::lightning::routing::scoring::ScoreLookUp {
1816                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1817                 free: None,
1818                 channel_penalty_msat: ProbabilisticScorer_ScoreLookUp_channel_penalty_msat,
1819         }
1820 }
1821
1822 #[must_use]
1823 extern "C" fn ProbabilisticScorer_ScoreLookUp_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, score_params: &crate::lightning::routing::scoring::ProbabilisticScoringFeeParameters) -> u64 {
1824         let mut ret = <nativeProbabilisticScorer as lightning::routing::scoring::ScoreLookUp<>>::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()) }, score_params.get_native_ref());
1825         ret
1826 }
1827
1828 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::ScoreUpdate {
1829         fn from(obj: nativeProbabilisticScorer) -> Self {
1830                 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
1831                 let mut ret = ProbabilisticScorer_as_ScoreUpdate(&rust_obj);
1832                 // 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
1833                 rust_obj.inner = core::ptr::null_mut();
1834                 ret.free = Some(ProbabilisticScorer_free_void);
1835                 ret
1836         }
1837 }
1838 /// Constructs a new ScoreUpdate which calls the relevant methods on this_arg.
1839 /// This copies the `inner` pointer in this_arg and thus the returned ScoreUpdate must be freed before this_arg is
1840 #[no_mangle]
1841 pub extern "C" fn ProbabilisticScorer_as_ScoreUpdate(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::ScoreUpdate {
1842         crate::lightning::routing::scoring::ScoreUpdate {
1843                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1844                 free: None,
1845                 payment_path_failed: ProbabilisticScorer_ScoreUpdate_payment_path_failed,
1846                 payment_path_successful: ProbabilisticScorer_ScoreUpdate_payment_path_successful,
1847                 probe_failed: ProbabilisticScorer_ScoreUpdate_probe_failed,
1848                 probe_successful: ProbabilisticScorer_ScoreUpdate_probe_successful,
1849         }
1850 }
1851
1852 extern "C" fn ProbabilisticScorer_ScoreUpdate_payment_path_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
1853         <nativeProbabilisticScorer as lightning::routing::scoring::ScoreUpdate<>>::payment_path_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, path.get_native_ref(), short_channel_id)
1854 }
1855 extern "C" fn ProbabilisticScorer_ScoreUpdate_payment_path_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
1856         <nativeProbabilisticScorer as lightning::routing::scoring::ScoreUpdate<>>::payment_path_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, path.get_native_ref())
1857 }
1858 extern "C" fn ProbabilisticScorer_ScoreUpdate_probe_failed(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path, mut short_channel_id: u64) {
1859         <nativeProbabilisticScorer as lightning::routing::scoring::ScoreUpdate<>>::probe_failed(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, path.get_native_ref(), short_channel_id)
1860 }
1861 extern "C" fn ProbabilisticScorer_ScoreUpdate_probe_successful(this_arg: *mut c_void, path: &crate::lightning::routing::router::Path) {
1862         <nativeProbabilisticScorer as lightning::routing::scoring::ScoreUpdate<>>::probe_successful(unsafe { &mut *(this_arg as *mut nativeProbabilisticScorer) }, path.get_native_ref())
1863 }
1864
1865 impl From<nativeProbabilisticScorer> for crate::lightning::routing::scoring::Score {
1866         fn from(obj: nativeProbabilisticScorer) -> Self {
1867                 let mut rust_obj = ProbabilisticScorer { inner: ObjOps::heap_alloc(obj), is_owned: true };
1868                 let mut ret = ProbabilisticScorer_as_Score(&rust_obj);
1869                 // 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
1870                 rust_obj.inner = core::ptr::null_mut();
1871                 ret.free = Some(ProbabilisticScorer_free_void);
1872                 ret
1873         }
1874 }
1875 /// Constructs a new Score which calls the relevant methods on this_arg.
1876 /// This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
1877 #[no_mangle]
1878 pub extern "C" fn ProbabilisticScorer_as_Score(this_arg: &ProbabilisticScorer) -> crate::lightning::routing::scoring::Score {
1879         crate::lightning::routing::scoring::Score {
1880                 this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1881                 free: None,
1882                 ScoreLookUp: crate::lightning::routing::scoring::ScoreLookUp {
1883                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1884                         free: None,
1885                         channel_penalty_msat: ProbabilisticScorer_ScoreLookUp_channel_penalty_msat,
1886                 },
1887                 ScoreUpdate: crate::lightning::routing::scoring::ScoreUpdate {
1888                         this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
1889                         free: None,
1890                         payment_path_failed: ProbabilisticScorer_ScoreUpdate_payment_path_failed,
1891                         payment_path_successful: ProbabilisticScorer_ScoreUpdate_payment_path_successful,
1892                         probe_failed: ProbabilisticScorer_ScoreUpdate_probe_failed,
1893                         probe_successful: ProbabilisticScorer_ScoreUpdate_probe_successful,
1894                 },
1895                 write: ProbabilisticScorer_write_void,
1896         }
1897 }
1898
1899
1900 mod approx {
1901
1902 use alloc::str::FromStr;
1903 use alloc::string::String;
1904 use core::ffi::c_void;
1905 use core::convert::Infallible;
1906 use bitcoin::hashes::Hash;
1907 use crate::c_types::*;
1908 #[cfg(feature="no-std")]
1909 use alloc::{vec::Vec, boxed::Box};
1910
1911 }
1912 mod bucketed_history {
1913
1914 use alloc::str::FromStr;
1915 use alloc::string::String;
1916 use core::ffi::c_void;
1917 use core::convert::Infallible;
1918 use bitcoin::hashes::Hash;
1919 use crate::c_types::*;
1920 #[cfg(feature="no-std")]
1921 use alloc::{vec::Vec, boxed::Box};
1922
1923 }
1924 #[no_mangle]
1925 /// Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
1926 pub extern "C" fn ProbabilisticScorer_write(obj: &crate::lightning::routing::scoring::ProbabilisticScorer) -> crate::c_types::derived::CVec_u8Z {
1927         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
1928 }
1929 #[no_mangle]
1930 pub(crate) extern "C" fn ProbabilisticScorer_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1931         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeProbabilisticScorer) })
1932 }
1933 #[no_mangle]
1934 /// Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
1935 pub extern "C" fn ProbabilisticScorer_read(ser: crate::c_types::u8slice, arg_a: crate::lightning::routing::scoring::ProbabilisticScoringDecayParameters, arg_b: &crate::lightning::routing::gossip::NetworkGraph, arg_c: crate::lightning::util::logger::Logger) -> crate::c_types::derived::CResult_ProbabilisticScorerDecodeErrorZ {
1936         let arg_a_conv = *unsafe { Box::from_raw(arg_a.take_inner()) };
1937         let arg_b_conv = arg_b.get_native_ref();
1938         let arg_c_conv = arg_c;
1939         let arg_conv = (arg_a_conv, arg_b_conv, arg_c_conv);
1940         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);
1941         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::scoring::ProbabilisticScorer { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
1942         local_res
1943 }