bkpr: insert obscure 60s pop references.

The initial snapshots on an already-running lightningd are expected to
be unbalanced, but this shouldn't cause users to long for the green,
green grass of home.

This controls the Art of Noise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-08-01 09:55:05 +09:30 committed by neil saitug
parent 3445882ee4
commit 2971b2af79
7 changed files with 43 additions and 20 deletions

View file

@ -290,7 +290,7 @@ void db_prepare_for_changes(struct db *db)
db->changes = tal_arr(db, const char *, 0);
}
struct db *db_open(const tal_t *ctx, char *filename)
struct db *db_open(const tal_t *ctx, const char *filename)
{
struct db *db;

View file

@ -80,7 +80,7 @@ struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
/**
* db_open - Open or create a database
*/
struct db *db_open(const tal_t *ctx, char *filename);
struct db *db_open(const tal_t *ctx, const char *filename);
/**
* Report a statement that changes the wallet

View file

@ -36,6 +36,7 @@ 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)
@ -1061,7 +1062,9 @@ static struct command_result *json_balance_snapshot(struct command *cmd,
struct channel_event *ev;
u64 timestamp;
plugin_log(cmd->plugin, LOG_UNUSUAL,
/* This is *expected* on first run of bookkeeper! */
plugin_log(cmd->plugin,
tom_jones ? LOG_DBG : LOG_UNUSUAL,
"Snapshot balance does not equal ondisk"
" reported %s, off by (+%s/-%s) (account %s)"
" Logging journal entry.",
@ -1838,7 +1841,8 @@ 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);
db = notleak(db_setup(p, p, db_dsn));
/* Final flag tells us What's New, Pussycat. */
db = notleak(db_setup(p, p, db_dsn, &tom_jones));
db_dsn = tal_free(db_dsn);
return NULL;

View file

@ -100,7 +100,7 @@ static struct migration db_migrations[] = {
{SQL("ALTER TABLE channel_events ADD ev_desc TEXT DEFAULT NULL;"), NULL},
};
static bool db_migrate(struct plugin *p, struct db *db)
static bool db_migrate(struct plugin *p, struct db *db, bool *created)
{
/* Read current version from database */
int current, orig, available;
@ -109,9 +109,11 @@ static bool db_migrate(struct plugin *p, struct db *db)
orig = current = db_get_version(db);
available = ARRAY_SIZE(db_migrations) - 1;
if (current == -1)
*created = false;
if (current == -1) {
*created = true;
plugin_log(p, LOG_INFORM, "Creating database");
else if (available < current)
} else if (available < current)
plugin_err(p,
"Refusing to migrate down from version %u to %u",
current, available);
@ -154,7 +156,8 @@ void db_fatal(const char *fmt, ...)
}
#endif /* DB_FATAL */
struct db *db_setup(const tal_t *ctx, struct plugin *p, char *db_dsn)
struct db *db_setup(const tal_t *ctx, struct plugin *p,
const char *db_dsn, bool *created)
{
bool migrated;
struct db *db;
@ -165,7 +168,7 @@ struct db *db_setup(const tal_t *ctx, struct plugin *p, char *db_dsn)
db->report_changes_fn = NULL;
db_begin_transaction(db);
migrated = db_migrate(p, db);
migrated = db_migrate(p, db, created);
db->data_version = db_data_version_get(db);
db_commit_transaction(db);

View file

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

View file

@ -258,19 +258,27 @@ static struct db *create_test_db(void)
return db;
}
static bool test_empty_db_migrate(struct plugin *plugin)
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);
db_migrate(plugin, db);
CHECK(db_migrate(plugin, db, &created) == true);
CHECK(created);
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, &created) == false);
CHECK(!created);
db_commit_transaction(db);
tal_free(db);
return true;
}
@ -284,7 +292,7 @@ int main(int argc, char *argv[])
common_setup(argv[0]);
ok &= test_empty_db_migrate(plugin);
ok &= test_db_migrate(plugin);
tal_free(plugin);
common_shutdown();

View file

@ -393,7 +393,8 @@ 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)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id node_id, peer_id;
struct account *wal_acct, *ext_acct;
struct bitcoin_txid txid;
@ -470,7 +471,8 @@ 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)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id node_id, peer_id;
struct account *acct, *wal_acct, *ext_acct;
struct onchain_fee **ofs, **ofs1;
@ -744,7 +746,8 @@ 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)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id node_id, peer_id;
struct account *acct, *acct2, *wal_acct, *ext_acct;
struct bitcoin_txid txid;
@ -868,7 +871,8 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx, struct plugin *p)
static bool test_channel_event_crud(const tal_t *ctx, struct plugin *p)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id peer_id;
struct account *acct, *acct2;
struct channel_event *ev1, *ev2, *ev3, **chan_evs;
@ -954,7 +958,8 @@ 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)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id peer_id;
struct account *acct, *acct2;
struct chain_event *ev1, *ev2, *ev3, **chain_evs;
@ -1088,7 +1093,8 @@ 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)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id peer_id;
struct account *acct, *acct2;
struct chain_event *ev1;
@ -1193,7 +1199,8 @@ static bool test_account_balances(const tal_t *ctx, struct plugin *p)
static bool test_account_crud(const tal_t *ctx, struct plugin *p)
{
struct db *db = db_setup(ctx, p, tmp_dsn(ctx));
bool created;
struct db *db = db_setup(ctx, p, tmp_dsn(ctx), &created);
struct node_id *peer_id;
struct account *acct, *acct2, **acct_list;
struct chain_event *ev1;