2023-07-31 11:21:22 +09:30
|
|
|
#ifndef LIGHTNING_PLUGINS_RENEPAY_FLOW_H
|
|
|
|
#define LIGHTNING_PLUGINS_RENEPAY_FLOW_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <bitcoin/short_channel_id.h>
|
|
|
|
#include <ccan/htable/htable_type.h>
|
|
|
|
#include <common/amount.h>
|
|
|
|
#include <common/gossmap.h>
|
2024-04-08 11:00:33 +01:00
|
|
|
#include <plugins/renepay/chan_extra.h>
|
|
|
|
#include <plugins/renepay/errorcodes.h>
|
2023-07-31 11:21:22 +09:30
|
|
|
|
|
|
|
/* An actual partial flow. */
|
|
|
|
struct flow {
|
2023-07-31 11:21:25 +09:30
|
|
|
const struct gossmap_chan **path;
|
2023-07-31 11:21:22 +09:30
|
|
|
/* The directions to traverse. */
|
|
|
|
int *dirs;
|
|
|
|
/* Amounts for this flow (fees mean this shrinks across path). */
|
|
|
|
double success_prob;
|
2024-04-08 11:00:33 +01:00
|
|
|
struct amount_msat amount;
|
2023-07-31 11:21:22 +09:30
|
|
|
};
|
|
|
|
|
2024-05-06 10:01:24 +01:00
|
|
|
const char *fmt_flows(const tal_t *ctx, const struct gossmap *gossmap,
|
|
|
|
struct chan_extra_map *chan_extra_map,
|
|
|
|
struct flow **flows);
|
|
|
|
|
2023-07-31 11:21:22 +09:30
|
|
|
/* Helper to access the half chan at flow index idx */
|
|
|
|
const struct half_chan *flow_edge(const struct flow *flow, size_t idx);
|
|
|
|
|
|
|
|
/* A big number, meaning "don't bother" (not infinite, since you may add) */
|
|
|
|
#define FLOW_INF_COST 100000000.0
|
|
|
|
|
|
|
|
/* Cost function to send @f msat through @c in direction @dir,
|
|
|
|
* given we already have a flow of prev_flow. */
|
|
|
|
double flow_edge_cost(const struct gossmap *gossmap,
|
|
|
|
const struct gossmap_chan *c, int dir,
|
|
|
|
const struct amount_msat known_min,
|
|
|
|
const struct amount_msat known_max,
|
|
|
|
struct amount_msat prev_flow,
|
|
|
|
struct amount_msat f,
|
|
|
|
double mu,
|
|
|
|
double basefee_penalty,
|
|
|
|
double delay_riskfactor);
|
|
|
|
|
|
|
|
/* Compute the prob. of success of a set of concurrent set of flows. */
|
2023-12-18 14:18:00 +01:00
|
|
|
double flowset_probability(const tal_t *ctx, struct flow **flows,
|
|
|
|
const struct gossmap *const gossmap,
|
2024-08-15 07:19:00 +01:00
|
|
|
struct chan_extra_map *chan_extra_map,
|
|
|
|
bool compute_fees, char **fail);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 11:00:33 +01:00
|
|
|
/* How much do we need to send to make this flow arrive. */
|
|
|
|
bool flow_spend(struct amount_msat *ret, struct flow *flow);
|
2023-12-18 14:18:00 +01:00
|
|
|
|
2024-04-08 11:00:33 +01:00
|
|
|
/* How much do we pay in fees to make this flow arrive. */
|
|
|
|
bool flow_fee(struct amount_msat *ret, struct flow *flow);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2023-12-18 14:18:00 +01:00
|
|
|
bool flowset_fee(struct amount_msat *fee, struct flow **flows);
|
2023-07-31 11:21:22 +09:30
|
|
|
|
2024-04-08 11:00:33 +01:00
|
|
|
bool flowset_delivers(struct amount_msat *delivers, struct flow **flows);
|
2024-01-25 07:13:43 +01:00
|
|
|
|
2024-08-08 11:20:02 +01:00
|
|
|
/* how many channels are being used */
|
|
|
|
size_t flowset_size(struct flow **flows);
|
|
|
|
|
2024-04-08 11:00:33 +01:00
|
|
|
static inline struct amount_msat flow_delivers(const struct flow *flow)
|
2024-01-29 08:57:05 +01:00
|
|
|
{
|
2024-04-08 11:00:33 +01:00
|
|
|
return flow->amount;
|
2024-01-29 08:57:05 +01:00
|
|
|
}
|
|
|
|
|
2024-08-15 07:19:00 +01:00
|
|
|
struct amount_msat *tal_flow_amounts(const tal_t *ctx, const struct flow *flow,
|
|
|
|
bool compute_fees);
|
2024-04-08 11:00:33 +01:00
|
|
|
|
|
|
|
enum renepay_errorcode
|
|
|
|
flow_maximum_deliverable(struct amount_msat *max_deliverable,
|
|
|
|
const struct flow *flow,
|
|
|
|
const struct gossmap *gossmap,
|
|
|
|
struct chan_extra_map *chan_extra_map,
|
|
|
|
const struct gossmap_chan **bad_channel);
|
|
|
|
|
|
|
|
/* Assign the delivered amount to the flow if it fits
|
|
|
|
the path maximum capacity. */
|
|
|
|
bool flow_assign_delivery(struct flow *flow, const struct gossmap *gossmap,
|
|
|
|
struct chan_extra_map *chan_extra_map,
|
|
|
|
struct amount_msat requested_amount);
|
|
|
|
|
|
|
|
double flow_probability(struct flow *flow, const struct gossmap *gossmap,
|
2024-08-15 07:19:00 +01:00
|
|
|
struct chan_extra_map *chan_extra_map,
|
|
|
|
bool compute_fees);
|
2024-04-08 11:00:33 +01:00
|
|
|
|
|
|
|
u64 flow_delay(const struct flow *flow);
|
|
|
|
u64 flows_worst_delay(struct flow **flows);
|
|
|
|
|
|
|
|
struct flow **
|
|
|
|
flows_ensure_liquidity_constraints(const tal_t *ctx, struct flow **flows TAKES,
|
|
|
|
const struct gossmap *gossmap,
|
|
|
|
struct chan_extra_map *chan_extra_map);
|
|
|
|
|
2023-07-31 11:21:22 +09:30
|
|
|
#endif /* LIGHTNING_PLUGINS_RENEPAY_FLOW_H */
|