electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 21e907a4e3b7540b9f410ec5d28314432b25c5c2
parent 135951a13f515e6e5567aa6cd2ca41dbf36ef07b
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue, 17 Jul 2018 13:41:34 +0200

ChannelDB: print_graph

Diffstat:
Melectrum/lnbase.py | 3++-
Melectrum/lnrouter.py | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/electrum/lnbase.py b/electrum/lnbase.py @@ -825,8 +825,9 @@ class Peer(PrintError): short_chan_id = route[sender_idx + 1].short_channel_id except IndexError: print("payment destination reported error") + else: + self.network.path_finder.blacklist.add(short_chan_id) - self.network.path_finder.blacklist.add(short_chan_id) self.update_fail_htlc[payload["channel_id"]].put_nowait("HTLC failure with code {} (categories {})".format(code, codes)) @aiosafe diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py @@ -140,6 +140,44 @@ class ChannelDB(PrintError): except KeyError: pass + def print_graph(self, full_ids=False): + # used for debugging. + # FIXME there is a race here - iterables could change size from another thread + def other_node_id(node_id, channel_id): + channel_info = self._id_to_channel_info[channel_id] + if node_id == channel_info.node_id_1: + other = channel_info.node_id_2 + else: + other = channel_info.node_id_1 + return other if full_ids else other[-4:] + + self.print_msg('node: {(channel, other_node), ...}') + for node_id, short_channel_ids in list(self._channels_for_node.items()): + short_channel_ids = {(bh2u(cid), bh2u(other_node_id(node_id, cid))) + for cid in short_channel_ids} + node_id = bh2u(node_id) if full_ids else bh2u(node_id[-4:]) + self.print_msg('{}: {}'.format(node_id, short_channel_ids)) + + self.print_msg('channel: node1, node2, direction') + for short_channel_id, channel_info in list(self._id_to_channel_info.items()): + node1 = channel_info.node_id_1 + node2 = channel_info.node_id_2 + direction1 = channel_info.get_policy_for_node(node1) is not None + direction2 = channel_info.get_policy_for_node(node2) is not None + if direction1 and direction2: + direction = 'both' + elif direction1: + direction = 'forward' + elif direction2: + direction = 'backward' + else: + direction = 'none' + self.print_msg('{}: {}, {}, {}' + .format(bh2u(short_channel_id), + bh2u(node1) if full_ids else bh2u(node1[-4:]), + bh2u(node2) if full_ids else bh2u(node2[-4:]), + direction)) + class RouteEdge: