diff --git a/pallets/ah-ops/src/lib.rs b/pallets/ah-ops/src/lib.rs index 7eba5947e4..0f40d07a5e 100644 --- a/pallets/ah-ops/src/lib.rs +++ b/pallets/ah-ops/src/lib.rs @@ -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, block: BlockNumberFor, @@ -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, block: BlockNumberFor, @@ -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, block: BlockNumberFor, diff --git a/pallets/rc-migrator/src/accounts.rs b/pallets/rc-migrator/src/accounts.rs index 705740acee..c64e714032 100644 --- a/pallets/rc-migrator/src/accounts.rs +++ b/pallets/rc-migrator/src/accounts.rs @@ -264,9 +264,11 @@ impl PalletMigration for AccountsMigrator { } if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceiveAccounts { accounts: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceiveAccounts { accounts: batch }, + |len| T::AhWeightInfo::receive_accounts(len), + )?; } Ok(maybe_last_key) diff --git a/pallets/rc-migrator/src/asset_rate.rs b/pallets/rc-migrator/src/asset_rate.rs index fda06ef549..f2a7da4cfe 100644 --- a/pallets/rc-migrator/src/asset_rate.rs +++ b/pallets/rc-migrator/src/asset_rate.rs @@ -70,9 +70,11 @@ impl PalletMigration for AssetRateMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveAssetRates { asset_rates: messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveAssetRates { asset_rates: messages }, + |_| Weight::from_all(1), // TODO + )?; } Ok(last_key) diff --git a/pallets/rc-migrator/src/bounties.rs b/pallets/rc-migrator/src/bounties.rs index 6788c21b01..67230ee91d 100644 --- a/pallets/rc-migrator/src/bounties.rs +++ b/pallets/rc-migrator/src/bounties.rs @@ -138,9 +138,11 @@ impl PalletMigration for BountiesMigrator { }; } - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveBountiesMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveBountiesMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; if last_key == BountiesStage::Finished { log::info!(target: LOG_TARGET, "Bounties migration finished"); diff --git a/pallets/rc-migrator/src/claims.rs b/pallets/rc-migrator/src/claims.rs index 997077d916..226faeaf9a 100644 --- a/pallets/rc-migrator/src/claims.rs +++ b/pallets/rc-migrator/src/claims.rs @@ -160,9 +160,11 @@ impl PalletMigration for ClaimsMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveClaimsMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveClaimsMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; } if inner_key == ClaimsStage::Finished { diff --git a/pallets/rc-migrator/src/conviction_voting.rs b/pallets/rc-migrator/src/conviction_voting.rs index 5d490c11e8..377da87166 100644 --- a/pallets/rc-migrator/src/conviction_voting.rs +++ b/pallets/rc-migrator/src/conviction_voting.rs @@ -141,9 +141,11 @@ impl PalletMigration for ConvictionVotingMigrator { }; } - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveConvictionVotingMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveConvictionVotingMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; if last_key == ConvictionVotingStage::Finished { Ok(None) diff --git a/pallets/rc-migrator/src/crowdloan.rs b/pallets/rc-migrator/src/crowdloan.rs index 9be763a8a0..9895028cf2 100644 --- a/pallets/rc-migrator/src/crowdloan.rs +++ b/pallets/rc-migrator/src/crowdloan.rs @@ -255,9 +255,11 @@ impl PalletMigration for CrowdloanMigrator } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveCrowdloanMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveCrowdloanMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; } if inner_key == CrowdloanStage::Finished { diff --git a/pallets/rc-migrator/src/indices.rs b/pallets/rc-migrator/src/indices.rs index 5fe1ab8b60..7026dff48e 100644 --- a/pallets/rc-migrator/src/indices.rs +++ b/pallets/rc-migrator/src/indices.rs @@ -20,7 +20,7 @@ use crate::*; -use crate::{types::AccountIdOf, *}; +use crate::types::AccountIdOf; use frame_support::traits::Currency; pub struct IndicesMigrator { @@ -84,9 +84,11 @@ impl PalletMigration for IndicesMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |batch| { - types::AhMigratorCall::::ReceiveIndices { indices: batch } - })?; + Pallet::::send_chunked_xcm( + messages, + |batch| types::AhMigratorCall::::ReceiveIndices { indices: batch }, + |_| Weight::from_all(1), // TODO + )?; } Ok(inner_key) diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 2a06423212..010ec982f7 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -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, stage: MigrationStageOf) -> DispatchResult { ::ManagerOrigin::ensure_origin(origin)?; Self::transition(stage); @@ -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, start_moment: DispatchTime>, @@ -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) -> DispatchResult { ::ManagerOrigin::ensure_origin(origin)?; Self::transition(MigrationStage::AccountsMigrationInit); @@ -492,7 +492,7 @@ pub mod pallet { }, MigrationStage::Scheduled { block_number } => if now >= block_number { - match Self::send_xcm(types::AhMigratorCall::::StartMigration) { + match Self::send_xcm(types::AhMigratorCall::::StartMigration, Weight::from_all(1)) { Ok(_) => { Self::transition(MigrationStage::Initializing); }, @@ -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( mut items: Vec, create_call: impl Fn(Vec) -> types::AhMigratorCall, + weight_at_most: impl Fn(u32) -> Weight, ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Received {} items to batch send via XCM", items.len()); items.reverse(); @@ -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::::AhmController(create_call(batch)); let message = Xcm(vec![ @@ -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(), }, ]); @@ -1201,7 +1219,14 @@ pub mod pallet { } /// Send a single XCM message. - pub fn send_xcm(call: types::AhMigratorCall) -> Result<(), Error> { + /// + /// ### Parameters: + /// - call - the call to send + /// - weight_at_most - the weight limit for the call on AH + pub fn send_xcm( + call: types::AhMigratorCall, + weight_at_most: Weight, + ) -> Result<(), Error> { log::info!(target: LOG_TARGET, "Sending XCM message"); let call = types::AssetHubPalletConfig::::AhmController(call); @@ -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(), }, ]); diff --git a/pallets/rc-migrator/src/multisig.rs b/pallets/rc-migrator/src/multisig.rs index d8c4b98ff8..1e0ce807a0 100644 --- a/pallets/rc-migrator/src/multisig.rs +++ b/pallets/rc-migrator/src/multisig.rs @@ -160,9 +160,11 @@ impl PalletMigration for MultisigMigrator { let (batch, last_key) = Self::migrate_out_many(last_key, weight_counter, &mut ah_weight)?; if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceiveMultisigs { multisigs: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceiveMultisigs { multisigs: batch }, + |len| T::AhWeightInfo::receive_multisigs(len), + )?; } Ok(last_key) diff --git a/pallets/rc-migrator/src/preimage/chunks.rs b/pallets/rc-migrator/src/preimage/chunks.rs index b14e9aff2e..a45134d871 100644 --- a/pallets/rc-migrator/src/preimage/chunks.rs +++ b/pallets/rc-migrator/src/preimage/chunks.rs @@ -121,9 +121,11 @@ impl PalletMigration for PreimageChunkMigrator { } if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceivePreimageChunks { chunks: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceivePreimageChunks { chunks: batch }, + |_| Weight::from_all(1), // TODO + )?; } Ok(last_key) diff --git a/pallets/rc-migrator/src/preimage/legacy_request_status.rs b/pallets/rc-migrator/src/preimage/legacy_request_status.rs index b324d5ce59..3cdc869870 100644 --- a/pallets/rc-migrator/src/preimage/legacy_request_status.rs +++ b/pallets/rc-migrator/src/preimage/legacy_request_status.rs @@ -86,9 +86,13 @@ impl PalletMigration for PreimageLegacyRequestStatusMigrator { }; if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceivePreimageLegacyStatus { legacy_status: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceivePreimageLegacyStatus { + legacy_status: batch, + }, + |_| Weight::from_all(1), // TODO + )?; } Ok(new_next_key) diff --git a/pallets/rc-migrator/src/preimage/request_status.rs b/pallets/rc-migrator/src/preimage/request_status.rs index b7a11a6662..182934ca73 100644 --- a/pallets/rc-migrator/src/preimage/request_status.rs +++ b/pallets/rc-migrator/src/preimage/request_status.rs @@ -72,9 +72,13 @@ impl PalletMigration for PreimageRequestStatusMigrator { }; if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceivePreimageRequestStatus { request_status: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceivePreimageRequestStatus { + request_status: batch, + }, + |_| Weight::from_all(1), // TODO + )?; } Ok(new_next_key) diff --git a/pallets/rc-migrator/src/proxy.rs b/pallets/rc-migrator/src/proxy.rs index 585616c5b8..5f82f566f9 100644 --- a/pallets/rc-migrator/src/proxy.rs +++ b/pallets/rc-migrator/src/proxy.rs @@ -110,9 +110,11 @@ impl PalletMigration for ProxyProxiesMigrator { // Send batch if we have any items if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceiveProxyProxies { proxies: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceiveProxyProxies { proxies: batch }, + |len| T::AhWeightInfo::receive_proxy_proxies(len), + )?; } // Return last processed key if there are more items, None if we're done @@ -194,9 +196,13 @@ impl PalletMigration for ProxyAnnouncementMigrator { // Send batch if we have any items if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceiveProxyAnnouncements { announcements: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceiveProxyAnnouncements { + announcements: batch, + }, + |len| T::AhWeightInfo::receive_proxy_announcements(len), + )?; } // Return last processed key if there are more items, None if we're done diff --git a/pallets/rc-migrator/src/referenda.rs b/pallets/rc-migrator/src/referenda.rs index 4d7cc6e998..be44566c14 100644 --- a/pallets/rc-migrator/src/referenda.rs +++ b/pallets/rc-migrator/src/referenda.rs @@ -75,11 +75,14 @@ impl ReferendaMigrator { .collect::>(); defensive_assert!(track_queue.len() <= TRACKS_COUNT, "Track queue unexpectedly large"); - Pallet::::send_xcm(types::AhMigratorCall::::ReceiveReferendaValues { - referendum_count, - deciding_count, - track_queue, - })?; + Pallet::::send_xcm( + types::AhMigratorCall::::ReceiveReferendaValues { + referendum_count, + deciding_count, + track_queue, + }, + Weight::from_all(1), + )?; Ok(()) } @@ -143,9 +146,11 @@ impl ReferendaMigrator { }; if !batch.is_empty() { - Pallet::::send_chunked_xcm(batch, |batch| { - types::AhMigratorCall::::ReceiveReferendums { referendums: batch } - })?; + Pallet::::send_chunked_xcm( + batch, + |batch| types::AhMigratorCall::::ReceiveReferendums { referendums: batch }, + |_| Weight::from_all(1), // TODO + )?; } Ok(last_key) diff --git a/pallets/rc-migrator/src/scheduler.rs b/pallets/rc-migrator/src/scheduler.rs index c708e6f3c4..42f582e4cd 100644 --- a/pallets/rc-migrator/src/scheduler.rs +++ b/pallets/rc-migrator/src/scheduler.rs @@ -128,9 +128,11 @@ impl PalletMigration for SchedulerMigrator { }; } - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveSchedulerMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveSchedulerMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; if last_key == SchedulerStage::Finished { Ok(None) diff --git a/pallets/rc-migrator/src/staking/bags_list.rs b/pallets/rc-migrator/src/staking/bags_list.rs index 9ab41121b8..168bdf652e 100644 --- a/pallets/rc-migrator/src/staking/bags_list.rs +++ b/pallets/rc-migrator/src/staking/bags_list.rs @@ -120,9 +120,11 @@ impl PalletMigration for BagsListMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveBagsListMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveBagsListMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; } if inner_key == BagsListStage::Finished { diff --git a/pallets/rc-migrator/src/staking/fast_unstake.rs b/pallets/rc-migrator/src/staking/fast_unstake.rs index 801f524e70..58fa83bd68 100644 --- a/pallets/rc-migrator/src/staking/fast_unstake.rs +++ b/pallets/rc-migrator/src/staking/fast_unstake.rs @@ -138,9 +138,11 @@ impl PalletMigration for FastUnstakeMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveFastUnstakeMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveFastUnstakeMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; } if inner_key == FastUnstakeStage::Finished { diff --git a/pallets/rc-migrator/src/staking/nom_pools.rs b/pallets/rc-migrator/src/staking/nom_pools.rs index 8f070e1795..316b5f96d6 100644 --- a/pallets/rc-migrator/src/staking/nom_pools.rs +++ b/pallets/rc-migrator/src/staking/nom_pools.rs @@ -273,9 +273,11 @@ impl PalletMigration for NomPoolsMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::::ReceiveNomPoolsMessages { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::::ReceiveNomPoolsMessages { messages }, + |_| Weight::from_all(1), // TODO + )?; } if inner_key == NomPoolsStage::Finished { diff --git a/pallets/rc-migrator/src/vesting.rs b/pallets/rc-migrator/src/vesting.rs index efe09049ed..c862aacb1a 100644 --- a/pallets/rc-migrator/src/vesting.rs +++ b/pallets/rc-migrator/src/vesting.rs @@ -86,9 +86,11 @@ impl PalletMigration for VestingMigrator { } if !messages.is_empty() { - Pallet::::send_chunked_xcm(messages, |messages| { - types::AhMigratorCall::ReceiveVestingSchedules { messages } - })?; + Pallet::::send_chunked_xcm( + messages, + |messages| types::AhMigratorCall::ReceiveVestingSchedules { messages }, + |_| Weight::from_all(1), // TODO + )?; } Ok(inner_key)