From 1eb7e92a30c6495ade5ccda96457bb2b29c0b132 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 1 Nov 2017 11:40:48 +1030 Subject: [PATCH] db_migrate: get version inside transaction. we should never be doing two startups at once, but why take chances? Plus, we can then assert that all db calls are in transactions. Signed-off-by: Rusty Russell --- wallet/db.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index f5cb2a9e6..1f50fc2a0 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -366,14 +366,16 @@ static int db_migration_count(void) static bool db_migrate(struct db *db) { /* Attempt to read the version from the database */ - int current = db_get_version(db); - int available = db_migration_count(); + int current, available; if (!db_begin_transaction(db)) { /* No need to rollback, we didn't even start... */ return false; } + current = db_get_version(db); + available = db_migration_count(); + while (++current <= available) { if (!db_exec(__func__, db, "%s", dbmigrations[current])) goto fail;