Skip to content

Commit

Permalink
wallet: only log broken if we have duplicate scids in channels.
Browse files Browse the repository at this point in the history
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: ElementsProject#5760
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and ddustin committed Apr 11, 2023
1 parent f771c8d commit a7d01d8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
Expand All @@ -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!).
Expand Down

0 comments on commit a7d01d8

Please sign in to comment.