Skip to content

Commit 04ba55d

Browse files
rustyrussellendothermicdev
authored andcommitted
wallet: fix incorrect channel_htlcs id migration.
We were supposed to initialize `last_htlcs_created_index` but a typo made us initialize `last_forwards_created_index` instead. Fix up the overwritten one, and actually initialize the one we were supposed to. Fixes: #8269 Fixes: #8270 Changelog-None: recently introduced bug Signed-off-by: Rusty Russell <[email protected]>
1 parent 1cc64dd commit 04ba55d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

tests/test_db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ def test_db_forward_migrate(bitcoind, node_factory):
521521
wait_for(lambda: l1.rpc.listforwards()['forwards'] == [])
522522

523523

524-
@pytest.mark.xfail(strict=True)
525524
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Canned db used")
526525
@unittest.skipIf(TEST_NETWORK != 'regtest', "The DB migration is network specific due to the chain var.")
527526
def test_channel_htlcs_id_change(bitcoind, node_factory):

wallet/db.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static void insert_addrtype_to_addresses(struct lightningd *ld,
8888
struct db *db);
8989
static void migrate_convert_old_channel_keyidx(struct lightningd *ld,
9090
struct db *db);
91-
static void migrate_initialize_channel_htlcs_wait_indexes(struct lightningd *ld,
92-
struct db *db);
91+
static void migrate_initialize_channel_htlcs_wait_indexes_and_fixup_forwards(struct lightningd *ld,
92+
struct db *db);
9393

9494
/* Do not reorder or remove elements from this array, it is used to
9595
* migrate existing databases from a previous state, based on the
@@ -1039,8 +1039,9 @@ static struct migration dbmigrations[] = {
10391039
" VALUES('needs_p2wpkh_close_rescan', 1)"), NULL},
10401040
{SQL("ALTER TABLE channel_htlcs ADD updated_index BIGINT DEFAULT 0"), NULL},
10411041
{SQL("CREATE INDEX channel_htlcs_updated_idx ON channel_htlcs (updated_index)"), NULL},
1042-
{NULL, migrate_initialize_channel_htlcs_wait_indexes},
1042+
{NULL, NULL}, /* Old, incorrect channel_htlcs_wait_indexes migration */
10431043
{SQL("ALTER TABLE channel_funding_inflights ADD locked_scid BIGINT DEFAULT 0;"), NULL},
1044+
{NULL, migrate_initialize_channel_htlcs_wait_indexes_and_fixup_forwards},
10441045
};
10451046

10461047
/**
@@ -1856,14 +1857,17 @@ static void migrate_initialize_forwards_wait_indexes(struct lightningd *ld,
18561857
"MAX(rowid)");
18571858
}
18581859

1859-
static void migrate_initialize_channel_htlcs_wait_indexes(struct lightningd *ld,
1860-
struct db *db)
1860+
static void migrate_initialize_channel_htlcs_wait_indexes_and_fixup_forwards(struct lightningd *ld,
1861+
struct db *db)
18611862
{
1863+
/* A previous badly-written migration (now NULL-ed out) set
1864+
* the forwards, not htlc index! Set the htlcs migration, and fixup forwards. */
18621865
migrate_initialize_wait_indexes(db,
1863-
WAIT_SUBSYSTEM_FORWARD,
1866+
WAIT_SUBSYSTEM_HTLCS,
18641867
WAIT_INDEX_CREATED,
18651868
SQL("SELECT MAX(id) FROM channel_htlcs;"),
18661869
"MAX(id)");
1870+
migrate_initialize_forwards_wait_indexes(ld, db);
18671871
}
18681872

18691873
static void complain_unfixed(struct lightningd *ld,

0 commit comments

Comments
 (0)