mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 05:21:03 +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:
@@ -261,7 +261,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{authorities::AuthoritySetChanges, BlockNumberOps, ClientError, SetId};
|
||||
use futures::executor::block_on;
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sc_block_builder::BlockBuilderBuilder;
|
||||
use sc_client_api::{apply_aux, LockImportRun};
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_consensus_grandpa::GRANDPA_ENGINE_ID as ID;
|
||||
@@ -323,7 +323,14 @@ mod tests {
|
||||
|
||||
let mut blocks = Vec::new();
|
||||
for _ in 0..number_of_blocks {
|
||||
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
||||
let block = BlockBuilderBuilder::new(&*client)
|
||||
.on_parent_block(client.chain_info().best_hash)
|
||||
.with_parent_block_number(client.chain_info().best_number)
|
||||
.build()
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
block_on(client.import(BlockOrigin::Own, block.clone())).unwrap();
|
||||
blocks.push(block);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ use tokio::runtime::Handle;
|
||||
|
||||
use authorities::AuthoritySet;
|
||||
use communication::grandpa_protocol_name;
|
||||
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
|
||||
use sc_block_builder::{BlockBuilder, BlockBuilderBuilder};
|
||||
use sc_consensus::LongestChain;
|
||||
use sp_application_crypto::key_types::GRANDPA;
|
||||
|
||||
@@ -897,8 +897,11 @@ async fn allows_reimporting_change_blocks() {
|
||||
let (mut block_import, ..) = net.make_block_import(client.clone());
|
||||
|
||||
let full_client = client.as_client();
|
||||
let mut builder = full_client
|
||||
.new_block_at(full_client.chain_info().genesis_hash, Default::default(), false)
|
||||
let mut builder = BlockBuilderBuilder::new(&*full_client)
|
||||
.on_parent_block(full_client.chain_info().best_hash)
|
||||
.fetch_parent_block_number(&*full_client)
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
add_scheduled_change(
|
||||
@@ -942,8 +945,11 @@ async fn test_bad_justification() {
|
||||
let (mut block_import, ..) = net.make_block_import(client.clone());
|
||||
|
||||
let full_client = client.as_client();
|
||||
let mut builder = full_client
|
||||
.new_block_at(full_client.chain_info().genesis_hash, Default::default(), false)
|
||||
let mut builder = BlockBuilderBuilder::new(&*full_client)
|
||||
.on_parent_block(full_client.chain_info().best_hash)
|
||||
.fetch_parent_block_number(&*full_client)
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
add_scheduled_change(
|
||||
@@ -1913,7 +1919,12 @@ async fn imports_justification_for_regular_blocks_on_import() {
|
||||
|
||||
// create a new block (without importing it)
|
||||
let generate_block = |parent| {
|
||||
let builder = full_client.new_block_at(parent, Default::default(), false).unwrap();
|
||||
let builder = BlockBuilderBuilder::new(&*full_client)
|
||||
.on_parent_block(parent)
|
||||
.fetch_parent_block_number(&*full_client)
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
builder.build().unwrap().block
|
||||
};
|
||||
|
||||
@@ -2042,8 +2053,7 @@ async fn revert_prunes_authority_changes() {
|
||||
|
||||
let peers = &[Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie];
|
||||
|
||||
type TestBlockBuilder<'a> =
|
||||
BlockBuilder<'a, Block, PeersFullClient, substrate_test_runtime_client::Backend>;
|
||||
type TestBlockBuilder<'a> = BlockBuilder<'a, Block, PeersFullClient>;
|
||||
let edit_block = |mut builder: TestBlockBuilder| {
|
||||
add_scheduled_change(
|
||||
&mut builder,
|
||||
|
||||
@@ -330,7 +330,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sc_block_builder::BlockBuilderBuilder;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_runtime::traits::Header as _;
|
||||
|
||||
@@ -371,7 +371,14 @@ mod tests {
|
||||
let mut hashes = Vec::with_capacity(200);
|
||||
|
||||
for _ in 0..200 {
|
||||
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
||||
let block = BlockBuilderBuilder::new(&*client)
|
||||
.on_parent_block(client.chain_info().best_hash)
|
||||
.with_parent_block_number(client.chain_info().best_number)
|
||||
.build()
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
hashes.push(block.hash());
|
||||
|
||||
futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
|
||||
@@ -414,7 +421,14 @@ mod tests {
|
||||
let n = 5;
|
||||
let mut hashes = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
||||
let block = BlockBuilderBuilder::new(&*client)
|
||||
.on_parent_block(client.chain_info().best_hash)
|
||||
.with_parent_block_number(client.chain_info().best_number)
|
||||
.build()
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
hashes.push(block.hash());
|
||||
|
||||
futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
|
||||
|
||||
@@ -322,7 +322,7 @@ mod tests {
|
||||
use crate::{AuthoritySetChanges, GrandpaJustification};
|
||||
use parity_scale_codec::Encode;
|
||||
use rand::prelude::*;
|
||||
use sc_block_builder::BlockBuilderProvider;
|
||||
use sc_block_builder::BlockBuilderBuilder;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use sp_consensus_grandpa::GRANDPA_ENGINE_ID;
|
||||
@@ -348,7 +348,11 @@ mod tests {
|
||||
let mut authority_set_changes = Vec::new();
|
||||
|
||||
for n in 1..=100 {
|
||||
let mut builder = client.new_block(Default::default()).unwrap();
|
||||
let mut 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 new_authorities = None;
|
||||
|
||||
// we will trigger an authority set change every 10 blocks
|
||||
|
||||
Reference in New Issue
Block a user