wallet: store payment failure details per groupid
What changed, and why it matters
This commit fixes a database bug in Core Lightning where failure details for a payment attempt were being overwritten by later retry attempts that shared the same payment identifier fragment. The fix makes the failure record match on an additional 'groupid' field, so each retry group's error is stored separately. It is a correctness bug, not a security vulnerability: no funds are at risk and no attacker can exploit it.
No security action required. Treat as a normal bug-fix release. Operators may update to obtain correct waitsendpay/listsendpays error reporting for retried payments.
Security signals we found
Data integrity bug causing incorrect error reporting across payment retry groups
No memory safety, authentication, authorization, or cryptographic issues present
No external input is trusted or validated differently
Fix is localized to SQL UPDATE key matching
Evidence from the diff
wallet_payment_set_failinfo() previously updated the payments table using only payment_hash and partid as the key. Because groupid is now part of the payments primary key, any failed retry in a new groupid with the same partid overwrote the failonion, failcode, faildetail, etc. of earlier groups. The patch adds groupid to the WHERE clause and function signature, aligning it with wallet_payment_set_status() and wallet_payment_get_failinfo(). A test that was marked xfail is now enabled.
Changed components
wallet/wallet.cwallet/wallet.hlightningd/pay.ctests/test_pay.pyInspect captured patch +6 / −3
### lightningd/pay.c
@@ -643,6 +643,7 @@ void payment_failed(struct lightningd *ld,
wallet_payment_set_failinfo(ld->wallet,
payment_hash,
partid,
+ groupid,
/* We only save failonion if it's unparseable */
fail ? NULL : failonion,
pay_errcode == PAY_DESTINATION_PERM_FAIL,
@@ -1548,7 +1549,7 @@ static struct command_result *self_payment(struct lightningd *ld,
/* Only some of these fields make sense for self payments */
wallet_payment_set_failinfo(ld->wallet,
rhash,
- partid, NULL,
+ partid, groupid, NULL,
true,
0,
fail->failcode, fail->erring_node,
### tests/test_pay.py
@@ -6056,7 +6056,6 @@ def test_self_sendpay(node_factory):
assert [p['status'] for p in l1.rpc.listsendpays()['payments'] if p['status'] != 'failed'] == ['complete']
-@pytest.mark.xfail(strict=True)
def test_failinfo_per_groupid(node_factory):
"""A failed retry in a new group must not overwrite the failure details
of an earlier group with the same payment_hash and partid."""
### wallet/wallet.c
@@ -4429,6 +4429,7 @@ void wallet_payment_get_failinfo(const tal_t *ctx,
void wallet_payment_set_failinfo(struct wallet *wallet,
const struct sha256 *payment_hash,
u64 partid,
+ u64 groupid,
const struct onionreply *failonionreply,
bool faildestperm,
int failindex,
@@ -4454,7 +4455,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
" , faildetail=?"
" , failmsg=?"
" WHERE payment_hash=?"
- " AND partid=?;"));
+ " AND partid=? AND groupid=?;"));
if (failonionreply)
db_bind_talarr(stmt, failonionreply->contents);
else
@@ -4487,6 +4488,7 @@ void wallet_payment_set_failinfo(struct wallet *wallet,
db_bind_sha256(stmt, payment_hash);
db_bind_u64(stmt, partid);
+ db_bind_u64(stmt, groupid);
db_exec_prepared_v2(take(stmt));
}
### wallet/wallet.h
@@ -1088,6 +1088,7 @@ void wallet_payment_get_failinfo(const tal_t *ctx,
void wallet_payment_set_failinfo(struct wallet *wallet,
const struct sha256 *payment_hash,
u64 partid,
+ u64 groupid,
const struct onionreply *failonionreply,
bool faildestperm,
int failindex,Why this scored 30/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.