Unverified Commit acd72ad0 authored by Keith Yeung's avatar Keith Yeung Committed by GitHub
Browse files

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 <>
parent 95f6aa20
Pipeline #142508 passed with stages
in 35 minutes and 31 seconds
This diff is collapsed.
...@@ -397,7 +397,7 @@ construct_runtime!( ...@@ -397,7 +397,7 @@ construct_runtime!(
BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage}, BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage},
BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage}, BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Aura: pallet_aura::{Pallet, Config<T>}, Aura: pallet_aura::{Pallet, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
......
...@@ -507,7 +507,7 @@ construct_runtime!( ...@@ -507,7 +507,7 @@ construct_runtime!(
BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event<T>}, BridgeDispatch: pallet_bridge_dispatch::{Pallet, Event<T>},
BridgeMillauMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>}, BridgeMillauMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Aura: pallet_aura::{Pallet, Config<T>}, Aura: pallet_aura::{Pallet, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
......
...@@ -27,8 +27,7 @@ use sp_runtime::traits::Zero; ...@@ -27,8 +27,7 @@ use sp_runtime::traits::Zero;
use sp_runtime::{ use sp_runtime::{
traits::{CheckedSub, SignedExtension, DispatchInfoOf}, RuntimeDebug, traits::{CheckedSub, SignedExtension, DispatchInfoOf}, RuntimeDebug,
transaction_validity::{ transaction_validity::{
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidity, ValidTransaction, InvalidTransaction, TransactionValidityError,
TransactionSource, TransactionValidityError,
}, },
}; };
use primitives::v1::ValidityError; use primitives::v1::ValidityError;
...@@ -429,6 +428,53 @@ pub mod pallet { ...@@ -429,6 +428,53 @@ pub mod pallet {
Ok(Pays::No.into()) 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. /// Converts the given binary data into ASCII-encoded hex. It will be twice the length.
...@@ -503,52 +549,6 @@ impl<T: Config> Pallet<T> { ...@@ -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 /// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are
/// otherwise free to place on chain. /// otherwise free to place on chain.
#[derive(Encode, Decode, Clone, Eq, PartialEq)] #[derive(Encode, Decode, Clone, Eq, PartialEq)]
...@@ -649,7 +649,11 @@ mod tests { ...@@ -649,7 +649,11 @@ mod tests {
use parity_scale_codec::Encode; use parity_scale_codec::Encode;
// The testing primitives are very useful for avoiding having to work with signatures // 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. // 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::{ use frame_support::{
assert_ok, assert_err, assert_noop, parameter_types, assert_ok, assert_err, assert_noop, parameter_types,
ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::{ExistenceRequirement, GenesisBuild}, ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::{ExistenceRequirement, GenesisBuild},
......
...@@ -451,7 +451,7 @@ mod tests { ...@@ -451,7 +451,7 @@ mod tests {
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Slots: slots::{Pallet, Call, Storage, Event<T>}, Slots: slots::{Pallet, Call, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage}, RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage},
} }
); );
......
...@@ -965,11 +965,9 @@ impl InstanceFilter<Call> for ProxyType { ...@@ -965,11 +965,9 @@ impl InstanceFilter<Call> for ProxyType {
// Specifically omitting the entire Balances pallet // Specifically omitting the entire Balances pallet
Call::Authorship(..) | Call::Authorship(..) |
Call::Staking(..) | Call::Staking(..) |
Call::Offences(..) |
Call::Session(..) | Call::Session(..) |
Call::Grandpa(..) | Call::Grandpa(..) |
Call::ImOnline(..) | Call::ImOnline(..) |
Call::AuthorityDiscovery(..) |
Call::Democracy(..) | Call::Democracy(..) |
Call::Council(..) | Call::Council(..) |
Call::TechnicalCommittee(..) | Call::TechnicalCommittee(..) |
...@@ -1401,12 +1399,12 @@ construct_runtime! { ...@@ -1401,12 +1399,12 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 5, Authorship: pallet_authorship::{Pallet, Call, Storage} = 5,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7, Offences: pallet_offences::{Pallet, Storage, Event} = 7,
Historical: session_historical::{Pallet} = 34, Historical: session_historical::{Pallet} = 34,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10,
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11, ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11,
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Call, Config} = 12, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 12,
// Governance stuff; uncallable initially. // Governance stuff; uncallable initially.
Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 13, Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 13,
......
...@@ -129,9 +129,8 @@ impl Filter<Call> for BaseFilter { ...@@ -129,9 +129,8 @@ impl Filter<Call> for BaseFilter {
Call::TechnicalMembership(_) | Call::Treasury(_) | Call::PhragmenElection(_) | Call::TechnicalMembership(_) | Call::Treasury(_) | Call::PhragmenElection(_) |
Call::System(_) | Call::Scheduler(_) | Call::Indices(_) | Call::System(_) | Call::Scheduler(_) | Call::Indices(_) |
Call::Babe(_) | Call::Timestamp(_) | Call::Balances(_) | Call::Babe(_) | Call::Timestamp(_) | Call::Balances(_) |
Call::Authorship(_) | Call::Staking(_) | Call::Offences(_) | Call::Authorship(_) | Call::Staking(_) |
Call::Session(_) | Call::Grandpa(_) | Call::ImOnline(_) | Call::Session(_) | Call::Grandpa(_) | Call::ImOnline(_) |
Call::AuthorityDiscovery(_) |
Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) | Call::Utility(_) | Call::Claims(_) | Call::Vesting(_) |
Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) | Call::Identity(_) | Call::Proxy(_) | Call::Multisig(_) |
Call::Bounties(_) | Call::Tips(_) | Call::ElectionProviderMultiPhase(_) Call::Bounties(_) | Call::Tips(_) | Call::ElectionProviderMultiPhase(_)
...@@ -904,11 +903,9 @@ impl InstanceFilter<Call> for ProxyType { ...@@ -904,11 +903,9 @@ impl InstanceFilter<Call> for ProxyType {
// Specifically omitting the entire Balances pallet // Specifically omitting the entire Balances pallet
Call::Authorship(..) | Call::Authorship(..) |
Call::Staking(..) | Call::Staking(..) |
Call::Offences(..) |
Call::Session(..) | Call::Session(..) |
Call::Grandpa(..) | Call::Grandpa(..) |
Call::ImOnline(..) | Call::ImOnline(..) |
Call::AuthorityDiscovery(..) |
Call::Democracy(..) | Call::Democracy(..) |
Call::Council(..) | Call::Council(..) |
Call::TechnicalCommittee(..) | Call::TechnicalCommittee(..) |
...@@ -998,12 +995,12 @@ construct_runtime! { ...@@ -998,12 +995,12 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 6, Authorship: pallet_authorship::{Pallet, Call, Storage} = 6,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 7, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 7,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 8, Offences: pallet_offences::{Pallet, Storage, Event} = 8,
Historical: session_historical::{Pallet} = 33, Historical: session_historical::{Pallet} = 33,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 9, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 9,
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 11, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 11,
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 12, ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 12,
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Call, Config} = 13, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 13,
// Governance stuff. // Governance stuff.
Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 14, Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 14,
......
...@@ -200,12 +200,12 @@ construct_runtime! { ...@@ -200,12 +200,12 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage}, Authorship: pallet_authorship::{Pallet, Call, Storage},
Offences: pallet_offences::{Pallet, Call, Storage, Event}, Offences: pallet_offences::{Pallet, Storage, Event},
Historical: session_historical::{Pallet}, Historical: session_historical::{Pallet},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>}, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned},
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>}, ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Call, Config}, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config},
// Parachains modules. // Parachains modules.
ParachainsOrigin: parachains_origin::{Pallet, Origin}, ParachainsOrigin: parachains_origin::{Pallet, Origin},
......
...@@ -517,11 +517,11 @@ construct_runtime! { ...@@ -517,11 +517,11 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage}, Authorship: pallet_authorship::{Pallet, Call, Storage},
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>}, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>},
Offences: pallet_offences::{Pallet, Call, Storage, Event}, Offences: pallet_offences::{Pallet, Storage, Event},
Historical: session_historical::{Pallet}, Historical: session_historical::{Pallet},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>}, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event}, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Call, Config}, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config},
// Claims. Usable initially. // Claims. Usable initially.
Claims: claims::{Pallet, Call, Storage, Event<T>, Config<T>, ValidateUnsigned}, Claims: claims::{Pallet, Call, Storage, Event<T>, Config<T>, ValidateUnsigned},
......
...@@ -659,11 +659,9 @@ impl InstanceFilter<Call> for ProxyType { ...@@ -659,11 +659,9 @@ impl InstanceFilter<Call> for ProxyType {
// Specifically omitting the entire Balances pallet // Specifically omitting the entire Balances pallet
Call::Authorship(..) | Call::Authorship(..) |
Call::Staking(..) | Call::Staking(..) |
Call::Offences(..) |
Call::Session(..) | Call::Session(..) |
Call::Grandpa(..) | Call::Grandpa(..) |
Call::ImOnline(..) | Call::ImOnline(..) |
Call::AuthorityDiscovery(..) |
Call::Utility(..) | Call::Utility(..) |
Call::Identity(..) | Call::Identity(..) |
Call::Recovery(pallet_recovery::Call::as_recovered(..)) | Call::Recovery(pallet_recovery::Call::as_recovered(..)) |
...@@ -1018,12 +1016,12 @@ construct_runtime! { ...@@ -1018,12 +1016,12 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 5, Authorship: pallet_authorship::{Pallet, Call, Storage} = 5,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7, Offences: pallet_offences::{Pallet, Storage, Event} = 7,
Historical: session_historical::{Pallet} = 27, Historical: session_historical::{Pallet} = 27,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10, Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event, ValidateUnsigned} = 10,
ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11, ImOnline: pallet_im_online::{Pallet, Call, Storage, Event<T>, ValidateUnsigned, Config<T>} = 11,
AuthorityDiscovery: pallet_authority_discovery::{Pallet, Call, Config} = 12, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 12,
// Utility module. // Utility module.
Utility: pallet_utility::{Pallet, Call, Event} = 16, Utility: pallet_utility::{Pallet, Call, Event} = 16,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment