mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
wallet: Make wallet_payment_store idempotent.
This commit is contained in:
parent
8fd71ad654
commit
60f5abdc9b
@ -1516,7 +1516,23 @@ void wallet_payment_store(struct wallet *wallet,
|
||||
struct wallet_payment *payment;
|
||||
|
||||
payment = find_unstored_payment(wallet, payment_hash);
|
||||
assert(payment);
|
||||
if (!payment) {
|
||||
/* Already stored on-disk */
|
||||
#if DEVELOPER
|
||||
/* Double-check that it is indeed stored to disk
|
||||
* (catch bug, where we call this on a payment_hash
|
||||
* we never paid to) */
|
||||
int res;
|
||||
stmt = db_prepare(wallet->db,
|
||||
"SELECT status FROM payments"
|
||||
" WHERE payment_hash=?;");
|
||||
sqlite3_bind_sha256(stmt, 1, payment_hash);
|
||||
res = sqlite3_step(stmt);
|
||||
assert(res == SQLITE_ROW);
|
||||
sqlite3_finalize(stmt);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't attempt to add the same payment twice */
|
||||
assert(!payment->id);
|
||||
|
Loading…
Reference in New Issue
Block a user