diff --git a/lightningd/channel.h b/lightningd/channel.h index a971b012e..9f8ec75e5 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -466,6 +466,13 @@ static inline bool channel_unsaved(const struct channel *channel) && channel->dbid == 0; } +static inline bool channel_pre_open(const struct channel *channel) +{ + return channel->state == CHANNELD_AWAITING_LOCKIN + || channel->state == DUALOPEND_OPEN_INIT + || channel->state == DUALOPEND_AWAITING_LOCKIN; +} + static inline bool channel_active(const struct channel *channel) { return channel->state != FUNDING_SPEND_SEEN diff --git a/lightningd/coin_mvts.c b/lightningd/coin_mvts.c index 7ff18015b..b1cf1418b 100644 --- a/lightningd/coin_mvts.c +++ b/lightningd/coin_mvts.c @@ -81,6 +81,13 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx, hout->fees); } +static bool report_chan_balance(const struct channel *chan) +{ + return (channel_active(chan) + || chan->state == AWAITING_UNILATERAL) + && !channel_pre_open(chan); +} + void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight) { struct balance_snapshot *snap = tal(NULL, struct balance_snapshot); @@ -121,8 +128,7 @@ void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight) /* Add channel balances */ list_for_each(&ld->peers, p, list) { list_for_each(&p->channels, chan, list) { - if (channel_active(chan) - || chan->state == AWAITING_UNILATERAL) { + if (report_chan_balance(chan)) { bal = tal(snap, struct account_balance); bal->bip173_name = chainparams->lightning_hrp; bal->acct_id = type_to_string(bal, diff --git a/tests/test_opening.py b/tests/test_opening.py index 2ef1df163..7e5801a69 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -1513,7 +1513,6 @@ def test_buy_liquidity_ad_no_v2(node_factory, bitcoind): compact_lease='029a002d000000004b2003e8') -@pytest.mark.xfail @pytest.mark.openchannel('v2') def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind): """ Test that your bookkeeping for a liquidity ad is good.""" @@ -1523,7 +1522,8 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind): 'rescan': 10, 'disable-plugin': 'bookkeeper', 'funding-confirms': 6, 'may_reconnect': True}, {'funder-policy': 'match', 'funder-policy-mod': 100, - 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100}] + 'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100, + 'may_reconnect': True}] l1, l2, = node_factory.get_nodes(2, opts=opts) amount = 500000 feerate = 2000 @@ -1548,13 +1548,13 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind): del l1.daemon.opts['disable-plugin'] l1.start() + bitcoind.generate_block(2) + l1.daemon.wait_for_log('to CHANNELD_NORMAL') + chan_id = first_channel_id(l1, l2) ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']] assert 'lease_fee' in ev_tags - bitcoind.generate_block(2) - l1.daemon.wait_for_log('to CHANNELD_NORMAL') - # This should work ok l1.rpc.bkpr_listbalances() @@ -1564,7 +1564,7 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind): l1.daemon.wait_for_log(' to ONCHAIN') l2.daemon.wait_for_log(' to ONCHAIN') - # This should crash + # This should not crash l1.rpc.bkpr_listbalances()