bkpr: check for channel resolution for any "originated" event

We were failing to mark channels as resolved b/c we weren't using later
events to external (but originated from this account) events as signals
to run the channel resolution check.

This fixes that, and adds a test.
This commit is contained in:
niftynei 2022-07-19 17:04:39 +09:30 committed by Rusty Russell
parent cf8b30d2e8
commit d72033882f
3 changed files with 85 additions and 2 deletions

View File

@ -862,7 +862,9 @@ static char *do_account_close_checks(const tal_t *ctx,
db_begin_transaction(db);
/* If is an external acct event, might be close channel related */
if (!is_channel_account(acct) && !e->spending_txid)
if (!is_channel_account(acct) && e->origin_acct) {
closed_acct = find_account(ctx, db, e->origin_acct);
} else if (!is_channel_account(acct) && !e->spending_txid)
closed_acct = find_close_account(ctx, db, &e->outpoint.txid);
else
closed_acct = acct;

View File

@ -7,7 +7,7 @@ from utils import (
account_balance, first_channel_id, closing_fee, TEST_NETWORK,
scriptpubkey_addr, calc_lease_fee, EXPERIMENTAL_FEATURES,
check_utxos_channel, anchor_expected, check_coin_moves,
check_balance_snaps, mine_funding_to_announce
check_balance_snaps, mine_funding_to_announce, check_inspect_channel
)
import os
@ -1514,6 +1514,15 @@ def test_penalty_htlc_tx_timeout(node_factory, bitcoind, chainparams):
tags = check_utxos_channel(l2, [channel_id], expected_2, filter_channel=channel_id)
check_utxos_channel(l3, [channel_id], expected_3, tags, filter_channel=channel_id)
# Check that it's marked as resolved
for node in [l2, l3]:
bals = node.rpc.bkpr_listbalances()['accounts']
for acc in bals:
if acc['account'] == channel_id:
assert acc['account_closed']
assert acc['account_resolved']
assert acc['resolved_at_block'] > 0
@pytest.mark.developer("uses dev_sign_last_tx")
def test_penalty_rbf_normal(node_factory, bitcoind, executor, chainparams):
@ -2422,6 +2431,20 @@ def test_onchain_their_unilateral_out(node_factory, bitcoind):
tags = check_utxos_channel(l1, [channel_id], expected_1)
check_utxos_channel(l2, [channel_id], expected_2, tags)
# Check 'bkpr-inspect' and 'bkpr-listbalances'
# The wallet events aren't in the channel's events
del expected_1['0']
expected_1['A'] = expected_1['A'][1:]
check_inspect_channel(l1, channel_id, expected_1)
for node in [l1, l2]:
bals = node.rpc.bkpr_listbalances()['accounts']
for acc in bals:
if acc['account'] == channel_id:
assert acc['account_closed']
assert acc['account_resolved']
assert acc['resolved_at_block'] > 0
def test_listfunds_after_their_unilateral(node_factory, bitcoind):
"""We keep spending info around for their unilateral closes.

View File

@ -315,6 +315,64 @@ def dedupe_moves(moves):
return deduped_moves
def inspect_check_actual(txids, channel_id, actual, exp):
assert len(actual['outputs']) == len(exp)
for e in exp:
# find the event in actual that matches
found = False
for a in actual['outputs']:
if e[0].startswith('cid'):
if a['account'] != channel_id:
continue
elif a['account'] != e[0]:
continue
if e[1][0] != a['output_tag']:
continue
if e[2]:
assert e[2][0] == a['spend_tag']
txids.append((e[3], a['spending_txid']))
else:
assert 'spend_tag' not in a
found = True
break
assert found
return txids
def check_inspect_channel(n, channel_id, expected_txs):
actual_txs = n.rpc.bkpr_inspect(channel_id)['txs']
assert len(actual_txs) == len(expected_txs.keys())
# start at the top
exp = list(expected_txs.values())[0]
actual = actual_txs[0]
txids = []
exp_counter = 1
inspect_check_actual(txids, channel_id, actual, exp)
actual_txs.remove(actual)
for (marker, txid) in txids:
actual = None
for a in actual_txs:
if a['txid'] == txid:
actual = a
break
assert actual
exp = expected_txs[marker]
inspect_check_actual(txids, channel_id, actual, exp)
# after we've inspected it, remove it
actual_txs.remove(actual)
exp_counter += 1
# Did we inspect everything?
assert len(actual_txs) == 0
assert exp_counter == len(expected_txs.keys())
def check_utxos_channel(n, chans, expected, exp_tag_list=None, filter_channel=None):
tag_list = {}
moves = n.rpc.call('listcoinmoves_plugin')['coin_moves']