Rename pallet trait Trait to Config (#7599)

* rename Trait to Config

* add test asserting using Trait is still valid.

* fix ui tests
This commit is contained in:
Guillaume Thiolliere
2020-11-30 15:34:54 +01:00
committed by GitHub
parent dd3c84c362
commit 1cbfc9257f
200 changed files with 1767 additions and 1607 deletions
+5 -5
View File
@@ -54,13 +54,13 @@ use sp_staking::{
SessionIndex,
};
use super::{Call, Module, Trait};
use super::{Call, Module, Config};
/// A trait with utility methods for handling equivocation reports in GRANDPA.
/// The offence type is generic, and the trait provides , reporting an offence
/// triggered by a valid equivocation report, and also for creating and
/// submitting equivocation report extrinsics (useful only in offchain context).
pub trait HandleEquivocation<T: Trait> {
pub trait HandleEquivocation<T: Config> {
/// The offence type used for reporting offences on valid equivocation reports.
type Offence: GrandpaOffence<T::KeyOwnerIdentification>;
@@ -86,7 +86,7 @@ pub trait HandleEquivocation<T: Trait> {
fn block_author() -> Option<T::AccountId>;
}
impl<T: Trait> HandleEquivocation<T> for () {
impl<T: Config> HandleEquivocation<T> for () {
type Offence = GrandpaEquivocationOffence<T::KeyOwnerIdentification>;
fn report_offence(
@@ -136,7 +136,7 @@ where
// We use the authorship pallet to fetch the current block author and use
// `offchain::SendTransactionTypes` for unsigned extrinsic creation and
// submission.
T: Trait + pallet_authorship::Trait + frame_system::offchain::SendTransactionTypes<Call<T>>,
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
// A system for reporting offences after valid equivocation reports are
// processed.
R: ReportOffence<T::AccountId, T::KeyOwnerIdentification, O>,
@@ -187,7 +187,7 @@ pub struct GrandpaTimeSlot {
/// A `ValidateUnsigned` implementation that restricts calls to `report_equivocation_unsigned`
/// to local calls (i.e. extrinsics generated on this node) or that already in a block. This
/// guarantees that only block authors can include unsigned equivocation reports.
impl<T: Trait> frame_support::unsigned::ValidateUnsigned for Module<T> {
impl<T: Config> frame_support::unsigned::ValidateUnsigned for Module<T> {
type Call = Call<T>;
fn validate_unsigned(source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::report_equivocation_unsigned(equivocation_proof, _) = call {
+9 -9
View File
@@ -67,9 +67,9 @@ pub use equivocation::{
HandleEquivocation,
};
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The event type of this module.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// The function call.
type Call: From<Call<Self>>;
@@ -188,7 +188,7 @@ decl_event! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Attempt to signal GRANDPA pause when the authority set isn't live
/// (either paused or already pending pause).
PauseFailed,
@@ -209,7 +209,7 @@ decl_error! {
}
decl_storage! {
trait Store for Module<T: Trait> as GrandpaFinality {
trait Store for Module<T: Config> as GrandpaFinality {
/// State of the current authority set.
State get(fn state): StoredState<T::BlockNumber> = StoredState::Live;
@@ -241,7 +241,7 @@ decl_storage! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
@@ -372,7 +372,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Get the current set of authorities, along with their respective weights.
pub fn grandpa_authorities() -> AuthorityList {
storage::unhashed::get_or_default::<VersionedAuthorityList>(GRANDPA_AUTHORITIES_KEY).into()
@@ -583,12 +583,12 @@ impl<T: Trait> Module<T> {
}
}
impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T>
where T: pallet_session::Trait
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T>
where T: pallet_session::Config
{
type Key = AuthorityId;
+10 -10
View File
@@ -19,7 +19,7 @@
#![cfg(test)]
use crate::{AuthorityId, AuthorityList, ConsensusLog, Module, Trait};
use crate::{AuthorityId, AuthorityList, ConsensusLog, Module, Config};
use ::grandpa as finality_grandpa;
use codec::Encode;
use frame_support::{
@@ -79,7 +79,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -122,7 +122,7 @@ parameter_types! {
}
/// Custom `SessionHandler` since we use `TestSessionKeys` as `Keys`.
impl pallet_session::Trait for Test {
impl pallet_session::Config for Test {
type Event = TestEvent;
type ValidatorId = u64;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
@@ -135,7 +135,7 @@ impl pallet_session::Trait for Test {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Test {
impl pallet_session::historical::Config for Test {
type FullIdentification = pallet_staking::Exposure<u64, u128>;
type FullIdentificationOf = pallet_staking::ExposureOf<Self>;
}
@@ -144,7 +144,7 @@ parameter_types! {
pub const UncleGenerations: u64 = 0;
}
impl pallet_authorship::Trait for Test {
impl pallet_authorship::Config for Test {
type FindAuthor = ();
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -155,7 +155,7 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 1;
}
impl pallet_balances::Trait for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
@@ -169,7 +169,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 3;
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -198,7 +198,7 @@ parameter_types! {
pub const StakingUnsignedPriority: u64 = u64::max_value() / 2;
}
impl pallet_staking::Trait for Test {
impl pallet_staking::Config for Test {
type RewardRemainder = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = TestEvent;
@@ -227,14 +227,14 @@ parameter_types! {
pub OffencesWeightSoftLimit: Weight = Perbill::from_percent(60) * MaximumBlockWeight::get();
}
impl pallet_offences::Trait for Test {
impl pallet_offences::Config for Test {
type Event = TestEvent;
type IdentificationTuple = pallet_session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = Staking;
type WeightSoftLimit = OffencesWeightSoftLimit;
}
impl Trait for Test {
impl Config for Test {
type Event = TestEvent;
type Call = Call;
+2 -2
View File
@@ -850,7 +850,7 @@ fn report_equivocation_has_valid_weight() {
// but there's a lower bound of 100 validators.
assert!(
(1..=100)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] == w[1])
@@ -860,7 +860,7 @@ fn report_equivocation_has_valid_weight() {
// with every extra validator.
assert!(
(100..=1000)
.map(<Test as Trait>::WeightInfo::report_equivocation)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] < w[1])