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
+46 -51
View File
@@ -18,34 +18,33 @@
//! Methods that light client could use to execute runtime calls.
use std::{
sync::Arc, panic::UnwindSafe, result, cell::RefCell,
};
use std::{cell::RefCell, panic::UnwindSafe, result, sync::Arc};
use codec::{Encode, Decode};
use codec::{Decode, Encode};
use hash_db::Hasher;
use sp_core::{
convert_hash, NativeOrEncoded, traits::{CodeExecutor, SpawnNamed},
};
use sp_runtime::{
generic::BlockId, traits::{Block as BlockT, Header as HeaderT, HashFor},
convert_hash,
traits::{CodeExecutor, SpawnNamed},
NativeOrEncoded,
};
use sp_externalities::Extensions;
use sp_state_machine::{
self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend,
execution_proof_check_on_trie_backend, ExecutionManager, StorageProof,
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT},
};
use sp_state_machine::{
self, create_proof_check_backend, execution_proof_check_on_trie_backend,
Backend as StateBackend, ExecutionManager, ExecutionStrategy, OverlayedChanges, StorageProof,
};
use hash_db::Hasher;
use sp_api::{ProofRecorder, StorageTransactionCache};
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use sc_client_api::{
backend::RemoteBackend,
light::RemoteCallRequest,
call_executor::CallExecutor,
backend::RemoteBackend, call_executor::CallExecutor, light::RemoteCallRequest,
};
use sc_executor::{RuntimeVersion, NativeVersion};
use sc_executor::{NativeVersion, RuntimeVersion};
/// Call executor that is able to execute calls only on genesis state.
///
@@ -64,19 +63,15 @@ impl<B, L> GenesisCallExecutor<B, L> {
impl<B, L: Clone> Clone for GenesisCallExecutor<B, L> {
fn clone(&self) -> Self {
GenesisCallExecutor {
backend: self.backend.clone(),
local: self.local.clone(),
}
GenesisCallExecutor { backend: self.backend.clone(), local: self.local.clone() }
}
}
impl<Block, B, Local> CallExecutor<Block> for
GenesisCallExecutor<B, Local>
where
Block: BlockT,
B: RemoteBackend<Block>,
Local: CallExecutor<Block>,
impl<Block, B, Local> CallExecutor<Block> for GenesisCallExecutor<B, Local>
where
Block: BlockT,
B: RemoteBackend<Block>,
Local: CallExecutor<Block>,
{
type Error = ClientError;
@@ -99,7 +94,7 @@ impl<Block, B, Local> CallExecutor<Block> for
fn contextual_call<
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
Result<NativeOrEncoded<R>, Self::Error>
Result<NativeOrEncoded<R>, Self::Error>,
) -> Result<NativeOrEncoded<R>, Self::Error>,
R: Encode + Decode + PartialEq,
NC: FnOnce() -> result::Result<R, sp_api::ApiError> + UnwindSafe,
@@ -114,7 +109,10 @@ impl<Block, B, Local> CallExecutor<Block> for
native_call: Option<NC>,
recorder: &Option<ProofRecorder<Block>>,
extensions: Option<Extensions>,
) -> ClientResult<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone {
) -> ClientResult<NativeOrEncoded<R>>
where
ExecutionManager<EM>: Clone,
{
// there's no actual way/need to specify native/wasm execution strategy on light node
// => we can safely ignore passed values
@@ -125,7 +123,7 @@ impl<Block, B, Local> CallExecutor<Block> for
Result<NativeOrEncoded<R>, Local::Error>,
) -> Result<NativeOrEncoded<R>, Local::Error>,
_,
NC
NC,
>(
&self.local,
at,
@@ -137,7 +135,8 @@ impl<Block, B, Local> CallExecutor<Block> for
native_call,
recorder,
extensions,
).map_err(|e| ClientError::Execution(Box::new(e.to_string()))),
)
.map_err(|e| ClientError::Execution(Box::new(e.to_string()))),
false => Err(ClientError::NotAvailableOnLightClient),
}
}
@@ -174,24 +173,19 @@ pub fn prove_execution<Block, S, E>(
method: &str,
call_data: &[u8],
) -> ClientResult<(Vec<u8>, StorageProof)>
where
Block: BlockT,
S: StateBackend<HashFor<Block>>,
E: CallExecutor<Block>,
where
Block: BlockT,
S: StateBackend<HashFor<Block>>,
E: CallExecutor<Block>,
{
let trie_state = state.as_trie_backend()
.ok_or_else(||
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as
Box<dyn sp_state_machine::Error>
)?;
let trie_state = state.as_trie_backend().ok_or_else(|| {
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof)
as Box<dyn sp_state_machine::Error>
})?;
// execute method + record execution proof
let (result, exec_proof) = executor.prove_at_trie_state(
&trie_state,
&mut Default::default(),
method,
call_data,
)?;
let (result, exec_proof) =
executor.prove_at_trie_state(&trie_state, &mut Default::default(), method, call_data)?;
Ok((result, exec_proof))
}
@@ -205,11 +199,11 @@ pub fn check_execution_proof<Header, E, H>(
request: &RemoteCallRequest<Header>,
remote_proof: StorageProof,
) -> ClientResult<Vec<u8>>
where
Header: HeaderT,
E: CodeExecutor + Clone + 'static,
H: Hasher,
H::Out: Ord + codec::Codec + 'static,
where
Header: HeaderT,
E: CodeExecutor + Clone + 'static,
H: Hasher,
H::Out: Ord + codec::Codec + 'static,
{
let local_state_root = request.header.state_root();
let root: H::Out = convert_hash(&local_state_root);
@@ -220,7 +214,8 @@ pub fn check_execution_proof<Header, E, H>(
// TODO: Remove when solved: https://github.com/paritytech/substrate/issues/5047
let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&trie_backend);
let runtime_code = backend_runtime_code.runtime_code()
let runtime_code = backend_runtime_code
.runtime_code()
.map_err(|_e| ClientError::RuntimeCodeMissing)?;
// execute method