Skip to content

Commit b2708cf

Browse files
committed
bkpr: failing test for bookkeeper crash
Reproduce crash for #5557! If we record the channel open because bookkeeper was added after the channel open request started but the channel confirms later, we end up with re-recording any associated push or leased fees (paid or rcvd). In the case where you've paid for these fees, your channel balance goes negative and the node crashes the next time you call `listbalances`. Reported-by: @chrisguida
1 parent 7cb754c commit b2708cf

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/test_opening.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,61 @@ def test_buy_liquidity_ad_no_v2(node_factory, bitcoind):
15131513
compact_lease='029a002d000000004b2003e8')
15141514

15151515

1516+
@pytest.mark.xfail
1517+
@pytest.mark.openchannel('v2')
1518+
def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind):
1519+
""" Test that your bookkeeping for a liquidity ad is good."""
1520+
1521+
opts = [{'funder-policy': 'match', 'funder-policy-mod': 100,
1522+
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1523+
'rescan': 10, 'disable-plugin': 'bookkeeper',
1524+
'funding-confirms': 6, 'may_reconnect': True},
1525+
{'funder-policy': 'match', 'funder-policy-mod': 100,
1526+
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100}]
1527+
l1, l2, = node_factory.get_nodes(2, opts=opts)
1528+
amount = 500000
1529+
feerate = 2000
1530+
1531+
l1.fundwallet(amount * 100)
1532+
l2.fundwallet(amount * 100)
1533+
1534+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1535+
rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
1536+
wait_for(lambda: len(l1.rpc.listpeers(l2.info['id'])['peers']) == 0)
1537+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1538+
1539+
# l1 leases a channel from l2
1540+
l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
1541+
feerate='{}perkw'.format(feerate),
1542+
compact_lease=rates['compact_lease'])
1543+
1544+
# add the funding transaction
1545+
bitcoind.generate_block(4, wait_for_mempool=1)
1546+
1547+
l1.stop()
1548+
del l1.daemon.opts['disable-plugin']
1549+
l1.start()
1550+
1551+
chan_id = first_channel_id(l1, l2)
1552+
ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
1553+
assert 'lease_fee' in ev_tags
1554+
1555+
bitcoind.generate_block(2)
1556+
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
1557+
1558+
# This should work ok
1559+
l1.rpc.bkpr_listbalances()
1560+
1561+
l1.rpc.close(l2.info['id'], 1)
1562+
bitcoind.generate_block(6, wait_for_mempool=1)
1563+
1564+
l1.daemon.wait_for_log(' to ONCHAIN')
1565+
l2.daemon.wait_for_log(' to ONCHAIN')
1566+
1567+
# This should crash
1568+
l1.rpc.bkpr_listbalances()
1569+
1570+
15161571
def test_scid_alias_private(node_factory, bitcoind):
15171572
"""Test that we don't allow use of real scid for scid_alias-type channels"""
15181573
l1, l2, l3 = node_factory.line_graph(3, fundchannel=False, opts=[{}, {},

0 commit comments

Comments
 (0)