pay: Allow using a channel on equality of estimated capacity

In the case of the local channel we set the estimation to the exact
value spendable, which is important when we want to drain a channel,
because there we actually want to get the last msat.
This commit is contained in:
Christian Decker
2022-07-06 14:56:46 +02:00
parent 5a54f450bd
commit 2def843dce

View File

@@ -584,10 +584,8 @@ payment_get_excluded_channels(const tal_t *ctx, struct payment *p)
if (!hint->enabled) if (!hint->enabled)
tal_arr_expand(&res, hint->scid); tal_arr_expand(&res, hint->scid);
else if (amount_msat_greater_eq(p->amount, else if (amount_msat_greater(p->amount,
hint->estimated_capacity)) hint->estimated_capacity))
/* We exclude on equality because we've set the
* estimate to the smallest failed attempt. */
tal_arr_expand(&res, hint->scid); tal_arr_expand(&res, hint->scid);
else if (hint->local && hint->htlc_budget == 0) else if (hint->local && hint->htlc_budget == 0)
@@ -1248,6 +1246,7 @@ handle_intermediate_failure(struct command *cmd,
enum onion_wire failcode) enum onion_wire failcode)
{ {
struct payment *root = payment_root(p); struct payment *root = payment_root(p);
struct amount_msat estimated;
paymod_log(p, LOG_DBG, paymod_log(p, LOG_DBG,
"Intermediate node %s reported %04x (%s) at %s on route %s", "Intermediate node %s reported %04x (%s) at %s on route %s",
@@ -1288,11 +1287,20 @@ handle_intermediate_failure(struct command *cmd,
break; break;
case WIRE_TEMPORARY_CHANNEL_FAILURE: { case WIRE_TEMPORARY_CHANNEL_FAILURE: {
estimated = errchan->amount;
/* Subtract one msat more, since we know that the amount did not
* work. This allows us to then allow on equality, this is for
* example necessary for local channels where exact matches
* should be allowed. */
if (!amount_msat_sub(&estimated, estimated, AMOUNT_MSAT(1)))
abort();
/* These are an indication that the capacity was insufficient, /* These are an indication that the capacity was insufficient,
* remember the amount we tried as an estimate. */ * remember the amount we tried as an estimate. */
channel_hints_update(root, errchan->scid, channel_hints_update(root, errchan->scid,
errchan->direction, true, false, errchan->direction, true, false,
&errchan->amount, NULL); &estimated, NULL);
goto error; goto error;
} }