diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 22ef19d94..9d6e48f16 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1978,6 +1978,7 @@ void htlcs_reconnect(struct lightningd *ld, struct htlc_in *hin; struct htlc_out *hout; struct htlc_in_map unprocessed; + enum onion_type failcode; /* Any HTLCs which happened to be incoming and weren't forwarded before * we shutdown/crashed: fail them now. @@ -2037,9 +2038,17 @@ void htlcs_reconnect(struct lightningd *ld, for (hin = htlc_in_map_first(&unprocessed, &ini); hin; hin = htlc_in_map_next(&unprocessed, &ini)) { log_unusual(hin->key.channel->log, - "Failing old unprocessed HTLC #%"PRIu64, + "Replaying old unprocessed HTLC #%"PRIu64, hin->key.id); - fail_in_htlc(hin, WIRE_TEMPORARY_NODE_FAILURE, NULL, NULL); + if (!peer_accepted_htlc(hin->key.channel, hin->key.id, &failcode)) { + fail_in_htlc(hin, + failcode != 0 + ? failcode + : WIRE_TEMPORARY_NODE_FAILURE, + NULL, NULL); + } else if (failcode) { + fail_in_htlc(hin, failcode, NULL, NULL); + } } /* Don't leak memory! */ diff --git a/tests/test_closing.py b/tests/test_closing.py index 3ca6c4908..e46b8c4dc 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -1125,6 +1125,10 @@ def test_onchain_multihtlc_our_unilateral(node_factory, bitcoind): # Now, restart and manually reconnect end nodes (so they don't ignore HTLCs) # In fact, they'll fail them with WIRE_TEMPORARY_NODE_FAILURE. + # TODO Remove our reliance on HTLCs failing on startup and the need for + # this plugin + nodes[0].daemon.opts['plugin'] = 'tests/plugins/fail_htlcs.py' + nodes[-1].daemon.opts['plugin'] = 'tests/plugins/fail_htlcs.py' nodes[0].restart() nodes[-1].restart() @@ -1213,6 +1217,10 @@ def test_onchain_multihtlc_their_unilateral(node_factory, bitcoind): # Now, restart and manually reconnect end nodes (so they don't ignore HTLCs) # In fact, they'll fail them with WIRE_TEMPORARY_NODE_FAILURE. + # TODO Remove our reliance on HTLCs failing on startup and the need for + # this plugin + nodes[0].daemon.opts['plugin'] = 'tests/plugins/fail_htlcs.py' + nodes[-1].daemon.opts['plugin'] = 'tests/plugins/fail_htlcs.py' nodes[0].restart() nodes[-1].restart()