Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions pallets/ah-ops/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub mod pallet {
///
/// Solo bidder accounts that won lease auctions can use this to unreserve their amount.
#[pallet::call_index(0)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO weight
pub fn unreserve_lease_deposit(
origin: OriginFor<T>,
block: BlockNumberFor<T>,
Expand All @@ -218,7 +218,7 @@ pub mod pallet {
///
/// Can be called by any signed origin.
#[pallet::call_index(1)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO weight
pub fn withdraw_crowdloan_contribution(
origin: OriginFor<T>,
block: BlockNumberFor<T>,
Expand All @@ -240,7 +240,7 @@ pub mod pallet {
/// Can be called by any signed origin. The condition that all contributions are withdrawn
/// is in place since the reserve acts as a storage deposit.
#[pallet::call_index(2)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO weight
pub fn unreserve_crowdloan_reserve(
origin: OriginFor<T>,
block: BlockNumberFor<T>,
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ impl<T: Config> PalletMigration for AccountsMigrator<T> {
}

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceiveAccounts { accounts: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceiveAccounts { accounts: batch },
|len| T::AhWeightInfo::receive_accounts(len),
)?;
}

Ok(maybe_last_key)
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/asset_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ impl<T: Config> PalletMigration for AssetRateMigrator<T> {
}

if !messages.is_empty() {
Pallet::<T>::send_chunked_xcm(messages, |messages| {
types::AhMigratorCall::<T>::ReceiveAssetRates { asset_rates: messages }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|messages| types::AhMigratorCall::<T>::ReceiveAssetRates { asset_rates: messages },
|_| Weight::from_all(1), // TODO
)?;
}

Ok(last_key)
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ impl<T: Config> PalletMigration for BountiesMigrator<T> {
};
}

Pallet::<T>::send_chunked_xcm(messages, |messages| {
types::AhMigratorCall::<T>::ReceiveBountiesMessages { messages }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|messages| types::AhMigratorCall::<T>::ReceiveBountiesMessages { messages },
|_| Weight::from_all(1), // TODO
)?;

if last_key == BountiesStage::Finished {
log::info!(target: LOG_TARGET, "Bounties migration finished");
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ impl<T: Config> PalletMigration for ClaimsMigrator<T> {
}

if !messages.is_empty() {
Pallet::<T>::send_chunked_xcm(messages, |messages| {
types::AhMigratorCall::<T>::ReceiveClaimsMessages { messages }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|messages| types::AhMigratorCall::<T>::ReceiveClaimsMessages { messages },
|_| Weight::from_all(1), // TODO
)?;
}

if inner_key == ClaimsStage::Finished {
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/conviction_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ impl<T: Config> PalletMigration for ConvictionVotingMigrator<T> {
};
}

Pallet::<T>::send_chunked_xcm(messages, |messages| {
types::AhMigratorCall::<T>::ReceiveConvictionVotingMessages { messages }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|messages| types::AhMigratorCall::<T>::ReceiveConvictionVotingMessages { messages },
|_| Weight::from_all(1), // TODO
)?;

if last_key == ConvictionVotingStage::Finished {
Ok(None)
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/crowdloan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,11 @@ impl<T: Config> PalletMigration for CrowdloanMigrator<T>
}

if !messages.is_empty() {
Pallet::<T>::send_chunked_xcm(messages, |messages| {
types::AhMigratorCall::<T>::ReceiveCrowdloanMessages { messages }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|messages| types::AhMigratorCall::<T>::ReceiveCrowdloanMessages { messages },
|_| Weight::from_all(1), // TODO
)?;
}

if inner_key == CrowdloanStage::Finished {
Expand Down
10 changes: 6 additions & 4 deletions pallets/rc-migrator/src/indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::*;

use crate::{types::AccountIdOf, *};
use crate::types::AccountIdOf;
use frame_support::traits::Currency;

pub struct IndicesMigrator<T> {
Expand Down Expand Up @@ -84,9 +84,11 @@ impl<T: Config> PalletMigration for IndicesMigrator<T> {
}

if !messages.is_empty() {
Pallet::<T>::send_chunked_xcm(messages, |batch| {
types::AhMigratorCall::<T>::ReceiveIndices { indices: batch }
})?;
Pallet::<T>::send_chunked_xcm(
messages,
|batch| types::AhMigratorCall::<T>::ReceiveIndices { indices: batch },
|_| Weight::from_all(1), // TODO
)?;
}

Ok(inner_key)
Expand Down
51 changes: 43 additions & 8 deletions pallets/rc-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pub mod pallet {
/// This call is intended for emergency use only and is guarded by the
/// [`Config::ManagerOrigin`].
#[pallet::call_index(0)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO: weight
pub fn force_set_stage(origin: OriginFor<T>, stage: MigrationStageOf<T>) -> DispatchResult {
<T as Config>::ManagerOrigin::ensure_origin(origin)?;
Self::transition(stage);
Expand All @@ -445,7 +445,7 @@ pub mod pallet {

/// Schedule the migration to start at a given moment.
#[pallet::call_index(1)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO: weight
pub fn schedule_migration(
origin: OriginFor<T>,
start_moment: DispatchTime<BlockNumberFor<T>>,
Expand All @@ -462,7 +462,7 @@ pub mod pallet {
/// This is typically called by the Asset Hub to indicate it's readiness to receive the
/// migration data.
#[pallet::call_index(2)]
#[pallet::weight(0)]
#[pallet::weight({0})] // TODO: weight
pub fn start_data_migration(origin: OriginFor<T>) -> DispatchResult {
<T as Config>::ManagerOrigin::ensure_origin(origin)?;
Self::transition(MigrationStage::AccountsMigrationInit);
Expand Down Expand Up @@ -492,7 +492,7 @@ pub mod pallet {
},
MigrationStage::Scheduled { block_number } =>
if now >= block_number {
match Self::send_xcm(types::AhMigratorCall::<T>::StartMigration) {
match Self::send_xcm(types::AhMigratorCall::<T>::StartMigration, Weight::from_all(1)) {
Ok(_) => {
Self::transition(MigrationStage::Initializing);
},
Expand Down Expand Up @@ -1148,11 +1148,18 @@ pub mod pallet {
/// Split up the items into chunks of `MAX_XCM_SIZE` and send them as separate XCM
/// transacts.
///
/// ### Parameters:
/// - items - data items to batch and send with the `create_call`
/// - create_call - function to create the call from the items
/// - weight_at_most - function to calculate the weight limit on AH for the call with `n`
/// elements from `items`
///
/// Will modify storage in the error path.
/// This is done to avoid exceeding the XCM message size limit.
pub fn send_chunked_xcm<E: Encode>(
mut items: Vec<E>,
create_call: impl Fn(Vec<E>) -> types::AhMigratorCall<T>,
weight_at_most: impl Fn(u32) -> Weight,
) -> Result<(), Error<T>> {
log::info!(target: LOG_TARGET, "Received {} items to batch send via XCM", items.len());
items.reverse();
Expand All @@ -1173,7 +1180,8 @@ pub mod pallet {
batch.push(items.pop().unwrap()); // FAIL-CI no unwrap
}

log::info!(target: LOG_TARGET, "Sending XCM batch of {} items", batch.len());
let batch_len = batch.len() as u32;
log::info!(target: LOG_TARGET, "Sending XCM batch of {} items", batch_len);
let call = types::AssetHubPalletConfig::<T>::AhmController(create_call(batch));

let message = Xcm(vec![
Expand All @@ -1183,7 +1191,17 @@ pub mod pallet {
},
Instruction::Transact {
origin_kind: OriginKind::Superuser,
require_weight_at_most: Weight::from_all(1), // TODO
// The `require_weight_at_most` parameter is used by the XCM executor to
// verify if the available weight is sufficient to process this call. If
// sufficient, the executor will execute the call and use the actual weight
// from the dispatchable result to adjust the meter limit. The weight meter
// limit on the Asset Hub is [Config::MaxAhWeight], which applies not only
// to process the calls passed with XCM messages but also to some base work
// required to process an XCM message.
// Additionally the call will not be executed if `require_weight_at_most` is
// lower than the actual weight of the call.
// TODO: we can remove ths with XCMv5
require_weight_at_most: weight_at_most(batch_len),
call: call.encode().into(),
},
]);
Expand All @@ -1201,7 +1219,14 @@ pub mod pallet {
}

/// Send a single XCM message.
pub fn send_xcm(call: types::AhMigratorCall<T>) -> Result<(), Error<T>> {
///
/// ### Parameters:
/// - call - the call to send
/// - weight_at_most - the weight limit for the call on AH
pub fn send_xcm(
call: types::AhMigratorCall<T>,
weight_at_most: Weight,
) -> Result<(), Error<T>> {
log::info!(target: LOG_TARGET, "Sending XCM message");

let call = types::AssetHubPalletConfig::<T>::AhmController(call);
Expand All @@ -1213,7 +1238,17 @@ pub mod pallet {
},
Instruction::Transact {
origin_kind: OriginKind::Superuser,
require_weight_at_most: Weight::from_all(1), // TODO
// The `require_weight_at_most` parameter is used by the XCM executor to verify
// if the available weight is sufficient to process this call. If sufficient,
// the executor will execute the call and use the actual weight from the
// dispatchable result to adjust the meter limit. The weight meter limit on the
// Asset Hub is [Config::MaxAhWeight], which applies not only to process the
// calls passed with XCM messages but also to some base work required to process
// an XCM message.
// Additionally the call will not be executed if `require_weight_at_most` is
// lower than the actual weight of the call.
// TODO: we can remove ths with XCMv5
require_weight_at_most: weight_at_most,
call: call.encode().into(),
},
]);
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ impl<T: Config, W: AhWeightInfo> PalletMigration for MultisigMigrator<T, W> {
let (batch, last_key) = Self::migrate_out_many(last_key, weight_counter, &mut ah_weight)?;

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceiveMultisigs { multisigs: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceiveMultisigs { multisigs: batch },
|len| T::AhWeightInfo::receive_multisigs(len),
)?;
}

Ok(last_key)
Expand Down
8 changes: 5 additions & 3 deletions pallets/rc-migrator/src/preimage/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ impl<T: Config> PalletMigration for PreimageChunkMigrator<T> {
}

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceivePreimageChunks { chunks: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceivePreimageChunks { chunks: batch },
|_| Weight::from_all(1), // TODO
)?;
}

Ok(last_key)
Expand Down
10 changes: 7 additions & 3 deletions pallets/rc-migrator/src/preimage/legacy_request_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ impl<T: Config> PalletMigration for PreimageLegacyRequestStatusMigrator<T> {
};

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceivePreimageLegacyStatus { legacy_status: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceivePreimageLegacyStatus {
legacy_status: batch,
},
|_| Weight::from_all(1), // TODO
)?;
}

Ok(new_next_key)
Expand Down
10 changes: 7 additions & 3 deletions pallets/rc-migrator/src/preimage/request_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ impl<T: Config> PalletMigration for PreimageRequestStatusMigrator<T> {
};

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceivePreimageRequestStatus { request_status: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceivePreimageRequestStatus {
request_status: batch,
},
|_| Weight::from_all(1), // TODO
)?;
}

Ok(new_next_key)
Expand Down
18 changes: 12 additions & 6 deletions pallets/rc-migrator/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ impl<T: Config> PalletMigration for ProxyProxiesMigrator<T> {

// Send batch if we have any items
if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceiveProxyProxies { proxies: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceiveProxyProxies { proxies: batch },
|len| T::AhWeightInfo::receive_proxy_proxies(len),
)?;
}

// Return last processed key if there are more items, None if we're done
Expand Down Expand Up @@ -194,9 +196,13 @@ impl<T: Config> PalletMigration for ProxyAnnouncementMigrator<T> {

// Send batch if we have any items
if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceiveProxyAnnouncements { announcements: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceiveProxyAnnouncements {
announcements: batch,
},
|len| T::AhWeightInfo::receive_proxy_announcements(len),
)?;
}

// Return last processed key if there are more items, None if we're done
Expand Down
21 changes: 13 additions & 8 deletions pallets/rc-migrator/src/referenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ impl<T: Config> ReferendaMigrator<T> {
.collect::<Vec<_>>();
defensive_assert!(track_queue.len() <= TRACKS_COUNT, "Track queue unexpectedly large");

Pallet::<T>::send_xcm(types::AhMigratorCall::<T>::ReceiveReferendaValues {
referendum_count,
deciding_count,
track_queue,
})?;
Pallet::<T>::send_xcm(
types::AhMigratorCall::<T>::ReceiveReferendaValues {
referendum_count,
deciding_count,
track_queue,
},
Weight::from_all(1),
)?;

Ok(())
}
Expand Down Expand Up @@ -143,9 +146,11 @@ impl<T: Config> ReferendaMigrator<T> {
};

if !batch.is_empty() {
Pallet::<T>::send_chunked_xcm(batch, |batch| {
types::AhMigratorCall::<T>::ReceiveReferendums { referendums: batch }
})?;
Pallet::<T>::send_chunked_xcm(
batch,
|batch| types::AhMigratorCall::<T>::ReceiveReferendums { referendums: batch },
|_| Weight::from_all(1), // TODO
)?;
}

Ok(last_key)
Expand Down
Loading
Loading