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

Companion for substrate#9878 #3949

Merged
merged 11 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{
construct_runtime, match_type, parameter_types,
traits::{Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing},
traits::{Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing, OnRuntimeUpgrade},
weights::Weight,
PalletId, RuntimeDebug,
};
Expand Down Expand Up @@ -1565,11 +1565,39 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
(),
(SessionHistoricalPalletPrefixMigration,),
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

const SESSION_HISTORICAL_OLD_PREFIX: &str = "Session";
/// Migrate session-historical from `Session` to the new pallet prefix `Historical`
pub struct SessionHistoricalPalletPrefixMigration;

impl OnRuntimeUpgrade for SessionHistoricalPalletPrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_session::migrations::v1::migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::pre_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::post_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}
}

#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down
102 changes: 15 additions & 87 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{
construct_runtime, parameter_types,
traits::{Contains, KeyOwnerProofSystem, LockIdentifier, OnRuntimeUpgrade},
weights::{constants::WEIGHT_PER_MILLIS, Weight},
weights::Weight,
PalletId, RuntimeDebug,
};
use frame_system::{EnsureOneOf, EnsureRoot};
Expand Down Expand Up @@ -1369,7 +1369,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
StakingBagsListMigrationV8,
(StakingBagsListMigrationV8, SessionHistoricalPalletPrefixMigration),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
Expand All @@ -1393,102 +1393,30 @@ impl OnRuntimeUpgrade for StakingBagsListMigrationV8 {
}
}

/// Set the initial host configuration for Polkadot.
pub struct SetInitialHostConfiguration;
impl OnRuntimeUpgrade for SetInitialHostConfiguration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use parachains_configuration::HostConfiguration;

let active_config: HostConfiguration<BlockNumber> = HostConfiguration {
max_code_size: 10_485_760,
max_head_data_size: 20_480,
max_upward_queue_count: 10,
max_upward_queue_size: 51_200,
max_upward_message_size: 51_200,
max_upward_message_num_per_candidate: 10,
hrmp_max_message_num_per_candidate: 10,
validation_upgrade_frequency: 14_400,
validation_upgrade_delay: 600,
max_pov_size: 5_242_880,
max_downward_message_size: 51_200,
ump_service_total_weight: 100_000_000_000,
hrmp_max_parachain_outbound_channels: 10,
hrmp_max_parathread_outbound_channels: 0,
hrmp_sender_deposit: deposit(1004, 100 * 1024),
hrmp_recipient_deposit: deposit(1004, 100 * 1024),
hrmp_channel_max_capacity: 1_000,
hrmp_channel_max_total_size: 102_400,
hrmp_max_parachain_inbound_channels: 10,
hrmp_max_parathread_inbound_channels: 0,
hrmp_channel_max_message_size: 102_400,
code_retention_period: EPOCH_DURATION_IN_SLOTS * 6,
parathread_cores: 0,
parathread_retries: 0,
group_rotation_frequency: 10,
chain_availability_period: 10,
thread_availability_period: 10,
scheduling_lookahead: 1,
max_validators_per_core: Some(5),
max_validators: Some(200),
dispute_period: 6,
dispute_post_conclusion_acceptance_period: 600,
dispute_max_spam_slots: 2,
dispute_conclusion_by_time_out_period: 600,
no_show_slots: 2,
n_delay_tranches: 89,
zeroth_delay_tranche_width: 0,
needed_approvals: 30,
relay_vrf_modulo_samples: 40,
ump_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
};

// Only set the config if it's needed to be set explicitly.
if Configuration::config() == Default::default() {
Configuration::force_set_active_config(active_config);
}

{
// At the moment, the `parachains_configuration` crate has already had one runtime
// storage migration (performed as part of [#3575]). As the result a call to
// `StorageVersion::get::<Configuration>` will return `Some(1)`
//
// However, Polkadot is just about to have its first version of parachains runtime
// pallets and thus there is no existing storage which needs to be migrated. Above
// we just have set the active configuration of the actual version, i.e. the same as the
// version 1 on Kusama.
//
// The caveat here is when we deploy a module for the first time, it's runtime version
// will be empty and thus it will be considered as version 0. Since we want to avoid
// the situation where the same storage structure has version 0 on Polkadot and
// version 1 on Kusama we need to set the storage version explicitly.
//
// [#3575]: https://github.com/paritytech/polkadot/pull/3575
use frame_support::traits::StorageVersion;
StorageVersion::new(1).put::<Configuration>();
}
koushiro marked this conversation as resolved.
Show resolved Hide resolved
const SESSION_HISTORICAL_OLD_PREFIX: &str = "Session";
/// Migrate session-historical from `Session` to the new pallet prefix `Historical`
pub struct SessionHistoricalPalletPrefixMigration;

RocksDbWeight::get().reads(1) + RocksDbWeight::get().writes(1)
}
}

const TIPS_OLD_PREFIX: &str = "Treasury";
/// Migrate pallet-tips from `Treasury` to the new pallet prefix `Tips`
pub struct MigrateTipsPalletPrefix;

impl OnRuntimeUpgrade for MigrateTipsPalletPrefix {
impl OnRuntimeUpgrade for SessionHistoricalPalletPrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_tips::migrations::v4::migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX)
pallet_session::migrations::v1::migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_tips::migrations::v4::pre_migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX);
pallet_session::migrations::v1::pre_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_tips::migrations::v4::post_migrate::<Runtime, Tips, _>(TIPS_OLD_PREFIX);
pallet_session::migrations::v1::post_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}
}
Expand Down
32 changes: 30 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub use pallet_balances::Call as BalancesCall;
use polkadot_parachain::primitives::Id as ParaId;

use constants::{currency::*, fee::*, time::*};
use frame_support::traits::InstanceFilter;
use frame_support::traits::{InstanceFilter, OnRuntimeUpgrade};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, BackingToPlurality,
Expand Down Expand Up @@ -158,11 +158,39 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
(),
(SessionHistoricalModulePrefixMigration,),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

const SESSION_HISTORICAL_OLD_PREFIX: &str = "Session";
/// Migrate session-historical from `Session` to the new pallet prefix `Historical`
pub struct SessionHistoricalModulePrefixMigration;

impl OnRuntimeUpgrade for SessionHistoricalModulePrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_session::migrations::v1::migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::pre_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::post_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}
}

impl_opaque_keys! {
pub struct SessionKeys {
pub grandpa: Grandpa,
Expand Down
34 changes: 32 additions & 2 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{
construct_runtime, parameter_types,
traits::{Contains, Everything, InstanceFilter, KeyOwnerProofSystem, Nothing},
traits::{
Contains, Everything, InstanceFilter, KeyOwnerProofSystem, Nothing, OnRuntimeUpgrade,
},
weights::Weight,
PalletId, RuntimeDebug,
};
Expand Down Expand Up @@ -1139,11 +1141,39 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
(),
(SessionHistoricalPalletPrefixMigration,),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

const SESSION_HISTORICAL_OLD_PREFIX: &str = "Session";
/// Migrate session-historical from `Session` to the new pallet prefix `Historical`
pub struct SessionHistoricalPalletPrefixMigration;

impl OnRuntimeUpgrade for SessionHistoricalPalletPrefixMigration {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_session::migrations::v1::migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::pre_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_session::migrations::v1::post_migrate::<Runtime, Historical, _>(
SESSION_HISTORICAL_OLD_PREFIX,
);
Ok(())
}
}

#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
Expand Down