lightningd: migrate (and delete) old commando blacklists.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-25 12:44:38 +09:30
parent dccbccf8f2
commit 925f9fcce5
3 changed files with 40 additions and 0 deletions

Binary file not shown.

View File

@@ -449,3 +449,22 @@ def test_commando_rune_migration(node_factory):
'geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==', 'geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==',
'unique_id': '1', 'restrictions': 'unique_id': '1', 'restrictions':
[], 'restrictions_as_english': ''}]} [], 'restrictions_as_english': ''}]}
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "Depends on canned sqlite3 db")
@unittest.skipIf(TEST_NETWORK != 'regtest', 'canned sqlite3 db is regtest')
def test_commando_blacklist_migration(node_factory):
"""Test migration from commando's datastore using db from test_commando_blacklist"""
l1 = node_factory.get_node(dbfile='commando_blacklist.sqlite3.xz',
options={'database-upgrade': True})
# This happens really early in logs!
l1.daemon.logsearch_start = 0
l1.daemon.wait_for_logs(['Transferring commando blacklist to db: '] * 2)
# datastore should be empty:
assert l1.rpc.listdatastore(['commando', 'blacklist']) == {'datastore': []}
# Should match commando results!
assert l1.rpc.blacklistrune() == {'blacklist': [{'start': 0, 'end': 6},
{'start': 9, 'end': 9}]}

View File

@@ -5672,6 +5672,7 @@ void migrate_datastore_commando_runes(struct lightningd *ld, struct db *db)
struct db_stmt *stmt; struct db_stmt *stmt;
const char **startkey, **k; const char **startkey, **k;
const u8 *data; const u8 *data;
size_t max;
/* datastore routines expect a tal_arr */ /* datastore routines expect a tal_arr */
startkey = tal_arr(tmpctx, const char *, 2); startkey = tal_arr(tmpctx, const char *, 2);
@@ -5701,4 +5702,24 @@ void migrate_datastore_commando_runes(struct lightningd *ld, struct db *db)
} }
db_datastore_remove(db, k); db_datastore_remove(db, k);
} }
/* Now convert blacklist */
startkey[0] = "commando";
startkey[1] = "blacklist";
data = db_datastore_get(tmpctx, db, startkey, NULL);
max = tal_bytelen(data);
while (max) {
struct rune_blacklist b;
b.start = fromwire_u64(&data, &max);
b.end = fromwire_u64(&data, &max);
if (!data)
db_fatal(db, "Invalid commando blacklist?");
log_debug(ld->log, "Transferring commando blacklist to db: %"PRIu64"-%"PRIu64,
b.start, b.end);
db_insert_blacklist(db, &b);
}
db_datastore_remove(db, startkey);
} }