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
@@ -16,8 +16,10 @@
// 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 std::collections::{HashMap, HashSet};
use std::sync::Arc;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use finality_grandpa::{voter_set::VoterSet, Error as GrandpaError};
use parity_scale_codec::{Decode, Encode};
@@ -52,7 +54,8 @@ impl<Block: BlockT> GrandpaJustification<Block> {
client: &Arc<C>,
round: u64,
commit: Commit<Block>,
) -> Result<GrandpaJustification<Block>, Error> where
) -> Result<GrandpaJustification<Block>, Error>
where
C: HeaderBackend<Block>,
{
let mut votes_ancestries_hashes = HashSet::new();
@@ -66,12 +69,14 @@ impl<Block: BlockT> GrandpaJustification<Block> {
for signed in commit.precommits.iter() {
let mut current_hash = signed.precommit.target_hash;
loop {
if current_hash == commit.target_hash { break; }
if current_hash == commit.target_hash {
break
}
match client.header(BlockId::Hash(current_hash))? {
Some(current_header) => {
if *current_header.number() <= commit.target_number {
return error();
return error()
}
let parent_hash = *current_header.parent_hash();
@@ -95,20 +100,20 @@ impl<Block: BlockT> GrandpaJustification<Block> {
finalized_target: (Block::Hash, NumberFor<Block>),
set_id: u64,
voters: &VoterSet<AuthorityId>,
) -> Result<GrandpaJustification<Block>, ClientError> where
) -> Result<GrandpaJustification<Block>, ClientError>
where
NumberFor<Block>: finality_grandpa::BlockNumberOps,
{
let justification = GrandpaJustification::<Block>::decode(&mut &*encoded)
.map_err(|_| ClientError::JustificationDecode)?;
if (justification.commit.target_hash, justification.commit.target_number) != finalized_target {
if (justification.commit.target_hash, justification.commit.target_number) !=
finalized_target
{
let msg = "invalid commit target in grandpa justification".to_string();
Err(ClientError::BadJustification(msg))
} else {
justification
.verify_with_voter_set(set_id, voters)
.map(|_| justification)
justification.verify_with_voter_set(set_id, voters).map(|_| justification)
}
}
@@ -117,9 +122,8 @@ impl<Block: BlockT> GrandpaJustification<Block> {
where
NumberFor<Block>: finality_grandpa::BlockNumberOps,
{
let voters = VoterSet::new(authorities.iter().cloned()).ok_or(ClientError::Consensus(
sp_consensus::Error::InvalidAuthoritiesSet,
))?;
let voters = VoterSet::new(authorities.iter().cloned())
.ok_or(ClientError::Consensus(sp_consensus::Error::InvalidAuthoritiesSet))?;
self.verify_with_voter_set(set_id, &voters)
}
@@ -137,16 +141,12 @@ impl<Block: BlockT> GrandpaJustification<Block> {
let ancestry_chain = AncestryChain::<Block>::new(&self.votes_ancestries);
match finality_grandpa::validate_commit(
&self.commit,
voters,
&ancestry_chain,
) {
match finality_grandpa::validate_commit(&self.commit, voters, &ancestry_chain) {
Ok(ref result) if result.ghost().is_some() => {},
_ => {
let msg = "invalid commit in grandpa justification".to_string();
return Err(ClientError::BadJustification(msg));
}
return Err(ClientError::BadJustification(msg))
},
}
let mut buf = Vec::new();
@@ -161,11 +161,12 @@ impl<Block: BlockT> GrandpaJustification<Block> {
&mut buf,
) {
return Err(ClientError::BadJustification(
"invalid signature for precommit in grandpa justification".to_string()));
"invalid signature for precommit in grandpa justification".to_string(),
))
}
if self.commit.target_hash == signed.precommit.target_hash {
continue;
continue
}
match ancestry_chain.ancestry(self.commit.target_hash, signed.precommit.target_hash) {
@@ -176,21 +177,21 @@ impl<Block: BlockT> GrandpaJustification<Block> {
visited_hashes.insert(hash);
}
},
_ => {
_ =>
return Err(ClientError::BadJustification(
"invalid precommit ancestry proof in grandpa justification".to_string()));
},
"invalid precommit ancestry proof in grandpa justification".to_string(),
)),
}
}
let ancestry_hashes = self.votes_ancestries
.iter()
.map(|h: &Block::Header| h.hash())
.collect();
let ancestry_hashes =
self.votes_ancestries.iter().map(|h: &Block::Header| h.hash()).collect();
if visited_hashes != ancestry_hashes {
return Err(ClientError::BadJustification(
"invalid precommit ancestries in grandpa justification with unused headers".to_string()));
"invalid precommit ancestries in grandpa justification with unused headers"
.to_string(),
))
}
Ok(())
@@ -211,24 +212,28 @@ struct AncestryChain<Block: BlockT> {
impl<Block: BlockT> AncestryChain<Block> {
fn new(ancestry: &[Block::Header]) -> AncestryChain<Block> {
let ancestry: HashMap<_, _> = ancestry
.iter()
.cloned()
.map(|h: Block::Header| (h.hash(), h))
.collect();
let ancestry: HashMap<_, _> =
ancestry.iter().cloned().map(|h: Block::Header| (h.hash(), h)).collect();
AncestryChain { ancestry }
}
}
impl<Block: BlockT> finality_grandpa::Chain<Block::Hash, NumberFor<Block>> for AncestryChain<Block> where
NumberFor<Block>: finality_grandpa::BlockNumberOps
impl<Block: BlockT> finality_grandpa::Chain<Block::Hash, NumberFor<Block>> for AncestryChain<Block>
where
NumberFor<Block>: finality_grandpa::BlockNumberOps,
{
fn ancestry(&self, base: Block::Hash, block: Block::Hash) -> Result<Vec<Block::Hash>, GrandpaError> {
fn ancestry(
&self,
base: Block::Hash,
block: Block::Hash,
) -> Result<Vec<Block::Hash>, GrandpaError> {
let mut route = Vec::new();
let mut current_hash = block;
loop {
if current_hash == base { break; }
if current_hash == base {
break
}
match self.ancestry.get(&current_hash) {
Some(current_header) => {
current_hash = *current_header.parent_hash();