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
@@ -22,15 +22,15 @@
//! restrictions that are taken into account by the GRANDPA environment when
//! selecting a finality target to vote on.
use std::future::Future;
use std::sync::Arc;
use std::pin::Pin;
use std::{future::Future, pin::Pin, sync::Arc};
use dyn_clone::DynClone;
use sc_client_api::blockchain::HeaderBackend;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{Block as BlockT, Header, NumberFor, One, Zero};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header, NumberFor, One, Zero},
};
/// A future returned by a `VotingRule` to restrict a given vote, if any restriction is necessary.
pub type VotingRuleResult<Block> =
@@ -63,7 +63,8 @@ where
) -> VotingRuleResult<Block>;
}
impl<Block, B> VotingRule<Block, B> for () where
impl<Block, B> VotingRule<Block, B> for ()
where
Block: BlockT,
B: HeaderBackend<Block>,
{
@@ -83,7 +84,8 @@ impl<Block, B> VotingRule<Block, B> for () where
/// behind the best block.
#[derive(Clone)]
pub struct BeforeBestBlockBy<N>(N);
impl<Block, B> VotingRule<Block, B> for BeforeBestBlockBy<NumberFor<Block>> where
impl<Block, B> VotingRule<Block, B> for BeforeBestBlockBy<NumberFor<Block>>
where
Block: BlockT,
B: HeaderBackend<Block>,
{
@@ -97,7 +99,7 @@ impl<Block, B> VotingRule<Block, B> for BeforeBestBlockBy<NumberFor<Block>> wher
use sp_arithmetic::traits::Saturating;
if current_target.number().is_zero() {
return Box::pin(async { None });
return Box::pin(async { None })
}
// find the target number restricted by this rule
@@ -105,17 +107,13 @@ impl<Block, B> VotingRule<Block, B> for BeforeBestBlockBy<NumberFor<Block>> wher
// our current target is already lower than this rule would restrict
if target_number >= *current_target.number() {
return Box::pin(async { None });
return Box::pin(async { None })
}
let current_target = current_target.clone();
// find the block at the given target height
Box::pin(std::future::ready(find_target(
&*backend,
target_number.clone(),
&current_target,
)))
Box::pin(std::future::ready(find_target(&*backend, target_number.clone(), &current_target)))
}
}
@@ -125,7 +123,8 @@ impl<Block, B> VotingRule<Block, B> for BeforeBestBlockBy<NumberFor<Block>> wher
#[derive(Clone)]
pub struct ThreeQuartersOfTheUnfinalizedChain;
impl<Block, B> VotingRule<Block, B> for ThreeQuartersOfTheUnfinalizedChain where
impl<Block, B> VotingRule<Block, B> for ThreeQuartersOfTheUnfinalizedChain
where
Block: BlockT,
B: HeaderBackend<Block>,
{
@@ -150,15 +149,11 @@ impl<Block, B> VotingRule<Block, B> for ThreeQuartersOfTheUnfinalizedChain where
// our current target is already lower than this rule would restrict
if target_number >= *current_target.number() {
return Box::pin(async { None });
return Box::pin(async { None })
}
// find the block at the given target height
Box::pin(std::future::ready(find_target(
&*backend,
target_number,
current_target,
)))
Box::pin(std::future::ready(find_target(&*backend, target_number, current_target)))
}
}
@@ -167,7 +162,8 @@ fn find_target<Block, B>(
backend: &B,
target_number: NumberFor<Block>,
current_header: &Block::Header,
) -> Option<(Block::Hash, NumberFor<Block>)> where
) -> Option<(Block::Hash, NumberFor<Block>)>
where
Block: BlockT,
B: HeaderBackend<Block>,
{
@@ -184,11 +180,13 @@ fn find_target<Block, B>(
}
if *target_header.number() == target_number {
return Some((target_hash, target_number));
return Some((target_hash, target_number))
}
target_hash = *target_header.parent_hash();
target_header = backend.header(BlockId::Hash(target_hash)).ok()?
target_header = backend
.header(BlockId::Hash(target_hash))
.ok()?
.expect("Header known to exist due to the existence of one of its descendents; qed");
}
}
@@ -199,13 +197,12 @@ struct VotingRules<Block, B> {
impl<B, Block> Clone for VotingRules<B, Block> {
fn clone(&self) -> Self {
VotingRules {
rules: self.rules.clone(),
}
VotingRules { rules: self.rules.clone() }
}
}
impl<Block, B> VotingRule<Block, B> for VotingRules<Block, B> where
impl<Block, B> VotingRule<Block, B> for VotingRules<Block, B>
where
Block: BlockT,
B: HeaderBackend<Block> + 'static,
{
@@ -230,8 +227,8 @@ impl<Block, B> VotingRule<Block, B> for VotingRules<Block, B> where
.await
.filter(|(_, restricted_number)| {
// NOTE: we can only restrict votes within the interval [base, target)
restricted_number >= base.number()
&& restricted_number < restricted_target.number()
restricted_number >= base.number() &&
restricted_number < restricted_target.number()
})
.and_then(|(hash, _)| backend.header(BlockId::Hash(hash)).ok())
.and_then(std::convert::identity)
@@ -257,7 +254,8 @@ pub struct VotingRulesBuilder<Block, B> {
rules: Vec<Box<dyn VotingRule<Block, B>>>,
}
impl<Block, B> Default for VotingRulesBuilder<Block, B> where
impl<Block, B> Default for VotingRulesBuilder<Block, B>
where
Block: BlockT,
B: HeaderBackend<Block> + 'static,
{
@@ -268,19 +266,19 @@ impl<Block, B> Default for VotingRulesBuilder<Block, B> where
}
}
impl<Block, B> VotingRulesBuilder<Block, B> where
impl<Block, B> VotingRulesBuilder<Block, B>
where
Block: BlockT,
B: HeaderBackend<Block> + 'static,
{
/// Return a new voting rule builder using the given backend.
pub fn new() -> Self {
VotingRulesBuilder {
rules: Vec::new(),
}
VotingRulesBuilder { rules: Vec::new() }
}
/// Add a new voting rule to the builder.
pub fn add<R>(mut self, rule: R) -> Self where
pub fn add<R>(mut self, rule: R) -> Self
where
R: VotingRule<Block, B> + 'static,
{
self.rules.push(Box::new(rule));
@@ -288,8 +286,9 @@ impl<Block, B> VotingRulesBuilder<Block, B> where
}
/// Add all given voting rules to the builder.
pub fn add_all<I>(mut self, rules: I) -> Self where
I: IntoIterator<Item=Box<dyn VotingRule<Block, B>>>,
pub fn add_all<I>(mut self, rules: I) -> Self
where
I: IntoIterator<Item = Box<dyn VotingRule<Block, B>>>,
{
self.rules.extend(rules);
self
@@ -298,13 +297,12 @@ impl<Block, B> VotingRulesBuilder<Block, B> where
/// Return a new `VotingRule` that applies all of the previously added
/// voting rules in-order.
pub fn build(self) -> impl VotingRule<Block, B> + Clone {
VotingRules {
rules: Arc::new(self.rules),
}
VotingRules { rules: Arc::new(self.rules) }
}
}
impl<Block, B> VotingRule<Block, B> for Box<dyn VotingRule<Block, B>> where
impl<Block, B> VotingRule<Block, B> for Box<dyn VotingRule<Block, B>>
where
Block: BlockT,
B: HeaderBackend<Block>,
Self: Clone,
@@ -358,33 +356,19 @@ mod tests {
fn multiple_voting_rules_cannot_restrict_past_base() {
// setup an aggregate voting rule composed of two voting rules
// where each subtracts 50 blocks from the current target
let rule = VotingRulesBuilder::new()
.add(Subtract(50))
.add(Subtract(50))
.build();
let rule = VotingRulesBuilder::new().add(Subtract(50)).add(Subtract(50)).build();
let mut client = Arc::new(TestClientBuilder::new().build());
for _ in 0..200 {
let block = client
.new_block(Default::default())
.unwrap()
.build()
.unwrap()
.block;
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap();
}
let genesis = client
.header(&BlockId::Number(0u32.into()))
.unwrap()
.unwrap();
let genesis = client.header(&BlockId::Number(0u32.into())).unwrap().unwrap();
let best = client
.header(&BlockId::Hash(client.info().best_hash))
.unwrap()
.unwrap();
let best = client.header(&BlockId::Hash(client.info().best_hash)).unwrap().unwrap();
let (_, number) =
futures::executor::block_on(rule.restrict_vote(client.clone(), &genesis, &best, &best))
@@ -394,10 +378,7 @@ mod tests {
// which means that we should be voting for block #100
assert_eq!(number, 100);
let block110 = client
.header(&BlockId::Number(110u32.into()))
.unwrap()
.unwrap();
let block110 = client.header(&BlockId::Number(110u32.into())).unwrap().unwrap();
let (_, number) = futures::executor::block_on(rule.restrict_vote(
client.clone(),