Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Properly migrate weights to v2 (#6091)
Browse files Browse the repository at this point in the history
* Create migration for config pallet

* Use XcmWeight in XCM pallet extrinsics

* Link to PR in doc comment

* cargo fmt

* Fix tests

* Fix tests

* Remove unused import

* Update runtime/parachains/src/configuration/migration.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add missing on_runtime_upgrade implementation

* Use new migration API

* cargo fmt

* Fix log message

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
KiChjang and ggwpez authored Oct 5, 2022
1 parent edd6499 commit 3eb61f8
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 16 deletions.
1 change: 1 addition & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ pub type Executive = frame_executive::Executive<
StakingMigrationV11OldPallet,
>,
pallet_staking::migrations::v12::MigrateToV12<Runtime>,
parachains_configuration::migration::v3::MigrateToV3<Runtime>,
),
>;
/// The payload being signed in the transactions.
Expand Down
3 changes: 2 additions & 1 deletion runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
hrmp_max_parachain_outbound_channels: Default::default(),
hrmp_max_parathread_outbound_channels: Default::default(),
hrmp_max_message_num_per_candidate: Default::default(),
ump_max_individual_weight: 20u64 * WEIGHT_PER_MILLIS,
ump_max_individual_weight: (20u64 * WEIGHT_PER_MILLIS)
.set_proof_size(MAX_POV_SIZE as u64),
pvf_checking_enabled: false,
pvf_voting_ttl: 2u32.into(),
minimum_validation_upgrade_delay: 2.into(),
Expand Down
322 changes: 320 additions & 2 deletions runtime/parachains/src/configuration/migration.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,7 @@ pub type Executive = frame_executive::Executive<
StakingMigrationV11OldPallet,
>,
pallet_staking::migrations::v12::MigrateToV12<Runtime>,
parachains_configuration::migration::v3::MigrateToV3<Runtime>,
),
>;

Expand Down
1 change: 1 addition & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(parachains_configuration::migration::v3::MigrateToV3<Runtime>,),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
Expand Down
1 change: 1 addition & 0 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ pub type Executive = frame_executive::Executive<
StakingMigrationV11OldPallet,
>,
pallet_staking::migrations::v12::MigrateToV12<Runtime>,
parachains_configuration::migration::v3::MigrateToV3<Runtime>,
),
>;
/// The payload being signed in transactions.
Expand Down
10 changes: 5 additions & 5 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sp_runtime::{
RuntimeDebug,
};
use sp_std::{boxed::Box, marker::PhantomData, prelude::*, result::Result, vec};
use xcm::prelude::*;
use xcm::{latest::Weight as XcmWeight, prelude::*};
use xcm_executor::traits::ConvertOrigin;

use frame_support::PalletId;
Expand Down Expand Up @@ -570,11 +570,11 @@ pub mod pallet {
///
/// NOTE: A successful return to this does *not* imply that the `msg` was executed successfully
/// to completion; only that *some* of it was executed.
#[pallet::weight(max_weight.saturating_add(Weight::from_ref_time(100_000_000u64)))]
#[pallet::weight(Weight::from_ref_time(max_weight.saturating_add(100_000_000u64)))]
pub fn execute(
origin: OriginFor<T>,
message: Box<VersionedXcm<<T as SysConfig>::RuntimeCall>>,
max_weight: Weight,
max_weight: XcmWeight,
) -> DispatchResultWithPostInfo {
let origin_location = T::ExecuteXcmOrigin::ensure_origin(origin)?;
let message = (*message).try_into().map_err(|()| Error::<T>::BadVersion)?;
Expand All @@ -584,8 +584,8 @@ pub mod pallet {
let outcome = T::XcmExecutor::execute_xcm_in_credit(
origin_location,
message,
max_weight.ref_time(),
max_weight.ref_time(),
max_weight,
max_weight,
);
let result = Ok(Some(outcome.weight_used().saturating_add(100_000_000)).into());
Self::deposit_event(Event::Attempted(outcome));
Expand Down
8 changes: 4 additions & 4 deletions xcm/pallet-xcm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ fn execute_withdraw_to_deposit_works() {
buy_execution((Here, SEND_AMOUNT)),
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
]))),
Weight::from_ref_time(weight)
weight
));
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
assert_eq!(Balances::total_balance(&BOB), SEND_AMOUNT);
Expand Down Expand Up @@ -549,7 +549,7 @@ fn trapped_assets_can_be_claimed() {
// This would succeed, but we never get to it.
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest.clone() },
]))),
Weight::from_ref_time(weight)
weight
));
let source: MultiLocation =
Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into() }.into();
Expand Down Expand Up @@ -579,7 +579,7 @@ fn trapped_assets_can_be_claimed() {
buy_execution((Here, SEND_AMOUNT)),
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest.clone() },
]))),
Weight::from_ref_time(weight)
weight
));

assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
Expand All @@ -594,7 +594,7 @@ fn trapped_assets_can_be_claimed() {
buy_execution((Here, SEND_AMOUNT)),
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
]))),
Weight::from_ref_time(weight)
weight
));
assert_eq!(
last_event(),
Expand Down
7 changes: 3 additions & 4 deletions xcm/xcm-executor/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg(test)]

use frame_support::weights::Weight;
use polkadot_test_client::{
BlockBuilderExt, ClientBlockImportExt, DefaultTestClientBuilderExt, ExecutionStrategy,
InitPolkadotBlockBuilder, TestClientBuilder, TestClientBuilderExt,
Expand Down Expand Up @@ -47,7 +46,7 @@ fn basic_buy_fees_message_executes() {
&client,
polkadot_test_runtime::RuntimeCall::Xcm(pallet_xcm::Call::execute {
message: Box::new(VersionedXcm::from(msg)),
max_weight: Weight::from_ref_time(1_000_000_000),
max_weight: 1_000_000_000,
}),
sp_keyring::Sr25519Keyring::Alice,
0,
Expand Down Expand Up @@ -129,7 +128,7 @@ fn query_response_fires() {
&client,
polkadot_test_runtime::RuntimeCall::Xcm(pallet_xcm::Call::execute {
message: msg,
max_weight: Weight::from_ref_time(1_000_000_000),
max_weight: 1_000_000_000,
}),
sp_keyring::Sr25519Keyring::Alice,
1,
Expand Down Expand Up @@ -217,7 +216,7 @@ fn query_response_elicits_handler() {
&client,
polkadot_test_runtime::RuntimeCall::Xcm(pallet_xcm::Call::execute {
message: Box::new(VersionedXcm::from(msg)),
max_weight: Weight::from_ref_time(1_000_000_000),
max_weight: 1_000_000_000,
}),
sp_keyring::Sr25519Keyring::Alice,
1,
Expand Down

0 comments on commit 3eb61f8

Please sign in to comment.