Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Jan 31, 2025
1 parent 72f365f commit 3cea6f6
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 52 deletions.
10 changes: 5 additions & 5 deletions pallets/ah-migrator/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,35 @@ impl<T: Config> Pallet<T> {
if pallet_claims::Total::<T>::exists() {
return Err(Error::<T>::InsertConflict);
}
log::debug!(target: LOG_TARGET, "Processing claims message: total");
log::debug!(target: LOG_TARGET, "Processing claims message: total {:?}", total);
pallet_claims::Total::<T>::put(total);
},
RcClaimsMessage::Claims((who, amount)) => {
if alias::Claims::<T>::contains_key(&who) {
return Err(Error::<T>::InsertConflict);
}
log::debug!(target: LOG_TARGET, "Processing claims message: claims");
log::debug!(target: LOG_TARGET, "Processing claims message: claims {:?}", who);
alias::Claims::<T>::insert(who, amount);
},
RcClaimsMessage::Vesting { who, schedule } => {
if alias::Vesting::<T>::contains_key(&who) {
return Err(Error::<T>::InsertConflict);
}
log::debug!(target: LOG_TARGET, "Processing claims message: vesting");
log::debug!(target: LOG_TARGET, "Processing claims message: vesting {:?}", who);
alias::Vesting::<T>::insert(who, schedule);
},
RcClaimsMessage::Signing((who, statement_kind)) => {
if alias::Signing::<T>::contains_key(&who) {
return Err(Error::<T>::InsertConflict);
}
log::debug!(target: LOG_TARGET, "Processing claims message: signing");
log::debug!(target: LOG_TARGET, "Processing claims message: signing {:?}", who);
alias::Signing::<T>::insert(who, statement_kind);
},
RcClaimsMessage::Preclaims((who, address)) => {
if alias::Preclaims::<T>::contains_key(&who) {
return Err(Error::<T>::InsertConflict);
}
log::debug!(target: LOG_TARGET, "Processing claims message: preclaims");
log::debug!(target: LOG_TARGET, "Processing claims message: preclaims {:?}", who);
alias::Preclaims::<T>::insert(who, address);
},
}
Expand Down
14 changes: 6 additions & 8 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod account;
pub mod claims;
pub mod call;
pub mod claims;
pub mod multisig;
pub mod preimage;
pub mod proxy;
Expand All @@ -56,8 +56,8 @@ use frame_support::{
use frame_system::pallet_prelude::*;
use pallet_balances::{AccountData, Reasons as LockReasons};
use pallet_rc_migrator::{
accounts::Account as RcAccount, claims::RcClaimsMessageOf, multisig::*, preimage::*, proxy::*,
staking::nom_pools::*,
accounts::Account as RcAccount,
claims::RcClaimsMessageOf,
multisig::*,
preimage::*,
proxy::*,
Expand Down Expand Up @@ -177,8 +177,6 @@ pub mod pallet {
FailedToConvertType,
/// Failed to fetch preimage.
PreimageNotFound,
/// Failed to insert into storage because it is already present.
InsertConflict,
/// Failed to convert RC call to AH call.
FailedToConvertCall,
/// Failed to bound a call.
Expand Down Expand Up @@ -470,7 +468,7 @@ pub mod pallet {
Self::do_receive_referendums(referendums).map_err(Into::into)
}

#[pallet::call_index(10)]
#[pallet::call_index(11)]
pub fn receive_claims(
origin: OriginFor<T>,
messages: Vec<RcClaimsMessageOf<T>>,
Expand All @@ -480,7 +478,7 @@ pub mod pallet {
Self::do_receive_claims(messages).map_err(Into::into)
}

#[pallet::call_index(11)]
#[pallet::call_index(12)]
pub fn receive_bags_list_messages(
origin: OriginFor<T>,
messages: Vec<RcBagsListMessage<T>>,
Expand All @@ -490,7 +488,7 @@ pub mod pallet {
Self::do_receive_bags_list_messages(messages).map_err(Into::into)
}

#[pallet::call_index(12)]
#[pallet::call_index(13)]
pub fn receive_scheduler_messages(
origin: OriginFor<T>,
messages: Vec<scheduler::RcSchedulerMessageOf<T>>,
Expand Down
6 changes: 3 additions & 3 deletions pallets/ah-migrator/src/staking/bags_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T: Config> Pallet<T> {
messages: Vec<RcBagsListMessage<T>>,
) -> Result<(), Error<T>> {
let (mut good, mut bad) = (0, 0);
log::info!("Integrating {} BagsListMessages", messages.len());
log::info!(target: LOG_TARGET, "Integrating {} BagsListMessages", messages.len());
Self::deposit_event(Event::BatchReceived {
pallet: PalletEventName::BagsList,
count: messages.len() as u32,
Expand Down Expand Up @@ -55,15 +55,15 @@ impl<T: Config> Pallet<T> {
}

alias::ListNodes::<T>::insert(&id, &node);
log::debug!("Integrating BagsListNode: {:?}", &id);
log::debug!(target: LOG_TARGET, "Integrating BagsListNode: {:?}", &id);
},
RcBagsListMessage::Bag { score, bag } => {
if alias::ListBags::<T>::contains_key(&score) {
return Err(Error::<T>::InsertConflict);
}

alias::ListBags::<T>::insert(&score, &bag);
log::debug!("Integrating BagsListBag: {:?}", &score);
log::debug!(target: LOG_TARGET, "Integrating BagsListBag: {:?}", &score);
},
}

Expand Down
6 changes: 3 additions & 3 deletions pallets/ah-migrator/src/staking/fast_unstake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<T: Config> Pallet<T> {
messages: Vec<RcFastUnstakeMessage<T>>,
) -> Result<(), Error<T>> {
let (mut good, mut bad) = (0, 0);
log::info!("Integrating {} FastUnstakeMessages", messages.len());
log::info!(target: LOG_TARGET, "Integrating {} FastUnstakeMessages", messages.len());
Self::deposit_event(Event::BatchReceived {
pallet: PalletEventName::FastUnstake,
count: messages.len() as u32,
Expand Down Expand Up @@ -52,13 +52,13 @@ impl<T: Config> Pallet<T> {
match message {
RcFastUnstakeMessage::StorageValues { values } => {
FastUnstakeMigrator::<T>::put_values(values);
log::debug!("Integrating FastUnstakeStorageValues");
log::debug!(target: LOG_TARGET, "Integrating FastUnstakeStorageValues");
},
RcFastUnstakeMessage::Queue { member } => {
if pallet_fast_unstake::Queue::<T>::contains_key(&member.0) {
return Err(Error::<T>::InsertConflict);
}
log::debug!("Integrating FastUnstakeQueueMember: {:?}", &member.0);
log::debug!(target: LOG_TARGET, "Integrating FastUnstakeQueueMember: {:?}", &member.0);
pallet_fast_unstake::Queue::<T>::insert(member.0, member.1);
},
}
Expand Down
18 changes: 9 additions & 9 deletions pallets/ah-migrator/src/staking/nom_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: Config> Pallet<T> {
messages: Vec<RcNomPoolsMessage<T>>,
) -> Result<(), Error<T>> {
let mut good = 0;
log::info!("Integrating {} NomPoolsMessages", messages.len());
log::info!(target: LOG_TARGET, "Integrating {} NomPoolsMessages", messages.len());
Self::deposit_event(Event::NomPoolsMessagesBatchReceived { count: messages.len() as u32 });

for message in messages {
Expand All @@ -48,45 +48,45 @@ impl<T: Config> Pallet<T> {
match message {
StorageValues { values } => {
pallet_rc_migrator::staking::nom_pools::NomPoolsMigrator::<T>::put_values(values);
log::debug!("Integrating NomPoolsStorageValues");
log::debug!(target: LOG_TARGET, "Integrating NomPoolsStorageValues");
},
PoolMembers { member } => {
debug_assert!(!pallet_nomination_pools::PoolMembers::<T>::contains_key(&member.0));
log::debug!("Integrating NomPoolsPoolMember: {:?}", &member.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsPoolMember: {:?}", &member.0);
pallet_nomination_pools::PoolMembers::<T>::insert(member.0, member.1);
},
BondedPools { pool } => {
debug_assert!(!pallet_nomination_pools::BondedPools::<T>::contains_key(pool.0));
log::debug!("Integrating NomPoolsBondedPool: {}", &pool.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsBondedPool: {}", &pool.0);
pallet_nomination_pools::BondedPools::<T>::insert(
pool.0,
Self::rc_to_ah_bonded_pool(pool.1),
);
},
RewardPools { rewards } => {
log::debug!("Integrating NomPoolsRewardPool: {:?}", &rewards.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsRewardPool: {:?}", &rewards.0);
// Not sure if it is the best to use the alias here, but it is the easiest...
pallet_rc_migrator::staking::nom_pools_alias::RewardPools::<T>::insert(
rewards.0, rewards.1,
);
},
SubPoolsStorage { sub_pools } => {
log::debug!("Integrating NomPoolsSubPoolsStorage: {:?}", &sub_pools.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsSubPoolsStorage: {:?}", &sub_pools.0);
pallet_rc_migrator::staking::nom_pools_alias::SubPoolsStorage::<T>::insert(
sub_pools.0,
sub_pools.1,
);
},
Metadata { meta } => {
log::debug!("Integrating NomPoolsMetadata: {:?}", &meta.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsMetadata: {:?}", &meta.0);
pallet_nomination_pools::Metadata::<T>::insert(meta.0, meta.1);
},
ReversePoolIdLookup { lookups } => {
log::debug!("Integrating NomPoolsReversePoolIdLookup: {:?}", &lookups.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsReversePoolIdLookup: {:?}", &lookups.0);
pallet_nomination_pools::ReversePoolIdLookup::<T>::insert(lookups.0, lookups.1);
},
ClaimPermissions { perms } => {
log::debug!("Integrating NomPoolsClaimPermissions: {:?}", &perms.0);
log::debug!(target: LOG_TARGET, "Integrating NomPoolsClaimPermissions: {:?}", &perms.0);
pallet_nomination_pools::ClaimPermissions::<T>::insert(perms.0, perms.1);
},
}
Expand Down
34 changes: 17 additions & 17 deletions pallets/rc-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub use pallet::*;
pub mod scheduler;

use accounts::AccountsMigrator;
use claims::{ClaimsMigrator, ClaimsStage};
use frame_support::{
pallet_prelude::*,
sp_runtime::traits::AccountIdConversion,
Expand All @@ -60,19 +61,6 @@ use multisig::MultisigMigrator;
use pallet_balances::AccountData;
use polkadot_parachain_primitives::primitives::Id as ParaId;
use polkadot_runtime_common::{claims as pallet_claims, paras_registrar};
use runtime_parachains::hrmp;
use sp_core::{crypto::Ss58Codec, H256};
use sp_runtime::AccountId32;
use sp_std::prelude::*;
use storage::TransactionOutcome;
use types::AhWeightInfo;
use weights::WeightInfo;
use xcm::prelude::*;

use accounts::AccountsMigrator;
use claims::{ClaimsMigrator, ClaimsStage};
use multisig::MultisigMigrator;
use polkadot_runtime_common::paras_registrar;
use preimage::{
PreimageChunkMigrator, PreimageLegacyRequestStatusMigrator, PreimageRequestStatusMigrator,
};
Expand Down Expand Up @@ -117,6 +105,12 @@ pub type MigrationStageOf<T> = MigrationStage<
<T as pallet_bags_list::Config<pallet_bags_list::Instance1>>::Score,
>;

#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum PalletEventName {
FastUnstake,
BagsList,
}

#[derive(Encode, Decode, Clone, Default, RuntimeDebug, TypeInfo, MaxEncodedLen, PartialEq, Eq)]
pub enum MigrationStage<AccountId, BlockNumber, BagsListScore> {
/// The migration has not yet started but will start in the next block.
Expand All @@ -130,22 +124,23 @@ pub enum MigrationStage<AccountId, BlockNumber, BagsListScore> {
// Last migrated account
last_key: Option<AccountId>,
},
/// Accounts migration is done. Ready to go to the next one.
///
/// Note that this stage does not have any logic attached to itself. It just exists to make it
/// easier to swap out what stage should run next for testing.
AccountsMigrationDone,

MultisigMigrationInit,
MultisigMigrationOngoing {
/// Last migrated key of the `Multisigs` double map.
last_key: Option<(AccountId, [u8; 32])>,
},
MultisigMigrationDone,

ClaimsMigrationInit,
ClaimsMigrationOngoing {
current_key: Option<ClaimsStage<AccountId>>,
},
ClaimsMigrationDone,

ProxyMigrationInit,
/// Currently migrating the proxies of the proxy pallet.
ProxyMigrationProxies {
Expand All @@ -156,6 +151,7 @@ pub enum MigrationStage<AccountId, BlockNumber, BagsListScore> {
last_key: Option<AccountId>,
},
ProxyMigrationDone,

PreimageMigrationInit,
PreimageMigrationChunksOngoing {
// TODO type
Expand All @@ -172,26 +168,31 @@ pub enum MigrationStage<AccountId, BlockNumber, BagsListScore> {
},
PreimageMigrationLegacyRequestStatusDone,
PreimageMigrationDone,

NomPoolsMigrationInit,
NomPoolsMigrationOngoing {
next_key: Option<NomPoolsStage<AccountId>>,
},
NomPoolsMigrationDone,

FastUnstakeMigrationInit,
FastUnstakeMigrationOngoing {
next_key: Option<FastUnstakeStage<AccountId>>,
},
FastUnstakeMigrationDone,

ReferendaMigrationInit,
ReferendaMigrationOngoing {
last_key: Option<ReferendaStage>,
},
ReferendaMigrationDone,

BagsListMigrationInit,
BagsListMigrationOngoing {
next_key: Option<BagsListStage<AccountId, BagsListScore>>,
},
BagsListMigrationDone,

SchedulerMigrationInit,
SchedulerMigrationOngoing {
last_key: Option<scheduler::SchedulerStage<BlockNumber>>,
Expand Down Expand Up @@ -459,8 +460,7 @@ pub mod pallet {
}
},
MigrationStage::ClaimsMigrationDone => {
//Self::transition(MigrationStage::ProxyMigrationInit);
Self::transition(MigrationStage::MigrationDone);
Self::transition(MigrationStage::ProxyMigrationInit);
},
MigrationStage::ProxyMigrationInit => {
Self::transition(MigrationStage::ProxyMigrationProxies { last_key: None });
Expand Down
2 changes: 1 addition & 1 deletion pallets/rc-migrator/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<T: Config> PalletMigration for MultisigMigrator<T> {
break;
};

log::debug!("Migrating multisigs of acc {:?}", k1);
log::debug!(target: LOG_TARGET, "Migrating multisigs of acc {:?}", k1);

match Self::migrate_single(k1.clone(), multisig, weight_counter) {
Ok(ms) => batch.push(ms), // TODO continue here
Expand Down
2 changes: 1 addition & 1 deletion pallets/rc-migrator/src/preimage/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<T: Config> PalletMigration for PreimageChunkMigrator<T> {
};

if last_key.is_none() {
log::info!("No more preimages");
log::info!(target: LOG_TARGET, "No more preimages");
}

if !batch.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions pallets/rc-migrator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub enum AhMigratorCall<T: Config> {
},
#[codec(index = 10)]
ReceiveReferendums { referendums: Vec<(u32, ReferendumInfoOf<T, ()>)> },
#[codec(index = 10)]
ReceiveClaimsMessages { messages: Vec<claims::RcClaimsMessageOf<T>> },
#[codec(index = 11)]
ReceiveBagsListMessages { messages: Vec<staking::bags_list::RcBagsListMessage<T>> },
ReceiveClaimsMessages { messages: Vec<claims::RcClaimsMessageOf<T>> },
#[codec(index = 12)]
ReceiveBagsListMessages { messages: Vec<staking::bags_list::RcBagsListMessage<T>> },
#[codec(index = 13)]
ReceiveSchedulerMessages { messages: Vec<scheduler::RcSchedulerMessageOf<T>> },
}

Expand Down
2 changes: 0 additions & 2 deletions relay/polkadot/tests/ahm/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{pallet_prelude::*, traits::*};

use super::*;
use pallet_rc_migrator::RcMigrationStage;

Expand Down

0 comments on commit 3cea6f6

Please sign in to comment.