mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
wallet: add list of upgrades.
Useful for debugging a db. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -1047,6 +1047,29 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
wait_forget_channels(l1)
|
wait_forget_channels(l1)
|
||||||
wait_forget_channels(l2)
|
wait_forget_channels(l2)
|
||||||
|
|
||||||
|
def test_db_upgrade(self):
|
||||||
|
l1 = self.node_factory.get_node()
|
||||||
|
l1.stop()
|
||||||
|
|
||||||
|
version = subprocess.check_output(['lightningd/lightningd',
|
||||||
|
'--version']).decode('utf-8').splitlines()[0]
|
||||||
|
|
||||||
|
upgrades = l1.db_query("SELECT * from db_upgrades;")
|
||||||
|
assert len(upgrades) == 1
|
||||||
|
assert(upgrades[0]['upgrade_from'] == -1)
|
||||||
|
assert(upgrades[0]['lightning_version'] == version)
|
||||||
|
|
||||||
|
# Try resetting to earlier db state.
|
||||||
|
os.unlink(os.path.join(l1.daemon.lightning_dir, "lightningd.sqlite3"))
|
||||||
|
l1.db_manip("CREATE TABLE version (version INTEGER);")
|
||||||
|
l1.db_manip("INSERT INTO version VALUES (1);")
|
||||||
|
|
||||||
|
l1.daemon.start()
|
||||||
|
upgrades = l1.db_query("SELECT * from db_upgrades;")
|
||||||
|
assert len(upgrades) == 1
|
||||||
|
assert(upgrades[0]['upgrade_from'] == 1)
|
||||||
|
assert(upgrades[0]['lightning_version'] == version)
|
||||||
|
|
||||||
def test_closing_different_fees(self):
|
def test_closing_different_fees(self):
|
||||||
l1 = self.node_factory.get_node()
|
l1 = self.node_factory.get_node()
|
||||||
|
|
||||||
|
|||||||
@@ -365,6 +365,16 @@ class LightningNode(object):
|
|||||||
db.close()
|
db.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# Assumes node is stopped!
|
||||||
|
def db_manip(self, query):
|
||||||
|
db = sqlite3.connect(os.path.join(self.daemon.lightning_dir, "lightningd.sqlite3"))
|
||||||
|
db.row_factory = sqlite3.Row
|
||||||
|
c = db.cursor()
|
||||||
|
c.execute(query)
|
||||||
|
db.commit()
|
||||||
|
c.close()
|
||||||
|
db.close()
|
||||||
|
|
||||||
def stop(self, timeout=10):
|
def stop(self, timeout=10):
|
||||||
""" Attempt to do a clean shutdown, but kill if it hangs
|
""" Attempt to do a clean shutdown, but kill if it hangs
|
||||||
"""
|
"""
|
||||||
|
|||||||
13
wallet/db.c
13
wallet/db.c
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
|
#include <common/version.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
@@ -193,6 +194,8 @@ char *dbmigrations[] = {
|
|||||||
"CREATE INDEX channel_idx ON htlc_sigs (channelid)",
|
"CREATE INDEX channel_idx ON htlc_sigs (channelid)",
|
||||||
/* Get rid of OPENINGD entries; we don't put them in db any more */
|
/* Get rid of OPENINGD entries; we don't put them in db any more */
|
||||||
"DELETE FROM channels WHERE state=1",
|
"DELETE FROM channels WHERE state=1",
|
||||||
|
/* Keep track of db ugprades, for debugging */
|
||||||
|
"CREATE TABLE db_upgrades (upgrade_from INTEGER, lightning_version TEXT);",
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -386,11 +389,11 @@ static int db_migration_count(void)
|
|||||||
static void db_migrate(struct db *db, struct log *log)
|
static void db_migrate(struct db *db, struct log *log)
|
||||||
{
|
{
|
||||||
/* Attempt to read the version from the database */
|
/* Attempt to read the version from the database */
|
||||||
int current, available;
|
int current, orig, available;
|
||||||
|
|
||||||
db_begin_transaction(db);
|
db_begin_transaction(db);
|
||||||
|
|
||||||
current = db_get_version(db);
|
orig = current = db_get_version(db);
|
||||||
available = db_migration_count();
|
available = db_migration_count();
|
||||||
|
|
||||||
if (current == -1)
|
if (current == -1)
|
||||||
@@ -408,6 +411,12 @@ static void db_migrate(struct db *db, struct log *log)
|
|||||||
/* Finally update the version number in the version table */
|
/* Finally update the version number in the version table */
|
||||||
db_exec(__func__, db, "UPDATE version SET version=%d;", available);
|
db_exec(__func__, db, "UPDATE version SET version=%d;", available);
|
||||||
|
|
||||||
|
/* Annotate that we did upgrade, if any. */
|
||||||
|
if (current != orig)
|
||||||
|
db_exec(__func__, db,
|
||||||
|
"INSERT INTO db_upgrades VALUES (%i, '%s');",
|
||||||
|
orig, version());
|
||||||
|
|
||||||
db_commit_transaction(db);
|
db_commit_transaction(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ WALLET_TEST_COMMON_OBJS := \
|
|||||||
common/timeout.o \
|
common/timeout.o \
|
||||||
common/utils.o \
|
common/utils.o \
|
||||||
common/wireaddr.o \
|
common/wireaddr.o \
|
||||||
|
common/version.o \
|
||||||
wire/towire.o \
|
wire/towire.o \
|
||||||
wire/fromwire.o
|
wire/fromwire.o
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user