removes use of sc_client::Client from node-transaction-factory (#5158)

* removes use of sc_client::Client from node-transaction-factory

* move sc-block-builder to [dev-dependencies] in substrate-test-runtime
This commit is contained in:
Seun Lanlege
2020-03-12 19:19:38 +01:00
committed by GitHub
parent 6f2aaf9d11
commit 3193b0d4aa
19 changed files with 60 additions and 43 deletions
+5
View File
@@ -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",
+1 -1
View File
@@ -94,7 +94,7 @@ where
);
let service_builder = new_full_start!(config).0;
node_transaction_factory::factory::<FactoryState<_>, _, _, _, _, _>(
node_transaction_factory::factory(
factory_state,
service_builder.client(),
service_builder.select_chain()
+1
View File
@@ -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"
+1
View File
@@ -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.
///
@@ -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" }
@@ -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<RA, Backend, Exec, Block, RtApi, Sc>(
pub fn factory<Backend, Block, Client, Sc, RA>(
mut factory_state: RA,
client: &Arc<Client<Backend, Exec, Block, RtApi>>,
client: &Arc<Client>,
select_chain: &Sc,
) -> sc_cli::Result<()>
where
Block: BlockT,
Exec: sc_client::CallExecutor<Block, Backend = Backend> + Send + Sync + Clone,
Backend: sc_client_api::backend::Backend<Block> + Send,
Client<Backend, Exec, Block, RtApi>: ProvideRuntimeApi<Block>,
<Client<Backend, Exec, Block, RtApi> as ProvideRuntimeApi<Block>>::Api:
BlockBuilder<Block, Error = sp_blockchain::Error> +
ApiExt<Block, StateBackend = Backend::State>,
RtApi: ConstructRuntimeApi<Block, Client<Backend, Exec, Block, RtApi>> + Send + Sync,
Sc: SelectChain<Block>,
RA: RuntimeAdapter<Block = Block>,
Block::Hash: From<sp_core::H256>,
where
Backend: sc_client_api::backend::Backend<Block> + Send,
Block: BlockT,
Client: BlockBuilderProvider<Backend, Block, Client> + CallApiAt<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block> + HeaderBackend<Block>,
Client::Api: BlockBuilder<Block, Error = sp_blockchain::Error> + ApiExt<Block, StateBackend = Backend::State>,
Sc: SelectChain<Block>,
RA: RuntimeAdapter<Block = Block>,
Block::Hash: From<sp_core::H256>,
for<'a> &'a Client: BlockImport<Block, Transaction = TransactionFor<Client, Block>>,
{
let best_header: Result<<Block as BlockT>::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::<Block>::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());
}
@@ -80,6 +80,12 @@ pub trait BlockBuilderProvider<B, Block, RA>
inherent_digests: DigestFor<Block>,
record_proof: R,
) -> sp_blockchain::Result<BlockBuilder<Block, RA, B>>;
/// Create a new block, built on the head of the chain.
fn new_block(
&self,
inherent_digests: DigestFor<Block>,
) -> sp_blockchain::Result<BlockBuilder<Block, RA, B>>;
}
/// Utility for building new (valid) blocks from a stream of extrinsics.
@@ -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" }
@@ -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;
@@ -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]
@@ -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<Block>) {
+1
View File
@@ -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" }
+1
View File
@@ -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() {
+1
View File
@@ -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::*,
+15 -22
View File
@@ -544,28 +544,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
Ok((storage, configs))
}
/// Create a new block, built on the head of the chain.
pub fn new_block(
&self,
inherent_digests: DigestFor<Block>,
) -> sp_blockchain::Result<sc_block_builder::BlockBuilder<Block, Self, B>> where
E: Clone + Send + Sync,
RA: Send + Sync,
Self: ProvideRuntimeApi<Block>,
<Self as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block, Error = Error> +
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
{
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<B, E, Block, RA> BlockBuilderProvider<B, Block, Self> for Client<B, E, Bloc
&self.backend
)
}
fn new_block(
&self,
inherent_digests: DigestFor<Block>,
) -> sp_blockchain::Result<sc_block_builder::BlockBuilder<Block, Self, B>> {
let info = self.chain_info();
sc_block_builder::BlockBuilder::new(
self,
info.best_hash,
info.best_number,
RecordProof::No,
inherent_digests,
&self.backend,
)
}
}
impl<B, E, Block, RA> ExecutorProvider<Block> for Client<B, E, Block, RA> where
@@ -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;
+1
View File
@@ -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");
+1
View File
@@ -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" }
+1
View File
@@ -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() {