From e778ebb9af5a6157a4b605a77f87b2c48b9d03b0 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 6 Dec 2022 11:19:16 +1030 Subject: [PATCH] wallet: only log broken if we have duplicate scids in channels. This was reported, but the channel was closed. So however we ended up with a duplicate, we're no *worse* off than we were before migration? Fixes: #5760 Signed-off-by: Rusty Russell --- wallet/db.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wallet/db.c b/wallet/db.c index 6b39a4405..5286d8cc1 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -1486,6 +1486,7 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld, { struct db_stmt *stmt; char **scids = tal_arr(tmpctx, char *, 0); + size_t changes; stmt = db_prepare_v2(db, SQL("SELECT short_channel_id FROM channels")); db_query_prepared(stmt); @@ -1497,6 +1498,7 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld, } tal_free(stmt); + changes = 0; for (size_t i = 0; i < tal_count(scids); i++) { struct short_channel_id scid; if (!short_channel_id_from_str(scids[i], strlen(scids[i]), &scid)) @@ -1509,12 +1511,21 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld, db_bind_scid(stmt, 0, &scid); db_bind_text(stmt, 1, scids[i]); db_exec_prepared_v2(stmt); + + /* This was reported to happen with an (old, closed) channel: that we'd have + * more than one change here! That's weird, but just log about it. */ if (db_count_changes(stmt) != 1) - db_fatal("Converting channels.short_channel_id '%s' gave %zu changes != 1?", - scids[i], db_count_changes(stmt)); + log_broken(ld->log, + "migrate_channels_scids_as_integers: converting channels.short_channel_id '%s' gave %zu changes != 1!", + scids[i], db_count_changes(stmt)); + changes += db_count_changes(stmt); tal_free(stmt); } + if (changes != tal_count(scids)) + fatal("migrate_channels_scids_as_integers: only converted %zu of %zu scids!", + changes, tal_count(scids)); + /* FIXME: We cannot use ->delete_columns to remove * short_channel_id, as other tables reference the channels * (and sqlite3 has them referencing a now-deleted table!).