fix(remote-externalities): child trie not loaded (#14365)

* fix remote-ext chlid keys

* sanity check test that child trie is loaded
This commit is contained in:
Liam Aharon
2023-06-22 00:16:33 +10:00
committed by GitHub
parent 321a52bb27
commit 38cc4ad6aa
@@ -541,7 +541,6 @@ where
.rpc_get_keys_paged(prefix.clone(), at)
.await?
.into_iter()
.filter(|k| !is_default_child_storage_key(&k.0))
.collect::<Vec<_>>();
sp.stop_with_message(format!(
"✅ Found {} keys ({:.2}s)",
@@ -609,7 +608,14 @@ where
let mut sp = Spinner::with_timer(Spinners::Dots, "Inserting keys into DB...".into());
let start = Instant::now();
pending_ext.batch_insert(key_values.clone().into_iter().map(|(k, v)| (k.0, v.0)));
pending_ext.batch_insert(key_values.clone().into_iter().filter_map(|(k, v)| {
// Don't insert the child keys here, they need to be inserted seperately with all their
// data in the load_child_remote function.
match is_default_child_storage_key(&k.0) {
true => None,
false => Some((k.0, v.0)),
}
}));
sp.stop_with_message(format!(
"✅ Inserted keys into DB ({:.2}s)",
start.elapsed().as_secs_f32()
@@ -727,6 +733,10 @@ where
.collect::<Vec<_>>();
if child_roots.is_empty() {
info!(
target: LOG_TARGET,
"👩‍👦 no child roots found to scrape",
);
return Ok(Default::default())
}
@@ -1190,6 +1200,42 @@ mod remote_tests {
assert_eq!(ext.block_hash, cached_ext.block_hash);
}
#[tokio::test]
async fn child_keys_are_loaded() {
const CACHE: &'static str = "snapshot_retains_storage";
init_logger();
// create an ext with children keys
let child_ext = Builder::<Block>::new()
.mode(Mode::Online(OnlineConfig {
pallets: vec!["Proxy".to_owned()],
child_trie: true,
state_snapshot: Some(SnapshotConfig::new(CACHE)),
..Default::default()
}))
.build()
.await
.unwrap();
// create an ext without children keys
let ext = Builder::<Block>::new()
.mode(Mode::Online(OnlineConfig {
pallets: vec!["Proxy".to_owned()],
child_trie: false,
state_snapshot: Some(SnapshotConfig::new(CACHE)),
..Default::default()
}))
.build()
.await
.unwrap();
// there should be more keys in the child ext.
assert!(
child_ext.as_backend().backend_storage().keys().len() >
ext.as_backend().backend_storage().keys().len()
);
}
#[tokio::test]
async fn offline_else_online_works() {
const CACHE: &'static str = "offline_else_online_works_data";