mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 09:51:10 +00:00
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:
committed by
GitHub
parent
dd3c84c362
commit
1cbfc9257f
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user