mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
plugins/libplugin-pay.c: Add facility to have paymods request lowering of the estimated max HTLCs.
This commit is contained in:
parent
d15717b576
commit
deced56344
2 changed files with 52 additions and 0 deletions
|
@ -39,6 +39,7 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
|
||||||
p->failroute_retry = false;
|
p->failroute_retry = false;
|
||||||
p->bolt11 = NULL;
|
p->bolt11 = NULL;
|
||||||
p->routetxt = NULL;
|
p->routetxt = NULL;
|
||||||
|
p->max_htlcs = UINT32_MAX;
|
||||||
|
|
||||||
/* Copy over the relevant pieces of information. */
|
/* Copy over the relevant pieces of information. */
|
||||||
if (parent != NULL) {
|
if (parent != NULL) {
|
||||||
|
@ -2908,6 +2909,7 @@ static struct presplit_mod_data *presplit_mod_data_init(struct payment *p)
|
||||||
|
|
||||||
static u32 payment_max_htlcs(const struct payment *p)
|
static u32 payment_max_htlcs(const struct payment *p)
|
||||||
{
|
{
|
||||||
|
const struct payment *root;
|
||||||
struct channel_hint *h;
|
struct channel_hint *h;
|
||||||
u32 res = 0;
|
u32 res = 0;
|
||||||
for (size_t i = 0; i < tal_count(p->channel_hints); i++) {
|
for (size_t i = 0; i < tal_count(p->channel_hints); i++) {
|
||||||
|
@ -2915,9 +2917,49 @@ static u32 payment_max_htlcs(const struct payment *p)
|
||||||
if (h->local && h->enabled)
|
if (h->local && h->enabled)
|
||||||
res += h->htlc_budget;
|
res += h->htlc_budget;
|
||||||
}
|
}
|
||||||
|
root = p;
|
||||||
|
while (root->parent)
|
||||||
|
root = root->parent;
|
||||||
|
if (res > root->max_htlcs)
|
||||||
|
res = root->max_htlcs;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Temporary comment out else GCC will complain that it is unused;
|
||||||
|
* will be used in a later commit. */
|
||||||
|
#if 0
|
||||||
|
/** payment_lower_max_htlcs
|
||||||
|
*
|
||||||
|
* @brief indicates that we have a good reason to believe that
|
||||||
|
* we should limit our number of max HTLCs.
|
||||||
|
*
|
||||||
|
* @desc Causes future payment_max_htlcs to have a maximum value
|
||||||
|
* they return.
|
||||||
|
* Can be called by multiple paymods: the lowest one any paymod
|
||||||
|
* has given will be used.
|
||||||
|
* If this is called with a limit higher than the existing limit,
|
||||||
|
* it just successfully returns without doing anything.
|
||||||
|
*
|
||||||
|
* @param p - a payment on the payment tree we should limit.
|
||||||
|
* @param limit - the number of max HTLCs.
|
||||||
|
* @param why - the reason we think the given max HTLCs is
|
||||||
|
* reasonable.
|
||||||
|
*/
|
||||||
|
static void payment_lower_max_htlcs(struct payment *p, u32 limit,
|
||||||
|
const char *why)
|
||||||
|
{
|
||||||
|
struct payment *root = payment_root(p);
|
||||||
|
if (root->max_htlcs > limit) {
|
||||||
|
paymod_log(p, LOG_INFORM,
|
||||||
|
"%s limit on max HTLCs: %"PRIu32", %s",
|
||||||
|
root->max_htlcs == UINT32_MAX ?
|
||||||
|
"Initial" : "Lowering",
|
||||||
|
limit, why);
|
||||||
|
root->max_htlcs = limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool payment_supports_mpp(struct payment *p)
|
static bool payment_supports_mpp(struct payment *p)
|
||||||
{
|
{
|
||||||
if (p->invoice == NULL || p->invoice->features == NULL)
|
if (p->invoice == NULL || p->invoice->features == NULL)
|
||||||
|
|
|
@ -270,6 +270,16 @@ struct payment {
|
||||||
|
|
||||||
/* A short description of the route of this payment. */
|
/* A short description of the route of this payment. */
|
||||||
char *routetxt;
|
char *routetxt;
|
||||||
|
|
||||||
|
/* The maximum number of parallel outgoing HTLCs we will allow.
|
||||||
|
* If unset, the maximum is based on the number of outgoing HTLCs.
|
||||||
|
* This only applies for the root payment, and is ignored on non-root
|
||||||
|
* payments.
|
||||||
|
* Clients of the paymod system MUST NOT modify it, and individual
|
||||||
|
* paymods MUST interact with it only via the payment_max_htlcs
|
||||||
|
* and payment_lower_max_htlcs functions.
|
||||||
|
*/
|
||||||
|
u32 max_htlcs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct payment_modifier {
|
struct payment_modifier {
|
||||||
|
|
Loading…
Add table
Reference in a new issue