mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
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
This commit is contained in:
parent
8452d903b4
commit
1980ba420b
3 changed files with 21 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue