From e2c5104aab9987fc171755972a89b361c0d1b685 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 26 Jun 2017 10:52:56 +0930 Subject: [PATCH] lightningd: immediately fail HTLCs coming in from shutting down channels. This can happen even without a protocol violation, if the incoming update_add_htlc crosses over our outgoing shutdown. Signed-off-by: Rusty Russell --- lightningd/peer_htlcs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index d34619b03..22bd7aefe 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -600,6 +600,15 @@ static bool peer_accepted_htlc(struct peer *peer, if (!htlc_in_update_state(peer, hin, RCVD_ADD_ACK_REVOCATION)) return false; + /* BOLT #2: + * + * A sending node SHOULD fail to route any HTLC added after it + * sent `shutdown`. */ + if (peer->state == CHANNELD_SHUTTING_DOWN) { + *failcode = WIRE_PERMANENT_CHANNEL_FAILURE; + goto out; + } + /* channeld tests this, so it should have set ss to zeroes. */ op = parse_onionpacket(tmpctx, hin->onion_routing_packet, sizeof(hin->onion_routing_packet));