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

Commit

Permalink
BlockId::Number refactor: trivial changes to BlockId::Hash (#12471)
Browse files Browse the repository at this point in the history
* Trivial BlockId::Number => Hash

* missed BlockId::Hash added
  • Loading branch information
michalkucharczyk authored Oct 12, 2022
1 parent 06a9f0a commit f8a0b7a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ mod tests {

assert_eq!(client.chain_info().best_number, 0);
assert_eq!(
authorities(&client, &BlockId::Number(0)).unwrap(),
authorities(&client, &BlockId::Hash(client.chain_info().best_hash)).unwrap(),
vec![
Keyring::Alice.public().into(),
Keyring::Bob.public().into(),
Expand Down
2 changes: 1 addition & 1 deletion client/db/benches/state_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn insert_blocks(db: &Backend<Block>, storage: Vec<(Vec<u8>, Vec<u8>)>) -> H256
.map(|(k, v)| (k.clone(), Some(v.clone())))
.collect::<Vec<_>>();

let (state_root, tx) = db.state_at(BlockId::Number(number - 1)).unwrap().storage_root(
let (state_root, tx) = db.state_at(BlockId::Hash(parent_hash)).unwrap().storage_root(
changes.iter().map(|(k, v)| (k.as_slice(), v.as_deref())),
StateVersion::V1,
);
Expand Down
6 changes: 3 additions & 3 deletions test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ mod tests {
.set_execution_strategy(ExecutionStrategy::AlwaysWasm)
.set_heap_pages(8)
.build();
let block_id = BlockId::Number(client.chain_info().best_number);
let block_id = BlockId::Hash(client.chain_info().best_hash);

// Try to allocate 1024k of memory on heap. This is going to fail since it is twice larger
// than the heap.
Expand Down Expand Up @@ -1369,7 +1369,7 @@ mod tests {
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);
let block_id = BlockId::Hash(client.chain_info().best_hash);

runtime_api.test_storage(&block_id).unwrap();
}
Expand All @@ -1396,7 +1396,7 @@ mod tests {
let client =
TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.chain_info().best_number);
let block_id = BlockId::Hash(client.chain_info().best_hash);

runtime_api.test_witness(&block_id, proof, root).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/benchmarking-cli/src/storage/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl StorageCmd {
B: BlockT + Debug,
BA: ClientBackend<B>,
{
let block = BlockId::Number(client.usage_info().chain.best_number);
let block = BlockId::Hash(client.usage_info().chain.best_hash);
let empty_prefix = StorageKey(Vec::new());
let mut keys = client.storage_keys(&block, &empty_prefix)?;
let (mut rng, _) = new_rng(None);
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/benchmarking-cli/src/storage/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl StorageCmd {
<<B as BlockT>::Header as HeaderT>::Number: From<u32>,
{
let mut record = BenchRecord::default();
let block = BlockId::Number(client.usage_info().chain.best_number);
let block = BlockId::Hash(client.usage_info().chain.best_hash);

info!("Preparing keys from block {}", block);
// Load all keys and randomly shuffle them.
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/benchmarking-cli/src/storage/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl StorageCmd {
// Store the time that it took to write each value.
let mut record = BenchRecord::default();

let block = BlockId::Number(client.usage_info().chain.best_number);
let block = BlockId::Hash(client.usage_info().chain.best_hash);
let header = client.header(block)?.ok_or("Header not found")?;
let original_root = *header.state_root();
let trie = DbStateBuilder::<Block>::new(storage.clone(), original_root).build();
Expand Down

0 comments on commit f8a0b7a

Please sign in to comment.