mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 16:14:23 +01:00
lightningd: migrate (and delete) old commando blacklists.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
BIN
tests/data/commando_blacklist.sqlite3.xz
Normal file
BIN
tests/data/commando_blacklist.sqlite3.xz
Normal file
Binary file not shown.
@@ -449,3 +449,22 @@ def test_commando_rune_migration(node_factory):
|
||||
'geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==',
|
||||
'unique_id': '1', 'restrictions':
|
||||
[], '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}]}
|
||||
|
||||
@@ -5672,6 +5672,7 @@ void migrate_datastore_commando_runes(struct lightningd *ld, struct db *db)
|
||||
struct db_stmt *stmt;
|
||||
const char **startkey, **k;
|
||||
const u8 *data;
|
||||
size_t max;
|
||||
|
||||
/* datastore routines expect a tal_arr */
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user