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
+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),
}
}
}