cargo +nightly fmt (#3540)

* cargo +nightly fmt

* add cargo-fmt check to ci

* update ci

* fmt

* fmt

* skip macro

* ignore bridges
This commit is contained in:
Shawn Tabrizi
2021-08-02 12:47:33 +02:00
committed by GitHub
parent 30e3012270
commit ff5d56fb76
350 changed files with 20617 additions and 21266 deletions
+11 -16
View File
@@ -16,16 +16,16 @@
//! Types relevant for approval.
pub use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof, Randomness};
pub use sp_consensus_babe::Slot;
pub use sp_consensus_vrf::schnorrkel::{Randomness, VRFOutput, VRFProof};
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::v1::{
CandidateHash, Hash, ValidatorIndex, ValidatorSignature, CoreIndex,
Header, BlockNumber, CandidateIndex,
BlockNumber, CandidateHash, CandidateIndex, CoreIndex, Hash, Header, ValidatorIndex,
ValidatorSignature,
};
use parity_scale_codec::{Encode, Decode};
use sp_consensus_babe as babe_primitives;
use sp_application_crypto::Public;
use sp_consensus_babe as babe_primitives;
/// Validators assigning to check a particular candidate are split up into tranches.
/// Earlier tranches of validators check first, with later tranches serving as backup.
@@ -168,13 +168,12 @@ impl UnsafeVRFOutput {
let pubkey = schnorrkel::PublicKey::from_bytes(author.as_slice())
.map_err(ApprovalError::SchnorrkelSignature)?;
let transcript = babe_primitives::make_transcript(
randomness,
self.slot,
epoch_index,
);
let transcript = babe_primitives::make_transcript(randomness, self.slot, epoch_index);
let inout = self.vrf_output.0.attach_input_hash(&pubkey, transcript)
let inout = self
.vrf_output
.0
.attach_input_hash(&pubkey, transcript)
.map_err(ApprovalError::SchnorrkelSignature)?;
Ok(RelayVRFStory(inout.make_bytes(RELAY_VRF_STORY_CONTEXT)))
}
@@ -200,11 +199,7 @@ pub fn babe_unsafe_vrf_info(header: &Header) -> Option<UnsafeVRFOutput> {
PreDigest::SecondaryPlain(_) => return None,
};
return Some(UnsafeVRFOutput {
vrf_output,
slot,
authority_index,
});
return Some(UnsafeVRFOutput { vrf_output, slot, authority_index })
}
}
@@ -23,7 +23,9 @@ use thiserror::Error;
use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::v1::{CandidateReceipt, DisputeStatement, SessionIndex, SessionInfo, ValidatorIndex};
use polkadot_primitives::v1::{
CandidateReceipt, DisputeStatement, SessionIndex, SessionInfo, ValidatorIndex,
};
use super::{InvalidDisputeVote, SignedDisputeStatement, ValidDisputeVote};
@@ -92,7 +94,6 @@ pub enum Error {
}
impl DisputeMessage {
/// Build a `SignedDisputeMessage` and check what can be checked.
///
/// This function checks that:
@@ -156,16 +157,12 @@ impl DisputeMessage {
let valid_kind = match valid_statement.statement() {
DisputeStatement::Valid(v) => v,
_ => {
return Err(Error::ValidStatementHasInvalidKind)
}
_ => return Err(Error::ValidStatementHasInvalidKind),
};
let invalid_kind = match invalid_statement.statement() {
DisputeStatement::Invalid(v) => v,
_ => {
return Err(Error::InvalidStatementHasValidKind)
}
_ => return Err(Error::InvalidStatementHasValidKind),
};
let valid_vote = ValidDisputeVote {
@@ -211,46 +208,51 @@ impl DisputeMessage {
impl UncheckedDisputeMessage {
/// Try to recover the two signed dispute votes from an `UncheckedDisputeMessage`.
pub fn try_into_signed_votes(self, session_info: &SessionInfo)
-> Result<(CandidateReceipt, (SignedDisputeStatement, ValidatorIndex), (SignedDisputeStatement, ValidatorIndex)), ()>
{
let Self {
candidate_receipt,
session_index,
valid_vote,
invalid_vote,
} = self;
pub fn try_into_signed_votes(
self,
session_info: &SessionInfo,
) -> Result<
(
CandidateReceipt,
(SignedDisputeStatement, ValidatorIndex),
(SignedDisputeStatement, ValidatorIndex),
),
(),
> {
let Self { candidate_receipt, session_index, valid_vote, invalid_vote } = self;
let candidate_hash = candidate_receipt.hash();
let vote_valid = {
let ValidDisputeVote {
validator_index,
signature,
kind,
} = valid_vote;
let validator_public = session_info.validators.get(validator_index.0 as usize).ok_or(())?.clone();
let ValidDisputeVote { validator_index, signature, kind } = valid_vote;
let validator_public =
session_info.validators.get(validator_index.0 as usize).ok_or(())?.clone();
(
SignedDisputeStatement::new_checked(
DisputeStatement::Valid(kind), candidate_hash, session_index, validator_public, signature
DisputeStatement::Valid(kind),
candidate_hash,
session_index,
validator_public,
signature,
)?,
validator_index
validator_index,
)
};
let vote_invalid = {
let InvalidDisputeVote {
validator_index,
signature,
kind,
} = invalid_vote;
let validator_public = session_info.validators.get(validator_index.0 as usize).ok_or(())?.clone();
let InvalidDisputeVote { validator_index, signature, kind } = invalid_vote;
let validator_public =
session_info.validators.get(validator_index.0 as usize).ok_or(())?.clone();
(
SignedDisputeStatement::new_checked(
DisputeStatement::Invalid(kind), candidate_hash, session_index, validator_public, signature
DisputeStatement::Invalid(kind),
candidate_hash,
session_index,
validator_public,
signature,
)?,
validator_index
validator_index,
)
};
+20 -23
View File
@@ -19,18 +19,17 @@ use std::convert::TryInto;
use parity_scale_codec::{Decode, Encode};
use sp_application_crypto::AppKey;
use sp_keystore::{CryptoStore, SyncCryptoStorePtr, Error as KeystoreError};
use sp_keystore::{CryptoStore, Error as KeystoreError, SyncCryptoStorePtr};
use super::{Statement, UncheckedSignedFullStatement};
use polkadot_primitives::v1::{
CandidateHash, CandidateReceipt, DisputeStatement, InvalidDisputeStatementKind,
SessionIndex, ValidDisputeStatementKind, ValidatorId, ValidatorIndex,
ValidatorSignature, SigningContext,
CandidateHash, CandidateReceipt, DisputeStatement, InvalidDisputeStatementKind, SessionIndex,
SigningContext, ValidDisputeStatementKind, ValidatorId, ValidatorIndex, ValidatorSignature,
};
use super::{UncheckedSignedFullStatement, Statement};
/// `DisputeMessage` and related types.
mod message;
pub use message::{DisputeMessage, UncheckedDisputeMessage, Error as DisputeMessageCheckError};
pub use message::{DisputeMessage, Error as DisputeMessageCheckError, UncheckedDisputeMessage};
/// A checked dispute statement from an associated validator.
#[derive(Debug, Clone)]
@@ -56,9 +55,8 @@ pub struct CandidateVotes {
impl CandidateVotes {
/// Get the set of all validators who have votes in the set, ascending.
pub fn voted_indices(&self) -> Vec<ValidatorIndex> {
let mut v: Vec<_> = self.valid.iter().map(|x| x.1).chain(
self.invalid.iter().map(|x| x.1)
).collect();
let mut v: Vec<_> =
self.valid.iter().map(|x| x.1).chain(self.invalid.iter().map(|x| x.1)).collect();
v.sort();
v.dedup();
@@ -76,18 +74,15 @@ impl SignedDisputeStatement {
validator_public: ValidatorId,
validator_signature: ValidatorSignature,
) -> Result<Self, ()> {
dispute_statement.check_signature(
&validator_public,
candidate_hash,
session_index,
&validator_signature,
).map(|_| SignedDisputeStatement {
dispute_statement,
candidate_hash,
validator_public,
validator_signature,
session_index,
})
dispute_statement
.check_signature(&validator_public, candidate_hash, session_index, &validator_signature)
.map(|_| SignedDisputeStatement {
dispute_statement,
candidate_hash,
validator_public,
validator_signature,
session_index,
})
}
/// Sign this statement with the given keystore and key. Pass `valid = true` to
@@ -111,10 +106,12 @@ impl SignedDisputeStatement {
ValidatorId::ID,
&validator_public.clone().into(),
&data,
).await?;
)
.await?;
let signature = match signature {
Some(sig) => sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?,
Some(sig) =>
sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?,
None => return Ok(None),
};
+15 -12
View File
@@ -22,23 +22,22 @@
#![deny(missing_docs)]
use std::pin::Pin;
use serde::{Serialize, Deserialize};
use futures::Future;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
pub use sp_core::traits::SpawnNamed;
pub use sp_consensus_babe::{
Epoch as BabeEpoch, BabeEpochConfiguration, AllowedSlots as BabeAllowedSlots,
AllowedSlots as BabeAllowedSlots, BabeEpochConfiguration, Epoch as BabeEpoch,
};
pub use sp_core::traits::SpawnNamed;
use polkadot_primitives::v1::{
BlakeTwo256, CandidateCommitments, CandidateHash, CollatorPair, CommittedCandidateReceipt,
CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId, OutboundHrmpMessage,
PersistedValidationData, Signed, UncheckedSigned, UpwardMessage, ValidationCode,
ValidatorIndex, SessionIndex, MAX_CODE_SIZE, MAX_POV_SIZE,
PersistedValidationData, SessionIndex, Signed, UncheckedSigned, UpwardMessage, ValidationCode,
ValidatorIndex, MAX_CODE_SIZE, MAX_POV_SIZE,
};
pub use polkadot_parachain::primitives::BlockData;
@@ -48,8 +47,8 @@ pub mod approval;
/// Disputes related types.
pub mod disputes;
pub use disputes::{
SignedDisputeStatement, UncheckedDisputeMessage, DisputeMessage, CandidateVotes, InvalidDisputeVote, ValidDisputeVote,
DisputeMessageCheckError,
CandidateVotes, DisputeMessage, DisputeMessageCheckError, InvalidDisputeVote,
SignedDisputeStatement, UncheckedDisputeMessage, ValidDisputeVote,
};
/// The bomb limit for decompressing code blobs.
@@ -230,7 +229,9 @@ pub struct CollationResult {
impl CollationResult {
/// Convert into the inner values.
pub fn into_inner(self) -> (Collation, Option<futures::channel::oneshot::Sender<SignedFullStatement>>) {
pub fn into_inner(
self,
) -> (Collation, Option<futures::channel::oneshot::Sender<SignedFullStatement>>) {
(self.collation, self.result_sender)
}
}
@@ -242,7 +243,10 @@ impl CollationResult {
///
/// Returns an optional [`CollationResult`].
pub type CollatorFn = Box<
dyn Fn(Hash, &PersistedValidationData) -> Pin<Box<dyn Future<Output = Option<CollationResult>> + Send>>
dyn Fn(
Hash,
&PersistedValidationData,
) -> Pin<Box<dyn Future<Output = Option<CollationResult>> + Send>>
+ Send
+ Sync,
>;
@@ -287,8 +291,7 @@ pub struct ErasureChunk {
#[cfg(not(target_os = "unknown"))]
pub fn maybe_compress_pov(pov: PoV) -> PoV {
let PoV { block_data: BlockData(raw) } = pov;
let raw = sp_maybe_compressed_blob::compress(&raw, POV_BOMB_LIMIT)
.unwrap_or(raw);
let raw = sp_maybe_compressed_blob::compress(&raw, POV_BOMB_LIMIT).unwrap_or(raw);
let pov = PoV { block_data: BlockData(raw) };
pov