thandle failing htlc after restart - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 864efa029bb695f98beeeaa46f1b22c98241eee2 DIR parent eced61123dc49db80366d4988c8594683e100be8 HTML Author: SomberNight <somber.night@protonmail.com> Date: Tue, 9 Oct 2018 20:37:09 +0200 handle failing htlc after restart Diffstat: M electrum/lnbase.py | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) --- DIR diff --git a/electrum/lnbase.py b/electrum/lnbase.py t@@ -1014,22 +1014,28 @@ class Peer(PrintError): chan = self.channels[channel_id] htlc_id = int.from_bytes(payload["id"], "big") key = (channel_id, htlc_id) - route = self.attempted_route[key] - failure_msg, sender_idx = decode_onion_error(payload["reason"], [x.node_id for x in route], chan.onion_keys[htlc_id]) - code = failure_msg.code - code_name = ONION_FAILURE_CODE_MAP.get(code, 'unknown_error!!') - data = failure_msg.data - self.print_error("UPDATE_FAIL_HTLC", code_name, code, data) try: - short_chan_id = route[sender_idx + 1].short_channel_id - except IndexError: - self.print_error("payment destination reported error") + route = self.attempted_route[key] + except KeyError: + # the remote might try to fail an htlc after we restarted... + # attempted_route is not persisted, so we will get here then + self.print_error("UPDATE_FAIL_HTLC. cannot decode! attempted route is MISSING. {}".format(key)) else: - # TODO this should depend on the error - # also, we need finer blacklisting (directed edges; nodes) - self.network.path_finder.blacklist.add(short_chan_id) - - self.print_error("HTLC failure with code {} ({})".format(code, code_name)) + failure_msg, sender_idx = decode_onion_error(payload["reason"], [x.node_id for x in route], chan.onion_keys[htlc_id]) + code = failure_msg.code + code_name = ONION_FAILURE_CODE_MAP.get(code, 'unknown_error??') + data = failure_msg.data + self.print_error("UPDATE_FAIL_HTLC", code_name, code, data) + try: + short_chan_id = route[sender_idx + 1].short_channel_id + except IndexError: + self.print_error("payment destination reported error") + else: + # TODO this should depend on the error + # also, we need finer blacklisting (directed edges; nodes) + self.network.path_finder.blacklist.add(short_chan_id) + self.print_error("HTLC failure with code {} ({})".format(code, code_name)) + # process update_fail_htlc on channel chan = self.channels[channel_id] chan.receive_fail_htlc(htlc_id) await self.receive_commitment(chan)