Skip to content

Commit

Permalink
Merge branch 'master' into aleks-container-chains-disabled-offchain-w…
Browse files Browse the repository at this point in the history
…orkers-check
  • Loading branch information
chexware authored Oct 30, 2024
2 parents 5c8f778 + 74479db commit 1ef792a
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,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 }
Expand Down
3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
43 changes: 41 additions & 2 deletions runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -1030,10 +1031,48 @@ where
}
}

pub struct MigrateMMRLeafPallet<T>(pub PhantomData<T>);

impl<T: frame_system::Config> Migration for MigrateMMRLeafPallet<T> {
fn friendly_name(&self) -> &str {
"SM_MigrateMMRLeafPallet"
}

fn migrate(&self, available_weight: Weight) -> Weight {
let new_name =
<<T as frame_system::Config>::PalletInfo as frame_support::traits::PalletInfo>::name::<
pallet_beefy_mmr::Pallet<T>,
>()
.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<Vec<u8>, sp_runtime::DispatchError> {
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
Ok(())
}
}

impl<T> MigrateMMRLeafPallet<T> {
pub fn old_pallet_name() -> &'static str {
"MMRLeaf"
}
}

pub struct DancelightMigrations<Runtime>(PhantomData<Runtime>);

impl<Runtime> GetMigrations for DancelightMigrations<Runtime> {
impl<Runtime> GetMigrations for DancelightMigrations<Runtime>
where
Runtime: frame_system::Config,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
vec![]
let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::<Runtime>(Default::default());
vec![Box::new(migrate_mmr_leaf_pallet)]
}
}
2 changes: 2 additions & 0 deletions solo-chains/runtime/dancelight/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -631,6 +631,7 @@ where
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
Expand Down Expand Up @@ -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 = <Historical as KeyOwnerProofSystem<(KeyTypeId, BeefyId)>>::Proof;
type EquivocationReportSystem =
pallet_beefy::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
type AncestryHelper = MmrLeaf;
type AncestryHelper = BeefyMmrLeaf;
}

/// MMR helper types.
Expand Down Expand Up @@ -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<N>.
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,
Expand Down Expand Up @@ -1633,6 +1634,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);

/// Unchecked extrinsic type as expected by this runtime.
Expand Down Expand Up @@ -2408,11 +2410,11 @@ sp_api::impl_runtime_apis! {

impl pallet_beefy_mmr::BeefyMmrApi<Block, Hash> for RuntimeApi {
fn authority_set_proof() -> beefy_primitives::mmr::BeefyAuthoritySet<Hash> {
MmrLeaf::authority_set_proof()
BeefyMmrLeaf::authority_set_proof()
}

fn next_authority_set_proof() -> beefy_primitives::mmr::BeefyNextAuthoritySet<Hash> {
MmrLeaf::next_authority_set_proof()
BeefyMmrLeaf::next_authority_set_proof()
}
}

Expand Down
8 changes: 4 additions & 4 deletions solo-chains/runtime/dancelight/src/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
74 changes: 74 additions & 0 deletions solo-chains/runtime/dancelight/src/tests/migrations_test.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>

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::<Runtime>(Default::default());
let old_pallet_name = MigrateMMRLeafPallet::<Runtime>::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::<BeefyMmrLeaf>()
.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::<BeefyMmrLeaf>()
.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::<u64>(&old_storage_1), None);
assert_eq!(unhashed::get::<BeefyAuthoritySet<()>>(&old_storage_2), None);

assert_eq!(unhashed::get::<u64>(&new_storage_1), Some(1u64));
assert_eq!(
unhashed::get::<BeefyAuthoritySet<()>>(&new_storage_2),
Some(BeefyAuthoritySet {
len: 5,
..Default::default()
})
);
});
}
1 change: 1 addition & 0 deletions solo-chains/runtime/dancelight/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev-tanssi-relay/chain-spec/test_chain_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions typescript-api/src/dancelight/interfaces/augment-api-query.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion typescript-api/src/dancelight/interfaces/lookup.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions typescript-api/src/dancelight/interfaces/registry.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1ef792a

Please sign in to comment.