From 791c1a7526cf8ad961e2b6b93022f7f9d57dd325 Mon Sep 17 00:00:00 2001 From: niftynei Date: Tue, 19 Jul 2022 17:04:36 +0930 Subject: [PATCH] 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. --- plugins/bkpr/recorder.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c index 9754f01a8..929e2628a 100644 --- a/plugins/bkpr/recorder.c +++ b/plugins/bkpr/recorder.c @@ -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