From 9db145862c52e8b78ffc08cdd841fde3889eb4cc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 18 Sep 2024 17:00:27 +0930 Subject: [PATCH] lightningd: remove incorrect old-payment-htlc-delete logic. This was incorrect once we stopped removing old payments on failure, which was the reason we had to remove the HTLCs. It also removed by partid, which is wrong since it should have done old_payment->partid and old_payment->groupid! Signed-off-by: Rusty Russell --- lightningd/pay.c | 29 ++++++----------------------- wallet/wallet.c | 19 ------------------- wallet/wallet.h | 12 ------------ 3 files changed, 6 insertions(+), 54 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index 7c4659896c4e..37768853dab9 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -844,9 +844,7 @@ find_channel_for_htlc_add(struct lightningd *ld, return channel; } -/* Check if payment already in progress. Returns NULL if all good; - * sets old_payment to a previous attempt if there is one (otherwise - * NULL). */ +/* Check if payment already in progress. Returns NULL if all good */ static struct command_result *check_progress(struct lightningd *ld, struct command *cmd, const struct sha256 *rhash, @@ -854,14 +852,11 @@ static struct command_result *check_progress(struct lightningd *ld, struct amount_msat total_msat, u64 partid, u64 group, - const struct node_id *destination, - const struct wallet_payment **old_payment) + const struct node_id *destination) { bool have_complete = false; struct amount_msat msat_already_pending = AMOUNT_MSAT(0); - *old_payment = NULL; - /* Now, do we already have one or more payments? */ for (struct db_stmt *stmt = payments_by_hash(cmd->ld->wallet, rhash); stmt; @@ -974,8 +969,7 @@ static struct command_result *check_progress(struct lightningd *ld, break; case PAYMENT_FAILED: - if (payment->partid == partid) - *old_payment = payment; + break; } /* There is no way for us to add a payment with the * same (payment_hash, partid, groupid) tuple since @@ -1040,7 +1034,6 @@ send_payment_core(struct lightningd *ld, struct secret *path_secrets, const struct sha256 *local_invreq_id) { - const struct wallet_payment *old_payment; struct channel *channel; const u8 *failmsg; struct htlc_out *hout; @@ -1049,8 +1042,8 @@ send_payment_core(struct lightningd *ld, struct wallet_payment *payment; /* Reconcile this with previous attempts */ - ret = check_progress(ld, cmd, rhash, msat, total_msat, partid, group, destination, - &old_payment); + ret = check_progress(ld, cmd, rhash, msat, total_msat, partid, group, + destination); if (ret) return ret; @@ -1096,21 +1089,11 @@ send_payment_core(struct lightningd *ld, &channel->peer->id); return sendpay_fail( - cmd, old_payment, PAY_TRY_OTHER_ROUTE, NULL, fail, + cmd, NULL, PAY_TRY_OTHER_ROUTE, NULL, fail, sendpay_errmsg_fmt(tmpctx, PAY_TRY_OTHER_ROUTE, fail, "First peer not ready")); } - /* If we're retrying we delete outgoing HTLC otherwise it gets - * reported to onchaind as a possibility, and we end up in - * handle_missing_htlc_output -> onchain_failed_our_htlc -> - * payment_failed with no payment. - */ - if (old_payment) { - wallet_local_htlc_out_delete(ld->wallet, channel, rhash, - partid); - } - payment = wallet_add_payment(cmd, ld->wallet, time_now().ts.tv_sec, diff --git a/wallet/wallet.c b/wallet/wallet.c index 07048cc869ff..efc8316ad24b 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -3287,25 +3287,6 @@ struct htlc_stub *wallet_htlc_stubs(const tal_t *ctx, struct wallet *wallet, return stubs; } -void wallet_local_htlc_out_delete(struct wallet *wallet, - struct channel *chan, - const struct sha256 *payment_hash, - u64 partid) -{ - struct db_stmt *stmt; - - stmt = db_prepare_v2(wallet->db, SQL("DELETE FROM channel_htlcs" - " WHERE direction = ?" - " AND origin_htlc = ?" - " AND payment_hash = ?" - " AND partid = ?;")); - db_bind_int(stmt, DIRECTION_OUTGOING); - db_bind_int(stmt, 0); - db_bind_sha256(stmt, payment_hash); - db_bind_u64(stmt, partid); - db_exec_prepared_v2(take(stmt)); -} - /* FIXME: reorder! */ static struct wallet_payment *wallet_payment_new(const tal_t *ctx, diff --git a/wallet/wallet.h b/wallet/wallet.h index 2c1520c60e25..9329e5a37750 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -899,18 +899,6 @@ void wallet_payment_delete(struct wallet *wallet, const u64 *groupid, const u64 *partid, const enum payment_status *status); -/** - * wallet_local_htlc_out_delete - Remove a local outgoing failed HTLC - * - * This is not a generic HTLC cleanup! This is specifically for the - * narrow (and simple!) case of removing the HTLC associated with a - * local outgoing payment. - */ -void wallet_local_htlc_out_delete(struct wallet *wallet, - struct channel *chan, - const struct sha256 *payment_hash, - u64 partid); - /** * wallet_payment_by_hash - Retrieve a specific payment *