diff --git a/wallet/wallet.c b/wallet/wallet.c index ff9506299b67..f005e3470ef1 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -4325,22 +4325,26 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")); db_bind_u64(stmt, 0, in->dbid); - if (out) { - db_bind_u64(stmt, 1, out->dbid); - db_bind_u64(stmt, 3, out->key.channel->scid->u64); - db_bind_amount_msat(stmt, 5, &out->msat); - } else { - /* FORWARD_LOCAL_FAILED may occur before we get htlc_out */ + /* FORWARD_LOCAL_FAILED may occur before we get htlc_out */ + if (!out || !scid_out) { assert(failcode != 0); assert(state == FORWARD_LOCAL_FAILED); - db_bind_null(stmt, 1); - db_bind_null(stmt, 3); - db_bind_null(stmt, 5); } + if (out) + db_bind_u64(stmt, 1, out->dbid); + else + db_bind_null(stmt, 1); db_bind_u64(stmt, 2, in->key.channel->scid->u64); - + if (scid_out) + db_bind_u64(stmt, 3, scid_out->u64); + else + db_bind_null(stmt, 3); db_bind_amount_msat(stmt, 4, &in->msat); + if (out) + db_bind_amount_msat(stmt, 5, &out->msat); + else + db_bind_null(stmt, 5); db_bind_int(stmt, 6, wallet_forward_status_in_db(state)); db_bind_timeabs(stmt, 7, in->received_time);