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
+10 -10
View File
@@ -41,8 +41,8 @@ mod shared;
pub mod offchain;
pub mod onchain;
/// Trait necessary for the historical module.
pub trait Trait: super::Trait {
/// Config necessary for the historical module.
pub trait Config: super::Config {
/// Full identification of the validator.
type FullIdentification: Parameter;
@@ -57,7 +57,7 @@ pub trait Trait: super::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Session {
trait Store for Module<T: Config> as Session {
/// Mapping from historical session indices to session-data root hash and validator count.
HistoricalSessions get(fn historical_root):
map hasher(twox_64_concat) SessionIndex => Option<(T::Hash, ValidatorCount)>;
@@ -71,10 +71,10 @@ 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 {}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Prune historical stored session roots up to (but not including)
/// `up_to`.
pub fn prune_up_to(up_to: SessionIndex) {
@@ -116,7 +116,7 @@ pub trait SessionManager<ValidatorId, FullIdentification>: crate::SessionManager
/// sets the historical trie root of the ending session.
pub struct NoteHistoricalRoot<T, I>(sp_std::marker::PhantomData<(T, I)>);
impl<T: Trait, I> crate::SessionManager<T::ValidatorId> for NoteHistoricalRoot<T, I>
impl<T: Config, I> crate::SessionManager<T::ValidatorId> for NoteHistoricalRoot<T, I>
where I: SessionManager<T::ValidatorId, T::FullIdentification>
{
fn new_session(new_index: SessionIndex) -> Option<Vec<T::ValidatorId>> {
@@ -160,15 +160,15 @@ impl<T: Trait, I> crate::SessionManager<T::ValidatorId> for NoteHistoricalRoot<T
}
/// A tuple of the validator's ID and their full identification.
pub type IdentificationTuple<T> = (<T as crate::Trait>::ValidatorId, <T as Trait>::FullIdentification);
pub type IdentificationTuple<T> = (<T as crate::Config>::ValidatorId, <T as Config>::FullIdentification);
/// A trie instance for checking and generating proofs.
pub struct ProvingTrie<T: Trait> {
pub struct ProvingTrie<T: Config> {
db: MemoryDB<T::Hashing>,
root: T::Hash,
}
impl<T: Trait> ProvingTrie<T> {
impl<T: Config> ProvingTrie<T> {
fn generate_for<I>(validators: I) -> Result<Self, &'static str>
where I: IntoIterator<Item=(T::ValidatorId, T::FullIdentification)>
{
@@ -260,7 +260,7 @@ impl<T: Trait> ProvingTrie<T> {
}
}
impl<T: Trait, D: AsRef<[u8]>> frame_support::traits::KeyOwnerProofSystem<(KeyTypeId, D)>
impl<T: Config, D: AsRef<[u8]>> frame_support::traits::KeyOwnerProofSystem<(KeyTypeId, D)>
for Module<T>
{
type Proof = MembershipProof;
@@ -29,18 +29,18 @@ use sp_runtime::{offchain::storage::StorageValueRef, KeyTypeId};
use sp_session::MembershipProof;
use super::super::{Module as SessionModule, SessionIndex};
use super::{IdentificationTuple, ProvingTrie, Trait};
use super::{IdentificationTuple, ProvingTrie, Config};
use super::shared;
use sp_std::prelude::*;
/// A set of validators, which was used for a fixed session index.
struct ValidatorSet<T: Trait> {
struct ValidatorSet<T: Config> {
validator_set: Vec<IdentificationTuple<T>>,
}
impl<T: Trait> ValidatorSet<T> {
impl<T: Config> ValidatorSet<T> {
/// Load the set of validators for a particular session index from the off-chain storage.
///
/// If none is found or decodable given `prefix` and `session`, it will return `None`.
@@ -61,7 +61,7 @@ impl<T: Trait> ValidatorSet<T> {
/// Implement conversion into iterator for usage
/// with [ProvingTrie](super::ProvingTrie::generate_for).
impl<T: Trait> sp_std::iter::IntoIterator for ValidatorSet<T> {
impl<T: Config> sp_std::iter::IntoIterator for ValidatorSet<T> {
type Item = (T::ValidatorId, T::FullIdentification);
type IntoIter = sp_std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
@@ -74,7 +74,7 @@ impl<T: Trait> sp_std::iter::IntoIterator for ValidatorSet<T> {
/// Based on the yielded `MembershipProof` the implementer may decide what
/// to do, i.e. in case of a failed proof, enqueue a transaction back on
/// chain reflecting that, with all its consequences such as i.e. slashing.
pub fn prove_session_membership<T: Trait, D: AsRef<[u8]>>(
pub fn prove_session_membership<T: Config, D: AsRef<[u8]>>(
session_index: SessionIndex,
session_key: (KeyTypeId, D),
) -> Option<MembershipProof> {
@@ -97,7 +97,7 @@ pub fn prove_session_membership<T: Trait, D: AsRef<[u8]>>(
/// Due to re-organisation it could be that the `first_to_keep` might be less
/// than the stored one, in which case the conservative choice is made to keep records
/// up to the one that is the lesser.
pub fn prune_older_than<T: Trait>(first_to_keep: SessionIndex) {
pub fn prune_older_than<T: Config>(first_to_keep: SessionIndex) {
let derived_key = shared::LAST_PRUNE.to_vec();
let entry = StorageValueRef::persistent(derived_key.as_ref());
match entry.mutate(|current: Option<Option<SessionIndex>>| -> Result<_, ()> {
@@ -127,7 +127,7 @@ pub fn prune_older_than<T: Trait>(first_to_keep: SessionIndex) {
}
/// Keep the newest `n` items, and prune all items older than that.
pub fn keep_newest<T: Trait>(n_to_keep: usize) {
pub fn keep_newest<T: Config>(n_to_keep: usize) {
let session_index = <SessionModule<T>>::current_index();
let n_to_keep = n_to_keep as SessionIndex;
if n_to_keep < session_index {
@@ -189,8 +189,8 @@ mod tests {
#[test]
fn encode_decode_roundtrip() {
use codec::{Decode, Encode};
use super::super::super::Trait as SessionTrait;
use super::super::Trait as HistoricalTrait;
use super::super::super::Config as SessionTrait;
use super::super::Config as HistoricalTrait;
let sample = (
22u32 as <Test as SessionTrait>::ValidatorId,
@@ -20,9 +20,9 @@
use codec::Encode;
use sp_runtime::traits::Convert;
use super::super::Trait as SessionTrait;
use super::super::Config as SessionTrait;
use super::super::{Module as SessionModule, SessionIndex};
use super::Trait as HistoricalTrait;
use super::Config as HistoricalTrait;
use super::shared;
use sp_std::prelude::*;
+11 -11
View File
@@ -20,7 +20,7 @@
//! The Session module allows validators to manage their session keys, provides a function for changing
//! the session length, and handles session rotation.
//!
//! - [`session::Trait`](./trait.Trait.html)
//! - [`session::Config`](./trait.Config.html)
//! - [`Call`](./enum.Call.html)
//! - [`Module`](./struct.Module.html)
//!
@@ -88,7 +88,7 @@
//! ```
//! use pallet_session as session;
//!
//! fn validators<T: pallet_session::Trait>() -> Vec<<T as pallet_session::Trait>::ValidatorId> {
//! fn validators<T: pallet_session::Config>() -> Vec<<T as pallet_session::Config>::ValidatorId> {
//! <pallet_session::Module<T>>::validators()
//! }
//! # fn main(){}
@@ -346,15 +346,15 @@ impl<AId> SessionHandler<AId> for TestSessionHandler {
fn on_disabled(_: usize) {}
}
impl<T: Trait> ValidatorRegistration<T::ValidatorId> for Module<T> {
impl<T: Config> ValidatorRegistration<T::ValidatorId> for Module<T> {
fn is_registered(id: &T::ValidatorId) -> bool {
Self::load_keys(id).is_some()
}
}
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event> + Into<<Self as frame_system::Config>::Event>;
/// A stable ID for a validator.
type ValidatorId: Member + Parameter;
@@ -392,7 +392,7 @@ pub trait Trait: frame_system::Trait {
}
decl_storage! {
trait Store for Module<T: Trait> as Session {
trait Store for Module<T: Config> as Session {
/// The current set of validators.
Validators get(fn validators): Vec<T::ValidatorId>;
@@ -483,7 +483,7 @@ decl_event!(
decl_error! {
/// Error for the session module.
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// Invalid ownership proof.
InvalidProof,
/// No associated validator ID for account.
@@ -496,7 +496,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;
@@ -560,7 +560,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Move on to next session. Register new validator set and session keys. Changes
/// to the validator set have a session of delay to take effect. This allows for
/// equivocation punishment after a fork.
@@ -776,7 +776,7 @@ impl<T: Trait> Module<T> {
/// registering account-ID of that session key index.
pub struct FindAccountFromAuthorIndex<T, Inner>(sp_std::marker::PhantomData<(T, Inner)>);
impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::ValidatorId>
impl<T: Config, Inner: FindAuthor<u32>> FindAuthor<T::ValidatorId>
for FindAccountFromAuthorIndex<T, Inner>
{
fn find_author<'a, I>(digests: I) -> Option<T::ValidatorId>
@@ -789,7 +789,7 @@ impl<T: Trait, Inner: FindAuthor<u32>> FindAuthor<T::ValidatorId>
}
}
impl<T: Trait> EstimateNextNewSession<T::BlockNumber> for Module<T> {
impl<T: Config> EstimateNextNewSession<T::BlockNumber> for Module<T> {
/// This session module always calls new_session and next_session at the same time, hence we
/// do a simple proxy and pass the function to next rotation.
fn estimate_next_new_session(now: T::BlockNumber) -> Option<T::BlockNumber> {
+4 -4
View File
@@ -172,7 +172,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;
@@ -200,7 +200,7 @@ impl frame_system::Trait for Test {
type SystemWeightInfo = ();
}
impl pallet_timestamp::Trait for Test {
impl pallet_timestamp::Config for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
@@ -211,7 +211,7 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(33);
}
impl Trait for Test {
impl Config for Test {
type ShouldEndSession = TestShouldEndSession;
#[cfg(feature = "historical")]
type SessionManager = crate::historical::NoteHistoricalRoot<Test, TestSessionManager>;
@@ -228,7 +228,7 @@ impl Trait for Test {
}
#[cfg(feature = "historical")]
impl crate::historical::Trait for Test {
impl crate::historical::Config for Test {
type FullIdentification = u64;
type FullIdentificationOf = sp_runtime::traits::ConvertInto;
}
+1 -1
View File
@@ -285,7 +285,7 @@ fn session_keys_generate_output_works_as_set_keys_input() {
assert_ok!(
Session::set_keys(
Origin::signed(2),
<mock::Test as Trait>::Keys::decode(&mut &new_keys[..]).expect("Decode keys"),
<mock::Test as Config>::Keys::decode(&mut &new_keys[..]).expect("Decode keys"),
vec![],
)
);
+1 -1
View File
@@ -50,7 +50,7 @@ pub trait WeightInfo {
/// Weights for pallet_session 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 set_keys() -> Weight {
(86_033_000 as Weight)
.saturating_add(T::DbWeight::get().reads(6 as Weight))