From be112f7b395754d5a6981d413df8df43cafbe56c Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Wed, 28 Dec 2022 18:25:12 +0100 Subject: [PATCH] jitrebalance: fix upstream changes --- jitrebalance/jitrebalance.py | 13 +++++++------ jitrebalance/test_jitrebalance.py | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/jitrebalance/jitrebalance.py b/jitrebalance/jitrebalance.py index 897e1b0..ddc57d4 100755 --- a/jitrebalance/jitrebalance.py +++ b/jitrebalance/jitrebalance.py @@ -38,7 +38,7 @@ def get_circular_route(scid, chan, amt, peer, exclusions, request): try: route = plugin.rpc.getroute( node_id=peer['id'], - msatoshi=last_amt, + amount_msat=last_amt, riskfactor=1, exclude=exclusions, cltv=last_cltv, @@ -49,7 +49,6 @@ def get_circular_route(scid, chan, amt, peer, exclusions, request): 'id': plugin.node_id, 'channel': scid, 'direction': chan['direction'], - 'msatoshi': amt, 'amount_msat': '{}msat'.format(amt), 'delay': 9 }] @@ -106,14 +105,16 @@ def try_rebalance(scid, chan, amt, peer, request): "payment_hash={}".format(scid, payment_hash)) return except RpcError as e: - error = e.error['data'] + if not "data" in e.error: + raise e + data = e.error['data'] # The erring_channel field can not be present (shouldn't happen) or # can be "0x0x0" - erring_channel = error.get('erring_channel', '0x0x0') + erring_channel = data.get('erring_channel', '0x0x0') if erring_channel != '0x0x0': if erring_channel == scid: break - erring_direction = error['erring_direction'] + erring_direction = data['erring_direction'] exclusions.append("{}/{}".format(erring_channel, erring_direction)) plugin.log("Excluding {} due to a failed attempt" @@ -182,7 +183,7 @@ def on_htlc_accepted(htlc, onion, plugin, request, **kwargs): # TODO If we are the funder we need to take the cost of an HTLC into # account as well. # funder = chan['msatoshi_to_us_max'] == chan['msatoshi_total'] - forward_amt = Millisatoshi(onion['forward_amount']) + forward_amt = Millisatoshi(onion['forward_msat']) # If we have enough capacity just let it through now. Otherwise the # Millisatoshi raises an error for negative amounts in the calculation diff --git a/jitrebalance/test_jitrebalance.py b/jitrebalance/test_jitrebalance.py index b92199d..d89c372 100644 --- a/jitrebalance/test_jitrebalance.py +++ b/jitrebalance/test_jitrebalance.py @@ -46,7 +46,7 @@ def test_simple_rebalance(node_factory): # Send 9 million millisatoshis + reserve + a tiny fee allowance from l3 to # l2 for the actual payment inv = l2.rpc.invoice( - chan['our_channel_reserve_satoshis'] * 1000 + 9000000 + 100, + chan['our_reserve_msat'] + 9000000 + 100, "imbalance", "imbalance" ) time.sleep(1) @@ -59,7 +59,7 @@ def test_simple_rebalance(node_factory): wait_for(no_pending_htlcs) chan = l2.rpc.listpeers(l3.info['id'])['peers'][0]['channels'][0] - assert(chan['spendable_msatoshi'] < amt) + assert(int(chan['spendable_msat']) < amt) # Get (l2, l5) so we can exclude it when routing from l1 to l4 peer = l2.rpc.listpeers(l5.info['id'])['peers'][0] @@ -113,7 +113,7 @@ def test_rebalance_failure(node_factory): # Send 9 million millisatoshis + reserve + a tiny fee allowance from l3 to # l2 for the actual payment inv = l2.rpc.invoice( - chan['our_channel_reserve_satoshis'] * 1000 + 9000000 + 100, + chan['our_reserve_msat'] + 9000000 + 100, "imbalance", "imbalance" ) time.sleep(1) @@ -126,7 +126,7 @@ def test_rebalance_failure(node_factory): wait_for(no_pending_htlcs) chan = l2.rpc.listpeers(l3.info['id'])['peers'][0]['channels'][0] - assert(chan['spendable_msatoshi'] < amt) + assert(int(chan['spendable_msat']) < amt) # Get (l2, l5) so we can exclude it when routing from l1 to l4 peer = l2.rpc.listpeers(l5.info['id'])['peers'][0]