[Java] Update auto-generated Java bindings to LDK 0.0.110
[ldk-java] / src / main / java / org / ldk / structs / ProbabilisticScorer.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * [`Score`] implementation using channel success probability distributions.
13  * 
14  * Based on *Optimally Reliable & Cheap Payment Flows on the Lightning Network* by Rene Pickhardt
15  * and Stefan Richter [[1]]. Given the uncertainty of channel liquidity balances, probability
16  * distributions are defined based on knowledge learned from successful and unsuccessful attempts.
17  * Then the negative `log10` of the success probability is used to determine the cost of routing a
18  * specific HTLC amount through a channel.
19  * 
20  * Knowledge about channel liquidity balances takes the form of upper and lower bounds on the
21  * possible liquidity. Certainty of the bounds is decreased over time using a decay function. See
22  * [`ProbabilisticScoringParameters`] for details.
23  * 
24  * Since the scorer aims to learn the current channel liquidity balances, it works best for nodes
25  * with high payment volume or that actively probe the [`NetworkGraph`]. Nodes with low payment
26  * volume are more likely to experience failed payment paths, which would need to be retried.
27  * 
28  * # Note
29  * 
30  * Mixing the `no-std` feature between serialization and deserialization results in undefined
31  * behavior.
32  * 
33  * [1]: https://arxiv.org/abs/2107.05322
34  */
35 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
36 public class ProbabilisticScorer extends CommonBase {
37         ProbabilisticScorer(Object _dummy, long ptr) { super(ptr); }
38         @Override @SuppressWarnings("deprecation")
39         protected void finalize() throws Throwable {
40                 super.finalize();
41                 if (ptr != 0) { bindings.ProbabilisticScorer_free(ptr); }
42         }
43
44         /**
45          * Creates a new scorer using the given scoring parameters for sending payments from a node
46          * through a network graph.
47          */
48         public static ProbabilisticScorer of(ProbabilisticScoringParameters params, NetworkGraph network_graph, Logger logger) {
49                 long ret = bindings.ProbabilisticScorer_new(params == null ? 0 : params.ptr & ~1, network_graph == null ? 0 : network_graph.ptr & ~1, logger == null ? 0 : logger.ptr);
50                 Reference.reachabilityFence(params);
51                 Reference.reachabilityFence(network_graph);
52                 Reference.reachabilityFence(logger);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 org.ldk.structs.ProbabilisticScorer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ProbabilisticScorer(null, ret); }
55                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
56                 ret_hu_conv.ptrs_to.add(network_graph);
57                 ret_hu_conv.ptrs_to.add(logger);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * Dump the contents of this scorer into the configured logger.
63          * 
64          * Note that this writes roughly one line per channel for which we have a liquidity estimate,
65          * which may be a substantial amount of log output.
66          */
67         public void debug_log_liquidity_stats() {
68                 bindings.ProbabilisticScorer_debug_log_liquidity_stats(this.ptr);
69                 Reference.reachabilityFence(this);
70         }
71
72         /**
73          * Query the estimated minimum and maximum liquidity available for sending a payment over the
74          * channel with `scid` towards the given `target` node.
75          */
76         public Option_C2Tuple_u64u64ZZ estimated_channel_liquidity_range(long scid, NodeId target) {
77                 long ret = bindings.ProbabilisticScorer_estimated_channel_liquidity_range(this.ptr, scid, target == null ? 0 : target.ptr & ~1);
78                 Reference.reachabilityFence(this);
79                 Reference.reachabilityFence(scid);
80                 Reference.reachabilityFence(target);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 org.ldk.structs.Option_C2Tuple_u64u64ZZ ret_hu_conv = org.ldk.structs.Option_C2Tuple_u64u64ZZ.constr_from_ptr(ret);
83                 ret_hu_conv.ptrs_to.add(this);
84                 this.ptrs_to.add(target);
85                 return ret_hu_conv;
86         }
87
88         /**
89          * Marks the node with the given `node_id` as banned, i.e.,
90          * it will be avoided during path finding.
91          */
92         public void add_banned(NodeId node_id) {
93                 bindings.ProbabilisticScorer_add_banned(this.ptr, node_id == null ? 0 : node_id.ptr & ~1);
94                 Reference.reachabilityFence(this);
95                 Reference.reachabilityFence(node_id);
96                 this.ptrs_to.add(node_id);
97         }
98
99         /**
100          * Removes the node with the given `node_id` from the list of nodes to avoid.
101          */
102         public void remove_banned(NodeId node_id) {
103                 bindings.ProbabilisticScorer_remove_banned(this.ptr, node_id == null ? 0 : node_id.ptr & ~1);
104                 Reference.reachabilityFence(this);
105                 Reference.reachabilityFence(node_id);
106                 this.ptrs_to.add(node_id);
107         }
108
109         /**
110          * Sets a manual penalty for the given node.
111          */
112         public void set_manual_penalty(NodeId node_id, long penalty) {
113                 bindings.ProbabilisticScorer_set_manual_penalty(this.ptr, node_id == null ? 0 : node_id.ptr & ~1, penalty);
114                 Reference.reachabilityFence(this);
115                 Reference.reachabilityFence(node_id);
116                 Reference.reachabilityFence(penalty);
117                 this.ptrs_to.add(node_id);
118         }
119
120         /**
121          * Removes the node with the given `node_id` from the list of manual penalties.
122          */
123         public void remove_manual_penalty(NodeId node_id) {
124                 bindings.ProbabilisticScorer_remove_manual_penalty(this.ptr, node_id == null ? 0 : node_id.ptr & ~1);
125                 Reference.reachabilityFence(this);
126                 Reference.reachabilityFence(node_id);
127                 this.ptrs_to.add(node_id);
128         }
129
130         /**
131          * Clears the list of manual penalties that are applied during path finding.
132          */
133         public void clear_manual_penalties() {
134                 bindings.ProbabilisticScorer_clear_manual_penalties(this.ptr);
135                 Reference.reachabilityFence(this);
136         }
137
138         /**
139          * Constructs a new Score which calls the relevant methods on this_arg.
140          * This copies the `inner` pointer in this_arg and thus the returned Score must be freed before this_arg is
141          */
142         public Score as_Score() {
143                 long ret = bindings.ProbabilisticScorer_as_Score(this.ptr);
144                 Reference.reachabilityFence(this);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 Score ret_hu_conv = new Score(null, ret);
147                 ret_hu_conv.ptrs_to.add(this);
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Serialize the ProbabilisticScorer object into a byte array which can be read by ProbabilisticScorer_read
153          */
154         public byte[] write() {
155                 byte[] ret = bindings.ProbabilisticScorer_write(this.ptr);
156                 Reference.reachabilityFence(this);
157                 return ret;
158         }
159
160         /**
161          * Read a ProbabilisticScorer from a byte array, created by ProbabilisticScorer_write
162          */
163         public static Result_ProbabilisticScorerDecodeErrorZ read(byte[] ser, ProbabilisticScoringParameters arg_a, NetworkGraph arg_b, Logger arg_c) {
164                 long ret = bindings.ProbabilisticScorer_read(ser, arg_a == null ? 0 : arg_a.ptr & ~1, arg_b == null ? 0 : arg_b.ptr & ~1, arg_c == null ? 0 : arg_c.ptr);
165                 Reference.reachabilityFence(ser);
166                 Reference.reachabilityFence(arg_a);
167                 Reference.reachabilityFence(arg_b);
168                 Reference.reachabilityFence(arg_c);
169                 if (ret >= 0 && ret <= 4096) { return null; }
170                 Result_ProbabilisticScorerDecodeErrorZ ret_hu_conv = Result_ProbabilisticScorerDecodeErrorZ.constr_from_ptr(ret);
171                 ret_hu_conv.ptrs_to.add(arg_b);
172                 ret_hu_conv.ptrs_to.add(arg_c);
173                 return ret_hu_conv;
174         }
175
176 }