mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
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:
@@ -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,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user