bkpr: cleanup wallet fee entries if decide they belong to a channel

Because we update the onchain_fee table every time a new event comes in,
it's possible (and in fact happens) that we get a wallet
withdraw/deposit event and then the channel open output event.

What we'd expect in this case is that the fees for the tx were credited
to the channel's account, not the wallet. But since we got the two
in/out events first, the fees were accumulated there first.

Our existing logic will add the channel's fees correctly, but we weren't
zeroing out the wallet's balance once it'd been determined that they
were 'ineligble' so to speak, for being included in the fees that round.
This commit is contained in:
niftynei 2022-07-19 17:04:36 +09:30 committed by Rusty Russell
parent 08d8de8e45
commit 791c1a7526
1 changed files with 9 additions and 1 deletions

View File

@ -1111,8 +1111,16 @@ char *maybe_update_onchain_fees(const tal_t *ctx, struct db *db,
/* We only attribute fees to the wallet
* if the wallet is the only game in town */
if (skip_wallet && last_id == wallet_id)
if (skip_wallet && last_id == wallet_id) {
/* But we might need to clean up any fees assigned
* to the wallet from a previous round, where it
* *was* the only game in town */
insert_chain_fees_diff(db, last_id, txid,
AMOUNT_MSAT(0),
events[i]->currency,
events[i]->timestamp);
continue;
}
/* Add an extra msat onto plus_ones accts
* so we don't lose any precision in