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
5 changes: 1 addition & 4 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
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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::RecordProof;
use sp_api::{Core, ProvideRuntimeApi};
use sp_keyring::Sr25519Keyring::Alice;

Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/block_import_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_arithmetic::{
use core::time::Duration;
use cumulus_primitives_core::ParaId;

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

use cumulus_test_service::bench_utils as utils;
Expand Down
2 changes: 1 addition & 1 deletion 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::RecordProof;

use sp_keyring::Sr25519Keyring::Alice;

Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/block_production_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,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::RecordProof;

use sp_keyring::Sr25519Keyring::Alice;

Expand Down
1 change: 0 additions & 1 deletion cumulus/test/service/benches/validate_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ 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_client_api::UsageProvider;
use sc_executor_common::wasm_runtime::WasmModule;

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
24 changes: 13 additions & 11 deletions polkadot/node/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::{Client, FullBackend};
use crate::Client;
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::{Block, InherentData as ParachainsInherentData};
use polkadot_test_runtime::UncheckedExtrinsic;
use polkadot_test_service::GetLastTimestamp;
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sc_block_builder::{BlockBuilder, BlockBuilderBuilder};
use sp_api::ProvideRuntimeApi;
use sp_consensus_babe::{
digests::{PreDigest, SecondaryPlainPreDigest},
Expand All @@ -34,9 +34,7 @@ pub trait InitPolkadotBlockBuilder {
///
/// This will automatically create and push the inherents for you to make the block valid for
/// the test runtime.
fn init_polkadot_block_builder(
&self,
) -> sc_block_builder::BlockBuilder<Block, Client, FullBackend>;
fn init_polkadot_block_builder(&self) -> sc_block_builder::BlockBuilder<Block, Client>;

/// Init a Polkadot specific block builder at a specific block that works for the test runtime.
///
Expand All @@ -45,19 +43,19 @@ pub trait InitPolkadotBlockBuilder {
fn init_polkadot_block_builder_at(
&self,
hash: <Block as BlockT>::Hash,
) -> sc_block_builder::BlockBuilder<Block, Client, FullBackend>;
) -> sc_block_builder::BlockBuilder<Block, Client>;
}

impl InitPolkadotBlockBuilder for Client {
fn init_polkadot_block_builder(&self) -> BlockBuilder<Block, Client, FullBackend> {
fn init_polkadot_block_builder(&self) -> BlockBuilder<Block, Client> {
let chain_info = self.chain_info();
self.init_polkadot_block_builder_at(chain_info.best_hash)
}

fn init_polkadot_block_builder_at(
&self,
hash: <Block as BlockT>::Hash,
) -> BlockBuilder<Block, Client, FullBackend> {
) -> BlockBuilder<Block, Client> {
let last_timestamp =
self.runtime_api().get_last_timestamp(hash).expect("Get last timestamp");

Expand Down Expand Up @@ -90,8 +88,12 @@ impl InitPolkadotBlockBuilder for Client {
)],
};

let mut block_builder = self
.new_block_at(hash, digest, false)
let mut block_builder = BlockBuilderBuilder::new(self)
.on_parent_block(hash)
.fetch_parent_block_number(&self)
.expect("Fetches parent block number")
.with_inherent_digests(digest)
.build()
.expect("Creates new block builder for test runtime");

let mut inherent_data = sp_inherents::InherentData::new();
Expand Down Expand Up @@ -144,7 +146,7 @@ pub trait BlockBuilderExt {
) -> Result<(), sp_blockchain::Error>;
}

impl BlockBuilderExt for BlockBuilder<'_, Block, Client, FullBackend> {
impl BlockBuilderExt for BlockBuilder<'_, Block, Client> {
fn push_polkadot_extrinsic(
&mut self,
ext: UncheckedExtrinsic,
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion, Throughpu

use kitchensink_runtime::{constants::currency::*, BalancesCall};
use node_cli::service::{create_extrinsic, FullClient};
use sc_block_builder::{BlockBuilderProvider, BuiltBlock, RecordProof};
use sc_block_builder::{BuiltBlock, RecordProof};
use sc_consensus::{
block_import::{BlockImportParams, ForkChoiceStrategy},
BlockImport, StateAction,
Expand Down
11 changes: 8 additions & 3 deletions substrate/bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use kitchensink_runtime::{
RuntimeCall, Signature, SystemCall, UncheckedExtrinsic,
};
use node_primitives::Block;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::execution_extensions::ExecutionExtensions;
use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::{execution_extensions::ExecutionExtensions, UsageProvider};
use sc_client_db::PruningMode;
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, ImportedAux};
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmtimeInstantiationStrategy};
Expand Down Expand Up @@ -455,8 +455,13 @@ impl BenchDb {
/// Generate new block using this database.
pub fn generate_block(&mut self, content: BlockContent) -> Block {
let client = self.client();
let chain = client.usage_info().chain;

let mut block = client.new_block(Default::default()).expect("Block creation failed");
let mut block = BlockBuilderBuilder::new(&client)
.on_parent_block(chain.best_hash)
.with_parent_block_number(chain.best_number)
.build()
.expect("Failed to create block builder.");

for extrinsic in self.generate_inherents(&client) {
block.push(extrinsic).expect("Push inherent failed");
Expand Down
1 change: 0 additions & 1 deletion substrate/client/basic-authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ futures-timer = "3.0.1"
log = "0.4.17"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus" }
sc-block-builder = { path = "../block-builder" }
sc-client-api = { path = "../api" }
sc-proposer-metrics = { path = "../proposer-metrics" }
sc-telemetry = { path = "../telemetry" }
sc-transaction-pool-api = { path = "../transaction-pool/api" }
Expand Down
Loading