From 712595f0d269dc76f3a7b9a8bddc4f6354e8335f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 21 Oct 2019 09:10:24 +0200 Subject: [PATCH] db: Wire in the logs into the database so we can give feedback --- wallet/db.c | 9 +++++---- wallet/db_common.h | 2 ++ wallet/test/run-db.c | 4 ++-- wallet/test/run-wallet.c | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index d6591a68e..91745b604 100644 --- a/wallet/db.c +++ b/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; } diff --git a/wallet/db_common.h b/wallet/db_common.h index 03ef9a345..95532916c 100644 --- a/wallet/db_common.h +++ b/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 { diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index 80a2b8815..e2ff7a864 100644 --- a/wallet/test/run-db.c +++ b/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 */ diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index d24235ba9..953e157af 100644 --- a/wallet/test/run-wallet.c +++ b/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;