From aabcb4b67ffc0ac5f2b846eaa9eee39289e4c275 Mon Sep 17 00:00:00 2001 From: antonva Date: Wed, 20 Mar 2024 13:49:12 +0000 Subject: [PATCH 01/67] Start implementing request revenue info --- .../parachains/src/coretime/benchmarking.rs | 14 ++++++ .../runtime/parachains/src/coretime/mod.rs | 48 +++++++++++-------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index d1ac71f580ee..dba2051d26dc 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -28,6 +28,20 @@ mod benchmarks { use super::*; use assigner_coretime::PartsOf57600; + #[benchmark] + fn request_revenue_info_at() { + //TODO: write actual benchmark + // Setup + let root_origin = ::RuntimeOrigin::root(); + + #[extrinsic_call] + _( + root_origin as ::RuntimeOrigin, + // TODO: Better when param + BlockNumberFor::::from(100), + ) + } + #[benchmark] fn request_core_count() { // Setup diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index eb9646d7e869..317f28a65dba 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -30,6 +30,7 @@ use xcm::v4::{send_xcm, Instruction, Junction, Location, OriginKind, SendXcm, We use crate::{ assigner_coretime::{self, PartsOf57600}, + assigner_on_demand, initializer::{OnNewSession, SessionChangeNotification}, origin::{ensure_parachain, Origin}, }; @@ -39,7 +40,7 @@ pub mod migration; pub trait WeightInfo { fn request_core_count() -> Weight; - //fn request_revenue_info_at() -> Weight; + fn request_revenue_info_at() -> Weight; //fn credit_account() -> Weight; fn assign_core(s: u32) -> Weight; } @@ -51,14 +52,14 @@ impl WeightInfo for TestWeightInfo { fn request_core_count() -> Weight { Weight::MAX } - // TODO: Add real benchmarking functionality for each of these to - // benchmarking.rs, then uncomment here and in trait definition. - /*fn request_revenue_info_at() -> Weight { + fn request_revenue_info_at() -> Weight { Weight::MAX } - fn credit_account() -> Weight { - Weight::MAX - }*/ + // TODO: Add real benchmarking functionality for each of these to + // benchmarking.rs, then uncomment here and in trait definition. + //fn credit_account() -> Weight { + // Weight::MAX + //} fn assign_core(_s: u32) -> Weight { Weight::MAX } @@ -96,7 +97,9 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + assigner_coretime::Config { + pub trait Config: + frame_system::Config + assigner_coretime::Config + assigner_on_demand::Config + { type RuntimeOrigin: From<::RuntimeOrigin> + Into::RuntimeOrigin>>; type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -139,17 +142,24 @@ pub mod pallet { configuration::Pallet::::set_coretime_cores_unchecked(u32::from(count)) } - //// TODO Impl me! - ////#[pallet::weight(::WeightInfo::request_revenue_info_at())] - //#[pallet::call_index(2)] - //pub fn request_revenue_info_at( - // origin: OriginFor, - // _when: BlockNumberFor, - //) -> DispatchResult { - // // Ignore requests not coming from the broker parachain or root. - // Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; - // Ok(()) - //} + /// Requests that the Relay-chain send a notify_revenue message back at or soon + /// after Relay-chain block number when whose until parameter is equal to `when`. + /// + /// The period in to the past which when is allowed to be may be limited; + /// if so the limit should be understood on a channel outside of this proposal. + /// In the case that the request cannot be serviced because when is too old a block + /// then a `notify_revenue`` message must still be returned, but its `revenue` field + /// may be `None``. + #[pallet::weight(::WeightInfo::request_revenue_info_at())] + #[pallet::call_index(2)] + pub fn request_revenue_info_at( + origin: OriginFor, + when: BlockNumberFor, + ) -> DispatchResult { + // Ignore requests not coming from the broker parachain or root. + Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; + assigner_on_demand::Pallet::::do_request_revenue_info_at(when) + } //// TODO Impl me! ////#[pallet::weight(::WeightInfo::credit_account())] From d8df101bc24d114950e1fd708b7ade5eabe9c52c Mon Sep 17 00:00:00 2001 From: antonva Date: Wed, 20 Mar 2024 13:50:28 +0000 Subject: [PATCH 02/67] Add revenue tracking to on demand pallet --- .../parachains/src/assigner_on_demand/mod.rs | 55 ++++++++++++++++++- .../src/assigner_on_demand/tests.rs | 35 +++++++++++- polkadot/runtime/parachains/src/mock.rs | 8 ++- polkadot/runtime/rococo/src/lib.rs | 3 + .../weights/runtime_parachains_coretime.rs | 1 + polkadot/runtime/westend/src/lib.rs | 3 + .../weights/runtime_parachains_coretime.rs | 1 + 7 files changed, 100 insertions(+), 6 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index c47c8745e654..e6ff7b914e8f 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -49,7 +49,7 @@ use frame_support::{ traits::{ Currency, ExistenceRequirement::{self, AllowDeath, KeepAlive}, - WithdrawReasons, + Imbalance, WithdrawReasons, }, }; use frame_system::pallet_prelude::*; @@ -205,6 +205,11 @@ enum QueuePushDirection { type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; +/// Shorthand for the NegativeImbalance type the runtime is using. +type NegativeImbalanceOf = <::Currency as Currency< + ::AccountId, +>>::NegativeImbalance; + /// Errors that can happen during spot traffic calculation. #[derive(PartialEq, RuntimeDebug)] enum SpotTrafficCalculationErr { @@ -324,6 +329,17 @@ pub mod pallet { /// The default value for the spot traffic multiplier. #[pallet::constant] type TrafficDefaultValue: Get; + + /// The maximum number of blocks some historical revenue + /// information stored for. + #[pallet::constant] + type MaxHistoricalRevenue: Get; + } + + /// Creates and empty revenue tracker if one isn't present in storage already. + #[pallet::type_value] + pub fn RevenueOnEmpty() -> BoundedVec, T::MaxHistoricalRevenue> { + BoundedVec::new() } /// Creates an empty queue status for an empty queue with initial traffic value. @@ -365,6 +381,15 @@ pub mod pallet { EntriesOnEmpty, >; + /// Keeps track of accumulated revenue from on demand order sales. + #[pallet::storage] + pub type Revenue = StorageValue< + _, + BoundedVec, T::MaxHistoricalRevenue>, + ValueQuery, + RevenueOnEmpty, + >; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -386,6 +411,12 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_now: BlockNumberFor) -> Weight { + // Update revenue information storage. + let zero_balance: BalanceOf = 0u32.into(); + Revenue::::mutate(|revenue| { + let _ = revenue.force_insert_keep_left(0, zero_balance); + }); + let config = >::config(); // We need to update the spot traffic on block initialize in order to account for idle // blocks. @@ -566,13 +597,16 @@ where ensure!(spot_price.le(&max_amount), Error::::SpotPriceHigherThanMaxAmount); // Charge the sending account the spot price - let _ = T::Currency::withdraw( + let withdrawn_amount = T::Currency::withdraw( &sender, spot_price, WithdrawReasons::FEE, existence_requirement, )?; + // Add the spot price to the revenue information + Self::add_revenue_info(withdrawn_amount); + ensure!( queue_status.size() < config.scheduler_params.on_demand_queue_max_size, Error::::QueueFull @@ -780,6 +814,23 @@ where }) } + pub fn do_request_revenue_info_at(_when: BlockNumberFor) -> DispatchResult { + //TODO: impl + Ok(()) + } + + /// Adds revenue information for the current block. + /// TODO Make sure we don't mess up total issuance + fn add_revenue_info(amount: NegativeImbalanceOf) { + Revenue::::mutate(|revenue| { + let current_revenue = revenue.get_mut(0); + current_revenue.map(|rev| { + let new_revenue = rev.saturating_add(amount.peek()); + *rev = new_revenue; + }) + }); + } + /// Getter for the affinity tracker. #[cfg(test)] fn get_affinity_map(para_id: ParaId) -> Option { diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 982efe77b939..b1b2f7e4a42f 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -26,7 +26,7 @@ use crate::{ paras::{ParaGenesisArgs, ParaKind}, }; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; -use pallet_balances::Error as BalancesError; +use pallet_balances::{Error as BalancesError, NegativeImbalance}; use primitives::{BlockNumber, SessionIndex, ValidationCode}; use sp_std::collections::btree_map::BTreeMap; @@ -73,7 +73,7 @@ fn run_to_block( Paras::initializer_initialize(b + 1); Scheduler::initializer_initialize(b + 1); - // We need to update the spot traffic on every block. + // Update the spot traffic on every block. OnDemandAssigner::on_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. @@ -707,3 +707,34 @@ fn queue_status_size_fn_works() { assert_eq!(OnDemandAssigner::get_queue_status().size(), 4) }); } + +#[test] +fn add_revenue_info_works() { + new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { + // Revenue should be empty on block 0 + assert_eq!(Revenue::::get().len(), 0); + + // Mock assigner sets max revenue history to 10. + run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); + assert_eq!(Revenue::::get().len(), 10); + + // New revenue + let val: u128 = 1; + let imbalance = NegativeImbalance::new(val); + OnDemandAssigner::add_revenue_info(imbalance); + let rev = Revenue::::get(); + assert_eq!(rev.get(0).unwrap(), &val); + + let imbalance = NegativeImbalance::new(val); + OnDemandAssigner::add_revenue_info(imbalance); + let rev = Revenue::::get(); + assert_eq!(rev.get(0).unwrap(), &2); + + // Should still be at 10 and the previous value should be + // shifted from index 0 -> 1. + run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); + assert_eq!(Revenue::::get().len(), 10); + let rev = Revenue::::get(); + assert_eq!(rev.get(1).unwrap(), &2); + }); +} diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 7ed62a392e4e..41a8238799c8 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -367,17 +367,21 @@ impl pallet_message_queue::Config for Test { type ServiceWeight = MessageQueueServiceWeight; } +impl assigner_parachains::Config for Test {} + parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); + // Production chains should keep this numbar around twice the + // defined Timeslice for Coretime. + pub const MaxHistoricalRevenue: BlockNumber = 2 * 5; } -impl assigner_parachains::Config for Test {} - impl assigner_on_demand::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = crate::assigner_on_demand::TestWeightInfo; + type MaxHistoricalRevenue = MaxHistoricalRevenue; } impl assigner_coretime::Config for Test {} diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index c9f5d81d286a..50725d9883ca 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1028,6 +1028,8 @@ impl coretime::Config for Runtime { parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); + // Keep 2 timeslices worth of revenue information. + pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; } impl parachains_assigner_on_demand::Config for Runtime { @@ -1035,6 +1037,7 @@ impl parachains_assigner_on_demand::Config for Runtime { type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; + type MaxHistoricalRevenue = MaxHistoricalRevenue; } impl parachains_assigner_coretime::Config for Runtime {} diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs index d9f2d45207b9..7b6604a7b46e 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs @@ -70,4 +70,5 @@ impl runtime_parachains::coreti .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } + fn request_revenue_info_at() -> frame_support::weights::Weight { todo!() } } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 83d47508c7c7..1e9bec61ccb9 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1233,6 +1233,8 @@ impl coretime::Config for Runtime { parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); + // Keep 2 timeslices worth of revenue information. + pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; } impl parachains_assigner_on_demand::Config for Runtime { @@ -1240,6 +1242,7 @@ impl parachains_assigner_on_demand::Config for Runtime { type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; + type MaxHistoricalRevenue = MaxHistoricalRevenue; } impl parachains_assigner_coretime::Config for Runtime {} diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs index aa65a2e9034a..77e07319845b 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs @@ -81,4 +81,5 @@ impl runtime_parachains::coretime::WeightInfo for Weigh .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } + fn request_revenue_info_at() -> frame_support::weights::Weight { todo!() } } From 8f7c179e79f9cac0018565e8fca31fc3d6e82f40 Mon Sep 17 00:00:00 2001 From: antonva Date: Tue, 2 Apr 2024 11:43:49 +0000 Subject: [PATCH 03/67] Add revenue call to broker pallet --- substrate/frame/broker/src/dispatchable_impls.rs | 5 +++++ substrate/frame/broker/src/lib.rs | 12 ++++++++++++ substrate/frame/broker/src/weights.rs | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index f2451013251f..ee3df6b3a854 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -437,4 +437,9 @@ impl Pallet { Self::deposit_event(Event::AllowedRenewalDropped { core, when }); Ok(()) } + + pub(crate) fn do_notify_revenue(amount: BalanceOf) -> DispatchResult { + RevenueInbox::::put(Some(amount)); + Ok(()) + } } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index a669463aa02d..a9a5ed46b109 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -163,6 +163,10 @@ pub mod pallet { #[pallet::storage] pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; + /// Received revenue info from the relay chain. + #[pallet::storage] + pub type RevenueInbox = StorageValue<_, RelayBalanceOf, OptionQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -786,5 +790,13 @@ pub mod pallet { Self::do_notify_core_count(core_count)?; Ok(()) } + + #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::notify_revenue())] + pub fn notify_revenue(origin: OriginFor, amount: BalanceOf) -> DispatchResult { + T::AdminOrigin::ensure_origin_or_root(origin)?; + Self::do_notify_revenue(amount)?; + Ok(()) + } } } diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index a8f50eeee6e6..46686fb9b1e4 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -75,6 +75,7 @@ pub trait WeightInfo { fn process_core_schedule() -> Weight; fn request_revenue_info_at() -> Weight; fn notify_core_count() -> Weight; + fn notify_revenue() -> Weight; fn do_tick_base() -> Weight; } @@ -451,6 +452,9 @@ impl WeightInfo for SubstrateWeight { fn notify_core_count() -> Weight { T::DbWeight::get().reads_writes(1, 1) } + fn notify_revenue() -> Weight { + T::DbWeight::get().reads_writes(1, 1) + } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) @@ -843,6 +847,12 @@ impl WeightInfo for () { RocksDbWeight::get().reads(1) .saturating_add(RocksDbWeight::get().writes(1)) } + + fn notify_revenue() -> Weight { + RocksDbWeight::get().reads(1) + .saturating_add(RocksDbWeight::get().writes(1)) + } + /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) From 54e0326967fb00b64a4e33694e38ca693ae2ede3 Mon Sep 17 00:00:00 2001 From: antonva Date: Tue, 2 Apr 2024 11:45:11 +0000 Subject: [PATCH 04/67] Partial impl of revenue from relay chain --- .../parachains/src/assigner_on_demand/mod.rs | 102 ++++++++++++++---- .../src/assigner_on_demand/tests.rs | 5 + .../runtime/parachains/src/coretime/mod.rs | 12 ++- polkadot/runtime/rococo/src/lib.rs | 2 + polkadot/runtime/westend/src/lib.rs | 2 + 5 files changed, 99 insertions(+), 24 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index e6ff7b914e8f..c0074b0182b7 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -42,18 +42,24 @@ mod tests; use core::mem::take; -use crate::{configuration, paras, scheduler::common::Assignment}; +use crate::{ + configuration, + coretime::{mk_coretime_call, BrokerRuntimePallets, CoretimeCalls}, + paras, + scheduler::common::Assignment, +}; +use xcm::v4::{send_xcm, Instruction, Junction, Location, OriginKind, SendXcm, WeightLimit, Xcm}; use frame_support::{ pallet_prelude::*, traits::{ Currency, ExistenceRequirement::{self, AllowDeath, KeepAlive}, - Imbalance, WithdrawReasons, + Imbalance, OnUnbalanced, WithdrawReasons, }, }; use frame_system::pallet_prelude::*; -use primitives::{CoreIndex, Id as ParaId, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; +use primitives::{Balance, CoreIndex, Id as ParaId, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; use sp_runtime::{ traits::{One, SaturatedConversion}, FixedPointNumber, FixedPointOperand, FixedU128, Perbill, Saturating, @@ -334,6 +340,12 @@ pub mod pallet { /// information stored for. #[pallet::constant] type MaxHistoricalRevenue: Get; + + type SendXcm: SendXcm; + + /// The ParaId of the broker system parachain. + #[pallet::constant] + type BrokerId: Get; } /// Creates and empty revenue tracker if one isn't present in storage already. @@ -406,6 +418,9 @@ pub mod pallet { /// The current spot price is higher than the max amount specified in the `place_order` /// call, making it invalid. SpotPriceHigherThanMaxAmount, + /// Requested revenue information `when` parameter was in the future from the current + /// block height. + RequestedFutureRevenue, } #[pallet::hooks] @@ -560,7 +575,8 @@ where } /// Helper function for `place_order_*` calls. Used to differentiate between placing orders - /// with a keep alive check or to allow the account to be reaped. + /// with a keep alive check or to allow the account to be reaped. The amount charged is + /// burnt from the `Currency` and stored to /// /// Parameters: /// - `sender`: The sender of the call, funds will be withdrawn from this account. @@ -596,17 +612,15 @@ where // Is the current price higher than `max_amount` ensure!(spot_price.le(&max_amount), Error::::SpotPriceHigherThanMaxAmount); - // Charge the sending account the spot price - let withdrawn_amount = T::Currency::withdraw( + // Charge the sending account the spot price. The imbalance is handled by this pallet's + // `OnUnbalanced` trait implementation and added to the revenue information. + let _ = T::Currency::withdraw( &sender, spot_price, WithdrawReasons::FEE, existence_requirement, )?; - // Add the spot price to the revenue information - Self::add_revenue_info(withdrawn_amount); - ensure!( queue_status.size() < config.scheduler_params.on_demand_queue_max_size, Error::::QueueFull @@ -814,21 +828,51 @@ where }) } - pub fn do_request_revenue_info_at(_when: BlockNumberFor) -> DispatchResult { - //TODO: impl + /// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain + /// block number last_until to until, not including until itself. last_until is defined as being + /// the until argument of the last notify_revenue message sent, or zero for the first call. If + /// revenue is None, this indicates that the information is no longer available. This explicitly + /// disregards the possibility of multiple parachains requesting and being notified of revenue + /// information. + /// + /// The Relay-chain must be configured to ensure that only a single revenue information + /// destination exists. + pub fn notify_revenue(when: BlockNumberFor) -> DispatchResult { + let now = >::block_number(); + // When cannot be in the future. + ensure!(when <= now, Error::::RequestedFutureRevenue); + + // TODO actual revenue + let revenue: Balance = 0u128; + let message = Xcm(vec![ + Instruction::UnpaidExecution { + weight_limit: WeightLimit::Unlimited, + check_origin: None, + }, + mk_coretime_call(CoretimeCalls::NotifyRevenue(revenue)), + ]); + if let Err(err) = send_xcm::( + Location::new(0, [Junction::Parachain(T::BrokerId::get())]), + message, + ) { + log::error!("Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); + } + Ok(()) } - /// Adds revenue information for the current block. - /// TODO Make sure we don't mess up total issuance - fn add_revenue_info(amount: NegativeImbalanceOf) { - Revenue::::mutate(|revenue| { - let current_revenue = revenue.get_mut(0); - current_revenue.map(|rev| { - let new_revenue = rev.saturating_add(amount.peek()); - *rev = new_revenue; + fn get_revenue(now: BlockNumberFor, when: BlockNumberFor) -> Balance { + let revenue: Balance = 0u128; + T::Revenue::mutate(|revenue| { + revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { + // + if when >= now.saturating_sub(index) { + revenue.saturating_add(block_revenue); + block_revenue = 0; + } }) }); + revenue } /// Getter for the affinity tracker. @@ -873,3 +917,23 @@ where ::TrafficDefaultValue::get() } } + +/// Add all negative imbalance dropped to the historical on demand revenue. +impl OnUnbalanced> for Pallet { + fn on_nonzero_unbalanced(amount: NegativeImbalanceOf) { + let numeric_amount = amount.peek(); + + // Add the amount to the current block's revenue information. + Revenue::::mutate(|revenue| { + let current_revenue = revenue.get_mut(0); + current_revenue.map(|rev| { + let new_revenue = rev.saturating_add(numeric_amount); + *rev = new_revenue; + }) + }); + + // NOTE: The tokens could be burned at this point, but are kept in total issuance + // and teleported (burnt on the relay chain) to the broker chain when it requests + // revenue information. + } +} diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index b1b2f7e4a42f..0eb55af0e96b 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -710,7 +710,12 @@ fn queue_status_size_fn_works() { #[test] fn add_revenue_info_works() { + let alice = 100u64; + let amt = 10_000_000u128; new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { + Balances::make_free_balance_be(&alice, amt); + assert_eq!(Balances::total_issuance(), amt); + // Revenue should be empty on block 0 assert_eq!(Revenue::::get().len(), 0); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 317f28a65dba..a758bb4fabbc 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -24,7 +24,7 @@ use frame_support::{pallet_prelude::*, traits::Currency}; use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_broker::{CoreAssignment, CoreIndex as BrokerCoreIndex}; -use primitives::{CoreIndex, Id as ParaId}; +use primitives::{Balance, CoreIndex, Id as ParaId}; use sp_arithmetic::traits::SaturatedConversion; use xcm::v4::{send_xcm, Instruction, Junction, Location, OriginKind, SendXcm, WeightLimit, Xcm}; @@ -70,20 +70,22 @@ impl WeightInfo for TestWeightInfo { /// construct remote calls. The codec index must correspond to the index of `Broker` in the /// `construct_runtime` of the coretime chain. #[derive(Encode, Decode)] -enum BrokerRuntimePallets { +pub(crate) enum BrokerRuntimePallets { #[codec(index = 50)] Broker(CoretimeCalls), } /// Call encoding for the calls needed from the Broker pallet. #[derive(Encode, Decode)] -enum CoretimeCalls { +pub(crate) enum CoretimeCalls { #[codec(index = 1)] Reserve(pallet_broker::Schedule), #[codec(index = 3)] SetLease(pallet_broker::TaskId, pallet_broker::Timeslice), #[codec(index = 19)] NotifyCoreCount(u16), + #[codec(index = 20)] + NotifyRevenue(Balance), } #[frame_support::pallet] @@ -158,7 +160,7 @@ pub mod pallet { ) -> DispatchResult { // Ignore requests not coming from the broker parachain or root. Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; - assigner_on_demand::Pallet::::do_request_revenue_info_at(when) + assigner_on_demand::Pallet::::notify_revenue(when) } //// TODO Impl me! @@ -251,7 +253,7 @@ impl OnNewSession> for Pallet { } } -fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> { +pub(crate) fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> { Instruction::Transact { origin_kind: OriginKind::Superuser, // Largest call is set_lease with 1526 byte: diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 50725d9883ca..44f3391f069f 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1038,6 +1038,8 @@ impl parachains_assigner_on_demand::Config for Runtime { type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; + type SendXcm = crate::xcm_config::XcmRouter; + type BrokerId = BrokerId; } impl parachains_assigner_coretime::Config for Runtime {} diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 1e9bec61ccb9..55772f0c8c2a 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1243,6 +1243,8 @@ impl parachains_assigner_on_demand::Config for Runtime { type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; + type SendXcm = crate::xcm_config::XcmRouter; + type BrokerId = BrokerId; } impl parachains_assigner_coretime::Config for Runtime {} From d8bfb7290ef188edc9746a641876030abcaaf8e0 Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 10:11:19 +0000 Subject: [PATCH 05/67] Move xcm sending from ondemand to coretime pallet --- .../parachains/src/assigner_on_demand/mod.rs | 58 +++---------------- .../runtime/parachains/src/coretime/mod.rs | 48 +++++++++++++-- 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index c0074b0182b7..c25ed660105c 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -340,12 +340,6 @@ pub mod pallet { /// information stored for. #[pallet::constant] type MaxHistoricalRevenue: Get; - - type SendXcm: SendXcm; - - /// The ParaId of the broker system parachain. - #[pallet::constant] - type BrokerId: Get; } /// Creates and empty revenue tracker if one isn't present in storage already. @@ -418,9 +412,6 @@ pub mod pallet { /// The current spot price is higher than the max amount specified in the `place_order` /// call, making it invalid. SpotPriceHigherThanMaxAmount, - /// Requested revenue information `when` parameter was in the future from the current - /// block height. - RequestedFutureRevenue, } #[pallet::hooks] @@ -828,51 +819,18 @@ where }) } - /// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain - /// block number last_until to until, not including until itself. last_until is defined as being - /// the until argument of the last notify_revenue message sent, or zero for the first call. If - /// revenue is None, this indicates that the information is no longer available. This explicitly - /// disregards the possibility of multiple parachains requesting and being notified of revenue - /// information. - /// - /// The Relay-chain must be configured to ensure that only a single revenue information - /// destination exists. - pub fn notify_revenue(when: BlockNumberFor) -> DispatchResult { - let now = >::block_number(); - // When cannot be in the future. - ensure!(when <= now, Error::::RequestedFutureRevenue); - - // TODO actual revenue - let revenue: Balance = 0u128; - let message = Xcm(vec![ - Instruction::UnpaidExecution { - weight_limit: WeightLimit::Unlimited, - check_origin: None, - }, - mk_coretime_call(CoretimeCalls::NotifyRevenue(revenue)), - ]); - if let Err(err) = send_xcm::( - Location::new(0, [Junction::Parachain(T::BrokerId::get())]), - message, - ) { - log::error!("Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); - } - - Ok(()) - } - - fn get_revenue(now: BlockNumberFor, when: BlockNumberFor) -> Balance { - let revenue: Balance = 0u128; - T::Revenue::mutate(|revenue| { - revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { + pub fn get_revenue(now: BlockNumberFor, when: BlockNumberFor) -> BalanceOf { + let mut amount: BalanceOf = 0.into(); + Revenue::::mutate(|revenue| { + revenue.into_iter().enumerate().for_each(|(index, mut block_revenue)| { // - if when >= now.saturating_sub(index) { - revenue.saturating_add(block_revenue); - block_revenue = 0; + if when >= now.saturating_sub((index as u32).into()) { + amount.saturating_add(*block_revenue); + block_revenue = 0.into(); } }) }); - revenue + amount } /// Getter for the affinity tracker. diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index a758bb4fabbc..179b72e4d6e9 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -65,19 +65,23 @@ impl WeightInfo for TestWeightInfo { } } +/// Shorthand for the Balance type the runtime is using. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + /// Broker pallet index on the coretime chain. Used to /// /// construct remote calls. The codec index must correspond to the index of `Broker` in the /// `construct_runtime` of the coretime chain. #[derive(Encode, Decode)] -pub(crate) enum BrokerRuntimePallets { +enum BrokerRuntimePallets { #[codec(index = 50)] Broker(CoretimeCalls), } /// Call encoding for the calls needed from the Broker pallet. #[derive(Encode, Decode)] -pub(crate) enum CoretimeCalls { +enum CoretimeCalls { #[codec(index = 1)] Reserve(pallet_broker::Schedule), #[codec(index = 3)] @@ -128,6 +132,9 @@ pub mod pallet { pub enum Error { /// The paraid making the call is not the coretime brokerage system parachain. NotBroker, + /// Requested revenue information `when` parameter was in the future from the current + /// block height. + RequestedFutureRevenue, } #[pallet::hooks] @@ -160,7 +167,7 @@ pub mod pallet { ) -> DispatchResult { // Ignore requests not coming from the broker parachain or root. Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; - assigner_on_demand::Pallet::::notify_revenue(when) + Self::notify_revenue(when) } //// TODO Impl me! @@ -245,6 +252,39 @@ impl Pallet { } } } + + /// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain + /// block number last_until to until, not including until itself. last_until is defined as being + /// the until argument of the last notify_revenue message sent, or zero for the first call. If + /// revenue is None, this indicates that the information is no longer available. This explicitly + /// disregards the possibility of multiple parachains requesting and being notified of revenue + /// information. + /// + /// The Relay-chain must be configured to ensure that only a single revenue information + /// destination exists. + pub fn notify_revenue(when: BlockNumberFor) -> DispatchResult { + let now = >::block_number(); + // When cannot be in the future. + ensure!(when <= now, Error::::RequestedFutureRevenue); + + // TODO actual revenue + let revenue = >::get_revenue(now, when); + let message = Xcm(vec![ + Instruction::UnpaidExecution { + weight_limit: WeightLimit::Unlimited, + check_origin: None, + }, + mk_coretime_call(CoretimeCalls::NotifyRevenue(revenue.inner())), + ]); + if let Err(err) = send_xcm::( + Location::new(0, [Junction::Parachain(T::BrokerId::get())]), + message, + ) { + log::error!("Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); + } + + Ok(()) + } } impl OnNewSession> for Pallet { @@ -253,7 +293,7 @@ impl OnNewSession> for Pallet { } } -pub(crate) fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> { +fn mk_coretime_call(call: crate::coretime::CoretimeCalls) -> Instruction<()> { Instruction::Transact { origin_kind: OriginKind::Superuser, // Largest call is set_lease with 1526 byte: From f3dfe449398f39cf3535c1c41d0a4df84114af6e Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 10:13:19 +0000 Subject: [PATCH 06/67] Move ondemand types into separate module --- .../parachains/src/assigner_on_demand/mod.rs | 239 +---------------- .../src/assigner_on_demand/types.rs | 246 ++++++++++++++++++ 2 files changed, 254 insertions(+), 231 deletions(-) create mode 100644 polkadot/runtime/parachains/src/assigner_on_demand/types.rs diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index c25ed660105c..159800dad8c7 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -34,22 +34,16 @@ mod benchmarking; pub mod migration; mod mock_helpers; +mod types; extern crate alloc; #[cfg(test)] mod tests; +use crate::{configuration, paras, scheduler::common::Assignment}; +use alloc::collections::BinaryHeap; use core::mem::take; - -use crate::{ - configuration, - coretime::{mk_coretime_call, BrokerRuntimePallets, CoretimeCalls}, - paras, - scheduler::common::Assignment, -}; -use xcm::v4::{send_xcm, Instruction, Junction, Location, OriginKind, SendXcm, WeightLimit, Xcm}; - use frame_support::{ pallet_prelude::*, traits::{ @@ -59,16 +53,15 @@ use frame_support::{ }, }; use frame_system::pallet_prelude::*; -use primitives::{Balance, CoreIndex, Id as ParaId, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; +use primitives::{CoreIndex, Id as ParaId}; use sp_runtime::{ traits::{One, SaturatedConversion}, FixedPointNumber, FixedPointOperand, FixedU128, Perbill, Saturating, }; - -use alloc::collections::BinaryHeap; -use sp_std::{ - cmp::{Ord, Ordering, PartialOrd}, - prelude::*, +use sp_std::prelude::*; +use types::{ + BalanceOf, CoreAffinityCount, EnqueuedOrder, NegativeImbalanceOf, QueuePushDirection, + QueueStatusType, SpotTrafficCalculationErr, }; const LOG_TARGET: &str = "runtime::parachains::assigner-on-demand"; @@ -93,222 +86,6 @@ impl WeightInfo for TestWeightInfo { } } -/// Meta data for full queue. -/// -/// This includes elements with affinity and free entries. -/// -/// The actual queue is implemented via multiple priority queues. One for each core, for entries -/// which currently have a core affinity and one free queue, with entries without any affinity yet. -/// -/// The design aims to have most queue accessess be O(1) or O(log(N)). Absolute worst case is O(N). -/// Importantly this includes all accessess that happen in a single block. Even with 50 cores, the -/// total complexity of all operations in the block should maintain above complexities. In -/// particular O(N) stays O(N), it should never be O(N*cores). -/// -/// More concrete rundown on complexity: -/// -/// - insert: O(1) for placing an order, O(log(N)) for push backs. -/// - pop_assignment_for_core: O(log(N)), O(N) worst case: Can only happen for one core, next core -/// is already less work. -/// - report_processed & push back: If affinity dropped to 0, then O(N) in the worst case. Again -/// this divides per core. -/// -/// Reads still exist, also improved slightly, but worst case we fetch all entries. -#[derive(Encode, Decode, TypeInfo)] -struct QueueStatusType { - /// Last calculated traffic value. - traffic: FixedU128, - /// The next index to use. - next_index: QueueIndex, - /// Smallest index still in use. - /// - /// In case of a completely empty queue (free + affinity queues), `next_index - smallest_index - /// == 0`. - smallest_index: QueueIndex, - /// Indices that have been freed already. - /// - /// But have a hole to `smallest_index`, so we can not yet bump `smallest_index`. This binary - /// heap is roughly bounded in the number of on demand cores: - /// - /// For a single core, elements will always be processed in order. With each core added, a - /// level of out of order execution is added. - freed_indices: BinaryHeap, -} - -impl Default for QueueStatusType { - fn default() -> QueueStatusType { - QueueStatusType { - traffic: FixedU128::default(), - next_index: QueueIndex(0), - smallest_index: QueueIndex(0), - freed_indices: BinaryHeap::new(), - } - } -} - -impl QueueStatusType { - /// How many orders are queued in total? - /// - /// This includes entries which have core affinity. - fn size(&self) -> u32 { - self.next_index - .0 - .overflowing_sub(self.smallest_index.0) - .0 - .saturating_sub(self.freed_indices.len() as u32) - } - - /// Get current next index - /// - /// to use for an element newly pushed to the back of the queue. - fn push_back(&mut self) -> QueueIndex { - let QueueIndex(next_index) = self.next_index; - self.next_index = QueueIndex(next_index.overflowing_add(1).0); - QueueIndex(next_index) - } - - /// Push something to the front of the queue - fn push_front(&mut self) -> QueueIndex { - self.smallest_index = QueueIndex(self.smallest_index.0.overflowing_sub(1).0); - self.smallest_index - } - - /// The given index is no longer part of the queue. - /// - /// This updates `smallest_index` if need be. - fn consume_index(&mut self, removed_index: QueueIndex) { - if removed_index != self.smallest_index { - self.freed_indices.push(removed_index.reverse()); - return - } - let mut index = self.smallest_index.0.overflowing_add(1).0; - // Even more to advance? - while self.freed_indices.peek() == Some(&ReverseQueueIndex(index)) { - index = index.overflowing_add(1).0; - self.freed_indices.pop(); - } - self.smallest_index = QueueIndex(index); - } -} - -/// Keeps track of how many assignments a scheduler currently has at a specific `CoreIndex` for a -/// specific `ParaId`. -#[derive(Encode, Decode, Default, Clone, Copy, TypeInfo)] -#[cfg_attr(test, derive(PartialEq, RuntimeDebug))] -struct CoreAffinityCount { - core_index: CoreIndex, - count: u32, -} - -/// An indicator as to which end of the `OnDemandQueue` an assignment will be placed. -#[cfg_attr(test, derive(RuntimeDebug))] -enum QueuePushDirection { - Back, - Front, -} - -/// Shorthand for the Balance type the runtime is using. -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -/// Shorthand for the NegativeImbalance type the runtime is using. -type NegativeImbalanceOf = <::Currency as Currency< - ::AccountId, ->>::NegativeImbalance; - -/// Errors that can happen during spot traffic calculation. -#[derive(PartialEq, RuntimeDebug)] -enum SpotTrafficCalculationErr { - /// The order queue capacity is at 0. - QueueCapacityIsZero, - /// The queue size is larger than the queue capacity. - QueueSizeLargerThanCapacity, - /// Arithmetic error during division, either division by 0 or over/underflow. - Division, -} - -/// Type used for priority indices. -// NOTE: The `Ord` implementation for this type is unsound in the general case. -// Do not use it for anything but it's intended purpose. -#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] -struct QueueIndex(u32); - -/// QueueIndex with reverse ordering. -/// -/// Same as `Reverse(QueueIndex)`, but with all the needed traits implemented. -#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] -struct ReverseQueueIndex(u32); - -impl QueueIndex { - fn reverse(self) -> ReverseQueueIndex { - ReverseQueueIndex(self.0) - } -} - -impl Ord for QueueIndex { - fn cmp(&self, other: &Self) -> Ordering { - let diff = self.0.overflowing_sub(other.0).0; - if diff == 0 { - Ordering::Equal - } else if diff <= ON_DEMAND_MAX_QUEUE_MAX_SIZE { - Ordering::Greater - } else { - Ordering::Less - } - } -} - -impl PartialOrd for QueueIndex { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for ReverseQueueIndex { - fn cmp(&self, other: &Self) -> Ordering { - QueueIndex(other.0).cmp(&QueueIndex(self.0)) - } -} -impl PartialOrd for ReverseQueueIndex { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(&other)) - } -} - -/// Internal representation of an order after it has been enqueued already. -/// -/// This data structure is provided for a min BinaryHeap (Ord compares in reverse order with regards -/// to its elements) -#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq)] -struct EnqueuedOrder { - para_id: ParaId, - idx: QueueIndex, -} - -impl EnqueuedOrder { - fn new(idx: QueueIndex, para_id: ParaId) -> Self { - Self { idx, para_id } - } -} - -impl PartialOrd for EnqueuedOrder { - fn partial_cmp(&self, other: &Self) -> Option { - match other.idx.partial_cmp(&self.idx) { - Some(Ordering::Equal) => other.para_id.partial_cmp(&self.para_id), - o => o, - } - } -} - -impl Ord for EnqueuedOrder { - fn cmp(&self, other: &Self) -> Ordering { - match other.idx.cmp(&self.idx) { - Ordering::Equal => other.para_id.cmp(&self.para_id), - o => o, - } - } -} - #[frame_support::pallet] pub mod pallet { diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs new file mode 100644 index 000000000000..c0452c86fa75 --- /dev/null +++ b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs @@ -0,0 +1,246 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! On demand module types. + +use super::{alloc, pallet::Config}; +use alloc::collections::BinaryHeap; +use frame_support::{ + pallet_prelude::{Decode, Encode, RuntimeDebug, TypeInfo}, + traits::Currency, +}; +use primitives::{CoreIndex, Id as ParaId, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; +use sp_runtime::FixedU128; +use sp_std::{ + cmp::{Ord, Ordering, PartialOrd}, + prelude::*, +}; + +/// Shorthand for the Balance type the runtime is using. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + +/// Shorthand for the NegativeImbalance type the runtime is using. +pub type NegativeImbalanceOf = <::Currency as Currency< + ::AccountId, +>>::NegativeImbalance; + +/// Meta data for full queue. +/// +/// This includes elements with affinity and free entries. +/// +/// The actual queue is implemented via multiple priority queues. One for each core, for entries +/// which currently have a core affinity and one free queue, with entries without any affinity yet. +/// +/// The design aims to have most queue accessess be O(1) or O(log(N)). Absolute worst case is O(N). +/// Importantly this includes all accessess that happen in a single block. Even with 50 cores, the +/// total complexity of all operations in the block should maintain above complexities. In +/// particular O(N) stays O(N), it should never be O(N*cores). +/// +/// More concrete rundown on complexity: +/// +/// - insert: O(1) for placing an order, O(log(N)) for push backs. +/// - pop_assignment_for_core: O(log(N)), O(N) worst case: Can only happen for one core, next core +/// is already less work. +/// - report_processed & push back: If affinity dropped to 0, then O(N) in the worst case. Again +/// this divides per core. +/// +/// Reads still exist, also improved slightly, but worst case we fetch all entries. +#[derive(Encode, Decode, TypeInfo)] +pub struct QueueStatusType { + /// Last calculated traffic value. + pub traffic: FixedU128, + /// The next index to use. + pub next_index: QueueIndex, + /// Smallest index still in use. + /// + /// In case of a completely empty queue (free + affinity queues), `next_index - smallest_index + /// == 0`. + pub smallest_index: QueueIndex, + /// Indices that have been freed already. + /// + /// But have a hole to `smallest_index`, so we can not yet bump `smallest_index`. This binary + /// heap is roughly bounded in the number of on demand cores: + /// + /// For a single core, elements will always be processed in order. With each core added, a + /// level of out of order execution is added. + pub freed_indices: BinaryHeap, +} + +impl Default for QueueStatusType { + fn default() -> QueueStatusType { + QueueStatusType { + traffic: FixedU128::default(), + next_index: QueueIndex(0), + smallest_index: QueueIndex(0), + freed_indices: BinaryHeap::new(), + } + } +} + +impl QueueStatusType { + /// How many orders are queued in total? + /// + /// This includes entries which have core affinity. + pub fn size(&self) -> u32 { + self.next_index + .0 + .overflowing_sub(self.smallest_index.0) + .0 + .saturating_sub(self.freed_indices.len() as u32) + } + + /// Get current next index + /// + /// to use for an element newly pushed to the back of the queue. + pub fn push_back(&mut self) -> QueueIndex { + let QueueIndex(next_index) = self.next_index; + self.next_index = QueueIndex(next_index.overflowing_add(1).0); + QueueIndex(next_index) + } + + /// Push something to the front of the queue + pub fn push_front(&mut self) -> QueueIndex { + self.smallest_index = QueueIndex(self.smallest_index.0.overflowing_sub(1).0); + self.smallest_index + } + + /// The given index is no longer part of the queue. + /// + /// This updates `smallest_index` if need be. + pub fn consume_index(&mut self, removed_index: QueueIndex) { + if removed_index != self.smallest_index { + self.freed_indices.push(removed_index.reverse()); + return + } + let mut index = self.smallest_index.0.overflowing_add(1).0; + // Even more to advance? + while self.freed_indices.peek() == Some(&ReverseQueueIndex(index)) { + index = index.overflowing_add(1).0; + self.freed_indices.pop(); + } + self.smallest_index = QueueIndex(index); + } +} + +/// Type used for priority indices. +// NOTE: The `Ord` implementation for this type is unsound in the general case. +// Do not use it for anything but it's intended purpose. +#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] +pub struct QueueIndex(u32); + +/// QueueIndex with reverse ordering. +/// +/// Same as `Reverse(QueueIndex)`, but with all the needed traits implemented. +#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] +pub struct ReverseQueueIndex(u32); + +impl QueueIndex { + fn reverse(self) -> ReverseQueueIndex { + ReverseQueueIndex(self.0) + } +} + +impl Ord for QueueIndex { + fn cmp(&self, other: &Self) -> Ordering { + let diff = self.0.overflowing_sub(other.0).0; + if diff == 0 { + Ordering::Equal + } else if diff <= ON_DEMAND_MAX_QUEUE_MAX_SIZE { + Ordering::Greater + } else { + Ordering::Less + } + } +} + +impl PartialOrd for QueueIndex { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for ReverseQueueIndex { + fn cmp(&self, other: &Self) -> Ordering { + QueueIndex(other.0).cmp(&QueueIndex(self.0)) + } +} +impl PartialOrd for ReverseQueueIndex { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(&other)) + } +} + +/// Internal representation of an order after it has been enqueued already. +/// +/// This data structure is provided for a min BinaryHeap (Ord compares in reverse order with regards +/// to its elements) +#[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq)] +pub struct EnqueuedOrder { + pub para_id: ParaId, + pub idx: QueueIndex, +} + +impl EnqueuedOrder { + pub fn new(idx: QueueIndex, para_id: ParaId) -> Self { + Self { idx, para_id } + } +} + +impl PartialOrd for EnqueuedOrder { + fn partial_cmp(&self, other: &Self) -> Option { + match other.idx.partial_cmp(&self.idx) { + Some(Ordering::Equal) => other.para_id.partial_cmp(&self.para_id), + o => o, + } + } +} + +impl Ord for EnqueuedOrder { + fn cmp(&self, other: &Self) -> Ordering { + match other.idx.cmp(&self.idx) { + Ordering::Equal => other.para_id.cmp(&self.para_id), + o => o, + } + } +} + +/// Keeps track of how many assignments a scheduler currently has at a specific `CoreIndex` for a +/// specific `ParaId`. +#[derive(Encode, Decode, Default, Clone, Copy, TypeInfo)] +#[cfg_attr(test, derive(PartialEq, RuntimeDebug))] +pub struct CoreAffinityCount { + pub core_index: CoreIndex, + pub count: u32, +} + +/// An indicator as to which end of the `OnDemandQueue` an assignment will be placed. +#[cfg_attr(test, derive(RuntimeDebug))] +pub enum QueuePushDirection { + Back, + Front, +} + +/// Errors that can happen during spot traffic calculation. +#[derive(PartialEq, RuntimeDebug)] +pub enum SpotTrafficCalculationErr { + /// The order queue capacity is at 0. + QueueCapacityIsZero, + /// The queue size is larger than the queue capacity. + QueueSizeLargerThanCapacity, + /// Arithmetic error during division, either division by 0 or over/underflow. + Division, +} From 4f1a44d904cb66e5c3e960ac571fc11ae62b3899 Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 10:58:03 +0000 Subject: [PATCH 07/67] Add pallet id to on demand --- polkadot/runtime/parachains/src/assigner_on_demand/mod.rs | 4 ++++ polkadot/runtime/parachains/src/mock.rs | 3 +++ polkadot/runtime/rococo/src/lib.rs | 4 ++-- polkadot/runtime/westend/src/lib.rs | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 159800dad8c7..4a48e74d3738 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -117,6 +117,10 @@ pub mod pallet { /// information stored for. #[pallet::constant] type MaxHistoricalRevenue: Get; + + /// Identifier for the internal revenue balance. + #[pallet::constant] + type PalletId: Get; } /// Creates and empty revenue tracker if one isn't present in storage already. diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 41a8238799c8..28e17129a299 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -35,6 +35,7 @@ use frame_support::{ Currency, ProcessMessage, ProcessMessageError, ValidatorSet, ValidatorSetWithIdentification, }, weights::{Weight, WeightMeter}, + PalletId, }; use frame_support_test::TestRandomness; use frame_system::limits; @@ -374,6 +375,7 @@ parameter_types! { // Production chains should keep this numbar around twice the // defined Timeslice for Coretime. pub const MaxHistoricalRevenue: BlockNumber = 2 * 5; + pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } impl assigner_on_demand::Config for Test { @@ -382,6 +384,7 @@ impl assigner_on_demand::Config for Test { type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = crate::assigner_on_demand::TestWeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; + type PalletId = OnDemandPalletId; } impl assigner_coretime::Config for Test {} diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 44f3391f069f..486aa1d0609f 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1030,6 +1030,7 @@ parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); // Keep 2 timeslices worth of revenue information. pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; + pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } impl parachains_assigner_on_demand::Config for Runtime { @@ -1038,8 +1039,7 @@ impl parachains_assigner_on_demand::Config for Runtime { type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; - type SendXcm = crate::xcm_config::XcmRouter; - type BrokerId = BrokerId; + type PalletId = OnDemandPalletId; } impl parachains_assigner_coretime::Config for Runtime {} diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 55772f0c8c2a..1373ee0b11f0 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1235,6 +1235,7 @@ parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); // Keep 2 timeslices worth of revenue information. pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; + pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } impl parachains_assigner_on_demand::Config for Runtime { @@ -1243,8 +1244,7 @@ impl parachains_assigner_on_demand::Config for Runtime { type TrafficDefaultValue = OnDemandTrafficDefaultValue; type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; - type SendXcm = crate::xcm_config::XcmRouter; - type BrokerId = BrokerId; + type PalletId = OnDemandPalletId; } impl parachains_assigner_coretime::Config for Runtime {} From ef1174ba23be1667e8c291f41b77bf6e62465340 Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 11:07:36 +0000 Subject: [PATCH 08/67] Fix tests for on demand --- .../src/assigner_on_demand/tests.rs | 84 +++++++++++-------- .../src/assigner_on_demand/types.rs | 4 +- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 0eb55af0e96b..8d676db48b4b 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -17,7 +17,11 @@ use super::*; use crate::{ - assigner_on_demand::{mock_helpers::GenesisConfigBuilder, Error}, + assigner_on_demand::{ + mock_helpers::GenesisConfigBuilder, + types::{QueueIndex, ReverseQueueIndex}, + Error, + }, initializer::SessionChangeNotification, mock::{ new_test_ext, Balances, OnDemandAssigner, Paras, ParasShared, RuntimeOrigin, Scheduler, @@ -27,8 +31,11 @@ use crate::{ }; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; use pallet_balances::{Error as BalancesError, NegativeImbalance}; -use primitives::{BlockNumber, SessionIndex, ValidationCode}; -use sp_std::collections::btree_map::BTreeMap; +use primitives::{BlockNumber, SessionIndex, ValidationCode, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; +use sp_std::{ + cmp::{Ord, Ordering}, + collections::btree_map::BTreeMap, +}; fn schedule_blank_para(id: ParaId, parakind: ParaKind) { let validation_code: ValidationCode = vec![1, 2, 3].into(); @@ -708,38 +715,43 @@ fn queue_status_size_fn_works() { }); } -#[test] -fn add_revenue_info_works() { - let alice = 100u64; - let amt = 10_000_000u128; - new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { - Balances::make_free_balance_be(&alice, amt); - assert_eq!(Balances::total_issuance(), amt); - - // Revenue should be empty on block 0 - assert_eq!(Revenue::::get().len(), 0); - - // Mock assigner sets max revenue history to 10. - run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); - assert_eq!(Revenue::::get().len(), 10); - - // New revenue - let val: u128 = 1; - let imbalance = NegativeImbalance::new(val); - OnDemandAssigner::add_revenue_info(imbalance); - let rev = Revenue::::get(); - assert_eq!(rev.get(0).unwrap(), &val); - - let imbalance = NegativeImbalance::new(val); - OnDemandAssigner::add_revenue_info(imbalance); - let rev = Revenue::::get(); - assert_eq!(rev.get(0).unwrap(), &2); +//#[test] +//fn add_revenue_info_works() { +// let alice = 100u64; +// let amt = 10_000_000u128; +// new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { +// Balances::make_free_balance_be(&alice, amt); +// assert_eq!(Balances::total_issuance(), amt); +// +// // Revenue should be empty on block 0 +// assert_eq!(Revenue::::get().len(), 0); +// +// // Mock assigner sets max revenue history to 10. +// run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); +// assert_eq!(Revenue::::get().len(), 10); +// +// // New revenue +// let val: u128 = 1; +// let imbalance = NegativeImbalance::new(val); +// OnDemandAssigner::add_revenue_info(imbalance); +// let rev = Revenue::::get(); +// assert_eq!(rev.get(0).unwrap(), &val); +// +// let imbalance = NegativeImbalance::new(val); +// OnDemandAssigner::add_revenue_info(imbalance); +// let rev = Revenue::::get(); +// assert_eq!(rev.get(0).unwrap(), &2); +// +// // Should still be at 10 and the previous value should be +// // shifted from index 0 -> 1. +// run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); +// assert_eq!(Revenue::::get().len(), 10); +// let rev = Revenue::::get(); +// assert_eq!(rev.get(1).unwrap(), &2); +// }); +//} - // Should still be at 10 and the previous value should be - // shifted from index 0 -> 1. - run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); - assert_eq!(Revenue::::get().len(), 10); - let rev = Revenue::::get(); - assert_eq!(rev.get(1).unwrap(), &2); - }); +#[test] +fn get_revenue_info_works() { + new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| {}); } diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs index c0452c86fa75..017107d14e84 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs @@ -140,13 +140,13 @@ impl QueueStatusType { // NOTE: The `Ord` implementation for this type is unsound in the general case. // Do not use it for anything but it's intended purpose. #[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] -pub struct QueueIndex(u32); +pub struct QueueIndex(pub u32); /// QueueIndex with reverse ordering. /// /// Same as `Reverse(QueueIndex)`, but with all the needed traits implemented. #[derive(Encode, Decode, TypeInfo, Debug, PartialEq, Clone, Eq, Copy)] -pub struct ReverseQueueIndex(u32); +pub struct ReverseQueueIndex(pub u32); impl QueueIndex { fn reverse(self) -> ReverseQueueIndex { From 21f9657eafdaefb047f326516a7705586c977768 Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 11:08:17 +0000 Subject: [PATCH 09/67] Rework get_revenue --- .../parachains/src/assigner_on_demand/mod.rs | 7 +++-- .../runtime/parachains/src/coretime/mod.rs | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 4a48e74d3738..a413c684c8b2 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -51,11 +51,12 @@ use frame_support::{ ExistenceRequirement::{self, AllowDeath, KeepAlive}, Imbalance, OnUnbalanced, WithdrawReasons, }, + PalletId, }; use frame_system::pallet_prelude::*; use primitives::{CoreIndex, Id as ParaId}; use sp_runtime::{ - traits::{One, SaturatedConversion}, + traits::{One, SaturatedConversion, Zero}, FixedPointNumber, FixedPointOperand, FixedU128, Perbill, Saturating, }; use sp_std::prelude::*; @@ -601,13 +602,13 @@ where } pub fn get_revenue(now: BlockNumberFor, when: BlockNumberFor) -> BalanceOf { - let mut amount: BalanceOf = 0.into(); + let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { revenue.into_iter().enumerate().for_each(|(index, mut block_revenue)| { // if when >= now.saturating_sub((index as u32).into()) { amount.saturating_add(*block_revenue); - block_revenue = 0.into(); + *block_revenue = BalanceOf::::zero(); } }) }); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 179b72e4d6e9..48e414c30e0a 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -269,18 +269,25 @@ impl Pallet { // TODO actual revenue let revenue = >::get_revenue(now, when); - let message = Xcm(vec![ - Instruction::UnpaidExecution { - weight_limit: WeightLimit::Unlimited, - check_origin: None, + match TryInto::::try_into(revenue) { + Ok(raw_revenue) => { + let message = Xcm(vec![ + Instruction::UnpaidExecution { + weight_limit: WeightLimit::Unlimited, + check_origin: None, + }, + mk_coretime_call(CoretimeCalls::NotifyRevenue(raw_revenue)), + ]); + if let Err(err) = send_xcm::( + Location::new(0, [Junction::Parachain(T::BrokerId::get())]), + message, + ) { + log::error!("Sending `NotifyRevenue` to coretime chain failed: {:?}", err); + } + }, + Err(_err) => { + log::error!("Converting on demand revenue for `NotifyRevenue`failed"); }, - mk_coretime_call(CoretimeCalls::NotifyRevenue(revenue.inner())), - ]); - if let Err(err) = send_xcm::( - Location::new(0, [Junction::Parachain(T::BrokerId::get())]), - message, - ) { - log::error!("Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); } Ok(()) From 4d00c85f12b4fb9247a44ead43cc33d543d3945a Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 12:40:00 +0000 Subject: [PATCH 10/67] Add empty weight implementations --- .../coretime/coretime-rococo/src/weights/pallet_broker.rs | 3 +++ .../coretime/coretime-westend/src/weights/pallet_broker.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs index 2d30ddc612cb..fc3042399436 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs @@ -495,6 +495,9 @@ impl pallet_broker::WeightInfo for WeightInfo { .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } + fn notify_revenue() -> Weight { + todo!() + } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs index 8727b9633b1f..203baa6dfdc8 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs @@ -493,6 +493,9 @@ impl pallet_broker::WeightInfo for WeightInfo { .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } + fn notify_revenue() -> Weight { + todo!() + } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) From 8251ededf6976f78c626ba2d44a1bd7ee11e45bf Mon Sep 17 00:00:00 2001 From: antonva Date: Thu, 4 Apr 2024 12:40:29 +0000 Subject: [PATCH 11/67] Add revenueinbox for broker pallet --- substrate/frame/broker/src/dispatchable_impls.rs | 5 +++-- substrate/frame/broker/src/lib.rs | 2 +- substrate/frame/broker/src/types.rs | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index ee3df6b3a854..8f7752ae801b 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -16,12 +16,13 @@ // limitations under the License. use super::*; +use coretime_interface::CoretimeInterface; use frame_support::{ pallet_prelude::{DispatchResult, *}, traits::{fungible::Mutate, tokens::Preservation::Expendable, DefensiveResult}, }; use sp_arithmetic::traits::{CheckedDiv, Saturating, Zero}; -use sp_runtime::traits::Convert; +use sp_runtime::traits::{Convert, ConvertBack}; use CompletionStatus::{Complete, Partial}; impl Pallet { @@ -439,7 +440,7 @@ impl Pallet { } pub(crate) fn do_notify_revenue(amount: BalanceOf) -> DispatchResult { - RevenueInbox::::put(Some(amount)); + RevenueInbox::::put(amount); Ok(()) } } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index a9a5ed46b109..ff3634de1977 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -165,7 +165,7 @@ pub mod pallet { /// Received revenue info from the relay chain. #[pallet::storage] - pub type RevenueInbox = StorageValue<_, RelayBalanceOf, OptionQuery>; + pub type RevenueInbox = StorageValue<_, OnDemandRevenueRecord, OptionQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index 7e9f351723a5..5b71c7b44f3d 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -251,6 +251,12 @@ pub struct LeaseRecordItem { pub type LeasesRecord = BoundedVec; pub type LeasesRecordOf = LeasesRecord<::MaxLeasedCores>; +/// Record for On demand core sales. +/// +/// The blocknumber is the relay chain block height `when` the original request +/// for revenue was made. +pub type OnDemandRevenueRecord = BalanceOf; + /// Configuration of this pallet. #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct ConfigRecord { From 7dd6a34c415bb6bd6b3fd36043f93a24bf2d5b22 Mon Sep 17 00:00:00 2001 From: antonva Date: Wed, 17 Apr 2024 10:18:05 +0000 Subject: [PATCH 12/67] Add log target to coretime pallet --- polkadot/runtime/parachains/src/coretime/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index fcf48e744ab5..aadea762c6ba 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -38,6 +38,8 @@ use crate::{ mod benchmarking; pub mod migration; +const LOG_TARGET: &str = "runtime::parachains::coretime"; + pub trait WeightInfo { fn request_core_count() -> Weight; fn request_revenue_info_at() -> Weight; @@ -250,7 +252,7 @@ impl Pallet { Location::new(0, [Junction::Parachain(T::BrokerId::get())]), message, ) { - log::error!("Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); + log::error!(target: LOG_TARGET, "Sending `NotifyCoreCount` to coretime chain failed: {:?}", err); } } } @@ -284,11 +286,11 @@ impl Pallet { Location::new(0, [Junction::Parachain(T::BrokerId::get())]), message, ) { - log::error!("Sending `NotifyRevenue` to coretime chain failed: {:?}", err); + log::error!(target: LOG_TARGET, "Sending `NotifyRevenue` to coretime chain failed: {:?}", err); } }, Err(_err) => { - log::error!("Converting on demand revenue for `NotifyRevenue`failed"); + log::error!(target: LOG_TARGET, "Converting on demand revenue for `NotifyRevenue`failed"); }, } @@ -309,7 +311,7 @@ impl Pallet { Location::new(0, [Junction::Parachain(T::BrokerId::get())]), message, ) { - log::error!("Sending `SwapLeases` to coretime chain failed: {:?}", err); + log::error!(target: LOG_TARGET, "Sending `SwapLeases` to coretime chain failed: {:?}", err); } } } From d5d84e3b7ae0500ee2fe5de6857d17580fc720ff Mon Sep 17 00:00:00 2001 From: antonva Date: Wed, 17 Apr 2024 10:18:37 +0000 Subject: [PATCH 13/67] Fix coretime benchmarking --- polkadot/runtime/parachains/src/coretime/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index dba2051d26dc..d9d46a3eca92 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -38,7 +38,7 @@ mod benchmarks { _( root_origin as ::RuntimeOrigin, // TODO: Better when param - BlockNumberFor::::from(100), + BlockNumberFor::::from(100u32), ) } From aecc034dce1d972192ed6c56152c07501254da47 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 13:33:04 +0000 Subject: [PATCH 14/67] Remove check notify revenue info --- .../coretime/coretime-rococo/src/coretime.rs | 16 ----------- .../src/weights/pallet_broker.rs | 4 ++- .../coretime/coretime-westend/src/coretime.rs | 16 ----------- substrate/bin/node/runtime/src/lib.rs | 13 --------- .../frame/broker/src/coretime_interface.rs | 28 ++----------------- 5 files changed, 6 insertions(+), 71 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 742dd50f6fa1..68a5b3d748e0 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -68,11 +68,6 @@ parameter_types! { pub const BrokerPalletId: PalletId = PalletId(*b"py/broke"); } -parameter_types! { - pub storage CoreCount: Option = None; - pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None; -} - /// Type that implements the `CoretimeInterface` for the allocation of Coretime. Meant to operate /// from the parachain context. That is, the parachain provides a market (broker) for the sale of /// coretime, but assumes a `CoretimeProvider` (i.e. a Relay Chain) to actually provide cores. @@ -204,17 +199,6 @@ impl CoretimeInterface for CoretimeAllocator { ), } } - - fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { - let revenue = CoretimeRevenue::get(); - CoretimeRevenue::set(&None); - revenue - } - - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(when: RCBlockNumberOf, revenue: Self::Balance) { - CoretimeRevenue::set(&Some((when, revenue))); - } } impl pallet_broker::Config for Runtime { diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs index d6370d1815e6..b700250aeb7d 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs @@ -492,7 +492,9 @@ impl pallet_broker::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().writes(1)) } fn notify_revenue() -> Weight { - todo!() + Weight::from_parts(1_904_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 41cbc62fa211..0bb3c4c0aa2e 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -68,11 +68,6 @@ parameter_types! { pub const BrokerPalletId: PalletId = PalletId(*b"py/broke"); } -parameter_types! { - pub storage CoreCount: Option = None; - pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None; -} - /// Type that implements the `CoretimeInterface` for the allocation of Coretime. Meant to operate /// from the parachain context. That is, the parachain provides a market (broker) for the sale of /// coretime, but assumes a `CoretimeProvider` (i.e. a Relay Chain) to actually provide cores. @@ -216,17 +211,6 @@ impl CoretimeInterface for CoretimeAllocator { ), } } - - fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { - let revenue = CoretimeRevenue::get(); - CoretimeRevenue::set(&None); - revenue - } - - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(when: RCBlockNumberOf, revenue: Self::Balance) { - CoretimeRevenue::set(&Some((when, revenue))); - } } impl pallet_broker::Config for Runtime { diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 191244c3bb06..b7549661f218 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2045,10 +2045,6 @@ impl OnUnbalanced> for IntoAuthor { } } -parameter_types! { - pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None; -} - pub struct CoretimeProvider; impl CoretimeInterface for CoretimeProvider { type AccountId = AccountId; @@ -2064,15 +2060,6 @@ impl CoretimeInterface for CoretimeProvider { _end_hint: Option, ) { } - fn check_notify_revenue_info() -> Option<(u32, Self::Balance)> { - let revenue = CoretimeRevenue::get(); - CoretimeRevenue::set(&None); - revenue - } - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(when: u32, revenue: Self::Balance) { - CoretimeRevenue::set(&Some((when, revenue))); - } } impl pallet_broker::Config for Runtime { diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 58efa7fa92bb..58ad4c0906a1 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -17,13 +17,13 @@ #![deny(missing_docs)] -use codec::{Decode, Encode, MaxEncodedLen}; +use codec::{Codec, Decode, Encode, MaxEncodedLen}; use frame_support::Parameter; use scale_info::TypeInfo; use sp_arithmetic::traits::AtLeast32BitUnsigned; use sp_core::RuntimeDebug; use sp_runtime::traits::BlockNumberProvider; -use sp_std::vec::Vec; +use sp_std::{fmt::Debug, vec::Vec}; /// Index of a Polkadot Core. pub type CoreIndex = u16; @@ -62,7 +62,7 @@ pub trait CoretimeInterface { type AccountId: Parameter; /// A (Relay-chain-side) balance. - type Balance: AtLeast32BitUnsigned; + type Balance: AtLeast32BitUnsigned + Codec + MaxEncodedLen + TypeInfo + Debug; /// A provider for the relay chain block number. type RelayChainBlockNumberProvider: BlockNumberProvider; @@ -106,23 +106,6 @@ pub trait CoretimeInterface { assignment: Vec<(CoreAssignment, PartsOf57600)>, end_hint: Option>, ); - - /// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain - /// block number `last_until` to `until`, not including `until` itself. `last_until` is defined - /// as being the `until` argument of the last `notify_revenue` message sent, or zero for the - /// first call. If `revenue` is `None`, this indicates that the information is no longer - /// available. - /// - /// This explicitly disregards the possibility of multiple parachains requesting and being - /// notified of revenue information. The Relay-chain must be configured to ensure that only a - /// single revenue information destination exists. - fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)>; - - /// Ensure that revenue information is updated to the provided value. - /// - /// This is only used for benchmarking. - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(when: RCBlockNumberOf, revenue: Self::Balance); } impl CoretimeInterface for () { @@ -140,9 +123,4 @@ impl CoretimeInterface for () { _end_hint: Option>, ) { } - fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { - None - } - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } From 1f9a4de6f13a73089d2f57bc4d12f116c47cf6f2 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 13:36:11 +0000 Subject: [PATCH 15/67] Update broker pallet for revenue info --- .../rococo/src/weights/runtime_parachains_coretime.rs | 5 ++++- substrate/frame/broker/src/dispatchable_impls.rs | 6 +++--- substrate/frame/broker/src/lib.rs | 9 ++++++--- substrate/frame/broker/src/tick_impls.rs | 4 +++- substrate/frame/broker/src/types.rs | 11 ++++++++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs index 7b6604a7b46e..aec64a93bfd1 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs @@ -70,5 +70,8 @@ impl runtime_parachains::coreti .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - fn request_revenue_info_at() -> frame_support::weights::Weight { todo!() } + fn request_revenue_info_at() -> frame_support::weights::Weight { + ::WeightInfo::set_config_with_u32() + } + } diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 8939b99792be..c365c91b14e0 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -22,7 +22,7 @@ use frame_support::{ traits::{fungible::Mutate, tokens::Preservation::Expendable, DefensiveResult}, }; use sp_arithmetic::traits::{CheckedDiv, Saturating, Zero}; -use sp_runtime::traits::{Convert, ConvertBack}; +use sp_runtime::traits::Convert; use CompletionStatus::{Complete, Partial}; impl Pallet { @@ -439,8 +439,8 @@ impl Pallet { Ok(()) } - pub(crate) fn do_notify_revenue(amount: BalanceOf) -> DispatchResult { - RevenueInbox::::put(amount); + pub(crate) fn do_notify_revenue(revenue: OnDemandRevenueRecordOf) -> DispatchResult { + RevenueInbox::::put(revenue); Ok(()) } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index fd4dc9f8ccf3..953d90efc40b 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -165,7 +165,7 @@ pub mod pallet { /// Received revenue info from the relay chain. #[pallet::storage] - pub type RevenueInbox = StorageValue<_, OnDemandRevenueRecord, OptionQuery>; + pub type RevenueInbox = StorageValue<_, OnDemandRevenueRecordOf, OptionQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -793,9 +793,12 @@ pub mod pallet { #[pallet::call_index(20)] #[pallet::weight(T::WeightInfo::notify_revenue())] - pub fn notify_revenue(origin: OriginFor, amount: BalanceOf) -> DispatchResult { + pub fn notify_revenue( + origin: OriginFor, + revenue: OnDemandRevenueRecordOf, + ) -> DispatchResult { T::AdminOrigin::ensure_origin_or_root(origin)?; - Self::do_notify_revenue(amount)?; + Self::do_notify_revenue(revenue)?; Ok(()) } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 388370bce4d4..903897a57382 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -96,7 +96,9 @@ impl Pallet { } pub(crate) fn process_revenue() -> bool { - let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { return false }; + let Some(OnDemandRevenueRecord { until, amount }) = RevenueInbox::::take() else { + return false + }; let when: Timeslice = (until / T::TimeslicePeriod::get()).saturating_sub(One::one()).saturated_into(); let mut revenue = T::ConvertBalance::convert_back(amount); diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index 4757c5f27c3a..5aaa4f6dcb10 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -255,7 +255,16 @@ pub type LeasesRecordOf = LeasesRecord<::MaxLeasedCores>; /// /// The blocknumber is the relay chain block height `when` the original request /// for revenue was made. -pub type OnDemandRevenueRecord = BalanceOf; +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct OnDemandRevenueRecord { + /// The height of the Relay-chain at the time the revenue request was made. + pub until: RelayBlockNumber, + /// The accumulated balance of on demand sales made on the relay chain. + pub amount: RelayBalance, +} + +pub type OnDemandRevenueRecordOf = + OnDemandRevenueRecord, RelayBalanceOf>; /// Configuration of this pallet. #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] From 6879dd7f9ca86d6713d945997d1417bd17610ee8 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 13:36:52 +0000 Subject: [PATCH 16/67] Remove negative imbalance shorthand --- polkadot/runtime/parachains/src/assigner_on_demand/types.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs index 017107d14e84..07a2ff86dabf 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/types.rs @@ -33,11 +33,6 @@ use sp_std::{ pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -/// Shorthand for the NegativeImbalance type the runtime is using. -pub type NegativeImbalanceOf = <::Currency as Currency< - ::AccountId, ->>::NegativeImbalance; - /// Meta data for full queue. /// /// This includes elements with affinity and free entries. From 7a1f198306abdc4d6005b199c34b81fc3d6f3180 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 13:38:00 +0000 Subject: [PATCH 17/67] Update revenue info calls --- .../parachains/src/assigner_on_demand/mod.rs | 82 ++++++++++-------- .../src/assigner_on_demand/tests.rs | 84 +++++++++++++++---- .../runtime/parachains/src/coretime/mod.rs | 29 +++---- 3 files changed, 127 insertions(+), 68 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 7e3c873a6645..fa03820d8b23 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -49,20 +49,20 @@ use frame_support::{ traits::{ Currency, ExistenceRequirement::{self, AllowDeath, KeepAlive}, - Imbalance, OnUnbalanced, WithdrawReasons, + WithdrawReasons, }, PalletId, }; use frame_system::pallet_prelude::*; use primitives::{CoreIndex, Id as ParaId}; use sp_runtime::{ - traits::{One, SaturatedConversion, Zero}, + traits::{AccountIdConversion, One, SaturatedConversion, Zero}, FixedPointNumber, FixedPointOperand, FixedU128, Perbill, Saturating, }; use sp_std::prelude::*; use types::{ - BalanceOf, CoreAffinityCount, EnqueuedOrder, NegativeImbalanceOf, QueuePushDirection, - QueueStatusType, SpotTrafficCalculationErr, + BalanceOf, CoreAffinityCount, EnqueuedOrder, QueuePushDirection, QueueStatusType, + SpotTrafficCalculationErr, }; const LOG_TARGET: &str = "runtime::parachains::assigner-on-demand"; @@ -200,9 +200,17 @@ pub mod pallet { impl Hooks> for Pallet { fn on_initialize(_now: BlockNumberFor) -> Weight { // Update revenue information storage. - let zero_balance: BalanceOf = 0u32.into(); Revenue::::mutate(|revenue| { - let _ = revenue.force_insert_keep_left(0, zero_balance); + match revenue.force_insert_keep_left(0, 0u32.into()) { + Ok(_) => (), + Err(e) => { + // Defensive, should not fail. + log::debug!( + target: LOG_TARGET, + "Error updating historical revenue: {:?}", e + ); + }, + } }); let config = >::config(); @@ -385,19 +393,22 @@ where // Is the current price higher than `max_amount` ensure!(spot_price.le(&max_amount), Error::::SpotPriceHigherThanMaxAmount); - // Charge the sending account the spot price. The imbalance is handled by this pallet's - // `OnUnbalanced` trait implementation and added to the revenue information. - let _ = T::Currency::withdraw( - &sender, - spot_price, - WithdrawReasons::FEE, - existence_requirement, - )?; - ensure!( queue_status.size() < config.scheduler_params.on_demand_queue_max_size, Error::::QueueFull ); + + // Charge the sending account the spot price. The amount will be burnt once the + // broker chain requests revenue information. + T::Currency::transfer(&sender, &Self::account_id(), spot_price, existence_requirement)?; + + // Add the amount to the current block's (index 0) revenue information. + Revenue::::mutate(|bounded_revenue| { + if let Some(current_block) = bounded_revenue.get_mut(0) { + *current_block = current_block.saturating_add(spot_price); + } + }); + Pallet::::add_on_demand_order(queue_status, para_id, QueuePushDirection::Back); Ok(()) }) @@ -601,20 +612,32 @@ where }) } - pub fn get_revenue(now: BlockNumberFor, when: BlockNumberFor) -> BalanceOf { + /// Collect the revenue from the `when` blockheight + pub fn revenue_until(now: BlockNumberFor, when: BlockNumberFor) -> BalanceOf { let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { - revenue.into_iter().enumerate().for_each(|(index, mut block_revenue)| { - // + revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { if when >= now.saturating_sub((index as u32).into()) { - amount.saturating_add(*block_revenue); + amount = amount.saturating_add(*block_revenue); *block_revenue = BalanceOf::::zero(); } }) }); + + let imbalance = T::Currency::burn(amount); + let _ = T::Currency::settle( + &Self::account_id(), + imbalance, + WithdrawReasons::FEE, + ExistenceRequirement::AllowDeath, + ); amount } + pub fn account_id() -> T::AccountId { + T::PalletId::get().into_account_truncating() + } + /// Getter for the affinity tracker. #[cfg(test)] fn get_affinity_map(para_id: ParaId) -> Option { @@ -656,24 +679,9 @@ where fn get_traffic_default_value() -> FixedU128 { ::TrafficDefaultValue::get() } -} -/// Add all negative imbalance dropped to the historical on demand revenue. -impl OnUnbalanced> for Pallet { - fn on_nonzero_unbalanced(amount: NegativeImbalanceOf) { - let numeric_amount = amount.peek(); - - // Add the amount to the current block's revenue information. - Revenue::::mutate(|revenue| { - let current_revenue = revenue.get_mut(0); - current_revenue.map(|rev| { - let new_revenue = rev.saturating_add(numeric_amount); - *rev = new_revenue; - }) - }); - - // NOTE: The tokens could be burned at this point, but are kept in total issuance - // and teleported (burnt on the relay chain) to the broker chain when it requests - // revenue information. + #[cfg(test)] + fn get_revenue() -> Vec> { + Revenue::::get().to_vec() } } diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 8d676db48b4b..affd85d2c9ca 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -88,16 +88,26 @@ fn run_to_block( } } -fn place_order(para_id: ParaId) { +fn place_order_run_to_blocknumber(para_id: ParaId, blocknumber: Option) { let alice = 100u64; let amt = 10_000_000u128; Balances::make_free_balance_be(&alice, amt); - run_to_block(101, |n| if n == 101 { Some(Default::default()) } else { None }); + if let Some(bn) = blocknumber { + run_to_block(bn, |n| if n == bn { Some(Default::default()) } else { None }); + } OnDemandAssigner::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id).unwrap() } +fn place_order_run_to_101(para_id: ParaId) { + place_order_run_to_blocknumber(para_id, Some(101)); +} + +fn place_order(para_id: ParaId) { + place_order_run_to_blocknumber(para_id, None); +} + #[test] fn spot_traffic_capacity_zero_returns_none() { match OnDemandAssigner::calculate_spot_traffic( @@ -349,8 +359,8 @@ fn pop_assignment_for_core_works() { // Add enough assignments to the order queue. for _ in 0..2 { - place_order(para_a); - place_order(para_b); + place_order_run_to_101(para_a); + place_order_run_to_101(para_b); } // Popped assignments should be for the correct paras and cores @@ -384,8 +394,8 @@ fn push_back_assignment_works() { run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); // Add enough assignments to the order queue. - place_order(para_a); - place_order(para_b); + place_order_run_to_101(para_a); + place_order_run_to_101(para_b); // Pop order a assert_eq!( @@ -431,9 +441,9 @@ fn affinity_prohibits_parallel_scheduling() { assert!(OnDemandAssigner::get_affinity_map(para_b).is_none()); // Add 2 assignments for para_a for every para_b. - place_order(para_a); - place_order(para_a); - place_order(para_b); + place_order_run_to_101(para_a); + place_order_run_to_101(para_a); + place_order_run_to_101(para_b); // Approximate having 1 core. for _ in 0..3 { @@ -455,9 +465,9 @@ fn affinity_prohibits_parallel_scheduling() { OnDemandAssigner::report_processed(para_b, 0.into()); // Add 2 assignments for para_a for every para_b. - place_order(para_a); - place_order(para_a); - place_order(para_b); + place_order_run_to_101(para_a); + place_order_run_to_101(para_a); + place_order_run_to_101(para_b); // Approximate having 3 cores. CoreIndex 2 should be unable to obtain an assignment for _ in 0..3 { @@ -497,7 +507,7 @@ fn affinity_changes_work() { // Add enough assignments to the order queue. for _ in 0..10 { - place_order(para_a); + place_order_run_to_101(para_a); } // There should be no affinity before the scheduler pops. @@ -561,7 +571,7 @@ fn new_affinity_for_a_core_must_come_from_free_entries() { // Place orders for all chains. parachains.iter().for_each(|chain| { - place_order(*chain); + place_order_run_to_101(*chain); }); // There are 4 entries in free_entries. @@ -686,8 +696,8 @@ fn queue_status_size_fn_works() { // Place orders for all chains. parachains.iter().for_each(|chain| { // 2 per chain for a total of 6 - place_order(*chain); - place_order(*chain); + place_order_run_to_101(*chain); + place_order_run_to_101(*chain); }); // 6 orders in free entries @@ -753,5 +763,45 @@ fn queue_status_size_fn_works() { #[test] fn get_revenue_info_works() { - new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| {}); + new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { + let para_a = ParaId::from(111); + schedule_blank_para(para_a, ParaKind::Parathread); + // Mock assigner sets max revenue history to 10. + run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); + let revenue = OnDemandAssigner::revenue_until(10, 10); + + // No revenue should be recorded. + assert_eq!(revenue, 0); + + // Place one order + place_order_run_to_blocknumber(para_a, Some(11)); + let revenue = OnDemandAssigner::get_revenue(); + let amt = OnDemandAssigner::revenue_until(11, 11); + + // Revenue for a single order should be recorded. + assert_eq!(amt, revenue[0]); + + run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); + let revenue = OnDemandAssigner::revenue_until(12, 12); + + // No revenue should be recorded. + assert_eq!(revenue, 0); + + // Place many orders + place_order(para_a); + place_order(para_a); + + run_to_block(13, |n| if n == 13 { Some(Default::default()) } else { None }); + + place_order(para_a); + + run_to_block(14, |n| if n == 14 { Some(Default::default()) } else { None }); + + println!("{:?}", OnDemandAssigner::get_revenue()); + let revenue = OnDemandAssigner::revenue_until(14, 14); + println!("{:?}", OnDemandAssigner::get_revenue()); + + // All 3 orders should be + assert_eq!(revenue, 30_000); + }); } diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index aadea762c6ba..6b80044c199f 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -18,14 +18,13 @@ //! //! -use sp_std::{prelude::*, result}; - use frame_support::{pallet_prelude::*, traits::Currency}; use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_broker::{CoreAssignment, CoreIndex as BrokerCoreIndex}; -use primitives::{Balance, CoreIndex, Id as ParaId}; +use primitives::{Balance, BlockNumber, CoreIndex, Id as ParaId}; use sp_arithmetic::traits::SaturatedConversion; +use sp_std::{prelude::*, result}; use xcm::v4::{send_xcm, Instruction, Junction, Location, OriginKind, SendXcm, WeightLimit, Xcm}; use crate::{ @@ -91,13 +90,14 @@ enum CoretimeCalls { #[codec(index = 19)] NotifyCoreCount(u16), #[codec(index = 20)] - NotifyRevenue(Balance), + NotifyRevenue((BlockNumber, Balance)), #[codec(index = 99)] SwapLeases(ParaId, ParaId), } #[frame_support::pallet] pub mod pallet { + use crate::configuration; use super::*; @@ -165,10 +165,7 @@ pub mod pallet { /// may be `None``. #[pallet::weight(::WeightInfo::request_revenue_info_at())] #[pallet::call_index(2)] - pub fn request_revenue_info_at( - origin: OriginFor, - when: BlockNumberFor, - ) -> DispatchResult { + pub fn request_revenue_info_at(origin: OriginFor, when: BlockNumber) -> DispatchResult { // Ignore requests not coming from the broker parachain or root. Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; Self::notify_revenue(when) @@ -266,27 +263,31 @@ impl Pallet { /// /// The Relay-chain must be configured to ensure that only a single revenue information /// destination exists. - pub fn notify_revenue(when: BlockNumberFor) -> DispatchResult { + pub fn notify_revenue(when: BlockNumber) -> DispatchResult { let now = >::block_number(); + let when_bnf: BlockNumberFor = when.into(); + // When cannot be in the future. - ensure!(when <= now, Error::::RequestedFutureRevenue); + ensure!(when_bnf <= now, Error::::RequestedFutureRevenue); - // TODO actual revenue - let revenue = >::get_revenue(now, when); + let revenue = >::revenue_until(now, when_bnf); + log::info!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); match TryInto::::try_into(revenue) { Ok(raw_revenue) => { + log::info!(target: LOG_TARGET, "Revenue into balance success: {:?}", raw_revenue); let message = Xcm(vec![ Instruction::UnpaidExecution { weight_limit: WeightLimit::Unlimited, check_origin: None, }, - mk_coretime_call(CoretimeCalls::NotifyRevenue(raw_revenue)), + mk_coretime_call(CoretimeCalls::NotifyRevenue((when, raw_revenue))), ]); if let Err(err) = send_xcm::( Location::new(0, [Junction::Parachain(T::BrokerId::get())]), message, ) { - log::error!(target: LOG_TARGET, "Sending `NotifyRevenue` to coretime chain failed: {:?}", err); + log::error!(target: LOG_TARGET, "Sending `NotifyRevenue` to coretime chain failed: {:?}", + err); } }, Err(_err) => { From c7d586d832edaf30aa7cb9cfba4c1c334ff3f34a Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 14:24:55 +0000 Subject: [PATCH 18/67] Remove unused imports --- .../runtimes/coretime/coretime-rococo/src/coretime.rs | 2 +- .../runtimes/coretime/coretime-westend/src/coretime.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 68a5b3d748e0..e2f0fe3d944b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -26,7 +26,7 @@ use frame_support::{ }, }; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; -use parachains_common::{AccountId, Balance, BlockNumber}; +use parachains_common::{AccountId, Balance}; use xcm::latest::prelude::*; pub struct CreditToCollatorPot; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 0bb3c4c0aa2e..138ad412d4e5 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -26,7 +26,7 @@ use frame_support::{ }, }; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; -use parachains_common::{AccountId, Balance, BlockNumber}; +use parachains_common::{AccountId, Balance}; use xcm::latest::prelude::*; pub struct CreditToCollatorPot; From 74c88b1bd18ca457a33b2f98d0dd0f8c10f6b590 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 15:18:49 +0000 Subject: [PATCH 19/67] Fix benchmarks --- .../runtime/parachains/src/coretime/benchmarking.rs | 2 +- substrate/frame/broker/src/benchmarking.rs | 10 ++++++---- substrate/frame/broker/src/coretime_interface.rs | 4 ++-- substrate/frame/broker/src/mock.rs | 12 +++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index d9d46a3eca92..8a0f4aff50b9 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -38,7 +38,7 @@ mod benchmarks { _( root_origin as ::RuntimeOrigin, // TODO: Better when param - BlockNumberFor::::from(100u32), + 100u32, ) } diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 98ac074ca917..8049123b455a 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -54,6 +54,10 @@ fn new_config_record() -> ConfigRecordOf { } } +fn new_revenue() -> OnDemandRevenueRecordOf { + OnDemandRevenueRecord { until: 2u32.into(), amount: 10u32.into() } +} + fn new_schedule() -> Schedule { // Max items for worst case let mut items = Vec::new(); @@ -734,10 +738,8 @@ mod benches { let timeslice_period: u32 = T::TimeslicePeriod::get().try_into().ok().unwrap(); let multiplicator = 5; - ::ensure_notify_revenue_info( - (timeslice_period * multiplicator).into(), - 10u32.into(), - ); + + RevenueInbox::::put(new_revenue::()); let timeslice = multiplicator - 1; InstaPoolHistory::::insert( diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 58ad4c0906a1..eda64840a55f 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -17,7 +17,7 @@ #![deny(missing_docs)] -use codec::{Codec, Decode, Encode, MaxEncodedLen}; +use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}; use frame_support::Parameter; use scale_info::TypeInfo; use sp_arithmetic::traits::AtLeast32BitUnsigned; @@ -62,7 +62,7 @@ pub trait CoretimeInterface { type AccountId: Parameter; /// A (Relay-chain-side) balance. - type Balance: AtLeast32BitUnsigned + Codec + MaxEncodedLen + TypeInfo + Debug; + type Balance: AtLeast32BitUnsigned + Encode + Decode + MaxEncodedLen + TypeInfo + Debug; /// A provider for the relay chain block number. type RelayChainBlockNumberProvider: BlockNumberProvider; diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index c7205058c972..db5ce785049c 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -125,14 +125,8 @@ impl CoretimeInterface for TestCoretimeProvider { ); CoretimeTrace::mutate(|v| v.push(item)); } - fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { - NotifyRevenueInfo::mutate(|s| s.pop()).map(|v| (v.0 as _, v.1)) - } - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_revenue_info(when: RCBlockNumberOf, revenue: Self::Balance) { - NotifyRevenueInfo::mutate(|s| s.push((when as u32, revenue))); - } } + impl TestCoretimeProvider { pub fn spend_instantaneous(who: u64, price: u64) -> Result<(), ()> { let mut c = CoretimeCredit::get(); @@ -239,6 +233,10 @@ pub fn new_config() -> ConfigRecordOf { } } +pub fn new_revenue() -> OnDemandRevenueRecordOf { + OnDemandRevenueRecord { until: 2, amount: 10 } +} + pub struct TestExt(ConfigRecordOf); #[allow(dead_code)] impl TestExt { From aa137da7c3848626063f7b16f7cf0e2221788d36 Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 19 Apr 2024 16:58:29 +0000 Subject: [PATCH 20/67] Fix tests --- .../runtime/parachains/src/assigner_on_demand/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index aadb1816e507..c73c1ade4f83 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -400,7 +400,14 @@ where // Charge the sending account the spot price. The amount will be burnt once the // broker chain requests revenue information. - T::Currency::transfer(&sender, &Self::account_id(), spot_price, existence_requirement)?; + let amt = T::Currency::withdraw( + &sender, + spot_price, + WithdrawReasons::FEE, + existence_requirement, + )?; + // Consume the negative imbalance and deposit it into the pallet account. + T::Currency::resolve_creating(&Self::account_id(), amt); // Add the amount to the current block's (index 0) revenue information. Revenue::::mutate(|bounded_revenue| { From f255e47b49c4a2eb93d4d8bb842d410f7bdb491a Mon Sep 17 00:00:00 2001 From: antonva Date: Tue, 23 Apr 2024 10:29:30 +0000 Subject: [PATCH 21/67] Update revenue_until fn --- .../parachains/src/assigner_on_demand/mod.rs | 3 +- .../src/assigner_on_demand/tests.rs | 58 +++++-------------- .../runtime/parachains/src/coretime/mod.rs | 2 +- 3 files changed, 17 insertions(+), 46 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index c73c1ade4f83..bc4802be0746 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -620,7 +620,8 @@ where } /// Collect the revenue from the `when` blockheight - pub fn revenue_until(now: BlockNumberFor, when: BlockNumberFor) -> BalanceOf { + pub fn revenue_until(when: BlockNumberFor) -> BalanceOf { + let now = >::block_number(); let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index affd85d2c9ca..a3220cf7417b 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -725,50 +725,14 @@ fn queue_status_size_fn_works() { }); } -//#[test] -//fn add_revenue_info_works() { -// let alice = 100u64; -// let amt = 10_000_000u128; -// new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { -// Balances::make_free_balance_be(&alice, amt); -// assert_eq!(Balances::total_issuance(), amt); -// -// // Revenue should be empty on block 0 -// assert_eq!(Revenue::::get().len(), 0); -// -// // Mock assigner sets max revenue history to 10. -// run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); -// assert_eq!(Revenue::::get().len(), 10); -// -// // New revenue -// let val: u128 = 1; -// let imbalance = NegativeImbalance::new(val); -// OnDemandAssigner::add_revenue_info(imbalance); -// let rev = Revenue::::get(); -// assert_eq!(rev.get(0).unwrap(), &val); -// -// let imbalance = NegativeImbalance::new(val); -// OnDemandAssigner::add_revenue_info(imbalance); -// let rev = Revenue::::get(); -// assert_eq!(rev.get(0).unwrap(), &2); -// -// // Should still be at 10 and the previous value should be -// // shifted from index 0 -> 1. -// run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); -// assert_eq!(Revenue::::get().len(), 10); -// let rev = Revenue::::get(); -// assert_eq!(rev.get(1).unwrap(), &2); -// }); -//} - #[test] -fn get_revenue_info_works() { +fn revenue_information_fetching_works() { new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { let para_a = ParaId::from(111); schedule_blank_para(para_a, ParaKind::Parathread); // Mock assigner sets max revenue history to 10. run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(10, 10); + let revenue = OnDemandAssigner::revenue_until(10); // No revenue should be recorded. assert_eq!(revenue, 0); @@ -776,13 +740,13 @@ fn get_revenue_info_works() { // Place one order place_order_run_to_blocknumber(para_a, Some(11)); let revenue = OnDemandAssigner::get_revenue(); - let amt = OnDemandAssigner::revenue_until(11, 11); + let amt = OnDemandAssigner::revenue_until(11); // Revenue for a single order should be recorded. assert_eq!(amt, revenue[0]); run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(12, 12); + let revenue = OnDemandAssigner::revenue_until(12); // No revenue should be recorded. assert_eq!(revenue, 0); @@ -797,11 +761,17 @@ fn get_revenue_info_works() { run_to_block(14, |n| if n == 14 { Some(Default::default()) } else { None }); - println!("{:?}", OnDemandAssigner::get_revenue()); - let revenue = OnDemandAssigner::revenue_until(14, 14); - println!("{:?}", OnDemandAssigner::get_revenue()); + let revenue = OnDemandAssigner::revenue_until(14); - // All 3 orders should be + // All 3 orders should be accounted for. assert_eq!(revenue, 30_000); + + // Place one order + place_order_run_to_blocknumber(para_a, Some(16)); + + let revenue = OnDemandAssigner::revenue_until(15); + + // Order is not in range of the revenue_until call + assert_eq!(revenue, 0); }); } diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 6b80044c199f..23d173447e60 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -270,7 +270,7 @@ impl Pallet { // When cannot be in the future. ensure!(when_bnf <= now, Error::::RequestedFutureRevenue); - let revenue = >::revenue_until(now, when_bnf); + let revenue = >::revenue_until(when_bnf); log::info!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); match TryInto::::try_into(revenue) { Ok(raw_revenue) => { From a6be112813dc5798c5a09d44cd08a8d481d81ada Mon Sep 17 00:00:00 2001 From: antonva Date: Fri, 26 Apr 2024 11:29:38 +0000 Subject: [PATCH 22/67] Remove unused imports --- substrate/frame/broker/src/coretime_interface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index eda64840a55f..650920729e56 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -17,7 +17,7 @@ #![deny(missing_docs)] -use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen}; +use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::Parameter; use scale_info::TypeInfo; use sp_arithmetic::traits::AtLeast32BitUnsigned; From f8da2cd4e9bf029be816ec3b6400786278116d3f Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 25 May 2024 13:27:28 +0200 Subject: [PATCH 23/67] Adress minor discussions --- polkadot/runtime/parachains/src/assigner_on_demand/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index bc4802be0746..51227469b420 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -220,8 +220,9 @@ pub mod pallet { Self::update_spot_traffic(&config, queue_status); }); - // 2 reads in config and queuestatus, at maximum 1 write to queuestatus. - T::DbWeight::get().reads_writes(2, 1) + // Reads: `Revenue`, `ActiveConfig`, `QueueStatus` + // Writes: `Revenue`, `QueueStatus` + T::DbWeight::get().reads_writes(3, 2) } } @@ -357,7 +358,7 @@ where /// Helper function for `place_order_*` calls. Used to differentiate between placing orders /// with a keep alive check or to allow the account to be reaped. The amount charged is - /// burnt from the `Currency` and stored to + /// burnt from the `Currency` and stored to the pallet account. /// /// Parameters: /// - `sender`: The sender of the call, funds will be withdrawn from this account. From 2e0e3ef1d8794a96fb135778d51a45b14d180020 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 25 May 2024 14:32:26 +0200 Subject: [PATCH 24/67] Fix revenue calculation --- polkadot/runtime/parachains/src/assigner_on_demand/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 4a9c9bf51274..3624471bbd9d 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -626,7 +626,7 @@ where let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { - if when >= now.saturating_sub((index as u32).into()) { + if when > now.saturating_sub((index as u32).into()) { amount = amount.saturating_add(*block_revenue); *block_revenue = BalanceOf::::zero(); } From 0f6a2bafaa8311824c793d57b557a1ab9ffec141 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sun, 26 May 2024 12:55:58 +0200 Subject: [PATCH 25/67] Propose different implementation of revenue reporting --- .../runtime/parachains/src/assigner_on_demand/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 3624471bbd9d..541d80ce187a 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -625,6 +625,18 @@ where let now = >::block_number(); let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { + // + // TODO: Proposed implementation, decide which is better + // + // while !revenue.is_empty() { + // let index = (revenue.len() - 1) as u32; + // if when > now.saturating_sub(index.into()) { + // amount = amount.saturating_add(revenue.pop().expect("Checked to contain at least one element; qed")); + // } else { + // break + // } + // } + revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { if when > now.saturating_sub((index as u32).into()) { amount = amount.saturating_add(*block_revenue); From af899e2def779ca48df65194d0a8b2b92d52683c Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sun, 26 May 2024 12:56:17 +0200 Subject: [PATCH 26/67] Minor fix --- polkadot/runtime/parachains/src/coretime/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 793f8c591cd5..2a03b117b582 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -293,7 +293,7 @@ impl Pallet { weight_limit: WeightLimit::Unlimited, check_origin: None, }, - mk_coretime_call(CoretimeCalls::NotifyRevenue((when, raw_revenue))), + mk_coretime_call::(CoretimeCalls::NotifyRevenue((when, raw_revenue))), ]); if let Err(err) = send_xcm::( Location::new(0, [Junction::Parachain(T::BrokerId::get())]), From f1b9000a1a76ba743acb806e7f448e1c1bdf9dc2 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sun, 26 May 2024 13:04:29 +0200 Subject: [PATCH 27/67] Rename call --- polkadot/runtime/parachains/src/coretime/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 2a03b117b582..0506d063713e 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -43,7 +43,7 @@ const LOG_TARGET: &str = "runtime::parachains::coretime"; pub trait WeightInfo { fn request_core_count() -> Weight; - fn request_revenue_info_at() -> Weight; + fn request_revenue_at() -> Weight; //fn credit_account() -> Weight; fn assign_core(s: u32) -> Weight; } @@ -55,7 +55,7 @@ impl WeightInfo for TestWeightInfo { fn request_core_count() -> Weight { Weight::MAX } - fn request_revenue_info_at() -> Weight { + fn request_revenue_at() -> Weight { Weight::MAX } // TODO: Add real benchmarking functionality for each of these to @@ -176,9 +176,9 @@ pub mod pallet { /// In the case that the request cannot be serviced because when is too old a block /// then a `notify_revenue`` message must still be returned, but its `revenue` field /// may be `None``. - #[pallet::weight(::WeightInfo::request_revenue_info_at())] + #[pallet::weight(::WeightInfo::request_revenue_at())] #[pallet::call_index(2)] - pub fn request_revenue_info_at(origin: OriginFor, when: BlockNumber) -> DispatchResult { + pub fn request_revenue_at(origin: OriginFor, when: BlockNumber) -> DispatchResult { // Ignore requests not coming from the broker parachain or root. Self::ensure_root_or_para(origin, ::BrokerId::get().into())?; Self::notify_revenue(when) From 65af55c1358935643be61c1b14f633cad6a38c54 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 29 May 2024 10:42:58 +0200 Subject: [PATCH 28/67] Fix weights --- .../runtime/rococo/src/weights/runtime_parachains_coretime.rs | 2 +- .../runtime/westend/src/weights/runtime_parachains_coretime.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs index aec64a93bfd1..b4f893f1bb3e 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs @@ -70,7 +70,7 @@ impl runtime_parachains::coreti .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - fn request_revenue_info_at() -> frame_support::weights::Weight { + fn request_revenue_at() -> frame_support::weights::Weight { ::WeightInfo::set_config_with_u32() } diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs index 77e07319845b..4aa85595f674 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs @@ -81,5 +81,5 @@ impl runtime_parachains::coretime::WeightInfo for Weigh .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - fn request_revenue_info_at() -> frame_support::weights::Weight { todo!() } + fn request_revenue_at() -> frame_support::weights::Weight { todo!() } } From 84151b1936bdaeabf68a0751048a9be502630261 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 29 May 2024 10:43:47 +0200 Subject: [PATCH 29/67] Move constants --- .../runtimes/coretime/coretime-rococo/src/coretime.rs | 6 ++---- .../runtimes/coretime/coretime-westend/src/coretime.rs | 6 ++---- polkadot/runtime/rococo/constants/src/lib.rs | 9 +++++++++ polkadot/runtime/rococo/src/lib.rs | 4 ++-- polkadot/runtime/westend/constants/src/lib.rs | 9 +++++++++ polkadot/runtime/westend/src/lib.rs | 9 +++++++-- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index e2f0fe3d944b..da27ecdf6d15 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -27,6 +27,7 @@ use frame_support::{ }; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; use parachains_common::{AccountId, Balance}; +use rococo_runtime_constants::system_parachain::coretime; use xcm::latest::prelude::*; pub struct CreditToCollatorPot; @@ -205,10 +206,7 @@ impl pallet_broker::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type OnRevenue = CreditToCollatorPot; - #[cfg(feature = "fast-runtime")] - type TimeslicePeriod = ConstU32<10>; - #[cfg(not(feature = "fast-runtime"))] - type TimeslicePeriod = ConstU32<80>; + type TimeslicePeriod = ConstU32<{ coretime::TIMESLICE_PERIOD }>; type MaxLeasedCores = ConstU32<50>; type MaxReservedCores = ConstU32<10>; type Coretime = CoretimeAllocator; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 138ad412d4e5..af691c10fd42 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -27,6 +27,7 @@ use frame_support::{ }; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; use parachains_common::{AccountId, Balance}; +use westend_runtime_constants::system_parachain::coretime; use xcm::latest::prelude::*; pub struct CreditToCollatorPot; @@ -217,10 +218,7 @@ impl pallet_broker::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type OnRevenue = CreditToCollatorPot; - #[cfg(feature = "fast-runtime")] - type TimeslicePeriod = ConstU32<10>; - #[cfg(not(feature = "fast-runtime"))] - type TimeslicePeriod = ConstU32<80>; + type TimeslicePeriod = ConstU32<{ coretime::TIMESLICE_PERIOD }>; // We don't actually need any leases at launch but set to 10 in case we want to sudo some in. type MaxLeasedCores = ConstU32<10>; type MaxReservedCores = ConstU32<10>; diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 89d5deb86f1a..eeb875b8359a 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -121,6 +121,15 @@ pub mod system_parachain { /// All system parachains of Rococo. pub type SystemParachains = IsChildSystemParachain; + + /// Coretime constants + pub mod coretime { + /// Coretime timeslice period in blocks + #[cfg(feature = "fast-runtime")] + pub const TIMESLICE_PERIOD: u32 = 10; + #[cfg(not(feature = "fast-runtime"))] + pub const TIMESLICE_PERIOD: u32 = 80; + } } /// Rococo Treasury pallet instance. diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 290bfac8a076..dcbde4085b2c 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -39,7 +39,7 @@ use primitives::{ SessionInfo, Signature, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex, PARACHAIN_KEY_TYPE_ID, }; -use rococo_runtime_constants::system_parachain::BROKER_ID; +use rococo_runtime_constants::system_parachain::{coretime::TIMESLICE_PERIOD, BROKER_ID}; use runtime_common::{ assigned_slots, auctions, claims, crowdloan, identity_migrator, impl_runtime_weights, impls::{ @@ -1083,7 +1083,7 @@ impl coretime::Config for Runtime { parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); // Keep 2 timeslices worth of revenue information. - pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; + pub const MaxHistoricalRevenue: BlockNumber = 2 * TIMESLICE_PERIOD; pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index 1a4c1f311061..cd8568f7ed87 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -116,6 +116,15 @@ pub mod system_parachain { /// All system parachains of Westend. pub type SystemParachains = IsChildSystemParachain; + + /// Coretime constants + pub mod coretime { + /// Coretime timeslice period in blocks + #[cfg(feature = "fast-runtime")] + pub const TIMESLICE_PERIOD: u32 = 10; + #[cfg(not(feature = "fast-runtime"))] + pub const TIMESLICE_PERIOD: u32 = 80; + } } /// Westend Treasury pallet instance. diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 30b779fe709b..2ae2f1978f7f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -125,7 +125,12 @@ use sp_runtime::traits::Get; pub use sp_runtime::BuildStorage; /// Constant values used within the runtime. -use westend_runtime_constants::{currency::*, fee::*, system_parachain::BROKER_ID, time::*}; +use westend_runtime_constants::{ + currency::*, + fee::*, + system_parachain::{coretime::TIMESLICE_PERIOD, BROKER_ID}, + time::*, +}; mod bag_thresholds; mod weights; @@ -1212,7 +1217,7 @@ impl coretime::Config for Runtime { parameter_types! { pub const OnDemandTrafficDefaultValue: FixedU128 = FixedU128::from_u32(1); // Keep 2 timeslices worth of revenue information. - pub const MaxHistoricalRevenue: BlockNumber = 2 * 80; + pub const MaxHistoricalRevenue: BlockNumber = 2 * TIMESLICE_PERIOD; pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } From 6df281b977f475cac8896f4829fb266baec1a757 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 29 May 2024 11:49:01 +0200 Subject: [PATCH 30/67] Improve error handling --- .../parachains/src/assigner_on_demand/mod.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index a3aa752036d0..c82e932a0522 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -47,6 +47,7 @@ use core::mem::take; use frame_support::{ pallet_prelude::*, traits::{ + defensive_prelude::*, Currency, ExistenceRequirement::{self, AllowDeath, KeepAlive}, WithdrawReasons, @@ -201,16 +202,7 @@ pub mod pallet { fn on_initialize(_now: BlockNumberFor) -> Weight { // Update revenue information storage. Revenue::::mutate(|revenue| { - match revenue.force_insert_keep_left(0, 0u32.into()) { - Ok(_) => (), - Err(e) => { - // Defensive, should not fail. - log::debug!( - target: LOG_TARGET, - "Error updating historical revenue: {:?}", e - ); - }, - } + let _ = revenue.force_insert_keep_left(0, 0u32.into()).defensive_proof("Inserting a revenue value does not fail"); }); let config = configuration::ActiveConfig::::get(); @@ -411,6 +403,9 @@ where Revenue::::mutate(|bounded_revenue| { if let Some(current_block) = bounded_revenue.get_mut(0) { *current_block = current_block.saturating_add(spot_price); + } else { + // The value's been inserted in `on_initialize` so this should never happen + defensive!("Cannot update current block's revenue info"); } }); @@ -641,7 +636,7 @@ where // while !revenue.is_empty() { // let index = (revenue.len() - 1) as u32; // if when > now.saturating_sub(index.into()) { - // amount = amount.saturating_add(revenue.pop().expect("Checked to contain at least one element; qed")); + // amount = amount.saturating_add(revenue.pop().defensive_unwrap_or(0)); // } else { // break // } From 8f482fe1aada11c99562a82ac8487a5aff397c01 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 29 May 2024 16:44:31 +0200 Subject: [PATCH 31/67] Fix and improve test --- .../parachains/src/assigner_on_demand/tests.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index a3220cf7417b..118bc5008ea3 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -30,7 +30,7 @@ use crate::{ paras::{ParaGenesisArgs, ParaKind}, }; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; -use pallet_balances::{Error as BalancesError, NegativeImbalance}; +use pallet_balances::Error as BalancesError; use primitives::{BlockNumber, SessionIndex, ValidationCode, ON_DEMAND_MAX_QUEUE_MAX_SIZE}; use sp_std::{ cmp::{Ord, Ordering}, @@ -742,11 +742,17 @@ fn revenue_information_fetching_works() { let revenue = OnDemandAssigner::get_revenue(); let amt = OnDemandAssigner::revenue_until(11); - // Revenue for a single order should be recorded. + // Revenue until the current block is still zero as "until" is non-inclusive + assert_eq!(amt, 0); + + let amt = OnDemandAssigner::revenue_until(12); + + // Revenue for a single order should be recorded and shouldn't have been pruned by the + // previous call assert_eq!(amt, revenue[0]); run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(12); + let revenue = OnDemandAssigner::revenue_until(13); // No revenue should be recorded. assert_eq!(revenue, 0); From 724b7a58bf95e1e0d35b65e8eedb35d2296f6056 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 30 May 2024 11:01:27 +0200 Subject: [PATCH 32/67] Fix benchmarking code --- substrate/frame/broker/src/benchmarking.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index dbac13f45dfd..1e4429f0adff 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -54,10 +54,6 @@ fn new_config_record() -> ConfigRecordOf { } } -fn new_revenue() -> OnDemandRevenueRecordOf { - OnDemandRevenueRecord { until: 2u32.into(), amount: 10u32.into() } -} - fn new_schedule() -> Schedule { // Max items for worst case let mut items = Vec::new(); @@ -117,6 +113,10 @@ mod benches { use super::*; use crate::Finality::*; + fn new_revenue() -> OnDemandRevenueRecordOf { + OnDemandRevenueRecord { until: 2u32.into(), amount: 10u32.into() } + } + #[benchmark] fn configure() -> Result<(), BenchmarkError> { let config = new_config_record::(); From 00fd411fdacdffa3f9c5db4ad9a35722e605ae5c Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 30 May 2024 14:15:32 +0200 Subject: [PATCH 33/67] Add benchmark --- .../parachains/src/coretime/benchmarking.rs | 19 +++++++++++-------- .../runtime/parachains/src/coretime/mod.rs | 7 +++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index 8a0f4aff50b9..552d1fd543fe 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -29,17 +29,20 @@ mod benchmarks { use assigner_coretime::PartsOf57600; #[benchmark] - fn request_revenue_info_at() { - //TODO: write actual benchmark - // Setup + fn request_revenue_at() { let root_origin = ::RuntimeOrigin::root(); + let mhr = ::MaxHistoricalRevenue::get(); + frame_system::Pallet::::set_block_number((mhr + 2).into()); + let rev: BoundedVec< + <::Currency as frame_support::traits::Currency< + T::AccountId, + >>::Balance, + T::MaxHistoricalRevenue, + > = BoundedVec::try_from((1..=mhr).map(|v| v.into()).collect::>()).unwrap(); + assigner_on_demand::Revenue::::put(rev); #[extrinsic_call] - _( - root_origin as ::RuntimeOrigin, - // TODO: Better when param - 100u32, - ) + _(root_origin as ::RuntimeOrigin, mhr + 1) } #[benchmark] diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 0506d063713e..7f808396af3d 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -284,10 +284,10 @@ impl Pallet { ensure!(when_bnf <= now, Error::::RequestedFutureRevenue); let revenue = >::revenue_until(when_bnf); - log::info!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); + log::debug!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); match TryInto::::try_into(revenue) { Ok(raw_revenue) => { - log::info!(target: LOG_TARGET, "Revenue into balance success: {:?}", raw_revenue); + log::trace!(target: LOG_TARGET, "Revenue into balance success: {:?}", raw_revenue); let message = Xcm(vec![ Instruction::UnpaidExecution { weight_limit: WeightLimit::Unlimited, @@ -299,8 +299,7 @@ impl Pallet { Location::new(0, [Junction::Parachain(T::BrokerId::get())]), message, ) { - log::error!(target: LOG_TARGET, "Sending `NotifyRevenue` to coretime chain failed: {:?}", - err); + log::error!(target: LOG_TARGET, "Sending `NotifyRevenue` to coretime chain failed: {:?}", err); } }, Err(_err) => { From d5d668b3397143faa94c3c8cca0cee28d9c8fd73 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 30 May 2024 14:15:49 +0200 Subject: [PATCH 34/67] Minor fixes --- polkadot/runtime/parachains/src/assigner_on_demand/mod.rs | 2 +- polkadot/runtime/parachains/src/assigner_on_demand/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index c82e932a0522..85db9e6726ff 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -202,7 +202,7 @@ pub mod pallet { fn on_initialize(_now: BlockNumberFor) -> Weight { // Update revenue information storage. Revenue::::mutate(|revenue| { - let _ = revenue.force_insert_keep_left(0, 0u32.into()).defensive_proof("Inserting a revenue value does not fail"); + revenue.force_insert_keep_left(0, 0u32.into()).defensive_ok(); }); let config = configuration::ActiveConfig::::get(); diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 118bc5008ea3..5dbb48dfc8ef 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -747,7 +747,7 @@ fn revenue_information_fetching_works() { let amt = OnDemandAssigner::revenue_until(12); - // Revenue for a single order should be recorded and shouldn't have been pruned by the + // Revenue for a single order should be recorded and shouldn't have been pruned by the // previous call assert_eq!(amt, revenue[0]); From 36d9cef2ed79f23854bf246eff78012c4361f90a Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 30 May 2024 15:03:52 +0200 Subject: [PATCH 35/67] Fix clippy --- substrate/frame/broker/src/mock.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 16fecbcc6ee8..28d58565eff4 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -242,10 +242,6 @@ pub fn new_config() -> ConfigRecordOf { } } -pub fn new_revenue() -> OnDemandRevenueRecordOf { - OnDemandRevenueRecord { until: 2, amount: 10 } -} - pub struct TestExt(ConfigRecordOf); #[allow(dead_code)] impl TestExt { From fac55b05b328901ac87cad4185f6f48456a753e5 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 30 May 2024 22:03:06 +0200 Subject: [PATCH 36/67] Fix broker benchmark --- substrate/frame/broker/src/benchmarking.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 5107edc8c03f..129a81c876ad 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -113,10 +113,6 @@ mod benches { use super::*; use crate::Finality::*; - fn new_revenue() -> OnDemandRevenueRecordOf { - OnDemandRevenueRecord { until: 2u32.into(), amount: 10u32.into() } - } - #[benchmark] fn configure() -> Result<(), BenchmarkError> { let config = new_config_record::(); @@ -743,7 +739,10 @@ mod benches { let timeslice_period: u32 = T::TimeslicePeriod::get().try_into().ok().unwrap(); let multiplicator = 5; - RevenueInbox::::put(new_revenue::()); + RevenueInbox::::put(OnDemandRevenueRecord { + until: (timeslice_period * multiplicator).into(), + amount: 10u32.into(), + }); let timeslice = multiplicator - 1; InstaPoolHistory::::insert( From 3f8482a41144885a3a8b1af555e88c41011d33ab Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 10:42:42 +0200 Subject: [PATCH 37/67] Fix mock impl --- substrate/frame/broker/src/mock.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 627bfd62501a..3cc9095a1968 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -70,7 +70,6 @@ parameter_types! { pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default(); pub static CoretimeUsage: BTreeMap> = Default::default(); pub static CoretimeInPool: CoreMaskBitCount = 0; - pub static NotifyRevenueInfo: Vec<(u32, u64)> = Default::default(); } pub struct TestCoretimeProvider; @@ -90,11 +89,10 @@ impl CoretimeInterface for TestCoretimeProvider { ); } - let when = when as u32; let mut total = 0; CoretimeSpending::mutate(|s| { s.retain(|(n, a)| { - if *n < when { + if *n < when as u32 { total += a; false } else { @@ -102,7 +100,7 @@ impl CoretimeInterface for TestCoretimeProvider { } }) }); - NotifyRevenueInfo::mutate(|s| s.insert(0, (when, total))); + RevenueInbox::::set(Some(OnDemandRevenueRecord { until: when, amount: total })); } fn credit_account(who: Self::AccountId, amount: Self::Balance) { CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); From 338316ea986a64a94d93c781910e3d14f22c06af Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 11:23:15 +0200 Subject: [PATCH 38/67] Fix tests --- polkadot/runtime/parachains/src/assigner_coretime/tests.rs | 3 +++ polkadot/runtime/parachains/src/assigner_on_demand/tests.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs index 5d42a9d0c8ee..f7a024196eda 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs @@ -74,6 +74,9 @@ fn run_to_block( Paras::initializer_initialize(b + 1); Scheduler::initializer_initialize(b + 1); + // Update the spot traffic and revenue on every block. + OnDemandAssigner::on_initialize(b + 1); + // In the real runtime this is expected to be called by the `InclusionInherent` pallet. Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); } diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 5dbb48dfc8ef..65252d587174 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -80,7 +80,7 @@ fn run_to_block( Paras::initializer_initialize(b + 1); Scheduler::initializer_initialize(b + 1); - // Update the spot traffic on every block. + // Update the spot traffic and revenue on every block. OnDemandAssigner::on_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. From bf4ed2ee663fb1639acaadb5e344cd77a9710371 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 13:11:06 +0200 Subject: [PATCH 39/67] Improve revenue collection implementation --- .../parachains/src/assigner_on_demand/mod.rs | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 85db9e6726ff..22666f6742d2 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -404,8 +404,11 @@ where if let Some(current_block) = bounded_revenue.get_mut(0) { *current_block = current_block.saturating_add(spot_price); } else { - // The value's been inserted in `on_initialize` so this should never happen - defensive!("Cannot update current block's revenue info"); + // Revenue has already been claimed in the same block, including the block + // itself. It shouldn't normally happen as the parachain part checks not to + // claim revenue in the future, but relay-chain-only implementations (e.g. mocks + // or some future implementations) may still do that. + bounded_revenue.try_push(spot_price).defensive_ok(); } }); @@ -630,24 +633,14 @@ where let now = >::block_number(); let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { - // - // TODO: Proposed implementation, decide which is better - // - // while !revenue.is_empty() { - // let index = (revenue.len() - 1) as u32; - // if when > now.saturating_sub(index.into()) { - // amount = amount.saturating_add(revenue.pop().defensive_unwrap_or(0)); - // } else { - // break - // } - // } - - revenue.into_iter().enumerate().for_each(|(index, block_revenue)| { - if when > now.saturating_sub((index as u32).into()) { - amount = amount.saturating_add(*block_revenue); - *block_revenue = BalanceOf::::zero(); + while !revenue.is_empty() { + let index = (revenue.len() - 1) as u32; + if when > now.saturating_sub(index.into()) { + amount = amount.saturating_add(revenue.pop().defensive_unwrap_or(0u32.into())); + } else { + break } - }) + } }); let imbalance = T::Currency::burn(amount); From 14e4bc28ad2338eda2c9fd7dd25f20b995851775 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 31 May 2024 12:49:42 +0000 Subject: [PATCH 40/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=rococo --target_dir=polkadot --pallet=runtime_common::coretime --- .../src/weights/runtime_common_coretime.rs | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs diff --git a/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs new file mode 100644 index 000000000000..876635862d2d --- /dev/null +++ b/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs @@ -0,0 +1,106 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Autogenerated weights for `runtime_common::coretime` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=runtime_common::coretime +// --chain=rococo-dev +// --header=./polkadot/file_header.txt +// --output=./polkadot/runtime/rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `runtime_common::coretime`. +pub struct WeightInfo(PhantomData); +impl runtime_common::coretime::WeightInfo for WeightInfo { + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn request_revenue_at() -> Weight { + // Proof Size summary in bytes: + // Measured: `2963` + // Estimated: `6428` + // Minimum execution time: 36_613_000 picoseconds. + Weight::from_parts(37_637_000, 0) + .saturating_add(Weight::from_parts(0, 6428)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Configuration::PendingConfigs` (r:1 w:1) + /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) + /// Proof: `Configuration::BypassConsistencyCheck` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParasShared::CurrentSessionIndex` (r:1 w:0) + /// Proof: `ParasShared::CurrentSessionIndex` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn request_core_count() -> Weight { + // Proof Size summary in bytes: + // Measured: `151` + // Estimated: `1636` + // Minimum execution time: 7_527_000 picoseconds. + Weight::from_parts(7_784_000, 0) + .saturating_add(Weight::from_parts(0, 1636)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `CoretimeAssignmentProvider::CoreDescriptors` (r:1 w:1) + /// Proof: `CoretimeAssignmentProvider::CoreDescriptors` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CoretimeAssignmentProvider::CoreSchedules` (r:0 w:1) + /// Proof: `CoretimeAssignmentProvider::CoreSchedules` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `s` is `[1, 100]`. + fn assign_core(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `180` + // Estimated: `3645` + // Minimum execution time: 9_220_000 picoseconds. + Weight::from_parts(9_905_773, 0) + .saturating_add(Weight::from_parts(0, 3645)) + // Standard Error: 257 + .saturating_add(Weight::from_parts(12_400, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} From 3130df8f8b24eabb45858d7a36be2d33c6aaeeaa Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 31 May 2024 13:58:00 +0000 Subject: [PATCH 41/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=rococo --target_dir=polkadot --pallet=runtime_parachains::assigner_on_demand --- .../runtime_parachains_assigner_on_demand.rs | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs index dba9e7904c79..0b384e29cf12 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `runtime_parachains::assigner_on_demand` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-03-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-h2rr8wx7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 // Executed Command: @@ -50,6 +50,10 @@ pub struct WeightInfo(PhantomData); impl runtime_parachains::assigner_on_demand::WeightInfo for WeightInfo { /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::ParaIdAffinity` (r:1 w:0) /// Proof: `OnDemandAssignmentProvider::ParaIdAffinity` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::FreeEntries` (r:1 w:1) @@ -57,19 +61,23 @@ impl runtime_parachains::assigner_on_demand::WeightInfo /// The range of component `s` is `[1, 9999]`. fn place_order_keep_alive(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `218 + s * (8 ±0)` - // Estimated: `3681 + s * (8 ±0)` - // Minimum execution time: 21_053_000 picoseconds. - Weight::from_parts(17_291_897, 0) - .saturating_add(Weight::from_parts(0, 3681)) - // Standard Error: 104 - .saturating_add(Weight::from_parts(18_779, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `270 + s * (8 ±0)` + // Estimated: `3733 + s * (8 ±0)` + // Minimum execution time: 28_422_000 picoseconds. + Weight::from_parts(28_146_882, 0) + .saturating_add(Weight::from_parts(0, 3733)) + // Standard Error: 140 + .saturating_add(Weight::from_parts(21_283, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 8).saturating_mul(s.into())) } /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::ParaIdAffinity` (r:1 w:0) /// Proof: `OnDemandAssignmentProvider::ParaIdAffinity` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::FreeEntries` (r:1 w:1) @@ -77,15 +85,15 @@ impl runtime_parachains::assigner_on_demand::WeightInfo /// The range of component `s` is `[1, 9999]`. fn place_order_allow_death(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `218 + s * (8 ±0)` - // Estimated: `3681 + s * (8 ±0)` - // Minimum execution time: 20_843_000 picoseconds. - Weight::from_parts(16_881_986, 0) - .saturating_add(Weight::from_parts(0, 3681)) - // Standard Error: 104 - .saturating_add(Weight::from_parts(18_788, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `270 + s * (8 ±0)` + // Estimated: `3733 + s * (8 ±0)` + // Minimum execution time: 28_680_000 picoseconds. + Weight::from_parts(31_024_579, 0) + .saturating_add(Weight::from_parts(0, 3733)) + // Standard Error: 119 + .saturating_add(Weight::from_parts(20_989, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 8).saturating_mul(s.into())) } } From d90b4cb46c3a730461819ce2e9a45eeb1a7c8749 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 19:57:39 +0200 Subject: [PATCH 42/67] Accumulate overdue revenue instead of burning it --- .../parachains/src/assigner_on_demand/mod.rs | 10 +++++++++- .../parachains/src/assigner_on_demand/tests.rs | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 22666f6742d2..b40b17f1533d 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -202,7 +202,15 @@ pub mod pallet { fn on_initialize(_now: BlockNumberFor) -> Weight { // Update revenue information storage. Revenue::::mutate(|revenue| { - revenue.force_insert_keep_left(0, 0u32.into()).defensive_ok(); + if let Some(overdue) = + revenue.force_insert_keep_left(0, 0u32.into()).defensive_unwrap_or(None) + { + // We have some overdue revenue not claimed by the parachain, let's accumulate + // it at the oldest stored block + if let Some(last) = revenue.last_mut() { + *last = last.saturating_add(overdue); + } + } }); let config = configuration::ActiveConfig::::get(); diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index 65252d587174..ebe72996c7d1 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -767,7 +767,7 @@ fn revenue_information_fetching_works() { run_to_block(14, |n| if n == 14 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(14); + let revenue = OnDemandAssigner::revenue_until(15); // All 3 orders should be accounted for. assert_eq!(revenue, 30_000); @@ -779,5 +779,17 @@ fn revenue_information_fetching_works() { // Order is not in range of the revenue_until call assert_eq!(revenue, 0); + + run_to_block(20, |n| if n == 20 { Some(Default::default()) } else { None }); + let revenue = OnDemandAssigner::revenue_until(21); + assert_eq!(revenue, 10_000); + + // Make sure overdue revenue is accumulated + for i in 21..=35 { + run_to_block(i, |n| if n % 10 == 0 { Some(Default::default()) } else { None }); + place_order(para_a); + } + let revenue = OnDemandAssigner::revenue_until(36); + assert_eq!(revenue, 150_000); }); } From 8744d5d581c0431cdf018c3b8d4c6557dd5743bb Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 31 May 2024 18:47:35 +0000 Subject: [PATCH 43/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_broker --- substrate/frame/broker/src/weights.rs | 298 +++++++++++++------------- 1 file changed, 146 insertions(+), 152 deletions(-) diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index b7b8fde80267..c2fb13d22f49 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_broker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-05-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-vicqj8em-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -75,7 +75,6 @@ pub trait WeightInfo { fn process_core_schedule() -> Weight; fn request_revenue_info_at() -> Weight; fn notify_core_count() -> Weight; - fn notify_revenue() -> Weight; fn do_tick_base() -> Weight; fn swap_leases() -> Weight; } @@ -89,8 +88,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_945_000 picoseconds. - Weight::from_parts(2_142_000, 0) + // Minimum execution time: 1_891_000 picoseconds. + Weight::from_parts(2_006_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -99,8 +98,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 16_274_000 picoseconds. - Weight::from_parts(16_828_000, 7496) + // Minimum execution time: 16_842_000 picoseconds. + Weight::from_parts(17_517_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -110,8 +109,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 15_080_000 picoseconds. - Weight::from_parts(15_874_000, 7496) + // Minimum execution time: 15_553_000 picoseconds. + Weight::from_parts(15_997_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -121,8 +120,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 8_761_000 picoseconds. - Weight::from_parts(9_203_000, 1526) + // Minimum execution time: 8_671_000 picoseconds. + Weight::from_parts(9_110_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -145,10 +144,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 26_057_000 picoseconds. - Weight::from_parts(46_673_357, 8499) - // Standard Error: 456 - .saturating_add(Weight::from_parts(2_677, 0).saturating_mul(n.into())) + // Minimum execution time: 26_243_000 picoseconds. + Weight::from_parts(46_796_897, 8499) + // Standard Error: 452 + .saturating_add(Weight::from_parts(2_457, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -166,8 +165,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `651` // Estimated: `2136` - // Minimum execution time: 40_907_000 picoseconds. - Weight::from_parts(42_566_000, 2136) + // Minimum execution time: 40_723_000 picoseconds. + Weight::from_parts(42_099_000, 2136) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -189,8 +188,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `769` // Estimated: `4698` - // Minimum execution time: 65_209_000 picoseconds. - Weight::from_parts(68_604_000, 4698) + // Minimum execution time: 59_817_000 picoseconds. + Weight::from_parts(61_693_000, 4698) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -200,8 +199,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 15_860_000 picoseconds. - Weight::from_parts(16_393_000, 3551) + // Minimum execution time: 15_389_000 picoseconds. + Weight::from_parts(16_058_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -211,8 +210,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 17_651_000 picoseconds. - Weight::from_parts(18_088_000, 3551) + // Minimum execution time: 16_849_000 picoseconds. + Weight::from_parts(17_517_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -222,8 +221,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 18_576_000 picoseconds. - Weight::from_parts(19_810_000, 3551) + // Minimum execution time: 18_170_000 picoseconds. + Weight::from_parts(18_870_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -239,8 +238,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 31_015_000 picoseconds. - Weight::from_parts(31_932_000, 4681) + // Minimum execution time: 29_200_000 picoseconds. + Weight::from_parts(30_266_000, 4681) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -258,8 +257,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 36_473_000 picoseconds. - Weight::from_parts(37_382_000, 5996) + // Minimum execution time: 34_994_000 picoseconds. + Weight::from_parts(35_593_000, 5996) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -274,10 +273,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `859` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 64_957_000 picoseconds. - Weight::from_parts(66_024_232, 6196) - // Standard Error: 50_170 - .saturating_add(Weight::from_parts(1_290_632, 0).saturating_mul(m.into())) + // Minimum execution time: 63_588_000 picoseconds. + Weight::from_parts(64_705_862, 6196) + // Standard Error: 46_784 + .saturating_add(Weight::from_parts(1_308_067, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -289,8 +288,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 39_939_000 picoseconds. - Weight::from_parts(40_788_000, 3593) + // Minimum execution time: 39_913_000 picoseconds. + Weight::from_parts(40_718_000, 3593) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -302,8 +301,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 31_709_000 picoseconds. - Weight::from_parts(37_559_000, 3551) + // Minimum execution time: 29_085_000 picoseconds. + Weight::from_parts(32_115_000, 3551) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -317,8 +316,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 42_895_000 picoseconds. - Weight::from_parts(53_945_000, 3533) + // Minimum execution time: 38_143_000 picoseconds. + Weight::from_parts(46_943_000, 3533) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -334,8 +333,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `995` // Estimated: `3593` - // Minimum execution time: 50_770_000 picoseconds. - Weight::from_parts(63_117_000, 3593) + // Minimum execution time: 46_646_000 picoseconds. + Weight::from_parts(53_739_000, 3593) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -347,8 +346,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 33_396_000 picoseconds. - Weight::from_parts(36_247_000, 4698) + // Minimum execution time: 25_755_000 picoseconds. + Weight::from_parts(29_195_000, 4698) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -357,8 +356,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_625_000 picoseconds. - Weight::from_parts(4_011_396, 0) + // Minimum execution time: 3_593_000 picoseconds. + Weight::from_parts(3_877_345, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -367,13 +366,13 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_217_000 picoseconds. - Weight::from_parts(6_608_394, 1487) + // Minimum execution time: 6_207_000 picoseconds. + Weight::from_parts(6_626_616, 1487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) @@ -384,10 +383,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn process_revenue() -> Weight { // Proof Size summary in bytes: - // Measured: `972` - // Estimated: `4437` - // Minimum execution time: 46_853_000 picoseconds. - Weight::from_parts(47_740_000, 4437) + // Measured: `829` + // Estimated: `3593` + // Minimum execution time: 45_425_000 picoseconds. + Weight::from_parts(46_703_000, 3593) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -402,12 +401,14 @@ impl WeightInfo for SubstrateWeight { /// Storage: `Broker::Workplan` (r:0 w:10) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn rotate_sale(_n: u32, ) -> Weight { + fn rotate_sale(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `6281` // Estimated: `8499` - // Minimum execution time: 34_240_000 picoseconds. - Weight::from_parts(35_910_175, 8499) + // Minimum execution time: 34_627_000 picoseconds. + Weight::from_parts(35_896_560, 8499) + // Standard Error: 54 + .saturating_add(Weight::from_parts(32, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -419,8 +420,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 7_083_000 picoseconds. - Weight::from_parts(7_336_000, 3493) + // Minimum execution time: 6_959_000 picoseconds. + Weight::from_parts(7_343_000, 3493) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -432,8 +433,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 15_029_000 picoseconds. - Weight::from_parts(15_567_000, 4681) + // Minimum execution time: 14_973_000 picoseconds. + Weight::from_parts(15_823_000, 4681) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -441,8 +442,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 123_000 picoseconds. - Weight::from_parts(136_000, 0) + // Minimum execution time: 121_000 picoseconds. + Weight::from_parts(135_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -450,29 +451,26 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_775_000 picoseconds. - Weight::from_parts(1_911_000, 0) + // Minimum execution time: 1_700_000 picoseconds. + Weight::from_parts(1_863_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn notify_revenue() -> Weight { - T::DbWeight::get().reads_writes(1, 1) - } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) /// Storage: `Broker::CoreCountInbox` (r:1 w:0) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:0) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) fn do_tick_base() -> Weight { // Proof Size summary in bytes: - // Measured: `603` - // Estimated: `4068` - // Minimum execution time: 11_859_000 picoseconds. - Weight::from_parts(12_214_000, 4068) + // Measured: `441` + // Estimated: `1516` + // Minimum execution time: 9_171_000 picoseconds. + Weight::from_parts(9_766_000, 1516) .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) @@ -480,8 +478,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_864_000 picoseconds. - Weight::from_parts(6_231_000, 1526) + // Minimum execution time: 5_878_000 picoseconds. + Weight::from_parts(6_266_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -495,8 +493,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_945_000 picoseconds. - Weight::from_parts(2_142_000, 0) + // Minimum execution time: 1_891_000 picoseconds. + Weight::from_parts(2_006_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -505,8 +503,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 16_274_000 picoseconds. - Weight::from_parts(16_828_000, 7496) + // Minimum execution time: 16_842_000 picoseconds. + Weight::from_parts(17_517_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -516,8 +514,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 15_080_000 picoseconds. - Weight::from_parts(15_874_000, 7496) + // Minimum execution time: 15_553_000 picoseconds. + Weight::from_parts(15_997_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -527,8 +525,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 8_761_000 picoseconds. - Weight::from_parts(9_203_000, 1526) + // Minimum execution time: 8_671_000 picoseconds. + Weight::from_parts(9_110_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -551,10 +549,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 26_057_000 picoseconds. - Weight::from_parts(46_673_357, 8499) - // Standard Error: 456 - .saturating_add(Weight::from_parts(2_677, 0).saturating_mul(n.into())) + // Minimum execution time: 26_243_000 picoseconds. + Weight::from_parts(46_796_897, 8499) + // Standard Error: 452 + .saturating_add(Weight::from_parts(2_457, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -572,8 +570,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `651` // Estimated: `2136` - // Minimum execution time: 40_907_000 picoseconds. - Weight::from_parts(42_566_000, 2136) + // Minimum execution time: 40_723_000 picoseconds. + Weight::from_parts(42_099_000, 2136) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -595,8 +593,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `769` // Estimated: `4698` - // Minimum execution time: 65_209_000 picoseconds. - Weight::from_parts(68_604_000, 4698) + // Minimum execution time: 59_817_000 picoseconds. + Weight::from_parts(61_693_000, 4698) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -606,8 +604,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 15_860_000 picoseconds. - Weight::from_parts(16_393_000, 3551) + // Minimum execution time: 15_389_000 picoseconds. + Weight::from_parts(16_058_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -617,8 +615,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 17_651_000 picoseconds. - Weight::from_parts(18_088_000, 3551) + // Minimum execution time: 16_849_000 picoseconds. + Weight::from_parts(17_517_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -628,8 +626,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 18_576_000 picoseconds. - Weight::from_parts(19_810_000, 3551) + // Minimum execution time: 18_170_000 picoseconds. + Weight::from_parts(18_870_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -645,8 +643,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 31_015_000 picoseconds. - Weight::from_parts(31_932_000, 4681) + // Minimum execution time: 29_200_000 picoseconds. + Weight::from_parts(30_266_000, 4681) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -664,8 +662,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 36_473_000 picoseconds. - Weight::from_parts(37_382_000, 5996) + // Minimum execution time: 34_994_000 picoseconds. + Weight::from_parts(35_593_000, 5996) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -680,10 +678,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `859` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 64_957_000 picoseconds. - Weight::from_parts(66_024_232, 6196) - // Standard Error: 50_170 - .saturating_add(Weight::from_parts(1_290_632, 0).saturating_mul(m.into())) + // Minimum execution time: 63_588_000 picoseconds. + Weight::from_parts(64_705_862, 6196) + // Standard Error: 46_784 + .saturating_add(Weight::from_parts(1_308_067, 0).saturating_mul(m.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -695,8 +693,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 39_939_000 picoseconds. - Weight::from_parts(40_788_000, 3593) + // Minimum execution time: 39_913_000 picoseconds. + Weight::from_parts(40_718_000, 3593) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -708,8 +706,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 31_709_000 picoseconds. - Weight::from_parts(37_559_000, 3551) + // Minimum execution time: 29_085_000 picoseconds. + Weight::from_parts(32_115_000, 3551) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -723,8 +721,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 42_895_000 picoseconds. - Weight::from_parts(53_945_000, 3533) + // Minimum execution time: 38_143_000 picoseconds. + Weight::from_parts(46_943_000, 3533) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -740,8 +738,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `995` // Estimated: `3593` - // Minimum execution time: 50_770_000 picoseconds. - Weight::from_parts(63_117_000, 3593) + // Minimum execution time: 46_646_000 picoseconds. + Weight::from_parts(53_739_000, 3593) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -753,8 +751,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 33_396_000 picoseconds. - Weight::from_parts(36_247_000, 4698) + // Minimum execution time: 25_755_000 picoseconds. + Weight::from_parts(29_195_000, 4698) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -763,8 +761,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_625_000 picoseconds. - Weight::from_parts(4_011_396, 0) + // Minimum execution time: 3_593_000 picoseconds. + Weight::from_parts(3_877_345, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -773,13 +771,13 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_217_000 picoseconds. - Weight::from_parts(6_608_394, 1487) + // Minimum execution time: 6_207_000 picoseconds. + Weight::from_parts(6_626_616, 1487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) @@ -790,10 +788,10 @@ impl WeightInfo for () { /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn process_revenue() -> Weight { // Proof Size summary in bytes: - // Measured: `972` - // Estimated: `4437` - // Minimum execution time: 46_853_000 picoseconds. - Weight::from_parts(47_740_000, 4437) + // Measured: `829` + // Estimated: `3593` + // Minimum execution time: 45_425_000 picoseconds. + Weight::from_parts(46_703_000, 3593) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -808,12 +806,14 @@ impl WeightInfo for () { /// Storage: `Broker::Workplan` (r:0 w:10) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn rotate_sale(_n: u32, ) -> Weight { + fn rotate_sale(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `6281` // Estimated: `8499` - // Minimum execution time: 34_240_000 picoseconds. - Weight::from_parts(35_910_175, 8499) + // Minimum execution time: 34_627_000 picoseconds. + Weight::from_parts(35_896_560, 8499) + // Standard Error: 54 + .saturating_add(Weight::from_parts(32, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -825,8 +825,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 7_083_000 picoseconds. - Weight::from_parts(7_336_000, 3493) + // Minimum execution time: 6_959_000 picoseconds. + Weight::from_parts(7_343_000, 3493) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -838,8 +838,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 15_029_000 picoseconds. - Weight::from_parts(15_567_000, 4681) + // Minimum execution time: 14_973_000 picoseconds. + Weight::from_parts(15_823_000, 4681) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -847,8 +847,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 123_000 picoseconds. - Weight::from_parts(136_000, 0) + // Minimum execution time: 121_000 picoseconds. + Weight::from_parts(135_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -856,32 +856,26 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_775_000 picoseconds. - Weight::from_parts(1_911_000, 0) + // Minimum execution time: 1_700_000 picoseconds. + Weight::from_parts(1_863_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - - fn notify_revenue() -> Weight { - RocksDbWeight::get().reads(1) - .saturating_add(RocksDbWeight::get().writes(1)) - } - /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) /// Storage: `Broker::CoreCountInbox` (r:1 w:0) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:0) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) fn do_tick_base() -> Weight { // Proof Size summary in bytes: - // Measured: `603` - // Estimated: `4068` - // Minimum execution time: 11_859_000 picoseconds. - Weight::from_parts(12_214_000, 4068) + // Measured: `441` + // Estimated: `1516` + // Minimum execution time: 9_171_000 picoseconds. + Weight::from_parts(9_766_000, 1516) .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) @@ -889,8 +883,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_864_000 picoseconds. - Weight::from_parts(6_231_000, 1526) + // Minimum execution time: 5_878_000 picoseconds. + Weight::from_parts(6_266_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } From 884c0779ec18fdffc05b69fe40c8456869ba922f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 31 May 2024 18:55:09 +0000 Subject: [PATCH 44/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::assigner_on_demand --- .../runtime_parachains_assigner_on_demand.rs | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs index acd1834f79ed..bc8201180fc6 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `runtime_parachains::assigner_on_demand` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-03-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-h2rr8wx7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024 // Executed Command: @@ -50,6 +50,10 @@ pub struct WeightInfo(PhantomData); impl runtime_parachains::assigner_on_demand::WeightInfo for WeightInfo { /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::ParaIdAffinity` (r:1 w:0) /// Proof: `OnDemandAssignmentProvider::ParaIdAffinity` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::FreeEntries` (r:1 w:1) @@ -57,19 +61,23 @@ impl runtime_parachains::assigner_on_demand::WeightInfo /// The range of component `s` is `[1, 9999]`. fn place_order_keep_alive(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `218 + s * (8 ±0)` - // Estimated: `3681 + s * (8 ±0)` - // Minimum execution time: 21_396_000 picoseconds. - Weight::from_parts(20_585_695, 0) - .saturating_add(Weight::from_parts(0, 3681)) - // Standard Error: 127 - .saturating_add(Weight::from_parts(20_951, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `270 + s * (8 ±0)` + // Estimated: `3733 + s * (8 ±0)` + // Minimum execution time: 29_427_000 picoseconds. + Weight::from_parts(26_756_913, 0) + .saturating_add(Weight::from_parts(0, 3733)) + // Standard Error: 121 + .saturating_add(Weight::from_parts(20_849, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 8).saturating_mul(s.into())) } /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::ParaIdAffinity` (r:1 w:0) /// Proof: `OnDemandAssignmentProvider::ParaIdAffinity` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `OnDemandAssignmentProvider::FreeEntries` (r:1 w:1) @@ -77,15 +85,15 @@ impl runtime_parachains::assigner_on_demand::WeightInfo /// The range of component `s` is `[1, 9999]`. fn place_order_allow_death(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `218 + s * (8 ±0)` - // Estimated: `3681 + s * (8 ±0)` - // Minimum execution time: 21_412_000 picoseconds. - Weight::from_parts(19_731_554, 0) - .saturating_add(Weight::from_parts(0, 3681)) - // Standard Error: 128 - .saturating_add(Weight::from_parts(21_055, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) + // Measured: `270 + s * (8 ±0)` + // Estimated: `3733 + s * (8 ±0)` + // Minimum execution time: 29_329_000 picoseconds. + Weight::from_parts(26_415_340, 0) + .saturating_add(Weight::from_parts(0, 3733)) + // Standard Error: 129 + .saturating_add(Weight::from_parts(20_909, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 8).saturating_mul(s.into())) } } From db2bb279fd64da58508d5a616b7a188f675ad188 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 21:17:48 +0200 Subject: [PATCH 45/67] Add missing benchmark --- substrate/frame/broker/src/benchmarking.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 129a81c876ad..9822217bd007 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -902,6 +902,21 @@ mod benches { Ok(()) } + #[benchmark] + fn notify_revenue() -> Result<(), BenchmarkError> { + let admin_origin = + T::AdminOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + #[extrinsic_call] + _( + admin_origin as T::RuntimeOrigin, + OnDemandRevenueRecord { until: 100u32.into(), amount: 100u32.into() }, + ); + + assert!(RevenueInbox::::take().is_some()); + Ok(()) + } + #[benchmark] fn do_tick_base() -> Result<(), BenchmarkError> { setup_and_start_sale::()?; From 7dd59f618ebcb35c6bd535d65adca10a7c1c4c17 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 31 May 2024 22:02:11 +0200 Subject: [PATCH 46/67] Add stub weights --- substrate/frame/broker/src/weights.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index c2fb13d22f49..e6f56d9f776a 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -75,6 +75,7 @@ pub trait WeightInfo { fn process_core_schedule() -> Weight; fn request_revenue_info_at() -> Weight; fn notify_core_count() -> Weight; + fn notify_revenue() -> Weight; fn do_tick_base() -> Weight; fn swap_leases() -> Weight; } @@ -445,6 +446,9 @@ impl WeightInfo for SubstrateWeight { // Minimum execution time: 121_000 picoseconds. Weight::from_parts(135_000, 0) } + + fn notify_revenue() -> Weight { Weight::zero() } + /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) fn notify_core_count() -> Weight { @@ -860,6 +864,9 @@ impl WeightInfo for () { Weight::from_parts(1_863_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + + fn notify_revenue() -> Weight { Weight::zero() } + /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) From b794eecf8d1df406de40b66b1801db38fce678ce Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 31 May 2024 21:23:10 +0000 Subject: [PATCH 47/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_broker --- substrate/frame/broker/src/weights.rs | 274 +++++++++++++------------- 1 file changed, 142 insertions(+), 132 deletions(-) diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index e6f56d9f776a..38d771bda3fc 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -89,8 +89,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_891_000 picoseconds. - Weight::from_parts(2_006_000, 0) + // Minimum execution time: 2_104_000 picoseconds. + Weight::from_parts(2_259_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -99,8 +99,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 16_842_000 picoseconds. - Weight::from_parts(17_517_000, 7496) + // Minimum execution time: 16_734_000 picoseconds. + Weight::from_parts(17_465_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -110,8 +110,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 15_553_000 picoseconds. - Weight::from_parts(15_997_000, 7496) + // Minimum execution time: 15_652_000 picoseconds. + Weight::from_parts(16_269_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -121,8 +121,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 8_671_000 picoseconds. - Weight::from_parts(9_110_000, 1526) + // Minimum execution time: 9_158_000 picoseconds. + Weight::from_parts(9_330_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -145,10 +145,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 26_243_000 picoseconds. - Weight::from_parts(46_796_897, 8499) - // Standard Error: 452 - .saturating_add(Weight::from_parts(2_457, 0).saturating_mul(n.into())) + // Minimum execution time: 27_192_000 picoseconds. + Weight::from_parts(48_975_643, 8499) + // Standard Error: 487 + .saturating_add(Weight::from_parts(2_649, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -166,8 +166,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `651` // Estimated: `2136` - // Minimum execution time: 40_723_000 picoseconds. - Weight::from_parts(42_099_000, 2136) + // Minimum execution time: 41_743_000 picoseconds. + Weight::from_parts(43_387_000, 2136) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -189,8 +189,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `769` // Estimated: `4698` - // Minimum execution time: 59_817_000 picoseconds. - Weight::from_parts(61_693_000, 4698) + // Minimum execution time: 66_184_000 picoseconds. + Weight::from_parts(68_407_000, 4698) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -200,8 +200,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 15_389_000 picoseconds. - Weight::from_parts(16_058_000, 3551) + // Minimum execution time: 15_371_000 picoseconds. + Weight::from_parts(16_249_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -211,8 +211,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 16_849_000 picoseconds. - Weight::from_parts(17_517_000, 3551) + // Minimum execution time: 17_371_000 picoseconds. + Weight::from_parts(18_115_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -222,8 +222,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 18_170_000 picoseconds. - Weight::from_parts(18_870_000, 3551) + // Minimum execution time: 18_558_000 picoseconds. + Weight::from_parts(19_404_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -239,8 +239,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 29_200_000 picoseconds. - Weight::from_parts(30_266_000, 4681) + // Minimum execution time: 30_188_000 picoseconds. + Weight::from_parts(31_258_000, 4681) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -258,8 +258,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 34_994_000 picoseconds. - Weight::from_parts(35_593_000, 5996) + // Minimum execution time: 35_572_000 picoseconds. + Weight::from_parts(36_515_000, 5996) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -274,10 +274,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `859` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 63_588_000 picoseconds. - Weight::from_parts(64_705_862, 6196) - // Standard Error: 46_784 - .saturating_add(Weight::from_parts(1_308_067, 0).saturating_mul(m.into())) + // Minimum execution time: 66_746_000 picoseconds. + Weight::from_parts(68_785_896, 6196) + // Standard Error: 47_797 + .saturating_add(Weight::from_parts(879_222, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -289,8 +289,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 39_913_000 picoseconds. - Weight::from_parts(40_718_000, 3593) + // Minimum execution time: 42_179_000 picoseconds. + Weight::from_parts(42_844_000, 3593) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -302,8 +302,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 29_085_000 picoseconds. - Weight::from_parts(32_115_000, 3551) + // Minimum execution time: 33_451_000 picoseconds. + Weight::from_parts(36_982_000, 3551) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -317,8 +317,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 38_143_000 picoseconds. - Weight::from_parts(46_943_000, 3533) + // Minimum execution time: 42_235_000 picoseconds. + Weight::from_parts(50_230_000, 3533) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -334,8 +334,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `995` // Estimated: `3593` - // Minimum execution time: 46_646_000 picoseconds. - Weight::from_parts(53_739_000, 3593) + // Minimum execution time: 52_819_000 picoseconds. + Weight::from_parts(61_257_000, 3593) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -347,8 +347,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 25_755_000 picoseconds. - Weight::from_parts(29_195_000, 4698) + // Minimum execution time: 33_923_000 picoseconds. + Weight::from_parts(39_095_000, 4698) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -357,8 +357,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_593_000 picoseconds. - Weight::from_parts(3_877_345, 0) + // Minimum execution time: 3_811_000 picoseconds. + Weight::from_parts(4_130_498, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -367,8 +367,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_207_000 picoseconds. - Weight::from_parts(6_626_616, 1487) + // Minimum execution time: 6_285_000 picoseconds. + Weight::from_parts(6_753_434, 1487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -386,8 +386,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `829` // Estimated: `3593` - // Minimum execution time: 45_425_000 picoseconds. - Weight::from_parts(46_703_000, 3593) + // Minimum execution time: 46_390_000 picoseconds. + Weight::from_parts(47_241_000, 3593) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -402,14 +402,12 @@ impl WeightInfo for SubstrateWeight { /// Storage: `Broker::Workplan` (r:0 w:10) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn rotate_sale(n: u32, ) -> Weight { + fn rotate_sale(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `6281` // Estimated: `8499` - // Minimum execution time: 34_627_000 picoseconds. - Weight::from_parts(35_896_560, 8499) - // Standard Error: 54 - .saturating_add(Weight::from_parts(32, 0).saturating_mul(n.into())) + // Minimum execution time: 35_400_000 picoseconds. + Weight::from_parts(36_674_381, 8499) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(15_u64)) } @@ -421,8 +419,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 6_959_000 picoseconds. - Weight::from_parts(7_343_000, 3493) + // Minimum execution time: 6_941_000 picoseconds. + Weight::from_parts(7_323_000, 3493) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -434,8 +432,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 14_973_000 picoseconds. - Weight::from_parts(15_823_000, 4681) + // Minimum execution time: 15_457_000 picoseconds. + Weight::from_parts(16_267_000, 4681) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -443,20 +441,27 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 121_000 picoseconds. - Weight::from_parts(135_000, 0) + // Minimum execution time: 120_000 picoseconds. + Weight::from_parts(137_000, 0) } - - fn notify_revenue() -> Weight { Weight::zero() } - /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) fn notify_core_count() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_700_000 picoseconds. - Weight::from_parts(1_863_000, 0) + // Minimum execution time: 1_879_000 picoseconds. + Weight::from_parts(2_061_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Broker::RevenueInbox` (r:0 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn notify_revenue() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_938_000 picoseconds. + Weight::from_parts(2_098_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -471,8 +476,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `441` // Estimated: `1516` - // Minimum execution time: 9_171_000 picoseconds. - Weight::from_parts(9_766_000, 1516) + // Minimum execution time: 9_353_000 picoseconds. + Weight::from_parts(9_780_000, 1516) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -482,8 +487,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_878_000 picoseconds. - Weight::from_parts(6_266_000, 1526) + // Minimum execution time: 6_112_000 picoseconds. + Weight::from_parts(6_258_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -497,8 +502,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_891_000 picoseconds. - Weight::from_parts(2_006_000, 0) + // Minimum execution time: 2_104_000 picoseconds. + Weight::from_parts(2_259_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -507,8 +512,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 16_842_000 picoseconds. - Weight::from_parts(17_517_000, 7496) + // Minimum execution time: 16_734_000 picoseconds. + Weight::from_parts(17_465_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -518,8 +523,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 15_553_000 picoseconds. - Weight::from_parts(15_997_000, 7496) + // Minimum execution time: 15_652_000 picoseconds. + Weight::from_parts(16_269_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -529,8 +534,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 8_671_000 picoseconds. - Weight::from_parts(9_110_000, 1526) + // Minimum execution time: 9_158_000 picoseconds. + Weight::from_parts(9_330_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -553,10 +558,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 26_243_000 picoseconds. - Weight::from_parts(46_796_897, 8499) - // Standard Error: 452 - .saturating_add(Weight::from_parts(2_457, 0).saturating_mul(n.into())) + // Minimum execution time: 27_192_000 picoseconds. + Weight::from_parts(48_975_643, 8499) + // Standard Error: 487 + .saturating_add(Weight::from_parts(2_649, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -574,8 +579,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `651` // Estimated: `2136` - // Minimum execution time: 40_723_000 picoseconds. - Weight::from_parts(42_099_000, 2136) + // Minimum execution time: 41_743_000 picoseconds. + Weight::from_parts(43_387_000, 2136) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -597,8 +602,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `769` // Estimated: `4698` - // Minimum execution time: 59_817_000 picoseconds. - Weight::from_parts(61_693_000, 4698) + // Minimum execution time: 66_184_000 picoseconds. + Weight::from_parts(68_407_000, 4698) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -608,8 +613,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 15_389_000 picoseconds. - Weight::from_parts(16_058_000, 3551) + // Minimum execution time: 15_371_000 picoseconds. + Weight::from_parts(16_249_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -619,8 +624,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 16_849_000 picoseconds. - Weight::from_parts(17_517_000, 3551) + // Minimum execution time: 17_371_000 picoseconds. + Weight::from_parts(18_115_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -630,8 +635,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 18_170_000 picoseconds. - Weight::from_parts(18_870_000, 3551) + // Minimum execution time: 18_558_000 picoseconds. + Weight::from_parts(19_404_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -647,8 +652,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 29_200_000 picoseconds. - Weight::from_parts(30_266_000, 4681) + // Minimum execution time: 30_188_000 picoseconds. + Weight::from_parts(31_258_000, 4681) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -666,8 +671,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 34_994_000 picoseconds. - Weight::from_parts(35_593_000, 5996) + // Minimum execution time: 35_572_000 picoseconds. + Weight::from_parts(36_515_000, 5996) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -682,10 +687,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `859` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 63_588_000 picoseconds. - Weight::from_parts(64_705_862, 6196) - // Standard Error: 46_784 - .saturating_add(Weight::from_parts(1_308_067, 0).saturating_mul(m.into())) + // Minimum execution time: 66_746_000 picoseconds. + Weight::from_parts(68_785_896, 6196) + // Standard Error: 47_797 + .saturating_add(Weight::from_parts(879_222, 0).saturating_mul(m.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -697,8 +702,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 39_913_000 picoseconds. - Weight::from_parts(40_718_000, 3593) + // Minimum execution time: 42_179_000 picoseconds. + Weight::from_parts(42_844_000, 3593) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -710,8 +715,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 29_085_000 picoseconds. - Weight::from_parts(32_115_000, 3551) + // Minimum execution time: 33_451_000 picoseconds. + Weight::from_parts(36_982_000, 3551) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -725,8 +730,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 38_143_000 picoseconds. - Weight::from_parts(46_943_000, 3533) + // Minimum execution time: 42_235_000 picoseconds. + Weight::from_parts(50_230_000, 3533) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -742,8 +747,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `995` // Estimated: `3593` - // Minimum execution time: 46_646_000 picoseconds. - Weight::from_parts(53_739_000, 3593) + // Minimum execution time: 52_819_000 picoseconds. + Weight::from_parts(61_257_000, 3593) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -755,8 +760,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 25_755_000 picoseconds. - Weight::from_parts(29_195_000, 4698) + // Minimum execution time: 33_923_000 picoseconds. + Weight::from_parts(39_095_000, 4698) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -765,8 +770,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_593_000 picoseconds. - Weight::from_parts(3_877_345, 0) + // Minimum execution time: 3_811_000 picoseconds. + Weight::from_parts(4_130_498, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -775,8 +780,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_207_000 picoseconds. - Weight::from_parts(6_626_616, 1487) + // Minimum execution time: 6_285_000 picoseconds. + Weight::from_parts(6_753_434, 1487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -794,8 +799,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `829` // Estimated: `3593` - // Minimum execution time: 45_425_000 picoseconds. - Weight::from_parts(46_703_000, 3593) + // Minimum execution time: 46_390_000 picoseconds. + Weight::from_parts(47_241_000, 3593) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -810,14 +815,12 @@ impl WeightInfo for () { /// Storage: `Broker::Workplan` (r:0 w:10) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn rotate_sale(n: u32, ) -> Weight { + fn rotate_sale(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `6281` // Estimated: `8499` - // Minimum execution time: 34_627_000 picoseconds. - Weight::from_parts(35_896_560, 8499) - // Standard Error: 54 - .saturating_add(Weight::from_parts(32, 0).saturating_mul(n.into())) + // Minimum execution time: 35_400_000 picoseconds. + Weight::from_parts(36_674_381, 8499) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(15_u64)) } @@ -829,8 +832,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 6_959_000 picoseconds. - Weight::from_parts(7_343_000, 3493) + // Minimum execution time: 6_941_000 picoseconds. + Weight::from_parts(7_323_000, 3493) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -842,8 +845,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 14_973_000 picoseconds. - Weight::from_parts(15_823_000, 4681) + // Minimum execution time: 15_457_000 picoseconds. + Weight::from_parts(16_267_000, 4681) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -851,8 +854,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 121_000 picoseconds. - Weight::from_parts(135_000, 0) + // Minimum execution time: 120_000 picoseconds. + Weight::from_parts(137_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -860,13 +863,20 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_700_000 picoseconds. - Weight::from_parts(1_863_000, 0) + // Minimum execution time: 1_879_000 picoseconds. + Weight::from_parts(2_061_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Broker::RevenueInbox` (r:0 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn notify_revenue() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_938_000 picoseconds. + Weight::from_parts(2_098_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - - fn notify_revenue() -> Weight { Weight::zero() } - /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) @@ -879,8 +889,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `441` // Estimated: `1516` - // Minimum execution time: 9_171_000 picoseconds. - Weight::from_parts(9_766_000, 1516) + // Minimum execution time: 9_353_000 picoseconds. + Weight::from_parts(9_780_000, 1516) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -890,8 +900,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_878_000 picoseconds. - Weight::from_parts(6_266_000, 1526) + // Minimum execution time: 6_112_000 picoseconds. + Weight::from_parts(6_258_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } From 3d67f5de26782807e7a7dbfa5dc03527a71dde87 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 1 Jun 2024 10:00:43 +0200 Subject: [PATCH 48/67] Sort out weights mess --- .../parachains/src/coretime/benchmarking.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 2 +- .../src/weights/runtime_common_coretime.rs | 106 ------------------ .../weights/runtime_parachains_coretime.rs | 75 +++++++++---- 4 files changed, 54 insertions(+), 131 deletions(-) delete mode 100644 polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index 552d1fd543fe..1bf90c533c86 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! On demand assigner pallet benchmarking. +//! Coretime pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 5ace73fdc875..137191e3dcbb 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1708,13 +1708,13 @@ mod benches { // the that path resolves correctly in the generated file. [runtime_common::assigned_slots, AssignedSlots] [runtime_common::auctions, Auctions] - [runtime_common::coretime, Coretime] [runtime_common::crowdloan, Crowdloan] [runtime_common::claims, Claims] [runtime_common::identity_migrator, IdentityMigrator] [runtime_common::slots, Slots] [runtime_common::paras_registrar, Registrar] [runtime_parachains::configuration, Configuration] + [runtime_parachains::coretime, Coretime] [runtime_parachains::hrmp, Hrmp] [runtime_parachains::disputes, ParasDisputes] [runtime_parachains::inclusion, ParaInclusion] diff --git a/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs deleted file mode 100644 index 876635862d2d..000000000000 --- a/polkadot/runtime/rococo/src/weights/runtime_common_coretime.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot 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. - -// Polkadot 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 Polkadot. If not, see . - -//! Autogenerated weights for `runtime_common::coretime` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 - -// Executed Command: -// target/production/polkadot -// benchmark -// pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=runtime_common::coretime -// --chain=rococo-dev -// --header=./polkadot/file_header.txt -// --output=./polkadot/runtime/rococo/src/weights/ - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `runtime_common::coretime`. -pub struct WeightInfo(PhantomData); -impl runtime_common::coretime::WeightInfo for WeightInfo { - /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) - /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `System::Account` (r:1 w:0) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) - /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) - /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) - /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn request_revenue_at() -> Weight { - // Proof Size summary in bytes: - // Measured: `2963` - // Estimated: `6428` - // Minimum execution time: 36_613_000 picoseconds. - Weight::from_parts(37_637_000, 0) - .saturating_add(Weight::from_parts(0, 6428)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(3)) - } - /// Storage: `Configuration::PendingConfigs` (r:1 w:1) - /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) - /// Proof: `Configuration::BypassConsistencyCheck` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `ParasShared::CurrentSessionIndex` (r:1 w:0) - /// Proof: `ParasShared::CurrentSessionIndex` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn request_core_count() -> Weight { - // Proof Size summary in bytes: - // Measured: `151` - // Estimated: `1636` - // Minimum execution time: 7_527_000 picoseconds. - Weight::from_parts(7_784_000, 0) - .saturating_add(Weight::from_parts(0, 1636)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: `CoretimeAssignmentProvider::CoreDescriptors` (r:1 w:1) - /// Proof: `CoretimeAssignmentProvider::CoreDescriptors` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `CoretimeAssignmentProvider::CoreSchedules` (r:0 w:1) - /// Proof: `CoretimeAssignmentProvider::CoreSchedules` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `s` is `[1, 100]`. - fn assign_core(s: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `180` - // Estimated: `3645` - // Minimum execution time: 9_220_000 picoseconds. - Weight::from_parts(9_905_773, 0) - .saturating_add(Weight::from_parts(0, 3645)) - // Standard Error: 257 - .saturating_add(Weight::from_parts(12_400, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - } -} diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs index b4f893f1bb3e..f64a886356c1 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_coretime.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Autogenerated weights for `runtime_parachains::coretime` +//! Autogenerated weights for `runtime_common::coretime` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-r43aesjn-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 // Executed Command: @@ -45,33 +45,62 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -use runtime_parachains::configuration::{self, WeightInfo as ConfigWeightInfo}; - /// Weight functions for `runtime_common::coretime`. pub struct WeightInfo(PhantomData); -impl runtime_parachains::coretime::WeightInfo for WeightInfo { +impl runtime_parachains::coretime::WeightInfo for WeightInfo { + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn request_revenue_at() -> Weight { + // Proof Size summary in bytes: + // Measured: `2963` + // Estimated: `6428` + // Minimum execution time: 36_613_000 picoseconds. + Weight::from_parts(37_637_000, 0) + .saturating_add(Weight::from_parts(0, 6428)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Configuration::PendingConfigs` (r:1 w:1) + /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) + /// Proof: `Configuration::BypassConsistencyCheck` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParasShared::CurrentSessionIndex` (r:1 w:0) + /// Proof: `ParasShared::CurrentSessionIndex` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn request_core_count() -> Weight { - ::WeightInfo::set_config_with_u32() + // Proof Size summary in bytes: + // Measured: `151` + // Estimated: `1636` + // Minimum execution time: 7_527_000 picoseconds. + Weight::from_parts(7_784_000, 0) + .saturating_add(Weight::from_parts(0, 1636)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `CoreTimeAssignmentProvider::CoreDescriptors` (r:1 w:1) - /// Proof: `CoreTimeAssignmentProvider::CoreDescriptors` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `CoreTimeAssignmentProvider::CoreSchedules` (r:0 w:1) - /// Proof: `CoreTimeAssignmentProvider::CoreSchedules` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CoretimeAssignmentProvider::CoreDescriptors` (r:1 w:1) + /// Proof: `CoretimeAssignmentProvider::CoreDescriptors` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CoretimeAssignmentProvider::CoreSchedules` (r:0 w:1) + /// Proof: `CoretimeAssignmentProvider::CoreSchedules` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `s` is `[1, 100]`. fn assign_core(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `76` - // Estimated: `3541` - // Minimum execution time: 6_275_000 picoseconds. - Weight::from_parts(6_883_543, 0) - .saturating_add(Weight::from_parts(0, 3541)) - // Standard Error: 202 - .saturating_add(Weight::from_parts(15_028, 0).saturating_mul(s.into())) + // Measured: `180` + // Estimated: `3645` + // Minimum execution time: 9_220_000 picoseconds. + Weight::from_parts(9_905_773, 0) + .saturating_add(Weight::from_parts(0, 3645)) + // Standard Error: 257 + .saturating_add(Weight::from_parts(12_400, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - fn request_revenue_at() -> frame_support::weights::Weight { - ::WeightInfo::set_config_with_u32() - } - } From f6c23cc1505c51f9bb9904bf7c8e97583c2c0f1e Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Sat, 1 Jun 2024 09:18:43 +0000 Subject: [PATCH 49/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::coretime --- .../weights/runtime_parachains_coretime.rs | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs index 4aa85595f674..eb70a24da19d 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_coretime.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `runtime_parachains::coretime` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-02-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024 // Executed Command: @@ -48,6 +48,28 @@ use core::marker::PhantomData; /// Weight functions for `runtime_parachains::coretime`. pub struct WeightInfo(PhantomData); impl runtime_parachains::coretime::WeightInfo for WeightInfo { + /// Storage: `OnDemandAssignmentProvider::Revenue` (r:1 w:1) + /// Proof: `OnDemandAssignmentProvider::Revenue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Dmp::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `Dmp::DeliveryFeeFactor` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmPallet::SupportedVersion` (r:1 w:0) + /// Proof: `XcmPallet::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueues` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueues` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Dmp::DownwardMessageQueueHeads` (r:1 w:1) + /// Proof: `Dmp::DownwardMessageQueueHeads` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn request_revenue_at() -> Weight { + // Proof Size summary in bytes: + // Measured: `2930` + // Estimated: `6395` + // Minimum execution time: 34_947_000 picoseconds. + Weight::from_parts(35_550_000, 0) + .saturating_add(Weight::from_parts(0, 6395)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) + } /// Storage: `Configuration::PendingConfigs` (r:1 w:1) /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) @@ -58,8 +80,8 @@ impl runtime_parachains::coretime::WeightInfo for Weigh // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_486_000 picoseconds. - Weight::from_parts(7_889_000, 0) + // Minimum execution time: 7_519_000 picoseconds. + Weight::from_parts(7_803_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -73,13 +95,12 @@ impl runtime_parachains::coretime::WeightInfo for Weigh // Proof Size summary in bytes: // Measured: `147` // Estimated: `3612` - // Minimum execution time: 9_409_000 picoseconds. - Weight::from_parts(10_177_115, 0) + // Minimum execution time: 9_697_000 picoseconds. + Weight::from_parts(10_610_219, 0) .saturating_add(Weight::from_parts(0, 3612)) - // Standard Error: 259 - .saturating_add(Weight::from_parts(13_932, 0).saturating_mul(s.into())) + // Standard Error: 732 + .saturating_add(Weight::from_parts(10_364, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - fn request_revenue_at() -> frame_support::weights::Weight { todo!() } } From c3468bb4f8e782d3fed3ad2311bce047fb6bc604 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 1 Jun 2024 12:21:47 +0200 Subject: [PATCH 50/67] Add prdoc --- prdoc/pr_3940.prdoc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 prdoc/pr_3940.prdoc diff --git a/prdoc/pr_3940.prdoc b/prdoc/pr_3940.prdoc new file mode 100644 index 000000000000..3c99f28e3fa1 --- /dev/null +++ b/prdoc/pr_3940.prdoc @@ -0,0 +1,19 @@ +# 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: RFC-5: Add request revenue info + +doc: + - audience: Runtime Dev + description: | + Parially implemented RFC-5 in terms of revenue requests and notifications + +crates: + - name: polkadot-runtime-parachains + bump: major + - name: rococo-runtime + bump: major + - name: westend-runtime + bump: major + - name: pallet-broker + bump: minor From 1b60cbf96b3c4133f6dcea1e068669553cc84391 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 1 Jun 2024 12:24:08 +0200 Subject: [PATCH 51/67] Fix prdoc --- prdoc/pr_3940.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_3940.prdoc b/prdoc/pr_3940.prdoc index 3c99f28e3fa1..58557684eb2f 100644 --- a/prdoc/pr_3940.prdoc +++ b/prdoc/pr_3940.prdoc @@ -1,7 +1,7 @@ # 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: RFC-5: Add request revenue info +title: "RFC-5: Add request revenue info" doc: - audience: Runtime Dev From 832ee90b6616db03d7d187cb33a7024abb8c765c Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 1 Jun 2024 14:46:36 +0200 Subject: [PATCH 52/67] Add constant docs --- polkadot/runtime/rococo/constants/src/lib.rs | 2 ++ polkadot/runtime/westend/constants/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index eeb875b8359a..076e8ccae744 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -125,6 +125,8 @@ pub mod system_parachain { /// Coretime constants pub mod coretime { /// Coretime timeslice period in blocks + /// WARNING: This constant is used accross chains, so additional care should be taken + /// when changing it. #[cfg(feature = "fast-runtime")] pub const TIMESLICE_PERIOD: u32 = 10; #[cfg(not(feature = "fast-runtime"))] diff --git a/polkadot/runtime/westend/constants/src/lib.rs b/polkadot/runtime/westend/constants/src/lib.rs index cd8568f7ed87..a71703663c13 100644 --- a/polkadot/runtime/westend/constants/src/lib.rs +++ b/polkadot/runtime/westend/constants/src/lib.rs @@ -120,6 +120,8 @@ pub mod system_parachain { /// Coretime constants pub mod coretime { /// Coretime timeslice period in blocks + /// WARNING: This constant is used accross chains, so additional care should be taken + /// when changing it. #[cfg(feature = "fast-runtime")] pub const TIMESLICE_PERIOD: u32 = 10; #[cfg(not(feature = "fast-runtime"))] From ddd9f1e218d90a586ba57a9b540133446573cc7b Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Tue, 4 Jun 2024 14:57:51 +0200 Subject: [PATCH 53/67] Properly propagate `fast-runtime` feature --- .../parachains/runtimes/coretime/coretime-rococo/Cargo.toml | 4 +++- .../parachains/runtimes/coretime/coretime-westend/Cargo.toml | 4 +++- polkadot/runtime/westend/constants/Cargo.toml | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index dc99fe331f78..a291483f30a3 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -199,4 +199,6 @@ try-runtime = [ "sp-runtime/try-runtime", ] -fast-runtime = [] +fast-runtime = [ + "rococo-runtime-constants/fast-runtime", +] diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 78018537f5d3..4d3586d8cb00 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -196,4 +196,6 @@ try-runtime = [ "sp-runtime/try-runtime", ] -fast-runtime = [] +fast-runtime = [ + "westend-runtime-constants/fast-runtime", +] diff --git a/polkadot/runtime/westend/constants/Cargo.toml b/polkadot/runtime/westend/constants/Cargo.toml index 81df8f4f024d..cdaf57c631ae 100644 --- a/polkadot/runtime/westend/constants/Cargo.toml +++ b/polkadot/runtime/westend/constants/Cargo.toml @@ -34,3 +34,6 @@ std = [ "xcm-builder/std", "xcm/std", ] + +# Set timing constants (e.g. session period) to faster versions to speed up testing. +fast-runtime = [] From d59f8eca45f977692e06593efd7f1c66f27cd7ed Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Tue, 4 Jun 2024 14:58:30 +0200 Subject: [PATCH 54/67] Implement parachain-side end of revenue teleport --- substrate/frame/broker/src/tick_impls.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index a73c92749c49..df89376fb4eb 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -16,7 +16,11 @@ // limitations under the License. use super::*; -use frame_support::{pallet_prelude::*, weights::WeightMeter}; +use frame_support::{ + pallet_prelude::*, + traits::{fungible::Balanced, DefensiveResult}, + weights::WeightMeter, +}; use sp_arithmetic::traits::{One, SaturatedConversion, Saturating, Zero}; use sp_runtime::traits::ConvertBack; use sp_std::{vec, vec::Vec}; @@ -104,6 +108,11 @@ impl Pallet { InstaPoolHistory::::remove(when); return true } + + // Mint revenue amount on our end of the teleport + let revenue_imbalance = T::Currency::issue(revenue); + T::Currency::resolve(&Self::account_id(), revenue_imbalance).defensive_ok(); + let mut r = InstaPoolHistory::::get(when).unwrap_or_default(); if r.maybe_payout.is_some() { Self::deposit_event(Event::::HistoryIgnored { when, revenue }); From 3fb3f6aa715a8cf9eb27310b5ffa23c10e188618 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Tue, 4 Jun 2024 22:44:20 +0200 Subject: [PATCH 55/67] Fix test values and add explanation --- substrate/frame/broker/src/tests.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index e953afd6dc3c..78b7ad3e719f 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -449,6 +449,18 @@ fn renewals_affect_price() { }); } +// In the following payouts tests, assertions of the pot balances currently account for the fact +// that the pot is topped up twice: first, when the credits are purchased, the value is transferred +// from the buyer's account to the pot (and currently that doesn't really result in any credits +// being acquired on the relay chain as the credit system is not implemented yet), and second, +// when the revenue is teleported from the relay chain to the parachain, thus minting the revenue +// value into the pot. Thus, current pot assertions are not correct and should be fixed back when +// the credit system is implemented. +// +// The other way to handle that wold be burning the balance transferred from the buyer's account to +// the pot in `do_purchase_credit()`, but, as it would affect the code that will go into +// production, it's more error prone, so handling incorrect pot balance is the lesser evil. + #[test] fn instapool_payouts_work() { TestExt::new().endow(1, 1000).execute_with(|| { @@ -462,7 +474,7 @@ fn instapool_payouts_work() { advance_to(8); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(11); - assert_eq!(pot(), 14); + assert_eq!(pot(), 24); assert_eq!(revenue(), 106); // Cannot claim for 0 timeslices. @@ -470,7 +482,7 @@ fn instapool_payouts_work() { // Revenue can be claimed. assert_ok!(Broker::do_claim_revenue(region, 100)); - assert_eq!(pot(), 10); + assert_eq!(pot(), 20); assert_eq!(balance(2), 4); }); } @@ -496,7 +508,7 @@ fn instapool_partial_core_payouts_work() { assert_eq!(revenue(), 120); assert_eq!(balance(2), 5); assert_eq!(balance(3), 15); - assert_eq!(pot(), 0); + assert_eq!(pot(), 40); }); } @@ -518,17 +530,17 @@ fn instapool_core_payouts_work_with_partitioned_region() { advance_to(8); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(11); - assert_eq!(pot(), 20); + assert_eq!(pot(), 30); assert_eq!(revenue(), 100); assert_ok!(Broker::do_claim_revenue(region1, 100)); - assert_eq!(pot(), 10); + assert_eq!(pot(), 20); assert_eq!(balance(2), 10); advance_to(12); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(15); - assert_eq!(pot(), 10); + assert_eq!(pot(), 30); assert_ok!(Broker::do_claim_revenue(region2, 100)); - assert_eq!(pot(), 0); + assert_eq!(pot(), 20); // The balance of account `2` remains unchanged. assert_eq!(balance(2), 10); assert_eq!(balance(3), 10); From 4be7536319f330f591607cd37f5517164a0f2e91 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 5 Jun 2024 13:07:46 +0200 Subject: [PATCH 56/67] Address discussions --- .../parachains/src/assigner_on_demand/mod.rs | 2 +- .../src/assigner_on_demand/tests.rs | 20 +++++++++---------- .../runtime/parachains/src/coretime/mod.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index b40b17f1533d..a24ac80684b7 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -637,7 +637,7 @@ where } /// Collect the revenue from the `when` blockheight - pub fn revenue_until(when: BlockNumberFor) -> BalanceOf { + pub fn claim_revenue_until(when: BlockNumberFor) -> BalanceOf { let now = >::block_number(); let mut amount: BalanceOf = BalanceOf::::zero(); Revenue::::mutate(|revenue| { diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs index ebe72996c7d1..6465c515ff8b 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs @@ -359,8 +359,8 @@ fn pop_assignment_for_core_works() { // Add enough assignments to the order queue. for _ in 0..2 { - place_order_run_to_101(para_a); - place_order_run_to_101(para_b); + place_order(para_a); + place_order(para_b); } // Popped assignments should be for the correct paras and cores @@ -732,7 +732,7 @@ fn revenue_information_fetching_works() { schedule_blank_para(para_a, ParaKind::Parathread); // Mock assigner sets max revenue history to 10. run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(10); + let revenue = OnDemandAssigner::claim_revenue_until(10); // No revenue should be recorded. assert_eq!(revenue, 0); @@ -740,19 +740,19 @@ fn revenue_information_fetching_works() { // Place one order place_order_run_to_blocknumber(para_a, Some(11)); let revenue = OnDemandAssigner::get_revenue(); - let amt = OnDemandAssigner::revenue_until(11); + let amt = OnDemandAssigner::claim_revenue_until(11); // Revenue until the current block is still zero as "until" is non-inclusive assert_eq!(amt, 0); - let amt = OnDemandAssigner::revenue_until(12); + let amt = OnDemandAssigner::claim_revenue_until(12); // Revenue for a single order should be recorded and shouldn't have been pruned by the // previous call assert_eq!(amt, revenue[0]); run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(13); + let revenue = OnDemandAssigner::claim_revenue_until(13); // No revenue should be recorded. assert_eq!(revenue, 0); @@ -767,7 +767,7 @@ fn revenue_information_fetching_works() { run_to_block(14, |n| if n == 14 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(15); + let revenue = OnDemandAssigner::claim_revenue_until(15); // All 3 orders should be accounted for. assert_eq!(revenue, 30_000); @@ -775,13 +775,13 @@ fn revenue_information_fetching_works() { // Place one order place_order_run_to_blocknumber(para_a, Some(16)); - let revenue = OnDemandAssigner::revenue_until(15); + let revenue = OnDemandAssigner::claim_revenue_until(15); // Order is not in range of the revenue_until call assert_eq!(revenue, 0); run_to_block(20, |n| if n == 20 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::revenue_until(21); + let revenue = OnDemandAssigner::claim_revenue_until(21); assert_eq!(revenue, 10_000); // Make sure overdue revenue is accumulated @@ -789,7 +789,7 @@ fn revenue_information_fetching_works() { run_to_block(i, |n| if n % 10 == 0 { Some(Default::default()) } else { None }); place_order(para_a); } - let revenue = OnDemandAssigner::revenue_until(36); + let revenue = OnDemandAssigner::claim_revenue_until(36); assert_eq!(revenue, 150_000); }); } diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 7f808396af3d..63350d074df6 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -283,7 +283,7 @@ impl Pallet { // When cannot be in the future. ensure!(when_bnf <= now, Error::::RequestedFutureRevenue); - let revenue = >::revenue_until(when_bnf); + let revenue = >::claim_revenue_until(when_bnf); log::debug!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); match TryInto::::try_into(revenue) { Ok(raw_revenue) => { From 4e30a57aae3528b9f243db8d5f4c0f0abd86b2ac Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 5 Jun 2024 14:04:53 +0200 Subject: [PATCH 57/67] Rename `assigner_on_demand` to `on_demand` --- .../parachains/src/assigner_coretime/mod.rs | 14 +- .../parachains/src/assigner_coretime/tests.rs | 12 +- .../parachains/src/coretime/benchmarking.rs | 6 +- .../runtime/parachains/src/coretime/mod.rs | 8 +- polkadot/runtime/parachains/src/lib.rs | 2 +- polkadot/runtime/parachains/src/mock.rs | 13 +- .../benchmarking.rs | 2 +- .../migration.rs | 10 +- .../mock_helpers.rs | 0 .../{assigner_on_demand => on_demand}/mod.rs | 2 +- .../tests.rs | 237 ++++++++---------- .../types.rs | 0 polkadot/runtime/rococo/src/lib.rs | 16 +- polkadot/runtime/rococo/src/weights/mod.rs | 2 +- ...and.rs => runtime_parachains_on_demand.rs} | 8 +- polkadot/runtime/westend/src/lib.rs | 14 +- polkadot/runtime/westend/src/weights/mod.rs | 2 +- ...and.rs => runtime_parachains_on_demand.rs} | 8 +- 18 files changed, 159 insertions(+), 197 deletions(-) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/benchmarking.rs (97%) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/migration.rs (94%) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/mock_helpers.rs (100%) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/mod.rs (99%) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/tests.rs (72%) rename polkadot/runtime/parachains/src/{assigner_on_demand => on_demand}/types.rs (100%) rename polkadot/runtime/rococo/src/weights/{runtime_parachains_assigner_on_demand.rs => runtime_parachains_on_demand.rs} (94%) rename polkadot/runtime/westend/src/weights/{runtime_parachains_assigner_on_demand.rs => runtime_parachains_on_demand.rs} (94%) diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 1e821dd86846..59c3cb68371f 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -28,7 +28,7 @@ mod mock_helpers; mod tests; use crate::{ - assigner_on_demand, configuration, + configuration, on_demand, paras::AssignCoretime, scheduler::common::{Assignment, AssignmentProvider}, ParaId, @@ -202,10 +202,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: - frame_system::Config + configuration::Config + assigner_on_demand::Config - { - } + pub trait Config: frame_system::Config + configuration::Config + on_demand::Config {} /// Scheduled assignment sets. /// @@ -282,8 +279,7 @@ impl AssignmentProvider> for Pallet { match a_type { CoreAssignment::Idle => None, - CoreAssignment::Pool => - assigner_on_demand::Pallet::::pop_assignment_for_core(core_idx), + CoreAssignment::Pool => on_demand::Pallet::::pop_assignment_for_core(core_idx), CoreAssignment::Task(para_id) => Some(Assignment::Bulk((*para_id).into())), } }) @@ -292,7 +288,7 @@ impl AssignmentProvider> for Pallet { fn report_processed(assignment: Assignment) { match assignment { Assignment::Pool { para_id, core_index } => - assigner_on_demand::Pallet::::report_processed(para_id, core_index), + on_demand::Pallet::::report_processed(para_id, core_index), Assignment::Bulk(_) => {}, } } @@ -305,7 +301,7 @@ impl AssignmentProvider> for Pallet { fn push_back_assignment(assignment: Assignment) { match assignment { Assignment::Pool { para_id, core_index } => - assigner_on_demand::Pallet::::push_back_assignment(para_id, core_index), + on_demand::Pallet::::push_back_assignment(para_id, core_index), Assignment::Bulk(_) => { // Session changes are rough. We just drop assignments that did not make it on a // session boundary. This seems sensible as bulk is region based. Meaning, even if diff --git a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs index f7a024196eda..ded49aa259ca 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/tests.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/tests.rs @@ -20,8 +20,8 @@ use crate::{ assigner_coretime::{mock_helpers::GenesisConfigBuilder, pallet::Error, Schedule}, initializer::SessionChangeNotification, mock::{ - new_test_ext, Balances, CoretimeAssigner, OnDemandAssigner, Paras, ParasShared, - RuntimeOrigin, Scheduler, System, Test, + new_test_ext, Balances, CoretimeAssigner, OnDemand, Paras, ParasShared, RuntimeOrigin, + Scheduler, System, Test, }, paras::{ParaGenesisArgs, ParaKind}, scheduler::common::Assignment, @@ -75,7 +75,7 @@ fn run_to_block( Scheduler::initializer_initialize(b + 1); // Update the spot traffic and revenue on every block. - OnDemandAssigner::on_initialize(b + 1); + OnDemand::on_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); @@ -527,11 +527,7 @@ fn pop_assignment_for_core_works() { schedule_blank_para(para_id, ParaKind::Parathread); Balances::make_free_balance_be(&alice, amt); run_to_block(1, |n| if n == 1 { Some(Default::default()) } else { None }); - assert_ok!(OnDemandAssigner::place_order_allow_death( - RuntimeOrigin::signed(alice), - amt, - para_id - )); + assert_ok!(OnDemand::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id)); // Case 1: Assignment idle assert_ok!(CoretimeAssigner::assign_core( diff --git a/polkadot/runtime/parachains/src/coretime/benchmarking.rs b/polkadot/runtime/parachains/src/coretime/benchmarking.rs index 1bf90c533c86..c8cb31c3b207 100644 --- a/polkadot/runtime/parachains/src/coretime/benchmarking.rs +++ b/polkadot/runtime/parachains/src/coretime/benchmarking.rs @@ -31,15 +31,15 @@ mod benchmarks { #[benchmark] fn request_revenue_at() { let root_origin = ::RuntimeOrigin::root(); - let mhr = ::MaxHistoricalRevenue::get(); + let mhr = ::MaxHistoricalRevenue::get(); frame_system::Pallet::::set_block_number((mhr + 2).into()); let rev: BoundedVec< - <::Currency as frame_support::traits::Currency< + <::Currency as frame_support::traits::Currency< T::AccountId, >>::Balance, T::MaxHistoricalRevenue, > = BoundedVec::try_from((1..=mhr).map(|v| v.into()).collect::>()).unwrap(); - assigner_on_demand::Revenue::::put(rev); + on_demand::Revenue::::put(rev); #[extrinsic_call] _(root_origin as ::RuntimeOrigin, mhr + 1) diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 63350d074df6..754b8312b08b 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -31,8 +31,8 @@ use xcm::prelude::{ use crate::{ assigner_coretime::{self, PartsOf57600}, - assigner_on_demand, initializer::{OnNewSession, SessionChangeNotification}, + on_demand, origin::{ensure_parachain, Origin}, }; @@ -109,9 +109,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: - frame_system::Config + assigner_coretime::Config + assigner_on_demand::Config - { + pub trait Config: frame_system::Config + assigner_coretime::Config + on_demand::Config { type RuntimeOrigin: From<::RuntimeOrigin> + Into::RuntimeOrigin>>; type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -283,7 +281,7 @@ impl Pallet { // When cannot be in the future. ensure!(when_bnf <= now, Error::::RequestedFutureRevenue); - let revenue = >::claim_revenue_until(when_bnf); + let revenue = >::claim_revenue_until(when_bnf); log::debug!(target: LOG_TARGET, "Revenue info requested: {:?}", revenue); match TryInto::::try_into(revenue) { Ok(raw_revenue) => { diff --git a/polkadot/runtime/parachains/src/lib.rs b/polkadot/runtime/parachains/src/lib.rs index 97d6ab74904d..ba1319ce621f 100644 --- a/polkadot/runtime/parachains/src/lib.rs +++ b/polkadot/runtime/parachains/src/lib.rs @@ -24,7 +24,6 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod assigner_coretime; -pub mod assigner_on_demand; pub mod assigner_parachains; pub mod configuration; pub mod coretime; @@ -34,6 +33,7 @@ pub mod hrmp; pub mod inclusion; pub mod initializer; pub mod metrics; +pub mod on_demand; pub mod origin; pub mod paras; pub mod paras_inherent; diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index ce42693841fc..041c0cd10c0c 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -17,10 +17,9 @@ //! Mocks for all the traits. use crate::{ - assigner_coretime, assigner_on_demand, assigner_parachains, configuration, coretime, disputes, - dmp, hrmp, + assigner_coretime, assigner_parachains, configuration, coretime, disputes, dmp, hrmp, inclusion::{self, AggregateMessageOrigin, UmpQueueId}, - initializer, origin, paras, + initializer, on_demand, origin, paras, paras::ParaKind, paras_inherent, scheduler, scheduler::common::AssignmentProvider, @@ -79,7 +78,7 @@ frame_support::construct_runtime!( Scheduler: scheduler, MockAssigner: mock_assigner, ParachainsAssigner: assigner_parachains, - OnDemandAssigner: assigner_on_demand, + OnDemand: on_demand, CoretimeAssigner: assigner_coretime, Coretime: coretime, Initializer: initializer, @@ -411,11 +410,11 @@ parameter_types! { pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } -impl assigner_on_demand::Config for Test { +impl on_demand::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; - type WeightInfo = crate::assigner_on_demand::TestWeightInfo; + type WeightInfo = crate::on_demand::TestWeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; type PalletId = OnDemandPalletId; } @@ -540,7 +539,7 @@ pub mod mock_assigner { // We don't care about core affinity in the test assigner fn report_processed(_assignment: Assignment) {} - // The results of this are tested in assigner_on_demand tests. No need to represent it + // The results of this are tested in on_demand tests. No need to represent it // in the mock assigner. fn push_back_assignment(_assignment: Assignment) {} diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs b/polkadot/runtime/parachains/src/on_demand/benchmarking.rs similarity index 97% rename from polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs rename to polkadot/runtime/parachains/src/on_demand/benchmarking.rs index 779d6f04e396..67c13b9d7417 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs +++ b/polkadot/runtime/parachains/src/on_demand/benchmarking.rs @@ -93,7 +93,7 @@ mod benchmarks { impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext( - crate::assigner_on_demand::mock_helpers::GenesisConfigBuilder::default().build() + crate::on_demand::mock_helpers::GenesisConfigBuilder::default().build() ), crate::mock::Test ); diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/migration.rs b/polkadot/runtime/parachains/src/on_demand/migration.rs similarity index 94% rename from polkadot/runtime/parachains/src/assigner_on_demand/migration.rs rename to polkadot/runtime/parachains/src/on_demand/migration.rs index 50e5e1daf41a..93d0aa75d423 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/migration.rs +++ b/polkadot/runtime/parachains/src/on_demand/migration.rs @@ -47,7 +47,7 @@ mod v0 { mod v1 { use super::*; - use crate::assigner_on_demand::LOG_TARGET; + use crate::on_demand::LOG_TARGET; /// Migration to V1 pub struct UncheckedMigrateToV1(sp_std::marker::PhantomData); @@ -142,7 +142,7 @@ pub type MigrateV0ToV1 = VersionedMigration< #[cfg(test)] mod tests { use super::{v0, v1, UncheckedOnRuntimeUpgrade, Weight}; - use crate::mock::{new_test_ext, MockGenesisConfig, OnDemandAssigner, Test}; + use crate::mock::{new_test_ext, MockGenesisConfig, OnDemand, Test}; use primitives::Id as ParaId; #[test] @@ -159,7 +159,7 @@ mod tests { let old_queue = v0::OnDemandQueue::::get(); assert_eq!(old_queue.len(), 5); // New queue has 0 orders - assert_eq!(OnDemandAssigner::get_queue_status().size(), 0); + assert_eq!(OnDemand::get_queue_status().size(), 0); // For tests, db weight is zero. assert_eq!( @@ -168,10 +168,10 @@ mod tests { ); // New queue has 5 orders - assert_eq!(OnDemandAssigner::get_queue_status().size(), 5); + assert_eq!(OnDemand::get_queue_status().size(), 5); // Compare each entry from the old queue with the entry in the new queue. - old_queue.iter().zip(OnDemandAssigner::get_free_entries().iter()).for_each( + old_queue.iter().zip(OnDemand::get_free_entries().iter()).for_each( |(old_enq, new_enq)| { assert_eq!(old_enq.para_id, new_enq.para_id); }, diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/on_demand/mock_helpers.rs similarity index 100% rename from polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs rename to polkadot/runtime/parachains/src/on_demand/mock_helpers.rs diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/on_demand/mod.rs similarity index 99% rename from polkadot/runtime/parachains/src/assigner_on_demand/mod.rs rename to polkadot/runtime/parachains/src/on_demand/mod.rs index a24ac80684b7..ffdf03b859d9 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/on_demand/mod.rs @@ -66,7 +66,7 @@ use types::{ SpotTrafficCalculationErr, }; -const LOG_TARGET: &str = "runtime::parachains::assigner-on-demand"; +const LOG_TARGET: &str = "runtime::parachains::on-demand"; pub use pallet::*; diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs b/polkadot/runtime/parachains/src/on_demand/tests.rs similarity index 72% rename from polkadot/runtime/parachains/src/assigner_on_demand/tests.rs rename to polkadot/runtime/parachains/src/on_demand/tests.rs index 6465c515ff8b..d6bb10ab7bbc 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/on_demand/tests.rs @@ -17,16 +17,16 @@ use super::*; use crate::{ - assigner_on_demand::{ + initializer::SessionChangeNotification, + mock::{ + new_test_ext, Balances, OnDemand, Paras, ParasShared, RuntimeOrigin, Scheduler, System, + Test, + }, + on_demand::{ mock_helpers::GenesisConfigBuilder, types::{QueueIndex, ReverseQueueIndex}, Error, }, - initializer::SessionChangeNotification, - mock::{ - new_test_ext, Balances, OnDemandAssigner, Paras, ParasShared, RuntimeOrigin, Scheduler, - System, Test, - }, paras::{ParaGenesisArgs, ParaKind}, }; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; @@ -81,7 +81,7 @@ fn run_to_block( Scheduler::initializer_initialize(b + 1); // Update the spot traffic and revenue on every block. - OnDemandAssigner::on_initialize(b + 1); + OnDemand::on_initialize(b + 1); // In the real runtime this is expected to be called by the `InclusionInherent` pallet. Scheduler::free_cores_and_fill_claimqueue(BTreeMap::new(), b + 1); @@ -97,7 +97,7 @@ fn place_order_run_to_blocknumber(para_id: ParaId, blocknumber: Option::SpotPriceHigherThanMaxAmount, ); // Does not work with insufficient balance assert_noop!( - OnDemandAssigner::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id), + OnDemand::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id), BalancesError::::InsufficientBalance ); // Works Balances::make_free_balance_be(&alice, amt); run_to_block(101, |n| if n == 101 { Some(Default::default()) } else { None }); - assert_ok!(OnDemandAssigner::place_order_allow_death( - RuntimeOrigin::signed(alice), - amt, - para_id - )); + assert_ok!(OnDemand::place_order_allow_death(RuntimeOrigin::signed(alice), amt, para_id)); }); } @@ -334,11 +323,7 @@ fn place_order_keep_alive_keeps_alive() { assert!(Paras::is_parathread(para_id)); assert_noop!( - OnDemandAssigner::place_order_keep_alive( - RuntimeOrigin::signed(alice), - max_amt, - para_id - ), + OnDemand::place_order_keep_alive(RuntimeOrigin::signed(alice), max_amt, para_id), BalancesError::::InsufficientBalance ); }); @@ -355,7 +340,7 @@ fn pop_assignment_for_core_works() { run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); // Pop should return none with empty queue - assert_eq!(OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)), None); + assert_eq!(OnDemand::pop_assignment_for_core(CoreIndex(0)), None); // Add enough assignments to the order queue. for _ in 0..2 { @@ -365,19 +350,19 @@ fn pop_assignment_for_core_works() { // Popped assignments should be for the correct paras and cores assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).map(|a| a.para_id()), + OnDemand::pop_assignment_for_core(CoreIndex(0)).map(|a| a.para_id()), Some(para_a) ); assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(1)).map(|a| a.para_id()), + OnDemand::pop_assignment_for_core(CoreIndex(1)).map(|a| a.para_id()), Some(para_b) ); assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).map(|a| a.para_id()), + OnDemand::pop_assignment_for_core(CoreIndex(0)).map(|a| a.para_id()), Some(para_a) ); assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(1)).map(|a| a.para_id()), + OnDemand::pop_assignment_for_core(CoreIndex(1)).map(|a| a.para_id()), Some(para_b) ); }); @@ -398,30 +383,21 @@ fn push_back_assignment_works() { place_order_run_to_101(para_b); // Pop order a - assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), - para_a - ); + assert_eq!(OnDemand::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), para_a); // Para a should have affinity for core 0 - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 1); - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().core_index, CoreIndex(0)); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().core_index, CoreIndex(0)); // Push back order a - OnDemandAssigner::push_back_assignment(para_a, CoreIndex(0)); + OnDemand::push_back_assignment(para_a, CoreIndex(0)); // Para a should have no affinity - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).is_none(), true); + assert_eq!(OnDemand::get_affinity_map(para_a).is_none(), true); // Queue should contain orders a, b. A in front of b. - assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), - para_a - ); - assert_eq!( - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), - para_b - ); + assert_eq!(OnDemand::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), para_a); + assert_eq!(OnDemand::pop_assignment_for_core(CoreIndex(0)).unwrap().para_id(), para_b); }); } @@ -437,8 +413,8 @@ fn affinity_prohibits_parallel_scheduling() { run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); // There should be no affinity before starting. - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); - assert!(OnDemandAssigner::get_affinity_map(para_b).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); + assert!(OnDemand::get_affinity_map(para_b).is_none()); // Add 2 assignments for para_a for every para_b. place_order_run_to_101(para_a); @@ -447,22 +423,22 @@ fn affinity_prohibits_parallel_scheduling() { // Approximate having 1 core. for _ in 0..3 { - assert!(OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).is_some()); + assert!(OnDemand::pop_assignment_for_core(CoreIndex(0)).is_some()); } - assert!(OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)).is_none()); + assert!(OnDemand::pop_assignment_for_core(CoreIndex(0)).is_none()); // Affinity on one core is meaningless. - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 2); - assert_eq!(OnDemandAssigner::get_affinity_map(para_b).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 2); + assert_eq!(OnDemand::get_affinity_map(para_b).unwrap().count, 1); assert_eq!( - OnDemandAssigner::get_affinity_map(para_a).unwrap().core_index, - OnDemandAssigner::get_affinity_map(para_b).unwrap().core_index, + OnDemand::get_affinity_map(para_a).unwrap().core_index, + OnDemand::get_affinity_map(para_b).unwrap().core_index, ); // Clear affinity - OnDemandAssigner::report_processed(para_a, 0.into()); - OnDemandAssigner::report_processed(para_a, 0.into()); - OnDemandAssigner::report_processed(para_b, 0.into()); + OnDemand::report_processed(para_a, 0.into()); + OnDemand::report_processed(para_a, 0.into()); + OnDemand::report_processed(para_b, 0.into()); // Add 2 assignments for para_a for every para_b. place_order_run_to_101(para_a); @@ -471,25 +447,25 @@ fn affinity_prohibits_parallel_scheduling() { // Approximate having 3 cores. CoreIndex 2 should be unable to obtain an assignment for _ in 0..3 { - OnDemandAssigner::pop_assignment_for_core(CoreIndex(0)); - OnDemandAssigner::pop_assignment_for_core(CoreIndex(1)); - assert!(OnDemandAssigner::pop_assignment_for_core(CoreIndex(2)).is_none()); + OnDemand::pop_assignment_for_core(CoreIndex(0)); + OnDemand::pop_assignment_for_core(CoreIndex(1)); + assert!(OnDemand::pop_assignment_for_core(CoreIndex(2)).is_none()); } // Affinity should be the same as before, but on different cores. - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 2); - assert_eq!(OnDemandAssigner::get_affinity_map(para_b).unwrap().count, 1); - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().core_index, CoreIndex(0)); - assert_eq!(OnDemandAssigner::get_affinity_map(para_b).unwrap().core_index, CoreIndex(1)); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 2); + assert_eq!(OnDemand::get_affinity_map(para_b).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().core_index, CoreIndex(0)); + assert_eq!(OnDemand::get_affinity_map(para_b).unwrap().core_index, CoreIndex(1)); // Clear affinity - OnDemandAssigner::report_processed(para_a, CoreIndex(0)); - OnDemandAssigner::report_processed(para_a, CoreIndex(0)); - OnDemandAssigner::report_processed(para_b, CoreIndex(1)); + OnDemand::report_processed(para_a, CoreIndex(0)); + OnDemand::report_processed(para_a, CoreIndex(0)); + OnDemand::report_processed(para_b, CoreIndex(1)); // There should be no affinity after clearing. - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); - assert!(OnDemandAssigner::get_affinity_map(para_b).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); + assert!(OnDemand::get_affinity_map(para_b).is_none()); }); } @@ -503,7 +479,7 @@ fn affinity_changes_work() { run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); // There should be no affinity before starting. - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); // Add enough assignments to the order queue. for _ in 0..10 { @@ -511,46 +487,46 @@ fn affinity_changes_work() { } // There should be no affinity before the scheduler pops. - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); - OnDemandAssigner::pop_assignment_for_core(core_index); + OnDemand::pop_assignment_for_core(core_index); // Affinity count is 1 after popping. - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 1); - OnDemandAssigner::report_processed(para_a, 0.into()); - OnDemandAssigner::pop_assignment_for_core(core_index); + OnDemand::report_processed(para_a, 0.into()); + OnDemand::pop_assignment_for_core(core_index); // Affinity count is 1 after popping with a previous para. - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 1); for _ in 0..3 { - OnDemandAssigner::pop_assignment_for_core(core_index); + OnDemand::pop_assignment_for_core(core_index); } // Affinity count is 4 after popping 3 times without a previous para. - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 4); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 4); for _ in 0..5 { - OnDemandAssigner::report_processed(para_a, 0.into()); - assert!(OnDemandAssigner::pop_assignment_for_core(core_index).is_some()); + OnDemand::report_processed(para_a, 0.into()); + assert!(OnDemand::pop_assignment_for_core(core_index).is_some()); } // Affinity count should still be 4 but queue should be empty. - assert!(OnDemandAssigner::pop_assignment_for_core(core_index).is_none()); - assert_eq!(OnDemandAssigner::get_affinity_map(para_a).unwrap().count, 4); + assert!(OnDemand::pop_assignment_for_core(core_index).is_none()); + assert_eq!(OnDemand::get_affinity_map(para_a).unwrap().count, 4); // Pop 4 times and get to exactly 0 (None) affinity. for _ in 0..4 { - OnDemandAssigner::report_processed(para_a, 0.into()); - assert!(OnDemandAssigner::pop_assignment_for_core(core_index).is_none()); + OnDemand::report_processed(para_a, 0.into()); + assert!(OnDemand::pop_assignment_for_core(core_index).is_none()); } - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); // Decreasing affinity beyond 0 should still be None. - OnDemandAssigner::report_processed(para_a, 0.into()); - assert!(OnDemandAssigner::pop_assignment_for_core(core_index).is_none()); - assert!(OnDemandAssigner::get_affinity_map(para_a).is_none()); + OnDemand::report_processed(para_a, 0.into()); + assert!(OnDemand::pop_assignment_for_core(core_index).is_none()); + assert!(OnDemand::get_affinity_map(para_a).is_none()); }); } @@ -575,28 +551,25 @@ fn new_affinity_for_a_core_must_come_from_free_entries() { }); // There are 4 entries in free_entries. - let start_free_entries = OnDemandAssigner::get_free_entries().len(); + let start_free_entries = OnDemand::get_free_entries().len(); assert_eq!(start_free_entries, 4); // Pop assignments on all cores. core_indices.iter().enumerate().for_each(|(n, core_index)| { // There is no affinity on the core prior to popping. - assert!(OnDemandAssigner::get_affinity_entries(*core_index).is_empty()); + assert!(OnDemand::get_affinity_entries(*core_index).is_empty()); // There's always an order to be popped for each core. - let free_entries = OnDemandAssigner::get_free_entries(); + let free_entries = OnDemand::get_free_entries(); let next_order = free_entries.peek(); // There is no affinity on the paraid prior to popping. - assert!(OnDemandAssigner::get_affinity_map(next_order.unwrap().para_id).is_none()); + assert!(OnDemand::get_affinity_map(next_order.unwrap().para_id).is_none()); - match OnDemandAssigner::pop_assignment_for_core(*core_index) { + match OnDemand::pop_assignment_for_core(*core_index) { Some(assignment) => { // The popped assignment came from free entries. - assert_eq!( - start_free_entries - 1 - n, - OnDemandAssigner::get_free_entries().len() - ); + assert_eq!(start_free_entries - 1 - n, OnDemand::get_free_entries().len()); // The popped assignment has the same para id as the next order. assert_eq!(assignment.para_id(), next_order.unwrap().para_id); }, @@ -605,11 +578,11 @@ fn new_affinity_for_a_core_must_come_from_free_entries() { }); // All entries have been removed from free_entries. - assert!(OnDemandAssigner::get_free_entries().is_empty()); + assert!(OnDemand::get_free_entries().is_empty()); // All chains have an affinity count of 1. parachains.iter().for_each(|chain| { - assert_eq!(OnDemandAssigner::get_affinity_map(*chain).unwrap().count, 1); + assert_eq!(OnDemand::get_affinity_map(*chain).unwrap().count, 1); }); }); } @@ -689,7 +662,7 @@ fn queue_status_size_fn_works() { schedule_blank_para(*chain, ParaKind::Parathread); }); - assert_eq!(OnDemandAssigner::get_queue_status().size(), 0); + assert_eq!(OnDemand::get_queue_status().size(), 0); run_to_block(11, |n| if n == 11 { Some(Default::default()) } else { None }); @@ -701,27 +674,27 @@ fn queue_status_size_fn_works() { }); // 6 orders in free entries - assert_eq!(OnDemandAssigner::get_free_entries().len(), 6); + assert_eq!(OnDemand::get_free_entries().len(), 6); // 6 orders via queue status size assert_eq!( - OnDemandAssigner::get_free_entries().len(), - OnDemandAssigner::get_queue_status().size() as usize + OnDemand::get_free_entries().len(), + OnDemand::get_queue_status().size() as usize ); core_indices.iter().for_each(|core_index| { - OnDemandAssigner::pop_assignment_for_core(*core_index); + OnDemand::pop_assignment_for_core(*core_index); }); // There should be 2 orders in the scheduler's claimqueue, // 2 in assorted AffinityMaps and 2 in free. // ParaId 111 - assert_eq!(OnDemandAssigner::get_affinity_entries(core_indices[0]).len(), 1); + assert_eq!(OnDemand::get_affinity_entries(core_indices[0]).len(), 1); // ParaId 222 - assert_eq!(OnDemandAssigner::get_affinity_entries(core_indices[1]).len(), 1); + assert_eq!(OnDemand::get_affinity_entries(core_indices[1]).len(), 1); // Free entries are from ParaId 333 - assert_eq!(OnDemandAssigner::get_free_entries().len(), 2); + assert_eq!(OnDemand::get_free_entries().len(), 2); // For a total size of 4. - assert_eq!(OnDemandAssigner::get_queue_status().size(), 4) + assert_eq!(OnDemand::get_queue_status().size(), 4) }); } @@ -732,27 +705,27 @@ fn revenue_information_fetching_works() { schedule_blank_para(para_a, ParaKind::Parathread); // Mock assigner sets max revenue history to 10. run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(10); + let revenue = OnDemand::claim_revenue_until(10); // No revenue should be recorded. assert_eq!(revenue, 0); // Place one order place_order_run_to_blocknumber(para_a, Some(11)); - let revenue = OnDemandAssigner::get_revenue(); - let amt = OnDemandAssigner::claim_revenue_until(11); + let revenue = OnDemand::get_revenue(); + let amt = OnDemand::claim_revenue_until(11); // Revenue until the current block is still zero as "until" is non-inclusive assert_eq!(amt, 0); - let amt = OnDemandAssigner::claim_revenue_until(12); + let amt = OnDemand::claim_revenue_until(12); // Revenue for a single order should be recorded and shouldn't have been pruned by the // previous call assert_eq!(amt, revenue[0]); run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(13); + let revenue = OnDemand::claim_revenue_until(13); // No revenue should be recorded. assert_eq!(revenue, 0); @@ -767,7 +740,7 @@ fn revenue_information_fetching_works() { run_to_block(14, |n| if n == 14 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(15); + let revenue = OnDemand::claim_revenue_until(15); // All 3 orders should be accounted for. assert_eq!(revenue, 30_000); @@ -775,13 +748,13 @@ fn revenue_information_fetching_works() { // Place one order place_order_run_to_blocknumber(para_a, Some(16)); - let revenue = OnDemandAssigner::claim_revenue_until(15); + let revenue = OnDemand::claim_revenue_until(15); // Order is not in range of the revenue_until call assert_eq!(revenue, 0); run_to_block(20, |n| if n == 20 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(21); + let revenue = OnDemand::claim_revenue_until(21); assert_eq!(revenue, 10_000); // Make sure overdue revenue is accumulated @@ -789,7 +762,7 @@ fn revenue_information_fetching_works() { run_to_block(i, |n| if n % 10 == 0 { Some(Default::default()) } else { None }); place_order(para_a); } - let revenue = OnDemandAssigner::claim_revenue_until(36); + let revenue = OnDemand::claim_revenue_until(36); assert_eq!(revenue, 150_000); }); } diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/types.rs b/polkadot/runtime/parachains/src/on_demand/types.rs similarity index 100% rename from polkadot/runtime/parachains/src/assigner_on_demand/types.rs rename to polkadot/runtime/parachains/src/on_demand/types.rs diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 137191e3dcbb..bc54f08186e5 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -51,14 +51,14 @@ use runtime_common::{ BlockHashCount, BlockLength, SlowAdjustingFeeUpdate, }; use runtime_parachains::{ - assigner_coretime as parachains_assigner_coretime, - assigner_on_demand as parachains_assigner_on_demand, configuration as parachains_configuration, + assigner_coretime as parachains_assigner_coretime, configuration as parachains_configuration, configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio, coretime, disputes as parachains_disputes, disputes::slashing as parachains_slashing, dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion, inclusion::{AggregateMessageOrigin, UmpQueueId}, - initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, + initializer as parachains_initializer, on_demand as parachains_on_demand, + origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, runtime_api_impl::{ v10 as parachains_runtime_api_impl, vstaging as vstaging_parachains_runtime_api_impl, @@ -1084,11 +1084,11 @@ parameter_types! { pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } -impl parachains_assigner_on_demand::Config for Runtime { +impl parachains_on_demand::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; - type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; + type WeightInfo = weights::runtime_parachains_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; type PalletId = OnDemandPalletId; } @@ -1472,7 +1472,7 @@ construct_runtime! { ParasDisputes: parachains_disputes = 62, ParasSlashing: parachains_slashing = 63, MessageQueue: pallet_message_queue = 64, - OnDemandAssignmentProvider: parachains_assigner_on_demand = 66, + OnDemandAssignmentProvider: parachains_on_demand = 66, CoretimeAssignmentProvider: parachains_assigner_coretime = 68, // Parachain Onboarding Pallets. Start indices at 70 to leave room. @@ -1653,7 +1653,7 @@ pub mod migrations { // This needs to come after the `parachains_configuration` above as we are reading the configuration. coretime::migration::MigrateToCoretime, parachains_configuration::migration::v12::MigrateToV12, - parachains_assigner_on_demand::migration::MigrateV0ToV1, + parachains_on_demand::migration::MigrateV0ToV1, // permanent pallet_xcm::migration::MigrateToLatestXcmVersion, @@ -1721,7 +1721,7 @@ mod benches { [runtime_parachains::initializer, Initializer] [runtime_parachains::paras_inherent, ParaInherent] [runtime_parachains::paras, Paras] - [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] + [runtime_parachains::on_demand, OnDemandAssignmentProvider] // Substrate [pallet_balances, Balances] [pallet_balances, NisCounterpartBalances] diff --git a/polkadot/runtime/rococo/src/weights/mod.rs b/polkadot/runtime/rococo/src/weights/mod.rs index 3c6845dfb43e..cd6e5bbc6932 100644 --- a/polkadot/runtime/rococo/src/weights/mod.rs +++ b/polkadot/runtime/rococo/src/weights/mod.rs @@ -49,13 +49,13 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_identity_migrator; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; -pub mod runtime_parachains_assigner_on_demand; pub mod runtime_parachains_configuration; pub mod runtime_parachains_coretime; pub mod runtime_parachains_disputes; pub mod runtime_parachains_hrmp; pub mod runtime_parachains_inclusion; pub mod runtime_parachains_initializer; +pub mod runtime_parachains_on_demand; pub mod runtime_parachains_paras; pub mod runtime_parachains_paras_inherent; pub mod xcm; diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_on_demand.rs similarity index 94% rename from polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs rename to polkadot/runtime/rococo/src/weights/runtime_parachains_on_demand.rs index 0b384e29cf12..2d252201cd73 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_assigner_on_demand.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_on_demand.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Autogenerated weights for `runtime_parachains::assigner_on_demand` +//! Autogenerated weights for `runtime_parachains::on_demand` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 //! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` @@ -32,7 +32,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=runtime_parachains::assigner_on_demand +// --pallet=runtime_parachains::on_demand // --chain=rococo-dev // --header=./polkadot/file_header.txt // --output=./polkadot/runtime/rococo/src/weights/ @@ -45,9 +45,9 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -/// Weight functions for `runtime_parachains::assigner_on_demand`. +/// Weight functions for `runtime_parachains::on_demand`. pub struct WeightInfo(PhantomData); -impl runtime_parachains::assigner_on_demand::WeightInfo for WeightInfo { +impl runtime_parachains::on_demand::WeightInfo for WeightInfo { /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `System::Account` (r:1 w:0) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 5ca3fd4ece73..69dfc86ba293 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -66,14 +66,14 @@ use runtime_common::{ U256ToBalance, }; use runtime_parachains::{ - assigner_coretime as parachains_assigner_coretime, - assigner_on_demand as parachains_assigner_on_demand, configuration as parachains_configuration, + assigner_coretime as parachains_assigner_coretime, configuration as parachains_configuration, configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio, coretime, disputes as parachains_disputes, disputes::slashing as parachains_slashing, dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion, inclusion::{AggregateMessageOrigin, UmpQueueId}, - initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras, + initializer as parachains_initializer, on_demand as parachains_on_demand, + origin as parachains_origin, paras as parachains_paras, paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points, runtime_api_impl::{ v10 as parachains_runtime_api_impl, vstaging as vstaging_parachains_runtime_api_impl, @@ -1218,11 +1218,11 @@ parameter_types! { pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } -impl parachains_assigner_on_demand::Config for Runtime { +impl parachains_on_demand::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; - type WeightInfo = weights::runtime_parachains_assigner_on_demand::WeightInfo; + type WeightInfo = weights::runtime_parachains_on_demand::WeightInfo; type MaxHistoricalRevenue = MaxHistoricalRevenue; type PalletId = OnDemandPalletId; } @@ -1574,7 +1574,7 @@ mod runtime { #[runtime::pallet_index(54)] pub type ParasSlashing = parachains_slashing; #[runtime::pallet_index(56)] - pub type OnDemandAssignmentProvider = parachains_assigner_on_demand; + pub type OnDemandAssignmentProvider = parachains_on_demand; #[runtime::pallet_index(57)] pub type CoretimeAssignmentProvider = parachains_assigner_coretime; @@ -1732,7 +1732,7 @@ mod benches { [runtime_parachains::initializer, Initializer] [runtime_parachains::paras, Paras] [runtime_parachains::paras_inherent, ParaInherent] - [runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider] + [runtime_parachains::on_demand, OnDemandAssignmentProvider] [runtime_parachains::coretime, Coretime] // Substrate [pallet_bags_list, VoterList] diff --git a/polkadot/runtime/westend/src/weights/mod.rs b/polkadot/runtime/westend/src/weights/mod.rs index f6a9008d7187..130735644e0a 100644 --- a/polkadot/runtime/westend/src/weights/mod.rs +++ b/polkadot/runtime/westend/src/weights/mod.rs @@ -48,7 +48,6 @@ pub mod runtime_common_crowdloan; pub mod runtime_common_identity_migrator; pub mod runtime_common_paras_registrar; pub mod runtime_common_slots; -pub mod runtime_parachains_assigner_on_demand; pub mod runtime_parachains_configuration; pub mod runtime_parachains_coretime; pub mod runtime_parachains_disputes; @@ -56,6 +55,7 @@ pub mod runtime_parachains_disputes_slashing; pub mod runtime_parachains_hrmp; pub mod runtime_parachains_inclusion; pub mod runtime_parachains_initializer; +pub mod runtime_parachains_on_demand; pub mod runtime_parachains_paras; pub mod runtime_parachains_paras_inherent; pub mod xcm; diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_on_demand.rs similarity index 94% rename from polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs rename to polkadot/runtime/westend/src/weights/runtime_parachains_on_demand.rs index bc8201180fc6..ce42f3c96b04 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_assigner_on_demand.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_on_demand.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Autogenerated weights for `runtime_parachains::assigner_on_demand` +//! Autogenerated weights for `runtime_parachains::on_demand` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 //! DATE: 2024-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` @@ -32,7 +32,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=runtime_parachains::assigner_on_demand +// --pallet=runtime_parachains::on_demand // --chain=westend-dev // --header=./polkadot/file_header.txt // --output=./polkadot/runtime/westend/src/weights/ @@ -45,9 +45,9 @@ use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; -/// Weight functions for `runtime_parachains::assigner_on_demand`. +/// Weight functions for `runtime_parachains::on_demand`. pub struct WeightInfo(PhantomData); -impl runtime_parachains::assigner_on_demand::WeightInfo for WeightInfo { +impl runtime_parachains::on_demand::WeightInfo for WeightInfo { /// Storage: `OnDemandAssignmentProvider::QueueStatus` (r:1 w:1) /// Proof: `OnDemandAssignmentProvider::QueueStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `System::Account` (r:1 w:0) From 7eca0a0d2fa5e00d6c220c64b59623e3c9b26cbe Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 5 Jun 2024 12:46:00 +0000 Subject: [PATCH 58/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-rococo --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker --- .../src/weights/pallet_broker.rs | 247 ++++++++++-------- 1 file changed, 134 insertions(+), 113 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs index 4f243433688d..2f9f485c4ef4 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/pallet_broker.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `pallet_broker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-03-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-h2rr8wx7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("coretime-rococo-dev")`, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_918_000 picoseconds. - Weight::from_parts(2_092_000, 0) + // Minimum execution time: 1_889_000 picoseconds. + Weight::from_parts(1_998_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -65,8 +65,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `10888` // Estimated: `13506` - // Minimum execution time: 21_943_000 picoseconds. - Weight::from_parts(22_570_000, 0) + // Minimum execution time: 22_169_000 picoseconds. + Weight::from_parts(23_559_000, 0) .saturating_add(Weight::from_parts(0, 13506)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -77,8 +77,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `12090` // Estimated: `13506` - // Minimum execution time: 20_923_000 picoseconds. - Weight::from_parts(21_354_000, 0) + // Minimum execution time: 20_459_000 picoseconds. + Weight::from_parts(21_332_000, 0) .saturating_add(Weight::from_parts(0, 13506)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -93,24 +93,34 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `466` // Estimated: `1951` - // Minimum execution time: 10_687_000 picoseconds. - Weight::from_parts(11_409_000, 0) + // Minimum execution time: 10_543_000 picoseconds. + Weight::from_parts(10_865_000, 0) .saturating_add(Weight::from_parts(0, 1951)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Leases` (r:1 w:1) + /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(401), added: 896, mode: `MaxEncodedLen`) + /// Storage: `Broker::Reservations` (r:1 w:0) + /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(12021), added: 12516, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::LastRelayChainBlockNumber` (r:1 w:0) /// Proof: `ParachainSystem::LastRelayChainBlockNumber` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::InstaPoolIo` (r:3 w:3) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `Broker::Reservations` (r:1 w:0) - /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(12021), added: 12516, mode: `MaxEncodedLen`) - /// Storage: `Broker::Leases` (r:1 w:1) - /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(401), added: 896, mode: `MaxEncodedLen`) /// Storage: `Broker::SaleInfo` (r:0 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) /// Storage: `Broker::Status` (r:0 w:1) @@ -120,15 +130,16 @@ impl pallet_broker::WeightInfo for WeightInfo { /// The range of component `n` is `[0, 1000]`. fn start_sales(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `12567` - // Estimated: `14052` - // Minimum execution time: 111_288_000 picoseconds. - Weight::from_parts(117_804_282, 0) - .saturating_add(Weight::from_parts(0, 14052)) - // Standard Error: 391 - .saturating_add(Weight::from_parts(1_243, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(8)) - .saturating_add(T::DbWeight::get().writes(66)) + // Measured: `12599` + // Estimated: `15065 + n * (1 ±0)` + // Minimum execution time: 43_084_000 picoseconds. + Weight::from_parts(126_503_883, 0) + .saturating_add(Weight::from_parts(0, 15065)) + // Standard Error: 2_229 + .saturating_add(Weight::from_parts(18_956, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(13)) + .saturating_add(T::DbWeight::get().writes(59)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) @@ -137,13 +148,13 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:0 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn purchase() -> Weight { // Proof Size summary in bytes: - // Measured: `316` + // Measured: `332` // Estimated: `3593` - // Minimum execution time: 33_006_000 picoseconds. - Weight::from_parts(34_256_000, 0) + // Minimum execution time: 32_436_000 picoseconds. + Weight::from_parts(33_454_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -162,47 +173,47 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `434` + // Measured: `450` // Estimated: `4698` - // Minimum execution time: 61_473_000 picoseconds. - Weight::from_parts(66_476_000, 0) + // Minimum execution time: 58_419_000 picoseconds. + Weight::from_parts(69_572_000, 0) .saturating_add(Weight::from_parts(0, 4698)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 13_771_000 picoseconds. - Weight::from_parts(14_374_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 13_419_000 picoseconds. + Weight::from_parts(14_095_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Regions` (r:1 w:2) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn partition() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 15_162_000 picoseconds. - Weight::from_parts(15_742_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 15_299_000 picoseconds. + Weight::from_parts(15_857_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Broker::Regions` (r:1 w:3) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn interlace() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 16_196_000 picoseconds. - Weight::from_parts(16_796_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 16_647_000 picoseconds. + Weight::from_parts(17_124_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -211,15 +222,15 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:1 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn assign() -> Weight { // Proof Size summary in bytes: - // Measured: `936` + // Measured: `937` // Estimated: `4681` - // Minimum execution time: 25_653_000 picoseconds. - Weight::from_parts(27_006_000, 0) + // Minimum execution time: 25_310_000 picoseconds. + Weight::from_parts(26_626_000, 0) .saturating_add(Weight::from_parts(0, 4681)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -227,7 +238,7 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:1 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// Storage: `Broker::InstaPoolIo` (r:2 w:2) @@ -236,10 +247,10 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::InstaPoolContribution` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) fn pool() -> Weight { // Proof Size summary in bytes: - // Measured: `1002` + // Measured: `1003` // Estimated: `5996` - // Minimum execution time: 31_114_000 picoseconds. - Weight::from_parts(32_235_000, 0) + // Minimum execution time: 30_862_000 picoseconds. + Weight::from_parts(32_483_000, 0) .saturating_add(Weight::from_parts(0, 5996)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(5)) @@ -255,11 +266,11 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `652` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 57_280_000 picoseconds. - Weight::from_parts(58_127_480, 0) + // Minimum execution time: 55_503_000 picoseconds. + Weight::from_parts(55_740_513, 0) .saturating_add(Weight::from_parts(0, 6196)) - // Standard Error: 41_670 - .saturating_add(Weight::from_parts(1_203_066, 0).saturating_mul(m.into())) + // Standard Error: 43_492 + .saturating_add(Weight::from_parts(1_662_689, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(T::DbWeight::get().writes(5)) @@ -279,25 +290,25 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn purchase_credit() -> Weight { // Proof Size summary in bytes: - // Measured: `215` - // Estimated: `3680` - // Minimum execution time: 59_968_000 picoseconds. - Weight::from_parts(62_315_000, 0) - .saturating_add(Weight::from_parts(0, 3680)) + // Measured: `322` + // Estimated: `3787` + // Minimum execution time: 62_567_000 picoseconds. + Weight::from_parts(64_465_000, 0) + .saturating_add(Weight::from_parts(0, 3787)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn drop_region() -> Weight { // Proof Size summary in bytes: - // Measured: `465` - // Estimated: `3550` - // Minimum execution time: 50_887_000 picoseconds. - Weight::from_parts(57_366_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `466` + // Estimated: `3551` + // Minimum execution time: 59_352_000 picoseconds. + Weight::from_parts(69_601_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -311,8 +322,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `463` // Estimated: `3533` - // Minimum execution time: 84_472_000 picoseconds. - Weight::from_parts(96_536_000, 0) + // Minimum execution time: 79_201_000 picoseconds. + Weight::from_parts(104_454_000, 0) .saturating_add(Weight::from_parts(0, 3533)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -329,8 +340,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `857` // Estimated: `3593` - // Minimum execution time: 96_371_000 picoseconds. - Weight::from_parts(104_659_000, 0) + // Minimum execution time: 78_113_000 picoseconds. + Weight::from_parts(93_877_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -343,8 +354,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `957` // Estimated: `4698` - // Minimum execution time: 51_741_000 picoseconds. - Weight::from_parts(54_461_000, 0) + // Minimum execution time: 47_956_000 picoseconds. + Weight::from_parts(58_751_000, 0) .saturating_add(Weight::from_parts(0, 4698)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -360,13 +371,15 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// The range of component `n` is `[0, 1000]`. - fn request_core_count(_n: u32, ) -> Weight { + fn request_core_count(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3539` - // Minimum execution time: 19_901_000 picoseconds. - Weight::from_parts(21_028_116, 0) + // Minimum execution time: 20_170_000 picoseconds. + Weight::from_parts(21_041_556, 0) .saturating_add(Weight::from_parts(0, 3539)) + // Standard Error: 70 + .saturating_add(Weight::from_parts(311, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -377,26 +390,26 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `266` // Estimated: `1487` - // Minimum execution time: 5_987_000 picoseconds. - Weight::from_parts(6_412_478, 0) + // Minimum execution time: 5_880_000 picoseconds. + Weight::from_parts(6_411_677, 0) .saturating_add(Weight::from_parts(0, 1487)) - // Standard Error: 16 - .saturating_add(Weight::from_parts(47, 0).saturating_mul(n.into())) + // Standard Error: 18 + .saturating_add(Weight::from_parts(52, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) - /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `Broker::RevenueInbox` (r:1 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) + /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) fn process_revenue() -> Weight { // Proof Size summary in bytes: - // Measured: `447` + // Measured: `442` // Estimated: `6196` - // Minimum execution time: 38_623_000 picoseconds. - Weight::from_parts(39_773_000, 0) + // Minimum execution time: 42_485_000 picoseconds. + Weight::from_parts(43_140_000, 0) .saturating_add(Weight::from_parts(0, 6196)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -412,13 +425,15 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Workplan` (r:0 w:60) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn rotate_sale(_n: u32, ) -> Weight { + fn rotate_sale(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `12514` // Estimated: `13506` - // Minimum execution time: 97_074_000 picoseconds. - Weight::from_parts(101_247_740, 0) + // Minimum execution time: 93_599_000 picoseconds. + Weight::from_parts(96_127_749, 0) .saturating_add(Weight::from_parts(0, 13506)) + // Standard Error: 135 + .saturating_add(Weight::from_parts(74, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(65)) } @@ -430,8 +445,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `42` // Estimated: `3493` - // Minimum execution time: 6_317_000 picoseconds. - Weight::from_parts(6_521_000, 0) + // Minimum execution time: 5_741_000 picoseconds. + Weight::from_parts(6_027_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -454,8 +469,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `4786` - // Minimum execution time: 32_575_000 picoseconds. - Weight::from_parts(33_299_000, 0) + // Minimum execution time: 32_643_000 picoseconds. + Weight::from_parts(33_384_000, 0) .saturating_add(Weight::from_parts(0, 4786)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) @@ -474,8 +489,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3539` - // Minimum execution time: 15_256_000 picoseconds. - Weight::from_parts(15_927_000, 0) + // Minimum execution time: 15_650_000 picoseconds. + Weight::from_parts(16_140_000, 0) .saturating_add(Weight::from_parts(0, 3539)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) @@ -486,13 +501,19 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_783_000 picoseconds. - Weight::from_parts(1_904_000, 0) + // Minimum execution time: 1_650_000 picoseconds. + Weight::from_parts(1_787_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `Broker::RevenueInbox` (r:0 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) fn notify_revenue() -> Weight { - Weight::from_parts(1_904_000, 0) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_813_000 picoseconds. + Weight::from_parts(1_937_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -502,19 +523,19 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) /// Storage: `Broker::CoreCountInbox` (r:1 w:0) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:0) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn do_tick_base() -> Weight { // Proof Size summary in bytes: - // Measured: `398` - // Estimated: `3863` - // Minimum execution time: 12_307_000 picoseconds. - Weight::from_parts(12_967_000, 0) - .saturating_add(Weight::from_parts(0, 3863)) + // Measured: `408` + // Estimated: `1893` + // Minimum execution time: 10_774_000 picoseconds. + Weight::from_parts(11_211_000, 0) + .saturating_add(Weight::from_parts(0, 1893)) .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(401), added: 896, mode: `MaxEncodedLen`) @@ -522,8 +543,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `470` // Estimated: `1886` - // Minimum execution time: 6_597_000 picoseconds. - Weight::from_parts(6_969_000, 0) + // Minimum execution time: 6_320_000 picoseconds. + Weight::from_parts(6_726_000, 0) .saturating_add(Weight::from_parts(0, 1886)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) From 7de6355b2e6738b4491c2d58f3fce872e359b83f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 5 Jun 2024 14:00:05 +0000 Subject: [PATCH 59/67] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=coretime-westend --runtime_dir=coretime --target_dir=cumulus --pallet=pallet_broker --- .../src/weights/pallet_broker.rs | 247 ++++++++++-------- 1 file changed, 135 insertions(+), 112 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs index 28628657c0f7..9d94f1302efb 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/pallet_broker.rs @@ -17,9 +17,9 @@ //! Autogenerated weights for `pallet_broker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-03-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-06-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-h2rr8wx7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("coretime-westend-dev")`, DB CACHE: 1024 // Executed Command: @@ -54,8 +54,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_897_000 picoseconds. - Weight::from_parts(2_053_000, 0) + // Minimum execution time: 1_778_000 picoseconds. + Weight::from_parts(1_956_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -65,8 +65,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `10888` // Estimated: `13506` - // Minimum execution time: 22_550_000 picoseconds. - Weight::from_parts(22_871_000, 0) + // Minimum execution time: 21_562_000 picoseconds. + Weight::from_parts(21_996_000, 0) .saturating_add(Weight::from_parts(0, 13506)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -77,8 +77,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `12090` // Estimated: `13506` - // Minimum execution time: 21_170_000 picoseconds. - Weight::from_parts(21_645_000, 0) + // Minimum execution time: 20_391_000 picoseconds. + Weight::from_parts(20_926_000, 0) .saturating_add(Weight::from_parts(0, 13506)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -93,24 +93,34 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `146` // Estimated: `1631` - // Minimum execution time: 10_494_000 picoseconds. - Weight::from_parts(10_942_000, 0) + // Minimum execution time: 9_830_000 picoseconds. + Weight::from_parts(10_306_000, 0) .saturating_add(Weight::from_parts(0, 1631)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Leases` (r:1 w:1) + /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(81), added: 576, mode: `MaxEncodedLen`) + /// Storage: `Broker::Reservations` (r:1 w:0) + /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(12021), added: 12516, mode: `MaxEncodedLen`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::LastRelayChainBlockNumber` (r:1 w:0) /// Proof: `ParachainSystem::LastRelayChainBlockNumber` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::InstaPoolIo` (r:3 w:3) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `Broker::Reservations` (r:1 w:0) - /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(12021), added: 12516, mode: `MaxEncodedLen`) - /// Storage: `Broker::Leases` (r:1 w:1) - /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(81), added: 576, mode: `MaxEncodedLen`) /// Storage: `Broker::SaleInfo` (r:0 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) /// Storage: `Broker::Status` (r:0 w:1) @@ -118,15 +128,18 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Workplan` (r:0 w:20) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn start_sales(_n: u32, ) -> Weight { + fn start_sales(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `12247` - // Estimated: `13732` - // Minimum execution time: 61_014_000 picoseconds. - Weight::from_parts(63_267_651, 0) - .saturating_add(Weight::from_parts(0, 13732)) - .saturating_add(T::DbWeight::get().reads(8)) + // Measured: `12279` + // Estimated: `14805 + n * (1 ±0)` + // Minimum execution time: 40_593_000 picoseconds. + Weight::from_parts(81_958_426, 0) + .saturating_add(Weight::from_parts(0, 14805)) + // Standard Error: 925 + .saturating_add(Weight::from_parts(4_537, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(13)) .saturating_add(T::DbWeight::get().writes(26)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) @@ -135,13 +148,13 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:0 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn purchase() -> Weight { // Proof Size summary in bytes: - // Measured: `316` + // Measured: `332` // Estimated: `3593` - // Minimum execution time: 30_931_000 picoseconds. - Weight::from_parts(31_941_000, 0) + // Minimum execution time: 31_514_000 picoseconds. + Weight::from_parts(32_460_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -160,47 +173,47 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `434` + // Measured: `450` // Estimated: `4698` - // Minimum execution time: 57_466_000 picoseconds. - Weight::from_parts(65_042_000, 0) + // Minimum execution time: 73_289_000 picoseconds. + Weight::from_parts(84_064_000, 0) .saturating_add(Weight::from_parts(0, 4698)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 12_799_000 picoseconds. - Weight::from_parts(13_401_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 12_687_000 picoseconds. + Weight::from_parts(13_412_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Regions` (r:1 w:2) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn partition() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 14_107_000 picoseconds. - Weight::from_parts(14_630_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 14_454_000 picoseconds. + Weight::from_parts(15_084_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Broker::Regions` (r:1 w:3) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn interlace() -> Weight { // Proof Size summary in bytes: - // Measured: `357` - // Estimated: `3550` - // Minimum execution time: 15_254_000 picoseconds. - Weight::from_parts(16_062_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `358` + // Estimated: `3551` + // Minimum execution time: 15_748_000 picoseconds. + Weight::from_parts(16_426_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } @@ -209,15 +222,15 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:1 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn assign() -> Weight { // Proof Size summary in bytes: - // Measured: `735` + // Measured: `736` // Estimated: `4681` - // Minimum execution time: 23_557_000 picoseconds. - Weight::from_parts(24_382_000, 0) + // Minimum execution time: 24_266_000 picoseconds. + Weight::from_parts(24_902_000, 0) .saturating_add(Weight::from_parts(0, 4681)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(2)) @@ -225,7 +238,7 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:1 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) /// Storage: `Broker::InstaPoolIo` (r:2 w:2) @@ -234,10 +247,10 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::InstaPoolContribution` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) fn pool() -> Weight { // Proof Size summary in bytes: - // Measured: `801` + // Measured: `802` // Estimated: `5996` - // Minimum execution time: 29_371_000 picoseconds. - Weight::from_parts(30_200_000, 0) + // Minimum execution time: 29_533_000 picoseconds. + Weight::from_parts(30_577_000, 0) .saturating_add(Weight::from_parts(0, 5996)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(5)) @@ -253,11 +266,11 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `652` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 54_331_000 picoseconds. - Weight::from_parts(55_322_165, 0) + // Minimum execution time: 55_990_000 picoseconds. + Weight::from_parts(57_095_841, 0) .saturating_add(Weight::from_parts(0, 6196)) - // Standard Error: 35_225 - .saturating_add(Weight::from_parts(1_099_614, 0).saturating_mul(m.into())) + // Standard Error: 36_475 + .saturating_add(Weight::from_parts(1_192_381, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) .saturating_add(T::DbWeight::get().writes(5)) @@ -277,25 +290,25 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn purchase_credit() -> Weight { // Proof Size summary in bytes: - // Measured: `215` - // Estimated: `3680` - // Minimum execution time: 53_789_000 picoseconds. - Weight::from_parts(55_439_000, 0) - .saturating_add(Weight::from_parts(0, 3680)) + // Measured: `320` + // Estimated: `3785` + // Minimum execution time: 59_392_000 picoseconds. + Weight::from_parts(61_500_000, 0) + .saturating_add(Weight::from_parts(0, 3785)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Broker::Status` (r:1 w:0) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Regions` (r:1 w:1) - /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) + /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn drop_region() -> Weight { // Proof Size summary in bytes: - // Measured: `465` - // Estimated: `3550` - // Minimum execution time: 43_941_000 picoseconds. - Weight::from_parts(49_776_000, 0) - .saturating_add(Weight::from_parts(0, 3550)) + // Measured: `466` + // Estimated: `3551` + // Minimum execution time: 46_448_000 picoseconds. + Weight::from_parts(65_486_000, 0) + .saturating_add(Weight::from_parts(0, 3551)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -309,8 +322,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `463` // Estimated: `3533` - // Minimum execution time: 64_917_000 picoseconds. - Weight::from_parts(70_403_000, 0) + // Minimum execution time: 66_763_000 picoseconds. + Weight::from_parts(115_128_000, 0) .saturating_add(Weight::from_parts(0, 3533)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -327,8 +340,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `857` // Estimated: `3593` - // Minimum execution time: 72_633_000 picoseconds. - Weight::from_parts(79_305_000, 0) + // Minimum execution time: 78_794_000 picoseconds. + Weight::from_parts(108_322_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(1)) @@ -341,8 +354,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `556` // Estimated: `4698` - // Minimum execution time: 36_643_000 picoseconds. - Weight::from_parts(48_218_000, 0) + // Minimum execution time: 40_812_000 picoseconds. + Weight::from_parts(53_759_000, 0) .saturating_add(Weight::from_parts(0, 4698)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -358,13 +371,15 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// The range of component `n` is `[0, 1000]`. - fn request_core_count(_n: u32, ) -> Weight { + fn request_core_count(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3539` - // Minimum execution time: 17_617_000 picoseconds. - Weight::from_parts(18_904_788, 0) + // Minimum execution time: 18_214_000 picoseconds. + Weight::from_parts(19_115_584, 0) .saturating_add(Weight::from_parts(0, 3539)) + // Standard Error: 50 + .saturating_add(Weight::from_parts(183, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -375,26 +390,26 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `266` // Estimated: `1487` - // Minimum execution time: 5_575_000 picoseconds. - Weight::from_parts(5_887_598, 0) + // Minimum execution time: 5_491_000 picoseconds. + Weight::from_parts(5_941_581, 0) .saturating_add(Weight::from_parts(0, 1487)) - // Standard Error: 16 - .saturating_add(Weight::from_parts(41, 0).saturating_mul(n.into())) + // Standard Error: 31 + .saturating_add(Weight::from_parts(78, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) - /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) + /// Storage: `Broker::RevenueInbox` (r:1 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Broker::InstaPoolHistory` (r:1 w:1) + /// Proof: `Broker::InstaPoolHistory` (`max_values`: None, `max_size`: Some(45), added: 2520, mode: `MaxEncodedLen`) fn process_revenue() -> Weight { // Proof Size summary in bytes: - // Measured: `447` + // Measured: `442` // Estimated: `6196` - // Minimum execution time: 36_415_000 picoseconds. - Weight::from_parts(37_588_000, 0) + // Minimum execution time: 41_793_000 picoseconds. + Weight::from_parts(42_552_000, 0) .saturating_add(Weight::from_parts(0, 6196)) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) @@ -414,11 +429,11 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `12194` // Estimated: `13506` - // Minimum execution time: 48_362_000 picoseconds. - Weight::from_parts(49_616_106, 0) + // Minimum execution time: 47_771_000 picoseconds. + Weight::from_parts(49_602_852, 0) .saturating_add(Weight::from_parts(0, 13506)) - // Standard Error: 61 - .saturating_add(Weight::from_parts(59, 0).saturating_mul(n.into())) + // Standard Error: 91 + .saturating_add(Weight::from_parts(67, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(25)) } @@ -430,8 +445,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `42` // Estimated: `3493` - // Minimum execution time: 6_148_000 picoseconds. - Weight::from_parts(6_374_000, 0) + // Minimum execution time: 5_892_000 picoseconds. + Weight::from_parts(6_303_000, 0) .saturating_add(Weight::from_parts(0, 3493)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -454,8 +469,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `1321` // Estimated: `4786` - // Minimum execution time: 30_267_000 picoseconds. - Weight::from_parts(30_825_000, 0) + // Minimum execution time: 30_455_000 picoseconds. + Weight::from_parts(31_587_000, 0) .saturating_add(Weight::from_parts(0, 4786)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) @@ -474,8 +489,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `74` // Estimated: `3539` - // Minimum execution time: 13_491_000 picoseconds. - Weight::from_parts(13_949_000, 0) + // Minimum execution time: 14_579_000 picoseconds. + Weight::from_parts(15_770_000, 0) .saturating_add(Weight::from_parts(0, 3539)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) @@ -486,13 +501,21 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_711_000 picoseconds. - Weight::from_parts(1_913_000, 0) + // Minimum execution time: 1_592_000 picoseconds. + Weight::from_parts(1_763_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `Broker::RevenueInbox` (r:0 w:1) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) fn notify_revenue() -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_644_000 picoseconds. + Weight::from_parts(1_826_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) @@ -500,19 +523,19 @@ impl pallet_broker::WeightInfo for WeightInfo { /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) /// Storage: `Broker::CoreCountInbox` (r:1 w:0) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) - /// Storage: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) - /// Proof: UNKNOWN KEY `0xf308d869daf021a7724e69c557dd8dbe` (r:1 w:1) + /// Storage: `Broker::RevenueInbox` (r:1 w:0) + /// Proof: `Broker::RevenueInbox` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn do_tick_base() -> Weight { // Proof Size summary in bytes: - // Measured: `398` - // Estimated: `3863` - // Minimum execution time: 12_035_000 picoseconds. - Weight::from_parts(12_383_000, 0) - .saturating_add(Weight::from_parts(0, 3863)) + // Measured: `408` + // Estimated: `1893` + // Minimum execution time: 10_283_000 picoseconds. + Weight::from_parts(10_676_000, 0) + .saturating_add(Weight::from_parts(0, 1893)) .saturating_add(T::DbWeight::get().reads(5)) - .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(81), added: 576, mode: `MaxEncodedLen`) @@ -520,8 +543,8 @@ impl pallet_broker::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `150` // Estimated: `1566` - // Minimum execution time: 6_142_000 picoseconds. - Weight::from_parts(6_538_000, 0) + // Minimum execution time: 5_870_000 picoseconds. + Weight::from_parts(6_303_000, 0) .saturating_add(Weight::from_parts(0, 1566)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) From bcfcf64cb0f515e7e402458b812a221c7bfdd886 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Wed, 5 Jun 2024 19:05:49 +0200 Subject: [PATCH 60/67] Add logs and simplify tests --- substrate/frame/broker/src/mock.rs | 19 +++++++------ substrate/frame/broker/src/tests.rs | 34 +++++++++--------------- substrate/frame/broker/src/tick_impls.rs | 12 ++++++++- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 3cc9095a1968..0d7a218a30bf 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -32,7 +32,7 @@ use sp_arithmetic::Perbill; use sp_core::{ConstU32, ConstU64, Get}; use sp_runtime::{ traits::{BlockNumberProvider, Identity}, - BuildStorage, Saturating, + BuildStorage, }; use sp_std::collections::btree_map::BTreeMap; @@ -65,7 +65,8 @@ use CoretimeTraceItem::*; parameter_types! { pub static CoretimeTrace: Vec<(u32, CoretimeTraceItem)> = Default::default(); - pub static CoretimeCredit: BTreeMap = Default::default(); + // We don't have credits yet + // pub static CoretimeCredit: BTreeMap = Default::default(); pub static CoretimeSpending: Vec<(u32, u64)> = Default::default(); pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default(); pub static CoretimeUsage: BTreeMap> = Default::default(); @@ -102,8 +103,9 @@ impl CoretimeInterface for TestCoretimeProvider { }); RevenueInbox::::set(Some(OnDemandRevenueRecord { until: when, amount: total })); } - fn credit_account(who: Self::AccountId, amount: Self::Balance) { - CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); + fn credit_account(_who: Self::AccountId, _amount: Self::Balance) { + // We don't have credits yet + // CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); } fn assign_core( core: CoreIndex, @@ -126,11 +128,12 @@ impl CoretimeInterface for TestCoretimeProvider { } impl TestCoretimeProvider { - pub fn spend_instantaneous(who: u64, price: u64) -> Result<(), ()> { - let mut c = CoretimeCredit::get(); + pub fn spend_instantaneous(_who: u64, price: u64) -> Result<(), ()> { + // We don't have credits yet + // let mut c = CoretimeCredit::get(); ensure!(CoretimeInPool::get() > 0, ()); - c.insert(who, c.get(&who).ok_or(())?.checked_sub(price).ok_or(())?); - CoretimeCredit::set(c); + // c.insert(who, c.get(&who).ok_or(())?.checked_sub(price).ok_or(())?); + // CoretimeCredit::set(c); CoretimeSpending::mutate(|v| { v.push((RCBlockNumberProviderOf::::current_block_number() as u32, price)) }); diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 78b7ad3e719f..1850509c5b27 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -449,18 +449,6 @@ fn renewals_affect_price() { }); } -// In the following payouts tests, assertions of the pot balances currently account for the fact -// that the pot is topped up twice: first, when the credits are purchased, the value is transferred -// from the buyer's account to the pot (and currently that doesn't really result in any credits -// being acquired on the relay chain as the credit system is not implemented yet), and second, -// when the revenue is teleported from the relay chain to the parachain, thus minting the revenue -// value into the pot. Thus, current pot assertions are not correct and should be fixed back when -// the credit system is implemented. -// -// The other way to handle that wold be burning the balance transferred from the buyer's account to -// the pot in `do_purchase_credit()`, but, as it would affect the code that will go into -// production, it's more error prone, so handling incorrect pot balance is the lesser evil. - #[test] fn instapool_payouts_work() { TestExt::new().endow(1, 1000).execute_with(|| { @@ -470,11 +458,13 @@ fn instapool_payouts_work() { advance_to(2); let region = Broker::do_purchase(1, u64::max_value()).unwrap(); assert_ok!(Broker::do_pool(region, None, 2, Final)); - assert_ok!(Broker::do_purchase_credit(1, 20, 1)); + // assert_ok!(Broker::do_purchase_credit(1, 20, 1)); advance_to(8); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(11); - assert_eq!(pot(), 24); + // Should get revenue amount 10 from RC, from which 6 is system payout (goes to account0 + // instantly) and the rest is private (kept in the pot until claimed) + assert_eq!(pot(), 4); assert_eq!(revenue(), 106); // Cannot claim for 0 timeslices. @@ -482,7 +472,7 @@ fn instapool_payouts_work() { // Revenue can be claimed. assert_ok!(Broker::do_claim_revenue(region, 100)); - assert_eq!(pot(), 20); + assert_eq!(pot(), 0); assert_eq!(balance(2), 4); }); } @@ -499,7 +489,7 @@ fn instapool_partial_core_payouts_work() { Broker::do_interlace(region, None, CoreMask::from_chunk(0, 20)).unwrap(); assert_ok!(Broker::do_pool(region1, None, 2, Final)); assert_ok!(Broker::do_pool(region2, None, 3, Final)); - assert_ok!(Broker::do_purchase_credit(1, 40, 1)); + // assert_ok!(Broker::do_purchase_credit(1, 40, 1)); advance_to(8); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 40)); advance_to(11); @@ -508,7 +498,7 @@ fn instapool_partial_core_payouts_work() { assert_eq!(revenue(), 120); assert_eq!(balance(2), 5); assert_eq!(balance(3), 15); - assert_eq!(pot(), 40); + assert_eq!(pot(), 0); }); } @@ -526,21 +516,21 @@ fn instapool_core_payouts_work_with_partitioned_region() { // coretime will be purchased from `region2`. assert_ok!(Broker::do_pool(region1, None, 2, Final)); assert_ok!(Broker::do_pool(region2, None, 3, Final)); - assert_ok!(Broker::do_purchase_credit(1, 20, 1)); + // assert_ok!(Broker::do_purchase_credit(1, 20, 1)); advance_to(8); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(11); - assert_eq!(pot(), 30); + assert_eq!(pot(), 10); assert_eq!(revenue(), 100); assert_ok!(Broker::do_claim_revenue(region1, 100)); - assert_eq!(pot(), 20); + assert_eq!(pot(), 0); assert_eq!(balance(2), 10); advance_to(12); assert_ok!(TestCoretimeProvider::spend_instantaneous(1, 10)); advance_to(15); - assert_eq!(pot(), 30); + assert_eq!(pot(), 10); assert_ok!(Broker::do_claim_revenue(region2, 100)); - assert_eq!(pot(), 20); + assert_eq!(pot(), 0); // The balance of account `2` remains unchanged. assert_eq!(balance(2), 10); assert_eq!(balance(3), 10); diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index df89376fb4eb..1169612cffc1 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -102,13 +102,18 @@ impl Pallet { }; let when: Timeslice = (until / T::TimeslicePeriod::get()).saturating_sub(One::one()).saturated_into(); - let mut revenue = T::ConvertBalance::convert_back(amount); + let mut revenue = T::ConvertBalance::convert_back(amount.clone()); if revenue.is_zero() { Self::deposit_event(Event::::HistoryDropped { when, revenue }); InstaPoolHistory::::remove(when); return true } + log::debug!( + target: "pallet_broker::process_revenue", + "Received {amount:?} from RC, converted into {revenue:?} revenue", + ); + // Mint revenue amount on our end of the teleport let revenue_imbalance = T::Currency::issue(revenue); T::Currency::resolve(&Self::account_id(), revenue_imbalance).defensive_ok(); @@ -131,6 +136,11 @@ impl Pallet { Zero::zero() }; + log::debug!( + target: "pallet_broker::process_revenue", + "Charged {system_payout:?} for system payouts, {revenue:?} remaining for private contributions", + ); + if !revenue.is_zero() && r.private_contributions > 0 { r.maybe_payout = Some(revenue); InstaPoolHistory::::insert(when, &r); From 70e511fee4c488958c11140d9e8b95e69ffcb944 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 6 Jun 2024 20:20:38 +0200 Subject: [PATCH 61/67] Add comments addressing commented out code --- substrate/frame/broker/src/mock.rs | 12 +++++++++--- substrate/frame/broker/src/tests.rs | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 0d7a218a30bf..114850ea9392 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -64,8 +64,10 @@ pub enum CoretimeTraceItem { use CoretimeTraceItem::*; parameter_types! { + // Commented out code is from the reference mock implementation and should be uncommented as + // soon as we have the credit system implemented + pub static CoretimeTrace: Vec<(u32, CoretimeTraceItem)> = Default::default(); - // We don't have credits yet // pub static CoretimeCredit: BTreeMap = Default::default(); pub static CoretimeSpending: Vec<(u32, u64)> = Default::default(); pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default(); @@ -104,7 +106,9 @@ impl CoretimeInterface for TestCoretimeProvider { RevenueInbox::::set(Some(OnDemandRevenueRecord { until: when, amount: total })); } fn credit_account(_who: Self::AccountId, _amount: Self::Balance) { - // We don't have credits yet + // Commented out code is from the reference mock implementation and should be uncommented as + // soon as we have the credit system implemented + // CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); } fn assign_core( @@ -129,7 +133,9 @@ impl CoretimeInterface for TestCoretimeProvider { impl TestCoretimeProvider { pub fn spend_instantaneous(_who: u64, price: u64) -> Result<(), ()> { - // We don't have credits yet + // Commented out code is from the reference mock implementation and should be uncommented as + // soon as we have the credit system implemented + // let mut c = CoretimeCredit::get(); ensure!(CoretimeInPool::get() > 0, ()); // c.insert(who, c.get(&who).ok_or(())?.checked_sub(price).ok_or(())?); diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 1850509c5b27..2a8ea24b447a 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -451,6 +451,8 @@ fn renewals_affect_price() { #[test] fn instapool_payouts_work() { + // Commented out code is from the reference test implementation and should be uncommented as + // soon as we have the credit system implemented TestExt::new().endow(1, 1000).execute_with(|| { let item = ScheduleItem { assignment: Pool, mask: CoreMask::complete() }; assert_ok!(Broker::do_reserve(Schedule::truncate_from(vec![item]))); @@ -479,6 +481,8 @@ fn instapool_payouts_work() { #[test] fn instapool_partial_core_payouts_work() { + // Commented out code is from the reference test implementation and should be uncommented as + // soon as we have the credit system implemented TestExt::new().endow(1, 1000).execute_with(|| { let item = ScheduleItem { assignment: Pool, mask: CoreMask::complete() }; assert_ok!(Broker::do_reserve(Schedule::truncate_from(vec![item]))); @@ -504,6 +508,8 @@ fn instapool_partial_core_payouts_work() { #[test] fn instapool_core_payouts_work_with_partitioned_region() { + // Commented out code is from the reference test implementation and should be uncommented as + // soon as we have the credit system implemented TestExt::new().endow(1, 1000).execute_with(|| { assert_ok!(Broker::do_start_sales(100, 1)); advance_to(2); From d1d199be635db5cb0f5fda1f21ef35b920775f75 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Sat, 8 Jun 2024 12:06:32 +0200 Subject: [PATCH 62/67] Update Cargo.lock --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a96bb680b750..a68961edbda3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18371,18 +18371,18 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.28.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +checksum = "2acea373acb8c21ecb5a23741452acd2593ed44ee3d343e72baaa143bc89d0d5" dependencies = [ "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.9.2" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +checksum = "09e67c467c38fd24bd5499dc9a18183b31575c12ee549197e3e20d57aa4fe3b7" dependencies = [ "cc", ] From b25396ef9279ddf7ea753003a3d297f9ed5fd4c3 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 18 Jul 2024 17:27:11 +0200 Subject: [PATCH 63/67] Add prdoc --- prdoc/pr_4706.prdoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 prdoc/pr_4706.prdoc diff --git a/prdoc/pr_4706.prdoc b/prdoc/pr_4706.prdoc new file mode 100644 index 000000000000..7b77426c1631 --- /dev/null +++ b/prdoc/pr_4706.prdoc @@ -0,0 +1,13 @@ +# 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: "Rename `assigner_on_demand` pallet to `on_demand`" + +doc: + - audience: Runtime Dev + description: | + Renames `assigner_on_demand` pallet to `on_demand` + +crates: +- name: polkadot-runtime-parachains + bump: patch From a142540464e80d9b47b25f7374fa4f9d6e11a06a Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 18 Jul 2024 18:11:32 +0200 Subject: [PATCH 64/67] Fix merge --- .../runtime/parachains/src/on_demand/tests.rs | 65 ------------------- prdoc/pr_3940.prdoc | 19 ------ 2 files changed, 84 deletions(-) delete mode 100644 prdoc/pr_3940.prdoc diff --git a/polkadot/runtime/parachains/src/on_demand/tests.rs b/polkadot/runtime/parachains/src/on_demand/tests.rs index 7ed19cb3579d..115eff84b5dd 100644 --- a/polkadot/runtime/parachains/src/on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/on_demand/tests.rs @@ -774,71 +774,6 @@ fn revenue_information_fetching_works() { }); } -#[test] -fn revenue_information_fetching_works() { - new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { - let para_a = ParaId::from(111); - schedule_blank_para(para_a, ParaKind::Parathread); - // Mock assigner sets max revenue history to 10. - run_to_block(10, |n| if n == 10 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(10); - - // No revenue should be recorded. - assert_eq!(revenue, 0); - - // Place one order - place_order_run_to_blocknumber(para_a, Some(11)); - let revenue = OnDemandAssigner::get_revenue(); - let claim = OnDemandAssigner::claim_revenue_until(11); - - // Revenue until the current block is still zero as "until" is non-inclusive - assert_eq!(claim, 0); - - run_to_block(12, |n| if n == 12 { Some(Default::default()) } else { None }); - let claim = OnDemandAssigner::claim_revenue_until(12); - - // Revenue for a single order should be recorded and shouldn't have been pruned by the - // previous call - assert_eq!(claim, revenue[0]); - - // Place many orders - place_order(para_a); - place_order(para_a); - - run_to_block(13, |n| if n == 13 { Some(Default::default()) } else { None }); - - place_order(para_a); - - run_to_block(15, |n| if n == 14 { Some(Default::default()) } else { None }); - - let revenue = OnDemandAssigner::claim_revenue_until(15); - - // All 3 orders should be accounted for. - assert_eq!(revenue, 30_000); - - // Place one order - place_order_run_to_blocknumber(para_a, Some(16)); - - let revenue = OnDemandAssigner::claim_revenue_until(15); - - // Order is not in range of the revenue_until call - assert_eq!(revenue, 0); - - run_to_block(21, |n| if n == 20 { Some(Default::default()) } else { None }); - let revenue = OnDemandAssigner::claim_revenue_until(21); - assert_eq!(revenue, 10_000); - - // Make sure overdue revenue is accumulated - for i in 21..=35 { - run_to_block(i, |n| if n % 10 == 0 { Some(Default::default()) } else { None }); - place_order(para_a); - } - run_to_block(36, |_| None); - let revenue = OnDemandAssigner::claim_revenue_until(36); - assert_eq!(revenue, 150_000); - }); -} - #[test] fn pot_account_is_immortal() { new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { diff --git a/prdoc/pr_3940.prdoc b/prdoc/pr_3940.prdoc deleted file mode 100644 index 58557684eb2f..000000000000 --- a/prdoc/pr_3940.prdoc +++ /dev/null @@ -1,19 +0,0 @@ -# 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: "RFC-5: Add request revenue info" - -doc: - - audience: Runtime Dev - description: | - Parially implemented RFC-5 in terms of revenue requests and notifications - -crates: - - name: polkadot-runtime-parachains - bump: major - - name: rococo-runtime - bump: major - - name: westend-runtime - bump: major - - name: pallet-broker - bump: minor From 2c5bc9864836ce43670564abb1789cb0a0c73b56 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Thu, 18 Jul 2024 18:57:29 +0200 Subject: [PATCH 65/67] A bunch of minor fixes --- polkadot/runtime/parachains/src/mock.rs | 2 +- polkadot/runtime/parachains/src/on_demand/tests.rs | 13 ++++--------- substrate/frame/broker/src/mock.rs | 14 ++++---------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 813825384b9e..fbe9ebf809b3 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -400,7 +400,7 @@ parameter_types! { pub const OnDemandPalletId: PalletId = PalletId(*b"py/ondmd"); } -impl assigner_on_demand::Config for Test { +impl on_demand::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type TrafficDefaultValue = OnDemandTrafficDefaultValue; diff --git a/polkadot/runtime/parachains/src/on_demand/tests.rs b/polkadot/runtime/parachains/src/on_demand/tests.rs index 115eff84b5dd..974295411810 100644 --- a/polkadot/runtime/parachains/src/on_demand/tests.rs +++ b/polkadot/runtime/parachains/src/on_demand/tests.rs @@ -17,18 +17,13 @@ use super::*; use crate::{ - assigner_on_demand::{ - self, - mock_helpers::GenesisConfigBuilder, - types::{QueueIndex, ReverseQueueIndex}, - Error, - }, initializer::SessionChangeNotification, mock::{ new_test_ext, Balances, OnDemand, Paras, ParasShared, RuntimeOrigin, Scheduler, System, Test, }, on_demand::{ + self, mock_helpers::GenesisConfigBuilder, types::{QueueIndex, ReverseQueueIndex}, Error, @@ -778,7 +773,7 @@ fn revenue_information_fetching_works() { fn pot_account_is_immortal() { new_test_ext(GenesisConfigBuilder::default().build()).execute_with(|| { let para_a = ParaId::from(111); - let pot = OnDemandAssigner::account_id(); + let pot = OnDemand::account_id(); assert!(!System::account_exists(&pot)); schedule_blank_para(para_a, ParaKind::Parathread); // Mock assigner sets max revenue history to 10. @@ -789,7 +784,7 @@ fn pot_account_is_immortal() { assert!(purchase_revenue > 0); run_to_block(15, |_| None); - let _imb = ::Currency::withdraw( + let _imb = ::Currency::withdraw( &pot, purchase_revenue, WithdrawReasons::FEE, @@ -806,7 +801,7 @@ fn pot_account_is_immortal() { assert!(purchase_revenue > 0); run_to_block(25, |_| None); - let _imb = ::Currency::withdraw( + let _imb = ::Currency::withdraw( &pot, purchase_revenue, WithdrawReasons::FEE, diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 9266efb7b2d3..6b1d2bbf7015 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -33,7 +33,7 @@ use sp_arithmetic::Perbill; use sp_core::{ConstU32, ConstU64, Get}; use sp_runtime::{ traits::{BlockNumberProvider, Identity}, - BuildStorage, + BuildStorage, Saturating, }; type Block = frame_system::mocking::MockBlock; @@ -64,11 +64,8 @@ pub enum CoretimeTraceItem { use CoretimeTraceItem::*; parameter_types! { - // Commented out code is from the reference mock implementation and should be uncommented as - // soon as we have the credit system implemented - pub static CoretimeTrace: Vec<(u32, CoretimeTraceItem)> = Default::default(); - // pub static CoretimeCredit: BTreeMap = Default::default(); + pub static CoretimeCredit: BTreeMap = Default::default(); pub static CoretimeSpending: Vec<(u32, u64)> = Default::default(); pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default(); pub static CoretimeUsage: BTreeMap> = Default::default(); @@ -106,11 +103,8 @@ impl CoretimeInterface for TestCoretimeProvider { mint_to_pot(total); RevenueInbox::::put(OnDemandRevenueRecord { until: when, amount: total }); } - fn credit_account(_who: Self::AccountId, _amount: Self::Balance) { - // Commented out code is from the reference mock implementation and should be uncommented as - // soon as we have the credit system implemented - - // CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); + fn credit_account(who: Self::AccountId, amount: Self::Balance) { + CoretimeCredit::mutate(|c| c.entry(who).or_default().saturating_accrue(amount)); } fn assign_core( core: CoreIndex, From db8f23dcb05fcaa27a5d31f22f6210a08a08996d Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Fri, 19 Jul 2024 09:43:53 +0200 Subject: [PATCH 66/67] Update prdoc --- prdoc/pr_4706.prdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prdoc/pr_4706.prdoc b/prdoc/pr_4706.prdoc index 7b77426c1631..31b0dbaa3628 100644 --- a/prdoc/pr_4706.prdoc +++ b/prdoc/pr_4706.prdoc @@ -10,4 +10,8 @@ doc: crates: - name: polkadot-runtime-parachains + bump: minor +- name: rococo-runtime bump: patch +- name: westend-runtime + bump: patch \ No newline at end of file From 2ffd8333fad68c93b7bd55edefb15361dc460d88 Mon Sep 17 00:00:00 2001 From: Dmitry Sinyavin Date: Mon, 22 Jul 2024 15:11:10 +0200 Subject: [PATCH 67/67] Fix semver in prdoc --- prdoc/pr_4706.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4706.prdoc b/prdoc/pr_4706.prdoc index 31b0dbaa3628..ab235768b10d 100644 --- a/prdoc/pr_4706.prdoc +++ b/prdoc/pr_4706.prdoc @@ -10,7 +10,7 @@ doc: crates: - name: polkadot-runtime-parachains - bump: minor + bump: major - name: rococo-runtime bump: patch - name: westend-runtime