From 47775542b5c114983d9adebb4521e10898a00fcb Mon Sep 17 00:00:00 2001 From: hardliner66 Date: Tue, 23 Mar 2021 17:16:08 +0100 Subject: [PATCH 1/3] Combine SnapshotConfig string fields name and directory into single PathBuf field named path --- utils/frame/remote-externalities/src/lib.rs | 24 +++++------- utils/frame/try-runtime/cli/src/lib.rs | 41 ++------------------- 2 files changed, 14 insertions(+), 51 deletions(-) diff --git a/utils/frame/remote-externalities/src/lib.rs b/utils/frame/remote-externalities/src/lib.rs index 8d142100ec345..658a8dae6c22d 100644 --- a/utils/frame/remote-externalities/src/lib.rs +++ b/utils/frame/remote-externalities/src/lib.rs @@ -181,23 +181,19 @@ impl OnlineConfig { /// Configuration of the state snapshot. #[derive(Clone)] pub struct SnapshotConfig { - // TODO: I could mix these two into one filed, but I think separate is better bc one can be - // configurable while one not. - /// File name. - pub name: String, - /// Base directory. - pub directory: String, + /// The path to the snapshot file. + pub path: PathBuf, } -impl Default for SnapshotConfig { - fn default() -> Self { - Self { name: "SNAPSHOT".into(), directory: ".".into() } +impl SnapshotConfig { + pub fn new>(path: P) -> Self { + Self { path: path.into() } } } -impl SnapshotConfig { - fn path(&self) -> PathBuf { - Path::new(&self.directory).join(self.name.clone()) +impl Default for SnapshotConfig { + fn default() -> Self { + Self { path: Path::new("SNAPSHOT").into() } } } @@ -319,12 +315,12 @@ impl Builder { async fn pre_build(mut self) -> Result, &'static str> { let mut base_kv = match self.mode.clone() { - Mode::Offline(config) => self.load_state_snapshot(&config.state_snapshot.path())?, + Mode::Offline(config) => self.load_state_snapshot(&config.state_snapshot.path)?, Mode::Online(config) => { self.init_remote_client().await?; let kp = self.load_remote().await?; if let Some(c) = config.state_snapshot { - self.save_state_snapshot(&kp, &c.path())?; + self.save_state_snapshot(&kp, &c.path)?; } kp } diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index ff8c5c08ec5b7..8e407f3b2d739 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -67,15 +67,14 @@ pub struct TryRuntimeCmd { pub enum State { /// Use a state snapshot as state to run the migration. Snap { - #[structopt(flatten)] - snapshot_path: SnapshotPath, + snapshot_path: PathBuf, }, /// Use a live chain to run the migration. Live { /// An optional state snapshot file to WRITE to. Not written if set to `None`. #[structopt(short, long)] - snapshot_path: Option, + snapshot_path: Option, /// The block hash at which to connect. /// Will be latest finalized head if not provided. @@ -118,31 +117,6 @@ fn parse_url(s: &str) -> Result { } } -#[derive(Debug, structopt::StructOpt)] -pub struct SnapshotPath { - /// The directory of the state snapshot. - #[structopt(short, long, default_value = ".")] - directory: String, - - /// The file name of the state snapshot. - #[structopt(default_value = "SNAPSHOT")] - file_name: String, -} - -impl FromStr for SnapshotPath { - type Err = &'static str; - fn from_str(s: &str) -> Result { - let p: PathBuf = s.parse().map_err(|_| "invalid path")?; - let parent = p.parent(); - let file_name = p.file_name(); - - file_name.and_then(|file_name| Some(Self { - directory: parent.map(|p| p.to_string_lossy().into()).unwrap_or(".".to_string()), - file_name: file_name.to_string_lossy().into() - })).ok_or("invalid path") - } -} - impl TryRuntimeCmd { pub async fn run(&self, config: Configuration) -> sc_cli::Result<()> where @@ -182,12 +156,8 @@ impl TryRuntimeCmd { use remote_externalities::{Builder, Mode, SnapshotConfig, OfflineConfig, OnlineConfig}; let builder = match &self.state { State::Snap { snapshot_path } => { - let SnapshotPath { directory, file_name } = snapshot_path; Builder::::new().mode(Mode::Offline(OfflineConfig { - state_snapshot: SnapshotConfig { - name: file_name.into(), - directory: directory.into(), - }, + state_snapshot: SnapshotConfig::new(snapshot_path), })) }, State::Live { @@ -197,10 +167,7 @@ impl TryRuntimeCmd { modules } => Builder::::new().mode(Mode::Online(OnlineConfig { uri: url.into(), - state_snapshot: snapshot_path.as_ref().map(|c| SnapshotConfig { - name: c.file_name.clone(), - directory: c.directory.clone(), - }), + state_snapshot: snapshot_path.as_ref().map(SnapshotConfig::new), modules: modules.clone().unwrap_or_default(), at: match block_at { Some(b) => Some(b.parse().map_err(|e| format!("Could not parse hash: {:?}", e))?), From 11041425f67224fb1244c80ba5bf5be0fc983cc5 Mon Sep 17 00:00:00 2001 From: hardliner66 Date: Mon, 29 Mar 2021 11:11:44 +0200 Subject: [PATCH 2/3] Update Cargo.lock --- Cargo.lock | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83a2d4527ba22..5f09da33b79d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4635,22 +4635,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-assets-freezer" -version = "3.0.0" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "pallet-assets", - "parity-scale-codec 2.0.1", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-atomic-swap" version = "3.0.0" From f9e63cb716eea864898fbeb5425431506ed91f9b Mon Sep 17 00:00:00 2001 From: hardliner66 Date: Mon, 29 Mar 2021 12:16:18 +0200 Subject: [PATCH 3/3] fix test build failure --- utils/frame/remote-externalities/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/frame/remote-externalities/src/lib.rs b/utils/frame/remote-externalities/src/lib.rs index 658a8dae6c22d..8cca728c1ffaa 100644 --- a/utils/frame/remote-externalities/src/lib.rs +++ b/utils/frame/remote-externalities/src/lib.rs @@ -395,7 +395,7 @@ mod tests { init_logger(); Builder::::new() .mode(Mode::Offline(OfflineConfig { - state_snapshot: SnapshotConfig { name: "test_data/proxy_test".into(), ..Default::default() }, + state_snapshot: SnapshotConfig { path: "test_data/proxy_test".into() }, })) .build() .await