From 50f4f43de3f7089d13816a2f346d6a432a35264f Mon Sep 17 00:00:00 2001 From: DavidK Date: Fri, 6 Sep 2024 13:31:58 +0300 Subject: [PATCH 01/25] Use relay chain block number in the broker pallet instead of block number --- substrate/frame/broker/src/benchmarking.rs | 2 +- .../frame/broker/src/dispatchable_impls.rs | 8 +- substrate/frame/broker/src/lib.rs | 11 +- substrate/frame/broker/src/migration.rs | 230 ++++++++++++++++++ substrate/frame/broker/src/tick_impls.rs | 2 +- substrate/frame/broker/src/types.rs | 26 +- substrate/frame/broker/src/utility_impls.rs | 10 +- 7 files changed, 262 insertions(+), 27 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 595bf564f7e1..789ba0062f52 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -787,7 +787,7 @@ mod benches { let core_count = n.try_into().unwrap(); let config = new_config_record::(); - let now = frame_system::Pallet::::block_number(); + let now = Broker::::relay_height(); let end_price = 10_000_000u32.into(); let commit_timeslice = Broker::::latest_timeslice_ready_to_commit(&config); let sale = SaleInfoRecordOf:: { diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 5fbd957d7908..16a20c39c409 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -91,7 +91,7 @@ impl Pallet { last_committed_timeslice: commit_timeslice.saturating_sub(1), last_timeslice: Self::current_timeslice(), }; - let now = frame_system::Pallet::::block_number(); + let now = Self::relay_height(); // Imaginary old sale for bootstrapping the first actual sale: let old_sale = SaleInfoRecord { sale_start: now, @@ -119,7 +119,7 @@ impl Pallet { let mut sale = SaleInfo::::get().ok_or(Error::::NoSales)?; Self::ensure_cores_for_sale(&status, &sale)?; - let now = frame_system::Pallet::::block_number(); + let now = Self::relay_height(); ensure!(now > sale.sale_start, Error::::TooEarly); let price = Self::sale_price(&sale, now); ensure!(price_limit >= price, Error::::Overpriced); @@ -171,7 +171,7 @@ impl Pallet { let begin = sale.region_end; let price_cap = record.price + config.renewal_bump * record.price; - let now = frame_system::Pallet::::block_number(); + let now = Self::relay_height(); let price = Self::sale_price(&sale, now).min(price_cap); log::debug!( "Renew with: sale price: {:?}, price cap: {:?}, old price: {:?}", @@ -569,7 +569,7 @@ impl Pallet { Self::ensure_cores_for_sale(&status, &sale)?; - let now = frame_system::Pallet::::block_number(); + let now = Self::relay_height(); Ok(Self::sale_price(&sale, now)) } } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 10745544fadf..ed16b98d26cc 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -67,7 +67,7 @@ pub mod pallet { use frame_system::pallet_prelude::*; use sp_runtime::traits::{Convert, ConvertBack, MaybeConvert}; - const STORAGE_VERSION: StorageVersion = StorageVersion::new(3); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] @@ -305,10 +305,11 @@ pub mod pallet { }, /// A new sale has been initialized. SaleInitialized { - /// The local block number at which the sale will/did start. - sale_start: BlockNumberFor, - /// The length in blocks of the Leadin Period (where the price is decreasing). - leadin_length: BlockNumberFor, + /// The relay block number at which the sale will/did start. + sale_start: RelayBlockNumberOf, + /// The length in relay chain blocks of the Leadin Period (where the price is + /// decreasing). + leadin_length: RelayBlockNumberOf, /// The price of Bulk Coretime at the beginning of the Leadin Period. start_price: BalanceOf, /// The price of Bulk Coretime after the Leadin Period. diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index c2a243d6f0e8..e467177a5bac 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -130,7 +130,13 @@ mod v2 { mod v3 { use super::*; + use codec::MaxEncodedLen; + use frame_support::{ + pallet_prelude::{OptionQuery, RuntimeDebug, TypeInfo}, + storage_alias, + }; use frame_system::Pallet as System; + use sp_arithmetic::Perbill; pub struct MigrateToV3Impl(PhantomData); @@ -156,6 +162,223 @@ mod v3 { Ok(()) } } + + #[storage_alias] + pub type Configuration = StorageValue, ConfigRecordOf, OptionQuery>; + + // types added here for v4 migration + #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] + pub struct ConfigRecord { + /// The number of Relay-chain blocks in advance which scheduling should be fixed and the + /// `Coretime::assign` API used to inform the Relay-chain. + pub advance_notice: RelayBlockNumber, + /// The length in blocks of the Interlude Period for forthcoming sales. + pub interlude_length: BlockNumber, + /// The length in blocks of the Leadin Period for forthcoming sales. + pub leadin_length: BlockNumber, + /// The length in timeslices of Regions which are up for sale in forthcoming sales. + pub region_length: Timeslice, + /// The proportion of cores available for sale which should be sold in order for the price + /// to remain the same in the next sale. + pub ideal_bulk_proportion: Perbill, + /// An artificial limit to the number of cores which are allowed to be sold. If `Some` then + /// no more cores will be sold than this. + pub limit_cores_offered: Option, + /// The amount by which the renewal price increases each sale period. + pub renewal_bump: Perbill, + /// The duration by which rewards for contributions to the InstaPool must be collected. + pub contribution_timeout: Timeslice, + } + + #[storage_alias] + pub type SaleInfo = StorageValue, SaleInfoRecordOf, OptionQuery>; + pub type SaleInfoRecordOf = + SaleInfoRecord, frame_system::pallet_prelude::BlockNumberFor>; + + /// The status of a Bulk Coretime Sale. + #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] + pub struct SaleInfoRecord { + /// The relay block number at which the sale will/did start. + pub sale_start: BlockNumber, + /// The length in relay chain blocks of the Leadin Period (where the price is decreasing). + pub leadin_length: BlockNumber, + /// The price of Bulk Coretime after the Leadin Period. + pub price: Balance, + /// The first timeslice of the Regions which are being sold in this sale. + pub region_begin: Timeslice, + /// The timeslice on which the Regions which are being sold in the sale terminate. (i.e. + /// One after the last timeslice which the Regions control.) + pub region_end: Timeslice, + /// The number of cores we want to sell, ideally. Selling this amount would result in no + /// change to the price for the next sale. + pub ideal_cores_sold: CoreIndex, + /// Number of cores which are/have been offered for sale. + pub cores_offered: CoreIndex, + /// The index of the first core which is for sale. Core of Regions which are sold have + /// incrementing indices from this. + pub first_core: CoreIndex, + /// The latest price at which Bulk Coretime was purchased until surpassing the ideal number + /// of cores were sold. + pub sellout_price: Option, + /// Number of cores which have been sold; never more than cores_offered. + pub cores_sold: CoreIndex, + } +} + +mod v4 { + use super::*; + + pub struct MigrateToV4Impl(PhantomData); + impl UncheckedOnRuntimeUpgrade for MigrateToV4Impl + where + RelayBlockNumberOf: TryFrom>, + { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + let (interlude_length, configuration_leadin_length) = + if let Some(config_record) = v3::Configuration::::get() { + (config_record.interlude_length, config_record.leadin_length) + } else { + ((0 as u32).into(), (0 as u32).into()) + }; + + log::info!(target: LOG_TARGET, "Configuration Pre-Migration: Interlude Length {:?} Leading Length {:?} ", interlude_length, configuration_leadin_length); + + let (sale_start, sale_info_leadin_length) = + if let Some(sale_info_record) = v3::SaleInfo::::get() { + (sale_info_record.sale_start, sale_info_record.leadin_length) + } else { + ((0 as u32).into(), (0 as u32).into()) + }; + + log::info!(target: LOG_TARGET, "SaleInfo Pre-Migration: Sale Start {:?} Interlude Length {:?} ", sale_start, sale_info_leadin_length); + + Ok((interlude_length, configuration_leadin_length, sale_start, sale_info_leadin_length) + .encode()) + } + + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut weight = T::DbWeight::get().reads(1); + + // using a u32::MAX as sentinel value in case TryFrom fails. + // Ref: https://github.com/paritytech/polkadot-sdk/pull/3331#discussion_r1499014975 + + if let Some(config_record) = v3::Configuration::::take() { + log::info!(target: LOG_TARGET, "migrating Configuration record"); + + let updated_interlude_length: RelayBlockNumberOf = + match TryFrom::try_from(config_record.interlude_length) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + + let updated_leadin_length: RelayBlockNumberOf = + match TryFrom::try_from(config_record.leadin_length) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + + let updated_config_record = ConfigRecord { + interlude_length: updated_interlude_length, + leadin_length: updated_leadin_length, + advance_notice: config_record.advance_notice, + region_length: config_record.region_length, + ideal_bulk_proportion: config_record.ideal_bulk_proportion, + limit_cores_offered: config_record.limit_cores_offered, + renewal_bump: config_record.renewal_bump, + contribution_timeout: config_record.contribution_timeout, + }; + Configuration::::put(updated_config_record); + } + weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1)); + + if let Some(sale_info) = v3::SaleInfo::::take() { + log::info!(target: LOG_TARGET, "migrating SaleInfo record"); + + let updated_sale_start: RelayBlockNumberOf = + match TryFrom::try_from(sale_info.sale_start) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + + let updated_leadin_length: RelayBlockNumberOf = + match TryFrom::try_from(sale_info.leadin_length) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + + let updated_sale_info = SaleInfoRecord { + sale_start: updated_sale_start, + leadin_length: updated_leadin_length, + end_price: sale_info.price, + region_begin: sale_info.region_begin, + region_end: sale_info.region_end, + ideal_cores_sold: sale_info.ideal_cores_sold, + cores_offered: sale_info.cores_offered, + first_core: sale_info.first_core, + sellout_price: sale_info.sellout_price, + cores_sold: sale_info.cores_sold, + }; + SaleInfo::::put(updated_sale_info); + } + + weight.saturating_add(T::DbWeight::get().reads_writes(1, 2)) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + let ( + old_interlude_length, + old_configuration_leadin_length, + old_sale_start, + old_sale_info_leadin_length, + ): (BlockNumberFor, BlockNumberFor, BlockNumberFor, BlockNumberFor) = + Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); + + if let Some(config_record) = Configuration::::get() { + ensure!( + verify_updated::( + old_configuration_leadin_length, + config_record.leadin_length + ), + "must migrate configuration leadin_length" + ); + + ensure!( + verify_updated::(old_interlude_length, config_record.interlude_length), + "must migrate configuration interlude_length" + ); + } + + if let Some(sale_info) = SaleInfo::::get() { + ensure!( + verify_updated::(old_sale_start, sale_info.sale_start), + "must migrate sale info sale_start" + ); + + ensure!( + verify_updated::(old_sale_info_leadin_length, sale_info.leadin_length), + "must migrate sale info leadin_length" + ); + } + + Ok(()) + } + } + + #[cfg(feature = "try-runtime")] + fn verify_updated(old_value: BlockNumberFor, new_value: RelayBlockNumberOf) -> bool + where + T: Config, + RelayBlockNumberOf: TryFrom>, + { + let val: RelayBlockNumberOf = match TryFrom::try_from(old_value) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + + val == new_value + } } /// Migrate the pallet storage from `0` to `1`. @@ -182,3 +405,10 @@ pub type MigrateV2ToV3 = frame_support::migrations::VersionedMigration< Pallet, ::DbWeight, >; +pub type MigrateV3ToV4 = frame_support::migrations::VersionedMigration< + 3, + 4, + v4::MigrateToV4Impl, + Pallet, + ::DbWeight, +>; diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 8dbd5df57166..ebdc7208a225 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -158,7 +158,7 @@ impl Pallet { config: &ConfigRecordOf, status: &StatusRecord, ) -> Option<()> { - let now = frame_system::Pallet::::block_number(); + let now = Self::relay_height(); let pool_item = ScheduleItem { assignment: CoreAssignment::Pool, mask: CoreMask::complete() }; diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index 10e6756bc90e..7422bd749845 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -21,7 +21,7 @@ use crate::{ }; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::traits::fungible::Inspect; -use frame_system::{pallet_prelude::BlockNumberFor, Config as SConfig}; +use frame_system::Config as SConfig; use scale_info::TypeInfo; use sp_arithmetic::Perbill; use sp_core::{ConstU32, RuntimeDebug}; @@ -208,11 +208,11 @@ pub struct PoolIoRecord { /// The status of a Bulk Coretime Sale. #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct SaleInfoRecord { - /// The local block number at which the sale will/did start. - pub sale_start: BlockNumber, +pub struct SaleInfoRecord { + /// The relay block number at which the sale will/did start. + pub sale_start: RelayBlockNumber, /// The length in blocks of the Leadin Period (where the price is decreasing). - pub leadin_length: BlockNumber, + pub leadin_length: RelayBlockNumber, /// The price of Bulk Coretime after the Leadin Period. pub end_price: Balance, /// The first timeslice of the Regions which are being sold in this sale. @@ -235,7 +235,7 @@ pub struct SaleInfoRecord { /// Number of cores which have been sold; never more than cores_offered. pub cores_sold: CoreIndex, } -pub type SaleInfoRecordOf = SaleInfoRecord, BlockNumberFor>; +pub type SaleInfoRecordOf = SaleInfoRecord, RelayBlockNumberOf>; /// Record for Polkadot Core reservations (generally tasked with the maintenance of System /// Chains). @@ -272,14 +272,14 @@ pub type OnDemandRevenueRecordOf = /// Configuration of this pallet. #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct ConfigRecord { +pub struct ConfigRecord { /// The number of Relay-chain blocks in advance which scheduling should be fixed and the /// `Coretime::assign` API used to inform the Relay-chain. pub advance_notice: RelayBlockNumber, /// The length in blocks of the Interlude Period for forthcoming sales. - pub interlude_length: BlockNumber, + pub interlude_length: RelayBlockNumber, /// The length in blocks of the Leadin Period for forthcoming sales. - pub leadin_length: BlockNumber, + pub leadin_length: RelayBlockNumber, /// The length in timeslices of Regions which are up for sale in forthcoming sales. pub region_length: Timeslice, /// The proportion of cores available for sale which should be sold. @@ -296,16 +296,16 @@ pub struct ConfigRecord { /// The duration by which rewards for contributions to the InstaPool must be collected. pub contribution_timeout: Timeslice, } -pub type ConfigRecordOf = ConfigRecord, RelayBlockNumberOf>; +pub type ConfigRecordOf = ConfigRecord>; -impl ConfigRecord +impl ConfigRecord where - BlockNumber: sp_arithmetic::traits::Zero, + RelayBlockNumber: sp_arithmetic::traits::Zero, { /// Check the config for basic validity constraints. pub(crate) fn validate(&self) -> Result<(), ()> { if self.leadin_length.is_zero() { - return Err(()) + return Err(()); } Ok(()) diff --git a/substrate/frame/broker/src/utility_impls.rs b/substrate/frame/broker/src/utility_impls.rs index e937e0cbbec5..4ceb4acb8854 100644 --- a/substrate/frame/broker/src/utility_impls.rs +++ b/substrate/frame/broker/src/utility_impls.rs @@ -24,7 +24,6 @@ use frame_support::{ OnUnbalanced, }, }; -use frame_system::pallet_prelude::BlockNumberFor; use sp_arithmetic::{ traits::{SaturatedConversion, Saturating}, FixedPointNumber, FixedU64, @@ -60,7 +59,7 @@ impl Pallet { T::PalletId::get().into_account_truncating() } - pub fn sale_price(sale: &SaleInfoRecordOf, now: BlockNumberFor) -> BalanceOf { + pub fn sale_price(sale: &SaleInfoRecordOf, now: RelayBlockNumberOf) -> BalanceOf { let num = now.saturating_sub(sale.sale_start).min(sale.leadin_length).saturated_into(); let through = FixedU64::from_rational(num, sale.leadin_length.saturated_into()); T::PriceAdapter::leadin_factor_at(through).saturating_mul_int(sale.end_price) @@ -125,7 +124,7 @@ impl Pallet { region_id.begin = last_committed_timeslice + 1; if region_id.begin >= region.end { Self::deposit_event(Event::RegionDropped { region_id, duration }); - return Ok(None) + return Ok(None); } } else { Workplan::::mutate_extant((region_id.begin, region_id.core), |p| { @@ -138,4 +137,9 @@ impl Pallet { Ok(Some((region_id, region))) } + + /// Returns the current block number of Relay Chain + pub(crate) fn relay_height() -> RelayBlockNumberOf { + <<::Coretime as CoretimeInterface>::RelayChainBlockNumberProvider as BlockNumberProvider>::current_block_number() + } } From 7315ba73ad3fdc5c205ed5c5a4b200d9aa56015a Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 10 Sep 2024 10:46:04 +0300 Subject: [PATCH 02/25] Add prdoc --- prdoc/pr_5656.prdoc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 prdoc/pr_5656.prdoc diff --git a/prdoc/pr_5656.prdoc b/prdoc/pr_5656.prdoc new file mode 100644 index 000000000000..43c70df94155 --- /dev/null +++ b/prdoc/pr_5656.prdoc @@ -0,0 +1,10 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Use Relay Blocknumber in Pallet Broker + +doc: + - audience: Runtime Dev + description: | + Changing `sale_start`, `interlude_length` and `leading_length` in `pallet_broker` to use relay chain block numbers instead of parachain block numbers. + Relay chain block numbers are almost deterministic and more future proof. From c928b8a14a8a9ec1c004299c134f1d2434908a1a Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 11 Sep 2024 11:33:12 +0300 Subject: [PATCH 03/25] Translate block number to relay block number --- substrate/frame/broker/src/migration.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index e467177a5bac..e57cc3fa6913 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -262,19 +262,29 @@ mod v4 { // using a u32::MAX as sentinel value in case TryFrom fails. // Ref: https://github.com/paritytech/polkadot-sdk/pull/3331#discussion_r1499014975 + let current_block: RelayBlockNumberOf = + match TryFrom::try_from(frame_system::Pallet::::block_number()) { + Ok(val) => val, + Err(_) => u32::MAX.into(), + }; + let current_relay_number = crate::Pallet::::relay_height(); + let offset = current_relay_number - current_block * 2; + + let translate_old_block_number_to_relay_height = + |old_block_number: RelayBlockNumberOf| offset + old_block_number * 2u32.into(); if let Some(config_record) = v3::Configuration::::take() { log::info!(target: LOG_TARGET, "migrating Configuration record"); let updated_interlude_length: RelayBlockNumberOf = match TryFrom::try_from(config_record.interlude_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; let updated_leadin_length: RelayBlockNumberOf = match TryFrom::try_from(config_record.leadin_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; @@ -297,13 +307,13 @@ mod v4 { let updated_sale_start: RelayBlockNumberOf = match TryFrom::try_from(sale_info.sale_start) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; let updated_leadin_length: RelayBlockNumberOf = match TryFrom::try_from(sale_info.leadin_length) { - Ok(val) => val, + Ok(val) => translate_old_block_number_to_relay_height(val), Err(_) => u32::MAX.into(), }; From 60c56622a7a272d61bc02234ddfde4ebc0579b93 Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 12 Sep 2024 11:16:55 +0300 Subject: [PATCH 04/25] Allow runtime to specify parachain block number to relay height conversion --- .../coretime/coretime-rococo/src/lib.rs | 14 +++++ .../coretime/coretime-westend/src/lib.rs | 14 +++++ substrate/frame/broker/src/migration.rs | 60 +++++++------------ substrate/frame/broker/src/utility_impls.rs | 2 +- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 25324bf17764..347ad4b90e8b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -121,6 +121,7 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, ); @@ -451,6 +452,19 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = pallet_sudo::weights::SubstrateWeight; } +pub struct BrokerMigrationV4BlockTranslation; + +impl pallet_broker::migration::v4::BlockToRelayHeightTranslation + for BrokerMigrationV4BlockTranslation +{ + fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { + let relay_height = pallet_broker::Pallet::::relay_height(); + let parachain_block_number = frame_system::Pallet::::block_number(); + let offset = relay_height - parachain_block_number * 2; + offset + input_block_number * 2 + } +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index a3051e4bf271..fada2de6029e 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -120,6 +120,7 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, ); @@ -445,6 +446,19 @@ impl pallet_utility::Config for Runtime { type WeightInfo = weights::pallet_utility::WeightInfo; } +pub struct BrokerMigrationV4BlockTranslation; + +impl pallet_broker::migration::v4::BlockToRelayHeightTranslation + for BrokerMigrationV4BlockTranslation +{ + fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { + let relay_height = pallet_broker::Pallet::::relay_height(); + let parachain_block_number = frame_system::Pallet::::block_number(); + let offset = relay_height - parachain_block_number * 2; + offset + input_block_number * 2 + } +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index e57cc3fa6913..40cd35a3709c 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -165,6 +165,7 @@ mod v3 { #[storage_alias] pub type Configuration = StorageValue, ConfigRecordOf, OptionQuery>; + pub type ConfigRecordOf = ConfigRecord, RelayBlockNumberOf>; // types added here for v4 migration #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -225,13 +226,18 @@ mod v3 { } } -mod v4 { +pub mod v4 { use super::*; - pub struct MigrateToV4Impl(PhantomData); - impl UncheckedOnRuntimeUpgrade for MigrateToV4Impl - where - RelayBlockNumberOf: TryFrom>, + pub trait BlockToRelayHeightTranslation { + fn convert_block_number_to_relay_height( + block_number: frame_system::pallet_prelude::BlockNumberFor, + ) -> RelayBlockNumberOf; + } + + pub struct MigrateToV4Impl(PhantomData, PhantomData); + impl> UncheckedOnRuntimeUpgrade + for MigrateToV4Impl { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { @@ -260,33 +266,17 @@ mod v4 { fn on_runtime_upgrade() -> frame_support::weights::Weight { let mut weight = T::DbWeight::get().reads(1); - // using a u32::MAX as sentinel value in case TryFrom fails. - // Ref: https://github.com/paritytech/polkadot-sdk/pull/3331#discussion_r1499014975 - let current_block: RelayBlockNumberOf = - match TryFrom::try_from(frame_system::Pallet::::block_number()) { - Ok(val) => val, - Err(_) => u32::MAX.into(), - }; - let current_relay_number = crate::Pallet::::relay_height(); - let offset = current_relay_number - current_block * 2; - - let translate_old_block_number_to_relay_height = - |old_block_number: RelayBlockNumberOf| offset + old_block_number * 2u32.into(); - if let Some(config_record) = v3::Configuration::::take() { log::info!(target: LOG_TARGET, "migrating Configuration record"); let updated_interlude_length: RelayBlockNumberOf = - match TryFrom::try_from(config_record.interlude_length) { - Ok(val) => translate_old_block_number_to_relay_height(val), - Err(_) => u32::MAX.into(), - }; - + BlockTranslation::convert_block_number_to_relay_height( + config_record.interlude_length, + ); let updated_leadin_length: RelayBlockNumberOf = - match TryFrom::try_from(config_record.leadin_length) { - Ok(val) => translate_old_block_number_to_relay_height(val), - Err(_) => u32::MAX.into(), - }; + BlockTranslation::convert_block_number_to_relay_height( + config_record.leadin_length, + ); let updated_config_record = ConfigRecord { interlude_length: updated_interlude_length, @@ -306,16 +296,9 @@ mod v4 { log::info!(target: LOG_TARGET, "migrating SaleInfo record"); let updated_sale_start: RelayBlockNumberOf = - match TryFrom::try_from(sale_info.sale_start) { - Ok(val) => translate_old_block_number_to_relay_height(val), - Err(_) => u32::MAX.into(), - }; - + BlockTranslation::convert_block_number_to_relay_height(sale_info.sale_start); let updated_leadin_length: RelayBlockNumberOf = - match TryFrom::try_from(sale_info.leadin_length) { - Ok(val) => translate_old_block_number_to_relay_height(val), - Err(_) => u32::MAX.into(), - }; + BlockTranslation::convert_block_number_to_relay_height(sale_info.leadin_length); let updated_sale_info = SaleInfoRecord { sale_start: updated_sale_start, @@ -415,10 +398,11 @@ pub type MigrateV2ToV3 = frame_support::migrations::VersionedMigration< Pallet, ::DbWeight, >; -pub type MigrateV3ToV4 = frame_support::migrations::VersionedMigration< + +pub type MigrateV3ToV4 = frame_support::migrations::VersionedMigration< 3, 4, - v4::MigrateToV4Impl, + v4::MigrateToV4Impl, Pallet, ::DbWeight, >; diff --git a/substrate/frame/broker/src/utility_impls.rs b/substrate/frame/broker/src/utility_impls.rs index 4ceb4acb8854..25030250af7c 100644 --- a/substrate/frame/broker/src/utility_impls.rs +++ b/substrate/frame/broker/src/utility_impls.rs @@ -139,7 +139,7 @@ impl Pallet { } /// Returns the current block number of Relay Chain - pub(crate) fn relay_height() -> RelayBlockNumberOf { + pub fn relay_height() -> RelayBlockNumberOf { <<::Coretime as CoretimeInterface>::RelayChainBlockNumberProvider as BlockNumberProvider>::current_block_number() } } From 82115a00bb2dfb9adfa9e9019524180529b1e788 Mon Sep 17 00:00:00 2001 From: DavidK Date: Fri, 13 Sep 2024 11:27:42 +0300 Subject: [PATCH 05/25] Rename Translation to Conversion --- .../coretime/coretime-rococo/src/lib.rs | 8 ++++---- .../coretime/coretime-westend/src/lib.rs | 8 ++++---- substrate/frame/broker/src/migration.rs | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 347ad4b90e8b..6b44c2efa944 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -121,7 +121,7 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, - pallet_broker::migration::MigrateV3ToV4, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, ); @@ -452,10 +452,10 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = pallet_sudo::weights::SubstrateWeight; } -pub struct BrokerMigrationV4BlockTranslation; +pub struct BrokerMigrationV4BlockConversion; -impl pallet_broker::migration::v4::BlockToRelayHeightTranslation - for BrokerMigrationV4BlockTranslation +impl pallet_broker::migration::v4::BlockToRelayHeightConversion + for BrokerMigrationV4BlockConversion { fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index fada2de6029e..4040f4b33569 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -120,7 +120,7 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, - pallet_broker::migration::MigrateV3ToV4, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, ); @@ -446,10 +446,10 @@ impl pallet_utility::Config for Runtime { type WeightInfo = weights::pallet_utility::WeightInfo; } -pub struct BrokerMigrationV4BlockTranslation; +pub struct BrokerMigrationV4BlockConversion; -impl pallet_broker::migration::v4::BlockToRelayHeightTranslation - for BrokerMigrationV4BlockTranslation +impl pallet_broker::migration::v4::BlockToRelayHeightConversion + for BrokerMigrationV4BlockConversion { fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 40cd35a3709c..28c38f3d4c08 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -229,15 +229,15 @@ mod v3 { pub mod v4 { use super::*; - pub trait BlockToRelayHeightTranslation { + pub trait BlockToRelayHeightConversion { fn convert_block_number_to_relay_height( block_number: frame_system::pallet_prelude::BlockNumberFor, ) -> RelayBlockNumberOf; } - pub struct MigrateToV4Impl(PhantomData, PhantomData); - impl> UncheckedOnRuntimeUpgrade - for MigrateToV4Impl + pub struct MigrateToV4Impl(PhantomData, PhantomData); + impl> UncheckedOnRuntimeUpgrade + for MigrateToV4Impl { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { @@ -270,11 +270,11 @@ pub mod v4 { log::info!(target: LOG_TARGET, "migrating Configuration record"); let updated_interlude_length: RelayBlockNumberOf = - BlockTranslation::convert_block_number_to_relay_height( + BlockConversion::convert_block_number_to_relay_height( config_record.interlude_length, ); let updated_leadin_length: RelayBlockNumberOf = - BlockTranslation::convert_block_number_to_relay_height( + BlockConversion::convert_block_number_to_relay_height( config_record.leadin_length, ); @@ -296,9 +296,9 @@ pub mod v4 { log::info!(target: LOG_TARGET, "migrating SaleInfo record"); let updated_sale_start: RelayBlockNumberOf = - BlockTranslation::convert_block_number_to_relay_height(sale_info.sale_start); + BlockConversion::convert_block_number_to_relay_height(sale_info.sale_start); let updated_leadin_length: RelayBlockNumberOf = - BlockTranslation::convert_block_number_to_relay_height(sale_info.leadin_length); + BlockConversion::convert_block_number_to_relay_height(sale_info.leadin_length); let updated_sale_info = SaleInfoRecord { sale_start: updated_sale_start, @@ -399,10 +399,10 @@ pub type MigrateV2ToV3 = frame_support::migrations::VersionedMigration< ::DbWeight, >; -pub type MigrateV3ToV4 = frame_support::migrations::VersionedMigration< +pub type MigrateV3ToV4 = frame_support::migrations::VersionedMigration< 3, 4, - v4::MigrateToV4Impl, + v4::MigrateToV4Impl, Pallet, ::DbWeight, >; From 30f9953f1d5edbb2fd85400e3c5750ffef24e176 Mon Sep 17 00:00:00 2001 From: DavidK Date: Fri, 13 Sep 2024 12:32:56 +0300 Subject: [PATCH 06/25] Add crates to prdoc --- prdoc/pr_5656.prdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prdoc/pr_5656.prdoc b/prdoc/pr_5656.prdoc index 43c70df94155..8e2bcc5b8e3e 100644 --- a/prdoc/pr_5656.prdoc +++ b/prdoc/pr_5656.prdoc @@ -8,3 +8,7 @@ doc: description: | Changing `sale_start`, `interlude_length` and `leading_length` in `pallet_broker` to use relay chain block numbers instead of parachain block numbers. Relay chain block numbers are almost deterministic and more future proof. + +crates: + - name: pallet-broker + bump: major \ No newline at end of file From 1c36d205a1aed4568afd81204e18dfdc76ae0317 Mon Sep 17 00:00:00 2001 From: DavidK Date: Fri, 13 Sep 2024 13:31:21 +0300 Subject: [PATCH 07/25] Add remaining crates to prdoc changes --- prdoc/pr_5656.prdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prdoc/pr_5656.prdoc b/prdoc/pr_5656.prdoc index 8e2bcc5b8e3e..b20546bf7a5e 100644 --- a/prdoc/pr_5656.prdoc +++ b/prdoc/pr_5656.prdoc @@ -11,4 +11,8 @@ doc: crates: - name: pallet-broker + bump: major + - name: coretime-rococo-runtime + bump: major + - name: coretime-westend-runtime bump: major \ No newline at end of file From 2edbca9d0605e78afef274d8528507be4b62207c Mon Sep 17 00:00:00 2001 From: DavidK Date: Fri, 13 Sep 2024 13:53:04 +0300 Subject: [PATCH 08/25] Fix try runtime compilation --- substrate/frame/broker/src/migration.rs | 32 ++++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 28c38f3d4c08..135640d8ab3c 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -165,7 +165,8 @@ mod v3 { #[storage_alias] pub type Configuration = StorageValue, ConfigRecordOf, OptionQuery>; - pub type ConfigRecordOf = ConfigRecord, RelayBlockNumberOf>; + pub type ConfigRecordOf = + ConfigRecord, RelayBlockNumberOf>; // types added here for v4 migration #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -229,9 +230,11 @@ mod v3 { pub mod v4 { use super::*; + type BlockNumberFor = frame_system::pallet_prelude::BlockNumberFor; + pub trait BlockToRelayHeightConversion { fn convert_block_number_to_relay_height( - block_number: frame_system::pallet_prelude::BlockNumberFor, + block_number: BlockNumberFor, ) -> RelayBlockNumberOf; } @@ -330,7 +333,7 @@ pub mod v4 { if let Some(config_record) = Configuration::::get() { ensure!( - verify_updated::( + Self::verify_updated( old_configuration_leadin_length, config_record.leadin_length ), @@ -338,19 +341,19 @@ pub mod v4 { ); ensure!( - verify_updated::(old_interlude_length, config_record.interlude_length), + Self::verify_updated(old_interlude_length, config_record.interlude_length), "must migrate configuration interlude_length" ); } if let Some(sale_info) = SaleInfo::::get() { ensure!( - verify_updated::(old_sale_start, sale_info.sale_start), + Self::verify_updated(old_sale_start, sale_info.sale_start), "must migrate sale info sale_start" ); ensure!( - verify_updated::(old_sale_info_leadin_length, sale_info.leadin_length), + Self::verify_updated(old_sale_info_leadin_length, sale_info.leadin_length), "must migrate sale info leadin_length" ); } @@ -359,18 +362,13 @@ pub mod v4 { } } - #[cfg(feature = "try-runtime")] - fn verify_updated(old_value: BlockNumberFor, new_value: RelayBlockNumberOf) -> bool - where - T: Config, - RelayBlockNumberOf: TryFrom>, + impl> + MigrateToV4Impl { - let val: RelayBlockNumberOf = match TryFrom::try_from(old_value) { - Ok(val) => val, - Err(_) => u32::MAX.into(), - }; - - val == new_value + #[cfg(feature = "try-runtime")] + fn verify_updated(old_value: BlockNumberFor, new_value: RelayBlockNumberOf) -> bool { + BlockConversion::convert_block_number_to_relay_height(old_value) == new_value + } } } From 10b2f95b3104694627f2dce84a5f307516d1dafa Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 16 Sep 2024 12:08:21 +0300 Subject: [PATCH 09/25] Put broker migration last --- cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 2 +- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 6b44c2efa944..2f0adada9e99 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -121,9 +121,9 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, - pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, + pallet_broker::migration::MigrateV3ToV4, ); /// Executive: handles dispatch to the various modules. diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 4040f4b33569..a69133eaced1 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -120,9 +120,9 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, - pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, + pallet_broker::migration::MigrateV3ToV4, ); /// Executive: handles dispatch to the various modules. From db95a7f461bee76577bb498150cad6462ecca7cc Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 16 Sep 2024 13:02:50 +0300 Subject: [PATCH 10/25] Fix logic of converting block heights to block times --- .../coretime/coretime-rococo/src/lib.rs | 4 ++ .../coretime/coretime-westend/src/lib.rs | 4 ++ substrate/frame/broker/src/migration.rs | 52 +++++++++++++++---- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 975a96a57c5d..d1c5afc9f683 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -598,6 +598,10 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion let offset = relay_height - parachain_block_number * 2; offset + input_block_number * 2 } + + fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { + input_block_length * 2 + } } // Create the runtime by composing the FRAME pallets that were previously configured. diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 43f487ab456a..9368eb44686b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -592,6 +592,10 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion let offset = relay_height - parachain_block_number * 2; offset + input_block_number * 2 } + + fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { + input_block_length * 2 + } } // Create the runtime by composing the FRAME pallets that were previously configured. diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 135640d8ab3c..f19b1e19bdd1 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -233,9 +233,15 @@ pub mod v4 { type BlockNumberFor = frame_system::pallet_prelude::BlockNumberFor; pub trait BlockToRelayHeightConversion { + /// Converts absolute value of parachain block number to relay chain block number fn convert_block_number_to_relay_height( block_number: BlockNumberFor, ) -> RelayBlockNumberOf; + + /// Converts parachain block length into equivalent relay chain block length + fn convert_block_length_to_relay_length( + block_number: BlockNumberFor, + ) -> RelayBlockNumberOf; } pub struct MigrateToV4Impl(PhantomData, PhantomData); @@ -251,7 +257,11 @@ pub mod v4 { ((0 as u32).into(), (0 as u32).into()) }; - log::info!(target: LOG_TARGET, "Configuration Pre-Migration: Interlude Length {:?} Leading Length {:?} ", interlude_length, configuration_leadin_length); + let updated_interlude_length: RelayBlockNumberOf = + BlockConversion::convert_block_length_to_relay_length(interlude_length); + let updated_leadin_length: RelayBlockNumberOf = + BlockConversion::convert_block_length_to_relay_length(configuration_leadin_length); + log::info!(target: LOG_TARGET, "Configuration Pre-Migration: Interlude Length {:?}->{:?} Leadin Length {:?}->{:?}", interlude_length, updated_interlude_length, configuration_leadin_length, updated_leadin_length); let (sale_start, sale_info_leadin_length) = if let Some(sale_info_record) = v3::SaleInfo::::get() { @@ -260,7 +270,11 @@ pub mod v4 { ((0 as u32).into(), (0 as u32).into()) }; - log::info!(target: LOG_TARGET, "SaleInfo Pre-Migration: Sale Start {:?} Interlude Length {:?} ", sale_start, sale_info_leadin_length); + let updated_sale_start: RelayBlockNumberOf = + BlockConversion::convert_block_number_to_relay_height(sale_start); + let updated_sale_info_leadin_length: RelayBlockNumberOf = + BlockConversion::convert_block_length_to_relay_length(sale_info_leadin_length); + log::info!(target: LOG_TARGET, "SaleInfo Pre-Migration: Sale Start {:?}->{:?} Interlude Length {:?}->{:?}", sale_start, updated_sale_start, sale_info_leadin_length, updated_sale_info_leadin_length); Ok((interlude_length, configuration_leadin_length, sale_start, sale_info_leadin_length) .encode()) @@ -273,11 +287,11 @@ pub mod v4 { log::info!(target: LOG_TARGET, "migrating Configuration record"); let updated_interlude_length: RelayBlockNumberOf = - BlockConversion::convert_block_number_to_relay_height( + BlockConversion::convert_block_length_to_relay_length( config_record.interlude_length, ); let updated_leadin_length: RelayBlockNumberOf = - BlockConversion::convert_block_number_to_relay_height( + BlockConversion::convert_block_length_to_relay_length( config_record.leadin_length, ); @@ -301,7 +315,7 @@ pub mod v4 { let updated_sale_start: RelayBlockNumberOf = BlockConversion::convert_block_number_to_relay_height(sale_info.sale_start); let updated_leadin_length: RelayBlockNumberOf = - BlockConversion::convert_block_number_to_relay_height(sale_info.leadin_length); + BlockConversion::convert_block_length_to_relay_length(sale_info.leadin_length); let updated_sale_info = SaleInfoRecord { sale_start: updated_sale_start, @@ -333,7 +347,7 @@ pub mod v4 { if let Some(config_record) = Configuration::::get() { ensure!( - Self::verify_updated( + Self::verify_updated_block_length( old_configuration_leadin_length, config_record.leadin_length ), @@ -341,19 +355,25 @@ pub mod v4 { ); ensure!( - Self::verify_updated(old_interlude_length, config_record.interlude_length), + Self::verify_updated_block_length( + old_interlude_length, + config_record.interlude_length + ), "must migrate configuration interlude_length" ); } if let Some(sale_info) = SaleInfo::::get() { ensure!( - Self::verify_updated(old_sale_start, sale_info.sale_start), + Self::verify_updated_block_time(old_sale_start, sale_info.sale_start), "must migrate sale info sale_start" ); ensure!( - Self::verify_updated(old_sale_info_leadin_length, sale_info.leadin_length), + Self::verify_updated_block_length( + old_sale_info_leadin_length, + sale_info.leadin_length + ), "must migrate sale info leadin_length" ); } @@ -362,13 +382,23 @@ pub mod v4 { } } + #[cfg(feature = "try-runtime")] impl> MigrateToV4Impl { - #[cfg(feature = "try-runtime")] - fn verify_updated(old_value: BlockNumberFor, new_value: RelayBlockNumberOf) -> bool { + fn verify_updated_block_time( + old_value: BlockNumberFor, + new_value: RelayBlockNumberOf, + ) -> bool { BlockConversion::convert_block_number_to_relay_height(old_value) == new_value } + + fn verify_updated_block_length( + old_value: BlockNumberFor, + new_value: RelayBlockNumberOf, + ) -> bool { + BlockConversion::convert_block_length_to_relay_length(old_value) == new_value + } } } From 31418835751686962fbe73fc615ca51792f7e9bd Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 16 Sep 2024 13:24:46 +0300 Subject: [PATCH 11/25] Adjust conversions for rococo and westend conversions --- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 6 +++--- .../runtimes/coretime/coretime-westend/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index d1c5afc9f683..1f9201c31789 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -595,12 +595,12 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); let parachain_block_number = frame_system::Pallet::::block_number(); - let offset = relay_height - parachain_block_number * 2; - offset + input_block_number * 2 + let offset = relay_height - parachain_block_number; + offset + input_block_number } fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { - input_block_length * 2 + input_block_length } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 9368eb44686b..b19705a29c11 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -589,12 +589,12 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); let parachain_block_number = frame_system::Pallet::::block_number(); - let offset = relay_height - parachain_block_number * 2; - offset + input_block_number * 2 + let offset = relay_height - parachain_block_number; + offset + input_block_number } fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { - input_block_length * 2 + input_block_length } } From f06be141d25fe944ea06f454338635d1be6e1b13 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 16 Sep 2024 13:50:16 +0300 Subject: [PATCH 12/25] Revert "Adjust conversions for rococo and westend conversions" This reverts commit 31418835751686962fbe73fc615ca51792f7e9bd. --- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 6 +++--- .../runtimes/coretime/coretime-westend/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 1f9201c31789..d1c5afc9f683 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -595,12 +595,12 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); let parachain_block_number = frame_system::Pallet::::block_number(); - let offset = relay_height - parachain_block_number; - offset + input_block_number + let offset = relay_height - parachain_block_number * 2; + offset + input_block_number * 2 } fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { - input_block_length + input_block_length * 2 } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index b19705a29c11..9368eb44686b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -589,12 +589,12 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { let relay_height = pallet_broker::Pallet::::relay_height(); let parachain_block_number = frame_system::Pallet::::block_number(); - let offset = relay_height - parachain_block_number; - offset + input_block_number + let offset = relay_height - parachain_block_number * 2; + offset + input_block_number * 2 } fn convert_block_length_to_relay_length(input_block_length: u32) -> u32 { - input_block_length + input_block_length * 2 } } From 1b53fa9d54382f9b803fa84837b16dcb223f001c Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 16 Sep 2024 14:22:50 +0300 Subject: [PATCH 13/25] Migration fixes for rococo and westend --- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 4 ++-- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index d1c5afc9f683..bb51eaefbf92 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -124,9 +124,9 @@ pub type Migrations = ( pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, - pallet_broker::migration::MigrateV3ToV4, ); /// Executive: handles dispatch to the various modules. @@ -150,7 +150,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("coretime-rococo"), impl_name: create_runtime_str!("coretime-rococo"), authoring_version: 1, - spec_version: 1_015_000, + spec_version: 1_017_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 9368eb44686b..fc090f31f8da 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -120,12 +120,13 @@ pub type UncheckedExtrinsic = pub type Migrations = ( pallet_collator_selection::migration::v2::MigrationToV2, cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + cumulus_pallet_xcmp_queue::migration::v5::MigrateV4ToV5, pallet_broker::migration::MigrateV0ToV1, pallet_broker::migration::MigrateV1ToV2, pallet_broker::migration::MigrateV2ToV3, + pallet_broker::migration::MigrateV3ToV4, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, - pallet_broker::migration::MigrateV3ToV4, ); /// Executive: handles dispatch to the various modules. @@ -149,7 +150,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("coretime-westend"), impl_name: create_runtime_str!("coretime-westend"), authoring_version: 1, - spec_version: 1_015_000, + spec_version: 1_017_000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, From 51899f30088f61c4d54a43ebbad12a82c3130e42 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 17 Sep 2024 09:42:52 +0300 Subject: [PATCH 14/25] Revert minor formatting changes --- substrate/frame/broker/src/types.rs | 2 +- substrate/frame/broker/src/utility_impls.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index 7422bd749845..f970b310a3cb 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -305,7 +305,7 @@ where /// Check the config for basic validity constraints. pub(crate) fn validate(&self) -> Result<(), ()> { if self.leadin_length.is_zero() { - return Err(()); + return Err(()) } Ok(()) diff --git a/substrate/frame/broker/src/utility_impls.rs b/substrate/frame/broker/src/utility_impls.rs index 25030250af7c..ede9bdfc3092 100644 --- a/substrate/frame/broker/src/utility_impls.rs +++ b/substrate/frame/broker/src/utility_impls.rs @@ -124,7 +124,7 @@ impl Pallet { region_id.begin = last_committed_timeslice + 1; if region_id.begin >= region.end { Self::deposit_event(Event::RegionDropped { region_id, duration }); - return Ok(None); + return Ok(None) } } else { Workplan::::mutate_extant((region_id.begin, region_id.core), |p| { From d79d5ce132c7c5742981cb96812ef7d64b029df2 Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 30 Oct 2024 12:18:04 +0200 Subject: [PATCH 15/25] Remove custom relay_height function --- substrate/frame/broker/src/benchmarking.rs | 2 +- substrate/frame/broker/src/dispatchable_impls.rs | 10 +++++----- substrate/frame/broker/src/tick_impls.rs | 4 ++-- substrate/frame/broker/src/utility_impls.rs | 5 ----- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 789ba0062f52..98d69acab239 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -787,7 +787,7 @@ mod benches { let core_count = n.try_into().unwrap(); let config = new_config_record::(); - let now = Broker::::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); let end_price = 10_000_000u32.into(); let commit_timeslice = Broker::::latest_timeslice_ready_to_commit(&config); let sale = SaleInfoRecordOf:: { diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 16a20c39c409..733d96625da0 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -21,7 +21,7 @@ use frame_support::{ traits::{fungible::Mutate, tokens::Preservation::Expendable, DefensiveResult}, }; use sp_arithmetic::traits::{CheckedDiv, Saturating, Zero}; -use sp_runtime::traits::Convert; +use sp_runtime::traits::{BlockNumberProvider, Convert}; use CompletionStatus::{Complete, Partial}; impl Pallet { @@ -91,7 +91,7 @@ impl Pallet { last_committed_timeslice: commit_timeslice.saturating_sub(1), last_timeslice: Self::current_timeslice(), }; - let now = Self::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); // Imaginary old sale for bootstrapping the first actual sale: let old_sale = SaleInfoRecord { sale_start: now, @@ -119,7 +119,7 @@ impl Pallet { let mut sale = SaleInfo::::get().ok_or(Error::::NoSales)?; Self::ensure_cores_for_sale(&status, &sale)?; - let now = Self::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); ensure!(now > sale.sale_start, Error::::TooEarly); let price = Self::sale_price(&sale, now); ensure!(price_limit >= price, Error::::Overpriced); @@ -171,7 +171,7 @@ impl Pallet { let begin = sale.region_end; let price_cap = record.price + config.renewal_bump * record.price; - let now = Self::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); let price = Self::sale_price(&sale, now).min(price_cap); log::debug!( "Renew with: sale price: {:?}, price cap: {:?}, old price: {:?}", @@ -569,7 +569,7 @@ impl Pallet { Self::ensure_cores_for_sale(&status, &sale)?; - let now = Self::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); Ok(Self::sale_price(&sale, now)) } } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index ebdc7208a225..e0b4932f11e2 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -19,7 +19,7 @@ use super::*; use alloc::{vec, vec::Vec}; use frame_support::{pallet_prelude::*, traits::defensive_prelude::*, weights::WeightMeter}; use sp_arithmetic::traits::{One, SaturatedConversion, Saturating, Zero}; -use sp_runtime::traits::{ConvertBack, MaybeConvert}; +use sp_runtime::traits::{BlockNumberProvider, ConvertBack, MaybeConvert}; use CompletionStatus::Complete; impl Pallet { @@ -158,7 +158,7 @@ impl Pallet { config: &ConfigRecordOf, status: &StatusRecord, ) -> Option<()> { - let now = Self::relay_height(); + let now = RCBlockNumberProviderOf::::current_block_number(); let pool_item = ScheduleItem { assignment: CoreAssignment::Pool, mask: CoreMask::complete() }; diff --git a/substrate/frame/broker/src/utility_impls.rs b/substrate/frame/broker/src/utility_impls.rs index ede9bdfc3092..73f05d1e5ef4 100644 --- a/substrate/frame/broker/src/utility_impls.rs +++ b/substrate/frame/broker/src/utility_impls.rs @@ -137,9 +137,4 @@ impl Pallet { Ok(Some((region_id, region))) } - - /// Returns the current block number of Relay Chain - pub fn relay_height() -> RelayBlockNumberOf { - <<::Coretime as CoretimeInterface>::RelayChainBlockNumberProvider as BlockNumberProvider>::current_block_number() - } } From cfdab24974cc2da51418f5912968a84fef0f0712 Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 30 Oct 2024 12:44:31 +0200 Subject: [PATCH 16/25] Fix coretime runtimes --- .../parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 6 ++++-- .../runtimes/coretime/coretime-westend/src/lib.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index a8735617b31f..24a26140e014 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -68,7 +68,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; pub use sp_runtime::BuildStorage; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, Block as BlockT}, + traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug, }; @@ -598,7 +598,9 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion for BrokerMigrationV4BlockConversion { fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { - let relay_height = pallet_broker::Pallet::::relay_height(); + let relay_height = pallet_broker::RCBlockNumberProviderOf::< + ::Coretime, + >::current_block_number(); let parachain_block_number = frame_system::Pallet::::block_number(); let offset = relay_height - parachain_block_number * 2; offset + input_block_number * 2 diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 29f03afde5be..377f1d77548b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -68,7 +68,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; pub use sp_runtime::BuildStorage; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{BlakeTwo256, Block as BlockT}, + traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug, }; @@ -593,7 +593,9 @@ impl pallet_broker::migration::v4::BlockToRelayHeightConversion for BrokerMigrationV4BlockConversion { fn convert_block_number_to_relay_height(input_block_number: u32) -> u32 { - let relay_height = pallet_broker::Pallet::::relay_height(); + let relay_height = pallet_broker::RCBlockNumberProviderOf::< + ::Coretime, + >::current_block_number(); let parachain_block_number = frame_system::Pallet::::block_number(); let offset = relay_height - parachain_block_number * 2; offset + input_block_number * 2 From 5131629214e1555357f4b84cbe405909a3afe53c Mon Sep 17 00:00:00 2001 From: davidk-pt Date: Thu, 31 Oct 2024 09:19:55 +0200 Subject: [PATCH 17/25] Update substrate/frame/broker/src/migration.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/frame/broker/src/migration.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index f19b1e19bdd1..91bdf57b61c1 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -298,12 +298,7 @@ pub mod v4 { let updated_config_record = ConfigRecord { interlude_length: updated_interlude_length, leadin_length: updated_leadin_length, - advance_notice: config_record.advance_notice, - region_length: config_record.region_length, - ideal_bulk_proportion: config_record.ideal_bulk_proportion, - limit_cores_offered: config_record.limit_cores_offered, - renewal_bump: config_record.renewal_bump, - contribution_timeout: config_record.contribution_timeout, + ..config_record }; Configuration::::put(updated_config_record); } From 25532a2033b5d1766b6494e8c96e2eb3ad8cfc1b Mon Sep 17 00:00:00 2001 From: davidk-pt Date: Thu, 31 Oct 2024 09:20:30 +0200 Subject: [PATCH 18/25] Update substrate/frame/broker/src/migration.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- substrate/frame/broker/src/migration.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 91bdf57b61c1..0c6ce20f2e66 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -315,14 +315,7 @@ pub mod v4 { let updated_sale_info = SaleInfoRecord { sale_start: updated_sale_start, leadin_length: updated_leadin_length, - end_price: sale_info.price, - region_begin: sale_info.region_begin, - region_end: sale_info.region_end, - ideal_cores_sold: sale_info.ideal_cores_sold, - cores_offered: sale_info.cores_offered, - first_core: sale_info.first_core, - sellout_price: sale_info.sellout_price, - cores_sold: sale_info.cores_sold, + ..sale_info }; SaleInfo::::put(updated_sale_info); } From 3a98e4016e1a38e826f049b2c8b6de758e168f00 Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 31 Oct 2024 10:14:08 +0200 Subject: [PATCH 19/25] Revert "Update substrate/frame/broker/src/migration.rs" This reverts commit 25532a2033b5d1766b6494e8c96e2eb3ad8cfc1b. --- substrate/frame/broker/src/migration.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 0c6ce20f2e66..91bdf57b61c1 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -315,7 +315,14 @@ pub mod v4 { let updated_sale_info = SaleInfoRecord { sale_start: updated_sale_start, leadin_length: updated_leadin_length, - ..sale_info + end_price: sale_info.price, + region_begin: sale_info.region_begin, + region_end: sale_info.region_end, + ideal_cores_sold: sale_info.ideal_cores_sold, + cores_offered: sale_info.cores_offered, + first_core: sale_info.first_core, + sellout_price: sale_info.sellout_price, + cores_sold: sale_info.cores_sold, }; SaleInfo::::put(updated_sale_info); } From a8dfcbbd886a04a12acdf8e2f947fc565b705aee Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 31 Oct 2024 10:14:24 +0200 Subject: [PATCH 20/25] Revert "Update substrate/frame/broker/src/migration.rs" This reverts commit 5131629214e1555357f4b84cbe405909a3afe53c. --- substrate/frame/broker/src/migration.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 91bdf57b61c1..f19b1e19bdd1 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -298,7 +298,12 @@ pub mod v4 { let updated_config_record = ConfigRecord { interlude_length: updated_interlude_length, leadin_length: updated_leadin_length, - ..config_record + advance_notice: config_record.advance_notice, + region_length: config_record.region_length, + ideal_bulk_proportion: config_record.ideal_bulk_proportion, + limit_cores_offered: config_record.limit_cores_offered, + renewal_bump: config_record.renewal_bump, + contribution_timeout: config_record.contribution_timeout, }; Configuration::::put(updated_config_record); } From e44ad5e2b047f8e86fd0ae4c59d62ab16053c678 Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 31 Oct 2024 10:23:40 +0200 Subject: [PATCH 21/25] Allow panics in `try-runtime` code --- substrate/frame/broker/src/migration.rs | 67 ++++++++++++------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index f19b1e19bdd1..99ba94e042a2 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -263,12 +263,9 @@ pub mod v4 { BlockConversion::convert_block_length_to_relay_length(configuration_leadin_length); log::info!(target: LOG_TARGET, "Configuration Pre-Migration: Interlude Length {:?}->{:?} Leadin Length {:?}->{:?}", interlude_length, updated_interlude_length, configuration_leadin_length, updated_leadin_length); + let sale_info_record = v3::SaleInfo::::get().expect("must exist"); let (sale_start, sale_info_leadin_length) = - if let Some(sale_info_record) = v3::SaleInfo::::get() { - (sale_info_record.sale_start, sale_info_record.leadin_length) - } else { - ((0 as u32).into(), (0 as u32).into()) - }; + (sale_info_record.sale_start, sale_info_record.leadin_length); let updated_sale_start: RelayBlockNumberOf = BlockConversion::convert_block_number_to_relay_height(sale_start); @@ -345,38 +342,36 @@ pub mod v4 { ): (BlockNumberFor, BlockNumberFor, BlockNumberFor, BlockNumberFor) = Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); - if let Some(config_record) = Configuration::::get() { - ensure!( - Self::verify_updated_block_length( - old_configuration_leadin_length, - config_record.leadin_length - ), - "must migrate configuration leadin_length" - ); - - ensure!( - Self::verify_updated_block_length( - old_interlude_length, - config_record.interlude_length - ), - "must migrate configuration interlude_length" - ); - } + let config_record = Configuration::::get().expect("must exist"); + ensure!( + Self::verify_updated_block_length( + old_configuration_leadin_length, + config_record.leadin_length + ), + "must migrate configuration leadin_length" + ); - if let Some(sale_info) = SaleInfo::::get() { - ensure!( - Self::verify_updated_block_time(old_sale_start, sale_info.sale_start), - "must migrate sale info sale_start" - ); - - ensure!( - Self::verify_updated_block_length( - old_sale_info_leadin_length, - sale_info.leadin_length - ), - "must migrate sale info leadin_length" - ); - } + ensure!( + Self::verify_updated_block_length( + old_interlude_length, + config_record.interlude_length + ), + "must migrate configuration interlude_length" + ); + + let sale_info = SaleInfo::::get().expect("must exist"); + ensure!( + Self::verify_updated_block_time(old_sale_start, sale_info.sale_start), + "must migrate sale info sale_start" + ); + + ensure!( + Self::verify_updated_block_length( + old_sale_info_leadin_length, + sale_info.leadin_length + ), + "must migrate sale info leadin_length" + ); Ok(()) } From 675bf5ff44b962324fd155d8b8a1bc4bd1f95a42 Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 31 Oct 2024 10:44:28 +0200 Subject: [PATCH 22/25] Revert "Allow panics in `try-runtime` code" This reverts commit e44ad5e2b047f8e86fd0ae4c59d62ab16053c678. --- substrate/frame/broker/src/migration.rs | 67 +++++++++++++------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 99ba94e042a2..f19b1e19bdd1 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -263,9 +263,12 @@ pub mod v4 { BlockConversion::convert_block_length_to_relay_length(configuration_leadin_length); log::info!(target: LOG_TARGET, "Configuration Pre-Migration: Interlude Length {:?}->{:?} Leadin Length {:?}->{:?}", interlude_length, updated_interlude_length, configuration_leadin_length, updated_leadin_length); - let sale_info_record = v3::SaleInfo::::get().expect("must exist"); let (sale_start, sale_info_leadin_length) = - (sale_info_record.sale_start, sale_info_record.leadin_length); + if let Some(sale_info_record) = v3::SaleInfo::::get() { + (sale_info_record.sale_start, sale_info_record.leadin_length) + } else { + ((0 as u32).into(), (0 as u32).into()) + }; let updated_sale_start: RelayBlockNumberOf = BlockConversion::convert_block_number_to_relay_height(sale_start); @@ -342,36 +345,38 @@ pub mod v4 { ): (BlockNumberFor, BlockNumberFor, BlockNumberFor, BlockNumberFor) = Decode::decode(&mut &state[..]).expect("pre_upgrade provides a valid state; qed"); - let config_record = Configuration::::get().expect("must exist"); - ensure!( - Self::verify_updated_block_length( - old_configuration_leadin_length, - config_record.leadin_length - ), - "must migrate configuration leadin_length" - ); - - ensure!( - Self::verify_updated_block_length( - old_interlude_length, - config_record.interlude_length - ), - "must migrate configuration interlude_length" - ); - - let sale_info = SaleInfo::::get().expect("must exist"); - ensure!( - Self::verify_updated_block_time(old_sale_start, sale_info.sale_start), - "must migrate sale info sale_start" - ); + if let Some(config_record) = Configuration::::get() { + ensure!( + Self::verify_updated_block_length( + old_configuration_leadin_length, + config_record.leadin_length + ), + "must migrate configuration leadin_length" + ); + + ensure!( + Self::verify_updated_block_length( + old_interlude_length, + config_record.interlude_length + ), + "must migrate configuration interlude_length" + ); + } - ensure!( - Self::verify_updated_block_length( - old_sale_info_leadin_length, - sale_info.leadin_length - ), - "must migrate sale info leadin_length" - ); + if let Some(sale_info) = SaleInfo::::get() { + ensure!( + Self::verify_updated_block_time(old_sale_start, sale_info.sale_start), + "must migrate sale info sale_start" + ); + + ensure!( + Self::verify_updated_block_length( + old_sale_info_leadin_length, + sale_info.leadin_length + ), + "must migrate sale info leadin_length" + ); + } Ok(()) } From 96b1355be2c5e8d2206b8b371ca766153f65c487 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 11 Nov 2024 14:03:20 +0200 Subject: [PATCH 23/25] Remove version bumps --- cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 2 +- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 04a3c73d0d8b..64490ccef5bc 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -150,7 +150,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: alloc::borrow::Cow::Borrowed("coretime-rococo"), impl_name: alloc::borrow::Cow::Borrowed("coretime-rococo"), authoring_version: 1, - spec_version: 1_017_000, + spec_version: 1_016_001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index e25dcf0f7cb3..4d0800e4cb7d 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -150,7 +150,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: alloc::borrow::Cow::Borrowed("coretime-westend"), impl_name: alloc::borrow::Cow::Borrowed("coretime-westend"), authoring_version: 1, - spec_version: 1_017_000, + spec_version: 1_016_001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 2, From 25627b09cd965751a93e381a3751f373c67ad46d Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 11 Nov 2024 14:49:29 +0200 Subject: [PATCH 24/25] Remove deprecated core_runtime_str --- cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs | 2 +- .../parachains/runtimes/coretime/coretime-westend/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 64490ccef5bc..31700c2e25ff 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -67,7 +67,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, + generic, impl_opaque_keys, traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug, diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 4d0800e4cb7d..1f0f54884fa8 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -67,7 +67,7 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; use sp_runtime::{ - create_runtime_str, generic, impl_opaque_keys, + generic, impl_opaque_keys, traits::{BlakeTwo256, Block as BlockT, BlockNumberProvider}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, DispatchError, MultiAddress, Perbill, RuntimeDebug, From 48d96c8bd9c17b1031f5b42095864743ef2c42d8 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 11 Nov 2024 17:21:24 +0200 Subject: [PATCH 25/25] Adjust coretime calculation in benchmarks --- substrate/frame/broker/src/benchmarking.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 98d69acab239..9ef9b1254435 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -217,9 +217,11 @@ mod benches { _(origin as T::RuntimeOrigin, initial_price, extra_cores.try_into().unwrap()); assert!(SaleInfo::::get().is_some()); + let sale_start = RCBlockNumberProviderOf::::current_block_number() + + config.interlude_length; assert_last_event::( Event::SaleInitialized { - sale_start: 2u32.into(), + sale_start, leadin_length: 1u32.into(), start_price: 1_000_000_000u32.into(), end_price: 10_000_000u32.into(), @@ -844,9 +846,11 @@ mod benches { } assert!(SaleInfo::::get().is_some()); + let sale_start = RCBlockNumberProviderOf::::current_block_number() + + config.interlude_length; assert_last_event::( Event::SaleInitialized { - sale_start: 2u32.into(), + sale_start, leadin_length: 1u32.into(), start_price: 1_000_000_000u32.into(), end_price: 10_000_000u32.into(),