tools: delete gossip_store of needed for downgrade even if db hasn't changed.
What changed, and why it matters
This is a small bug-fix in a downgrade helper tool. Previously, the tool only deleted an incompatible gossip data file when the database actually needed changes. Now it deletes that file even if the database is already compatible, preventing a scenario where downgrading leaves behind a gossip file that the older version cannot read. It is a correctness fix, not an exploitable security vulnerability.
No security action required; treat as normal maintenance/correctness patch.
Security signals we found
No security-relevant signals in commit message or diff
Change is a functional correctness fix in a maintenance tool
No input validation, memory safety, or cryptographic changes
Evidence from the diff
The commit moves the gossip_store deletion logic in tools/lightning-downgrade.c so it runs before the database is opened and before the early-exit path for ‘already compatible’ versions. The test is relaxed from a prefix check to a substring check for the ‘Already compatible with’ message. This ensures an incompatible gossip_store is removed even when no DB migration is required.
Changed components
tools/lightning-downgrade.ctests/test_downgrade.pyInspect captured patch +7 / −6
diff --git a/tests/test_downgrade.py b/tests/test_downgrade.py
index 1d8dcc8..2e0062e 100644
--- a/tests/test_downgrade.py
+++ b/tests/test_downgrade.py
@@ -80,7 +80,7 @@ def test_downgrade(node_factory, executor):
l1.daemon.executable = current_executable
# Another downgrade is a noop.
- assert subprocess.check_output(cmd_line).decode("utf8").startswith("Already compatible with ")
+ assert "Already compatible with " in subprocess.check_output(cmd_line).decode("utf8")
# Should be able to upgrade without any trouble
l1.daemon.opts['database-upgrade'] = True
diff --git a/tools/lightning-downgrade.c b/tools/lightning-downgrade.c
index 3bf41c6..2c76bf7 100644
--- a/tools/lightning-downgrade.c
+++ b/tools/lightning-downgrade.c
@@ -239,6 +239,12 @@ int main(int argc, char *argv[])
migrations = get_db_migrations(&num_migrations);
prev_version = version_db(PREV_VERSION);
+ /* Do this even if the db hasn't changed. */
+ if (!version_db(PREV_VERSION)->gossip_store_compatible) {
+ printf("Deleting incompatible gossip_store\n");
+ unlink(path_join(tmpctx, net_dir, "gossip_store"));
+ }
+
/* Open db, check it's the expected version */
db = db_open(tmpctx, wallet_dsn, false, false, db_error, NULL);
if (!db)
@@ -290,11 +296,6 @@ int main(int argc, char *argv[])
printf("Downgrade to %s succeeded. Committing.\n", PREV_VERSION);
db_commit_transaction(db);
tal_free(db);
-
- if (!version_db(PREV_VERSION)->gossip_store_compatible) {
- printf("Deleting incompatible gossip_store\n");
- unlink(path_join(tmpctx, net_dir, "gossip_store"));
- }
}
/*** We don't actually perform migrations, so these are stubs which abort. ***/
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.