Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow hashed prefix to be configured. #33

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/commands/follow_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Block, HostFns>(&shared, &executor, None, true)
Expand Down
20 changes: 19 additions & 1 deletion core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `xx_hash_64(pallet)` to `--hashed_prefixes`.
#[arg(short, long, num_args = 1..)]
pub pallet: Vec<String>,

/// 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<String>,

/// Fetch the child-keys as well.
///
/// Default is `false`, if specific `--pallets` are specified, `true` otherwise. In other
Expand Down Expand Up @@ -132,11 +138,23 @@ impl State {
uri,
at,
child_tree,
hashed_prefixes,
}) => {
let at = match at {
Some(at_str) => Some(hash_of::<Block>(at_str)?),
None => None,
};
let hashed_prefixes = hashed_prefixes
.iter()
.map(|p_str| {
hex::decode(p_str).map_err(|e| {
format!(
"Error decoding `hashed_prefixes` hex string entry '{:?}' to bytes: {:?}",
p_str, e
)
})
})
.collect::<Result<Vec<_>, _>>()?;
Builder::<Block>::new().mode(Mode::Online(OnlineConfig {
at,
transport: uri.to_owned().into(),
Expand All @@ -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,
}))
}
};
Expand Down
Loading