From 74479db94b96df135f9beda063a7b4569b652fd6 Mon Sep 17 00:00:00 2001 From: Parth Date: Wed, 30 Oct 2024 20:55:38 +0400 Subject: [PATCH] Runtime change required for bridge to work (#734) * runtime change required for bridge to work * fix the name of test --- Cargo.lock | 2 + Cargo.toml | 1 + runtime/common/Cargo.toml | 3 + runtime/common/src/migrations.rs | 43 ++++++++++- solo-chains/runtime/dancelight/Cargo.toml | 2 + solo-chains/runtime/dancelight/src/lib.rs | 14 ++-- .../dancelight/src/tests/common/mod.rs | 8 +- .../dancelight/src/tests/migrations_test.rs | 74 +++++++++++++++++++ .../runtime/dancelight/src/tests/mod.rs | 1 + .../chain-spec/test_chain_spec.ts | 2 +- .../interfaces/augment-api-query.ts | 28 +++---- .../src/dancelight/interfaces/lookup.ts | 10 ++- .../src/dancelight/interfaces/registry.ts | 4 + .../src/dancelight/interfaces/types-lookup.ts | 14 +++- 14 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 solo-chains/runtime/dancelight/src/tests/migrations_test.rs diff --git a/Cargo.lock b/Cargo.lock index 5bc38e1bf..8779f6f6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3221,6 +3221,7 @@ dependencies = [ "dp-container-chain-genesis-data", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-remote-externalities", "frame-support", "frame-system", @@ -17552,6 +17553,7 @@ dependencies = [ "hex-literal 0.3.4", "log", "pallet-balances", + "pallet-beefy-mmr", "pallet-configuration", "pallet-data-preservers", "pallet-foreign-asset-creator", diff --git a/Cargo.toml b/Cargo.toml index 7f295cd92..152b826c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,6 +141,7 @@ xcm-primitives = { git = "https://github.com/moondance-labs/moonkit", branch = " frame-benchmarking = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } frame-executive = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } +frame-metadata-hash-extension = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } frame-support = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } frame-system = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } frame-system-benchmarking = { git = "https://github.com/moondance-labs/polkadot-sdk", branch = "tanssi-polkadot-stable2407", default-features = false } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 994076aee..dbf2b01d6 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -37,6 +37,7 @@ frame-support = { workspace = true } frame-system = { workspace = true } frame-try-runtime = { workspace = true, optional = true } pallet-balances = { workspace = true } +pallet-beefy-mmr = { workspace = true } # Cumulus cumulus-pallet-xcmp-queue = { workspace = true } @@ -64,6 +65,7 @@ std = [ "frame-try-runtime?/std", "log/std", "pallet-balances/std", + "pallet-beefy-mmr/std", "pallet-configuration/std", "pallet-data-preservers/std", "pallet-foreign-asset-creator/std", @@ -107,6 +109,7 @@ try-runtime = [ "frame-system/try-runtime", "frame-try-runtime/try-runtime", "pallet-balances/try-runtime", + "pallet-beefy-mmr/try-runtime", "pallet-configuration/try-runtime", "pallet-data-preservers/try-runtime", "pallet-foreign-asset-creator/try-runtime", diff --git a/runtime/common/src/migrations.rs b/runtime/common/src/migrations.rs index 99e5fffb3..90b9a9934 100644 --- a/runtime/common/src/migrations.rs +++ b/runtime/common/src/migrations.rs @@ -36,6 +36,7 @@ #[cfg(feature = "try-runtime")] use frame_support::ensure; +use frame_support::migration::move_pallet; use { cumulus_primitives_core::ParaId, frame_support::{ @@ -1030,10 +1031,48 @@ where } } +pub struct MigrateMMRLeafPallet(pub PhantomData); + +impl Migration for MigrateMMRLeafPallet { + fn friendly_name(&self) -> &str { + "SM_MigrateMMRLeafPallet" + } + + fn migrate(&self, available_weight: Weight) -> Weight { + let new_name = + <::PalletInfo as frame_support::traits::PalletInfo>::name::< + pallet_beefy_mmr::Pallet, + >() + .expect("pallet_beefy_mmr must be part of dancelight before this migration"); + move_pallet(Self::old_pallet_name().as_bytes(), new_name.as_bytes()); + available_weight + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + Ok(vec![]) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, _state: Vec) -> Result<(), sp_runtime::DispatchError> { + Ok(()) + } +} + +impl MigrateMMRLeafPallet { + pub fn old_pallet_name() -> &'static str { + "MMRLeaf" + } +} + pub struct DancelightMigrations(PhantomData); -impl GetMigrations for DancelightMigrations { +impl GetMigrations for DancelightMigrations +where + Runtime: frame_system::Config, +{ fn get_migrations() -> Vec> { - vec![] + let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::(Default::default()); + vec![Box::new(migrate_mmr_leaf_pallet)] } } diff --git a/solo-chains/runtime/dancelight/Cargo.toml b/solo-chains/runtime/dancelight/Cargo.toml index 8be59fbff..c6d094c71 100644 --- a/solo-chains/runtime/dancelight/Cargo.toml +++ b/solo-chains/runtime/dancelight/Cargo.toml @@ -52,6 +52,7 @@ sp-version = { workspace = true } tx-pool-api = { workspace = true } frame-executive = { workspace = true } +frame-metadata-hash-extension = { workspace = true } frame-support = { workspace = true, features = [ "tuples-96" ] } frame-system = { workspace = true } frame-system-rpc-runtime-api = { workspace = true } @@ -175,6 +176,7 @@ std = [ "dp-container-chain-genesis-data/std", "frame-benchmarking?/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-support/std", "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", diff --git a/solo-chains/runtime/dancelight/src/lib.rs b/solo-chains/runtime/dancelight/src/lib.rs index 962593c53..788cf9418 100644 --- a/solo-chains/runtime/dancelight/src/lib.rs +++ b/solo-chains/runtime/dancelight/src/lib.rs @@ -187,7 +187,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_version: 1000, impl_version: 0, apis: RUNTIME_API_VERSIONS, - transaction_version: 25, + transaction_version: 26, state_version: 1, }; @@ -631,6 +631,7 @@ where frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_metadata_hash_extension::CheckMetadataHash::::new(false), ); let raw_payload = SignedPayload::new(call, extra) .map_err(|e| { @@ -1152,12 +1153,12 @@ impl pallet_beefy::Config for Runtime { // weight computation. type MaxNominators = ConstU32<0>; type MaxSetIdSessionEntries = BeefySetIdSessionEntries; - type OnNewValidatorSet = MmrLeaf; + type OnNewValidatorSet = BeefyMmrLeaf; type WeightInfo = (); type KeyOwnerProof = >::Proof; type EquivocationReportSystem = pallet_beefy::EquivocationReportSystem; - type AncestryHelper = MmrLeaf; + type AncestryHelper = BeefyMmrLeaf; } /// MMR helper types. @@ -1597,7 +1598,7 @@ construct_runtime! { // MMR leaf construction must be after session in order to have a leaf's next_auth_set // refer to block. Mmr: pallet_mmr = 241, - MmrLeaf: pallet_beefy_mmr = 242, + BeefyMmrLeaf: pallet_beefy_mmr = 242, EthereumBeaconClient: snowbridge_pallet_ethereum_client = 243, ParasSudoWrapper: paras_sudo_wrapper = 250, @@ -1633,6 +1634,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); /// Unchecked extrinsic type as expected by this runtime. @@ -2408,11 +2410,11 @@ sp_api::impl_runtime_apis! { impl pallet_beefy_mmr::BeefyMmrApi for RuntimeApi { fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet { - MmrLeaf::authority_set_proof() + BeefyMmrLeaf::authority_set_proof() } fn next_authority_set_proof() -> beefy_primitives::mmr::BeefyNextAuthoritySet { - MmrLeaf::next_authority_set_proof() + BeefyMmrLeaf::next_authority_set_proof() } } diff --git a/solo-chains/runtime/dancelight/src/tests/common/mod.rs b/solo-chains/runtime/dancelight/src/tests/common/mod.rs index 30687cfca..aad6788ca 100644 --- a/solo-chains/runtime/dancelight/src/tests/common/mod.rs +++ b/solo-chains/runtime/dancelight/src/tests/common/mod.rs @@ -59,8 +59,8 @@ use { pub use crate::{ genesis_config_presets::get_authority_keys_from_seed, AccountId, AuthorNoting, Babe, Balance, - Balances, Beefy, ContainerRegistrar, DataPreservers, Grandpa, InflationRewards, Initializer, - Mmr, MmrLeaf, Runtime, RuntimeOrigin, Session, System, TanssiAuthorityAssignment, + Balances, Beefy, BeefyMmrLeaf, ContainerRegistrar, DataPreservers, Grandpa, InflationRewards, + Initializer, Mmr, Runtime, RuntimeOrigin, Session, System, TanssiAuthorityAssignment, TanssiCollatorAssignment, TransactionPayment, }; @@ -250,7 +250,7 @@ pub fn start_block() -> RunSummary { Beefy::on_initialize(System::block_number()); Mmr::on_initialize(System::block_number()); - MmrLeaf::on_initialize(System::block_number()); + BeefyMmrLeaf::on_initialize(System::block_number()); RunSummary { inflation: new_issuance - current_issuance, @@ -270,7 +270,7 @@ pub fn end_block() { TanssiCollatorAssignment::on_finalize(System::block_number()); Beefy::on_finalize(System::block_number()); Mmr::on_finalize(System::block_number()); - MmrLeaf::on_finalize(System::block_number()); + BeefyMmrLeaf::on_finalize(System::block_number()); } pub fn run_block() -> RunSummary { diff --git a/solo-chains/runtime/dancelight/src/tests/migrations_test.rs b/solo-chains/runtime/dancelight/src/tests/migrations_test.rs new file mode 100644 index 000000000..3db642a3d --- /dev/null +++ b/solo-chains/runtime/dancelight/src/tests/migrations_test.rs @@ -0,0 +1,74 @@ +// Copyright (C) Moondance Labs Ltd. +// This file is part of Tanssi. + +// Tanssi 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. + +// Tanssi 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 Tanssi. If not, see + +use crate::tests::common::ExtBuilder; +use crate::{BeefyMmrLeaf, PalletInfo, Runtime}; +use beefy_primitives::mmr::BeefyAuthoritySet; +use frame_support::storage::unhashed; +use frame_support::traits::PalletInfo as _; +use pallet_migrations::Migration; +use tanssi_runtime_common::migrations::MigrateMMRLeafPallet; +use xcm::v3::Weight; + +#[test] +fn test_migration_mmr_leaf_pallet_renaming() { + ExtBuilder::default().build().execute_with(|| { + let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::(Default::default()); + let old_pallet_name = MigrateMMRLeafPallet::::old_pallet_name(); + let old_storage_1 = frame_support::storage::storage_prefix( + old_pallet_name.as_bytes(), + b"example_storage_1", + ); + let new_storage_1 = frame_support::storage::storage_prefix( + PalletInfo::name::() + .expect("BeefyMMRLeaf pallet must be part of the runtime") + .as_bytes(), + b"example_storage_1", + ); + unhashed::put(&old_storage_1, &1u64); + + let beefy_authority_set: BeefyAuthoritySet<()> = BeefyAuthoritySet { + len: 5, + ..Default::default() + }; + let old_storage_2 = frame_support::storage::storage_prefix( + old_pallet_name.as_bytes(), + b"example_storage_2", + ); + let new_storage_2 = frame_support::storage::storage_prefix( + PalletInfo::name::() + .expect("BeefyMMRLeaf pallet must be part of the runtime") + .as_bytes(), + b"example_storage_2", + ); + unhashed::put(&old_storage_2, &beefy_authority_set); + + let used_weight = migrate_mmr_leaf_pallet.migrate(Weight::MAX); + assert_eq!(used_weight, Weight::MAX); + + assert_eq!(unhashed::get::(&old_storage_1), None); + assert_eq!(unhashed::get::>(&old_storage_2), None); + + assert_eq!(unhashed::get::(&new_storage_1), Some(1u64)); + assert_eq!( + unhashed::get::>(&new_storage_2), + Some(BeefyAuthoritySet { + len: 5, + ..Default::default() + }) + ); + }); +} diff --git a/solo-chains/runtime/dancelight/src/tests/mod.rs b/solo-chains/runtime/dancelight/src/tests/mod.rs index 226c7a6f4..1945ada25 100644 --- a/solo-chains/runtime/dancelight/src/tests/mod.rs +++ b/solo-chains/runtime/dancelight/src/tests/mod.rs @@ -28,6 +28,7 @@ mod core_scheduling_tests; mod ethereum_client; mod inflation_rewards; mod integration_test; +mod migrations_test; mod relay_configuration; mod relay_registrar; mod services_payment; diff --git a/test/suites/dev-tanssi-relay/chain-spec/test_chain_spec.ts b/test/suites/dev-tanssi-relay/chain-spec/test_chain_spec.ts index b2cbdeb5b..353775a82 100644 --- a/test/suites/dev-tanssi-relay/chain-spec/test_chain_spec.ts +++ b/test/suites/dev-tanssi-relay/chain-spec/test_chain_spec.ts @@ -29,7 +29,7 @@ describeSuite({ expect(implVersion, "Relay API incorrect").to.toBe(0); const transactionVersion = polkadotJs.consts.system.version.transactionVersion.toNumber(); - expect(transactionVersion, "Relay API incorrect").to.toBe(25); + expect(transactionVersion, "Relay API incorrect").to.toBe(26); const stateVersion = polkadotJs.consts.system.version.stateVersion.toNumber(); expect(stateVersion, "Relay API incorrect").to.toBe(1); diff --git a/typescript-api/src/dancelight/interfaces/augment-api-query.ts b/typescript-api/src/dancelight/interfaces/augment-api-query.ts index c4db62082..231d1abb2 100644 --- a/typescript-api/src/dancelight/interfaces/augment-api-query.ts +++ b/typescript-api/src/dancelight/interfaces/augment-api-query.ts @@ -405,6 +405,20 @@ declare module "@polkadot/api-base/types/storage" { /** Generic query */ [key: string]: QueryableStorageEntry; }; + beefyMmrLeaf: { + /** Details of current BEEFY authority set. */ + beefyAuthorities: AugmentedQuery Observable, []> & + QueryableStorageEntry; + /** + * Details of next BEEFY authority set. + * + * This storage entry is used as cache for calls to `update_beefy_next_authority_set`. + */ + beefyNextAuthorities: AugmentedQuery Observable, []> & + QueryableStorageEntry; + /** Generic query */ + [key: string]: QueryableStorageEntry; + }; collatorConfiguration: { /** The active configuration for the current session. */ activeConfig: AugmentedQuery Observable, []> & @@ -1159,20 +1173,6 @@ declare module "@polkadot/api-base/types/storage" { /** Generic query */ [key: string]: QueryableStorageEntry; }; - mmrLeaf: { - /** Details of current BEEFY authority set. */ - beefyAuthorities: AugmentedQuery Observable, []> & - QueryableStorageEntry; - /** - * Details of next BEEFY authority set. - * - * This storage entry is used as cache for calls to `update_beefy_next_authority_set`. - */ - beefyNextAuthorities: AugmentedQuery Observable, []> & - QueryableStorageEntry; - /** Generic query */ - [key: string]: QueryableStorageEntry; - }; multiBlockMigrations: { /** * The currently active migration to run and its cursor. diff --git a/typescript-api/src/dancelight/interfaces/lookup.ts b/typescript-api/src/dancelight/interfaces/lookup.ts index a06c80654..50aea4de4 100644 --- a/typescript-api/src/dancelight/interfaces/lookup.ts +++ b/typescript-api/src/dancelight/interfaces/lookup.ts @@ -6074,6 +6074,14 @@ export default { FrameSystemExtensionsCheckWeight: "Null", /** Lookup813: pallet_transaction_payment::ChargeTransactionPayment */ PalletTransactionPaymentChargeTransactionPayment: "Compact", - /** Lookup814: dancelight_runtime::Runtime */ + /** Lookup814: frame_metadata_hash_extension::CheckMetadataHash */ + FrameMetadataHashExtensionCheckMetadataHash: { + mode: "FrameMetadataHashExtensionMode", + }, + /** Lookup815: frame_metadata_hash_extension::Mode */ + FrameMetadataHashExtensionMode: { + _enum: ["Disabled", "Enabled"], + }, + /** Lookup816: dancelight_runtime::Runtime */ DancelightRuntimeRuntime: "Null", }; diff --git a/typescript-api/src/dancelight/interfaces/registry.ts b/typescript-api/src/dancelight/interfaces/registry.ts index 6136abcfd..f16d3482e 100644 --- a/typescript-api/src/dancelight/interfaces/registry.ts +++ b/typescript-api/src/dancelight/interfaces/registry.ts @@ -38,6 +38,8 @@ import type { FinalityGrandpaEquivocationPrevote, FinalityGrandpaPrecommit, FinalityGrandpaPrevote, + FrameMetadataHashExtensionCheckMetadataHash, + FrameMetadataHashExtensionMode, FrameSupportDispatchDispatchClass, FrameSupportDispatchDispatchInfo, FrameSupportDispatchPays, @@ -488,6 +490,8 @@ declare module "@polkadot/types/types/registry" { FinalityGrandpaEquivocationPrevote: FinalityGrandpaEquivocationPrevote; FinalityGrandpaPrecommit: FinalityGrandpaPrecommit; FinalityGrandpaPrevote: FinalityGrandpaPrevote; + FrameMetadataHashExtensionCheckMetadataHash: FrameMetadataHashExtensionCheckMetadataHash; + FrameMetadataHashExtensionMode: FrameMetadataHashExtensionMode; FrameSupportDispatchDispatchClass: FrameSupportDispatchDispatchClass; FrameSupportDispatchDispatchInfo: FrameSupportDispatchDispatchInfo; FrameSupportDispatchPays: FrameSupportDispatchPays; diff --git a/typescript-api/src/dancelight/interfaces/types-lookup.ts b/typescript-api/src/dancelight/interfaces/types-lookup.ts index 63c5e7145..5e17f3fae 100644 --- a/typescript-api/src/dancelight/interfaces/types-lookup.ts +++ b/typescript-api/src/dancelight/interfaces/types-lookup.ts @@ -7857,6 +7857,18 @@ declare module "@polkadot/types/lookup" { /** @name PalletTransactionPaymentChargeTransactionPayment (813) */ interface PalletTransactionPaymentChargeTransactionPayment extends Compact {} - /** @name DancelightRuntimeRuntime (814) */ + /** @name FrameMetadataHashExtensionCheckMetadataHash (814) */ + interface FrameMetadataHashExtensionCheckMetadataHash extends Struct { + readonly mode: FrameMetadataHashExtensionMode; + } + + /** @name FrameMetadataHashExtensionMode (815) */ + interface FrameMetadataHashExtensionMode extends Enum { + readonly isDisabled: boolean; + readonly isEnabled: boolean; + readonly type: "Disabled" | "Enabled"; + } + + /** @name DancelightRuntimeRuntime (816) */ type DancelightRuntimeRuntime = Null; } // declare module