From c7bbdd76d32fe51590f0a87788010cfd958f3998 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 18 Feb 2020 10:26:58 +1030 Subject: [PATCH] lightningd: handle fail_htlc_in with no known outgoing channel. Turn it into temporary node failure: this only happens if we restart with a failed htlc in, but it's clearer and more robust to handle it generically. Signed-off-by: Rusty Russell --- lightningd/peer_htlcs.c | 13 +++++++++++-- wallet/wallet.c | 7 ------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 19c5890e0..f0c24bae4 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -109,8 +109,16 @@ static void fail_in_htlc(struct htlc_in *hin, hin->failonion = dup_onionreply(hin, failonion); /* We need this set, since we send it to channeld. */ - if (hin->failcode & UPDATE) - hin->failoutchannel = *out_channelid; + if (hin->failcode & UPDATE) { + /* We don't save the outgoing channel which failed; probably + * not worth it for this corner case. So we can't set + * hin->failoutchannel to tell channeld what update to send, + * thus we turn those into a WIRE_TEMPORARY_NODE_FAILURE. */ + if (!out_channelid) + hin->failcode = WIRE_TEMPORARY_NODE_FAILURE; + else + hin->failoutchannel = *out_channelid; + } /* We update state now to signal it's in progress, for persistence. */ htlc_in_update_state(hin->key.channel, hin, SENT_REMOVE_HTLC); @@ -2167,6 +2175,7 @@ static const struct json_command dev_ignore_htlcs = { "Set ignoring incoming HTLCs for peer {id} to {ignore}", false, "Set/unset ignoring of all incoming HTLCs. For testing only." }; + AUTODATA(json_command, &dev_ignore_htlcs); #endif /* DEVELOPER */ diff --git a/wallet/wallet.c b/wallet/wallet.c index 1e724821e..8a918ec61 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1904,13 +1904,6 @@ static bool wallet_stmt2htlc_out(struct wallet *wallet, static void fixup_hin(struct wallet *wallet, struct htlc_in *hin) { - /* We don't save the outgoing channel which failed; probably not worth - * it for this corner case. So we can't set hin->failoutchannel to - * tell channeld what update to send, thus we turn those into a - * WIRE_TEMPORARY_NODE_FAILURE. */ - if (hin->failcode & UPDATE) - hin->failcode = WIRE_TEMPORARY_NODE_FAILURE; - /* We didn't used to save failcore, failonion... */ #ifdef COMPAT_V061 /* We care about HTLCs being removed only, not those being added. */