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
+83 -75
View File
@@ -18,26 +18,35 @@
//! Chain api required for the transaction pool.
use std::{marker::PhantomData, pin::Pin, sync::Arc};
use codec::{Decode, Encode};
use futures::{
channel::{oneshot, mpsc}, future::{Future, FutureExt, ready, Ready}, lock::Mutex, SinkExt,
StreamExt,
channel::{mpsc, oneshot},
future::{ready, Future, FutureExt, Ready},
lock::Mutex,
SinkExt, StreamExt,
};
use std::{marker::PhantomData, pin::Pin, sync::Arc};
use prometheus_endpoint::Registry as PrometheusRegistry;
use sc_client_api::{
blockchain::HeaderBackend, light::{Fetcher, RemoteCallRequest, RemoteBodyRequest}, BlockBackend,
blockchain::HeaderBackend,
light::{Fetcher, RemoteBodyRequest, RemoteCallRequest},
BlockBackend,
};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_core::traits::SpawnEssentialNamed;
use sp_runtime::{
generic::BlockId, traits::{self, Block as BlockT, BlockIdTo, Header as HeaderT, Hash as HashT},
transaction_validity::{TransactionValidity, TransactionSource},
generic::BlockId,
traits::{self, Block as BlockT, BlockIdTo, Hash as HashT, Header as HeaderT},
transaction_validity::{TransactionSource, TransactionValidity},
};
use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
use sp_api::{ProvideRuntimeApi, ApiExt};
use prometheus_endpoint::Registry as PrometheusRegistry;
use sp_core::traits::SpawnEssentialNamed;
use crate::{metrics::{ApiMetrics, ApiMetricsExt}, error::{self, Error}, graph};
use crate::{
error::{self, Error},
graph,
metrics::{ApiMetrics, ApiMetricsExt},
};
/// The transaction pool logic for full client.
pub struct FullChainApi<Client, Block> {
@@ -63,7 +72,8 @@ fn spawn_validation_pool_task(
Some(task) => task.await,
}
}
}.boxed(),
}
.boxed(),
);
}
@@ -74,18 +84,16 @@ impl<Client, Block> FullChainApi<Client, Block> {
prometheus: Option<&PrometheusRegistry>,
spawner: &impl SpawnEssentialNamed,
) -> Self {
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| {
match r {
Err(err) => {
log::warn!(
target: "txpool",
"Failed to register transaction pool api prometheus metrics: {:?}",
err,
);
None
},
Ok(api) => Some(Arc::new(api))
}
let metrics = prometheus.map(ApiMetrics::register).and_then(|r| match r {
Err(err) => {
log::warn!(
target: "txpool",
"Failed to register transaction pool api prometheus metrics: {:?}",
err,
);
None
},
Ok(api) => Some(Arc::new(api)),
});
let (sender, receiver) = mpsc::channel(0);
@@ -106,15 +114,15 @@ impl<Client, Block> FullChainApi<Client, Block> {
impl<Client, Block> graph::ChainApi for FullChainApi<Client, Block>
where
Block: BlockT,
Client: ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
type Block = Block;
type Error = error::Error;
type ValidationFuture = Pin<
Box<dyn Future<Output = error::Result<TransactionValidity>> + Send>
>;
type ValidationFuture =
Pin<Box<dyn Future<Output = error::Result<TransactionValidity>> + Send>>;
type BodyFuture = Ready<error::Result<Option<Vec<<Self::Block as BlockT>::Extrinsic>>>>;
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
@@ -136,14 +144,16 @@ where
async move {
metrics.report(|m| m.validations_scheduled.inc());
validation_pool.lock()
validation_pool
.lock()
.await
.send(
async move {
let res = validate_transaction_blocking(&*client, &at, source, uxt);
let _ = tx.send(res);
metrics.report(|m| m.validations_finished.inc());
}.boxed()
}
.boxed(),
)
.await
.map_err(|e| Error::RuntimeApi(format!("Validation pool down: {:?}", e)))?;
@@ -152,30 +162,33 @@ where
Ok(r) => r,
Err(_) => Err(Error::RuntimeApi("Validation was canceled".into())),
}
}.boxed()
}
.boxed()
}
fn block_id_to_number(
&self,
at: &BlockId<Self::Block>,
) -> error::Result<Option<graph::NumberFor<Self>>> {
self.client.to_number(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
self.client
.to_number(at)
.map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
}
fn block_id_to_hash(
&self,
at: &BlockId<Self::Block>,
) -> error::Result<Option<graph::BlockHash<Self>>> {
self.client.to_hash(at).map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
self.client
.to_hash(at)
.map_err(|e| Error::BlockIdConversion(format!("{:?}", e)))
}
fn hash_and_length(
&self,
ex: &graph::ExtrinsicFor<Self>,
) -> (graph::ExtrinsicHash<Self>, usize) {
ex.using_encoded(|x| {
(<traits::HashFor::<Block> as traits::Hash>::hash(x), x.len())
})
ex.using_encoded(|x| (<traits::HashFor<Block> as traits::Hash>::hash(x), x.len()))
}
fn block_header(
@@ -196,7 +209,8 @@ fn validate_transaction_blocking<Client, Block>(
) -> error::Result<TransactionValidity>
where
Block: BlockT,
Client: ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
@@ -257,7 +271,8 @@ where
impl<Client, Block> FullChainApi<Client, Block>
where
Block: BlockT,
Client: ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client:
ProvideRuntimeApi<Block> + BlockBackend<Block> + BlockIdTo<Block> + HeaderBackend<Block>,
Client: Send + Sync + 'static,
Client::Api: TaggedTransactionQueue<Block>,
{
@@ -285,30 +300,25 @@ pub struct LightChainApi<Client, F, Block> {
impl<Client, F, Block> LightChainApi<Client, F, Block> {
/// Create new transaction pool logic.
pub fn new(client: Arc<Client>, fetcher: Arc<F>) -> Self {
LightChainApi {
client,
fetcher,
_phantom: Default::default(),
}
LightChainApi { client, fetcher, _phantom: Default::default() }
}
}
impl<Client, F, Block> graph::ChainApi for
LightChainApi<Client, F, Block> where
Block: BlockT,
Client: HeaderBackend<Block> + 'static,
F: Fetcher<Block> + 'static,
impl<Client, F, Block> graph::ChainApi for LightChainApi<Client, F, Block>
where
Block: BlockT,
Client: HeaderBackend<Block> + 'static,
F: Fetcher<Block> + 'static,
{
type Block = Block;
type Error = error::Error;
type ValidationFuture = Box<
dyn Future<Output = error::Result<TransactionValidity>> + Send + Unpin
>;
type ValidationFuture =
Box<dyn Future<Output = error::Result<TransactionValidity>> + Send + Unpin>;
type BodyFuture = Pin<
Box<
dyn Future<Output = error::Result<Option<Vec<<Self::Block as BlockT>::Extrinsic>>>>
+ Send
>
+ Send,
>,
>;
fn validate_transaction(
@@ -318,9 +328,11 @@ impl<Client, F, Block> graph::ChainApi for
uxt: graph::ExtrinsicFor<Self>,
) -> Self::ValidationFuture {
let header_hash = self.client.expect_block_hash_from_id(at);
let header_and_hash = header_hash
.and_then(|header_hash| self.client.expect_header(BlockId::Hash(header_hash))
.map(|header| (header_hash, header)));
let header_and_hash = header_hash.and_then(|header_hash| {
self.client
.expect_header(BlockId::Hash(header_hash))
.map(|header| (header_hash, header))
});
let (block, header) = match header_and_hash {
Ok((header_hash, header)) => (header_hash, header),
Err(err) => return Box::new(ready(Err(err.into()))),
@@ -333,13 +345,12 @@ impl<Client, F, Block> graph::ChainApi for
retry_count: None,
});
let remote_validation_request = remote_validation_request.then(move |result| {
let result: error::Result<TransactionValidity> = result
.map_err(Into::into)
.and_then(|result| Decode::decode(&mut &result[..])
.map_err(|e| Error::RuntimeApi(
format!("Error decoding tx validation result: {:?}", e)
))
);
let result: error::Result<TransactionValidity> =
result.map_err(Into::into).and_then(|result| {
Decode::decode(&mut &result[..]).map_err(|e| {
Error::RuntimeApi(format!("Error decoding tx validation result: {:?}", e))
})
});
ready(result)
});
@@ -364,30 +375,26 @@ impl<Client, F, Block> graph::ChainApi for
&self,
ex: &graph::ExtrinsicFor<Self>,
) -> (graph::ExtrinsicHash<Self>, usize) {
ex.using_encoded(|x| {
(<<Block::Header as HeaderT>::Hashing as HashT>::hash(x), x.len())
})
ex.using_encoded(|x| (<<Block::Header as HeaderT>::Hashing as HashT>::hash(x), x.len()))
}
fn block_body(&self, id: &BlockId<Self::Block>) -> Self::BodyFuture {
let header = self.client.header(*id)
let header = self
.client
.header(*id)
.and_then(|h| h.ok_or_else(|| sp_blockchain::Error::UnknownBlock(format!("{}", id))));
let header = match header {
Ok(header) => header,
Err(err) => {
log::warn!(target: "txpool", "Failed to query header: {:?}", err);
return Box::pin(ready(Ok(None)));
}
return Box::pin(ready(Ok(None)))
},
};
let fetcher = self.fetcher.clone();
async move {
let transactions = fetcher.remote_body({
RemoteBodyRequest {
header,
retry_count: None,
}
})
let transactions = fetcher
.remote_body(RemoteBodyRequest { header, retry_count: None })
.await
.unwrap_or_else(|e| {
log::warn!(target: "txpool", "Failed to fetch block body: {:?}", e);
@@ -395,7 +402,8 @@ impl<Client, F, Block> graph::ChainApi for
});
Ok(Some(transactions))
}.boxed()
}
.boxed()
}
fn block_header(