fix: Complete snowbridge pezpallet rebrand and critical bug fixes
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs) - pallet/ directories → pezpallet/ (4 locations) - Fixed pezpallet.rs self-include recursion bug - Fixed sc-chain-spec hardcoded crate name in derive macro - Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API) - Added BizinikiwiConfig type alias for zombienet tests - Deleted obsolete session state files Verified: pezsnowbridge-pezpallet-*, pezpallet-staking, pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Elections-Phragmen pallet benchmarking.
|
||||
//! Elections-Phragmen pezpallet benchmarking.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
@@ -51,7 +51,7 @@ fn as_lookup<T: Config>(account: T::AccountId) -> AccountIdLookupOf<T> {
|
||||
// Get a reasonable amount of stake based on the execution trait's configuration.
|
||||
fn default_stake<T: Config>(num_votes: u32) -> BalanceOf<T> {
|
||||
let min = T::Currency::minimum_balance();
|
||||
Pallet::<T>::deposit_of(num_votes as usize).max(min)
|
||||
Pezpallet::<T>::deposit_of(num_votes as usize).max(min)
|
||||
}
|
||||
|
||||
// Get the current number of candidates.
|
||||
@@ -67,7 +67,7 @@ fn submit_candidates<T: Config>(
|
||||
(0..c)
|
||||
.map(|i| {
|
||||
let account = endowed_account::<T>(prefix, i);
|
||||
Pallet::<T>::submit_candidacy(
|
||||
Pezpallet::<T>::submit_candidacy(
|
||||
RawOrigin::Signed(account.clone()).into(),
|
||||
candidate_count::<T>(),
|
||||
)
|
||||
@@ -96,7 +96,7 @@ fn submit_voter<T: Config>(
|
||||
votes: Vec<T::AccountId>,
|
||||
stake: BalanceOf<T>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
Pallet::<T>::vote(RawOrigin::Signed(caller).into(), votes, stake)
|
||||
Pezpallet::<T>::vote(RawOrigin::Signed(caller).into(), votes, stake)
|
||||
}
|
||||
|
||||
// Create `num_voter` voters who randomly vote for at most `votes` of `all_candidates` if
|
||||
@@ -122,7 +122,7 @@ fn distribute_voters<T: Config>(
|
||||
fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
|
||||
submit_candidates_with_self_vote::<T>(m, "fill_seats_up_to")?;
|
||||
assert_eq!(Candidates::<T>::get().len() as u32, m, "wrong number of candidates.");
|
||||
Pallet::<T>::do_phragmen();
|
||||
Pezpallet::<T>::do_phragmen();
|
||||
assert_eq!(Candidates::<T>::get().len(), 0, "some candidates remaining.");
|
||||
assert_eq!(
|
||||
Members::<T>::get().len() + RunnersUp::<T>::get().len(),
|
||||
@@ -325,7 +325,7 @@ mod benchmarks {
|
||||
let members_and_runners_up = fill_seats_up_to::<T>(m)?;
|
||||
|
||||
let bailing = members_and_runners_up[0].clone();
|
||||
assert!(Pallet::<T>::is_member(&bailing));
|
||||
assert!(Pezpallet::<T>::is_member(&bailing));
|
||||
|
||||
whitelist!(bailing);
|
||||
|
||||
@@ -351,7 +351,7 @@ mod benchmarks {
|
||||
let members_and_runners_up = fill_seats_up_to::<T>(m)?;
|
||||
|
||||
let bailing = members_and_runners_up[T::DesiredMembers::get() as usize + 1].clone();
|
||||
assert!(Pallet::<T>::is_runner_up(&bailing));
|
||||
assert!(Pezpallet::<T>::is_runner_up(&bailing));
|
||||
|
||||
whitelist!(bailing);
|
||||
|
||||
@@ -389,7 +389,7 @@ mod benchmarks {
|
||||
clean::<T>();
|
||||
|
||||
fill_seats_up_to::<T>(m)?;
|
||||
let removing = as_lookup::<T>(Pallet::<T>::members_ids()[0].clone());
|
||||
let removing = as_lookup::<T>(Pezpallet::<T>::members_ids()[0].clone());
|
||||
|
||||
#[extrinsic_call]
|
||||
remove_member(RawOrigin::Root, removing, true, false);
|
||||
@@ -421,7 +421,7 @@ mod benchmarks {
|
||||
Candidates::<T>::kill();
|
||||
|
||||
// Now everyone is defunct.
|
||||
assert!(Voting::<T>::iter().all(|(_, v)| Pallet::<T>::is_defunct_voter(&v.votes)));
|
||||
assert!(Voting::<T>::iter().all(|(_, v)| Pezpallet::<T>::is_defunct_voter(&v.votes)));
|
||||
assert_eq!(Voting::<T>::iter().count() as u32, v);
|
||||
|
||||
#[extrinsic_call]
|
||||
@@ -461,7 +461,7 @@ mod benchmarks {
|
||||
|
||||
#[block]
|
||||
{
|
||||
Pallet::<T>::on_initialize(T::TermDuration::get());
|
||||
Pezpallet::<T>::on_initialize(T::TermDuration::get());
|
||||
}
|
||||
|
||||
assert_eq!(Members::<T>::get().len() as u32, T::DesiredMembers::get().min(c));
|
||||
@@ -478,7 +478,7 @@ mod benchmarks {
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite! {
|
||||
Pallet,
|
||||
Pezpallet,
|
||||
tests::ExtBuilder::default().desired_members(13).desired_runners_up(7),
|
||||
tests::Test,
|
||||
exec_name = build_and_execute,
|
||||
|
||||
@@ -181,12 +181,12 @@ pub struct SeatHolder<AccountId, Balance> {
|
||||
pub deposit: Balance,
|
||||
}
|
||||
|
||||
pub use pallet::*;
|
||||
pub use pezpallet::*;
|
||||
|
||||
type AccountIdLookupOf<T> = <<T as pezframe_system::Config>::Lookup as StaticLookup>::Source;
|
||||
|
||||
#[pezframe_support::pallet]
|
||||
pub mod pallet {
|
||||
#[pezframe_support::pezpallet]
|
||||
pub mod pezpallet {
|
||||
use super::*;
|
||||
use pezframe_support::pezpallet_prelude::*;
|
||||
use pezframe_system::pezpallet_prelude::*;
|
||||
@@ -194,18 +194,18 @@ pub mod pallet {
|
||||
/// The in-code storage version.
|
||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::storage_version(STORAGE_VERSION)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
#[pezpallet::pezpallet]
|
||||
#[pezpallet::storage_version(STORAGE_VERSION)]
|
||||
#[pezpallet::without_storage_info]
|
||||
pub struct Pezpallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
#[pezpallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
#[allow(deprecated)]
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// Identifier for the elections-phragmen pallet's lock
|
||||
#[pallet::constant]
|
||||
/// Identifier for the elections-phragmen pezpallet's lock
|
||||
#[pezpallet::constant]
|
||||
type PalletId: Get<LockIdentifier>;
|
||||
|
||||
/// The currency that people are electing with.
|
||||
@@ -223,18 +223,18 @@ pub mod pallet {
|
||||
type CurrencyToVote: CurrencyToVote<BalanceOf<Self>>;
|
||||
|
||||
/// How much should be locked up in order to submit one's candidacy.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type CandidacyBond: Get<BalanceOf<Self>>;
|
||||
|
||||
/// Base deposit associated with voting.
|
||||
///
|
||||
/// This should be sensibly high to economically ensure the pallet cannot be attacked by
|
||||
/// This should be sensibly high to economically ensure the pezpallet cannot be attacked by
|
||||
/// creating a gigantic number of votes.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type VotingBondBase: Get<BalanceOf<Self>>;
|
||||
|
||||
/// The amount of bond that need to be locked for each vote (32 bytes).
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type VotingBondFactor: Get<BalanceOf<Self>>;
|
||||
|
||||
/// Handler for the unbalanced reduction when a candidate has lost (and is not a runner-up)
|
||||
@@ -244,17 +244,17 @@ pub mod pallet {
|
||||
type KickedMember: OnUnbalanced<NegativeImbalanceOf<Self>>;
|
||||
|
||||
/// Number of members to elect.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type DesiredMembers: Get<u32>;
|
||||
|
||||
/// Number of runners_up to keep.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type DesiredRunnersUp: Get<u32>;
|
||||
|
||||
/// How long each seat is kept. This defines the next block number at which an election
|
||||
/// round will happen. If set to zero, no elections are ever triggered and the module will
|
||||
/// be in passive mode.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type TermDuration: Get<BlockNumberFor<Self>>;
|
||||
|
||||
/// The maximum number of candidates in a phragmen election.
|
||||
@@ -263,7 +263,7 @@ pub mod pallet {
|
||||
/// consider how it will impact `T::WeightInfo::election_phragmen`.
|
||||
///
|
||||
/// When this limit is reached no more candidates are accepted in the election.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxCandidates: Get<u32>;
|
||||
|
||||
/// The maximum number of voters to allow in a phragmen election.
|
||||
@@ -272,22 +272,22 @@ pub mod pallet {
|
||||
/// consider how it will impact `T::WeightInfo::election_phragmen`.
|
||||
///
|
||||
/// When the limit is reached the new voters are ignored.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxVoters: Get<u32>;
|
||||
|
||||
/// Maximum numbers of votes per voter.
|
||||
///
|
||||
/// Warning: This impacts the size of the election which is run onchain. Chose wisely, and
|
||||
/// consider how it will impact `T::WeightInfo::election_phragmen`.
|
||||
#[pallet::constant]
|
||||
#[pezpallet::constant]
|
||||
type MaxVotesPerVoter: Get<u32>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
/// Weight information for extrinsics in this pezpallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
#[pezpallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pezpallet<T> {
|
||||
/// What to do at the end of each block.
|
||||
///
|
||||
/// Checks if an election needs to happen or not.
|
||||
@@ -341,8 +341,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pezpallet::call]
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// Vote for a set of candidates for the upcoming round of election. This can be called to
|
||||
/// set the initial votes, or update already existing votes.
|
||||
///
|
||||
@@ -362,8 +362,8 @@ pub mod pallet {
|
||||
///
|
||||
/// It is the responsibility of the caller to **NOT** place all of their balance into the
|
||||
/// lock and keep some for further operations.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(
|
||||
#[pezpallet::call_index(0)]
|
||||
#[pezpallet::weight(
|
||||
T::WeightInfo::vote_more(votes.len() as u32)
|
||||
.max(T::WeightInfo::vote_less(votes.len() as u32))
|
||||
.max(T::WeightInfo::vote_equal(votes.len() as u32))
|
||||
@@ -371,7 +371,7 @@ pub mod pallet {
|
||||
pub fn vote(
|
||||
origin: OriginFor<T>,
|
||||
votes: Vec<T::AccountId>,
|
||||
#[pallet::compact] value: BalanceOf<T>,
|
||||
#[pezpallet::compact] value: BalanceOf<T>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
@@ -427,8 +427,8 @@ pub mod pallet {
|
||||
/// This removes the lock and returns the deposit.
|
||||
///
|
||||
/// The dispatch origin of this call must be signed and be a voter.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(T::WeightInfo::remove_voter())]
|
||||
#[pezpallet::call_index(1)]
|
||||
#[pezpallet::weight(T::WeightInfo::remove_voter())]
|
||||
pub fn remove_voter(origin: OriginFor<T>) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
ensure!(Self::is_voter(&who), Error::<T>::MustBeVoter);
|
||||
@@ -451,11 +451,11 @@ pub mod pallet {
|
||||
/// The number of current candidates must be provided as witness data.
|
||||
/// ## Complexity
|
||||
/// O(C + log(C)) where C is candidate_count.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight(T::WeightInfo::submit_candidacy(*candidate_count))]
|
||||
#[pezpallet::call_index(2)]
|
||||
#[pezpallet::weight(T::WeightInfo::submit_candidacy(*candidate_count))]
|
||||
pub fn submit_candidacy(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] candidate_count: u32,
|
||||
#[pezpallet::compact] candidate_count: u32,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
@@ -498,8 +498,8 @@ pub mod pallet {
|
||||
/// - Renouncing::Candidate(count): O(count + log(count))
|
||||
/// - Renouncing::Member: O(1)
|
||||
/// - Renouncing::RunnerUp: O(1)
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(match *renouncing {
|
||||
#[pezpallet::call_index(3)]
|
||||
#[pezpallet::weight(match *renouncing {
|
||||
Renouncing::Candidate(count) => T::WeightInfo::renounce_candidacy_candidate(count),
|
||||
Renouncing::Member => T::WeightInfo::renounce_candidacy_members(),
|
||||
Renouncing::RunnerUp => T::WeightInfo::renounce_candidacy_runners_up(),
|
||||
@@ -559,8 +559,8 @@ pub mod pallet {
|
||||
///
|
||||
/// ## Complexity
|
||||
/// - Check details of remove_and_replace_member() and do_phragmen().
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight(if *rerun_election {
|
||||
#[pezpallet::call_index(4)]
|
||||
#[pezpallet::weight(if *rerun_election {
|
||||
T::WeightInfo::remove_member_without_replacement()
|
||||
} else {
|
||||
T::WeightInfo::remove_member_with_replacement()
|
||||
@@ -594,8 +594,8 @@ pub mod pallet {
|
||||
///
|
||||
/// ## Complexity
|
||||
/// - Check is_defunct_voter() details.
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(T::WeightInfo::clean_defunct_voters(*num_voters, *num_defunct))]
|
||||
#[pezpallet::call_index(5)]
|
||||
#[pezpallet::weight(T::WeightInfo::clean_defunct_voters(*num_voters, *num_defunct))]
|
||||
pub fn clean_defunct_voters(
|
||||
origin: OriginFor<T>,
|
||||
num_voters: u32,
|
||||
@@ -613,8 +613,8 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
#[pezpallet::event]
|
||||
#[pezpallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A new term with new_members. This indicates that enough candidates existed to run
|
||||
/// the election, not that enough have been elected. The inner value must be examined
|
||||
@@ -644,7 +644,7 @@ pub mod pallet {
|
||||
},
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
#[pezpallet::error]
|
||||
pub enum Error<T> {
|
||||
/// Cannot vote when no candidates or members exist.
|
||||
UnableToVote,
|
||||
@@ -685,7 +685,7 @@ pub mod pallet {
|
||||
/// The current elected members.
|
||||
///
|
||||
/// Invariant: Always sorted based on account id.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type Members<T: Config> =
|
||||
StorageValue<_, Vec<SeatHolder<T::AccountId, BalanceOf<T>>>, ValueQuery>;
|
||||
|
||||
@@ -693,7 +693,7 @@ pub mod pallet {
|
||||
///
|
||||
/// Invariant: Always sorted based on rank (worse to best). Upon removal of a member, the
|
||||
/// last (i.e. _best_) runner-up will be replaced.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type RunnersUp<T: Config> =
|
||||
StorageValue<_, Vec<SeatHolder<T::AccountId, BalanceOf<T>>>, ValueQuery>;
|
||||
|
||||
@@ -703,27 +703,27 @@ pub mod pallet {
|
||||
/// Second element is the deposit.
|
||||
///
|
||||
/// Invariant: Always sorted based on account id.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type Candidates<T: Config> = StorageValue<_, Vec<(T::AccountId, BalanceOf<T>)>, ValueQuery>;
|
||||
|
||||
/// The total number of vote rounds that have happened, excluding the upcoming one.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type ElectionRounds<T: Config> = StorageValue<_, u32, ValueQuery>;
|
||||
|
||||
/// Votes and locked stake of a particular voter.
|
||||
///
|
||||
/// TWOX-NOTE: SAFE as `AccountId` is a crypto hash.
|
||||
#[pallet::storage]
|
||||
#[pezpallet::storage]
|
||||
pub type Voting<T: Config> =
|
||||
StorageMap<_, Twox64Concat, T::AccountId, Voter<T::AccountId, BalanceOf<T>>, ValueQuery>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[pezpallet::genesis_config]
|
||||
#[derive(pezframe_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub members: Vec<(T::AccountId, BalanceOf<T>)>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
#[pezpallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
assert!(
|
||||
@@ -782,7 +782,7 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
/// The deposit value of `count` votes.
|
||||
fn deposit_of(count: usize) -> BalanceOf<T> {
|
||||
T::VotingBondBase::get()
|
||||
@@ -1156,13 +1156,13 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Contains<T::AccountId> for Pallet<T> {
|
||||
impl<T: Config> Contains<T::AccountId> for Pezpallet<T> {
|
||||
fn contains(who: &T::AccountId) -> bool {
|
||||
Self::is_member(who)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> SortedMembers<T::AccountId> for Pallet<T> {
|
||||
impl<T: Config> SortedMembers<T::AccountId> for Pezpallet<T> {
|
||||
fn contains(who: &T::AccountId) -> bool {
|
||||
Self::is_member(who)
|
||||
}
|
||||
@@ -1171,7 +1171,7 @@ impl<T: Config> SortedMembers<T::AccountId> for Pallet<T> {
|
||||
Self::members_ids()
|
||||
}
|
||||
|
||||
// A special function to populate members in this pallet for passing Origin
|
||||
// A special function to populate members in this pezpallet for passing Origin
|
||||
// checks in runtime benchmarking.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn add(who: &T::AccountId) {
|
||||
@@ -1189,7 +1189,7 @@ impl<T: Config> SortedMembers<T::AccountId> for Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> ContainsLengthBound for Pallet<T> {
|
||||
impl<T: Config> ContainsLengthBound for Pezpallet<T> {
|
||||
fn min_len() -> usize {
|
||||
0
|
||||
}
|
||||
@@ -1201,7 +1201,7 @@ impl<T: Config> ContainsLengthBound for Pallet<T> {
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "try-runtime", test))]
|
||||
impl<T: Config> Pallet<T> {
|
||||
impl<T: Config> Pezpallet<T> {
|
||||
fn do_try_state() -> Result<(), TryRuntimeError> {
|
||||
Self::try_state_members()?;
|
||||
Self::try_state_runners_up()?;
|
||||
@@ -1264,8 +1264,8 @@ impl<T: Config> Pallet<T> {
|
||||
// - Members and candidates sets are disjoint;
|
||||
// - Members and runners-ups sets are disjoint.
|
||||
fn try_state_members_disjoint() -> Result<(), TryRuntimeError> {
|
||||
match Self::intersects(&Pallet::<T>::members_ids(), &Self::candidates_ids()) &&
|
||||
Self::intersects(&Pallet::<T>::members_ids(), &Self::runners_up_ids())
|
||||
match Self::intersects(&Pezpallet::<T>::members_ids(), &Self::candidates_ids()) &&
|
||||
Self::intersects(&Pezpallet::<T>::members_ids(), &Self::runners_up_ids())
|
||||
{
|
||||
true =>
|
||||
Err("Members set should be disjoint from candidates and runners-up sets".into()),
|
||||
@@ -1322,7 +1322,7 @@ mod tests {
|
||||
|
||||
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
|
||||
impl pezpallet_balances::Config for Test {
|
||||
type AccountStore = pezframe_system::Pallet<Test>;
|
||||
type AccountStore = pezframe_system::Pezpallet<Test>;
|
||||
}
|
||||
|
||||
pezframe_support::parameter_types! {
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! All migrations of this pallet.
|
||||
//! All migrations of this pezpallet.
|
||||
|
||||
/// Migration to unreserve all pallet funds.
|
||||
/// Migration to unreserve all pezpallet funds.
|
||||
pub mod unlock_and_unreserve_all_funds;
|
||||
/// Version 3.
|
||||
pub mod v3;
|
||||
|
||||
+16
-16
@@ -16,7 +16,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! A migration that unreserves all deposit and unlocks all stake held in the context of this
|
||||
//! pallet.
|
||||
//! pezpallet.
|
||||
|
||||
use alloc::{collections::btree_map::BTreeMap, vec::Vec};
|
||||
use core::iter::Sum;
|
||||
@@ -41,14 +41,14 @@ pub trait UnlockConfig: 'static {
|
||||
type AccountId: Parameter + Ord;
|
||||
/// The currency type used in the runtime.
|
||||
///
|
||||
/// Should match the currency type previously used for the pallet, if applicable.
|
||||
/// Should match the currency type previously used for the pezpallet, if applicable.
|
||||
type Currency: LockableCurrency<Self::AccountId> + ReservableCurrency<Self::AccountId>;
|
||||
/// The name of the pallet as previously configured in
|
||||
/// The name of the pezpallet as previously configured in
|
||||
/// [`construct_runtime!`](pezframe_support::construct_runtime).
|
||||
type PalletName: Get<&'static str>;
|
||||
/// The maximum number of votes per voter as configured previously in the previous runtime.
|
||||
type MaxVotesPerVoter: Get<u32>;
|
||||
/// Identifier for the elections-phragmen pallet's lock, as previously configured in the
|
||||
/// Identifier for the elections-phragmen pezpallet's lock, as previously configured in the
|
||||
/// runtime.
|
||||
type PalletId: Get<LockIdentifier>;
|
||||
/// The DB weight as configured in the runtime to calculate the correct weight.
|
||||
@@ -86,18 +86,18 @@ type Voting<T: UnlockConfig> = StorageMap<
|
||||
>;
|
||||
|
||||
/// A migration that unreserves all deposit and unlocks all stake held in the context of this
|
||||
/// pallet.
|
||||
/// pezpallet.
|
||||
///
|
||||
/// Useful to prevent funds from being locked up when the pallet is being deprecated.
|
||||
/// Useful to prevent funds from being locked up when the pezpallet is being deprecated.
|
||||
///
|
||||
/// The pallet should be made inoperable before this migration is run.
|
||||
/// The pezpallet should be made inoperable before this migration is run.
|
||||
///
|
||||
/// (See also [`RemovePallet`][pezframe_support::migrations::RemovePallet])
|
||||
pub struct UnlockAndUnreserveAllFunds<T: UnlockConfig>(core::marker::PhantomData<T>);
|
||||
|
||||
impl<T: UnlockConfig> UnlockAndUnreserveAllFunds<T> {
|
||||
/// Calculates and returns the total amounts deposited and staked by each account in the context
|
||||
/// of this pallet.
|
||||
/// of this pezpallet.
|
||||
///
|
||||
/// The deposited and staked amounts are returned in two separate `BTreeMap` collections.
|
||||
///
|
||||
@@ -177,20 +177,20 @@ where
|
||||
/// checks the integrity of deposited and reserved balances.
|
||||
///
|
||||
/// Steps:
|
||||
/// 1. Gets the deposited and staked balances for each account stored in this pallet.
|
||||
/// 1. Gets the deposited and staked balances for each account stored in this pezpallet.
|
||||
/// 2. Collects actual pre-migration locked and reserved balances for each account.
|
||||
/// 3. Checks the integrity of the deposited and reserved balances.
|
||||
/// 4. Prints summary statistics about the state to be migrated.
|
||||
/// 5. Encodes and returns pre-migration data to be used in post_upgrade.
|
||||
///
|
||||
/// Fails with a `TryRuntimeError` if there's a discrepancy between the amount
|
||||
/// reported as staked by the pallet and the amount actually locked in `Balances`.
|
||||
/// reported as staked by the pezpallet and the amount actually locked in `Balances`.
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, pezsp_runtime::TryRuntimeError> {
|
||||
use alloc::collections::btree_set::BTreeSet;
|
||||
use codec::Encode;
|
||||
|
||||
// Get staked and deposited balances as reported by this pallet.
|
||||
// Get staked and deposited balances as reported by this pezpallet.
|
||||
let (account_deposited_sums, account_staked_sums, _) =
|
||||
Self::get_account_deposited_and_staked_sums();
|
||||
|
||||
@@ -206,7 +206,7 @@ where
|
||||
.collect();
|
||||
|
||||
// Total deposited for each account *should* be less than or equal to the total reserved,
|
||||
// however this does not hold for all cases due to bugs in the reserve logic of this pallet.
|
||||
// however this does not hold for all cases due to bugs in the reserve logic of this pezpallet.
|
||||
let bugged_deposits = all_accounts
|
||||
.iter()
|
||||
.filter(|account| {
|
||||
@@ -241,11 +241,11 @@ where
|
||||
/// Executes the migration.
|
||||
///
|
||||
/// Steps:
|
||||
/// 1. Retrieves the deposit and stake amounts from the pallet.
|
||||
/// 1. Retrieves the deposit and stake amounts from the pezpallet.
|
||||
/// 2. Unreserves the deposited funds for each account.
|
||||
/// 3. Unlocks the staked funds for each account.
|
||||
fn on_runtime_upgrade() -> pezframe_support::weights::Weight {
|
||||
// Get staked and deposited balances as reported by this pallet.
|
||||
// Get staked and deposited balances as reported by this pezpallet.
|
||||
let (account_deposited_sums, account_staked_sums, initial_reads) =
|
||||
Self::get_account_deposited_and_staked_sums();
|
||||
|
||||
@@ -290,7 +290,7 @@ where
|
||||
BTreeMap::<T::AccountId, BalanceOf<T>>::decode(&mut &account_reserved_before_bytes[..])
|
||||
.map_err(|_| "Failed to decode account_reserved_before_bytes")?;
|
||||
|
||||
// Get deposited balances as reported by this pallet.
|
||||
// Get deposited balances as reported by this pezpallet.
|
||||
let (account_deposited_sums, _, _) = Self::get_account_deposited_and_staked_sums();
|
||||
|
||||
// Check that the reserved balance is reduced by the expected deposited amount.
|
||||
@@ -300,7 +300,7 @@ where
|
||||
.get(&account)
|
||||
.unwrap_or(&Zero::zero())
|
||||
// .min here to handle bugged deposits where actual_reserved_before is less than the
|
||||
// amount the pallet reports is reserved
|
||||
// amount the pezpallet reports is reserved
|
||||
.min(&actual_reserved_before);
|
||||
let expected_reserved_after =
|
||||
actual_reserved_before.saturating_sub(expected_amount_deducted);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//! Migrations to version [`3.0.0`], as denoted by the changelog.
|
||||
|
||||
use super::super::LOG_TARGET;
|
||||
use crate::{Config, Pallet};
|
||||
use crate::{Config, Pezpallet};
|
||||
use alloc::vec::Vec;
|
||||
use codec::{Decode, Encode, FullCodec};
|
||||
use pezframe_support::{
|
||||
@@ -51,25 +51,25 @@ pub trait V2ToV3 {
|
||||
|
||||
#[pezframe_support::storage_alias]
|
||||
type Candidates<V, T: Config> =
|
||||
StorageValue<Pallet<T>, Vec<(<V as V2ToV3>::AccountId, <V as V2ToV3>::Balance)>, ValueQuery>;
|
||||
StorageValue<Pezpallet<T>, Vec<(<V as V2ToV3>::AccountId, <V as V2ToV3>::Balance)>, ValueQuery>;
|
||||
|
||||
#[pezframe_support::storage_alias]
|
||||
type Members<V, T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Pezpallet<T>,
|
||||
Vec<SeatHolder<<V as V2ToV3>::AccountId, <V as V2ToV3>::Balance>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pezframe_support::storage_alias]
|
||||
type RunnersUp<V, T: Config> = StorageValue<
|
||||
Pallet<T>,
|
||||
Pezpallet<T>,
|
||||
Vec<SeatHolder<<V as V2ToV3>::AccountId, <V as V2ToV3>::Balance>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
#[pezframe_support::storage_alias]
|
||||
type Voting<V, T: Config> = StorageMap<
|
||||
Pallet<T>,
|
||||
Pezpallet<T>,
|
||||
Twox64Concat,
|
||||
<V as V2ToV3>::AccountId,
|
||||
Voter<<V as V2ToV3>::AccountId, <V as V2ToV3>::Balance>,
|
||||
@@ -88,7 +88,7 @@ pub fn apply<V: V2ToV3, T: Config>(
|
||||
old_voter_bond: V::Balance,
|
||||
old_candidacy_bond: V::Balance,
|
||||
) -> Weight {
|
||||
let storage_version = StorageVersion::get::<Pallet<T>>();
|
||||
let storage_version = StorageVersion::get::<Pezpallet<T>>();
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"Running migration for elections-phragmen with storage version {:?}",
|
||||
@@ -101,7 +101,7 @@ pub fn apply<V: V2ToV3, T: Config>(
|
||||
migrate_runners_up_to_recorded_deposit::<V, T>(old_candidacy_bond);
|
||||
migrate_members_to_recorded_deposit::<V, T>(old_candidacy_bond);
|
||||
|
||||
StorageVersion::new(3).put::<Pallet<T>>();
|
||||
StorageVersion::new(3).put::<Pezpallet<T>>();
|
||||
|
||||
Weight::MAX
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,7 @@ use pezframe_support::{
|
||||
/// The old prefix.
|
||||
pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
|
||||
|
||||
/// Migrate the entire storage of this pallet to a new prefix.
|
||||
/// Migrate the entire storage of this pezpallet to a new prefix.
|
||||
///
|
||||
/// This new prefix must be the same as the one set in construct_runtime. For safety, use
|
||||
/// `PalletInfo` to get it, as:
|
||||
@@ -37,11 +37,11 @@ pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
|
||||
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"New pallet name is equal to the old prefix. No migration needs to be done.",
|
||||
"New pezpallet name is equal to the old prefix. No migration needs to be done.",
|
||||
);
|
||||
return Weight::zero();
|
||||
}
|
||||
let storage_version = StorageVersion::get::<crate::Pallet<T>>();
|
||||
let storage_version = StorageVersion::get::<crate::Pezpallet<T>>();
|
||||
log::info!(
|
||||
target: LOG_TARGET,
|
||||
"Running migration to v4 for elections-phragmen with storage version {:?}",
|
||||
@@ -55,7 +55,7 @@ pub fn migrate<T: crate::Config, N: AsRef<str>>(new_pallet_name: N) -> Weight {
|
||||
new_pallet_name.as_ref().as_bytes(),
|
||||
);
|
||||
|
||||
StorageVersion::new(4).put::<crate::Pallet<T>>();
|
||||
StorageVersion::new(4).put::<crate::Pezpallet<T>>();
|
||||
|
||||
<T as pezframe_system::Config>::BlockWeights::get().max_block
|
||||
} else {
|
||||
@@ -93,7 +93,7 @@ pub fn pre_migration<T: crate::Config, N: AsRef<str>>(new: N) {
|
||||
pezsp_core::hexdisplay::HexDisplay::from(&pezsp_io::storage::next_key(new.as_bytes()).unwrap())
|
||||
);
|
||||
// ensure storage version is 3.
|
||||
assert_eq!(StorageVersion::get::<crate::Pallet<T>>(), 3);
|
||||
assert_eq!(StorageVersion::get::<crate::Pezpallet<T>>(), 3);
|
||||
}
|
||||
|
||||
/// Some checks for after migration. This can be linked to
|
||||
@@ -103,5 +103,5 @@ pub fn pre_migration<T: crate::Config, N: AsRef<str>>(new: N) {
|
||||
pub fn post_migration<T: crate::Config>() {
|
||||
log::info!("post-migration elections-phragmen");
|
||||
// ensure we've been updated to v4 by the automatic write of crate version -> storage version.
|
||||
assert_eq!(StorageVersion::get::<crate::Pallet<T>>(), 4);
|
||||
assert_eq!(StorageVersion::get::<crate::Pezpallet<T>>(), 4);
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// pezpallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/pez-kitchensink-runtime/pez_kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_elections_phragmen
|
||||
// --pezpallet=pezpallet_elections_phragmen
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/elections-phragmen/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
|
||||
Reference in New Issue
Block a user