From 9feb97f2eea9f4524ac88053d285aa10ba423b55 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 1 Aug 2018 18:22:23 +0200 Subject: [PATCH] lnrouter: use 'disable' flags from channel updates in path finding --- electrum/lnrouter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/electrum/lnrouter.py b/electrum/lnrouter.py index 987282b0a..84d3275a5 100644 --- a/electrum/lnrouter.py +++ b/electrum/lnrouter.py @@ -107,7 +107,7 @@ class ChannelInfo(PrintError): def on_channel_update(self, msg_payload, trusted=False): assert self.channel_id == msg_payload['short_channel_id'] flags = int.from_bytes(msg_payload['flags'], 'big') - direction = flags & 1 + direction = flags & ChannelInfoDirectedPolicy.FLAG_DIRECTION new_policy = ChannelInfoDirectedPolicy(msg_payload) if direction == 0: old_policy = self.policy_node1 @@ -136,6 +136,9 @@ class ChannelInfo(PrintError): class ChannelInfoDirectedPolicy: + FLAG_DIRECTION = 1 << 0 + FLAG_DISABLE = 1 << 1 + def __init__(self, channel_update_payload): cltv_expiry_delta = channel_update_payload['cltv_expiry_delta'] htlc_minimum_msat = channel_update_payload['htlc_minimum_msat'] @@ -151,6 +154,8 @@ class ChannelInfoDirectedPolicy: self.flags = int.from_bytes(flags, "big") self.timestamp = int.from_bytes(timestamp, "big") + self.disabled = self.flags & self.FLAG_DISABLE + def to_json(self) -> dict: d = {} d['cltv_expiry_delta'] = self.cltv_expiry_delta @@ -495,6 +500,7 @@ class LNPathFinder(PrintError): channel_policy = channel_info.get_policy_for_node(start_node) if channel_policy is None: return float('inf') + if channel_policy.disabled: return float('inf') cltv_expiry_delta = channel_policy.cltv_expiry_delta htlc_minimum_msat = channel_policy.htlc_minimum_msat fee_base_msat = channel_policy.fee_base_msat