Skip to content

Commit 6260052

Browse files
committed
pay: fix removal of channel hint estimated capacity
Changelog-Fixed: Plugins: pay now correctly estimates channel capacity after payment failure, fixing some retry cases. The `estimated_capacity` was properly substracted from the channel hint, but adding the amount back did not work. The amount was added back and then immediately substracted again. This caused the `estimated_capacity` to ever decrease. This commit makes sure re-adding the amount to the `estimated_capacity` works as expected.
1 parent 9a4be1a commit 6260052

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

plugins/libplugin-pay.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,19 @@ static bool payment_chanhints_apply_route(struct payment *p, bool remove)
583583
curhint->local->htlc_budget--;
584584
}
585585

586-
if (remove && !amount_msat_add(
586+
/* Don't get fancy and replace this with remove && !amount_msat_add
587+
* It won't work! */
588+
if (remove) {
589+
if (!amount_msat_add(
587590
&curhint->estimated_capacity,
588591
curhint->estimated_capacity,
589592
curhop->amount)) {
590-
/* This should never happen, it'd mean
591-
* that we unapply a route that would
592-
* result in a msatoshi
593-
* wrap-around. */
594-
abort();
593+
/* This should never happen, it'd mean
594+
* that we unapply a route that would
595+
* result in a msatoshi
596+
* wrap-around. */
597+
abort();
598+
}
595599
} else if (!amount_msat_sub(
596600
&curhint->estimated_capacity,
597601
curhint->estimated_capacity,

0 commit comments

Comments
 (0)