core-lightning/plugins/bkpr/account_entry.c
niftynei 5f41d9247e bkpr: properly account for onchain fees for channel closes
onchain fees are weird at channel close because:

- you may be missing an trimmed htlc (which went to fees)
- the balance from close may have been rounded (msats cant land on
chain)
- the close might have been a past state and you've actually
  ended up with more money onchain than you had in the channel. wut

This commit accounts for all of this appropriately, with some tests.

channel_close.debit should equal onchain_fee.credit (for that txid)
plus sum(chain_event.credit [wallet/channel_acct]).

In the penalty case, channel_close.debit becomes channel_close.debit +
penalty_adj.debit, i.e.

	channel-close.debit + (penalty_adj.debit) =
		onchain_fee.credit
	      + sum(chain_event.credit [wallet/channel_acct])
2022-07-28 12:08:18 +09:30

28 lines
499 B
C

#include "config.h"
#include <ccan/tal/str/str.h>
#include <plugins/bkpr/account_entry.h>
#include <stddef.h>
static const char *tags[] = {
"journal_entry",
"penalty_adj",
};
const char *account_entry_tag_str(enum account_entry_tag tag)
{
return tags[tag];
}
bool account_entry_tag_find(char *str, enum account_entry_tag *tag)
{
for (size_t i = 0; i < NUM_ACCOUNT_ENTRY_TAGS; i++) {
if (streq(str, tags[i])) {
*tag = (enum account_entry_tag) i;
return true;
}
}
return false;
}