X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Frouting%2Fscoring.rs;h=2c2980a8819bf83c6a60590604332786ab51ca83;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=3a3ad98848649fd512d4158970c08acb98eae1fb;hpb=a21177846ed75d66f68a1603f768410f07a65791;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/routing/scoring.rs b/lightning-c-bindings/src/lightning/routing/scoring.rs index 3a3ad98..2c2980a 100644 --- a/lightning-c-bindings/src/lightning/routing/scoring.rs +++ b/lightning-c-bindings/src/lightning/routing/scoring.rs @@ -19,7 +19,7 @@ //! # use lightning::routing::gossip::NetworkGraph; //! # use lightning::routing::router::{RouteParameters, find_route}; //! # use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters}; -//! # use lightning::chain::keysinterface::{KeysManager, KeysInterface}; +//! # use lightning::chain::keysinterface::KeysManager; //! # use lightning::util::logger::{Logger, Record}; //! # use bitcoin::secp256k1::PublicKey; //! # @@ -312,7 +312,7 @@ pub extern "C" fn MultiThreadedLockableScore_free(this_obj: MultiThreadedLockabl #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn MultiThreadedLockableScore_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedLockableScore) }; } #[allow(unused)] impl MultiThreadedLockableScore { @@ -363,7 +363,7 @@ pub extern "C" fn MultiThreadedScoreLock_free(this_obj: MultiThreadedScoreLock) #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn MultiThreadedScoreLock_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLock); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeMultiThreadedScoreLock) }; } #[allow(unused)] impl MultiThreadedScoreLock { @@ -542,7 +542,7 @@ pub extern "C" fn ChannelUsage_free(this_obj: ChannelUsage) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUsage_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUsage); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUsage) }; } #[allow(unused)] impl ChannelUsage { @@ -657,7 +657,7 @@ pub extern "C" fn FixedPenaltyScorer_free(this_obj: FixedPenaltyScorer) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FixedPenaltyScorer_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFixedPenaltyScorer) }; } #[allow(unused)] impl FixedPenaltyScorer { @@ -835,7 +835,7 @@ pub extern "C" fn ProbabilisticScorer_free(this_obj: ProbabilisticScorer) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScorer_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScorer); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScorer) }; } #[allow(unused)] impl ProbabilisticScorer { @@ -892,7 +892,7 @@ pub extern "C" fn ProbabilisticScoringParameters_free(this_obj: ProbabilisticSco #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ProbabilisticScoringParameters_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeProbabilisticScoringParameters) }; } #[allow(unused)] impl ProbabilisticScoringParameters { @@ -1309,6 +1309,35 @@ pub extern "C" fn ProbabilisticScorer_estimated_channel_liquidity_range(this_arg local_ret } +/// Query the historical estimated minimum and maximum liquidity available for sending a +/// payment over the channel with `scid` towards the given `target` node. +/// +/// Returns two sets of 8 buckets. The first set describes the octiles for lower-bound +/// liquidity estimates, the second set describes the octiles for upper-bound liquidity +/// estimates. Each bucket describes the relative frequency at which we've seen a liquidity +/// bound in the octile relative to the channel's total capacity, on an arbitrary scale. +/// Because the values are slowly decayed, more recent data points are weighted more heavily +/// than older datapoints. +/// +/// When scoring, the estimated probability that an upper-/lower-bound lies in a given octile +/// relative to the channel's total capacity is calculated by dividing that bucket's value with +/// the total of all buckets for the given bound. +/// +/// For example, a value of `[0, 0, 0, 0, 0, 0, 32]` indicates that we believe the probability +/// of a bound being in the top octile to be 100%, and have never (recently) seen it in any +/// other octiles. A value of `[31, 0, 0, 0, 0, 0, 0, 32]` indicates we've seen the bound being +/// both in the top and bottom octile, and roughly with similar (recent) frequency. +/// +/// Because the datapoints are decayed slowly over time, values will eventually return to +/// `Some(([0; 8], [0; 8]))`. +#[must_use] +#[no_mangle] +pub extern "C" fn ProbabilisticScorer_historical_estimated_channel_liquidity_probabilities(this_arg: &crate::lightning::routing::scoring::ProbabilisticScorer, mut scid: u64, target: &crate::lightning::routing::gossip::NodeId) -> crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.historical_estimated_channel_liquidity_probabilities(scid, target.get_native_ref()); + let mut local_ret = if ret.is_none() { crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ::None } else { crate::c_types::derived::COption_C2Tuple_EightU16sEightU16sZZ::Some( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (ret.unwrap()); let mut local_ret_0 = (crate::c_types::EightU16s { data: orig_ret_0_0 }, crate::c_types::EightU16s { data: orig_ret_0_1 }).into(); local_ret_0 }) }; + local_ret +} + /// Marks the node with the given `node_id` as banned, i.e., /// it will be avoided during path finding. #[no_mangle]