From aaefc60f1b4a5d1bf2ea769555beb77fba1fac6c Mon Sep 17 00:00:00 2001 From: Lagrang3 Date: Mon, 22 Jun 2026 08:29:28 +0100 Subject: [PATCH] listsendpays: discriminate ongoing payment by groupid A payment attempt in listpays is defined as pair (payment hash, group id). If we query xpay for ongoing payments we must discriminate using both values. Fixes flaky test tests/test_pay.py:test_sendpay_grouping ``` FAILED tests/test_pay.py::test_sendpay_grouping - AssertionError: assert ['pending', 'pending', 'complete'] == ['failed', 'failed', 'complete'] ``` Changelog-None Signed-off-by: Lagrang3 --- plugins/xpay/listpays.c | 3 ++- plugins/xpay/xpay.c | 6 ++++-- plugins/xpay/xpay.h | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/xpay/listpays.c b/plugins/xpay/listpays.c index e1c9de5a8..020fb2968 100644 --- a/plugins/xpay/listpays.c +++ b/plugins/xpay/listpays.c @@ -159,7 +159,8 @@ static void add_new_entry(struct plugin *plugin, if (pm->state & PAYMENT_COMPLETE) json_add_string(ret, "status", "complete"); - else if (pm->state & PAYMENT_PENDING || attempt_ongoing(plugin, pm->payment_hash)) + else if (pm->state & PAYMENT_PENDING || + attempt_ongoing(plugin, pm->payment_hash, pm->sortkey.groupid)) json_add_string(ret, "status", "pending"); else json_add_string(ret, "status", "failed"); diff --git a/plugins/xpay/xpay.c b/plugins/xpay/xpay.c index 7cf2c2061..d9a3c297f 100644 --- a/plugins/xpay/xpay.c +++ b/plugins/xpay/xpay.c @@ -2510,13 +2510,15 @@ static struct payment *new_payment(const tal_t *ctx, return payment; } -bool attempt_ongoing(struct plugin *plugin, const struct sha256 *payment_hash) +bool attempt_ongoing(struct plugin *plugin, const struct sha256 *payment_hash, + u64 groupid) { struct xpay *xpay = xpay_of(plugin); const struct payment *payment; list_for_each(&xpay->payments, payment, list) { - if (sha256_eq(&payment->payment_hash, payment_hash)) + if (sha256_eq(&payment->payment_hash, payment_hash) && + payment->group_id == groupid) return true; } return false; diff --git a/plugins/xpay/xpay.h b/plugins/xpay/xpay.h index 886380d5c..44d4305ae 100644 --- a/plugins/xpay/xpay.h +++ b/plugins/xpay/xpay.h @@ -7,6 +7,7 @@ struct plugin; struct sha256; /* Are we still attempting this payment? If so, we won't list is as failed. */ -bool attempt_ongoing(struct plugin *plugin, const struct sha256 *payment_hash); +bool attempt_ongoing(struct plugin *plugin, const struct sha256 *payment_hash, + u64 groupid); #endif /* LIGHTNING_PLUGINS_XPAY_XPAY_H */