|
16 | 16 | #define SUPERVERBOSE_ENABLED 1 |
17 | 17 | #endif |
18 | 18 |
|
19 | | -static struct amount_msat *flow_amounts(const tal_t *ctx, |
20 | | - struct plugin *plugin, |
21 | | - const struct flow *flow) |
22 | | -{ |
23 | | - const size_t pathlen = tal_count(flow->path); |
24 | | - struct amount_msat *amounts = tal_arr(ctx, struct amount_msat, pathlen); |
25 | | - amounts[pathlen - 1] = flow->delivers; |
26 | | - |
27 | | - for (int i = (int)pathlen - 2; i >= 0; i--) { |
28 | | - const struct half_chan *h = flow_edge(flow, i + 1); |
29 | | - amounts[i] = amounts[i + 1]; |
30 | | - if (!amount_msat_add_fee(&amounts[i], h->base_fee, |
31 | | - h->proportional_fee)) { |
32 | | - plugin_err(plugin, "Could not add fee %u/%u to amount %s in %i/%zu", |
33 | | - h->base_fee, h->proportional_fee, |
34 | | - fmt_amount_msat(tmpctx, amounts[i+1]), |
35 | | - i, pathlen); |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - return amounts; |
40 | | -} |
41 | | - |
42 | 19 | /* How much do we deliver to destination using this set of routes */ |
43 | 20 | struct amount_msat flowset_delivers(struct plugin *plugin, |
44 | 21 | struct flow **flows) |
@@ -84,75 +61,6 @@ static double edge_probability(struct amount_msat sent, |
84 | 61 | return 1.0 - amount_msat_ratio(numerator, denominator); |
85 | 62 | } |
86 | 63 |
|
87 | | -/* Compute the prob. of success of a set of concurrent set of flows. |
88 | | - * |
89 | | - * IMPORTANT: this is not simply the multiplication of the prob. of success of |
90 | | - * all of them, because they're not independent events. A flow that passes |
91 | | - * through a channel c changes that channel's liquidity and then if another flow |
92 | | - * passes through that same channel the previous liquidity change must be taken |
93 | | - * into account. |
94 | | - * |
95 | | - * P(A and B) != P(A) * P(B), |
96 | | - * |
97 | | - * but |
98 | | - * |
99 | | - * P(A and B) = P(A) * P(B | A) |
100 | | - * |
101 | | - * also due to the linear form of P() we have |
102 | | - * |
103 | | - * P(A and B) = P(A + B) |
104 | | - * */ |
105 | | -struct chan_inflight_flow |
106 | | -{ |
107 | | - struct amount_msat half[2]; |
108 | | -}; |
109 | | - |
110 | | -double flowset_probability(struct flow **flows, |
111 | | - const struct route_query *rq) |
112 | | -{ |
113 | | - double prob = 1.0; |
114 | | - |
115 | | - // TODO(eduardo): should it be better to use a map instead of an array |
116 | | - // here? |
117 | | - const size_t max_num_chans = gossmap_max_chan_idx(rq->gossmap); |
118 | | - struct chan_inflight_flow *in_flight = |
119 | | - tal_arrz(tmpctx, struct chan_inflight_flow, max_num_chans); |
120 | | - |
121 | | - for (size_t i = 0; i < tal_count(flows); ++i) { |
122 | | - const struct flow *f = flows[i]; |
123 | | - const size_t pathlen = tal_count(f->path); |
124 | | - struct amount_msat *amounts = flow_amounts(tmpctx, rq->plugin, f); |
125 | | - |
126 | | - for (size_t j = 0; j < pathlen; ++j) { |
127 | | - struct amount_msat mincap, maxcap; |
128 | | - const int c_dir = f->dirs[j]; |
129 | | - const u32 c_idx = gossmap_chan_idx(rq->gossmap, f->path[j]); |
130 | | - const struct amount_msat deliver = amounts[j]; |
131 | | - |
132 | | - get_constraints(rq, f->path[j], c_dir, &mincap, &maxcap); |
133 | | - struct short_channel_id_dir scidd; |
134 | | - scidd.scid = gossmap_chan_scid(rq->gossmap, f->path[j]); |
135 | | - scidd.dir = c_dir; |
136 | | - |
137 | | - rq_log(tmpctx, rq, LOG_DBG, "flow: edge_probability for %s: min=%s, max=%s, sent=%s", |
138 | | - fmt_short_channel_id_dir(tmpctx, &scidd), |
139 | | - fmt_amount_msat(tmpctx, mincap), |
140 | | - fmt_amount_msat(tmpctx, maxcap), |
141 | | - fmt_amount_msat(tmpctx, in_flight[c_idx].half[c_dir])); |
142 | | - prob *= edge_probability(deliver, mincap, maxcap, |
143 | | - in_flight[c_idx].half[c_dir]); |
144 | | - |
145 | | - if (!amount_msat_accumulate(&in_flight[c_idx].half[c_dir], |
146 | | - deliver)) { |
147 | | - plugin_err(rq->plugin, "Could not add %s to inflight %s", |
148 | | - fmt_amount_msat(tmpctx, deliver), |
149 | | - fmt_amount_msat(tmpctx, in_flight[c_idx].half[c_dir])); |
150 | | - } |
151 | | - } |
152 | | - } |
153 | | - return prob; |
154 | | -} |
155 | | - |
156 | 64 | struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow) |
157 | 65 | { |
158 | 66 | const size_t pathlen = tal_count(flow->path); |
|
0 commit comments