Skip to content

Commit 50d7b7e

Browse files
committed
bkpr: fixup htlc penalty test with anchors
Test flake where the balance for lightning-2 went negative ``` > assert account_balance(l2, channel_id) == 0 tests/test_closing.py:1314: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ tests/utils.py:183: in account_balance m_sum -= Millisatoshi(m['debit_msat']) contrib/pyln-client/pyln/client/lightning.py:193: in __sub__ return Millisatoshi(int(self) - int(other)) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = -10000msat, v = -10000 ``` Led me to look into this test. lightning-2 should go negative since we roll back the amounts it's received by going to a prior database state. Rather than trying to do the right thing with obviously broken node records, instead we just stop trying to account for them correctly (impossible). I also noticed that the anchor tests were failing the utxo output matchup, which we should be asserting on it. The HTLC RBF that our anchor code creates was causing an issue by creating another wallet deposit utxo under the HTLC output. We now optionally add this utxo in the case that anchors are turned on. Changelog-None: Fix test flake
1 parent 5c9eed1 commit 50d7b7e

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

tests/test_closing.py

+6-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
account_balance, first_channel_id, closing_fee, TEST_NETWORK,
88
scriptpubkey_addr, calc_lease_fee,
99
check_utxos_channel, check_coin_moves,
10-
check_balance_snaps, mine_funding_to_announce, check_inspect_channel,
10+
mine_funding_to_announce, check_inspect_channel,
1111
first_scid
1212
)
1313

@@ -1311,7 +1311,7 @@ def test_penalty_htlc_tx_fulfill(node_factory, bitcoind, chainparams, anchors):
13111311
l2.daemon.wait_for_log('{}.*: onchaind complete, forgetting peer'.format(l3.info['id']))
13121312

13131313
assert account_balance(l3, channel_id) == 0
1314-
assert account_balance(l2, channel_id) == 0
1314+
# we can't check the account balance on l2 because it goes negative
13151315

13161316
expected_2 = {
13171317
'A': [('cid1', ['channel_open', 'opener'], ['channel_close'], 'B')],
@@ -1332,25 +1332,11 @@ def test_penalty_htlc_tx_fulfill(node_factory, bitcoind, chainparams, anchors):
13321332
expected_3['B'].append(('external', ['anchor'], None, None))
13331333
expected_2['B'].append(('wallet', ['anchor', 'ignored'], None, None))
13341334
expected_3['B'].append(('wallet', ['anchor', 'ignored'], None, None))
1335+
# We RBF spend the HTLC tx, which creates a new deposit
1336+
expected_2['C'].append(('wallet', ['deposit'], None, None))
13351337

1336-
# FIXME: Why does this fail?
1337-
if not anchors:
1338-
tags = check_utxos_channel(l2, [channel_id], expected_2, filter_channel=channel_id)
1339-
check_utxos_channel(l3, [channel_id], expected_3, tags, filter_channel=channel_id)
1340-
1341-
if not chainparams['elements']:
1342-
# Also check snapshots
1343-
expected_bals_2 = [
1344-
{'blockheight': 101, 'accounts': [
1345-
{'balance_msat': '0msat', 'account_id': 'wallet'}
1346-
]}
1347-
] + [
1348-
{'blockheight': 108, 'accounts': [
1349-
{'balance_msat': '995073000msat', 'account_id': 'wallet'},
1350-
{'balance_msat': '500000000msat', 'account_id': first_channel_id(l1, l2)},
1351-
{'balance_msat': '499994999msat', 'account_id': channel_id}]}
1352-
] * 2 # duplicated; we stop and restart l2 twice (both at block 108)
1353-
check_balance_snaps(l2, expected_bals_2)
1338+
tags = check_utxos_channel(l2, [channel_id], expected_2, filter_channel=channel_id)
1339+
check_utxos_channel(l3, [channel_id], expected_3, tags, filter_channel=channel_id)
13541340

13551341

13561342
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Makes use of the sqlite3 db")

0 commit comments

Comments
 (0)