mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
7056018b15
The probability for a success forward of x amount on a channel is now computed as: P_success(x) = b * P_rene(x) where P_rene(x) is the probability distribution proposed by Rene Pickhardt with a uniform distribution on the known liquidity of the channel and 'b' is a new parameter we add in this PR, by the name of "base probability". The "base probability" represents the probability for a channel in the network choosen at random to be able to forward at least 1msat, ie. of being alive, non-depleted and with at least one HTLC slot. We don't know the value of 'b', but for the moment we assume that it is 0.98 and use that as default. As a consequence the probability cost becomes non-linear and non-convex because of the additional constant term: Cost(x) = - log P_success(x) = - log b - - log P_rene(x) = - log b + Cost_rene(x) We currently don't handle well base fees and neither this additional "base probability" but we can as a first approximation linearize the cost function in this way: Cost_linear(x) = (- log b)*x + Cost_rene_linear(x) Changelog-Added: renepay: Add a dev parameter to renepay that represents a constant probability of availability for all channels in the network. Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
68 lines
2.5 KiB
C
68 lines
2.5 KiB
C
#ifndef LIGHTNING_PLUGINS_RENEPAY_MCF_H
|
|
#define LIGHTNING_PLUGINS_RENEPAY_MCF_H
|
|
#include "config.h"
|
|
#include <ccan/bitmap/bitmap.h>
|
|
#include <common/amount.h>
|
|
#include <common/gossmap.h>
|
|
|
|
struct chan_extra_map;
|
|
|
|
enum {
|
|
RENEPAY_ERR_OK,
|
|
// No feasible flow found, either there is not enough known liquidity (or capacity)
|
|
// in the channels to complete the payment
|
|
RENEPAY_ERR_NOFEASIBLEFLOW,
|
|
// There is at least one feasible flow, but the the cheapest solution that we
|
|
// found is too expensive, we return the result anyways.
|
|
RENEPAY_ERR_NOCHEAPFLOW
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
* optimal_payment_flow - API for min cost flow function(s).
|
|
* @ctx: context to allocate returned flows from
|
|
* @gossmap: the gossip map
|
|
* @source: the source to start from
|
|
* @target: the target to pay
|
|
* @chan_extra_map: hashtable of extra per-channel information
|
|
* @disabled: NULL, or a bitmap by channel index of channels not to use.
|
|
* @amount: the amount we want to reach @target
|
|
*
|
|
* @max_fee: the maximum allowed in fees
|
|
*
|
|
* @min_probability: minimum probability accepted
|
|
*
|
|
* @delay_feefactor converts 1 block delay into msat, as if it were an additional
|
|
* fee. So if a CLTV delay on a node is 5 blocks, that's treated as if it
|
|
* were a fee of 5 * @delay_feefactor.
|
|
*
|
|
* @base_fee_penalty: factor to compute additional proportional cost from each
|
|
* unit of base fee. So #base_fee_penalty will be added to the effective
|
|
* proportional fee for each msat of base fee.
|
|
*
|
|
* effective_ppm = proportional_fee + base_fee_msat * base_fee_penalty
|
|
*
|
|
* @prob_cost_factor: factor used to monetize the probability cost. It is
|
|
* defined as the number of ppm (parts per million of the total payment) we
|
|
* are willing to pay to improve the probability of success by 0.1%.
|
|
*
|
|
* k_microsat = floor(1000*prob_cost_factor * payment_sat)
|
|
*
|
|
* this k is used to compute a prob. cost in units of microsats
|
|
*
|
|
* cost(payment) = - k_microsat * log Prob(payment)
|
|
*
|
|
* Return a series of subflows which deliver amount to target, or NULL.
|
|
*/
|
|
struct flow **minflow(const tal_t *ctx, struct gossmap *gossmap,
|
|
const struct gossmap_node *source,
|
|
const struct gossmap_node *target,
|
|
struct chan_extra_map *chan_extra_map,
|
|
const bitmap *disabled, struct amount_msat amount,
|
|
struct amount_msat max_fee, double min_probability,
|
|
double base_probability,
|
|
double delay_feefactor, double base_fee_penalty,
|
|
u32 prob_cost_factor, char **fail);
|
|
#endif /* LIGHTNING_PLUGINS_RENEPAY_MCF_H */
|