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

sc-block-builder: Remove BlockBuilderProvider #2099

Merged
merged 14 commits into from
Nov 3, 2023
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions cumulus/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use crate::{Backend, Client};
use crate::Client;
use cumulus_primitives_core::{ParachainBlockData, PersistedValidationData};
use cumulus_primitives_parachain_inherent::{ParachainInherentData, INHERENT_IDENTIFIER};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use cumulus_test_runtime::{Block, GetLastTimestamp, Hash, Header};
use polkadot_primitives::{BlockNumber as PBlockNumber, Hash as PHash};
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sc_block_builder::{BlockBuilder, BlockBuilderBuilder};
use sp_api::ProvideRuntimeApi;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

Expand All @@ -37,7 +37,7 @@ pub trait InitBlockBuilder {
&self,
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend>;
) -> sc_block_builder::BlockBuilder<Block, Client>;

/// Init a specific block builder at a specific block that works for the test runtime.
///
Expand All @@ -48,7 +48,7 @@ pub trait InitBlockBuilder {
at: Hash,
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend>;
) -> sc_block_builder::BlockBuilder<Block, Client>;

/// Init a specific block builder that works for the test runtime.
///
Expand All @@ -61,7 +61,7 @@ pub trait InitBlockBuilder {
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
timestamp: u64,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend>;
) -> sc_block_builder::BlockBuilder<Block, Client>;
}

fn init_block_builder(
Expand All @@ -70,9 +70,13 @@ fn init_block_builder(
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
timestamp: u64,
) -> BlockBuilder<'_, Block, Client, Backend> {
let mut block_builder = client
.new_block_at(at, Default::default(), true)
) -> BlockBuilder<'_, Block, Client> {
let mut block_builder = BlockBuilderBuilder::new(client)
.on_parent_block(at)
.fetch_parent_block_number(client)
.unwrap()
.enable_proof_recording()
.build()
.expect("Creates new block builder for test runtime");

let mut inherent_data = sp_inherents::InherentData::new();
Expand Down Expand Up @@ -118,7 +122,7 @@ impl InitBlockBuilder for Client {
&self,
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
) -> BlockBuilder<Block, Client, Backend> {
) -> BlockBuilder<Block, Client> {
let chain_info = self.chain_info();
self.init_block_builder_at(chain_info.best_hash, validation_data, relay_sproof_builder)
}
Expand All @@ -128,7 +132,7 @@ impl InitBlockBuilder for Client {
at: Hash,
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
) -> BlockBuilder<Block, Client, Backend> {
) -> BlockBuilder<Block, Client> {
let last_timestamp = self.runtime_api().get_last_timestamp(at).expect("Get last timestamp");

let timestamp = last_timestamp + cumulus_test_runtime::MinimumPeriod::get();
Expand All @@ -142,7 +146,7 @@ impl InitBlockBuilder for Client {
validation_data: Option<PersistedValidationData<PHash, PBlockNumber>>,
relay_sproof_builder: RelayStateSproofBuilder,
timestamp: u64,
) -> sc_block_builder::BlockBuilder<Block, Client, Backend> {
) -> sc_block_builder::BlockBuilder<Block, Client> {
init_block_builder(self, at, validation_data, relay_sproof_builder, timestamp)
}
}
Expand All @@ -155,7 +159,7 @@ pub trait BuildParachainBlockData {
fn build_parachain_block(self, parent_state_root: Hash) -> ParachainBlockData<Block>;
}

impl<'a> BuildParachainBlockData for sc_block_builder::BlockBuilder<'a, Block, Client, Backend> {
impl<'a> BuildParachainBlockData for sc_block_builder::BlockBuilder<'a, Block, Client> {
fn build_parachain_block(self, parent_state_root: Hash) -> ParachainBlockData<Block> {
let built_block = self.build().expect("Builds the block");

Expand Down
10 changes: 7 additions & 3 deletions cumulus/test/service/benches/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

use criterion::{criterion_group, criterion_main, BatchSize, Criterion, Throughput};

use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::UsageProvider;

use core::time::Duration;
use cumulus_primitives_core::ParaId;

use sc_block_builder::{BlockBuilderProvider, RecordProof};
use sp_api::{Core, ProvideRuntimeApi};
use sp_keyring::Sr25519Keyring::Alice;

Expand Down Expand Up @@ -52,8 +52,12 @@ fn benchmark_block_import(c: &mut Criterion) {
utils::create_benchmarking_transfer_extrinsics(&client, &src_accounts, &dst_accounts);

let parent_hash = client.usage_info().chain.best_hash;
let mut block_builder =
client.new_block_at(parent_hash, Default::default(), RecordProof::No).unwrap();
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(parent_hash)
.fetch_parent_block_number(&*client)
.unwrap()
.build()
.unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
}
Expand Down
13 changes: 8 additions & 5 deletions cumulus/test/service/benches/block_import_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};

use sc_client_api::UsageProvider;
use sp_api::{Core, ProvideRuntimeApi};
use sp_arithmetic::{
traits::{One, Zero},
Expand All @@ -27,7 +26,7 @@ use sp_arithmetic::{
use core::time::Duration;
use cumulus_primitives_core::ParaId;

use sc_block_builder::{BlockBuilderProvider, RecordProof};
use sc_block_builder::BlockBuilderBuilder;
use sp_keyring::Sr25519Keyring::Alice;

use cumulus_test_service::bench_utils as utils;
Expand Down Expand Up @@ -61,10 +60,14 @@ fn benchmark_block_import(c: &mut Criterion) {
runtime.block_on(utils::import_block(&client, &block, false));

// Build the block we will use for benchmarking
let parent_hash = client.usage_info().chain.best_hash;
let parent_hash = client.chain_info().best_hash;
let parent_header = client.header(parent_hash).expect("Just fetched this hash.").unwrap();
let mut block_builder =
client.new_block_at(parent_hash, Default::default(), RecordProof::No).unwrap();
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(parent_hash)
.fetch_parent_block_number(&*client)
.unwrap()
.build()
.unwrap();
block_builder
.push(utils::extrinsic_set_validation_data(parent_header.clone()).clone())
.unwrap();
Expand Down
25 changes: 18 additions & 7 deletions cumulus/test/service/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sc_client_api::UsageProvider;

use core::time::Duration;
use cumulus_primitives_core::ParaId;
use sc_block_builder::{BlockBuilderProvider, RecordProof};
use sc_block_builder::BlockBuilderBuilder;

use sp_keyring::Sr25519Keyring::Alice;

Expand Down Expand Up @@ -50,7 +50,11 @@ fn benchmark_block_production(c: &mut Criterion) {
let parent_header = client.header(parent_hash).expect("Just fetched this hash.").unwrap();
let set_validation_data_extrinsic = utils::extrinsic_set_validation_data(parent_header);

let mut block_builder = client.new_block(Default::default()).unwrap();
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(client.chain_info().best_hash)
.with_parent_block_number(client.chain_info().best_number)
.build()
.unwrap();
block_builder.push(utils::extrinsic_set_time(&client)).unwrap();
block_builder.push(set_validation_data_extrinsic).unwrap();
let built_block = block_builder.build().unwrap();
Expand All @@ -66,17 +70,21 @@ fn benchmark_block_production(c: &mut Criterion) {
group.measurement_time(Duration::from_secs(120));
group.throughput(Throughput::Elements(max_transfer_count as u64));

let best_hash = client.chain_info().best_hash;
let chain = client.chain_info();

group.bench_function(
format!("(proof = true, transfers = {}) block production", max_transfer_count),
|b| {
b.iter_batched(
|| extrinsics.clone(),
|extrinsics| {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::Yes)
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(chain.best_hash)
.with_parent_block_number(chain.best_number)
.enable_proof_recording()
.build()
.unwrap();

for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
}
Expand All @@ -93,9 +101,12 @@ fn benchmark_block_production(c: &mut Criterion) {
b.iter_batched(
|| extrinsics.clone(),
|extrinsics| {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::No)
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(chain.best_hash)
.with_parent_block_number(chain.best_number)
.build()
.unwrap();

for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
}
Expand Down
22 changes: 13 additions & 9 deletions cumulus/test/service/benches/block_production_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};

use sc_client_api::UsageProvider;
use sp_arithmetic::{
traits::{One, Zero},
FixedPointNumber,
Expand All @@ -26,7 +25,7 @@ use sp_arithmetic::{
use core::time::Duration;
use cumulus_primitives_core::ParaId;

use sc_block_builder::{BlockBuilderProvider, RecordProof};
use sc_block_builder::BlockBuilderBuilder;

use sp_keyring::Sr25519Keyring::Alice;

Expand Down Expand Up @@ -60,11 +59,11 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
runtime.block_on(utils::import_block(&client, &block, false));
initialize_glutton_pallet = false;

let parent_hash = client.usage_info().chain.best_hash;
let parent_header = client.header(parent_hash).expect("Just fetched this hash.").unwrap();
let best_hash = client.chain_info().best_hash;
let best_number = client.chain_info().best_number;
let parent_header = client.header(best_hash).expect("Just fetched this hash.").unwrap();
let set_validation_data_extrinsic = utils::extrinsic_set_validation_data(parent_header);
let set_time_extrinsic = utils::extrinsic_set_time(&client);
let best_hash = client.chain_info().best_hash;

group.bench_function(
format!(
Expand All @@ -76,8 +75,11 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
b.iter_batched(
|| (set_validation_data_extrinsic.clone(), set_time_extrinsic.clone()),
|(validation_data, time)| {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::Yes)
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(best_hash)
.with_parent_block_number(best_number)
.enable_proof_recording()
.build()
.unwrap();
block_builder.push(validation_data).unwrap();
block_builder.push(time).unwrap();
Expand All @@ -98,8 +100,10 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
b.iter_batched(
|| (set_validation_data_extrinsic.clone(), set_time_extrinsic.clone()),
|(validation_data, time)| {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::No)
let mut block_builder = BlockBuilderBuilder::new(&*client)
.on_parent_block(best_hash)
.with_parent_block_number(best_number)
.build()
.unwrap();
block_builder.push(validation_data).unwrap();
block_builder.push(time).unwrap();
Expand Down
8 changes: 6 additions & 2 deletions cumulus/test/service/benches/validate_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use cumulus_test_runtime::{BalancesCall, Block, Header, UncheckedExtrinsic};
use cumulus_test_service::bench_utils as utils;
use polkadot_primitives::HeadData;
use sc_block_builder::BlockBuilderProvider;
use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::UsageProvider;
use sc_executor_common::wasm_runtime::WasmModule;

Expand All @@ -46,7 +46,11 @@ fn create_extrinsics(
dst_accounts: &[sr25519::Pair],
) -> (usize, Vec<UncheckedExtrinsic>) {
// Add as many tranfer extrinsics as possible into a single block.
let mut block_builder = client.new_block(Default::default()).unwrap();
let mut block_builder = BlockBuilderBuilder::new(client)
.on_parent_block(client.chain_info().best_hash)
.with_parent_block_number(client.chain_info().best_number)
.build()
.unwrap();
let mut max_transfer_count = 0;
let mut extrinsics = Vec::new();

Expand Down
16 changes: 13 additions & 3 deletions cumulus/test/service/src/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

use codec::Encode;
use sc_block_builder::BlockBuilderBuilder;

use crate::{construct_extrinsic, Client as TestClient};
use cumulus_primitives_core::{relay_chain::AccountId, PersistedValidationData};
Expand All @@ -26,7 +27,6 @@ use cumulus_test_runtime::{
};
use frame_system_rpc_runtime_api::AccountNonceApi;
use polkadot_primitives::HeadData;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::UsageProvider;
use sc_consensus::{
block_import::{BlockImportParams, ForkChoiceStrategy},
Expand Down Expand Up @@ -126,8 +126,13 @@ pub fn create_benchmarking_transfer_extrinsics(
src_accounts: &[sr25519::Pair],
dst_accounts: &[sr25519::Pair],
) -> (usize, Vec<OpaqueExtrinsic>) {
let chain = client.usage_info().chain;
// Add as many transfer extrinsics as possible into a single block.
let mut block_builder = client.new_block(Default::default()).unwrap();
let mut block_builder = BlockBuilderBuilder::new(client)
.on_parent_block(chain.best_hash)
.with_parent_block_number(chain.best_number)
.build()
.expect("Creates block builder");
let mut max_transfer_count = 0;
let mut extrinsics = Vec::new();
// Every block needs one timestamp extrinsic.
Expand Down Expand Up @@ -248,8 +253,13 @@ pub fn set_glutton_parameters(
Some(last_nonce),
);
extrinsics.push(set_storage);
let chain = client.usage_info().chain;

let mut block_builder = client.new_block(Default::default()).unwrap();
let mut block_builder = BlockBuilderBuilder::new(client)
.on_parent_block(chain.best_hash)
.with_parent_block_number(chain.best_number)
.build()
.unwrap();
block_builder.push(extrinsic_set_time(client)).unwrap();
block_builder.push(extrinsic_set_validation_data(parent_header)).unwrap();
for extrinsic in extrinsics {
Expand Down
Loading
Loading