From b81129f87e127b63ac74ae07faf0789664aa00ce Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 18 Jan 2018 06:59:50 +1030 Subject: [PATCH] wallet: fix case of failed payment not yet in db. From test_reconnect_sender_add1: lightningd(13643):BROKEN: backtrace: wallet/wallet.c:1537 (wallet_payment_set_status) 0x561c91b03080 lightningd(13643):BROKEN: backtrace: lightningd/pay.c:67 (payment_failed) 0x561c91ac4f99 lightningd(13643):BROKEN: backtrace: lightningd/peer_htlcs.c:132 (fail_out_htlc) 0x561c91acf627 lightningd(13643):BROKEN: backtrace: lightningd/peer_htlcs.c:321 (hout_subd_died) 0x561c91acfb62 When payment fails, we call wallet_payment_set_status; this is perfectly possible before it's been committed. Signed-off-by: Rusty Russell --- wallet/wallet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wallet/wallet.c b/wallet/wallet.c index 056001514..4e436b1be 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1397,9 +1397,15 @@ void wallet_payment_set_status(struct wallet *wallet, const struct preimage *preimage) { sqlite3_stmt *stmt; + struct wallet_payment *payment; - /* We should never try this on an unstored payment! */ - assert(!find_unstored_payment(wallet, payment_hash)); + /* We can only fail an unstored payment! */ + payment = find_unstored_payment(wallet, payment_hash); + if (payment) { + assert(newstatus == PAYMENT_FAILED); + tal_free(payment); + return; + } stmt = db_prepare(wallet->db, "UPDATE payments SET status=? "