What changed, and why it matters
This commit removes the bookkeeper plugin's private SQLite database (accounts.db) and switches it to use the main lightningd database instead. It is a code cleanup/refactoring change, not a security fix. There is no evidence in the commit of a vulnerability being patched.
No security action required. Treat as normal refactoring; verify migration path for existing accounts.db users if upgrading.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes plugins/bkpr/db.c, db.h, and the dedicated db test, strips db.c from the Makefile, and removes db_begin_transaction/db_commit_transaction calls and direct log_chain_event/log_channel_event inserts from bookkeeper.c and recorder.c. The struct bkpr no longer holds a struct db *. The commit message frames this as a changelog change (‘bookkeeper now uses the lightningd database’), not a security-relevant fix.
Changed components
plugins/bkpr/bookkeeper.cplugins/bkpr/bookkeeper.hplugins/bkpr/recorder.cplugins/bkpr/recorder.hplugins/bkpr/db.cplugins/bkpr/db.hplugins/bkpr/Makefileplugins/bkpr/test/run-bkpr_db.cplugins/bkpr/test/MakefileInspect captured patch +4 / −552
diff --git a/plugins/bkpr/Makefile b/plugins/bkpr/Makefile
index 48f0aa59..943b8755 100644
--- a/plugins/bkpr/Makefile
+++ b/plugins/bkpr/Makefile
@@ -8,7 +8,6 @@ BOOKKEEPER_PLUGIN_SRC := \
plugins/bkpr/chain_event.c \
plugins/bkpr/channel_event.c \
plugins/bkpr/channelsapy.c \
- plugins/bkpr/db.c \
plugins/bkpr/descriptions.c \
plugins/bkpr/incomestmt.c \
plugins/bkpr/onchain_fee.c \
@@ -16,10 +15,6 @@ BOOKKEEPER_PLUGIN_SRC := \
plugins/bkpr/recorder.c \
plugins/bkpr/sql.c
-BOOKKEEPER_DB_QUERIES := \
- plugins/bkpr/db_sqlite3_sqlgen.c \
- plugins/bkpr/db_postgres_sqlgen.c
-
BOOKKEEPER_SRC := $(BOOKKEEPER_PLUGIN_SRC) $(BOOKKEEPER_DB_QUERIES)
BOOKKEEPER_HEADER := \
plugins/bkpr/account.h \
@@ -29,7 +24,6 @@ BOOKKEEPER_HEADER := \
plugins/bkpr/chain_event.h \
plugins/bkpr/channel_event.h \
plugins/bkpr/channelsapy.h \
- plugins/bkpr/db.h \
plugins/bkpr/descriptions.h \
plugins/bkpr/incomestmt.h \
plugins/bkpr/onchain_fee.h \
@@ -41,31 +35,12 @@ BOOKKEEPER_OBJS := $(BOOKKEEPER_SRC:.c=.o)
$(BOOKKEEPER_OBJS): $(PLUGIN_LIB_HEADER) $(BOOKKEEPER_HEADER)
-PLUGIN_ALL_SRC += $(BOOKKEEPER_SRC) $(BOOKKEEPER_DB_QUERIES)
+PLUGIN_ALL_SRC += $(BOOKKEEPER_SRC)
PLUGIN_ALL_HEADER += $(BOOKKEEPER_HEADER)
C_PLUGINS += plugins/bookkeeper
PLUGINS += plugins/bookkeeper
-plugins/bookkeeper: common/bolt12.o common/bolt12_merkle.o common/channel_type.o $(BOOKKEEPER_OBJS) $(PLUGIN_LIB_OBJS) $(JSMN_OBJTS) $(PLUGIN_COMMON_OBJS) $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) $(DB_OBJS)
-
-# The following files contain SQL-annotated statements that we need to extact
-BOOKKEEPER_SQL_FILES := \
- $(DB_SQL_FILES) \
- plugins/bkpr/db.c \
- plugins/bkpr/account.c \
- plugins/bkpr/incomestmt.c \
- plugins/bkpr/onchain_fee.c \
- plugins/bkpr/recorder.c
-
-plugins/bkpr/statements_gettextgen.po: $(BOOKKEEPER_SQL_FILES) $(FORCE)
- @if $(call SHA256STAMP_CHANGED); then \
- $(call VERBOSE,"xgettext $@",xgettext -kNAMED_SQL -kSQL --add-location --no-wrap --omit-header -o $@ $(BOOKKEEPER_SQL_FILES) && $(call SHA256STAMP,# ,)); \
- fi
-
-plugins/bkpr/db_%_sqlgen.c: plugins/bkpr/statements_gettextgen.po devtools/sql-rewrite.py $(BOOKKEEPER_SQL_FILES) $(FORCE)
- @if $(call SHA256STAMP_CHANGED); then \
- $(call VERBOSE,"sql-rewrite $@",devtools/sql-rewrite.py plugins/bkpr/statements_gettextgen.po $* > $@ && $(call SHA256STAMP,//,)); \
- fi
+plugins/bookkeeper: common/bolt12.o common/bolt12_merkle.o common/channel_type.o $(BOOKKEEPER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(WIRE_OBJS) $(WIRE_BOLT12_OBJS)
maintainer-clean: clean
clean: bkpr-maintainer-clean
diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c
index ae7d89d9..e150b7a7 100644
--- a/plugins/bkpr/bookkeeper.c
+++ b/plugins/bkpr/bookkeeper.c
@@ -22,7 +22,6 @@
#include <plugins/bkpr/chain_event.h>
#include <plugins/bkpr/channel_event.h>
#include <plugins/bkpr/channelsapy.h>
-#include <plugins/bkpr/db.h>
#include <plugins/bkpr/descriptions.h>
#include <plugins/bkpr/incomestmt.h>
#include <plugins/bkpr/onchain_fee.h>
@@ -218,12 +217,10 @@ getblockheight_done(struct command *cmd,
result->end - result->start, buf);
/* Get the income events */
- db_begin_transaction(bkpr->db);
apys = compute_channel_apys(cmd, bkpr, cmd,
*req->start_time,
*req->end_time,
blockheight);
- db_commit_transaction(bkpr->db);
/* Setup the net_apys entry */
net_apys = new_channel_apy(cmd);
@@ -313,10 +310,8 @@ static struct command_result *do_dump_income(struct command *cmd,
char *err;
/* Ok, go find me some income events! */
- db_begin_transaction(bkpr->db);
evs = list_income_events(cmd, bkpr, cmd, *info->start_time, *info->end_time,
*info->consolidate_fees);
- db_commit_transaction(bkpr->db);
if (!info->filename)
info->filename = csv_filename(info, info->csv_fmt);
@@ -365,10 +360,8 @@ static struct command_result *do_list_income(struct command *cmd,
struct bkpr *bkpr = bkpr_of(cmd->plugin);
/* Ok, go find me some income events! */
- db_begin_transaction(bkpr->db);
evs = list_income_events(cmd, bkpr, cmd, *info->start_time, *info->end_time,
*info->consolidate_fees);
- db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
@@ -417,10 +410,8 @@ static struct command_result *do_inspect(struct command *cmd,
"Account %s not found",
acct_name);
- db_begin_transaction(bkpr->db);
find_txo_chain(cmd, bkpr, cmd, acct, &txos);
fee_sums = find_account_onchain_fees(cmd, bkpr, acct);
- db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
json_array_start(res, "txs");
@@ -623,7 +614,6 @@ static struct command_result *do_account_events(struct command *cmd,
} else
acct = NULL;
- db_begin_transaction(bkpr->db);
if (acct) {
channel_events = account_get_channel_events(cmd, bkpr, cmd, acct);
chain_events = account_get_chain_events(cmd, bkpr, cmd, acct);
@@ -643,7 +633,6 @@ static struct command_result *do_account_events(struct command *cmd,
chain_events = list_chain_events(cmd, bkpr, cmd);
onchain_fees = list_chain_fees(cmd, bkpr);
}
- db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
json_array_start(res, "events");
@@ -680,10 +669,8 @@ static struct command_result *do_edit_desc(struct command *cmd,
struct chain_event **chain_events;
struct bkpr *bkpr = bkpr_of(cmd->plugin);
- db_begin_transaction(bkpr->db);
add_utxo_description(cmd, bkpr, info->outpoint, info->new_desc);
chain_events = get_chain_events_by_outpoint(cmd, bkpr, cmd, info->outpoint);
- db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
json_array_start(res, "updated");
@@ -721,12 +708,10 @@ static struct command_result *do_edit_desc_payment(struct command *cmd,
struct chain_event **chain_events;
struct bkpr *bkpr = bkpr_of(cmd->plugin);
- db_begin_transaction(bkpr->db);
add_payment_hash_description(cmd, bkpr, info->identifier, info->new_desc);
chain_events = get_chain_events_by_id(cmd, bkpr, cmd, info->identifier);
channel_events = get_channel_events_by_id(cmd, bkpr, cmd, info->identifier);
- db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
json_array_start(res, "updated");
@@ -760,7 +745,6 @@ static struct command_result *do_list_balances(struct command *cmd,
res = jsonrpc_stream_success(cmd);
/* List of accts */
- db_begin_transaction(bkpr->db);
accts = list_accounts(cmd, bkpr);
json_array_start(res, "accounts");
@@ -816,7 +800,6 @@ static struct command_result *do_list_balances(struct command *cmd,
json_object_end(res);
}
json_array_end(res);
- db_commit_transaction(bkpr->db);
return command_finished(cmd, res);
}
@@ -858,8 +841,6 @@ static char *do_account_close_checks(struct command *cmd,
{
struct account *closed_acct;
- db_begin_transaction(bkpr->db);
-
/* If is an external acct event, might be close channel related */
if (!is_channel_account(acct->name) && e->origin_acct) {
closed_acct = find_account(bkpr, e->origin_acct);
@@ -884,14 +865,11 @@ static char *do_account_close_checks(struct command *cmd,
account_update_closeheight(cmd, closed_acct, closeheight);
err = update_channel_onchain_fees(cmd, cmd, bkpr, closed_acct);
if (err) {
- db_commit_transaction(bkpr->db);
return err;
}
}
}
- db_commit_transaction(bkpr->db);
-
return NULL;
}
@@ -1218,7 +1196,6 @@ parse_and_log_chain_move(struct command *cmd,
fmt_amount_msat(tmpctx, e->debit),
CHAIN_MOVE, e->timestamp);
- db_begin_transaction(bkpr->db);
/* FIXME: lookup the peer id for this channel! */
acct = find_or_create_account(cmd, bkpr, acct_name);
@@ -1229,13 +1206,6 @@ parse_and_log_chain_move(struct command *cmd,
assert(e->db_id > bkpr->chainmoves_index);
bkpr->chainmoves_index = e->db_id;
- if (!log_chain_event(bkpr, acct, e)) {
- plugin_log(cmd->plugin, LOG_BROKEN, "Duplicated event!");
- db_commit_transaction(bkpr->db);
- /* This is not a new event, do nothing */
- return;
- }
-
/* This event *might* have implications for account;
* update as necessary */
maybe_update_account(cmd, acct, e, tags, closed_count,
@@ -1247,8 +1217,6 @@ parse_and_log_chain_move(struct command *cmd,
e->spending_txid :
&e->outpoint.txid);
- db_commit_transaction(bkpr->db);
-
if (err)
plugin_err(cmd->plugin,
"Unable to update onchain fees %s",
@@ -1258,13 +1226,11 @@ parse_and_log_chain_move(struct command *cmd,
* that it we've got an external deposit that's now
* confirmed */
if (e->spending_txid) {
- db_begin_transaction(bkpr->db);
/* Go see if there's any deposits to an external
* that are now confirmed */
/* FIXME: might need updating when we can splice? */
maybe_closeout_external_deposits(cmd, bkpr, e->spending_txid,
e->blockheight);
- db_commit_transaction(bkpr->db);
}
/* Maybe mark acct as onchain resolved */
@@ -1343,7 +1309,6 @@ parse_and_log_channel_move(struct command *cmd,
CHANNEL_MOVE, e->timestamp);
/* Go find the account for this event */
- db_begin_transaction(bkpr->db);
acct = find_account(bkpr, acct_name);
if (!acct)
plugin_err(cmd->plugin,
@@ -1355,8 +1320,6 @@ parse_and_log_channel_move(struct command *cmd,
assert(e->db_id > bkpr->channelmoves_index);
bkpr->channelmoves_index = e->db_id;
- log_channel_event(bkpr->db, acct, e);
-
/* Check for invoice desc data, necessary */
if (e->payment_id && tag == MVT_INVOICE) {
/* We only do rebalance checks for debits,
@@ -1364,12 +1327,9 @@ parse_and_log_channel_move(struct command *cmd,
if (!amount_msat_is_zero(e->debit))
maybe_record_rebalance(cmd, bkpr, e);
- db_commit_transaction(bkpr->db);
lookup_invoice_desc(cmd, e->credit, e->payment_id, rinfo);
return;
}
-
- db_commit_transaction(bkpr->db);
}
static bool json_to_tok(const char *buffer, const jsmntok_t *tok, const jsmntok_t **ret)
@@ -1574,7 +1534,6 @@ static const char *init(struct command *init_cmd, const char *b, const jsmntok_t
bkpr->db_dsn = tal_fmt(bkpr, "sqlite3://accounts.sqlite3");
plugin_log(p, LOG_DBG, "Setting up database at %s", bkpr->db_dsn);
- bkpr->db = db_setup(bkpr, p, bkpr->db_dsn);
bkpr->accounts = init_accounts(bkpr, init_cmd);
bkpr->onchain_fees = init_onchain_fees(bkpr, init_cmd);
bkpr->descriptions = init_descriptions(bkpr, init_cmd);
diff --git a/plugins/bkpr/bookkeeper.h b/plugins/bkpr/bookkeeper.h
index 9e229e30..8c5ceba5 100644
--- a/plugins/bkpr/bookkeeper.h
+++ b/plugins/bkpr/bookkeeper.h
@@ -7,8 +7,7 @@
struct command;
struct bkpr {
- /* The database that we store all the accounting data in */
- struct db *db;
+ /* The datastore-backed lookup tables for our annotations */
struct accounts *accounts;
struct onchain_fees *onchain_fees;
struct descriptions *descriptions;
diff --git a/plugins/bkpr/db.c b/plugins/bkpr/db.c
deleted file mode 100644
index 6caedb03..00000000
--- a/plugins/bkpr/db.c
+++ /dev/null
@@ -1,161 +0,0 @@
-#include "config.h"
-#include <ccan/array_size/array_size.h>
-#include <ccan/tal/str/str.h>
-#include <common/daemon.h>
-#include <db/bindings.h>
-#include <db/common.h>
-#include <db/exec.h>
-#include <db/utils.h>
-#include <plugins/bkpr/db.h>
-#include <plugins/libplugin.h>
-#include <stdio.h>
-
-struct migration {
- const char *sql;
- void (*func)(struct plugin *p, struct db *db);
-};
-
-/* Do not reorder or remove elements from this array.
- * It is used to migrate existing databases from a prevoius state, based on
- * string indices */
-static struct migration db_migrations[] = {
- {SQL("CREATE TABLE version (version INTEGER);"), NULL},
- {SQL("INSERT INTO version VALUES (1);"), NULL},
- {SQL("CREATE TABLE vars ("
- " name TEXT"
- ", val TEXT"
- ", intval INTEGER"
- ", blobval BLOB"
- ", PRIMARY KEY (name)"
- ");"),
- NULL},
- {SQL("INSERT INTO vars ("
- " name"
- ", intval"
- ") VALUES ("
- " 'data_version'"
- ", 0"
- ");"),
- NULL},
- {NULL, NULL},
- {SQL("CREATE TABLE chain_events ("
- " id BIGSERIAL"
- ", account_name TEXT"
- ", tag TEXT"
- ", credit BIGINT"
- ", debit BIGINT"
- ", output_value BIGINT"
- ", currency TEXT"
- ", timestamp BIGINT"
- ", blockheight INTEGER"
- ", utxo_txid BLOB"
- ", outnum INTEGER"
- ", payment_id BLOB"
- ", spending_txid BLOB"
- ", PRIMARY KEY (id)"
- ");"),
- NULL},
- {SQL("CREATE TABLE channel_events ("
- " id BIGSERIAL"
- ", account_name TEXT"
- ", tag TEXT"
- ", credit BIGINT"
- ", debit BIGINT"
- ", fees BIGINT"
- ", currency TEXT"
- ", payment_id BLOB"
- ", part_id INTEGER"
- ", timestamp BIGINT"
- ", PRIMARY KEY (id)"
- ");"),
- NULL},
- {NULL, NULL}, /* onchain_fees table */
- {SQL("ALTER TABLE chain_events ADD origin TEXT;"), NULL},
- {NULL, NULL},
- {SQL("ALTER TABLE chain_events ADD ignored INTEGER;"), NULL},
- {SQL("ALTER TABLE chain_events ADD stealable INTEGER;"), NULL},
- {SQL("ALTER TABLE chain_events ADD ev_desc TEXT DEFAULT NULL;"), NULL},
- {SQL("ALTER TABLE channel_events ADD ev_desc TEXT DEFAULT NULL;"), NULL},
- {SQL("ALTER TABLE channel_events ADD rebalance_id BIGINT DEFAULT NULL;"), NULL},
- {SQL("ALTER TABLE chain_events ADD spliced INTEGER DEFAULT 0;"), NULL},
- {NULL, NULL},
- {NULL, NULL},
- /* We used to send anchors to the wallet, but set ignored tag. Now we send
- * them to external. */
- {SQL("UPDATE chain_events"
- " SET account_name = 'external'"
- " WHERE account_name = 'wallet'"
- " AND ignored = 1"), NULL},
-};
-
-static bool db_migrate(struct plugin *p, struct db *db)
-{
- /* Read current version from database */
- int current, orig, available;
- struct db_stmt *stmt;
-
- orig = current = db_get_version(db);
- available = ARRAY_SIZE(db_migrations) - 1;
-
- if (current == -1) {
- plugin_log(p, LOG_INFORM, "Creating database");
- } else if (available < current)
- plugin_err(p,
- "Refusing to migrate down from version %u to %u",
- current, available);
- else if (current != available)
- plugin_log(p, LOG_INFORM,
- "Updating database from version %u to %u",
- current, available);
-
- while (current < available) {
- current++;
- if (db_migrations[current].sql) {
- stmt = db_prepare_v2(db, db_migrations[current].sql);
- db_exec_prepared_v2(take(stmt));
- }
- if (db_migrations[current].func)
- db_migrations[current].func(p, db);
- }
-
- /* Finally, update the version number in the version table */
- stmt = db_prepare_v2(db, SQL("UPDATE version SET version=?;"));
- db_bind_int(stmt, available);
- db_exec_prepared_v2(take(stmt));
-
- return current != orig;
-}
-
-static void db_error(struct plugin *plugin, bool fatal, const char *fmt, va_list ap)
-{
- if (fatal) {
- const char *msg = tal_vfmt(tmpctx, fmt, ap);
- send_backtrace(msg);
- plugin_err(plugin, "%s", msg);
- }
- else
- plugin_logv(plugin, LOG_BROKEN, fmt, ap);
-}
-
-struct db *db_setup(const tal_t *ctx, struct plugin *p,
- const char *db_dsn)
-{
- bool migrated;
- struct db *db;
-
- db = db_open(ctx, db_dsn, plugin_developer_mode(p), db_error, p);
- db->report_changes_fn = NULL;
-
- db_begin_transaction(db);
- migrated = db_migrate(p, db);
- db->data_version = db_data_version_get(db);
- db_commit_transaction(db);
-
- /* This needs to be done outside a transaction, apparently.
- * It's a good idea to do this every so often, and on db
- * upgrade is a reasonable time. */
- if (migrated && !db->config->vacuum_fn(db))
- db_fatal(db, "Error vacuuming db: %s", db->error);
-
- return db;
-}
diff --git a/plugins/bkpr/db.h b/plugins/bkpr/db.h
deleted file mode 100644
index 71af1ef6..00000000
--- a/plugins/bkpr/db.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef LIGHTNING_PLUGINS_BKPR_DB_H
-#define LIGHTNING_PLUGINS_BKPR_DB_H
-#include "config.h"
-#include <ccan/tal/tal.h>
-
-struct plugin;
-struct db;
-
-struct db *db_setup(const tal_t *ctx, struct plugin *p, const char *db_dsn);
-
-#endif /* LIGHTNING_PLUGINS_BKPR_DB_H */
diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c
index 2e84bedd..82c3498c 100644
--- a/plugins/bkpr/recorder.c
+++ b/plugins/bkpr/recorder.c
@@ -510,44 +510,6 @@ struct channel_event **get_channel_events_by_id(const tal_t *ctx,
bkpr->channelmoves_index);
}
-void log_channel_event(struct db *db,
- const struct account *acct,
- struct channel_event *e)
-{
- struct db_stmt *stmt;
-
- stmt = db_prepare_v2(db, SQL("INSERT INTO channel_events"
- " ("
- " account_name"
- ", tag"
- ", credit"
- ", debit"
- ", fees"
- ", payment_id"
- ", part_id"
- ", timestamp"
- ")"
- " VALUES"
- " (?, ?, ?, ?, ?, ?, ?, ?);"));
-
- db_bind_text(stmt, acct->name);
- db_bind_text(stmt, e->tag);
- db_bind_amount_msat(stmt, e->credit);
- db_bind_amount_msat(stmt, e->debit);
- db_bind_amount_msat(stmt, e->fees);
- if (e->payment_id)
- db_bind_sha256(stmt, e->payment_id);
- else
- db_bind_null(stmt);
- db_bind_int(stmt, e->part_id);
- db_bind_u64(stmt, e->timestamp);
-
- db_exec_prepared_v2(stmt);
- e->db_id = db_last_insert_id_v2(stmt);
- e->acct_name = tal_strdup(e, acct->name);
- tal_free(stmt);
-}
-
struct chain_event **find_chain_events_bytxid(const tal_t *ctx,
const struct bkpr *bkpr,
struct command *cmd,
@@ -644,61 +606,3 @@ void maybe_closeout_external_deposits(struct command *cmd,
}
}
-bool log_chain_event(struct bkpr *bkpr,
- const struct account *acct,
- struct chain_event *e)
-{
- struct db_stmt *stmt;
-
- stmt = db_prepare_v2(bkpr->db, SQL("INSERT INTO chain_events"
- " ("
- " account_name"
- ", origin"
- ", tag"
- ", credit"
- ", debit"
- ", output_value"
- ", timestamp"
- ", blockheight"
- ", utxo_txid"
- ", outnum"
- ", payment_id"
- ", spending_txid"
- ", stealable"
- ", spliced"
- ")"
- " VALUES "
- "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
-
- db_bind_text(stmt, acct->name);
- if (e->origin_acct)
- db_bind_text(stmt, e->origin_acct);
- else
- db_bind_null(stmt);
- db_bind_text(stmt, e->tag);
- db_bind_amount_msat(stmt, e->credit);
- db_bind_amount_msat(stmt, e->debit);
- db_bind_amount_msat(stmt, e->output_value);
- db_bind_u64(stmt, e->timestamp);
- db_bind_int(stmt, e->blockheight);
- db_bind_txid(stmt, &e->outpoint.txid);
- db_bind_int(stmt, e->outpoint.n);
-
- if (e->payment_id)
- db_bind_sha256(stmt, e->payment_id);
- else
- db_bind_null(stmt);
-
- if (e->spending_txid)
- db_bind_txid(stmt, e->spending_txid);
- else
- db_bind_null(stmt);
-
- db_bind_int(stmt, e->stealable ? 1 : 0);
- db_bind_int(stmt, e->splice_close ? 1 : 0);
- db_exec_prepared_v2(stmt);
- e->db_id = db_last_insert_id_v2(stmt);
- e->acct_name = tal_strdup(e, acct->name);
- tal_free(stmt);
- return true;
-}
diff --git a/plugins/bkpr/recorder.h b/plugins/bkpr/recorder.h
index 9ffdd272..3c807a7e 100644
--- a/plugins/bkpr/recorder.h
+++ b/plugins/bkpr/recorder.h
@@ -8,7 +8,6 @@ struct account;
struct bitcoin_txid;
struct chain_event;
struct channel_event;
-struct db;
struct plugin;
enum mvt_tag;
struct onchain_fee;
@@ -51,7 +50,6 @@ struct channel_event **list_channel_events(const tal_t *ctx,
/* Get all channel events, order by timestamp.
*
* @ctx - context to allocate from
- * @db - database to query
* @start_time - UNIX timestamp to query after (exclusive)
* @end_time - UNIX timestamp to query until (inclusive)
*/
@@ -159,17 +157,4 @@ void maybe_closeout_external_deposits(struct command *cmd,
void maybe_record_rebalance(struct command *cmd,
struct bkpr *bkpr,
const struct channel_event *out);
-
-/* Log a channel event */
-void log_channel_event(struct db *db,
- const struct account *acct,
- struct channel_event *e);
-
-/* Log a chain event.
- * Returns true if inserted, false if already exists;
- * ctx is for allocating objects onto chain_event `e` */
-bool log_chain_event(struct bkpr *bkpr,
- const struct account *acct,
- struct chain_event *e);
-
#endif /* LIGHTNING_PLUGINS_BKPR_RECORDER_H */
diff --git a/plugins/bkpr/test/Makefile b/plugins/bkpr/test/Makefile
index a043318c..52b92a1f 100644
--- a/plugins/bkpr/test/Makefile
+++ b/plugins/bkpr/test/Makefile
@@ -29,8 +29,7 @@ BOOKKEEPER_TEST_COMMON_OBJS := \
db/exec.o \
db/utils.o \
wire/towire.o \
- wire/fromwire.o \
- plugins/bkpr/db_sqlite3_sqlgen.o
+ wire/fromwire.o
$(BOOKKEEPER_TEST_PROGRAMS): $(BITCOIN_OBJS) $(BOOKKEEPER_TEST_COMMON_OBJS)
$(BOOKKEEPER_TEST_OBJS): $(BOOKKEEPER_HEADER) $(BOOKKEEPER_SRC) $(BOOKKEEPER_TEST_COMMON_OBJS)
diff --git a/plugins/bkpr/test/run-bkpr_db.c b/plugins/bkpr/test/run-bkpr_db.c
deleted file mode 100644
index c7826090..00000000
--- a/plugins/bkpr/test/run-bkpr_db.c
+++ /dev/null
@@ -1,197 +0,0 @@
-#include "config.h"
-
-#include <ccan/tal/str/str.h>
-#include <db/common.h>
-
-#include "common/json_filter.c"
-#include "plugins/bkpr/db.c"
-#include "plugins/libplugin.c"
-
-#include "test_utils.h"
-
-#include <common/fee_states.h>
-#include <common/htlc.h>
-#include <common/json_stream.h>
-#include <common/setup.h>
-#include <common/utils.h>
-#include <plugins/bkpr/account_entry.h>
-#include <plugins/bkpr/channel_event.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <wire/wire.h>
-
-/* AUTOGENERATED MOCKS START */
-/* Generated stub for command_fail_badparam */
-struct command_result *command_fail_badparam(struct command *cmd UNNEEDED,
- const char *paramname UNNEEDED,
- const char *buffer UNNEEDED,
- const jsmntok_t *tok UNNEEDED,
- const char *msg UNNEEDED)
-{ fprintf(stderr, "command_fail_badparam called!\n"); abort(); }
-/* Generated stub for daemon_developer_mode */
-bool daemon_developer_mode(char *argv[])
-{ fprintf(stderr, "daemon_developer_mode called!\n"); abort(); }
-/* Generated stub for daemon_setup */
-void daemon_setup(const char *argv0 UNNEEDED,
- void (*backtrace_print)(const char *fmt UNNEEDED, ...) UNNEEDED,
- void (*backtrace_exit)(void))
-{ fprintf(stderr, "daemon_setup called!\n"); abort(); }
-/* Generated stub for deprecated_ok_ */
-bool deprecated_ok_(bool deprecated_apis UNNEEDED,
- const char *feature UNNEEDED,
- const char *start UNNEEDED,
- const char *end UNNEEDED,
- const char **begs UNNEEDED,
- void (*complain)(const char *feat UNNEEDED, bool allowing UNNEEDED, void *) UNNEEDED,
- void *cbarg UNNEEDED)
-{ fprintf(stderr, "deprecated_ok_ called!\n"); abort(); }
-/* Generated stub for first_fee_state */
-enum htlc_state first_fee_state(enum side opener UNNEEDED)
-{ fprintf(stderr, "first_fee_state called!\n"); abort(); }
-/* Generated stub for fmt_wireaddr_without_port */
-char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED)
-{ fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); }
-/* Generated stub for fromwire_wireaddr */
-bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
-{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
-/* Generated stub for htlc_state_flags */
-int htlc_state_flags(enum htlc_state state UNNEEDED)
-{ fprintf(stderr, "htlc_state_flags called!\n"); abort(); }
-/* Generated stub for htlc_state_name */
-const char *htlc_state_name(enum htlc_state s UNNEEDED)
-{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
-/* Generated stub for is_asterix_notification */
-bool is_asterix_notification(const char *notification_name UNNEEDED,
- const char *subscriptions UNNEEDED)
-{ fprintf(stderr, "is_asterix_notification called!\n"); abort(); }
-/* Generated stub for json_scan */
-const char *json_scan(const tal_t *ctx UNNEEDED,
- const char *buffer UNNEEDED,
- const jsmntok_t *tok UNNEEDED,
- const char *guide UNNEEDED,
- ...)
-{ fprintf(stderr, "json_scan called!\n"); abort(); }
-/* Generated stub for json_scanv */
-const char *json_scanv(const tal_t *ctx UNNEEDED,
- const char *buffer UNNEEDED,
- const jsmntok_t *tok UNNEEDED,
- const char *guide UNNEEDED,
- va_list ap UNNEEDED)
-{ fprintf(stderr, "json_scanv called!\n"); abort(); }
-/* Generated stub for json_to_int */
-bool json_to_int(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, int *num UNNEEDED)
-{ fprintf(stderr, "json_to_int called!\n"); abort(); }
-/* Generated stub for json_to_msat */
-bool json_to_msat(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- struct amount_msat *msat UNNEEDED)
-{ fprintf(stderr, "json_to_msat called!\n"); abort(); }
-/* Generated stub for json_to_node_id */
-bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- struct node_id *id UNNEEDED)
-{ fprintf(stderr, "json_to_node_id called!\n"); abort(); }
-/* Generated stub for json_to_number */
-bool json_to_number(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- unsigned int *num UNNEEDED)
-{ fprintf(stderr, "json_to_number called!\n"); abort(); }
-/* Generated stub for json_to_secret */
-bool json_to_secret(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct secret *dest UNNEEDED)
-{ fprintf(stderr, "json_to_secret called!\n"); abort(); }
-/* Generated stub for json_to_short_channel_id */
-bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- struct short_channel_id *scid UNNEEDED)
-{ fprintf(stderr, "json_to_short_channel_id called!\n"); abort(); }
-/* Generated stub for json_to_txid */
-bool json_to_txid(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- struct bitcoin_txid *txid UNNEEDED)
-{ fprintf(stderr, "json_to_txid called!\n"); abort(); }
-/* Generated stub for json_to_u16 */
-bool json_to_u16(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
- uint16_t *num UNNEEDED)
-{ fprintf(stderr, "json_to_u16 called!\n"); abort(); }
-/* Generated stub for json_tok_bin_from_hex */
-u8 *json_tok_bin_from_hex(const tal_t *ctx UNNEEDED, const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED)
-{ fprintf(stderr, "json_tok_bin_from_hex called!\n"); abort(); }
-/* Generated stub for last_fee_state */
-enum htlc_state last_fee_state(enum side opener UNNEEDED)
-{ fprintf(stderr, "last_fee_state called!\n"); abort(); }
-/* Generated stub for log_level_name */
-const char *log_level_name(enum log_level level UNNEEDED)
-{ fprintf(stderr, "log_level_name called!\n"); abort(); }
-/* Generated stub for param_check */
-bool param_check(struct command *cmd UNNEEDED,
- const char *buffer UNNEEDED,
- const jsmntok_t tokens[] UNNEEDED, ...)
-{ fprintf(stderr, "param_check called!\n"); abort(); }
-/* Generated stub for send_backtrace */
-void send_backtrace(const char *why UNNEEDED)
-{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
-/* AUTOGENERATED MOCKS END */
-
-static char *tmp_dsn(const tal_t *ctx)
-{
- char *dsn, *filename;
- int fd = tmpdir_mkstemp(ctx, "lacct-db-XXXXXX", &filename);
- if (fd == -1)
- return NULL;
- close(fd);
-
- dsn = tal_fmt(NULL, "sqlite3://%s", filename);
- tal_free(filename);
-
- return dsn;
-}
-
-static struct db *create_test_db(void)
-{
- struct db *db;
- char *dsn;
-
- dsn = tmp_dsn(NULL);
- db = db_open(NULL, dsn, true, db_error, (struct plugin *)NULL);
- db->data_version = 0;
- db->report_changes_fn = NULL;
-
- tal_free(dsn);
- return db;
-}
-
-static bool test_db_migrate(struct plugin *plugin)
-{
- struct db *db = create_test_db();
-
- CHECK(db);
- db_begin_transaction(db);
- CHECK(db_get_version(db) == -1);
- CHECK(db_migrate(plugin, db) == true);
- db_commit_transaction(db);
-
- db_begin_transaction(db);
- CHECK(db_get_version(db) == ARRAY_SIZE(db_migrations) - 1);
- db_commit_transaction(db);
-
- db_begin_transaction(db);
- CHECK(db_migrate(plugin, db) == false);
- db_commit_transaction(db);
-
- tal_free(db);
- return true;
-}
-
-int main(int argc, char *argv[])
-{
- bool ok = true;
- /* Dummy for migration hooks */
- struct plugin *plugin = tal(NULL, struct plugin);
- list_head_init(&plugin->js_list);
-
- common_setup(argv[0]);
-
- if (HAVE_SQLITE3) {
- ok &= test_db_migrate(plugin);
- }
-
- tal_free(plugin);
- common_shutdown();
- trace_cleanup();
- return !ok;
-}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.