Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1d49362

Browse files
committed
Revert "use overlayedchanges"
This reverts commit c0ddb87.
1 parent c0ddb87 commit 1d49362

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

primitives/state-machine/src/overlayed_changes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl OverlayedChanges {
276276
/// `None` can be used to delete a value specified by the given key.
277277
///
278278
/// Can be rolled back or committed when called inside a transaction.
279-
pub fn set_child_storage(
279+
pub(crate) fn set_child_storage(
280280
&mut self,
281281
child_info: &ChildInfo,
282282
key: StorageKey,

primitives/state-machine/src/testing.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,7 @@ where
117117
}
118118
}
119119

120-
/// Returns a mutable reference to the overlayed changes.
121-
pub fn overlayed_changes_mut(&mut self) -> &mut OverlayedChanges {
122-
&mut self.overlay
123-
}
124-
125-
/// Returns an immutable reference to the overlayed changes.
120+
/// Returns the overlayed changes.
126121
pub fn overlayed_changes(&self) -> &OverlayedChanges {
127122
&self.overlay
128123
}

utils/frame/remote-externalities/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ codec = { package = "parity-scale-codec", version = "3.2.2" }
1717
log = "0.4.17"
1818
serde = "1.0.136"
1919
frame-support = { version = "4.0.0-dev", optional = true, path = "../../../frame/support" }
20-
sp-state-machine = { version = "0.13.0", path = "../../../primitives/state-machine" }
2120
sp-core = { version = "7.0.0", path = "../../../primitives/core" }
2221
sp-io = { version = "7.0.0", path = "../../../primitives/io" }
2322
sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" }

utils/frame/remote-externalities/src/lib.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use sp_core::{
3939
};
4040
pub use sp_io::TestExternalities;
4141
use sp_runtime::{traits::Block as BlockT, StateVersion};
42-
use sp_state_machine::OverlayedChanges;
4342
use spinners::{Spinner, Spinners};
4443
use std::{
4544
cmp::max,
@@ -521,7 +520,7 @@ where
521520
&self,
522521
prefix: StorageKey,
523522
at: B::Hash,
524-
ext_overlay: &mut OverlayedChanges,
523+
pending_ext: &mut TestExternalities,
525524
) -> Result<Vec<KeyValue>, &'static str> {
526525
let start = Instant::now();
527526
let mut sp = Spinner::with_timer(Spinners::Dots, "Scraping keys...".into());
@@ -547,7 +546,7 @@ where
547546
.collect::<Vec<_>>();
548547

549548
let bar = ProgressBar::new(payloads.len() as u64);
550-
let bar_message = "Downloading key values".to_string();
549+
let bar_message = format!("Downloading key values");
551550
bar.set_message(bar_message);
552551
bar.set_style(
553552
ProgressStyle::with_template(
@@ -597,9 +596,7 @@ where
597596

598597
let mut sp = Spinner::with_timer(Spinners::Dots, "Inserting keys into DB...".into());
599598
let start = Instant::now();
600-
key_values.clone().into_iter().for_each(|(k, v)| {
601-
ext_overlay.set_storage(k.0, Some(v.0));
602-
});
599+
pending_ext.batch_insert(key_values.clone().into_iter().map(|(k, v)| (k.0, v.0)));
603600
sp.stop_with_message(format!("✅ Inserted keys into DB ({}s)", start.elapsed().as_secs()));
604601
Ok(key_values)
605602
}
@@ -706,7 +703,7 @@ where
706703
async fn load_child_remote(
707704
&self,
708705
top_kv: &[KeyValue],
709-
ext_overlay: &mut OverlayedChanges,
706+
pending_ext: &mut TestExternalities,
710707
) -> Result<ChildKeyValues, &'static str> {
711708
let child_roots = top_kv
712709
.into_iter()
@@ -750,7 +747,7 @@ where
750747
child_kv_inner.iter().cloned().map(|(k, v)| (k.0, v.0)).collect::<Vec<_>>();
751748
child_kv.push((info.clone(), child_kv_inner));
752749
for (k, v) in key_values {
753-
ext_overlay.set_child_storage(&info, k, Some(v));
750+
pending_ext.insert_child(info.clone(), k, v);
754751
}
755752
}
756753

@@ -759,11 +756,11 @@ where
759756

760757
/// Build `Self` from a network node denoted by `uri`.
761758
///
762-
/// This function populates `ext_overlay`. The return value is for optionally writing to a
763-
/// snapshot file.
759+
/// This function concurrently populates `pending_ext`. the return value is only for writing to
760+
/// cache, we can also optimize further.
764761
async fn load_top_remote(
765762
&self,
766-
ext_overlay: &mut OverlayedChanges,
763+
pending_ext: &mut TestExternalities,
767764
) -> Result<TopKeyValues, &'static str> {
768765
let config = self.as_online();
769766
let at = self
@@ -776,7 +773,7 @@ where
776773
for prefix in &config.hashed_prefixes {
777774
let now = std::time::Instant::now();
778775
let additional_key_values =
779-
self.rpc_get_pairs_paged(StorageKey(prefix.to_vec()), at, ext_overlay).await?;
776+
self.rpc_get_pairs_paged(StorageKey(prefix.to_vec()), at, pending_ext).await?;
780777
let elapsed = now.elapsed();
781778
log::info!(
782779
target: LOG_TARGET,
@@ -796,7 +793,7 @@ where
796793
);
797794
match self.rpc_get_storage(key.clone(), Some(at)).await? {
798795
Some(value) => {
799-
ext_overlay.set_storage(key.clone().0, Some(value.clone().0));
796+
pending_ext.insert(key.clone().0, value.clone().0);
800797
keys_and_values.push((key, value));
801798
},
802799
None => {
@@ -877,10 +874,8 @@ where
877874
Default::default(),
878875
self.overwrite_state_version.unwrap_or(state_version),
879876
);
880-
let top_kv = self.load_top_remote(&mut pending_ext.overlayed_changes_mut()).await?;
881-
let child_kv = self
882-
.load_child_remote(&top_kv, &mut pending_ext.overlayed_changes_mut())
883-
.await?;
877+
let top_kv = self.load_top_remote(&mut pending_ext).await?;
878+
let child_kv = self.load_child_remote(&top_kv, &mut pending_ext).await?;
884879

885880
if let Some(path) = self.as_online().state_snapshot.clone().map(|c| c.path) {
886881
let snapshot = Snapshot::<B> {
@@ -930,23 +925,24 @@ where
930925
Default::default(),
931926
self.overwrite_state_version.unwrap_or(state_version),
932927
);
933-
let ext_overlay = inner_ext.overlayed_changes_mut();
934928

935-
info!(target: LOG_TARGET, "injecting {} top keys", top.len());
936-
top.into_iter()
929+
info!(target: LOG_TARGET, "injecting a total of {} top keys", top.len());
930+
let top = top
931+
.into_iter()
937932
.filter(|(k, _)| !is_default_child_storage_key(k.as_ref()))
938-
.for_each(|(k, v)| {
939-
ext_overlay.set_storage(k.0, Some(v.0));
940-
});
933+
.map(|(k, v)| (k.0, v.0))
934+
.collect::<Vec<_>>();
935+
inner_ext.batch_insert(top);
941936

942937
info!(
943938
target: LOG_TARGET,
944-
"injecting {} child keys",
939+
"injecting a total of {} child keys",
945940
child.iter().flat_map(|(_, kv)| kv).count()
946941
);
942+
947943
for (info, key_values) in child {
948944
for (k, v) in key_values {
949-
ext_overlay.set_child_storage(&info.clone(), k.0, Some(v.0));
945+
inner_ext.insert_child(info.clone(), k.0, v.0);
950946
}
951947
}
952948

@@ -964,7 +960,6 @@ where
964960
}
965961
},
966962
};
967-
let ext_overlay = ext.inner_ext.overlayed_changes_mut();
968963

969964
// inject manual key values.
970965
if !self.hashed_key_values.is_empty() {
@@ -973,10 +968,7 @@ where
973968
"extending externalities with {} manually injected key-values",
974969
self.hashed_key_values.len()
975970
);
976-
977-
self.hashed_key_values.into_iter().for_each(|(k, v)| {
978-
ext_overlay.set_storage(k.0, Some(v.0));
979-
});
971+
ext.batch_insert(self.hashed_key_values.into_iter().map(|(k, v)| (k.0, v.0)));
980972
}
981973

982974
// exclude manual key values.

0 commit comments

Comments
 (0)