bkpr: create onchain fee records for events

clightning doesn't give us any info about onchain fees (how could it?
it only knows about utxo object levels, and doesn't keep track of
how/when those are all related)

Instead, we keep running totals of the onchain fees for utxos. This
implements the master method for accounting for them, plus includes
tests to account for channel opens (across two accounts) as well as a
htlc-tx channel close.

Missing: we don't currently emit an event from cln for `withdraw`
initiated removal of funds, so the accounting for wallet -> external
funds is a bit janky. We don't account for the fees on these
transactions since we don't have the resulting 'external' event to
register them against!
This commit is contained in:
niftynei
2022-07-19 15:04:40 +09:30
committed by Rusty Russell
parent c12cd99039
commit dc113d0a3f
3 changed files with 678 additions and 34 deletions

View File

@@ -5,6 +5,7 @@
#include <ccan/tal/tal.h>
struct account;
struct bitcoin_txid;
struct chain_event;
struct channel_event;
struct db;
@@ -29,6 +30,9 @@ struct chain_event **account_get_chain_events(const tal_t *ctx,
struct db *db,
struct account *acct);
/* List all chain fees, for all accounts */
struct onchain_fee **list_chain_fees(const tal_t *ctx, struct db *db);
/* Add the given account to the database */
void account_add(struct db *db, struct account *acct);
@@ -43,6 +47,11 @@ void maybe_update_account(struct db *db,
struct chain_event *e,
const enum mvt_tag *tags);
/* Update our onchain fees now? */
char *maybe_update_onchain_fees(const tal_t *ctx,
struct db *db,
struct bitcoin_txid *txid);
/* Log a channel event */
void log_channel_event(struct db *db,
const struct account *acct,