From 8c3e7067deeb85dd9434d61fcdb2eb66dc8d5edf Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Sep 2023 18:03:29 +0200 Subject: [PATCH 1/5] allow hashed prefix to be configured. --- core/src/commands/follow_chain.rs | 1 + core/src/state.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/src/commands/follow_chain.rs b/core/src/commands/follow_chain.rs index 0726c7b21c2..311d8eb5aee 100644 --- a/core/src/commands/follow_chain.rs +++ b/core/src/commands/follow_chain.rs @@ -140,6 +140,7 @@ where at: Some(hex::encode(header.parent_hash().encode())), pallet: vec![], child_tree: true, + hashed_prefixes: vec![], }); let ext = state .to_ext::(&shared, &executor, None, true) diff --git a/core/src/state.rs b/core/src/state.rs index 445c5389e75..3ae8668a9cf 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -61,9 +61,15 @@ pub struct LiveState { /// A pallet to scrape. Can be provided multiple times. If empty, entire chain state will /// be scraped. + /// + /// This is equivalent to passing the `xx_hash_64(pallet)` to `prefix`. #[arg(short, long, num_args = 1..)] pub pallet: Vec, + /// A hashed prefix to scrape. + #[arg(long = "prefix", value_parser = parse::hash, num_args = 1..)] + pub hashed_prefixes: Vec, + /// Fetch the child-keys as well. /// /// Default is `false`, if specific `--pallets` are specified, `true` otherwise. In other @@ -132,11 +138,23 @@ impl State { uri, at, child_tree, + hashed_prefixes, }) => { let at = match at { Some(at_str) => Some(hash_of::(at_str)?), None => None, }; + let hashed_prefixes = hashed_prefixes + .into_iter() + .map(|p_str| { + hex::decode(p_str).map_err(|e| { + format!( + "error while decoding prefix {:?} as hex string: {:?}", + p_str, e + ) + }) + }) + .collect::, _>>()?; Builder::::new().mode(Mode::Online(OnlineConfig { at, transport: uri.to_owned().into(), @@ -152,7 +170,7 @@ impl State { [twox_128(b"System"), twox_128(b"LastRuntimeUpgrade")].concat(), [twox_128(b"System"), twox_128(b"Number")].concat(), ], - hashed_prefixes: vec![], + hashed_prefixes, })) } }; From f00cbb01a0e7d04f69828ae8a243e474c57cb30b Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Tue, 19 Sep 2023 10:46:10 +0200 Subject: [PATCH 2/5] Update core/src/state.rs --- core/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/state.rs b/core/src/state.rs index 3ae8668a9cf..a1f1f52322a 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -145,7 +145,7 @@ impl State { None => None, }; let hashed_prefixes = hashed_prefixes - .into_iter() + .iter() .map(|p_str| { hex::decode(p_str).map_err(|e| { format!( From bf417883a49cb2f3fa27b89faeb9478b4eaaec71 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:48:17 +0200 Subject: [PATCH 3/5] Update core/src/state.rs Co-authored-by: Liam Aharon --- core/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/state.rs b/core/src/state.rs index a1f1f52322a..014cedbf42a 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -62,7 +62,7 @@ pub struct LiveState { /// A pallet to scrape. Can be provided multiple times. If empty, entire chain state will /// be scraped. /// - /// This is equivalent to passing the `xx_hash_64(pallet)` to `prefix`. + /// This is equivalent to passing `xx_hash_64(pallet)` to `--hashed_prefixes`. #[arg(short, long, num_args = 1..)] pub pallet: Vec, From 77efa4dfe320105b45d4c454181d6cddb1534602 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:48:25 +0200 Subject: [PATCH 4/5] Update core/src/state.rs Co-authored-by: Liam Aharon --- core/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/state.rs b/core/src/state.rs index 014cedbf42a..bee256ab37a 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -149,7 +149,7 @@ impl State { .map(|p_str| { hex::decode(p_str).map_err(|e| { format!( - "error while decoding prefix {:?} as hex string: {:?}", + "Error decoding `hashed_prefixes` hex string entry '{:?}' to bytes: {:?}", p_str, e ) }) From 525414653ae7bb56c7408e96a5653030c68bee0e Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 25 Sep 2023 08:48:34 +0200 Subject: [PATCH 5/5] Update core/src/state.rs Co-authored-by: Liam Aharon --- core/src/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/state.rs b/core/src/state.rs index bee256ab37a..5d51632871b 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -66,7 +66,7 @@ pub struct LiveState { #[arg(short, long, num_args = 1..)] pub pallet: Vec, - /// A hashed prefix to scrape. + /// Storage entry key prefixes to scrape and inject into the test externalities. Pass as 0x prefixed hex strings. By default, all keys are scraped and included. #[arg(long = "prefix", value_parser = parse::hash, num_args = 1..)] pub hashed_prefixes: Vec,