Skip to content

Commit

Permalink
lightningd: remove incorrect old-payment-htlc-delete logic.
Browse files Browse the repository at this point in the history
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 <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and ShahanaFarooqui committed Sep 23, 2024
1 parent 81fac32 commit c0d7b87
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 54 deletions.
29 changes: 6 additions & 23 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,24 +844,19 @@ 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,
struct amount_msat msat,
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 0 additions & 19 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3283,25 +3283,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,
Expand Down
12 changes: 0 additions & 12 deletions wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit c0d7b87

Please sign in to comment.