bkpr: remove unused "account_exits" parameter to account_get_balance().
What changed, and why it matters
This is a small code cleanup in the bookkeeper plugin. It removes an unused 'account_exists' flag from a helper function that looks up account balances. The flag was only used in tests, so the change simplifies the code without altering real behavior.
No security action needed. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors account_get_balance() in plugins/bkpr/recorder.c to drop the bool *account_exists output parameter. All production callers passed NULL for this parameter; only the unit test in run-recorder.c used it, and those assertions are removed. The function still queries the database and returns balances exactly as before. No functional or security-relevant change is present.
Changed components
plugins/bkpr/bookkeeper.cplugins/bkpr/recorder.cplugins/bkpr/recorder.hplugins/bkpr/test/run-recorder.cInspect captured patch +10 / −22
diff --git a/plugins/bkpr/bookkeeper.c b/plugins/bkpr/bookkeeper.c
index 01999b02..3747f49d 100644
--- a/plugins/bkpr/bookkeeper.c
+++ b/plugins/bkpr/bookkeeper.c
@@ -573,8 +573,7 @@ static struct command_result *json_list_balances(struct command *cmd,
err = account_get_balance(cmd, db,
accts[i]->name,
true,
- &balances,
- NULL);
+ &balances);
if (err)
plugin_err(cmd->plugin,
@@ -968,7 +967,7 @@ static struct command_result *listpeerchannels_multi_done(struct command *cmd,
db_begin_transaction(db);
err = account_get_balance(tmpctx, db, info->acct->name,
- false, &balances, NULL);
+ false, &balances);
db_commit_transaction(db);
if (err)
@@ -1105,8 +1104,7 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
err = account_get_balance(cmd, db, acct_name,
/* Don't error if negative */
false,
- &balances,
- NULL);
+ &balances);
if (err)
plugin_err(cmd->plugin,
@@ -1410,7 +1408,7 @@ listpeerchannels_done(struct command *cmd,
info->ev->timestamp)) {
db_begin_transaction(db);
err = account_get_balance(tmpctx, db, info->acct->name,
- false, &balances, NULL);
+ false, &balances);
db_commit_transaction(db);
if (err)
diff --git a/plugins/bkpr/recorder.c b/plugins/bkpr/recorder.c
index 077cfd09..18c84094 100644
--- a/plugins/bkpr/recorder.c
+++ b/plugins/bkpr/recorder.c
@@ -921,8 +921,7 @@ char *account_get_balance(const tal_t *ctx,
struct db *db,
const char *acct_name,
bool calc_sum,
- struct acct_balance ***balances,
- bool *account_exists)
+ struct acct_balance ***balances)
{
struct db_stmt *stmt;
@@ -939,8 +938,6 @@ char *account_get_balance(const tal_t *ctx,
db_bind_text(stmt, acct_name);
db_query_prepared(stmt);
*balances = tal_arr(ctx, struct acct_balance *, 0);
- if (account_exists)
- *account_exists = false;
while (db_step(stmt)) {
struct acct_balance *bal;
@@ -951,9 +948,6 @@ char *account_get_balance(const tal_t *ctx,
bal->credit = db_col_amount_msat(stmt, "credit");
bal->debit = db_col_amount_msat(stmt, "debit");
tal_arr_expand(balances, bal);
-
- if (account_exists)
- *account_exists = true;
}
tal_free(stmt);
diff --git a/plugins/bkpr/recorder.h b/plugins/bkpr/recorder.h
index 068064bb..596ef355 100644
--- a/plugins/bkpr/recorder.h
+++ b/plugins/bkpr/recorder.h
@@ -124,8 +124,7 @@ char *account_get_balance(const tal_t *ctx,
struct db *db,
const char *acct_name,
bool calc_sum,
- struct acct_balance ***balances,
- bool *account_exists);
+ struct acct_balance ***balances);
/* Get chain fees for account */
struct onchain_fee **account_get_chain_fees(const tal_t *ctx, struct db *db,
diff --git a/plugins/bkpr/test/run-recorder.c b/plugins/bkpr/test/run-recorder.c
index ec5aa8b8..bea42719 100644
--- a/plugins/bkpr/test/run-recorder.c
+++ b/plugins/bkpr/test/run-recorder.c
@@ -1192,7 +1192,6 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
struct account *acct, *acct2;
struct chain_event *ev1;
struct acct_balance **balances;
- bool exists;
char *err;
memset(&peer_id, 3, sizeof(struct node_id));
@@ -1203,10 +1202,9 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
db_begin_transaction(db);
/* Check that account does not exist yet */
err = account_get_balance(ctx, db, acct->name, true,
- &balances, &exists);
+ &balances);
CHECK(!err);
- CHECK_MSG(!exists, "expected account not to exist");
account_add(db, acct);
account_add(db, acct2);
@@ -1253,7 +1251,7 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
log_chain_event(db, acct2, ev1);
err = account_get_balance(ctx, db, acct->name, true,
- &balances, NULL);
+ &balances);
CHECK_MSG(!err, err);
db_commit_transaction(db);
@@ -1275,13 +1273,12 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
log_chain_event(db, acct, ev1);
err = account_get_balance(ctx, db, acct->name, true,
- &balances, &exists);
+ &balances);
CHECK_MSG(err != NULL, "Expected err message");
CHECK(streq(err, "chf channel balance is negative? 5000msat - 5001msat"));
- CHECK_MSG(exists, "expected account to exist");
err = account_get_balance(ctx, db, acct->name, false,
- &balances, NULL);
+ &balances);
CHECK_MSG(!err, err);
db_commit_transaction(db);
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.