Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
1eb7e92a30
  1. 6
      wallet/db.c

6
wallet/db.c

@ -366,14 +366,16 @@ static int db_migration_count(void)
static bool db_migrate(struct db *db) static bool db_migrate(struct db *db)
{ {
/* Attempt to read the version from the database */ /* Attempt to read the version from the database */
int current = db_get_version(db); int current, available;
int available = db_migration_count();
if (!db_begin_transaction(db)) { if (!db_begin_transaction(db)) {
/* No need to rollback, we didn't even start... */ /* No need to rollback, we didn't even start... */
return false; return false;
} }
current = db_get_version(db);
available = db_migration_count();
while (++current <= available) { while (++current <= available) {
if (!db_exec(__func__, db, "%s", dbmigrations[current])) if (!db_exec(__func__, db, "%s", dbmigrations[current]))
goto fail; goto fail;

Loading…
Cancel
Save