TODO(eduardo): choose some default values for the minflow parameters eduardo: I think it should be clear that this module deals with linear * flows, ie. base fees are not considered. Hence a flow along a path is * described with a sequence of directed channels and one amount. * In the `pay_flow` module there are dedicated routes to compute the actual * amount to be forward on each hop. * * T
| 946 | // TODO(eduardo): we should LOG_DBG the process of finding the MCF while |
| 947 | // adjusting the frugality factor. |
| 948 | static struct flow **minflow(const tal_t *ctx, |
| 949 | const struct route_query *rq, |
| 950 | const struct gossmap_node *source, |
| 951 | const struct gossmap_node *target, |
| 952 | struct amount_msat amount, |
| 953 | u32 mu, |
| 954 | double delay_feefactor) |
| 955 | { |
| 956 | struct flow **flow_paths; |
| 957 | /* We allocate everything off this, and free it at the end, |
| 958 | * as we can be called multiple times without cleaning tmpctx! */ |
| 959 | tal_t *working_ctx = tal(NULL, char); |
| 960 | struct pay_parameters *params = tal(working_ctx, struct pay_parameters); |
| 961 | |
| 962 | params->rq = rq; |
| 963 | params->source = source; |
| 964 | params->target = target; |
| 965 | params->amount = amount; |
| 966 | /* -> We reduce the granularity of the flow by limiting the subdivision |
| 967 | * of the payment amount into 1000 units of flow. That reduces the |
| 968 | * computational burden for algorithms that depend on it, eg. "capacity |
| 969 | * scaling" and "successive shortest path". |
| 970 | * -> Using Ceil operation instead of Floor so that |
| 971 | * accuracy x 1000 >= amount |
| 972 | * */ |
| 973 | params->accuracy = |
| 974 | amount_msat_max(AMOUNT_MSAT(1), amount_msat_div_ceil(amount, 1000)); |
| 975 | |
| 976 | // template the channel partition into linear arcs |
| 977 | params->cap_fraction[0]=0; |
| 978 | params->cost_fraction[0]=0; |
| 979 | for(size_t i =1;i<CHANNEL_PARTS;++i) |
| 980 | { |
| 981 | params->cap_fraction[i]=CHANNEL_PIVOTS[i]-CHANNEL_PIVOTS[i-1]; |
| 982 | params->cost_fraction[i]= |
| 983 | log((1-CHANNEL_PIVOTS[i-1])/(1-CHANNEL_PIVOTS[i])) |
| 984 | /params->cap_fraction[i]; |
| 985 | } |
| 986 | |
| 987 | params->delay_feefactor = delay_feefactor; |
| 988 | params->base_fee_penalty = base_fee_penalty_estimate(amount); |
| 989 | |
| 990 | // build the uncertainty network with linearization and residual arcs |
| 991 | struct graph *graph; |
| 992 | double *arc_prob_cost; |
| 993 | s64 *arc_fee_cost; |
| 994 | s64 *arc_capacity; |
| 995 | init_linear_network(working_ctx, params, &graph, &arc_prob_cost, |
| 996 | &arc_fee_cost, &arc_capacity); |
| 997 | |
| 998 | const size_t max_num_arcs = graph_max_num_arcs(graph); |
| 999 | const size_t max_num_nodes = graph_max_num_nodes(graph); |
| 1000 | s64 *arc_cost; |
| 1001 | s64 *node_potential; |
| 1002 | s64 *node_excess; |
| 1003 | arc_cost = tal_arrz(working_ctx, s64, max_num_arcs); |
| 1004 | node_potential = tal_arrz(working_ctx, s64, max_num_nodes); |
| 1005 | node_excess = tal_arrz(working_ctx, s64, max_num_nodes); |
nothing calls this directly
no test coverage detected