Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/ahm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub fn ah_migrate(asset_hub: &mut TestExternalities, dmp_messages: Vec<InboundDo

// NOTE that the DMP queue is probably not empty because the snapshot that we use
// contains some overweight ones.
// TODO compare with the number of messages before the migration
// TODO: @re-gius compare with the number of messages before the migration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc: @re-gius

});
asset_hub.commit_all().unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/ahm/src/multisig_still_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl RcMigrationCheck for MultisigStillWork {

for i in 0..100 {
//let num_signatories = rng.gen_range(1..=10);
//let signatories = TODO
//let signatories = TODO @ggwpez
}

multisigs
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/ahm/src/proxy/basic_still_works.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct Proxy {
pub permissions: Vec<Permission>,
/// Can control `who`.
pub delegatee: AccountId32,
// TODO also check the delay
// TODO: @ggwpez also check the delay
}

/// Map of (Delegatee, Delegator) to Vec<Permissions>
Expand Down Expand Up @@ -187,7 +187,7 @@ impl ProxyBasicWorks {
);
}

// TODO add staking etc
// TODO: @ggwpez add staking etc

// Alice cannot transfer
assert!(!Self::can_transfer(&alice, &delegator, false), "Alice cannot transfer");
Expand Down
27 changes: 26 additions & 1 deletion integration-tests/ahm/src/queues_priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

use crate::porting_prelude::*;
use asset_hub_polkadot_runtime::{AhMigrator, BuildStorage};
use frame_support::traits::OnFinalize;
use frame_support::{
traits::{DefensiveTruncateFrom, OnFinalize},
BoundedSlice,
};
use pallet_ah_migrator::{
AhMigrationStage, DmpQueuePriority, DmpQueuePriorityConfig,
Event::DmpQueuePrioritySet as DmpQueuePrioritySetEvent, MigrationStage,
Expand All @@ -27,6 +30,7 @@ use pallet_rc_migrator::{
RcMigrationStage as RcMigrationStageStorage,
};
use polkadot_runtime::RcMigrator;
use xcm_emulator::EnqueueMessage;

#[test]
fn test_force_dmp_queue_priority() {
Expand All @@ -35,6 +39,17 @@ fn test_force_dmp_queue_priority() {
.unwrap()
.into();

// prioritization is not even attempted if the migration is not ongoing
t.execute_with(|| {
use asset_hub_polkadot_runtime::MessageQueue;
use cumulus_primitives_core::AggregateMessageOrigin;

MessageQueue::enqueue_message(
BoundedSlice::defensive_truncate_from(&[1]),
AggregateMessageOrigin::Parent,
);
});

// prioritization is not even attempted if the migration is not ongoing
t.execute_with(|| {
let now = 1;
Expand Down Expand Up @@ -193,6 +208,16 @@ fn test_force_ah_ump_queue_priority() {
.unwrap()
.into();

t.execute_with(|| {
use polkadot_runtime::MessageQueue;
use runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueueId};

MessageQueue::enqueue_message(
BoundedSlice::defensive_truncate_from(&[1]),
AggregateMessageOrigin::Ump(UmpQueueId::Para(1000.into())),
);
});

// prioritization is not even attempted if the migration is not ongoing
t.execute_with(|| {
let now = 1;
Expand Down
4 changes: 1 addition & 3 deletions pallets/ah-migrator/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ impl<T: Config> Pallet<T> {
"Integrating account: {}", who.to_ss58check(),
);

// TODO run some post-migration sanity checks

// Apply all additional consumers that were excluded from the balance stuff above:
for _ in 0..account.consumers {
if let Err(e) = frame_system::Pallet::<T>::inc_consumers(&who) {
Expand Down Expand Up @@ -278,7 +276,7 @@ impl<T: Config> crate::types::AhMigrationCheck for AccountsMigrator<T> {
//assert!(
// RcAccounts::<T>::iter().next().is_none(),
// "Failed accounts should not remain in storage after migration"
//); FAIL-CI fails
//); FAIL-CI: @re-gius fails

// TODO: Giuseppe @re-gius
// run post migration sanity checks like:
Expand Down
7 changes: 7 additions & 0 deletions pallets/ah-migrator/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,13 @@ pub mod benchmarks {

#[benchmark]
fn force_dmp_queue_priority() {
use frame_support::BoundedSlice;

T::MessageQueue::enqueue_message(
BoundedSlice::defensive_truncate_from(&[1]),
AggregateMessageOrigin::Parent,
);

let now = BlockNumberFor::<T>::from(1u32);
let priority_blocks = BlockNumberFor::<T>::from(10u32);
let round_robin_blocks = BlockNumberFor::<T>::from(1u32);
Expand Down
135 changes: 71 additions & 64 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub mod xcm_config;
pub use pallet::*;
pub use pallet_rc_migrator::{
types::{
ExceptResponseFor, ForceSetHead, LeftOrRight, MaxOnIdleOrInner,
QueuePriority as DmpQueuePriority, RouteInnerWithException,
ExceptResponseFor, LeftOrRight, MaxOnIdleOrInner, QueuePriority as DmpQueuePriority,
RouteInnerWithException,
},
weights_ah,
};
Expand All @@ -82,6 +82,8 @@ use pallet_rc_migrator::{
};

use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::traits::EnqueueMessage;
use pallet_message_queue::ForceSetHead;
use pallet_rc_migrator::{
accounts::Account as RcAccount,
conviction_voting::RcConvictionVotingMessageOf,
Expand Down Expand Up @@ -347,7 +349,8 @@ pub mod pallet {
type AhPostMigrationCalls: Contains<<Self as frame_system::Config>::RuntimeCall>;

/// Means to force a next queue within the message queue processing DMP and HRMP queues.
type MessageQueue: ForceSetHead<AggregateMessageOrigin>;
type MessageQueue: ForceSetHead<AggregateMessageOrigin>
+ EnqueueMessage<AggregateMessageOrigin>;

/// The priority pattern for DMP queue processing during migration [Config::MessageQueue].
///
Expand Down Expand Up @@ -393,8 +396,7 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// The error that should to be replaced by something meaningful.
TODO,
/// Failed to unreserve deposit.
FailedToUnreserveDeposit,
/// Failed to process an account data from RC.
FailedToProcessAccount,
Expand All @@ -420,6 +422,12 @@ pub mod pallet {
DmpQueuePriorityAlreadySet,
/// Invalid parameter.
InvalidParameter,
/// Preimage missing.
PreimageMissing,
/// Preimage too big.
PreimageTooBig,
/// Preimage chunk missing.
PreimageChunkMissing,
}

#[pallet::event]
Expand Down Expand Up @@ -471,6 +479,8 @@ pub mod pallet {
BalancesBeforeRecordSet { checking_account: T::Balance, total_issuance: T::Balance },
/// The balances before the migration were consumed.
BalancesBeforeRecordConsumed { checking_account: T::Balance, total_issuance: T::Balance },
/// A referendum was cancelled because it could not be mapped.
ReferendumCanceled { id: u32 },
}

#[pallet::pallet]
Expand All @@ -487,9 +497,7 @@ pub mod pallet {
let weight_of = |account: &RcAccountFor<T>| if account.is_liquid() {
T::AhWeightInfo::receive_liquid_accounts
} else {
// TODO: use `T::AhWeightInfo::receive_accounts` with xcm v5, where
// `require_weight_at_most` not required
T::AhWeightInfo::receive_liquid_accounts
T::AhWeightInfo::receive_accounts
};
for account in accounts.iter() {
let weight = if total.is_zero() {
Expand Down Expand Up @@ -551,15 +559,17 @@ pub mod pallet {
}

#[pallet::call_index(4)]
#[pallet::weight({1})]
// TODO use with xcm v5
// #[pallet::weight({
// let mut total = Weight::zero();
// for chunk in chunks.iter() {
// total = total.saturating_add(T::AhWeightInfo::receive_preimage_chunk(chunk.
// chunk_byte_offset / chunks::CHUNK_SIZE)); }
// total
// })]
#[pallet::weight({
let mut total = Weight::zero();
for chunk in chunks.iter() {
total = total.saturating_add(
T::AhWeightInfo::receive_preimage_chunk(
chunk.chunk_byte_offset / chunks::CHUNK_SIZE,
),
);
}
total
})]
pub fn receive_preimage_chunks(
origin: OriginFor<T>,
chunks: Vec<RcPreimageChunk>,
Expand Down Expand Up @@ -655,31 +665,29 @@ pub mod pallet {

/// Receive referendums from the Relay Chain.
#[pallet::call_index(11)]
#[pallet::weight(T::AhWeightInfo::receive_complete_referendums(referendums.len() as u32))]
// TODO: use with xcm v5
// #[pallet::weight({
// let mut total = Weight::zero();
// for (_, info) in referendums.iter() {
// let weight = match info {
// ReferendumInfo::Ongoing(status) => {
// let len = status.proposal.len().defensive_unwrap_or(
// // should not happen, but we pick some sane call length.
// 512,
// );
// T::AhWeightInfo::receive_single_active_referendums(len)
// },
// _ =>
// if total.is_zero() {
// T::AhWeightInfo::receive_complete_referendums(1)
// } else {
// T::AhWeightInfo::receive_complete_referendums(1)
// .saturating_sub(T::AhWeightInfo::receive_complete_referendums(0))
// },
// };
// total = total.saturating_add(weight);
// }
// total
// })]
#[pallet::weight({
let mut total = Weight::zero();
for (_, info) in referendums.iter() {
let weight = match info {
pallet_referenda::ReferendumInfo::Ongoing(status) => {
let len = status.proposal.len().defensive_unwrap_or(
// should not happen, but we pick some sane call length.
512,
);
T::AhWeightInfo::receive_single_active_referendums(len)
},
_ =>
if total.is_zero() {
T::AhWeightInfo::receive_complete_referendums(1)
} else {
T::AhWeightInfo::receive_complete_referendums(1)
.saturating_sub(T::AhWeightInfo::receive_complete_referendums(0))
},
};
total = total.saturating_add(weight);
}
total
})]
pub fn receive_referendums(
origin: OriginFor<T>,
referendums: Vec<(u32, RcReferendumInfoOf<T, ()>)>,
Expand Down Expand Up @@ -796,25 +804,24 @@ pub mod pallet {
}

#[pallet::call_index(22)]
#[pallet::weight({1})]
// TODO: use with xcm v5
// #[pallet::weight({
// let mut total = Weight::zero();
// for (_, agenda) in messages.iter() {
// for maybe_task in agenda {
// let Some(task) = maybe_task else {
// continue;
// };
// let preimage_len = task.call.len().defensive_unwrap_or(
// // should not happen, but we assume some sane call length.
// 512,
// );
// total =
// total.saturating_add(T::AhWeightInfo::receive_single_scheduler_agenda(preimage_len));
// }
// }
// total
// })]
#[pallet::weight({
let mut total = Weight::zero();
for (_, agenda) in messages.iter() {
for maybe_task in agenda {
let Some(task) = maybe_task else {
continue;
};
let preimage_len = task.call.len().defensive_unwrap_or(
// should not happen, but we assume some sane call length.
512,
);
total = total.saturating_add(
T::AhWeightInfo::receive_single_scheduler_agenda(preimage_len),
);
}
}
total
})]
pub fn receive_scheduler_agenda_messages(
origin: OriginFor<T>,
messages: Vec<(BlockNumberFor<T>, Vec<Option<scheduler::RcScheduledOf<T>>>)>,
Expand All @@ -837,7 +844,7 @@ pub mod pallet {

#[cfg(feature = "ahm-staking-migration")]
#[pallet::call_index(30)]
#[pallet::weight({1})] // TODO: weight
#[pallet::weight({1})] // TODO: @ggwpez weight
pub fn receive_staking_messages(
origin: OriginFor<T>,
messages: Vec<T::RcStakingMessage>,
Expand Down Expand Up @@ -922,7 +929,7 @@ pub mod pallet {
weight = weight.saturating_add(T::AhWeightInfo::force_dmp_queue_priority());
}

weight.saturating_add(T::AhWeightInfo::on_finalize())
weight
}

fn on_finalize(now: BlockNumberFor<T>) {
Expand Down Expand Up @@ -1023,7 +1030,7 @@ pub mod pallet {
},
Instruction::Transact {
origin_kind: OriginKind::Xcm,
fallback_max_weight: None, // TODO @muharem: please check
fallback_max_weight: None,
call: call.encode().into(),
},
]);
Expand Down
Loading