lightningd: clean up weird call to send_htlc_out.

1. forward_htlc sets hout to NULL.
2. forward_htlc passes &hout to send_htlc_out.
3. forward_htlc checks the failcode and frees(NULL) and sets hout to NULL
   (again).  This in fact covers every failcode which send_htlc_out returns.

We should ensure send_htlc_out sets *houtp to NULL on failure; in fact,
both callers pass houtp, so we can make it unconditional.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-02-18 10:24:58 +10:30
parent b84b4b4695
commit ad3c7f3a1f

View File

@ -455,9 +455,10 @@ enum onion_type send_htlc_out(struct channel *out,
struct htlc_in *in,
struct htlc_out **houtp)
{
struct htlc_out *hout;
u8 *msg;
*houtp = NULL;
if (!channel_can_add_htlc(out)) {
log_info(out->log, "Attempt to send HTLC but not ready (%s)",
channel_state_name(out));
@ -477,10 +478,10 @@ enum onion_type send_htlc_out(struct channel *out,
}
/* Make peer's daemon own it, catch if it dies. */
hout = new_htlc_out(out->owner, out, amount, cltv,
payment_hash, onion_routing_packet, in == NULL,
partid, in);
tal_add_destructor(hout, destroy_hout_subd_died);
*houtp = new_htlc_out(out->owner, out, amount, cltv,
payment_hash, onion_routing_packet, in == NULL,
partid, in);
tal_add_destructor(*houtp, destroy_hout_subd_died);
/* Give channel 30 seconds to commit (first) htlc. */
if (!out->htlc_timeout && !IFDEV(out->peer->ld->dev_no_htlc_timeout, 0))
@ -490,10 +491,9 @@ enum onion_type send_htlc_out(struct channel *out,
out);
msg = towire_channel_offer_htlc(out, amount, cltv, payment_hash,
onion_routing_packet);
subd_req(out->peer->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply, hout);
subd_req(out->peer->ld, out->owner, take(msg), -1, 0, rcvd_htlc_reply,
*houtp);
if (houtp)
*houtp = hout;
return 0;
}
@ -593,13 +593,6 @@ static void forward_htlc(struct htlc_in *hin,
if (!failcode)
return;
/* In fact, we didn't get the new htlc_out in these 2 cases */
if (failcode == WIRE_UNKNOWN_NEXT_PEER ||
failcode == WIRE_TEMPORARY_CHANNEL_FAILURE) {
tal_free(hout);
hout = NULL;
}
fail:
local_fail_htlc(hin, failcode, next->scid);
wallet_forwarded_payment_add(ld->wallet,