mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 01:47:55 +00:00
sc-block-builder: Remove BlockBuilderProvider (#2099)
The `BlockBuilderProvider` was a trait that was defined in `sc-block-builder`. The trait was implemented for `Client`. This basically meant that you needed to import `sc-block-builder` any way to have access to the block builder. So, this trait was not providing any real value. This pull request is removing the said trait. Instead of the trait it introduces a builder for creating a `BlockBuilder`. The builder currently has the quite fabulous name `BlockBuilderBuilder` (I'm open to any better name 😅). The rest of the pull request is about replacing the old trait with the new builder. # Downstream code changes If you used `new_block` or `new_block_at` before you now need to switch it over to the new `BlockBuilderBuilder` pattern: ```rust // `new` requires a type that implements `CallApiAt`. let mut block_builder = BlockBuilderBuilder::new(client) // Then you need to specify the hash of the parent block the block will be build on top of .on_parent_block(at) // The block builder also needs the block number of the parent block. // Here it is fetched from the given `client` using the `HeaderBackend` // However, there also exists `with_parent_block_number` for directly passing the number .fetch_parent_block_number(client) .unwrap() // Enable proof recording if required. This call is optional. .enable_proof_recording() // Pass the digests. This call is optional. .with_inherent_digests(digests) .build() .expect("Creates new block builder"); ``` --------- Co-authored-by: Sebastian Kunert <skunert49@gmail.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
use codec::DecodeAll;
|
||||
use frame_support::weights::constants::WEIGHT_REF_TIME_PER_NANOS;
|
||||
use frame_system::ConsumedWeight;
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sc_cli::{Error, Result};
|
||||
use sc_client_api::{
|
||||
Backend as ClientBackend, BlockBackend, HeaderBackend, StorageProvider, UsageProvider,
|
||||
@@ -71,8 +71,7 @@ impl<Block, BA, C> Benchmark<Block, BA, C>
|
||||
where
|
||||
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
|
||||
BA: ClientBackend<Block>,
|
||||
C: BlockBuilderProvider<BA, Block, C>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ StorageProvider<Block, BA>
|
||||
+ UsageProvider<Block>
|
||||
+ BlockBackend<Block>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Contains the [`BlockCmd`] as entry point for the CLI to execute
|
||||
//! the *block* benchmark.
|
||||
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||
use sc_client_api::{Backend as ClientBackend, BlockBackend, StorageProvider, UsageProvider};
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
@@ -84,8 +84,7 @@ impl BlockCmd {
|
||||
where
|
||||
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
|
||||
BA: ClientBackend<Block>,
|
||||
C: BlockBuilderProvider<BA, Block, C>
|
||||
+ BlockBackend<Block>
|
||||
C: BlockBackend<Block>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
+ StorageProvider<Block, BA>
|
||||
+ UsageProvider<Block>
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
//! Contains the core benchmarking logic.
|
||||
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderBuilder};
|
||||
use sc_cli::{Error, Result};
|
||||
use sc_client_api::Backend as ClientBackend;
|
||||
use sp_api::{ApiExt, Core, ProvideRuntimeApi};
|
||||
use sc_client_api::UsageProvider;
|
||||
use sp_api::{ApiExt, CallApiAt, Core, ProvideRuntimeApi};
|
||||
use sp_blockchain::{
|
||||
ApplyExtrinsicFailed::Validity,
|
||||
Error::{ApplyExtrinsicFailed, RuntimeApiError},
|
||||
@@ -61,20 +61,20 @@ pub struct BenchmarkParams {
|
||||
pub(crate) type BenchRecord = Vec<u64>;
|
||||
|
||||
/// Holds all objects needed to run the *overhead* benchmarks.
|
||||
pub(crate) struct Benchmark<Block, BA, C> {
|
||||
pub(crate) struct Benchmark<Block, C> {
|
||||
client: Arc<C>,
|
||||
params: BenchmarkParams,
|
||||
inherent_data: sp_inherents::InherentData,
|
||||
digest_items: Vec<DigestItem>,
|
||||
_p: PhantomData<(Block, BA)>,
|
||||
_p: PhantomData<Block>,
|
||||
}
|
||||
|
||||
impl<Block, BA, C> Benchmark<Block, BA, C>
|
||||
impl<Block, C> Benchmark<Block, C>
|
||||
where
|
||||
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
|
||||
BA: ClientBackend<Block>,
|
||||
C: BlockBuilderProvider<BA, Block, C>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ CallApiAt<Block>
|
||||
+ UsageProvider<Block>
|
||||
+ sp_blockchain::HeaderBackend<Block>,
|
||||
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
|
||||
{
|
||||
@@ -129,7 +129,13 @@ where
|
||||
&self,
|
||||
ext_builder: Option<&dyn ExtrinsicBuilder>,
|
||||
) -> Result<(Block, Option<u64>)> {
|
||||
let mut builder = self.client.new_block(Digest { logs: self.digest_items.clone() })?;
|
||||
let chain = self.client.usage_info().chain;
|
||||
let mut builder = BlockBuilderBuilder::new(&*self.client)
|
||||
.on_parent_block(chain.best_hash)
|
||||
.with_parent_block_number(chain.best_number)
|
||||
.with_inherent_digests(Digest { logs: self.digest_items.clone() })
|
||||
.build()?;
|
||||
|
||||
// Create and insert the inherents.
|
||||
let inherents = builder.create_inherents(self.inherent_data.clone())?;
|
||||
for inherent in inherents {
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||
use sc_client_api::Backend as ClientBackend;
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sc_client_api::UsageProvider;
|
||||
use sp_api::{ApiExt, CallApiAt, ProvideRuntimeApi};
|
||||
use sp_runtime::{traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
|
||||
|
||||
use clap::{Args, Parser};
|
||||
@@ -84,7 +84,7 @@ impl ExtrinsicCmd {
|
||||
/// Benchmark the execution time of a specific type of extrinsic.
|
||||
///
|
||||
/// The output will be printed to console.
|
||||
pub fn run<Block, BA, C>(
|
||||
pub fn run<Block, C>(
|
||||
&self,
|
||||
client: Arc<C>,
|
||||
inherent_data: sp_inherents::InherentData,
|
||||
@@ -93,9 +93,9 @@ impl ExtrinsicCmd {
|
||||
) -> Result<()>
|
||||
where
|
||||
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
|
||||
BA: ClientBackend<Block>,
|
||||
C: BlockBuilderProvider<BA, Block, C>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ CallApiAt<Block>
|
||||
+ UsageProvider<Block>
|
||||
+ sp_blockchain::HeaderBackend<Block>,
|
||||
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
|
||||
{
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
//! Contains the [`OverheadCmd`] as entry point for the CLI to execute
|
||||
//! the *overhead* benchmarks.
|
||||
|
||||
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
|
||||
use sc_block_builder::BlockBuilderApi;
|
||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||
use sc_client_api::Backend as ClientBackend;
|
||||
use sc_client_api::UsageProvider;
|
||||
use sc_service::Configuration;
|
||||
use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use sp_api::{ApiExt, CallApiAt, ProvideRuntimeApi};
|
||||
use sp_runtime::{traits::Block as BlockT, DigestItem, OpaqueExtrinsic};
|
||||
|
||||
use clap::{Args, Parser};
|
||||
@@ -97,7 +97,7 @@ impl OverheadCmd {
|
||||
///
|
||||
/// Writes the results to console and into two instances of the
|
||||
/// `weights.hbs` template, one for each benchmark.
|
||||
pub fn run<Block, BA, C>(
|
||||
pub fn run<Block, C>(
|
||||
&self,
|
||||
cfg: Configuration,
|
||||
client: Arc<C>,
|
||||
@@ -107,9 +107,9 @@ impl OverheadCmd {
|
||||
) -> Result<()>
|
||||
where
|
||||
Block: BlockT<Extrinsic = OpaqueExtrinsic>,
|
||||
BA: ClientBackend<Block>,
|
||||
C: BlockBuilderProvider<BA, Block, C>
|
||||
+ ProvideRuntimeApi<Block>
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ CallApiAt<Block>
|
||||
+ UsageProvider<Block>
|
||||
+ sp_blockchain::HeaderBackend<Block>,
|
||||
C::Api: ApiExt<Block> + BlockBuilderApi<Block>,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user