mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
askrene: remove flowset_probability() now refine step calculates it.
Now we've checked it gives the same answers, we can remove a lot of work in flow.c. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
5501e4b13d
commit
95c5fda79f
4 changed files with 1 additions and 109 deletions
|
@ -16,7 +16,6 @@
|
|||
#include <common/json_stream.h>
|
||||
#include <common/route.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <plugins/askrene/askrene.h>
|
||||
#include <plugins/askrene/explain_failure.h>
|
||||
#include <plugins/askrene/flow.h>
|
||||
|
@ -337,7 +336,6 @@ static const char *get_routes(const tal_t *ctx,
|
|||
double delay_feefactor;
|
||||
u32 mu;
|
||||
const char *ret;
|
||||
double flowset_prob;
|
||||
|
||||
if (gossmap_refresh(askrene->gossmap, NULL)) {
|
||||
/* FIXME: gossmap_refresh callbacks to we can update in place */
|
||||
|
@ -490,7 +488,7 @@ too_expensive:
|
|||
* fees, so we try to adjust now. We could re-run MCF if this
|
||||
* fails, but failure basically never happens where payment is
|
||||
* still possible */
|
||||
ret = refine_with_fees_and_limits(ctx, rq, amount, &flows, &flowset_prob);
|
||||
ret = refine_with_fees_and_limits(ctx, rq, amount, &flows, probability);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
|
@ -542,11 +540,6 @@ too_expensive:
|
|||
fmt_route(tmpctx, r, (*amounts)[i], finalcltv));
|
||||
}
|
||||
|
||||
*probability = flowset_probability(flows, rq);
|
||||
if (fabs(*probability - flowset_prob) > 0.000001) {
|
||||
rq_log(tmpctx, rq, LOG_BROKEN, "Probability %f != expected %f",
|
||||
*probability, flowset_prob);
|
||||
}
|
||||
gossmap_remove_localmods(askrene->gossmap, localmods);
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -16,29 +16,6 @@
|
|||
#define SUPERVERBOSE_ENABLED 1
|
||||
#endif
|
||||
|
||||
static struct amount_msat *flow_amounts(const tal_t *ctx,
|
||||
struct plugin *plugin,
|
||||
const struct flow *flow)
|
||||
{
|
||||
const size_t pathlen = tal_count(flow->path);
|
||||
struct amount_msat *amounts = tal_arr(ctx, struct amount_msat, pathlen);
|
||||
amounts[pathlen - 1] = flow->delivers;
|
||||
|
||||
for (int i = (int)pathlen - 2; i >= 0; i--) {
|
||||
const struct half_chan *h = flow_edge(flow, i + 1);
|
||||
amounts[i] = amounts[i + 1];
|
||||
if (!amount_msat_add_fee(&amounts[i], h->base_fee,
|
||||
h->proportional_fee)) {
|
||||
plugin_err(plugin, "Could not add fee %u/%u to amount %s in %i/%zu",
|
||||
h->base_fee, h->proportional_fee,
|
||||
fmt_amount_msat(tmpctx, amounts[i+1]),
|
||||
i, pathlen);
|
||||
}
|
||||
}
|
||||
|
||||
return amounts;
|
||||
}
|
||||
|
||||
/* How much do we deliver to destination using this set of routes */
|
||||
struct amount_msat flowset_delivers(struct plugin *plugin,
|
||||
struct flow **flows)
|
||||
|
@ -84,75 +61,6 @@ static double edge_probability(struct amount_msat sent,
|
|||
return 1.0 - amount_msat_ratio(numerator, denominator);
|
||||
}
|
||||
|
||||
/* Compute the prob. of success of a set of concurrent set of flows.
|
||||
*
|
||||
* IMPORTANT: this is not simply the multiplication of the prob. of success of
|
||||
* all of them, because they're not independent events. A flow that passes
|
||||
* through a channel c changes that channel's liquidity and then if another flow
|
||||
* passes through that same channel the previous liquidity change must be taken
|
||||
* into account.
|
||||
*
|
||||
* P(A and B) != P(A) * P(B),
|
||||
*
|
||||
* but
|
||||
*
|
||||
* P(A and B) = P(A) * P(B | A)
|
||||
*
|
||||
* also due to the linear form of P() we have
|
||||
*
|
||||
* P(A and B) = P(A + B)
|
||||
* */
|
||||
struct chan_inflight_flow
|
||||
{
|
||||
struct amount_msat half[2];
|
||||
};
|
||||
|
||||
double flowset_probability(struct flow **flows,
|
||||
const struct route_query *rq)
|
||||
{
|
||||
double prob = 1.0;
|
||||
|
||||
// TODO(eduardo): should it be better to use a map instead of an array
|
||||
// here?
|
||||
const size_t max_num_chans = gossmap_max_chan_idx(rq->gossmap);
|
||||
struct chan_inflight_flow *in_flight =
|
||||
tal_arrz(tmpctx, struct chan_inflight_flow, max_num_chans);
|
||||
|
||||
for (size_t i = 0; i < tal_count(flows); ++i) {
|
||||
const struct flow *f = flows[i];
|
||||
const size_t pathlen = tal_count(f->path);
|
||||
struct amount_msat *amounts = flow_amounts(tmpctx, rq->plugin, f);
|
||||
|
||||
for (size_t j = 0; j < pathlen; ++j) {
|
||||
struct amount_msat mincap, maxcap;
|
||||
const int c_dir = f->dirs[j];
|
||||
const u32 c_idx = gossmap_chan_idx(rq->gossmap, f->path[j]);
|
||||
const struct amount_msat deliver = amounts[j];
|
||||
|
||||
get_constraints(rq, f->path[j], c_dir, &mincap, &maxcap);
|
||||
struct short_channel_id_dir scidd;
|
||||
scidd.scid = gossmap_chan_scid(rq->gossmap, f->path[j]);
|
||||
scidd.dir = c_dir;
|
||||
|
||||
rq_log(tmpctx, rq, LOG_DBG, "flow: edge_probability for %s: min=%s, max=%s, sent=%s",
|
||||
fmt_short_channel_id_dir(tmpctx, &scidd),
|
||||
fmt_amount_msat(tmpctx, mincap),
|
||||
fmt_amount_msat(tmpctx, maxcap),
|
||||
fmt_amount_msat(tmpctx, in_flight[c_idx].half[c_dir]));
|
||||
prob *= edge_probability(deliver, mincap, maxcap,
|
||||
in_flight[c_idx].half[c_dir]);
|
||||
|
||||
if (!amount_msat_accumulate(&in_flight[c_idx].half[c_dir],
|
||||
deliver)) {
|
||||
plugin_err(rq->plugin, "Could not add %s to inflight %s",
|
||||
fmt_amount_msat(tmpctx, deliver),
|
||||
fmt_amount_msat(tmpctx, in_flight[c_idx].half[c_dir]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return prob;
|
||||
}
|
||||
|
||||
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow)
|
||||
{
|
||||
const size_t pathlen = tal_count(flow->path);
|
||||
|
|
|
@ -39,10 +39,6 @@ double flow_edge_cost(const struct gossmap *gossmap,
|
|||
double flow_probability(const struct flow *flow,
|
||||
const struct route_query *rq);
|
||||
|
||||
/* Compute the prob. of success of a set of concurrent set of flows. */
|
||||
double flowset_probability(struct flow **flows,
|
||||
const struct route_query *rq);
|
||||
|
||||
/* How much do we need to send to make this flow arrive. */
|
||||
struct amount_msat flow_spend(struct plugin *plugin, const struct flow *flow);
|
||||
|
||||
|
|
|
@ -427,11 +427,6 @@ static double edge_probability(const struct route_query *rq,
|
|||
|| !amount_msat_accumulate(&maxcap, additional))
|
||||
abort();
|
||||
|
||||
rq_log(tmpctx, rq, LOG_DBG, "refine: edge_probability for %s: min=%s, max=%s, sent=%s",
|
||||
fmt_short_channel_id_dir(tmpctx, scidd),
|
||||
fmt_amount_msat(tmpctx, mincap),
|
||||
fmt_amount_msat(tmpctx, maxcap),
|
||||
fmt_amount_msat(tmpctx, sent));
|
||||
if (amount_msat_less_eq(sent, mincap))
|
||||
return 1.0;
|
||||
else if (amount_msat_greater(sent, maxcap))
|
||||
|
|
Loading…
Add table
Reference in a new issue