Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+177 -163
View File
@@ -16,204 +16,218 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Client parts
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use sp_consensus_babe::BabeApi;
use crate::{ChainInfo, default_config};
use manual_seal::consensus::babe::{BabeConsensusDataProvider, SlotTimestampProvider};
use sp_keyring::sr25519::Keyring::Alice;
use std::str::FromStr;
use sp_runtime::traits::Header;
use crate::{default_config, ChainInfo};
use futures::channel::mpsc;
use jsonrpc_core::MetaIoHandler;
use manual_seal::{run_manual_seal, EngineCommand, ManualSealParams, import_queue, rpc::{ManualSeal, ManualSealApi}};
use manual_seal::{
consensus::babe::{BabeConsensusDataProvider, SlotTimestampProvider},
import_queue,
rpc::{ManualSeal, ManualSealApi},
run_manual_seal, EngineCommand, ManualSealParams,
};
use sc_client_api::backend::Backend;
use sc_service::{
build_network, spawn_tasks, BuildNetworkParams, SpawnTasksParams, TFullBackend,
TFullClient, TaskManager, new_full_parts, Configuration, ChainSpec, TaskExecutor,
build_network, new_full_parts, spawn_tasks, BuildNetworkParams, ChainSpec, Configuration,
SpawnTasksParams, TFullBackend, TFullClient, TaskExecutor, TaskManager,
};
use sc_transaction_pool::BasicPool;
use sc_transaction_pool_api::TransactionPool;
use sp_api::{ApiExt, ConstructRuntimeApi, Core, Metadata};
use sp_block_builder::BlockBuilder;
use sp_runtime::traits::Block as BlockT;
use sp_session::SessionKeys;
use sp_consensus_babe::BabeApi;
use sp_keyring::sr25519::Keyring::Alice;
use sp_offchain::OffchainWorkerApi;
use std::sync::Arc;
use sp_runtime::traits::{Block as BlockT, Header};
use sp_session::SessionKeys;
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use std::{str::FromStr, sync::Arc};
type ClientParts<T> = (
Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>>,
TaskManager,
Arc<TFullClient<<T as ChainInfo>::Block, <T as ChainInfo>::RuntimeApi, <T as ChainInfo>::Executor>>,
Arc<dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
InPoolTransaction = sc_transaction_pool::Transaction<
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>>,
mpsc::Sender<EngineCommand<<<T as ChainInfo>::Block as BlockT>::Hash>>,
Arc<TFullBackend<<T as ChainInfo>::Block>>,
Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>>,
TaskManager,
Arc<
TFullClient<
<T as ChainInfo>::Block,
<T as ChainInfo>::RuntimeApi,
<T as ChainInfo>::Executor,
>,
>,
Arc<
dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
InPoolTransaction = sc_transaction_pool::Transaction<
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>,
>,
mpsc::Sender<EngineCommand<<<T as ChainInfo>::Block as BlockT>::Hash>>,
Arc<TFullBackend<<T as ChainInfo>::Block>>,
);
/// Provide the config or chain spec for a given chain
pub enum ConfigOrChainSpec {
/// Configuration object
Config(Configuration),
/// Chain spec object
ChainSpec(Box<dyn ChainSpec>, TaskExecutor)
/// Configuration object
Config(Configuration),
/// Chain spec object
ChainSpec(Box<dyn ChainSpec>, TaskExecutor),
}
/// Creates all the client parts you need for [`Node`](crate::node::Node)
pub fn client_parts<T>(config_or_chain_spec: ConfigOrChainSpec) -> Result<ClientParts<T>, sc_service::Error>
where
T: ChainInfo + 'static,
<T::RuntimeApi as ConstructRuntimeApi<T::Block, TFullClient<T::Block, T::RuntimeApi, T::Executor>>>::RuntimeApi:
Core<T::Block> + Metadata<T::Block> + OffchainWorkerApi<T::Block> + SessionKeys<T::Block>
+ TaggedTransactionQueue<T::Block> + BlockBuilder<T::Block> + BabeApi<T::Block>
+ ApiExt<T::Block, StateBackend = <TFullBackend<T::Block> as Backend<T::Block>>::State>,
<T::Runtime as frame_system::Config>::Call: From<frame_system::Call<T::Runtime>>,
<<T as ChainInfo>::Block as BlockT>::Hash: FromStr,
<<<T as ChainInfo>::Block as BlockT>::Header as Header>::Number: num_traits::cast::AsPrimitive<usize>,
pub fn client_parts<T>(
config_or_chain_spec: ConfigOrChainSpec,
) -> Result<ClientParts<T>, sc_service::Error>
where
T: ChainInfo + 'static,
<T::RuntimeApi as ConstructRuntimeApi<
T::Block,
TFullClient<T::Block, T::RuntimeApi, T::Executor>,
>>::RuntimeApi: Core<T::Block>
+ Metadata<T::Block>
+ OffchainWorkerApi<T::Block>
+ SessionKeys<T::Block>
+ TaggedTransactionQueue<T::Block>
+ BlockBuilder<T::Block>
+ BabeApi<T::Block>
+ ApiExt<T::Block, StateBackend = <TFullBackend<T::Block> as Backend<T::Block>>::State>,
<T::Runtime as frame_system::Config>::Call: From<frame_system::Call<T::Runtime>>,
<<T as ChainInfo>::Block as BlockT>::Hash: FromStr,
<<<T as ChainInfo>::Block as BlockT>::Header as Header>::Number:
num_traits::cast::AsPrimitive<usize>,
{
use sp_consensus_babe::AuthorityId;
let config = match config_or_chain_spec {
ConfigOrChainSpec::Config(config) => config,
ConfigOrChainSpec::ChainSpec(chain_spec, task_executor) => {
default_config(task_executor, chain_spec)
},
};
use sp_consensus_babe::AuthorityId;
let config = match config_or_chain_spec {
ConfigOrChainSpec::Config(config) => config,
ConfigOrChainSpec::ChainSpec(chain_spec, task_executor) =>
default_config(task_executor, chain_spec),
};
let (client, backend, keystore, mut task_manager) =
new_full_parts::<T::Block, T::RuntimeApi, T::Executor>(&config, None)?;
let client = Arc::new(client);
let (client, backend, keystore, mut task_manager) =
new_full_parts::<T::Block, T::RuntimeApi, T::Executor>(&config, None)?;
let client = Arc::new(client);
let select_chain = sc_consensus::LongestChain::new(backend.clone());
let select_chain = sc_consensus::LongestChain::new(backend.clone());
let (grandpa_block_import, ..) =
grandpa::block_import(client.clone(), &(client.clone() as Arc<_>), select_chain.clone(), None)?;
let (grandpa_block_import, ..) = grandpa::block_import(
client.clone(),
&(client.clone() as Arc<_>),
select_chain.clone(),
None,
)?;
let slot_duration = sc_consensus_babe::Config::get_or_compute(&*client)?;
let (block_import, babe_link) = sc_consensus_babe::block_import(
slot_duration.clone(),
grandpa_block_import,
client.clone(),
)?;
let slot_duration = sc_consensus_babe::Config::get_or_compute(&*client)?;
let (block_import, babe_link) = sc_consensus_babe::block_import(
slot_duration.clone(),
grandpa_block_import,
client.clone(),
)?;
let consensus_data_provider = BabeConsensusDataProvider::new(
client.clone(),
keystore.sync_keystore(),
babe_link.epoch_changes().clone(),
vec![(AuthorityId::from(Alice.public()), 1000)],
)
.expect("failed to create ConsensusDataProvider");
let consensus_data_provider = BabeConsensusDataProvider::new(
client.clone(),
keystore.sync_keystore(),
babe_link.epoch_changes().clone(),
vec![(AuthorityId::from(Alice.public()), 1000)],
)
.expect("failed to create ConsensusDataProvider");
let import_queue =
import_queue(Box::new(block_import.clone()), &task_manager.spawn_essential_handle(), None);
let import_queue =
import_queue(Box::new(block_import.clone()), &task_manager.spawn_essential_handle(), None);
let transaction_pool = BasicPool::new_full(
config.transaction_pool.clone(),
true.into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);
let transaction_pool = BasicPool::new_full(
config.transaction_pool.clone(),
true.into(),
config.prometheus_registry(),
task_manager.spawn_essential_handle(),
client.clone(),
);
let (network, system_rpc_tx, network_starter) = {
let params = BuildNetworkParams {
config: &config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: None,
};
build_network(params)?
};
let (network, system_rpc_tx, network_starter) = {
let params = BuildNetworkParams {
config: &config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: None,
};
build_network(params)?
};
// offchain workers
sc_service::build_offchain_workers(
&config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
);
// offchain workers
sc_service::build_offchain_workers(
&config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
);
// Proposer object for block authorship.
let env = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool.clone(),
config.prometheus_registry(),
None
);
// Proposer object for block authorship.
let env = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool.clone(),
config.prometheus_registry(),
None,
);
// Channel for the rpc handler to communicate with the authorship task.
let (command_sink, commands_stream) = mpsc::channel(10);
// Channel for the rpc handler to communicate with the authorship task.
let (command_sink, commands_stream) = mpsc::channel(10);
let rpc_sink = command_sink.clone();
let rpc_sink = command_sink.clone();
let rpc_handlers = {
let params = SpawnTasksParams {
config,
client: client.clone(),
backend: backend.clone(),
task_manager: &mut task_manager,
keystore: keystore.sync_keystore(),
on_demand: None,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder: Box::new(move |_, _| {
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
ManualSealApi::to_delegate(ManualSeal::new(rpc_sink.clone()))
);
io
}),
remote_blockchain: None,
network,
system_rpc_tx,
telemetry: None
};
spawn_tasks(params)?
};
let rpc_handlers = {
let params = SpawnTasksParams {
config,
client: client.clone(),
backend: backend.clone(),
task_manager: &mut task_manager,
keystore: keystore.sync_keystore(),
on_demand: None,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder: Box::new(move |_, _| {
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(ManualSealApi::to_delegate(ManualSeal::new(rpc_sink.clone())));
io
}),
remote_blockchain: None,
network,
system_rpc_tx,
telemetry: None,
};
spawn_tasks(params)?
};
let cloned_client = client.clone();
let create_inherent_data_providers = Box::new(move |_, _| {
let client = cloned_client.clone();
async move {
let timestamp = SlotTimestampProvider::new(client.clone()).map_err(|err| format!("{:?}", err))?;
let babe = sp_consensus_babe::inherents::InherentDataProvider::new(timestamp.slot().into());
Ok((timestamp, babe))
}
});
let cloned_client = client.clone();
let create_inherent_data_providers = Box::new(move |_, _| {
let client = cloned_client.clone();
async move {
let timestamp =
SlotTimestampProvider::new(client.clone()).map_err(|err| format!("{:?}", err))?;
let babe =
sp_consensus_babe::inherents::InherentDataProvider::new(timestamp.slot().into());
Ok((timestamp, babe))
}
});
// Background authorship future.
let authorship_future = run_manual_seal(ManualSealParams {
block_import,
env,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: Some(Box::new(consensus_data_provider)),
create_inherent_data_providers,
});
// Background authorship future.
let authorship_future = run_manual_seal(ManualSealParams {
block_import,
env,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: Some(Box::new(consensus_data_provider)),
create_inherent_data_providers,
});
// spawn the authorship task as an essential task.
task_manager
.spawn_essential_handle()
.spawn("manual-seal", authorship_future);
// spawn the authorship task as an essential task.
task_manager.spawn_essential_handle().spawn("manual-seal", authorship_future);
network_starter.start_network();
let rpc_handler = rpc_handlers.io_handler();
network_starter.start_network();
let rpc_handler = rpc_handlers.io_handler();
Ok((
rpc_handler,
task_manager,
client,
transaction_pool,
command_sink,
backend,
))
Ok((rpc_handler, task_manager, client, transaction_pool, command_sink, backend))
}
@@ -73,12 +73,16 @@ macro_rules! override_host_functions {
pub struct SignatureVerificationOverride;
impl sp_wasm_interface::HostFunctions for SignatureVerificationOverride {
fn host_functions() -> Vec<&'static dyn sp_wasm_interface::Function> {
override_host_functions!(
"ext_crypto_ecdsa_verify_version_1", EcdsaVerify,
"ext_crypto_ed25519_verify_version_1", Ed25519Verify,
"ext_crypto_sr25519_verify_version_1", Sr25519Verify,
"ext_crypto_sr25519_verify_version_2", Sr25519VerifyV2,
)
}
fn host_functions() -> Vec<&'static dyn sp_wasm_interface::Function> {
override_host_functions!(
"ext_crypto_ecdsa_verify_version_1",
EcdsaVerify,
"ext_crypto_ed25519_verify_version_1",
Ed25519Verify,
"ext_crypto_sr25519_verify_version_1",
Sr25519Verify,
"ext_crypto_sr25519_verify_version_2",
Sr25519VerifyV2,
)
}
}
+15 -10
View File
@@ -187,12 +187,12 @@
//! fn simple_balances_test() {
//! // given
//! let config = NodeConfig {
//! execution_strategies: ExecutionStrategies {
//! syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! importing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! block_construction: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! execution_strategies: ExecutionStrategies {
//! syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! importing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! block_construction: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
//! },
//! chain_spec: Box::new(development_config()),
//! log_targets: vec![],
@@ -235,14 +235,14 @@ use sp_inherents::InherentDataProvider;
use sp_runtime::traits::{Block as BlockT, SignedExtension};
mod client;
mod host_functions;
mod node;
mod utils;
mod host_functions;
pub use client::*;
pub use host_functions::*;
pub use node::*;
pub use utils::*;
pub use client::*;
/// Wrapper trait for concrete type required by this testing framework.
pub trait ChainInfo: Sized {
@@ -271,7 +271,10 @@ pub trait ChainInfo: Sized {
+ BlockImport<
Self::Block,
Error = sp_consensus::Error,
Transaction = TransactionFor<TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>, Self::Block>,
Transaction = TransactionFor<
TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
Self::Block,
>,
> + 'static;
/// The signed extras required by the runtime
@@ -281,5 +284,7 @@ pub trait ChainInfo: Sized {
type InherentDataProviders: InherentDataProvider + 'static;
/// Signed extras, this function is caled in an externalities provided environment.
fn signed_extras(from: <Self::Runtime as frame_system::Config>::AccountId) -> Self::SignedExtras;
fn signed_extras(
from: <Self::Runtime as frame_system::Config>::AccountId,
) -> Self::SignedExtras;
}
+72 -47
View File
@@ -18,21 +18,28 @@
use std::sync::Arc;
use futures::{FutureExt, SinkExt, channel::{mpsc, oneshot}};
use crate::ChainInfo;
use futures::{
channel::{mpsc, oneshot},
FutureExt, SinkExt,
};
use jsonrpc_core::MetaIoHandler;
use manual_seal::EngineCommand;
use sc_client_api::{backend::{self, Backend}, CallExecutor, ExecutorProvider};
use sc_client_api::{
backend::{self, Backend},
CallExecutor, ExecutorProvider,
};
use sc_service::{TFullBackend, TFullCallExecutor, TFullClient, TaskManager};
use sc_transaction_pool_api::TransactionPool;
use sp_api::{OverlayedChanges, StorageTransactionCache};
use sp_blockchain::HeaderBackend;
use sp_core::ExecutionContext;
use sp_runtime::{
generic::{BlockId, UncheckedExtrinsic},
traits::{Block as BlockT, Header, Extrinsic, NumberFor},
transaction_validity::TransactionSource, MultiSignature, MultiAddress
traits::{Block as BlockT, Extrinsic, Header, NumberFor},
transaction_validity::TransactionSource,
MultiAddress, MultiSignature,
};
use crate::ChainInfo;
use sc_transaction_pool_api::TransactionPool;
use sp_state_machine::Ext;
/// This holds a reference to a running node on another thread,
@@ -46,36 +53,8 @@ pub struct Node<T: ChainInfo> {
/// client instance
client: Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>>,
/// transaction pool
pool: Arc<dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
InPoolTransaction = sc_transaction_pool::Transaction<
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>>,
/// channel to communicate with manual seal on.
manual_seal_command_sink: mpsc::Sender<EngineCommand<<T::Block as BlockT>::Hash>>,
/// backend type.
backend: Arc<TFullBackend<T::Block>>,
/// Block number at initialization of this Node.
initial_block_number: NumberFor<T::Block>
}
type EventRecord<T> = frame_system::EventRecord<<T as frame_system::Config>::Event, <T as frame_system::Config>::Hash>;
impl<T> Node<T>
where
T: ChainInfo,
<<T::Block as BlockT>::Header as Header>::Number: From<u32>,
{
/// Creates a new node.
pub fn new(
rpc_handler: Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>>,
task_manager: TaskManager,
client: Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>>,
pool: Arc<dyn TransactionPool<
pool: Arc<
dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
@@ -83,7 +62,42 @@ impl<T> Node<T>
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>>,
>,
>,
/// channel to communicate with manual seal on.
manual_seal_command_sink: mpsc::Sender<EngineCommand<<T::Block as BlockT>::Hash>>,
/// backend type.
backend: Arc<TFullBackend<T::Block>>,
/// Block number at initialization of this Node.
initial_block_number: NumberFor<T::Block>,
}
type EventRecord<T> = frame_system::EventRecord<
<T as frame_system::Config>::Event,
<T as frame_system::Config>::Hash,
>;
impl<T> Node<T>
where
T: ChainInfo,
<<T::Block as BlockT>::Header as Header>::Number: From<u32>,
{
/// Creates a new node.
pub fn new(
rpc_handler: Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>>,
task_manager: TaskManager,
client: Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>>,
pool: Arc<
dyn TransactionPool<
Block = <T as ChainInfo>::Block,
Hash = <<T as ChainInfo>::Block as BlockT>::Hash,
Error = sc_transaction_pool::error::Error,
InPoolTransaction = sc_transaction_pool::Transaction<
<<T as ChainInfo>::Block as BlockT>::Hash,
<<T as ChainInfo>::Block as BlockT>::Extrinsic,
>,
>,
>,
command_sink: mpsc::Sender<EngineCommand<<T::Block as BlockT>::Hash>>,
backend: Arc<TFullBackend<T::Block>>,
) -> Self {
@@ -102,10 +116,12 @@ impl<T> Node<T>
/// eg
/// ```ignore
/// let request = r#"{"jsonrpc":"2.0","method":"engine_createBlock","params": [true, true],"id":1}"#;
/// let response = node.rpc_handler()
/// let response = node.rpc_handler()
/// .handle_request_sync(request, Default::default());
/// ```
pub fn rpc_handler(&self) -> Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>> {
pub fn rpc_handler(
&self,
) -> Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>> {
self.rpc_handler.clone()
}
@@ -117,13 +133,18 @@ impl<T> Node<T>
/// Executes closure in an externalities provided environment.
pub fn with_state<R>(&self, closure: impl FnOnce() -> R) -> R
where
<TFullCallExecutor<T::Block, T::Executor> as CallExecutor<T::Block>>::Error: std::fmt::Debug,
<TFullCallExecutor<T::Block, T::Executor> as CallExecutor<T::Block>>::Error:
std::fmt::Debug,
{
let id = BlockId::Hash(self.client.info().best_hash);
let mut overlay = OverlayedChanges::default();
let changes_trie = backend::changes_tries_state_at_block(&id, self.backend.changes_trie_storage()).unwrap();
let mut cache =
StorageTransactionCache::<T::Block, <TFullBackend<T::Block> as Backend<T::Block>>::State>::default();
let changes_trie =
backend::changes_tries_state_at_block(&id, self.backend.changes_trie_storage())
.unwrap();
let mut cache = StorageTransactionCache::<
T::Block,
<TFullBackend<T::Block> as Backend<T::Block>>::State,
>::default();
let mut extensions = self
.client
.execution_extensions()
@@ -176,7 +197,9 @@ impl<T> Node<T>
.expect("UncheckedExtrinsic::new() always returns Some");
let at = self.client.info().best_hash;
self.pool.submit_one(&BlockId::Hash(at), TransactionSource::Local, ext.into()).await
self.pool
.submit_one(&BlockId::Hash(at), TransactionSource::Local, ext.into())
.await
}
/// Get the events of the most recently produced block
@@ -186,7 +209,7 @@ impl<T> Node<T>
/// Instructs manual seal to seal new, possibly empty blocks.
pub async fn seal_blocks(&self, num: usize) {
let mut sink = self.manual_seal_command_sink.clone();
let mut sink = self.manual_seal_command_sink.clone();
for count in 0..num {
let (sender, future_block) = oneshot::channel();
@@ -201,8 +224,10 @@ impl<T> Node<T>
future.await.expect(ERROR);
match future_block.await.expect(ERROR) {
Ok(block) => log::info!("sealed {} (hash: {}) of {} blocks", count + 1, block.hash, num),
Err(err) => log::error!("failed to seal block {} of {}, error: {:?}", count + 1, num, err),
Ok(block) =>
log::info!("sealed {} (hash: {}) of {} blocks", count + 1, block.hash, num),
Err(err) =>
log::error!("failed to seal block {} of {}, error: {:?}", count + 1, num, err),
}
}
}
+19 -21
View File
@@ -16,18 +16,20 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use futures::FutureExt;
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_executor::WasmExecutionMethod;
use sc_informant::OutputFormat;
use sc_network::{
config::{NetworkConfiguration, Role, TransportConfig},
multiaddr,
};
use sc_service::{
BasePath, ChainSpec, Configuration, TaskExecutor,
DatabaseConfig, KeepBlocks, TransactionStorageMode, TaskType,
config::KeystoreConfig, BasePath, ChainSpec, Configuration, DatabaseConfig, KeepBlocks,
TaskExecutor, TaskType, TransactionStorageMode,
};
use sp_keyring::sr25519::Keyring::Alice;
use sc_network::{multiaddr, config::{NetworkConfiguration, TransportConfig, Role}};
use sc_informant::OutputFormat;
use sc_service::config::KeystoreConfig;
use sc_executor::WasmExecutionMethod;
use sc_client_api::execution_extensions::ExecutionStrategies;
use tokio::runtime::Handle;
use futures::FutureExt;
pub use sc_cli::build_runtime;
@@ -41,7 +43,10 @@ pub fn base_path() -> BasePath {
}
/// Produces a default configuration object, suitable for use with most set ups.
pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn ChainSpec>) -> Configuration {
pub fn default_config(
task_executor: TaskExecutor,
mut chain_spec: Box<dyn ChainSpec>,
) -> Configuration {
let base_path = base_path();
let root_path = base_path.path().to_path_buf().join("chains").join(chain_spec.id());
@@ -62,9 +67,7 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn Chain
let informant_output_format = OutputFormat { enable_color: false };
network_config.allow_non_globals_in_dht = true;
network_config
.listen_addresses
.push(multiaddr::Protocol::Memory(0).into());
network_config.listen_addresses.push(multiaddr::Protocol::Memory(0).into());
network_config.transport = TransportConfig::MemoryOnly;
@@ -75,14 +78,8 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn Chain
task_executor: task_executor.into(),
transaction_pool: Default::default(),
network: network_config,
keystore: KeystoreConfig::Path {
path: root_path.join("key"),
password: None,
},
database: DatabaseConfig::RocksDb {
path: root_path.join("db"),
cache_size: 128,
},
keystore: KeystoreConfig::Path { path: root_path.join("key"), password: None },
database: DatabaseConfig::RocksDb { path: root_path.join("db"), cache_size: 128 },
state_cache_size: 16777216,
state_cache_child_ratio: None,
chain_spec,
@@ -129,7 +126,8 @@ pub fn default_config(task_executor: TaskExecutor, mut chain_spec: Box<dyn Chain
pub fn task_executor(handle: Handle) -> TaskExecutor {
let task_executor = move |fut, task_type| match task_type {
TaskType::Async => handle.spawn(fut).map(drop),
TaskType::Blocking => handle.spawn_blocking(move || futures::executor::block_on(fut)).map(drop),
TaskType::Blocking =>
handle.spawn_blocking(move || futures::executor::block_on(fut)).map(drop),
};
task_executor.into()