sc-network-test::Peer: block push methods return hashes vec (#12944)

* sc-network-test::Peer: block push methods return hashes vec

This commit reworks the block generation/push methods in
sc-network-test::Peer.

Now methods are providing the vector of hashes that were built.

This allows to get rid of redundant `block_hash_from_id` call, as all
hashes are known just after being built.

Similar approach was taken in BeefyTestNet::generate_blocks_and_sync
method.

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)

* fix

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2022-12-19 11:18:32 +01:00
committed by GitHub
parent 40c04cf11d
commit 1be51ccb5c
6 changed files with 212 additions and 197 deletions
+2 -7
View File
@@ -34,7 +34,7 @@ use std::borrow::Cow;
use node_primitives::Block;
use node_testing::bench::{BenchDb, BlockType, DatabaseType, KeyTypes, Profile};
use sc_client_api::{backend::Backend, HeaderBackend};
use sc_client_api::backend::Backend;
use sp_runtime::generic::BlockId;
use sp_state_machine::InspectState;
@@ -127,15 +127,10 @@ impl core::Benchmark for ImportBenchmark {
context.import_block(self.block.clone());
let elapsed = start.elapsed();
let hash = context
.client
.expect_block_hash_from_id(&BlockId::number(1))
.expect("Block 1 was imported; qed");
// Sanity checks.
context
.client
.state_at(hash)
.state_at(self.block.header.hash())
.expect("state_at failed for block#1")
.inspect_state(|| {
match self.block_type {