From 60f5abdc9b3ea3c850ae9f2c8a9aa4f9df6ecd5d Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Fri, 9 Mar 2018 02:17:51 +0000 Subject: [PATCH] wallet: Make wallet_payment_store idempotent. --- wallet/wallet.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index a2fa99e7f..ccd2ca763 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -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);