Skip to content

Commit e778ebb

Browse files
rustyrussellcdecker
authored andcommitted
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 <[email protected]>
1 parent 37590ee commit e778ebb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

wallet/db.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,7 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld,
14861486
{
14871487
struct db_stmt *stmt;
14881488
char **scids = tal_arr(tmpctx, char *, 0);
1489+
size_t changes;
14891490

14901491
stmt = db_prepare_v2(db, SQL("SELECT short_channel_id FROM channels"));
14911492
db_query_prepared(stmt);
@@ -1497,6 +1498,7 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld,
14971498
}
14981499
tal_free(stmt);
14991500

1501+
changes = 0;
15001502
for (size_t i = 0; i < tal_count(scids); i++) {
15011503
struct short_channel_id scid;
15021504
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,
15091511
db_bind_scid(stmt, 0, &scid);
15101512
db_bind_text(stmt, 1, scids[i]);
15111513
db_exec_prepared_v2(stmt);
1514+
1515+
/* This was reported to happen with an (old, closed) channel: that we'd have
1516+
* more than one change here! That's weird, but just log about it. */
15121517
if (db_count_changes(stmt) != 1)
1513-
db_fatal("Converting channels.short_channel_id '%s' gave %zu changes != 1?",
1514-
scids[i], db_count_changes(stmt));
1518+
log_broken(ld->log,
1519+
"migrate_channels_scids_as_integers: converting channels.short_channel_id '%s' gave %zu changes != 1!",
1520+
scids[i], db_count_changes(stmt));
1521+
changes += db_count_changes(stmt);
15151522
tal_free(stmt);
15161523
}
15171524

1525+
if (changes != tal_count(scids))
1526+
fatal("migrate_channels_scids_as_integers: only converted %zu of %zu scids!",
1527+
changes, tal_count(scids));
1528+
15181529
/* FIXME: We cannot use ->delete_columns to remove
15191530
* short_channel_id, as other tables reference the channels
15201531
* (and sqlite3 has them referencing a now-deleted table!).

0 commit comments

Comments
 (0)