Skip to content

Commit af41c7c

Browse files
committed
notif: dont send balance snapshot for not yet opened channel
We were double counting channel lease fees because we were double firing the channel open event sequence (so to speak). If we don't report balances for unopened channels, we don't have this problem? Changelog-Changed: Plugins: `balance_snapshot` notification does not send balances for channels that aren't locked-in/opened yet
1 parent b2708cf commit af41c7c

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lightningd/channel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ static inline bool channel_unsaved(const struct channel *channel)
466466
&& channel->dbid == 0;
467467
}
468468

469+
static inline bool channel_pre_open(const struct channel *channel)
470+
{
471+
return channel->state == CHANNELD_AWAITING_LOCKIN
472+
|| channel->state == DUALOPEND_OPEN_INIT
473+
|| channel->state == DUALOPEND_AWAITING_LOCKIN;
474+
}
475+
469476
static inline bool channel_active(const struct channel *channel)
470477
{
471478
return channel->state != FUNDING_SPEND_SEEN

lightningd/coin_mvts.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
8181
hout->fees);
8282
}
8383

84+
static bool report_chan_balance(const struct channel *chan)
85+
{
86+
return (channel_active(chan)
87+
|| chan->state == AWAITING_UNILATERAL)
88+
&& !channel_pre_open(chan);
89+
}
90+
8491
void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight)
8592
{
8693
struct balance_snapshot *snap = tal(NULL, struct balance_snapshot);
@@ -121,8 +128,7 @@ void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight)
121128
/* Add channel balances */
122129
list_for_each(&ld->peers, p, list) {
123130
list_for_each(&p->channels, chan, list) {
124-
if (channel_active(chan)
125-
|| chan->state == AWAITING_UNILATERAL) {
131+
if (report_chan_balance(chan)) {
126132
bal = tal(snap, struct account_balance);
127133
bal->bip173_name = chainparams->lightning_hrp;
128134
bal->acct_id = type_to_string(bal,

tests/test_opening.py

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

15151515

1516-
@pytest.mark.xfail
15171516
@pytest.mark.openchannel('v2')
15181517
def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind):
15191518
""" Test that your bookkeeping for a liquidity ad is good."""
@@ -1523,7 +1522,8 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind):
15231522
'rescan': 10, 'disable-plugin': 'bookkeeper',
15241523
'funding-confirms': 6, 'may_reconnect': True},
15251524
{'funder-policy': 'match', 'funder-policy-mod': 100,
1526-
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100}]
1525+
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
1526+
'may_reconnect': True}]
15271527
l1, l2, = node_factory.get_nodes(2, opts=opts)
15281528
amount = 500000
15291529
feerate = 2000
@@ -1548,13 +1548,13 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind):
15481548
del l1.daemon.opts['disable-plugin']
15491549
l1.start()
15501550

1551+
bitcoind.generate_block(2)
1552+
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
1553+
15511554
chan_id = first_channel_id(l1, l2)
15521555
ev_tags = [e['tag'] for e in l1.rpc.bkpr_listaccountevents(chan_id)['events']]
15531556
assert 'lease_fee' in ev_tags
15541557

1555-
bitcoind.generate_block(2)
1556-
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
1557-
15581558
# This should work ok
15591559
l1.rpc.bkpr_listbalances()
15601560

@@ -1564,7 +1564,7 @@ def test_buy_liquidity_ad_check_bookkeeping(node_factory, bitcoind):
15641564
l1.daemon.wait_for_log(' to ONCHAIN')
15651565
l2.daemon.wait_for_log(' to ONCHAIN')
15661566

1567-
# This should crash
1567+
# This should not crash
15681568
l1.rpc.bkpr_listbalances()
15691569

15701570

0 commit comments

Comments
 (0)