Files
palladum-lightning/plugins/bkpr
Rusty Russell bd1798323a bookkeeper: fix assert() which happens with parallel queries.
```
bookkeeper: plugins/bkpr/bookkeeper.c:1226: parse_and_log_chain_move: Assertion `e->db_id > bkpr->chainmoves_index' failed.
bookkeeper: FATAL SIGNAL 6 (version v25.09-245-g901714b-modded)
0x5d7d8718b40f send_backtrace
        common/daemon.c:36
0x5d7d8718b4ab crashdump
        common/daemon.c:81
0x7a6086c4532f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7a6086c9eb2c __pthread_kill_implementation
        ./nptl/pthread_kill.c:44
0x7a6086c9eb2c __pthread_kill_internal
        ./nptl/pthread_kill.c:78
0x7a6086c9eb2c __GI___pthread_kill
        ./nptl/pthread_kill.c:89
0x7a6086c4527d __GI_raise
        ../sysdeps/posix/raise.c:26
0x7a6086c288fe __GI_abort
        ./stdlib/abort.c:79
0x7a6086c2881a __assert_fail_base
        ./assert/assert.c:96
0x7a6086c3b516 __assert_fail
        ./assert/assert.c:105
0x5d7d8717505d parse_and_log_chain_move
        plugins/bkpr/bookkeeper.c:1226
0x5d7d871754f4 listchainmoves_done
        plugins/bkpr/bookkeeper.c:169
0x5d7d87182a4b handle_rpc_reply
        plugins/libplugin.c:1072
0x5d7d87182b5c rpc_conn_read_response
        plugins/libplugin.c:1361
0x5d7d871ba660 next_plan
        ccan/ccan/io/io.c:60
0x5d7d871bab31 do_plan
        ccan/ccan/io/io.c:422
0x5d7d871babee io_ready
        ccan/ccan/io/io.c:439
```

Reported-by: @michael1011
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: plugins: assertion crash in bookkeeper when fresh records arrive while multiple queries in progress.
2025-11-03 14:03:25 +10:30
..
2025-08-15 11:05:51 +09:30
2025-08-19 13:37:50 +09:30
2025-08-19 13:37:50 +09:30

The bookkeeper keeps track of coins moving through your Lightning node.

See the doc/PLUGINS.md#coin_movement section on the message that CLN emits for us to process.

// FIXME: add more detailed documenation for how bookkeeper works.

3rd Party Coin Movements

Bookeeper ingests 3rd party plugin notifications about on-chain movements that it should watch.

This allows for us to account for non-internal on-chain wallets in the single place, making bookkeeper your single source of truth for bitcoin for an organization or node-operator.

As a plugin writer, if you want to emit onchain events that the bookkeeper should track, you should emit an event with the following format:

{
	"utxo_deposit": {
		"account": "nifty's secret stash",
		"transfer_from: null,
		"outpoint": xxxx:x,
		"amount_msat": "10000sat",
		"coin_type": "bc",
		"timestamp": xxxx,
		"blockheight": xxx,
	}
}
{
	"utxo_spend": {
		"account": "nifty's secret stash",
		"outpoint": xxxx:x,
		"spending_txid": xxxx,
		"amount_msat": "10000sat",
		"coin_type": "bc",
		"timestamp": xxxx,
		"blockheight": xxx,
	}
}

Withdrawing money (sending to a external account)

Sending money to an external account is a bit unintuitive in the UTXO model that we're using to track coin moves; technically a send to an external account is a "deposit" to 3rd party's UTXO.

To account for these, bookkeeper expects to receive a utxo_deposit event for the creation of an output to a 3rd party. It's assumed that you'll issue these at transaction creation time, and that they won't be final until we receive notice of spend of the inputs in the tx that created them.

To notify that money is being sent to a 3rd party output, here's the event we'd expect.

The two keys here are the following:

  • The account is external. This is a special account in bookkeeper and used for tracking external deposits (aka sends)
  • The transfer_from field is set to the name of the account that is sending out the money.
{
	"utxo_deposit": {
		"account": "external",
		"transfer_from": "nifty's secret stash",
		"outpoint": xxxx:x,
		"amount_msat": "10000sat",
		"coin_type": "bc",
		"timestamp": xxxx,
		"blockheight": xxx,
	}
}

List of todos

List of things to check/work on, as a todo list.

  • Transfers btw a 3rd party wallet and the internal CLN wallet? These should be registered as internal transfers and not show up in listincome