Skip to content

Commit 712595f

Browse files
cdeckerniftynei
authored andcommitted
db: Wire in the logs into the database so we can give feedback
1 parent f5e4a30 commit 712595f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

wallet/db.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ static int db_get_version(struct db *db)
772772
/**
773773
* db_migrate - Apply all remaining migrations from the current version
774774
*/
775-
static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
775+
static void db_migrate(struct lightningd *ld, struct db *db)
776776
{
777777
/* Attempt to read the version from the database */
778778
int current, orig, available;
@@ -784,12 +784,12 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
784784
available = ARRAY_SIZE(dbmigrations) - 1;
785785

786786
if (current == -1)
787-
log_info(log, "Creating database");
787+
log_info(db->log, "Creating database");
788788
else if (available < current)
789789
db_fatal("Refusing to migrate down from version %u to %u",
790790
current, available);
791791
else if (current != available)
792-
log_info(log, "Updating database from version %u to %u",
792+
log_info(db->log, "Updating database from version %u to %u",
793793
current, available);
794794

795795
while (current < available) {
@@ -826,7 +826,8 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
826826
struct db *db_setup(const tal_t *ctx, struct lightningd *ld, struct log *log)
827827
{
828828
struct db *db = db_open(ctx, ld->wallet_dsn);
829-
db_migrate(ld, db, log);
829+
db->log = log;
830+
db_migrate(ld, db);
830831
return db;
831832
}
832833

wallet/db_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct db {
2828
/* List of statements that have been created but not executed yet. */
2929
struct list_head pending_statements;
3030
char *error;
31+
32+
struct log *log;
3133
};
3234

3335
struct db_query {

wallet/test/run-db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static bool test_empty_db_migrate(struct lightningd *ld)
6969
db_begin_transaction(db);
7070
CHECK(db_get_version(db) == -1);
7171
db_commit_transaction(db);
72-
db_migrate(ld, db, NULL);
72+
db_migrate(ld, db);
7373
db_begin_transaction(db);
7474
CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1);
7575
db_commit_transaction(db);
@@ -113,7 +113,7 @@ static bool test_vars(struct lightningd *ld)
113113
struct db *db = create_test_db();
114114
char *varname = "testvar";
115115
CHECK(db);
116-
db_migrate(ld, db, NULL);
116+
db_migrate(ld, db);
117117

118118
db_begin_transaction(db);
119119
/* Check default behavior */

wallet/test/run-wallet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
772772
w->bip32_base) == WALLY_OK);
773773

774774
CHECK_MSG(w->db, "Failed opening the db");
775-
db_migrate(ld, w->db, w->log);
775+
db_migrate(ld, w->db);
776776
CHECK_MSG(!wallet_err, "DB migration failed");
777777
w->max_channel_dbid = 0;
778778

0 commit comments

Comments
 (0)