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
@@ -34,7 +34,7 @@ use crate::Module as ImOnline;
const MAX_KEYS: u32 = 1000;
const MAX_EXTERNAL_ADDRESSES: u32 = 100;
pub fn create_heartbeat<T: Trait>(k: u32, e: u32) ->
pub fn create_heartbeat<T: Config>(k: u32, e: u32) ->
Result<(crate::Heartbeat<T::BlockNumber>, <T::AuthorityId as RuntimeAppPublic>::Signature), &'static str>
{
let mut keys = Vec::new();
+16 -16
View File
@@ -30,7 +30,7 @@
//! as the [NetworkState](../../client/offchain/struct.NetworkState.html).
//! It is submitted as an Unsigned Transaction via off-chain workers.
//!
//! - [`im_online::Trait`](./trait.Trait.html)
//! - [`im_online::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -47,10 +47,10 @@
//! use frame_system::ensure_signed;
//! use pallet_im_online::{self as im_online};
//!
//! pub trait Trait: im_online::Trait {}
//! pub trait Config: im_online::Config {}
//!
//! 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 {
//! #[weight = 0]
//! pub fn is_online(origin, authority_index: u32) -> dispatch::DispatchResult {
//! let _sender = ensure_signed(origin)?;
@@ -227,12 +227,12 @@ pub struct Heartbeat<BlockNumber>
pub validators_len: u32,
}
pub trait Trait: SendTransactionTypes<Call<Self>> + pallet_session::historical::Trait {
pub trait Config: SendTransactionTypes<Call<Self>> + pallet_session::historical::Config {
/// The identifier type for an authority.
type AuthorityId: Member + Parameter + RuntimeAppPublic + Default + Ord;
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// An expected duration of the session.
///
@@ -262,7 +262,7 @@ pub trait Trait: SendTransactionTypes<Call<Self>> + pallet_session::historical::
decl_event!(
pub enum Event<T> where
<T as Trait>::AuthorityId,
<T as Config>::AuthorityId,
IdentificationTuple = IdentificationTuple<T>,
{
/// A new heartbeat was received from `AuthorityId` \[authority_id\]
@@ -275,7 +275,7 @@ decl_event!(
);
decl_storage! {
trait Store for Module<T: Trait> as ImOnline {
trait Store for Module<T: Config> as ImOnline {
/// The block number after which it's ok to send heartbeats in current session.
///
/// At the beginning of each session we set this to a value that should
@@ -307,7 +307,7 @@ decl_storage! {
decl_error! {
/// Error for the im-online module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Non existent public key.
InvalidKey,
/// Duplicated heartbeat.
@@ -316,7 +316,7 @@ decl_error! {
}
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;
@@ -332,7 +332,7 @@ decl_module! {
/// # </weight>
// NOTE: the weight includes the cost of validate_unsigned as it is part of the cost to
// import block with such an extrinsic.
#[weight = <T as Trait>::WeightInfo::validate_unsigned_and_then_heartbeat(
#[weight = <T as Config>::WeightInfo::validate_unsigned_and_then_heartbeat(
heartbeat.validators_len as u32,
heartbeat.network_state.external_addresses.len() as u32,
)]
@@ -393,11 +393,11 @@ decl_module! {
}
}
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Trait>::BlockNumber>>;
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Config>::BlockNumber>>;
/// Keep track of number of authored blocks per authority, uncles are counted as
/// well since they're a valid proof of being online.
impl<T: Trait + pallet_authorship::Trait> pallet_authorship::EventHandler<T::ValidatorId, T::BlockNumber> for Module<T> {
impl<T: Config + pallet_authorship::Config> pallet_authorship::EventHandler<T::ValidatorId, T::BlockNumber> for Module<T> {
fn note_author(author: T::ValidatorId) {
Self::note_authorship(author);
}
@@ -407,7 +407,7 @@ impl<T: Trait + pallet_authorship::Trait> pallet_authorship::EventHandler<T::Val
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Returns `true` if a heartbeat has been received for the authority at
/// `authority_index` in the authorities series or if the authority has
/// authored at least one block, during the current session. Otherwise
@@ -610,11 +610,11 @@ 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 = T::AuthorityId;
}
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = T::AuthorityId;
fn on_genesis_session<'a, I: 'a>(validators: I)
@@ -677,7 +677,7 @@ impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
/// Invalid transaction custom error. Returned when validators_len field in heartbeat is incorrect.
const INVALID_VALIDATORS_LEN: u8 = 10;
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(
+6 -6
View File
@@ -21,7 +21,7 @@
use std::cell::RefCell;
use crate::{Module, Trait};
use crate::{Module, Config};
use sp_runtime::Perbill;
use sp_staking::{SessionIndex, offence::{ReportOffence, OffenceError}};
use sp_runtime::testing::{Header, UintAuthorityId, TestXt};
@@ -109,7 +109,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
@@ -146,7 +146,7 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}
impl pallet_session::Trait for Runtime {
impl pallet_session::Config for Runtime {
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Runtime, TestSessionManager>;
type SessionHandler = (ImOnline, );
@@ -159,7 +159,7 @@ impl pallet_session::Trait for Runtime {
type WeightInfo = ();
}
impl pallet_session::historical::Trait for Runtime {
impl pallet_session::historical::Config for Runtime {
type FullIdentification = u64;
type FullIdentificationOf = ConvertInto;
}
@@ -168,7 +168,7 @@ parameter_types! {
pub const UncleGenerations: u32 = 5;
}
impl pallet_authorship::Trait for Runtime {
impl pallet_authorship::Config for Runtime {
type FindAuthor = ();
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
@@ -179,7 +179,7 @@ parameter_types! {
pub const UnsignedPriority: u64 = 1 << 20;
}
impl Trait for Runtime {
impl Config for Runtime {
type AuthorityId = UintAuthorityId;
type Event = ();
type ReportUnresponsiveness = OffenceHandler;
+1 -1
View File
@@ -49,7 +49,7 @@ pub trait WeightInfo {
/// Weights for pallet_im_online using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Trait> WeightInfo for SubstrateWeight<T> {
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn validate_unsigned_and_then_heartbeat(k: u32, e: u32, ) -> Weight {
(114_379_000 as Weight)
.saturating_add((219_000 as Weight).saturating_mul(k as Weight))