Companion for #8949 (#3216)

* Remove Call part imports of the offences and authority discovery pallets

* Remove non-existent Call enum variants

* Move ValidateUnsigned impl to be under #[pallet::validate_unsigned] in claims pallet

* Remove unused imports

* Remove Call part import for randomness collective flip pallet

* update Substrate

Co-authored-by: parity-processbot <>
This commit is contained in:
Keith Yeung
2021-06-15 21:13:21 -07:00
committed by GitHub
parent 28ecc38646
commit 7d82d93f34
10 changed files with 222 additions and 225 deletions
+53 -49
View File
@@ -27,8 +27,7 @@ use sp_runtime::traits::Zero;
use sp_runtime::{
traits::{CheckedSub, SignedExtension, DispatchInfoOf}, RuntimeDebug,
transaction_validity::{
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction,
TransactionSource, TransactionValidityError,
TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,
},
};
use primitives::v1::ValidityError;
@@ -429,6 +428,53 @@ pub mod pallet {
Ok(Pays::No.into())
}
}
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
const PRIORITY: u64 = 100;
let (maybe_signer, maybe_statement) = match call {
// <weight>
// The weight of this logic is included in the `claim` dispatchable.
// </weight>
Call::claim(account, ethereum_signature) => {
let data = account.using_encoded(to_ascii_hex);
(Self::eth_recover(&ethereum_signature, &data, &[][..]), None)
}
// <weight>
// The weight of this logic is included in the `claim_attest` dispatchable.
// </weight>
Call::claim_attest(account, ethereum_signature, statement) => {
let data = account.using_encoded(to_ascii_hex);
(Self::eth_recover(&ethereum_signature, &data, &statement), Some(statement.as_slice()))
}
_ => return Err(InvalidTransaction::Call.into()),
};
let signer = maybe_signer
.ok_or(InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()))?;
let e = InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into());
ensure!(<Claims<T>>::contains_key(&signer), e);
let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
match Signing::<T>::get(signer) {
None => ensure!(maybe_statement.is_none(), e),
Some(s) => ensure!(Some(s.to_text()) == maybe_statement, e),
}
Ok(ValidTransaction {
priority: PRIORITY,
requires: vec![],
provides: vec![("claims", signer).encode()],
longevity: TransactionLongevity::max_value(),
propagate: true,
})
}
}
}
/// Converts the given binary data into ASCII-encoded hex. It will be twice the length.
@@ -503,52 +549,6 @@ impl<T: Config> Pallet<T> {
}
}
impl<T: Config> sp_runtime::traits::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
const PRIORITY: u64 = 100;
let (maybe_signer, maybe_statement) = match call {
// <weight>
// The weight of this logic is included in the `claim` dispatchable.
// </weight>
Call::claim(account, ethereum_signature) => {
let data = account.using_encoded(to_ascii_hex);
(Self::eth_recover(&ethereum_signature, &data, &[][..]), None)
}
// <weight>
// The weight of this logic is included in the `claim_attest` dispatchable.
// </weight>
Call::claim_attest(account, ethereum_signature, statement) => {
let data = account.using_encoded(to_ascii_hex);
(Self::eth_recover(&ethereum_signature, &data, &statement), Some(statement.as_slice()))
}
_ => return Err(InvalidTransaction::Call.into()),
};
let signer = maybe_signer
.ok_or(InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()))?;
let e = InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into());
ensure!(<Claims<T>>::contains_key(&signer), e);
let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into());
match Signing::<T>::get(signer) {
None => ensure!(maybe_statement.is_none(), e),
Some(s) => ensure!(Some(s.to_text()) == maybe_statement, e),
}
Ok(ValidTransaction {
priority: PRIORITY,
requires: vec![],
provides: vec![("claims", signer).encode()],
longevity: TransactionLongevity::max_value(),
propagate: true,
})
}
}
/// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are
/// otherwise free to place on chain.
#[derive(Encode, Decode, Clone, Eq, PartialEq)]
@@ -649,7 +649,11 @@ mod tests {
use parity_scale_codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, Identity},
transaction_validity::TransactionLongevity,
testing::Header,
};
use frame_support::{
assert_ok, assert_err, assert_noop, parameter_types,
ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::{ExistenceRequirement, GenesisBuild},