diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index dffb02b035..1cb703fd5f 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -3656,6 +3656,7 @@ dependencies = [ "pallet-transaction-payment", "pallet-treasury", "parity-scale-codec", + "sc-block-builder", "sc-cli", "sc-client", "sc-client-api", @@ -3684,6 +3685,7 @@ version = "0.8.0-alpha.3" dependencies = [ "log 0.4.8", "parity-scale-codec", + "sc-block-builder", "sc-cli", "sc-client", "sc-client-api", @@ -5834,6 +5836,7 @@ dependencies = [ "log 0.4.8", "parity-scale-codec", "parking_lot 0.10.0", + "sc-block-builder", "sc-client", "sc-client-api", "sc-consensus-slots", @@ -6338,6 +6341,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.10.0", "rustc-hex", + "sc-block-builder", "sc-client", "sc-client-api", "sc-executor", @@ -7781,6 +7785,7 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "parity-util-mem", + "sc-block-builder", "sc-client", "sc-executor", "serde", diff --git a/substrate/bin/node/cli/src/command.rs b/substrate/bin/node/cli/src/command.rs index a97257ddd7..21584f0898 100644 --- a/substrate/bin/node/cli/src/command.rs +++ b/substrate/bin/node/cli/src/command.rs @@ -94,7 +94,7 @@ where ); let service_builder = new_full_start!(config).0; - node_transaction_factory::factory::, _, _, _, _, _>( + node_transaction_factory::factory( factory_state, service_builder.client(), service_builder.select_chain() diff --git a/substrate/bin/node/testing/Cargo.toml b/substrate/bin/node/testing/Cargo.toml index 4496047b50..97d76467fe 100644 --- a/substrate/bin/node/testing/Cargo.toml +++ b/substrate/bin/node/testing/Cargo.toml @@ -41,6 +41,7 @@ sp-api = { version = "2.0.0-alpha.2", path = "../../../primitives/api" } sp-finality-tracker = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/finality-tracker" } sp-timestamp = { version = "2.0.0-alpha.2", default-features = false, path = "../../../primitives/timestamp" } sp-block-builder = { version = "2.0.0-alpha.2", path = "../../../primitives/block-builder" } +sc-block-builder = { version = "0.8.0-alpha.3", path = "../../../client/block-builder" } sp-inherents = { version = "2.0.0-alpha.2", path = "../../../primitives/inherents" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../../primitives/blockchain" } log = "0.4.8" diff --git a/substrate/bin/node/testing/src/bench.rs b/substrate/bin/node/testing/src/bench.rs index 797599c731..49949021b2 100644 --- a/substrate/bin/node/testing/src/bench.rs +++ b/substrate/bin/node/testing/src/bench.rs @@ -56,6 +56,7 @@ use sc_client_api::{ execution_extensions::{ExecutionExtensions, ExecutionStrategies}, }; use sp_core::{Pair, Public, sr25519}; +use sc_block_builder::BlockBuilderProvider; /// Keyring full of accounts for benching. /// diff --git a/substrate/bin/node/transaction-factory/Cargo.toml b/substrate/bin/node/transaction-factory/Cargo.toml index 25b4e960ba..44f2d87f9c 100644 --- a/substrate/bin/node/transaction-factory/Cargo.toml +++ b/substrate/bin/node/transaction-factory/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/paritytech/substrate/" sp-block-builder = { version = "2.0.0-alpha.2", path = "../../../primitives/block-builder" } sc-cli = { version = "0.8.0-alpha.2", path = "../../../client/cli" } sc-client-api = { version = "2.0.0-alpha.2", path = "../../../client/api" } +sc-block-builder = { version = "0.8.0-alpha.2", path = "../../../client/block-builder" } sc-client = { version = "0.8.0-alpha.2", path = "../../../client" } codec = { package = "parity-scale-codec", version = "1.2.0", features = ["derive"] } sp-consensus = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/common" } diff --git a/substrate/bin/node/transaction-factory/src/lib.rs b/substrate/bin/node/transaction-factory/src/lib.rs index a4c001145a..44cb178be1 100644 --- a/substrate/bin/node/transaction-factory/src/lib.rs +++ b/substrate/bin/node/transaction-factory/src/lib.rs @@ -26,12 +26,12 @@ use std::fmt::Display; use log::info; -use sc_client::Client; use sp_block_builder::BlockBuilder; -use sp_api::{ConstructRuntimeApi, ProvideRuntimeApi, ApiExt}; +use sc_block_builder::BlockBuilderProvider; +use sp_api::{ProvideRuntimeApi, ApiExt, CallApiAt, TransactionFor}; use sp_consensus::{ - BlockOrigin, BlockImportParams, InherentData, ForkChoiceStrategy, - SelectChain + BlockOrigin, BlockImportParams, InherentData, + ForkChoiceStrategy, SelectChain }; use sp_consensus::block_import::BlockImport; use codec::{Decode, Encode}; @@ -39,6 +39,7 @@ use sp_runtime::generic::BlockId; use sp_runtime::traits::{ Block as BlockT, Header as HeaderT, AtLeast32Bit, One, Zero, }; +use sp_blockchain::HeaderBackend; pub trait RuntimeAdapter { type AccountId: Display; @@ -79,30 +80,28 @@ pub trait RuntimeAdapter { } /// Manufactures transactions. The exact amount depends on `num` and `rounds`. -pub fn factory( +pub fn factory( mut factory_state: RA, - client: &Arc>, + client: &Arc, select_chain: &Sc, ) -> sc_cli::Result<()> -where - Block: BlockT, - Exec: sc_client::CallExecutor + Send + Sync + Clone, - Backend: sc_client_api::backend::Backend + Send, - Client: ProvideRuntimeApi, - as ProvideRuntimeApi>::Api: - BlockBuilder + - ApiExt, - RtApi: ConstructRuntimeApi> + Send + Sync, - Sc: SelectChain, - RA: RuntimeAdapter, - Block::Hash: From, + where + Backend: sc_client_api::backend::Backend + Send, + Block: BlockT, + Client: BlockBuilderProvider + CallApiAt + + ProvideRuntimeApi + HeaderBackend, + Client::Api: BlockBuilder + ApiExt, + Sc: SelectChain, + RA: RuntimeAdapter, + Block::Hash: From, + for<'a> &'a Client: BlockImport>, { let best_header: Result<::Header, sc_cli::Error> = select_chain.best_chain().map_err(|e| format!("{:?}", e).into()); let mut best_hash = best_header?.hash(); let mut best_block_id = BlockId::::hash(best_hash); let version = client.runtime_version_at(&best_block_id)?.spec_version; - let genesis_hash = client.block_hash(Zero::zero())? + let genesis_hash = client.hash(Zero::zero())? .expect("Genesis block always exists; qed").into(); while factory_state.block_number() < factory_state.blocks() { @@ -159,7 +158,7 @@ where let mut import = BlockImportParams::new(BlockOrigin::File, block.header().clone()); import.body = Some(block.extrinsics().to_vec()); import.fork_choice = Some(ForkChoiceStrategy::LongestChain); - client.clone().import_block(import, HashMap::new()).expect("Failed to import block"); + (&**client).import_block(import, HashMap::new()).expect("Failed to import block"); info!("Imported block at {}", factory_state.block_number()); } diff --git a/substrate/client/block-builder/src/lib.rs b/substrate/client/block-builder/src/lib.rs index d0e9f85ff4..480a759e30 100644 --- a/substrate/client/block-builder/src/lib.rs +++ b/substrate/client/block-builder/src/lib.rs @@ -80,6 +80,12 @@ pub trait BlockBuilderProvider inherent_digests: DigestFor, record_proof: R, ) -> sp_blockchain::Result>; + + /// Create a new block, built on the head of the chain. + fn new_block( + &self, + inherent_digests: DigestFor, + ) -> sp_blockchain::Result>; } /// Utility for building new (valid) blocks from a stream of extrinsics. diff --git a/substrate/client/consensus/aura/Cargo.toml b/substrate/client/consensus/aura/Cargo.toml index be610c16d9..f0b90f3819 100644 --- a/substrate/client/consensus/aura/Cargo.toml +++ b/substrate/client/consensus/aura/Cargo.toml @@ -12,6 +12,7 @@ repository = "https://github.com/paritytech/substrate/" sp-application-crypto = { version = "2.0.0-alpha.2", path = "../../../primitives/application-crypto" } sp-consensus-aura = { version = "0.8.0-alpha.2", path = "../../../primitives/consensus/aura" } sp-block-builder = { version = "2.0.0-alpha.2", path = "../../../primitives/block-builder" } +sc-block-builder = { version = "0.8.0-alpha.3", path = "../../../client/block-builder" } sc-client = { version = "0.8.0-alpha.2", path = "../../" } sc-client-api = { version = "2.0.0-alpha.2", path = "../../api" } codec = { package = "parity-scale-codec", version = "1.2.0" } diff --git a/substrate/client/consensus/aura/src/lib.rs b/substrate/client/consensus/aura/src/lib.rs index 5850228628..6bb87acd0e 100644 --- a/substrate/client/consensus/aura/src/lib.rs +++ b/substrate/client/consensus/aura/src/lib.rs @@ -833,6 +833,7 @@ mod tests { use sc_client::BlockchainEvents; use sp_consensus_aura::sr25519::AuthorityPair; use std::task::Poll; + use sc_block_builder::BlockBuilderProvider; type Error = sp_blockchain::Error; diff --git a/substrate/client/network/src/protocol/sync.rs b/substrate/client/network/src/protocol/sync.rs index 8157440dbc..ffbe6a096a 100644 --- a/substrate/client/network/src/protocol/sync.rs +++ b/substrate/client/network/src/protocol/sync.rs @@ -1407,6 +1407,7 @@ mod test { DefaultTestClientBuilderExt, TestClientBuilder, TestClientBuilderExt, }; use sp_blockchain::HeaderBackend; + use sc_block_builder::BlockBuilderProvider; use sp_consensus::block_validation::DefaultBlockAnnounceValidator; #[test] diff --git a/substrate/client/network/test/src/block_import.rs b/substrate/client/network/test/src/block_import.rs index 5b2a1266c6..aa6d275141 100644 --- a/substrate/client/network/test/src/block_import.rs +++ b/substrate/client/network/test/src/block_import.rs @@ -23,6 +23,7 @@ use sp_consensus::import_queue::{ use substrate_test_runtime_client::{self, prelude::*}; use substrate_test_runtime_client::runtime::{Block, Hash}; use sp_runtime::generic::BlockId; +use sc_block_builder::BlockBuilderProvider; use super::*; fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock) { diff --git a/substrate/client/rpc/Cargo.toml b/substrate/client/rpc/Cargo.toml index 9a8be85bec..f99e25b14e 100644 --- a/substrate/client/rpc/Cargo.toml +++ b/substrate/client/rpc/Cargo.toml @@ -27,6 +27,7 @@ sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" } sp-rpc = { version = "2.0.0-alpha.2", path = "../../primitives/rpc" } sp-state-machine = { version = "0.8.0-alpha.2", path = "../../primitives/state-machine" } sc-executor = { version = "0.8.0-alpha.2", path = "../executor" } +sc-block-builder = { version = "0.8.0-alpha.2", path = "../../client/block-builder" } sc-keystore = { version = "2.0.0-alpha.2", path = "../keystore" } sp-transaction-pool = { version = "2.0.0-alpha.2", path = "../../primitives/transaction-pool" } sp-blockchain = { version = "2.0.0-alpha.2", path = "../../primitives/blockchain" } diff --git a/substrate/client/rpc/src/chain/tests.rs b/substrate/client/rpc/src/chain/tests.rs index 02e4d2f163..68d904919b 100644 --- a/substrate/client/rpc/src/chain/tests.rs +++ b/substrate/client/rpc/src/chain/tests.rs @@ -22,6 +22,7 @@ use substrate_test_runtime_client::{ runtime::{H256, Block, Header}, }; use sp_rpc::list::ListOrValue; +use sc_block_builder::BlockBuilderProvider; #[test] fn should_return_header() { diff --git a/substrate/client/rpc/src/state/tests.rs b/substrate/client/rpc/src/state/tests.rs index a0ab11e977..6d7f7a4ef5 100644 --- a/substrate/client/rpc/src/state/tests.rs +++ b/substrate/client/rpc/src/state/tests.rs @@ -23,6 +23,7 @@ use assert_matches::assert_matches; use futures01::stream::Stream; use sp_core::{storage::{well_known_keys, ChildInfo}, ChangesTrieConfiguration}; use sp_core::hash::H256; +use sc_block_builder::BlockBuilderProvider; use sp_io::hashing::blake2_256; use substrate_test_runtime_client::{ prelude::*, diff --git a/substrate/client/src/client.rs b/substrate/client/src/client.rs index dcb889c5fb..f6feb0e858 100644 --- a/substrate/client/src/client.rs +++ b/substrate/client/src/client.rs @@ -544,28 +544,6 @@ impl Client where Ok((storage, configs)) } - /// Create a new block, built on the head of the chain. - pub fn new_block( - &self, - inherent_digests: DigestFor, - ) -> sp_blockchain::Result> where - E: Clone + Send + Sync, - RA: Send + Sync, - Self: ProvideRuntimeApi, - >::Api: BlockBuilderApi + - ApiExt> - { - let info = self.chain_info(); - sc_block_builder::BlockBuilder::new( - self, - info.best_hash, - info.best_number, - RecordProof::No, - inherent_digests, - &self.backend, - ) - } - /// Apply a checked and validated block to an operation. If a justification is provided /// then `finalized` *must* be true. fn apply_block( @@ -1201,6 +1179,21 @@ impl BlockBuilderProvider for Client, + ) -> sp_blockchain::Result> { + let info = self.chain_info(); + sc_block_builder::BlockBuilder::new( + self, + info.best_hash, + info.best_number, + RecordProof::No, + inherent_digests, + &self.backend, + ) + } } impl ExecutorProvider for Client where diff --git a/substrate/client/src/light/call_executor.rs b/substrate/client/src/light/call_executor.rs index 492755a88c..a08b0f4c44 100644 --- a/substrate/client/src/light/call_executor.rs +++ b/substrate/client/src/light/call_executor.rs @@ -297,6 +297,7 @@ mod tests { use crate::in_mem::Backend as InMemBackend; use sc_client_api::ProofProvider; use sp_runtime::traits::BlakeTwo256; + use sc_block_builder::BlockBuilderProvider; struct DummyCallExecutor; diff --git a/substrate/client/src/light/fetcher.rs b/substrate/client/src/light/fetcher.rs index 896126e4bd..b48e3a3b78 100644 --- a/substrate/client/src/light/fetcher.rs +++ b/substrate/client/src/light/fetcher.rs @@ -351,6 +351,7 @@ pub mod tests { use sp_state_machine::Backend; use super::*; use sc_client_api::{StorageProvider, ProofProvider}; + use sc_block_builder::BlockBuilderProvider; const CHILD_INFO_1: ChildInfo<'static> = ChildInfo::new_default(b"unique_id_1"); diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 96d91992af..b5ae15029a 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -43,6 +43,7 @@ trie-db = { version = "0.20.0", default-features = false } parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] } [dev-dependencies] +sc-block-builder = { version = "0.8.0-alpha.2", path = "../../client/block-builder" } sc-executor = { version = "0.8.0-alpha.2", path = "../../client/executor" } substrate-test-runtime-client = { version = "2.0.0-dev", path = "./client" } sp-state-machine = { version = "0.8.0-alpha.2", path = "../../primitives/state-machine" } diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index f4797f7ce9..655cf96006 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -952,6 +952,7 @@ mod tests { use sp_core::storage::well_known_keys::HEAP_PAGES; use sp_state_machine::ExecutionStrategy; use codec::Encode; + use sc_block_builder::BlockBuilderProvider; #[test] fn heap_pages_is_respected() {