rebalance: channel wo scid

A channel can exist without a short_channel_id, in the CHANNELD_AWAITING_LOCKIN state, while the funding transaction is sent but not yet included in a block.

Running `rebalanceall` while opening a channel could throw an exception:
```
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py: Exception in thread Thread-5:
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py: Traceback (most recent call last):
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/usr/lib/python3.6/threading.py\", line 916, in _bootstrap_inner
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     self.run()
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/usr/lib/python3.6/threading.py\", line 864, in run
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     self._target(*self._args, **self._kwargs)
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/home/user/plugins/rebalance/rebalance.py\", line 475, in rebalanceall_thread
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     result = maybe_rebalance_once(plugin, failed_pairs)
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/home/user/plugins/rebalance/rebalance.py\", line 443, in maybe_rebalance_once
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     result = maybe_rebalance_pairs(plugin, ch1, ch2, failed_pairs)
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/home/user/plugins/rebalance/rebalance.py\", line 425, in maybe_rebalance_pairs
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     wait_for_htlcs(plugin, [scid1, scid2])
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:   File \"/home/user/plugins/rebalance/rebalance.py\", line 384, in wait_for_htlcs
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py:     if scids is not None and channel['short_channel_id'] not in scids:
2021-02-14T09:31:39 UNUSUAL plugin-rebalance.py: KeyError: 'short_channel_id'
```
This commit is contained in:
Gálli Zoltán
2021-02-14 11:32:05 +01:00
committed by Michael Schmoock
parent 04eed3f595
commit 38b03cdddc

View File

@@ -26,7 +26,7 @@ def setup_routing_fees(plugin, route, msatoshi):
def get_channel(plugin, payload, peer_id, scid, check_state: bool = False):
peer = plugin.rpc.listpeers(peer_id).get('peers')[0]
channel = next(c for c in peer['channels'] if 'short_channel_id' in c and c['short_channel_id'] == scid)
channel = next(c for c in peer['channels'] if c.get('short_channel_id') == scid)
if check_state:
if channel['state'] != "CHANNELD_NORMAL":
raise RpcError('rebalance', payload, {'message': 'Channel %s not in state CHANNELD_NORMAL, but: %s' % (scid, channel['state'])})
@@ -37,7 +37,7 @@ def get_channel(plugin, payload, peer_id, scid, check_state: bool = False):
def amounts_from_scid(plugin, scid):
channels = plugin.rpc.listfunds().get('channels')
channel = next(c for c in channels if 'short_channel_id' in c and c['short_channel_id'] == scid)
channel = next(c for c in channels if c.get('short_channel_id') == scid)
our_msat = Millisatoshi(channel['our_amount_msat'])
total_msat = Millisatoshi(channel['amount_msat'])
return our_msat, total_msat
@@ -340,9 +340,7 @@ def get_chan(plugin: Plugin, scid: str):
# We might have multiple channel entries ! Eg if one was just closed
# and reopened.
for chan in peer["channels"]:
if "short_channel_id" not in chan:
continue
if chan["short_channel_id"] == scid:
if chan.get("short_channel_id") == scid:
return chan
@@ -381,7 +379,7 @@ def wait_for_htlcs(plugin, scids: list = None):
for p, peer in enumerate(peers):
if 'channels' in peer:
for c, channel in enumerate(peer['channels']):
if scids is not None and channel['short_channel_id'] not in scids:
if scids is not None and channel.get('short_channel_id') not in scids:
continue
if 'htlcs' in channel:
wait_for(lambda: len(plugin.rpc.listpeers()['peers'][p]['channels'][c]['htlcs']) == 0)