Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/zepter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workflows:
# Check that `A` activates the features of `B`.
'propagate-feature',
# These are the features to check:
'--features=try-runtime,runtime-benchmarks,std,ahm-kusama,ahm-staking-migration,stable2503',
'--features=try-runtime,runtime-benchmarks,std,ahm-kusama,stable2503',
# Do not try to add a new section into `[features]` of `A` only because `B` expose that feature. There are edge-cases where this is still needed, but we can add them manually.
'--left-side-feature-missing=ignore',
# Ignore the case that `A` it outside of the workspace. Otherwise it will report errors in external dependencies that we have no influence on.
Expand Down
483 changes: 243 additions & 240 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion integration-tests/ahm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use pallet_ah_migrator::{
MigrationStage as AhMigrationStage,
};
use pallet_rc_migrator::{
types::RcMigrationCheck, MigrationStage as RcMigrationStage,
staking::StakingMigratedCorrectly, types::RcMigrationCheck, MigrationStage as RcMigrationStage,
RcMigrationStage as RcMigrationStageStorage,
};
use polkadot_primitives::UpwardMessage;
Expand Down Expand Up @@ -107,6 +107,7 @@ pub type RcPolkadotChecks = (
pallet_rc_migrator::claims::ClaimsMigrator<Polkadot>,
pallet_rc_migrator::crowdloan::CrowdloanMigrator<Polkadot>,
ProxyWhaleWatching,
StakingMigratedCorrectly<Polkadot>,
);

type AhChecks = (
Expand Down Expand Up @@ -144,6 +145,7 @@ pub type AhPolkadotChecks = (
pallet_rc_migrator::claims::ClaimsMigrator<AssetHub>,
pallet_rc_migrator::crowdloan::CrowdloanMigrator<AssetHub>,
ProxyWhaleWatching,
StakingMigratedCorrectly<AssetHub>,
);

#[ignore] // we use the equivalent [migration_works_time] test instead
Expand Down
4 changes: 4 additions & 0 deletions pallets/ah-migrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pallet-rc-migrator = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-staking = { workspace = true }
pallet-staking-async = { workspace = true }
pallet-state-trie-migration = { workspace = true }
pallet-vesting = { workspace = true }
pallet-treasury = { workspace = true }
Expand Down Expand Up @@ -117,6 +118,7 @@ std = [
"xcm-executor/std",
"xcm-executor/std",
"xcm/std",
"pallet-staking-async/std"
]
runtime-benchmarks = [
"assets-common/runtime-benchmarks",
Expand Down Expand Up @@ -159,6 +161,7 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm/runtime-benchmarks",
"pallet-staking-async/runtime-benchmarks"
# "asset-hub-polkadot-runtime/runtime-benchmarks"
]
try-runtime = [
Expand Down Expand Up @@ -190,4 +193,5 @@ try-runtime = [
"polkadot-runtime-common/try-runtime",
"runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
"pallet-staking-async/try-runtime"
]
6 changes: 3 additions & 3 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use frame_system::pallet_prelude::*;
use pallet_balances::{AccountData, Reasons as LockReasons};
use pallet_rc_migrator::{
bounties::RcBountiesMessageOf, claims::RcClaimsMessageOf, crowdloan::RcCrowdloanMessageOf,
treasury::RcTreasuryMessage, types::MigrationStatus,
staking::PortableStakingMessage, treasury::RcTreasuryMessage, types::MigrationStatus,
};

use cumulus_primitives_core::AggregateMessageOrigin;
Expand Down Expand Up @@ -265,6 +265,7 @@ pub mod pallet {
+ pallet_bounties::Config
+ pallet_treasury::Config
+ pallet_delegated_staking::Config
+ pallet_staking_async::Config<CurrencyBalance = u128>
{
type RuntimeHoldReason: Parameter
+ VariantCount
Expand Down Expand Up @@ -857,12 +858,11 @@ pub mod pallet {
Self::do_receive_delegated_staking_messages(messages).map_err(Into::into)
}

#[cfg(feature = "ahm-staking-migration")]
#[pallet::call_index(30)]
#[pallet::weight({1})] // TODO: @ggwpez weight
pub fn receive_staking_messages(
origin: OriginFor<T>,
messages: Vec<T::RcStakingMessage>,
messages: Vec<PortableStakingMessage>,
) -> DispatchResult {
ensure_root(origin)?;

Expand Down
208 changes: 208 additions & 0 deletions pallets/ah-migrator/src/staking/checks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Checks that the staking migration succeeded.
use pallet_rc_migrator::{
staking::{
message::{PortableNominations, PortableUnappliedSlash},
PortableStakingMessage, RcData,
},
types::IntoPortable,
};
use sp_runtime::{AccountId32, Perbill};

impl<T: crate::Config> crate::types::AhMigrationCheck
for pallet_rc_migrator::staking::StakingMigratedCorrectly<T>
{
type RcPrePayload = RcData;
type AhPrePayload = ();

fn pre_check(_rc: Self::RcPrePayload) -> Self::AhPrePayload {}

fn post_check(rc: Self::RcPrePayload, _ah_pre_payload: Self::AhPrePayload) {
// Storage Values
assert_eq!(rc.validator_count, pallet_staking_async::ValidatorCount::<T>::get());
// Min validator count is not migrated @kianenigma review
assert_eq!(rc.min_nominator_bond, pallet_staking_async::MinNominatorBond::<T>::get());
assert_eq!(rc.min_validator_bond, pallet_staking_async::MinValidatorBond::<T>::get());
assert_eq!(rc.min_active_stake, pallet_staking_async::MinimumActiveStake::<T>::get());
assert_eq!(rc.min_commission, pallet_staking_async::MinCommission::<T>::get());
assert_eq!(rc.max_validators_count, pallet_staking_async::MaxValidatorsCount::<T>::get());
assert_eq!(rc.max_nominators_count, pallet_staking_async::MaxNominatorsCount::<T>::get());
// @kianenigma please review
if let Some(rc_era) = rc.current_era {
let diff = (rc_era as i64 -
pallet_staking_async::CurrentEra::<T>::get().expect("Must have current era")
as i64)
.abs();
assert!(diff <= 2, "Current era difference is at most 1");
} else {
assert_eq!(pallet_staking_async::CurrentEra::<T>::get(), None);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we are trying to do here.

Why should there be a diff in CurrentEra up to 1? And CurrentEra should never be none (unless its needed for tests?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is probably because we are overwriting CurrentEra with ActiveEra value. Instead we should ideally do this: #728

And then we can do a post check that active_era == current_era.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, this is not needed given that we:

  1. merge 728 and prevent migration during active_era != current_era
  2. we do indeed call staking_ah_client::on_migration_start which will freeze staking era progress.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will take a look at 728.

assert_eq!(
rc.active_era.map(translate_active_era),
pallet_staking_async::ActiveEra::<T>::get()
);
assert_eq!(translate_forcing(rc.force_era), pallet_staking_async::ForceEra::<T>::get());
assert_eq!(rc.max_staked_rewards, pallet_staking_async::MaxStakedRewards::<T>::get());
assert_eq!(rc.slash_reward_fraction, pallet_staking_async::SlashRewardFraction::<T>::get());
assert_eq!(rc.canceled_slash_payout, pallet_staking_async::CanceledSlashPayout::<T>::get());
// Current planned session is not migrated @kianenigma review
assert_eq!(rc.chill_threshold, pallet_staking_async::ChillThreshold::<T>::get());

// Storage Maps
assert_eq!(rc.invulnerables, pallet_staking_async::Invulnerables::<T>::get().into_inner());
assert_eq!(rc.bonded, pallet_staking_async::Bonded::<T>::iter().collect::<Vec<_>>());
assert_eq!(
rc.ledger.into_iter().map(|(k, v)| (k, v.into())).collect::<Vec<_>>(),
pallet_staking_async::Ledger::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.payee
.into_iter()
.map(|(k, v)| (k, translate_reward_destination(v)))
.collect::<Vec<_>>(),
pallet_staking_async::Payee::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.validators
.into_iter()
.map(|(k, v)| (k, translate_validator_prefs(v)))
.collect::<Vec<_>>(),
pallet_staking_async::Validators::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.nominators
.into_iter()
.map(|(k, v)| (k, translate_nominations(v)))
.collect::<Vec<_>>(),
pallet_staking_async::Nominators::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.virtual_stakers,
pallet_staking_async::VirtualStakers::<T>::iter_keys().collect::<Vec<_>>()
);
assert_eq!(
rc.eras_stakers_overview
.into_iter()
.map(|(k1, k2, v)| (k1, k2, v.into()))
.collect::<Vec<_>>(),
pallet_staking_async::ErasStakersOverview::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.eras_stakers_paged
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect::<Vec<_>>(),
pallet_staking_async::ErasStakersPaged::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.claimed_rewards,
pallet_staking_async::ClaimedRewards::<T>::iter()
.map(|(k1, k2, v)| (k1, k2, v.into_inner()))
.collect::<Vec<_>>()
);
assert_eq!(
rc.eras_validator_prefs
.into_iter()
.map(|(k1, k2, v)| (k1, k2, v.into()))
.collect::<Vec<_>>(),
pallet_staking_async::ErasValidatorPrefs::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.eras_validator_reward,
pallet_staking_async::ErasValidatorReward::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.eras_reward_points
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect::<Vec<_>>(),
pallet_staking_async::ErasRewardPoints::<T>::iter().collect::<Vec<_>>()
);
assert_eq!(
rc.eras_total_stake,
pallet_staking_async::ErasTotalStake::<T>::iter().collect::<Vec<_>>()
);
check_unapplied_slashes::<T>(rc.unapplied_slashes);
// TODO assert_eq!(rc.bonded_eras,
// pallet_staking_async::BondedEras::<T>::get().into_inner());
assert_eq!(
rc.validator_slash_in_era,
pallet_staking_async::ValidatorSlashInEra::<T>::iter().collect::<Vec<_>>()
);
}
}

fn translate_reward_destination(
destination: pallet_staking::RewardDestination<AccountId32>,
) -> pallet_staking_async::RewardDestination<AccountId32> {
use pallet_staking_async::RewardDestination::*;

match destination {
pallet_staking::RewardDestination::Staked => Staked,
pallet_staking::RewardDestination::Stash => Stash,
pallet_staking::RewardDestination::Controller => Controller,
pallet_staking::RewardDestination::Account(account) => Account(account),
pallet_staking::RewardDestination::None => None,
}
}

fn translate_active_era(era: pallet_staking::ActiveEraInfo) -> pallet_staking_async::ActiveEraInfo {
pallet_staking_async::ActiveEraInfo { index: era.index, start: era.start }
}

fn translate_forcing(forcing: pallet_staking::Forcing) -> pallet_staking_async::Forcing {
use pallet_staking_async::Forcing;
match forcing {
pallet_staking::Forcing::NotForcing => Forcing::NotForcing,
pallet_staking::Forcing::ForceNew => Forcing::ForceNew,
pallet_staking::Forcing::ForceNone => Forcing::ForceNone,
pallet_staking::Forcing::ForceAlways => Forcing::ForceAlways,
}
}

fn translate_validator_prefs(
prefs: pallet_staking::ValidatorPrefs,
) -> pallet_staking_async::ValidatorPrefs {
pallet_staking_async::ValidatorPrefs { commission: prefs.commission, blocked: prefs.blocked }
}

fn translate_nominations<T: crate::Config>(
nominations: PortableNominations,
) -> pallet_staking_async::Nominations<T> {
pallet_staking_async::Nominations {
targets: nominations.targets.into_inner().try_into().expect("Must not truncate"),
submitted_in: nominations.submitted_in,
suppressed: nominations.suppressed,
}
}

fn check_unapplied_slashes<T: crate::Config>(rc: Vec<(u32, Vec<PortableUnappliedSlash>)>) {
let mut expected_slashes =
Vec::<(u32, (AccountId32, Perbill, u32), PortableUnappliedSlash)>::new();

for (era, slashes) in rc {
for slash in slashes {
// We insert all slashes with this special key
let key = (slash.validator.clone(), Perbill::from_percent(99), 9999);
expected_slashes.push((era, key, slash));
}
}

// TODO assert
}
4 changes: 2 additions & 2 deletions pallets/ah-migrator/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
//! Staking migration logic.

pub mod bags_list;
#[cfg(feature = "std")]
pub mod checks;
pub mod delegated_staking;
pub mod fast_unstake;
pub mod nom_pools;

#[cfg(feature = "ahm-staking-migration")]
pub mod staking;
Loading
Loading