From 093933b14d4d199267eb414072721704fc78428d Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 3 Aug 2022 16:47:18 +0200 Subject: [PATCH] pay: Do not replay results against payments that were not suspended Suspended payments now have the same groupid as the actual attempt, this allows us to identify pay calls that were suspended due to us and terminate only those. Changelog-Fixed pay: Fixed a crash when `pay` was called multiple times while an attempt was already in progress. --- plugins/pay.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/pay.c b/plugins/pay.c index 5bf33031a..d6efa10e1 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -589,7 +589,12 @@ static void on_payment_success(struct payment *payment) * `payment_finished`. */ if (payment == p) continue; - if (!sha256_eq(payment->payment_hash, p->payment_hash)) + + /* Both groupid and payment_hash must match. This is + * because when we suspended the payment itself, we + * set the groupid to match. */ + if (!sha256_eq(payment->payment_hash, p->payment_hash) || + payment->groupid != p->groupid) continue; if (p->cmd == NULL) continue; @@ -675,7 +680,11 @@ static void on_payment_failure(struct payment *payment) * `payment_finished`. */ if (payment == p) continue; - if (!sha256_eq(payment->payment_hash, p->payment_hash)) + + /* When we suspended we've set the groupid to match so + * we'd know which calls were duplicates. */ + if (!sha256_eq(payment->payment_hash, p->payment_hash) || + payment->groupid != p->groupid) continue; if (p->cmd == NULL) continue;