MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_rebalance_tracking

Function test_rebalance_tracking

tests/test_bookkeeper.py:773–845  ·  view source on GitHub ↗

We identify rebalances (invoices paid and received by our node), this allows us to filter them out of "incomes" (self-transfers are not income/exp) and instead only display the cost incurred to move the payment (correctly marked as a rebalance) 1 -> 2 -> 3 -> 1

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

771
772
773def test_rebalance_tracking(node_factory, bitcoind):
774 """
775 We identify rebalances (invoices paid and received by our node),
776 this allows us to filter them out of "incomes" (self-transfers are not income/exp)
777 and instead only display the cost incurred to move the payment (correctly
778 marked as a rebalance)
779
780 1 -> 2 -> 3 -> 1
781 """
782
783 rebal_amt = 3210
784 l1, l2, l3 = node_factory.get_nodes(3)
785
786 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
787 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
788 l3.rpc.connect(l1.info['id'], 'localhost', l1.port)
789 c12, _ = l1.fundchannel(l2, 10**7, wait_for_active=True)
790 c23, _ = l2.fundchannel(l3, 10**7, wait_for_active=True)
791 c31, _ = l3.fundchannel(l1, 10**7, wait_for_active=True)
792
793 # Build a rebalance payment
794 invoice = l1.rpc.invoice(rebal_amt, 'to_self', 'to_self')
795 pay_hash = invoice['payment_hash']
796 pay_sec = invoice['payment_secret']
797
798 route = [{
799 'id': l2.info['id'],
800 'channel': c12,
801 'direction': int(not l1.info['id'] < l2.info['id']),
802 'amount_msat': rebal_amt + 1001,
803 'style': 'tlv',
804 'delay': 24,
805 }, {
806 'id': l3.info['id'],
807 'channel': c23,
808 'direction': int(not l2.info['id'] < l3.info['id']),
809 'amount_msat': rebal_amt + 500,
810 'style': 'tlv',
811 'delay': 16,
812 }, {
813 'id': l1.info['id'],
814 'channel': c31,
815 'direction': int(not l3.info['id'] < l1.info['id']),
816 'amount_msat': rebal_amt,
817 'style': 'tlv',
818 'delay': 8,
819 }]
820
821 l1.rpc.sendpay(route, pay_hash, payment_secret=pay_sec)
822 result = l1.rpc.waitsendpay(pay_hash, TIMEOUT)
823 assert result['status'] == 'complete'
824
825 wait_for(lambda: 'invoice' not in [ev['tag'] for ev in l1.rpc.bkpr_listincome()['income_events']])
826 inc_evs = l1.rpc.bkpr_listincome()['income_events']
827 outbound_chan_id = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['channel_id']
828
829 outbound_ev = only_one([ev for ev in inc_evs if ev['tag'] == 'rebalance_fee'])
830 assert outbound_ev['account'] == outbound_chan_id

Callers

nothing calls this directly

Calls 11

wait_forFunction · 0.90
only_oneFunction · 0.90
MillisatoshiClass · 0.90
get_nodesMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
listpeerchannelsMethod · 0.80
restartMethod · 0.80
connectMethod · 0.45
fundchannelMethod · 0.45
invoiceMethod · 0.45

Tested by

no test coverage detected