From 4f6d486c3417bbcd8c218ed79c934c057d2ef12d Mon Sep 17 00:00:00 2001 From: brenzi Date: Fri, 26 Jan 2024 15:19:27 +0100 Subject: [PATCH] fix XCM token key padding (#252) * fix XCM token zero padding * remove applied migrations * bump spec version --- Cargo.lock | 4 +- polkadot-parachains/Cargo.toml | 2 +- .../integritee-runtime/Cargo.toml | 2 +- .../integritee-runtime/src/lib.rs | 23 +- .../integritee-runtime/src/migrations_fix.rs | 380 ------------------ .../integritee-runtime/src/xcm_config.rs | 2 +- 6 files changed, 9 insertions(+), 404 deletions(-) delete mode 100644 polkadot-parachains/integritee-runtime/src/migrations_fix.rs diff --git a/Cargo.lock b/Cargo.lock index fbe3e5aa..b3b9b126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3602,7 +3602,7 @@ dependencies = [ [[package]] name = "integritee-collator" -version = "1.7.5" +version = "1.7.6" dependencies = [ "assert_cmd", "async-trait", @@ -3687,7 +3687,7 @@ dependencies = [ [[package]] name = "integritee-runtime" -version = "1.7.42" +version = "1.7.43" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index ddcc91b7..5a1e73c1 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -2,7 +2,7 @@ name = "integritee-collator" description = "The Integritee parachain collator binary" # align major.minor revision with the runtimes. bump patch revision ad lib. make this the github release tag -version = "1.7.5" +version = "1.7.6" authors = ["Integritee AG "] homepage = "https://integritee.network/" repository = "https://github.com/integritee-network/parachain" diff --git a/polkadot-parachains/integritee-runtime/Cargo.toml b/polkadot-parachains/integritee-runtime/Cargo.toml index 3272b5ce..03779c00 100644 --- a/polkadot-parachains/integritee-runtime/Cargo.toml +++ b/polkadot-parachains/integritee-runtime/Cargo.toml @@ -2,7 +2,7 @@ name = "integritee-runtime" description = "The Integritee parachain runtime" # patch revision must match runtime spec_version -version = "1.7.42" +version = "1.7.43" authors = ["Integritee AG "] homepage = "https://integritee.network/" repository = "https://github.com/integritee-network/parachain" diff --git a/polkadot-parachains/integritee-runtime/src/lib.rs b/polkadot-parachains/integritee-runtime/src/lib.rs index 9b447fce..5bf25aad 100644 --- a/polkadot-parachains/integritee-runtime/src/lib.rs +++ b/polkadot-parachains/integritee-runtime/src/lib.rs @@ -25,9 +25,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use frame_support::{ - instances::{Instance1, Instance2}, - traits::{ConstBool, EqualPrivilegeOnly, Imbalance, InstanceFilter, OnUnbalanced}, +use frame_support::traits::{ + ConstBool, EqualPrivilegeOnly, Imbalance, InstanceFilter, OnUnbalanced, }; pub use opaque::*; use pallet_collective; @@ -93,9 +92,6 @@ pub use pallet_teerex::Call as TeerexCall; mod helpers; mod weights; -// todo: temporary. remove after fixing -mod migrations_fix; - pub mod xcm_config; pub type SessionHandlers = (); @@ -128,7 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("integritee-parachain"), impl_name: create_runtime_str!("integritee-full"), authoring_version: 2, - spec_version: 42, + spec_version: 43, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 6, @@ -823,18 +819,7 @@ pub type UncheckedExtrinsic = pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = ( - migrations_fix::preimage::v1::MigrateToV1, - migrations_fix::bounties::v4::MigrateToV4, - // Multisig - pallet_multisig::migrations::v1::MigrateToV1, - // Collective - // migration changes the pallet name prefix (back in 2021). no need to touch this. I guess this has been left untouched when we migrated solo to para - // for consistency, we will bruteforce to V4 - // future: v1.6.0 is still at V4. - migrations_fix::collective::v4::MigrateToV4, - migrations_fix::collective::v4::MigrateToV4, -); +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< diff --git a/polkadot-parachains/integritee-runtime/src/migrations_fix.rs b/polkadot-parachains/integritee-runtime/src/migrations_fix.rs deleted file mode 100644 index 59b0ce77..00000000 --- a/polkadot-parachains/integritee-runtime/src/migrations_fix.rs +++ /dev/null @@ -1,380 +0,0 @@ -// Copyright (c) 2023 Encointer Association -// This file is part of Encointer -// -// Encointer is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Encointer is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Encointer. If not, see . - -// the following are temporary local migration fixes to solve inconsistencies caused by not -// migrating Storage at the time of migrating runtime code - -pub mod scheduler { - // this is necessary because migrations from v0 to v3 are no longer available in the scheduler - // pallet code and migrating is only possible from v3. The strategy here is to empty the agenda - // (has been empty since genesis) - use frame_support::traits::OnRuntimeUpgrade; - use frame_system::pallet_prelude::BlockNumberFor; - use pallet_scheduler::*; - use sp_std::vec::Vec; - - /// The log target. - const TARGET: &'static str = "runtime::fix::scheduler::migration"; - - pub mod v1 { - use super::*; - use frame_support::{pallet_prelude::*, traits::schedule}; - - #[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq))] - #[derive(Clone, RuntimeDebug, Encode, Decode)] - pub(crate) struct ScheduledV1 { - maybe_id: Option>, - priority: schedule::Priority, - call: Call, - maybe_periodic: Option>, - } - - #[frame_support::storage_alias] - pub(crate) type Agenda = StorageMap< - Pallet, - Twox64Concat, - BlockNumberFor, - Vec::RuntimeCall, BlockNumberFor>>>, - ValueQuery, - >; - - #[frame_support::storage_alias] - pub(crate) type Lookup = - StorageMap, Twox64Concat, Vec, TaskAddress>>; - } - - pub mod v3 { - use super::*; - use frame_support::pallet_prelude::*; - - #[frame_support::storage_alias] - pub(crate) type Agenda = StorageMap< - Pallet, - Twox64Concat, - BlockNumberFor, - Vec>>, - ValueQuery, - >; - - #[frame_support::storage_alias] - pub(crate) type Lookup = - StorageMap, Twox64Concat, Vec, TaskAddress>>; - } - - pub mod v4 { - use super::*; - use frame_support::pallet_prelude::*; - - #[frame_support::storage_alias] - pub type Agenda = StorageMap< - Pallet, - Twox64Concat, - BlockNumberFor, - BoundedVec< - Option>, - ::MaxScheduledPerBlock, - >, - ValueQuery, - >; - - #[allow(dead_code)] - type TaskName = [u8; 32]; - - #[frame_support::storage_alias] - pub(crate) type Lookup = - StorageMap, Twox64Concat, TaskName, TaskAddress>>; - - /// Migrate the scheduler pallet from V0 to V4 without changing storage. the only active schedule has been submitted already in V4 - pub struct MigrateToV4(sp_std::marker::PhantomData); - - impl OnRuntimeUpgrade for MigrateToV4 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - let agendas = v1::Agenda::::iter_keys().count() as u32; - let lookups = v1::Lookup::::iter_keys().count() as u32; - log::info!(target: TARGET, "agendas present which will be left untouched: {}/{}...", agendas, lookups); - Ok((agendas, lookups).encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version >= 3 { - log::warn!( - target: TARGET, - "skipping v0 to v4 migration: executed on wrong storage version.\ - Expected version < 3, found {:?}", - onchain_version, - ); - return T::DbWeight::get().reads(1) - } - log::info!(target: TARGET, "migrating from {:?} to 4", onchain_version); - StorageVersion::new(4).put::>(); - - T::DbWeight::get().reads_writes(1, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { - ensure!(StorageVersion::get::>() == 4, "Must upgrade"); - - let agendas = Agenda::::iter_keys().count() as u32; - let lookups = Lookup::::iter_keys().count() as u32; - log::info!(target: TARGET, "agendas present a posteriori: {}/{}...", agendas, lookups); - Ok(()) - } - } - } -} - -pub mod collective { - use frame_support::traits::OnRuntimeUpgrade; - use pallet_collective::*; - - /// The log target. - const TARGET: &'static str = "runtime::fix::collective::migration"; - - pub mod v4 { - use super::*; - use frame_support::{pallet_prelude::*, traits::Instance}; - use sp_std::vec::Vec; - - pub struct MigrateToV4, I: 'static>(PhantomData<(T, I)>); - impl, I: 'static> OnRuntimeUpgrade for MigrateToV4 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, DispatchError> { - Ok((0u32).encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version >= 3 { - log::warn!( - target: TARGET, - "skipping v0 to v4 migration: executed on wrong storage version.\ - Expected version < 3, found {:?}", - onchain_version, - ); - return T::DbWeight::get().reads(1) - } - log::info!(target: TARGET, "migrating from {:?} to 4", onchain_version); - StorageVersion::new(4).put::>(); - - T::DbWeight::get().reads_writes(1, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), DispatchError> { - ensure!(StorageVersion::get::>() == 4, "Must upgrade"); - Ok(()) - } - } - } -} - -//PolkadotXcm pallet -pub mod xcm { - // this is necessary because migrations from v0 to v3 are no longer available in the scheduler - // pallet code and migrating is only possible from v3. The strategy here is to empty the agenda - // (has been empty since genesis) - use frame_support::traits::OnRuntimeUpgrade; - use pallet_xcm::*; - - /// The log target. - const TARGET: &'static str = "runtime::fix::xcm::migration"; - - pub mod v1 { - use super::*; - use frame_support::pallet_prelude::*; - use sp_std::vec::Vec; - use xcm::{prelude::XcmVersion, v3::QueryId, VersionedMultiLocation}; - - #[frame_support::storage_alias] - pub(super) type VersionNotifyTargets = StorageDoubleMap< - Pallet, - Twox64Concat, - XcmVersion, - Blake2_128Concat, - VersionedMultiLocation, - (QueryId, Weight, XcmVersion), - OptionQuery, - >; - - pub struct MigrateToV1(sp_std::marker::PhantomData); - - impl OnRuntimeUpgrade for MigrateToV1 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - let targets = VersionNotifyTargets::::iter_prefix_values(3).count() as u32; - log::info!(target: TARGET, "found {} VersionNotifyTargets", targets); - Ok(targets.encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version > 0 { - log::warn!( - target: TARGET, - "skipping v0 to v1 migration: executed on wrong storage version.\ - Expected version 0, found {:?}", - onchain_version, - ); - return T::DbWeight::get().reads(1) - } - log::info!(target: TARGET, "migrating from {:?} to 1", onchain_version); - StorageVersion::new(1).put::>(); - - T::DbWeight::get().reads_writes(1, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(state: Vec) -> Result<(), sp_runtime::DispatchError> { - ensure!(StorageVersion::get::>() == 1, "Must upgrade"); - let old_targets: u32 = Decode::decode(&mut &state[..]) - .expect("pre_upgrade provides a valid state; qed"); - let targets = VersionNotifyTargets::::iter_prefix_values(3); - assert_eq!( - old_targets, - targets.count() as u32, - "must preserve all targets and be able to decode storage" - ); - Ok(()) - } - } - } -} - -/// the bounties pallet experienced a manual version fix which we didn't implement. this bruteforces v4 -/// https://github.com/paritytech/substrate/commit/9957da3cbb027f9b754c453a4d58a62665e532ef -pub mod bounties { - // this is necessary because migrations from v0 to v3 are no longer available in the scheduler - // pallet code and migrating is only possible from v3. The strategy here is to empty the agenda - // (has been empty since genesis) - use frame_support::traits::OnRuntimeUpgrade; - use pallet_bounties::*; - - /// The log target. - const TARGET: &'static str = "runtime::fix::bounties::migration"; - - pub mod v4 { - use super::*; - use frame_support::pallet_prelude::*; - use sp_std::vec::Vec; - - pub struct MigrateToV4(sp_std::marker::PhantomData); - - impl OnRuntimeUpgrade for MigrateToV4 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - Ok(0u32.encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version >= 4 { - log::warn!( - target: TARGET, - "skipping v0 to v4 migration: executed on wrong storage version.\ - Expected version 0, found {:?}", - onchain_version, - ); - return T::DbWeight::get().reads(1) - } - log::info!(target: TARGET, "migrating from {:?} to 4", onchain_version); - StorageVersion::new(4).put::>(); - - T::DbWeight::get().reads_writes(1, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { - ensure!(StorageVersion::get::>() == 4, "Must upgrade"); - Ok(()) - } - } - } -} - -/// the bounties pallet experienced a manual version fix which we didn't implement. this bruteforces v4 -/// https://github.com/paritytech/substrate/commit/9957da3cbb027f9b754c453a4d58a62665e532ef -pub mod preimage { - // this is necessary because migrations from v0 to v3 are no longer available in the scheduler - // pallet code and migrating is only possible from v3. The strategy here is to empty the agenda - // (has been empty since genesis) - use frame_support::traits::OnRuntimeUpgrade; - use pallet_preimage::*; - - /// The log target. - const TARGET: &'static str = "runtime::fix::preimage::migration"; - - pub mod v1 { - use super::*; - use frame_support::{pallet_prelude::*, traits::Currency}; - use sp_std::vec::Vec; - - const MAX_SIZE: u32 = 4 * 1024 * 1024; - type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - - //these are actually the same types as in the current version of the pallet. - #[frame_support::storage_alias] - pub(super) type StatusFor = StorageMap< - Pallet, - Identity, - crate::Hash, - RequestStatus>, - >; - - #[frame_support::storage_alias] - pub(super) type PreimageFor = - StorageMap, Identity, (crate::Hash, u32), BoundedVec>>; - - pub struct MigrateToV1(sp_std::marker::PhantomData); - - impl OnRuntimeUpgrade for MigrateToV1 { - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, sp_runtime::DispatchError> { - let images = PreimageFor::::iter_values().count() as u32; - let status = StatusFor::::iter_values().count() as u32; - log::info!(target: TARGET, "PreImageFor decoded: {}, StatusFor decoded {}", images, status); - assert_eq!(images, status); - Ok(0u32.encode()) - } - - fn on_runtime_upgrade() -> Weight { - let onchain_version = Pallet::::on_chain_storage_version(); - if onchain_version >= 1 { - log::warn!( - target: TARGET, - "skipping v0 to v1 migration: executed on wrong storage version.\ - Expected version 0, found {:?}", - onchain_version, - ); - return T::DbWeight::get().reads(1) - } - log::info!(target: TARGET, "migrating from {:?} to 1", onchain_version); - StorageVersion::new(1).put::>(); - - T::DbWeight::get().reads_writes(1, 1) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::DispatchError> { - ensure!(StorageVersion::get::>() == 1, "Must upgrade"); - Ok(()) - } - } - } -} diff --git a/polkadot-parachains/integritee-runtime/src/xcm_config.rs b/polkadot-parachains/integritee-runtime/src/xcm_config.rs index 35729ae0..c47c5dc7 100644 --- a/polkadot-parachains/integritee-runtime/src/xcm_config.rs +++ b/polkadot-parachains/integritee-runtime/src/xcm_config.rs @@ -60,7 +60,7 @@ use xcm_executor::XcmExecutor; use xcm_transactor_primitives::*; const fn teer_general_key() -> Junction { - const TEER_KEY: [u8; 32] = *b"TEER0000000000000000000000000000"; + const TEER_KEY: [u8; 32] = *b"TEER\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; GeneralKey { length: 4, data: TEER_KEY } }