bkpr: now that we're not doing empty acct logging, we dont need this bool

We stopped doing empty journal logs, so we no longer need to switch
our log severity based on whether or not an account exists.

Should make bookkeeper less chatty and remove noisy logs

Changelog-None
This commit is contained in:
niftynei 2023-11-21 15:15:24 -06:00 committed by Rusty Russell
parent ec7044e78e
commit a4f92eac81
6 changed files with 38 additions and 35 deletions

View File

@ -36,7 +36,6 @@ static struct db *db ;
static char *db_dsn;
static char *datadir;
static bool tom_jones;
static struct fee_sum *find_sum_for_txid(struct fee_sum **sums,
struct bitcoin_txid *txid)
@ -1083,8 +1082,7 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
if (!amount_msat_zero(credit_diff) || !amount_msat_zero(debit_diff)) {
struct channel_event *ev;
plugin_log(cmd->plugin,
tom_jones ? LOG_DBG : LOG_UNUSUAL,
plugin_log(cmd->plugin, LOG_UNUSUAL,
"Snapshot balance does not equal ondisk"
" reported %s, off by (+%s/-%s) (account %s)"
" Logging journal entry.",
@ -1831,8 +1829,7 @@ static const char *init(struct plugin *p, const char *b, const jsmntok_t *t)
db_dsn = tal_fmt(NULL, "sqlite3://accounts.sqlite3");
plugin_log(p, LOG_DBG, "Setting up database at %s", db_dsn);
/* Final flag tells us What's New, Pussycat. */
db = notleak(db_setup(p, p, db_dsn, &tom_jones));
db = notleak(db_setup(p, p, db_dsn));
db_dsn = tal_free(db_dsn);
return NULL;

View File

@ -102,7 +102,7 @@ static struct migration db_migrations[] = {
{NULL, migration_remove_dupe_lease_fees}
};
static bool db_migrate(struct plugin *p, struct db *db, bool *created)
static bool db_migrate(struct plugin *p, struct db *db)
{
/* Read current version from database */
int current, orig, available;
@ -111,9 +111,7 @@ static bool db_migrate(struct plugin *p, struct db *db, bool *created)
orig = current = db_get_version(db);
available = ARRAY_SIZE(db_migrations) - 1;
*created = false;
if (current == -1) {
*created = true;
plugin_log(p, LOG_INFORM, "Creating database");
} else if (available < current)
plugin_err(p,
@ -194,8 +192,7 @@ static void db_error(struct plugin *plugin, bool fatal, const char *fmt, va_list
}
struct db *db_setup(const tal_t *ctx, struct plugin *p,
const char *db_dsn,
bool *created)
const char *db_dsn)
{
bool migrated;
struct db *db;
@ -204,7 +201,7 @@ struct db *db_setup(const tal_t *ctx, struct plugin *p,
db->report_changes_fn = NULL;
db_begin_transaction(db);
migrated = db_migrate(p, db, created);
migrated = db_migrate(p, db);
db->data_version = db_data_version_get(db);
db_commit_transaction(db);

View File

@ -6,7 +6,6 @@
struct plugin;
struct db;
struct db *db_setup(const tal_t *ctx, struct plugin *p, const char *db_dsn,
bool *created);
struct db *db_setup(const tal_t *ctx, struct plugin *p, const char *db_dsn);
#endif /* LIGHTNING_PLUGINS_BKPR_DB_H */

View File

@ -260,13 +260,11 @@ static struct db *create_test_db(void)
static bool test_db_migrate(struct plugin *plugin)
{
struct db *db = create_test_db();
bool created;
CHECK(db);
db_begin_transaction(db);
CHECK(db_get_version(db) == -1);
CHECK(db_migrate(plugin, db, &created) == true);
CHECK(created);
CHECK(db_migrate(plugin, db) == true);
db_commit_transaction(db);
db_begin_transaction(db);
@ -274,8 +272,7 @@ static bool test_db_migrate(struct plugin *plugin)
db_commit_transaction(db);
db_begin_transaction(db);
CHECK(db_migrate(plugin, db, &created) == false);
CHECK(!created);
CHECK(db_migrate(plugin, db) == false);
db_commit_transaction(db);
tal_free(db);

View File

@ -398,8 +398,7 @@ static struct chain_event *make_chain_event(const tal_t *ctx,
static bool test_onchain_fee_wallet_spend(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id node_id, peer_id;
struct account *wal_acct, *ext_acct;
struct bitcoin_txid txid;
@ -474,8 +473,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx, struct plugin *p)
static bool test_onchain_fee_chan_close(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id node_id, peer_id;
struct account *acct, *wal_acct, *ext_acct;
struct onchain_fee **ofs, **ofs1;
@ -742,8 +740,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx, struct plugin *p)
static bool test_onchain_fee_chan_open(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id node_id, peer_id;
struct account *acct, *acct2, *wal_acct, *ext_acct;
struct bitcoin_txid txid;
@ -864,8 +861,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx, struct plugin *p)
static bool test_channel_rebalances(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct channel_event *ev1, *ev2, *ev3, **chan_evs;
struct rebalance **rebals;
struct account *acct1, *acct2, *acct3;
@ -948,8 +944,7 @@ static bool test_channel_rebalances(const tal_t *ctx, struct plugin *p)
static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id peer_id;
struct account *acct, *acct2;
struct channel_event *ev1, *ev2, *ev3, **chan_evs;
@ -1035,8 +1030,7 @@ static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p)
static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id peer_id;
struct account *acct, *acct2;
struct chain_event *ev1, *ev2, *ev3, **chain_evs;
@ -1164,8 +1158,7 @@ static bool test_chain_event_crud(const tal_t *ctx, struct plugin *p)
static bool test_account_balances(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id peer_id;
struct account *acct, *acct2;
struct chain_event *ev1;
@ -1278,8 +1271,7 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
static bool test_account_crud(const tal_t *ctx, struct plugin *p)
{
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
struct node_id *peer_id;
struct account *acct, *acct2, **acct_list;
struct chain_event *ev1;

View File

@ -1,6 +1,6 @@
from fixtures import * # noqa: F401,F403
from decimal import Decimal
from pyln.client import Millisatoshi
from pyln.client import Millisatoshi, RpcError
from db import Sqlite3Db
from fixtures import TEST_NETWORK
from utils import (
@ -668,6 +668,27 @@ def test_bookkeeping_descriptions(node_factory, bitcoind, chainparams):
assert l2_koinly_csv.find(bolt12_exp) >= 0
def test_empty_node(node_factory, bitcoind):
"""
Make sure that the bookkeeper commands don't blow up
on an empty accounts database.
"""
l1 = node_factory.get_node()
bkpr_cmds = [
('channelsapy', []),
('listaccountevents', []),
('listbalances', []),
('listincome', [])]
for cmd, params in bkpr_cmds:
l1.rpc.call('bkpr-' + cmd, params)
# inspect fails for non-channel accounts
# FIXME: implement for all accounts?
with pytest.raises(RpcError, match=r'not supported for non-channel accounts'):
l1.rpc.bkpr_inspect('wallet')
def test_rebalance_tracking(node_factory, bitcoind):
"""
We identify rebalances (invoices paid and received by our node),