Browse Source

db: Wire in the logs into the database so we can give feedback

travis-debug
Christian Decker 5 years ago
committed by neil saitug
parent
commit
712595f0d2
  1. 9
      wallet/db.c
  2. 2
      wallet/db_common.h
  3. 4
      wallet/test/run-db.c
  4. 2
      wallet/test/run-wallet.c

9
wallet/db.c

@ -772,7 +772,7 @@ static int db_get_version(struct db *db)
/**
* db_migrate - Apply all remaining migrations from the current version
*/
static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
static void db_migrate(struct lightningd *ld, struct db *db)
{
/* Attempt to read the version from the database */
int current, orig, available;
@ -784,12 +784,12 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
available = ARRAY_SIZE(dbmigrations) - 1;
if (current == -1)
log_info(log, "Creating database");
log_info(db->log, "Creating database");
else if (available < current)
db_fatal("Refusing to migrate down from version %u to %u",
current, available);
else if (current != available)
log_info(log, "Updating database from version %u to %u",
log_info(db->log, "Updating database from version %u to %u",
current, available);
while (current < available) {
@ -826,7 +826,8 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
struct db *db_setup(const tal_t *ctx, struct lightningd *ld, struct log *log)
{
struct db *db = db_open(ctx, ld->wallet_dsn);
db_migrate(ld, db, log);
db->log = log;
db_migrate(ld, db);
return db;
}

2
wallet/db_common.h

@ -28,6 +28,8 @@ struct db {
/* List of statements that have been created but not executed yet. */
struct list_head pending_statements;
char *error;
struct log *log;
};
struct db_query {

4
wallet/test/run-db.c

@ -69,7 +69,7 @@ static bool test_empty_db_migrate(struct lightningd *ld)
db_begin_transaction(db);
CHECK(db_get_version(db) == -1);
db_commit_transaction(db);
db_migrate(ld, db, NULL);
db_migrate(ld, db);
db_begin_transaction(db);
CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1);
db_commit_transaction(db);
@ -113,7 +113,7 @@ static bool test_vars(struct lightningd *ld)
struct db *db = create_test_db();
char *varname = "testvar";
CHECK(db);
db_migrate(ld, db, NULL);
db_migrate(ld, db);
db_begin_transaction(db);
/* Check default behavior */

2
wallet/test/run-wallet.c

@ -772,7 +772,7 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
w->bip32_base) == WALLY_OK);
CHECK_MSG(w->db, "Failed opening the db");
db_migrate(ld, w->db, w->log);
db_migrate(ld, w->db);
CHECK_MSG(!wallet_err, "DB migration failed");
w->max_channel_dbid = 0;

Loading…
Cancel
Save