From afb5e753ab2ea82c09e69ed0944b475bb63c0af2 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Sat, 4 May 2024 09:02:26 +0200 Subject: [PATCH 01/48] start --- substrate/frame/broker/src/lib.rs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index d59c4c9c6b24..cf3e62e5a4d4 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -172,6 +172,15 @@ pub mod pallet { #[pallet::storage] pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; + /// Storage map storing the account which will pay for the core during auto-renewal. + /// + /// If `None` the core doesn't have auto-renewal enabled. + // + // Safe to use `Twox64Concat` given that users have no real flexibility manipulating its value. + #[pallet::storage] + pub type AutoRenewals = + StorageMap<_, Twox64Concat, CoreIndex, T::AccountId, OptionQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -803,6 +812,29 @@ pub mod pallet { Ok(()) } + /// Extrinsic for enabling or disabling auto renewal by setting a target account which will get + /// upon renewal. + /// + /// If `target_account` is set to `None` the auto-renewal will be disabled. + #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::notify_core_count())] + pub fn set_auto_renew( + origin: OriginFor, + core: CoreIndex, + target_account: Option, + ) -> DispatchResult { + let _ = ensure_signed(origin)?; + if let Some(acc) = target_account { + // TODO: ensure origin is the parachain's sovereign account. + AutoRenewals::::insert(core, acc); + }else { + // TODO: ensure origin is the parachain's sovereign account or the account itself. + AutoRenewals::::remove(core); + } + + Ok(()) + } + #[pallet::call_index(99)] #[pallet::weight(T::WeightInfo::swap_leases())] pub fn swap_leases(origin: OriginFor, id: TaskId, other: TaskId) -> DispatchResult { From 2716e0fc032a32b92ae3571aa7a5da8122cb5059 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 8 May 2024 21:05:11 +0200 Subject: [PATCH 02/48] setup --- substrate/frame/broker/src/lib.rs | 53 ++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index cf3e62e5a4d4..500982e038d0 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -99,6 +99,12 @@ pub mod pallet { type ConvertBalance: Convert, RelayBalanceOf> + ConvertBack, RelayBalanceOf>; + /// Type used for getting the associated account of a task. This account is controlled by + /// the task itself. + // + // TODO: maybe rename this? + type SovereignAccountOf: Convert; + /// Identifier from which the internal Pot is generated. #[pallet::constant] type PalletId: Get; @@ -172,14 +178,15 @@ pub mod pallet { #[pallet::storage] pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; - /// Storage map storing the account which will pay for the core during auto-renewal. + /// Storage map storing the tasks for cores which have auto-renewal enabled. /// - /// If `None` the core doesn't have auto-renewal enabled. + /// If `None` auto-renewal is disabled. // // Safe to use `Twox64Concat` given that users have no real flexibility manipulating its value. + // + // TODO: Should probably make this a bounded vec instead. #[pallet::storage] - pub type AutoRenewals = - StorageMap<_, Twox64Concat, CoreIndex, T::AccountId, OptionQuery>; + pub type AutoRenewals = StorageMap<_, Twox64Concat, CoreIndex, TaskId, OptionQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -812,26 +819,34 @@ pub mod pallet { Ok(()) } - /// Extrinsic for enabling or disabling auto renewal by setting a target account which will get - /// upon renewal. + /// Extrinsic for enabling auto renewal. /// - /// If `target_account` is set to `None` the auto-renewal will be disabled. + /// Callable by the account associated with the task on the specified core. This account + /// will be charged at the start of every bulk period for renewing core time. #[pallet::call_index(20)] #[pallet::weight(T::WeightInfo::notify_core_count())] - pub fn set_auto_renew( - origin: OriginFor, - core: CoreIndex, - target_account: Option, - ) -> DispatchResult { + pub fn enable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { let _ = ensure_signed(origin)?; - if let Some(acc) = target_account { - // TODO: ensure origin is the parachain's sovereign account. - AutoRenewals::::insert(core, acc); - }else { - // TODO: ensure origin is the parachain's sovereign account or the account itself. - AutoRenewals::::remove(core); - } + let mut sale = SaleInfo::::get().ok_or(Error::::NoSales)?; + let renewal_id = AllowedRenewalId { core, when: sale.region_begin }; + let record = AllowedRenewals::::get(renewal_id).ok_or(Error::::NotAllowed)?; + + let workload = + record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; + // Given that only non-interlaced cores can be renewed, there should be only one + // assignment in the core's workload. + ensure!(workload.len() == 1, Error::::IncompleteAssignment); + let schedule_item = &workload[0]; + let CoreAssignment::Task(task_id) = schedule_item.assignment else { + todo!(); + }; + + // TODO: ensure origin is the parachain's sovereign account. + AutoRenewals::::insert(core, task_id); + + // The caller must pay for the transaction otherwise spamming would be possible by + // turning auto-renewal on and off. Ok(()) } From e443c9efbb3e0cfc820c99a8ba3f0a9261fd0c50 Mon Sep 17 00:00:00 2001 From: Szegoo Date: Thu, 9 May 2024 16:49:46 +0200 Subject: [PATCH 03/48] outlining the main logic --- substrate/frame/broker/src/lib.rs | 22 ++++++++++++++++++---- substrate/frame/broker/src/mock.rs | 11 ++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 500982e038d0..7e1f3c530bde 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -826,11 +826,25 @@ pub mod pallet { #[pallet::call_index(20)] #[pallet::weight(T::WeightInfo::notify_core_count())] pub fn enable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { - let _ = ensure_signed(origin)?; + let who = ensure_signed(origin)?; + // TODO: ensure origin is the parachain's sovereign account. let mut sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - let renewal_id = AllowedRenewalId { core, when: sale.region_begin }; - let record = AllowedRenewals::::get(renewal_id).ok_or(Error::::NotAllowed)?; + + // If the core hasn't been renewed yet we will renew it now. + let record = if let Some(record) = + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) + { + Self::do_renew(who, core)?; + record + } else { + // If we couldn't find the renewal record for the current bulk period we should be + // able to find it for the upcoming bulk period. + // + // If not the core is not eligable for renewal. + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) + .ok_or(Error::::NotAllowed)? + }; let workload = record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; @@ -839,10 +853,10 @@ pub mod pallet { ensure!(workload.len() == 1, Error::::IncompleteAssignment); let schedule_item = &workload[0]; let CoreAssignment::Task(task_id) = schedule_item.assignment else { + // return an error. todo!(); }; - // TODO: ensure origin is the parachain's sovereign account. AutoRenewals::::insert(core, task_id); // The caller must pay for the transaction otherwise spamming would be possible by diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 6219b4eff1b4..e0698682d7a9 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -31,7 +31,7 @@ use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_arithmetic::Perbill; use sp_core::{ConstU32, ConstU64, Get}; use sp_runtime::{ - traits::{BlockNumberProvider, Identity}, + traits::{BlockNumberProvider, Convert, Identity}, BuildStorage, Saturating, }; use sp_std::collections::btree_map::BTreeMap; @@ -187,6 +187,14 @@ ord_parameter_types! { } type EnsureOneOrRoot = EitherOfDiverse, EnsureSignedBy>; +pub struct TaskToAccountId; +// TODO +impl Convert for TaskToAccountId { + fn convert(_task: TaskId) -> u64 { + 0 + } +} + impl crate::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = ItemOf, ()>, (), u64>; @@ -200,6 +208,7 @@ impl crate::Config for Test { type PalletId = TestBrokerId; type AdminOrigin = EnsureOneOrRoot; type PriceAdapter = Linear; + type SovereignAccountOf = TaskToAccountId; } pub fn advance_to(b: u64) { From 2a8a68bebfe937b9b0601f9db5cffa073c25e5ff Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 10 May 2024 10:16:07 +0200 Subject: [PATCH 04/48] bounded vec --- substrate/frame/broker/src/lib.rs | 24 ++++++++++++++---------- substrate/frame/broker/src/tick_impls.rs | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 7e1f3c530bde..bd17c96b6353 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -120,6 +120,9 @@ pub mod pallet { /// Maximum number of system cores. #[pallet::constant] type MaxReservedCores: Get; + + #[pallet::constant] + type MaxAutoRenewals: Get; } /// The current configuration of this pallet. @@ -178,15 +181,10 @@ pub mod pallet { #[pallet::storage] pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; - /// Storage map storing the tasks for cores which have auto-renewal enabled. - /// - /// If `None` auto-renewal is disabled. - // - // Safe to use `Twox64Concat` given that users have no real flexibility manipulating its value. - // - // TODO: Should probably make this a bounded vec instead. + /// Keeping track of cores which have auto-renewal enabled. #[pallet::storage] - pub type AutoRenewals = StorageMap<_, Twox64Concat, CoreIndex, TaskId, OptionQuery>; + pub type AutoRenewals = + StorageValue<_, BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -829,7 +827,7 @@ pub mod pallet { let who = ensure_signed(origin)?; // TODO: ensure origin is the parachain's sovereign account. - let mut sale = SaleInfo::::get().ok_or(Error::::NoSales)?; + let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; // If the core hasn't been renewed yet we will renew it now. let record = if let Some(record) = @@ -857,7 +855,13 @@ pub mod pallet { todo!(); }; - AutoRenewals::::insert(core, task_id); + AutoRenewals::::try_mutate(|renewals| { + let pos = renewals + .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .unwrap_or_else(|e| e); + renewals.try_insert(pos, (core, task_id)) + }) + .map_err(|_| Error::::NotAllowed)?; // TODO: custom error // The caller must pay for the transaction otherwise spamming would be possible by // turning auto-renewal on and off. diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 04e9a65bf8f6..5080411fe0ce 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -21,7 +21,7 @@ use sp_arithmetic::{ traits::{One, SaturatedConversion, Saturating, Zero}, FixedPointNumber, }; -use sp_runtime::traits::ConvertBack; +use sp_runtime::traits::{Convert, ConvertBack}; use sp_std::{vec, vec::Vec}; use CompletionStatus::Complete; @@ -238,6 +238,8 @@ impl Pallet { }); Leases::::put(&leases); + Self::renew_cores(); + let max_possible_sales = status.core_count.saturating_sub(first_core); let limit_cores_offered = config.limit_cores_offered.unwrap_or(CoreIndex::max_value()); let cores_offered = limit_cores_offered.min(max_possible_sales); @@ -329,4 +331,15 @@ impl Pallet { T::Coretime::assign_core(core, rc_begin, assignment.clone(), None); Self::deposit_event(Event::::CoreAssigned { core, when: rc_begin, assignment }); } + + /// Renews all the cores which have auto-renewal enabled. + pub(crate) fn renew_cores() { + let renewals = AutoRenewals::::get(); + renewals.iter().for_each(|(core, task_id)| { + let payer = T::SovereignAccountOf::convert(*task_id); + if let Err(_) = Self::do_renew(payer, *core) { + // TODO: emit event + } + }); + } } From 8df2f81a3ada207f2f0992b9f747cae8bac82a08 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sat, 11 May 2024 09:19:39 +0200 Subject: [PATCH 05/48] resolvinig some todos --- substrate/frame/broker/src/lib.rs | 24 +++++++++++++++++------- substrate/frame/broker/src/tests.rs | 5 +++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index bd17c96b6353..8223aa77bb25 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -499,6 +499,12 @@ pub mod pallet { InvalidConfig, /// The revenue must be claimed for 1 or more timeslices. NoClaimTimeslices, + /// The caller doesn't have the permission to enable or disable auto-renewal. + NoPermission, + /// We reached the limit for auto-renewals. + TooManyAutoRenewals, + /// Only cores which are assigned to a task can be auto-renewed. + NonTaskAutoRenewal, } #[pallet::hooks] @@ -825,15 +831,13 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::notify_core_count())] pub fn enable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { let who = ensure_signed(origin)?; - // TODO: ensure origin is the parachain's sovereign account. let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - // If the core hasn't been renewed yet we will renew it now. let record = if let Some(record) = AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) { - Self::do_renew(who, core)?; + Self::do_renew(who.clone(), core)?; record } else { // If we couldn't find the renewal record for the current bulk period we should be @@ -846,22 +850,28 @@ pub mod pallet { let workload = record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; + // Given that only non-interlaced cores can be renewed, there should be only one // assignment in the core's workload. ensure!(workload.len() == 1, Error::::IncompleteAssignment); - let schedule_item = &workload[0]; + let Some(schedule_item) = workload.get(0) else { + return Err(Error::::NotAllowed.into()) + }; + let CoreAssignment::Task(task_id) = schedule_item.assignment else { - // return an error. - todo!(); + return Err(Error::::NonTaskAutoRenewal.into()) }; + // Only the sovereign account of the task can enable auto-renewal. + ensure!(who == T::SovereignAccountOf::convert(task_id), Error::::NoPermission); + AutoRenewals::::try_mutate(|renewals| { let pos = renewals .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) .unwrap_or_else(|e| e); renewals.try_insert(pos, (core, task_id)) }) - .map_err(|_| Error::::NotAllowed)?; // TODO: custom error + .map_err(|_| Error::::TooManyAutoRenewals)?; // The caller must pay for the transaction otherwise spamming would be possible by // turning auto-renewal on and off. diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index f929f0d50dcf..e5766702ee7c 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1428,3 +1428,8 @@ fn start_sales_sets_correct_core_count() { System::assert_has_event(Event::::CoreCountRequested { core_count: 9 }.into()); }) } + +#[test] +fn enable_auto_renew_works() { + TestExt::new().endow(1, 1000).execute_with(|| {}) +} From 82859ad82461ca3679de846de297cfc4387d922e Mon Sep 17 00:00:00 2001 From: Sergej Date: Sat, 11 May 2024 09:44:03 +0200 Subject: [PATCH 06/48] auto-renew for legacy leases --- substrate/frame/broker/src/lib.rs | 39 ++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 8223aa77bb25..936d539186ae 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -827,25 +827,38 @@ pub mod pallet { /// /// Callable by the account associated with the task on the specified core. This account /// will be charged at the start of every bulk period for renewing core time. + /// + /// The optional `workload_end_hint` parameter should be used when enabling auto-renewal for + /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. #[pallet::call_index(20)] #[pallet::weight(T::WeightInfo::notify_core_count())] - pub fn enable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { + pub fn enable_auto_renew( + origin: OriginFor, + core: CoreIndex, + workload_end_hint: Option, + ) -> DispatchResult { let who = ensure_signed(origin)?; let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - // If the core hasn't been renewed yet we will renew it now. - let record = if let Some(record) = - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) - { - Self::do_renew(who.clone(), core)?; - record - } else { - // If we couldn't find the renewal record for the current bulk period we should be - // able to find it for the upcoming bulk period. - // - // If not the core is not eligable for renewal. - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) + + let record = if let Some(workload_end) = workload_end_hint { + AllowedRenewals::::get(AllowedRenewalId { core, when: workload_end }) .ok_or(Error::::NotAllowed)? + } else { + // If the core hasn't been renewed yet we will renew it now. + if let Some(record) = + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) + { + Self::do_renew(who.clone(), core)?; + record + } else { + // If we couldn't find the renewal record for the current bulk period we should + // be able to find it for the upcoming bulk period. + // + // If not the core is not eligable for renewal. + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) + .ok_or(Error::::NotAllowed)? + } }; let workload = From e2a4dd5d321552bfb5244bf126ae68a83acff5e1 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sat, 11 May 2024 10:38:25 +0200 Subject: [PATCH 07/48] init test --- .../frame/broker/src/dispatchable_impls.rs | 56 +++++++++++++++++++ substrate/frame/broker/src/lib.rs | 50 +---------------- substrate/frame/broker/src/mock.rs | 7 ++- substrate/frame/broker/src/tests.rs | 18 ++++-- 4 files changed, 74 insertions(+), 57 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 45a0a514c307..8eaeade34280 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -469,6 +469,62 @@ impl Pallet { Ok(()) } + pub(crate) fn do_enable_auto_renew( + who: T::AccountId, + core: CoreIndex, + workload_end_hint: Option, + ) -> DispatchResult { + let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; + + let record = if let Some(workload_end) = workload_end_hint { + AllowedRenewals::::get(AllowedRenewalId { core, when: workload_end }) + .ok_or(Error::::NotAllowed)? + } else { + // If the core hasn't been renewed yet we will renew it now. + if let Some(record) = + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) + { + Self::do_renew(who.clone(), core)?; + record + } else { + // If we couldn't find the renewal record for the current bulk period we should + // be able to find it for the upcoming bulk period. + // + // If not the core is not eligable for renewal. + AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) + .ok_or(Error::::NotAllowed)? + } + }; + + let workload = + record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; + + // Given that only non-interlaced cores can be renewed, there should be only one + // assignment in the core's workload. + ensure!(workload.len() == 1, Error::::IncompleteAssignment); + let Some(schedule_item) = workload.get(0) else { + return Err(Error::::NotAllowed.into()) + }; + + let CoreAssignment::Task(task_id) = schedule_item.assignment else { + return Err(Error::::NonTaskAutoRenewal.into()) + }; + + // Only the sovereign account of the task can enable auto-renewal. + ensure!(who == T::SovereignAccountOf::convert(task_id), Error::::NoPermission); + + AutoRenewals::::try_mutate(|renewals| { + let pos = renewals + .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .unwrap_or_else(|e| e); + renewals.try_insert(pos, (core, task_id)) + }) + .map_err(|_| Error::::TooManyAutoRenewals)?; + + // TODO: event + Ok(()) + } + pub(crate) fn ensure_cores_for_sale( status: &StatusRecord, sale: &SaleInfoRecordOf, diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 936d539186ae..7b46c67fd320 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -101,8 +101,6 @@ pub mod pallet { /// Type used for getting the associated account of a task. This account is controlled by /// the task itself. - // - // TODO: maybe rename this? type SovereignAccountOf: Convert; /// Identifier from which the internal Pot is generated. @@ -838,53 +836,7 @@ pub mod pallet { workload_end_hint: Option, ) -> DispatchResult { let who = ensure_signed(origin)?; - - let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - - let record = if let Some(workload_end) = workload_end_hint { - AllowedRenewals::::get(AllowedRenewalId { core, when: workload_end }) - .ok_or(Error::::NotAllowed)? - } else { - // If the core hasn't been renewed yet we will renew it now. - if let Some(record) = - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) - { - Self::do_renew(who.clone(), core)?; - record - } else { - // If we couldn't find the renewal record for the current bulk period we should - // be able to find it for the upcoming bulk period. - // - // If not the core is not eligable for renewal. - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) - .ok_or(Error::::NotAllowed)? - } - }; - - let workload = - record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; - - // Given that only non-interlaced cores can be renewed, there should be only one - // assignment in the core's workload. - ensure!(workload.len() == 1, Error::::IncompleteAssignment); - let Some(schedule_item) = workload.get(0) else { - return Err(Error::::NotAllowed.into()) - }; - - let CoreAssignment::Task(task_id) = schedule_item.assignment else { - return Err(Error::::NonTaskAutoRenewal.into()) - }; - - // Only the sovereign account of the task can enable auto-renewal. - ensure!(who == T::SovereignAccountOf::convert(task_id), Error::::NoPermission); - - AutoRenewals::::try_mutate(|renewals| { - let pos = renewals - .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) - .unwrap_or_else(|e| e); - renewals.try_insert(pos, (core, task_id)) - }) - .map_err(|_| Error::::TooManyAutoRenewals)?; + Self::do_enable_auto_renew(who, core, workload_end_hint)?; // The caller must pay for the transaction otherwise spamming would be possible by // turning auto-renewal on and off. diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index e0698682d7a9..451a2b784434 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -188,10 +188,10 @@ ord_parameter_types! { type EnsureOneOrRoot = EitherOfDiverse, EnsureSignedBy>; pub struct TaskToAccountId; -// TODO +// Dummy implementation which converts `TaskId` to `AccountId`. impl Convert for TaskToAccountId { - fn convert(_task: TaskId) -> u64 { - 0 + fn convert(task: TaskId) -> u64 { + task.into() } } @@ -209,6 +209,7 @@ impl crate::Config for Test { type AdminOrigin = EnsureOneOrRoot; type PriceAdapter = Linear; type SovereignAccountOf = TaskToAccountId; + type MaxAutoRenewals = ConstU32<5>; } pub fn advance_to(b: u64) { diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index e5766702ee7c..fac6e381db16 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1409,6 +1409,19 @@ fn renewal_works_leases_ended_before_start_sales() { }); } +#[test] +fn enable_auto_renew_works() { + TestExt::new().endow(1, 1000).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 1)); + advance_to(2); + let region = Broker::do_purchase(1, u64::max_value()).unwrap(); + assert_ok!(Broker::do_assign(region, Some(1), 1001, Final)); + + assert_ok!(Broker::do_enable_auto_renew(1001, region.core, None)); + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + }); +} + #[test] fn start_sales_sets_correct_core_count() { TestExt::new().endow(1, 1000).execute_with(|| { @@ -1428,8 +1441,3 @@ fn start_sales_sets_correct_core_count() { System::assert_has_event(Event::::CoreCountRequested { core_count: 9 }.into()); }) } - -#[test] -fn enable_auto_renew_works() { - TestExt::new().endow(1, 1000).execute_with(|| {}) -} From 9c1c7e3cb22f780e3af2d4f8ecde5e9c45bf5c46 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 12 May 2024 10:34:54 +0200 Subject: [PATCH 08/48] more tests --- .../frame/broker/src/dispatchable_impls.rs | 2 +- substrate/frame/broker/src/lib.rs | 16 ++++++++++ substrate/frame/broker/src/tests.rs | 31 +++++++++++++++++-- substrate/frame/broker/src/tick_impls.rs | 8 ++--- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 8eaeade34280..a21ef9b26618 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -521,7 +521,7 @@ impl Pallet { }) .map_err(|_| Error::::TooManyAutoRenewals)?; - // TODO: event + Self::deposit_event(Event::AutoRenewalEnabled { core, task: task_id }); Ok(()) } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 7b46c67fd320..dc14b7b0d98b 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -431,6 +431,22 @@ pub mod pallet { /// The core whose workload is no longer available to be renewed for `when`. core: CoreIndex, }, + AutoRenewalEnabled { + /// The core for which the renewal was enabled. + core: CoreIndex, + /// The task for which the renewal was enabled. + task: TaskId, + }, + /// Failed to auto-renew a core, likely due to the payer account not being sufficiently + /// funded. + AutoRenewalFailed { + /// The core for which the renewal failed. + core: CoreIndex, + /// The task for which the renewal failed. + task: TaskId, + /// The account which was supposed to pay for renewal. + payer: T::AccountId, + }, } #[pallet::error] diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index fac6e381db16..eeb5dce5c16d 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1414,11 +1414,36 @@ fn enable_auto_renew_works() { TestExt::new().endow(1, 1000).execute_with(|| { assert_ok!(Broker::do_start_sales(100, 1)); advance_to(2); - let region = Broker::do_purchase(1, u64::max_value()).unwrap(); - assert_ok!(Broker::do_assign(region, Some(1), 1001, Final)); + let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); + let record = Regions::::get(region_id).unwrap(); + + // Cannot enable auto renewal with provisional finality: + assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Provisional)); + assert_noop!( + Broker::do_enable_auto_renew(1001, region_id.core, None), + Error::::NotAllowed + ); + + // Eligible for renewal after final assignment: + assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); + assert!(AllowedRenewals::::get(AllowedRenewalId { + core: region_id.core, + when: record.end + }) + .is_some()); + + // Only the task's sovereign account can enable auto renewal. + assert_noop!( + Broker::do_enable_auto_renew(1, region_id.core, None), + Error::::NoPermission + ); - assert_ok!(Broker::do_enable_auto_renew(1001, region.core, None)); + // Works when calling with the sovereign account: + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + System::assert_has_event( + Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), + ); }); } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 5080411fe0ce..e7795abeb851 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -335,10 +335,10 @@ impl Pallet { /// Renews all the cores which have auto-renewal enabled. pub(crate) fn renew_cores() { let renewals = AutoRenewals::::get(); - renewals.iter().for_each(|(core, task_id)| { - let payer = T::SovereignAccountOf::convert(*task_id); - if let Err(_) = Self::do_renew(payer, *core) { - // TODO: emit event + renewals.into_iter().for_each(|(core, task)| { + let payer = T::SovereignAccountOf::convert(task); + if let Err(_) = Self::do_renew(payer.clone(), core) { + Self::deposit_event(Event::::AutoRenewalFailed { core, task, payer }); } }); } From c7ccf5a76fb1a59b206627db06a453770f2024c0 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 12 May 2024 11:33:06 +0200 Subject: [PATCH 09/48] enable_auto_renew_renews --- substrate/frame/broker/src/mock.rs | 6 +++- substrate/frame/broker/src/tests.rs | 50 +++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 451a2b784434..d45c0d8cc08f 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -258,6 +258,10 @@ pub fn new_config() -> ConfigRecordOf { } } +pub fn endow(who: u64, amount: u64) { + assert_ok!(<::Currency as Mutate<_>>::mint_into(&who, amount)); +} + pub struct TestExt(ConfigRecordOf); #[allow(dead_code)] impl TestExt { @@ -306,7 +310,7 @@ impl TestExt { } pub fn endow(self, who: u64, amount: u64) -> Self { - assert_ok!(<::Currency as Mutate<_>>::mint_into(&who, amount)); + endow(who, amount); self } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index eeb5dce5c16d..bde1b9e9a225 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1411,8 +1411,8 @@ fn renewal_works_leases_ended_before_start_sales() { #[test] fn enable_auto_renew_works() { - TestExt::new().endow(1, 1000).execute_with(|| { - assert_ok!(Broker::do_start_sales(100, 1)); + TestExt::new().endow(1, 1000).limit_cores_offered(Some(10)).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 3)); advance_to(2); let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); let record = Regions::::get(region_id).unwrap(); @@ -1444,6 +1444,52 @@ fn enable_auto_renew_works() { System::assert_has_event( Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), ); + + // Enabling auto-renewal for more cores to ensure they are sorted based on core index. + let region_2 = Broker::do_purchase(1, u64::max_value()).unwrap(); + let region_3 = Broker::do_purchase(1, u64::max_value()).unwrap(); + assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); + assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); + + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1002), (2, 1003)]); + }); +} + +#[test] +fn enable_auto_renew_renews() { + TestExt::new().endow(1, 1000).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 1)); + advance_to(2); + let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); + + assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); + // advance to next bulk sale: + advance_to(6); + + // Since we didn't renew for the next bulk period, enabling auto-renewal will renew. + + // Will fail because we didn't fund the sovereign account: + assert_noop!( + Broker::do_enable_auto_renew(1001, region_id.core, None), + TokenError::FundsUnavailable + ); + + // Will succeed after funding the sovereign account: + endow(1001, 1000); + + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + assert!(AllowedRenewals::::get(AllowedRenewalId { + core: region_id.core, + when: 10 // region end after renewal + }) + .is_some()); + + System::assert_has_event( + Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), + ); }); } From c3eaa21075a472f3a9c0d46f23381d3ceb02a3b0 Mon Sep 17 00:00:00 2001 From: Sergej Date: Sun, 12 May 2024 13:34:48 +0200 Subject: [PATCH 10/48] different approach --- .../frame/broker/src/coretime_interface.rs | 17 +++++++++++++- .../frame/broker/src/dispatchable_impls.rs | 16 ++++++------- substrate/frame/broker/src/lib.rs | 12 +++++++--- substrate/frame/broker/src/mock.rs | 23 ++++++++++++++----- substrate/frame/broker/src/tests.rs | 3 +++ substrate/frame/broker/src/tick_impls.rs | 4 ++-- 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 58efa7fa92bb..a5f872a9838d 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -22,7 +22,7 @@ use frame_support::Parameter; use scale_info::TypeInfo; use sp_arithmetic::traits::AtLeast32BitUnsigned; use sp_core::RuntimeDebug; -use sp_runtime::traits::BlockNumberProvider; +use sp_runtime::traits::{BadOrigin, BlockNumberProvider}; use sp_std::vec::Vec; /// Index of a Polkadot Core. @@ -146,3 +146,18 @@ impl CoretimeInterface for () { #[cfg(feature = "runtime-benchmarks")] fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } + +/// TODO +pub trait TaskAccountInterface { + /// TODO + type AccountId; + /// TODO + type OuterOrigin: Into>; + /// TODO + type TaskOrigin; + + /// TODO + fn ensure_task_sovereign_account(o: Self::OuterOrigin) -> Result; + /// TODO + fn sovereign_account(task: TaskId) -> Self::AccountId; +} diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index a21ef9b26618..60a423df1453 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -470,7 +470,7 @@ impl Pallet { } pub(crate) fn do_enable_auto_renew( - who: T::AccountId, + task: TaskId, core: CoreIndex, workload_end_hint: Option, ) -> DispatchResult { @@ -484,7 +484,7 @@ impl Pallet { if let Some(record) = AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) { - Self::do_renew(who.clone(), core)?; + Self::do_renew(T::SovereignAccountOf::sovereign_account(task), core)?; record } else { // If we couldn't find the renewal record for the current bulk period we should @@ -506,22 +506,22 @@ impl Pallet { return Err(Error::::NotAllowed.into()) }; - let CoreAssignment::Task(task_id) = schedule_item.assignment else { + if let CoreAssignment::Task(core_task) = schedule_item.assignment { + // Sovereign account of a task can only enable auto renewal for its own core. + ensure!(task == core_task, Error::::NoPermission); + } else { return Err(Error::::NonTaskAutoRenewal.into()) }; - // Only the sovereign account of the task can enable auto-renewal. - ensure!(who == T::SovereignAccountOf::convert(task_id), Error::::NoPermission); - AutoRenewals::::try_mutate(|renewals| { let pos = renewals .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) .unwrap_or_else(|e| e); - renewals.try_insert(pos, (core, task_id)) + renewals.try_insert(pos, (core, task)) }) .map_err(|_| Error::::TooManyAutoRenewals)?; - Self::deposit_event(Event::AutoRenewalEnabled { core, task: task_id }); + Self::deposit_event(Event::AutoRenewalEnabled { core, task }); Ok(()) } diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index dc14b7b0d98b..ceb5d4f06d20 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -101,7 +101,10 @@ pub mod pallet { /// Type used for getting the associated account of a task. This account is controlled by /// the task itself. - type SovereignAccountOf: Convert; + type SovereignAccountOf: TaskAccountInterface< + AccountId = Self::AccountId, + OuterOrigin = Self::RuntimeOrigin, + >; /// Identifier from which the internal Pot is generated. #[pallet::constant] @@ -842,6 +845,8 @@ pub mod pallet { /// Callable by the account associated with the task on the specified core. This account /// will be charged at the start of every bulk period for renewing core time. /// + /// - `origin`: Must be the sovereign account of the task + /// - `core`: The core for which we want to enable auto renewal. /// The optional `workload_end_hint` parameter should be used when enabling auto-renewal for /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. #[pallet::call_index(20)] @@ -851,8 +856,9 @@ pub mod pallet { core: CoreIndex, workload_end_hint: Option, ) -> DispatchResult { - let who = ensure_signed(origin)?; - Self::do_enable_auto_renew(who, core, workload_end_hint)?; + // Only the sovereign account of the task can enable auto-renewal. + let task = T::SovereignAccountOf::ensure_task_sovereign_account(origin)?; + Self::do_enable_auto_renew(task, core, workload_end_hint)?; // The caller must pay for the transaction otherwise spamming would be possible by // turning auto-renewal on and off. diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index d45c0d8cc08f..423ec2ef4abd 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -27,11 +27,11 @@ use frame_support::{ }, PalletId, }; -use frame_system::{EnsureRoot, EnsureSignedBy}; +use frame_system::{EnsureRoot, EnsureSignedBy, RawOrigin}; use sp_arithmetic::Perbill; use sp_core::{ConstU32, ConstU64, Get}; use sp_runtime::{ - traits::{BlockNumberProvider, Convert, Identity}, + traits::{BadOrigin, BlockNumberProvider, Identity}, BuildStorage, Saturating, }; use sp_std::collections::btree_map::BTreeMap; @@ -187,10 +187,21 @@ ord_parameter_types! { } type EnsureOneOrRoot = EitherOfDiverse, EnsureSignedBy>; -pub struct TaskToAccountId; +pub struct TaskSovereignAccount; // Dummy implementation which converts `TaskId` to `AccountId`. -impl Convert for TaskToAccountId { - fn convert(task: TaskId) -> u64 { +impl TaskAccountInterface for TaskSovereignAccount { + type AccountId = u64; + type OuterOrigin = RuntimeOrigin; + type TaskOrigin = RawOrigin; + + fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { + match o.into() { + Ok(RawOrigin::Signed(account)) => Ok(account as TaskId), + _ => Err(BadOrigin), + } + } + + fn sovereign_account(task: TaskId) -> u64 { task.into() } } @@ -208,7 +219,7 @@ impl crate::Config for Test { type PalletId = TestBrokerId; type AdminOrigin = EnsureOneOrRoot; type PriceAdapter = Linear; - type SovereignAccountOf = TaskToAccountId; + type SovereignAccountOf = TaskSovereignAccount; type MaxAutoRenewals = ConstU32<5>; } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index bde1b9e9a225..782b3133ab92 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1457,6 +1457,9 @@ fn enable_auto_renew_works() { }); } +#[test] +fn enable_auto_renewal_with_end_hint_works() {} + #[test] fn enable_auto_renew_renews() { TestExt::new().endow(1, 1000).execute_with(|| { diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index e7795abeb851..4fbe7ad75aef 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -21,7 +21,7 @@ use sp_arithmetic::{ traits::{One, SaturatedConversion, Saturating, Zero}, FixedPointNumber, }; -use sp_runtime::traits::{Convert, ConvertBack}; +use sp_runtime::traits::ConvertBack; use sp_std::{vec, vec::Vec}; use CompletionStatus::Complete; @@ -336,7 +336,7 @@ impl Pallet { pub(crate) fn renew_cores() { let renewals = AutoRenewals::::get(); renewals.into_iter().for_each(|(core, task)| { - let payer = T::SovereignAccountOf::convert(task); + let payer = T::SovereignAccountOf::sovereign_account(task); if let Err(_) = Self::do_renew(payer.clone(), core) { Self::deposit_event(Event::::AutoRenewalFailed { core, task, payer }); } From edffbfc611feef360ada749ae6b042589d2152fd Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 13 May 2024 11:25:37 +0200 Subject: [PATCH 11/48] docs --- substrate/frame/broker/src/coretime_interface.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index a5f872a9838d..097702572eed 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -147,17 +147,21 @@ impl CoretimeInterface for () { fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } -/// TODO +/// Trait for retrieving the associated account and origin of a task. +/// +/// For parachains, this refers to the sovereign account, which is controlled by the parachain itself. pub trait TaskAccountInterface { - /// TODO + /// The type for representing accounts. type AccountId; - /// TODO + /// The overarching origin type. type OuterOrigin: Into>; - /// TODO + /// The custom task origin. Given that all tasks on Polkadot are parachains this will most likely + // be the `Parachain` origin. type TaskOrigin; - /// TODO + /// Ensures that the origin is a task origin and returns the associated `TaskId`. fn ensure_task_sovereign_account(o: Self::OuterOrigin) -> Result; - /// TODO + + /// Returns the associated account of a task. fn sovereign_account(task: TaskId) -> Self::AccountId; } From 68f244ca7bbb6441390f36af2d355481d1f5ae22 Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 13 May 2024 11:45:15 +0200 Subject: [PATCH 12/48] enable_auto_renewal_with_end_hint_works --- .../frame/broker/src/coretime_interface.rs | 9 ++++--- substrate/frame/broker/src/lib.rs | 2 +- substrate/frame/broker/src/tests.rs | 27 ++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 097702572eed..2204ee8b424d 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -149,14 +149,17 @@ impl CoretimeInterface for () { /// Trait for retrieving the associated account and origin of a task. /// -/// For parachains, this refers to the sovereign account, which is controlled by the parachain itself. +/// For parachains, this refers to the sovereign account, which is controlled by the parachain +/// itself. pub trait TaskAccountInterface { /// The type for representing accounts. type AccountId; + /// The overarching origin type. type OuterOrigin: Into>; - /// The custom task origin. Given that all tasks on Polkadot are parachains this will most likely - // be the `Parachain` origin. + + /// The custom task origin. Given that all tasks on Polkadot are parachains this will most + /// likely be the `Parachain` origin. type TaskOrigin; /// Ensures that the origin is a task origin and returns the associated `TaskId`. diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index ceb5d4f06d20..504d6ed7adca 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -847,7 +847,7 @@ pub mod pallet { /// /// - `origin`: Must be the sovereign account of the task /// - `core`: The core for which we want to enable auto renewal. - /// The optional `workload_end_hint` parameter should be used when enabling auto-renewal for + /// - `workload_end_hint` parameter should be used when enabling auto-renewal for /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. #[pallet::call_index(20)] #[pallet::weight(T::WeightInfo::notify_core_count())] diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 782b3133ab92..997e8ea785d0 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1458,7 +1458,32 @@ fn enable_auto_renew_works() { } #[test] -fn enable_auto_renewal_with_end_hint_works() {} +fn enable_auto_renewal_with_end_hint_works() { + TestExt::new().endow(1, 1000).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 1)); + advance_to(2); + + let record = AllowedRenewalRecord { + price: 100, + completion: CompletionStatus::Complete( + vec![ScheduleItem { mask: CoreMask::complete(), assignment: Task(2001) }] + .try_into() + .unwrap(), + ), + }; + // Each lease-holding parachain should be allowed to renew. Although the `when` field will + // likely be to a later timeslice. + AllowedRenewals::::insert(AllowedRenewalId { core: 1, when: 20 }, &record); + + // Will fail if we don't provide the end hint since it expects it to be at next sale start + // or end. + assert_noop!(Broker::do_enable_auto_renew(2001, 1, None), Error::::NotAllowed); + + assert_ok!(Broker::do_enable_auto_renew(2001, 1, Some(20)),); + assert_eq!(AutoRenewals::::get().to_vec(), vec![(1, 2001)]); + System::assert_has_event(Event::::AutoRenewalEnabled { core: 1, task: 2001 }.into()); + }); +} #[test] fn enable_auto_renew_renews() { From 893fa9d8bb8858c71cb82d7e00a12c5ccfdab91c Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 15 May 2024 16:21:40 +0200 Subject: [PATCH 13/48] auto_renewal_works --- substrate/frame/broker/src/tests.rs | 62 ++++++++++++++++++++++++ substrate/frame/broker/src/tick_impls.rs | 8 +-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 997e8ea785d0..b1d9b29cccba 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1521,6 +1521,68 @@ fn enable_auto_renew_renews() { }); } +#[test] +fn auto_renewal_works() { + TestExt::new().endow(1, 1000).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 3)); + advance_to(2); + let region_1 = Broker::do_purchase(1, u64::max_value()).unwrap(); + let region_2 = Broker::do_purchase(1, u64::max_value()).unwrap(); + let region_3 = Broker::do_purchase(1, u64::max_value()).unwrap(); + + // Eligible for renewal after final assignment: + assert_ok!(Broker::do_assign(region_1, Some(1), 1001, Final)); + assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); + assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1002), (2, 1003)]); + + // We have to fund the sovereign account: + endow(1001, 1000); + // We skip funding the sovereign account of task 1002 on purpose. + endow(1003, 1000); + + // Next cycle starting at timeslice 7. + advance_to(7); + System::assert_has_event( + Event::::Renewed { + who: 1001, // sovereign account + old_core: 0, + core: 0, + price: 100, + begin: 7, + duration: 3, + workload: Schedule::truncate_from(vec![ScheduleItem { + assignment: Task(1001), + mask: CoreMask::complete(), + }]), + } + .into(), + ); + // Sovereign account wasn't funded so it fails: + System::assert_has_event( + Event::::AutoRenewalFailed { core: 1, task: 1002, payer: 1002 }.into(), + ); + System::assert_has_event( + Event::::Renewed { + who: 1003, // sovereign account + old_core: 2, + core: 1, // Core #1 didn't get renewed, so core #2 will take its place. + price: 100, + begin: 7, + duration: 3, + workload: Schedule::truncate_from(vec![ScheduleItem { + assignment: Task(1003), + mask: CoreMask::complete(), + }]), + } + .into(), + ); + }); +} + #[test] fn start_sales_sets_correct_core_count() { TestExt::new().endow(1, 1000).execute_with(|| { diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 4fbe7ad75aef..304543da362d 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -238,8 +238,6 @@ impl Pallet { }); Leases::::put(&leases); - Self::renew_cores(); - let max_possible_sales = status.core_count.saturating_sub(first_core); let limit_cores_offered = config.limit_cores_offered.unwrap_or(CoreIndex::max_value()); let cores_offered = limit_cores_offered.min(max_possible_sales); @@ -260,6 +258,9 @@ impl Pallet { cores_sold: 0, }; SaleInfo::::put(&new_sale); + + Self::renew_cores(); + Self::deposit_event(Event::SaleInitialized { sale_start, leadin_length, @@ -337,7 +338,8 @@ impl Pallet { let renewals = AutoRenewals::::get(); renewals.into_iter().for_each(|(core, task)| { let payer = T::SovereignAccountOf::sovereign_account(task); - if let Err(_) = Self::do_renew(payer.clone(), core) { + if let Err(_e) = Self::do_renew(payer.clone(), core) { + println!("{:?}", _e); Self::deposit_event(Event::::AutoRenewalFailed { core, task, payer }); } }); From 0b50a5878c581bbca2b9a683bcecbfac10972474 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 15 May 2024 17:24:38 +0200 Subject: [PATCH 14/48] progress --- Cargo.lock | 1 + .../coretime/coretime-rococo/Cargo.toml | 1 + .../coretime/coretime-rococo/src/coretime.rs | 34 +++++++++++++++++-- .../coretime/coretime-rococo/src/lib.rs | 2 ++ .../frame/broker/src/coretime_interface.rs | 6 ++-- .../frame/broker/src/dispatchable_impls.rs | 6 +++- substrate/frame/broker/src/lib.rs | 4 +++ substrate/frame/broker/src/mock.rs | 2 +- substrate/frame/broker/src/tick_impls.rs | 10 ++++-- 9 files changed, 56 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 634a98f82f88..626a2b7ea11a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3207,6 +3207,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", + "polkadot-runtime-parachains", "rococo-runtime-constants", "scale-info", "serde", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index ee9f5e87ec87..7dcda43ca5dd 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -58,6 +58,7 @@ pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features pallet-xcm-benchmarks = { path = "../../../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false, optional = true } polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } +polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains", default-features = false } rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 742dd50f6fa1..4c6cb37cd674 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::*; +use crate::{xcm_config::LocationToAccountId, *}; use codec::{Decode, Encode}; use cumulus_pallet_parachain_system::RelaychainDataProvider; use cumulus_primitives_core::relay_chain; @@ -25,9 +25,15 @@ use frame_support::{ OnUnbalanced, }, }; -use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; +use pallet_broker::{ + CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, + TaskAccountInterface, TaskId, +}; use parachains_common::{AccountId, Balance, BlockNumber}; +use polkadot_runtime_parachains::{ensure_parachain, origin, Origin as ParaOrigin}; +use sp_runtime::traits::BadOrigin; use xcm::latest::prelude::*; +use xcm_executor::traits::ConvertLocation; pub struct CreditToCollatorPot; impl OnUnbalanced> for CreditToCollatorPot { @@ -217,6 +223,28 @@ impl CoretimeInterface for CoretimeAllocator { } } +impl origin::Config for Runtime {} + +pub struct TaskSovereignAccount; +impl TaskAccountInterface for TaskSovereignAccount { + type AccountId = AccountId; + type OuterOrigin = RuntimeOrigin; + type TaskOrigin = ParaOrigin; + + fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { + match ensure_parachain(o) { + Ok(para_id) => Ok(para_id.into()), + Err(e) => Err(e), + } + } + + fn sovereign_account(id: TaskId) -> Option { + // Currently all tasks are parachains. + let location = Location::new(1, [Parachain(id)]); + LocationToAccountId::convert_location(&location) + } +} + impl pallet_broker::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -233,4 +261,6 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type PriceAdapter = pallet_broker::Linear; + type SovereignAccountOf = TaskSovereignAccount; + type MaxAutoRenewals = ConstU32<50>; } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index ab925b04eb7c..b554d48dd659 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -56,6 +56,7 @@ use parachains_common::{ AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use polkadot_runtime_parachains::origin; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] @@ -462,6 +463,7 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility = 40, Multisig: pallet_multisig = 41, + ParachainsOrigin: origin = 42, // The main stage. Broker: pallet_broker = 50, diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 2204ee8b424d..cdc9ff8ed551 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -147,9 +147,9 @@ impl CoretimeInterface for () { fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } -/// Trait for retrieving the associated account and origin of a task. +/// Trait for getting the associated account and origin of a task. /// -/// For parachains, this refers to the sovereign account, which is controlled by the parachain +/// For parachains, this is the sovereign account, which is controlled by the parachain /// itself. pub trait TaskAccountInterface { /// The type for representing accounts. @@ -166,5 +166,5 @@ pub trait TaskAccountInterface { fn ensure_task_sovereign_account(o: Self::OuterOrigin) -> Result; /// Returns the associated account of a task. - fn sovereign_account(task: TaskId) -> Self::AccountId; + fn sovereign_account(task: TaskId) -> Option; } diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 60a423df1453..e0fc3cdedd90 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -475,6 +475,9 @@ impl Pallet { workload_end_hint: Option, ) -> DispatchResult { let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; + let Some(sovereign_account) = T::SovereignAccountOf::sovereign_account(task) else { + return Err(Error::::SovereignAccountNotFound.into()); + }; let record = if let Some(workload_end) = workload_end_hint { AllowedRenewals::::get(AllowedRenewalId { core, when: workload_end }) @@ -484,7 +487,7 @@ impl Pallet { if let Some(record) = AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) { - Self::do_renew(T::SovereignAccountOf::sovereign_account(task), core)?; + Self::do_renew(sovereign_account, core)?; record } else { // If we couldn't find the renewal record for the current bulk period we should @@ -513,6 +516,7 @@ impl Pallet { return Err(Error::::NonTaskAutoRenewal.into()) }; + // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 504d6ed7adca..48500b18d26d 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -183,6 +183,8 @@ pub mod pallet { pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; /// Keeping track of cores which have auto-renewal enabled. + /// + /// Sorted by `CoreIndex` to make the removal of cores from auto-renewal more efficient. #[pallet::storage] pub type AutoRenewals = StorageValue<_, BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals>, ValueQuery>; @@ -522,6 +524,8 @@ pub mod pallet { TooManyAutoRenewals, /// Only cores which are assigned to a task can be auto-renewed. NonTaskAutoRenewal, + /// Failed to get the sovereign account of a task. + SovereignAccountNotFound, } #[pallet::hooks] diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 423ec2ef4abd..c7ef1667a542 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -202,7 +202,7 @@ impl TaskAccountInterface for TaskSovereignAccount { } fn sovereign_account(task: TaskId) -> u64 { - task.into() + Some(task.into()) } } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 304543da362d..3161296f436f 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -338,9 +338,13 @@ impl Pallet { let renewals = AutoRenewals::::get(); renewals.into_iter().for_each(|(core, task)| { let payer = T::SovereignAccountOf::sovereign_account(task); - if let Err(_e) = Self::do_renew(payer.clone(), core) { - println!("{:?}", _e); - Self::deposit_event(Event::::AutoRenewalFailed { core, task, payer }); + if let Err(_) = Self::do_renew(payer.clone().unwrap().clone(), core) { + // TODO: no unwrap + Self::deposit_event(Event::::AutoRenewalFailed { + core, + task, + payer: payer.unwrap(), + }); } }); } From 9dc9b6a0050b69485af7b0fe5d55f574a9f51b12 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 15 May 2024 20:07:46 +0200 Subject: [PATCH 15/48] store account instead of task --- substrate/frame/broker/src/dispatchable_impls.rs | 6 +++--- substrate/frame/broker/src/lib.rs | 4 +--- substrate/frame/broker/src/mock.rs | 2 +- substrate/frame/broker/src/tests.rs | 4 +--- substrate/frame/broker/src/tick_impls.rs | 11 +++-------- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index e0fc3cdedd90..c7deebbab089 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -487,7 +487,7 @@ impl Pallet { if let Some(record) = AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) { - Self::do_renew(sovereign_account, core)?; + Self::do_renew(sovereign_account.clone(), core)?; record } else { // If we couldn't find the renewal record for the current bulk period we should @@ -519,9 +519,9 @@ impl Pallet { // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals - .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .binary_search_by(|r: &(CoreIndex, T::AccountId)| r.0.cmp(&core)) .unwrap_or_else(|e| e); - renewals.try_insert(pos, (core, task)) + renewals.try_insert(pos, (core, sovereign_account)) }) .map_err(|_| Error::::TooManyAutoRenewals)?; diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 48500b18d26d..a2dc471dcba1 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -187,7 +187,7 @@ pub mod pallet { /// Sorted by `CoreIndex` to make the removal of cores from auto-renewal more efficient. #[pallet::storage] pub type AutoRenewals = - StorageValue<_, BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals>, ValueQuery>; + StorageValue<_, BoundedVec<(CoreIndex, T::AccountId), T::MaxAutoRenewals>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -447,8 +447,6 @@ pub mod pallet { AutoRenewalFailed { /// The core for which the renewal failed. core: CoreIndex, - /// The task for which the renewal failed. - task: TaskId, /// The account which was supposed to pay for renewal. payer: T::AccountId, }, diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index c7ef1667a542..231d925f2b82 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -201,7 +201,7 @@ impl TaskAccountInterface for TaskSovereignAccount { } } - fn sovereign_account(task: TaskId) -> u64 { + fn sovereign_account(task: TaskId) -> Option { Some(task.into()) } } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index b1d9b29cccba..0f956c472654 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1562,9 +1562,7 @@ fn auto_renewal_works() { .into(), ); // Sovereign account wasn't funded so it fails: - System::assert_has_event( - Event::::AutoRenewalFailed { core: 1, task: 1002, payer: 1002 }.into(), - ); + System::assert_has_event(Event::::AutoRenewalFailed { core: 1, payer: 1002 }.into()); System::assert_has_event( Event::::Renewed { who: 1003, // sovereign account diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 3161296f436f..e3a1f8352b2a 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -336,15 +336,10 @@ impl Pallet { /// Renews all the cores which have auto-renewal enabled. pub(crate) fn renew_cores() { let renewals = AutoRenewals::::get(); - renewals.into_iter().for_each(|(core, task)| { - let payer = T::SovereignAccountOf::sovereign_account(task); - if let Err(_) = Self::do_renew(payer.clone().unwrap().clone(), core) { + renewals.into_iter().for_each(|(core, payer)| { + if let Err(_) = Self::do_renew(payer.clone(), core) { // TODO: no unwrap - Self::deposit_event(Event::::AutoRenewalFailed { - core, - task, - payer: payer.unwrap(), - }); + Self::deposit_event(Event::::AutoRenewalFailed { core, payer }); } }); } From 9baa77a1d21948a51a777f97a4b3d81cef5bd1b7 Mon Sep 17 00:00:00 2001 From: Sergej Date: Wed, 15 May 2024 20:18:33 +0200 Subject: [PATCH 16/48] fix builds --- Cargo.lock | 1 + .../coretime/coretime-westend/Cargo.toml | 1 + .../coretime/coretime-westend/src/coretime.rs | 34 +++++++++++++++++-- .../coretime/coretime-westend/src/lib.rs | 2 ++ substrate/bin/node/runtime/src/lib.rs | 22 ++++++++++-- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 626a2b7ea11a..b9655d8fa29e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3272,6 +3272,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", + "polkadot-runtime-parachains", "scale-info", "serde", "sp-api", diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 60cc7e2f7654..aeb6fabbcb66 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -57,6 +57,7 @@ pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features pallet-xcm-benchmarks = { path = "../../../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false, optional = true } polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } +polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains", default-features = false } westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 41cbc62fa211..75fe678a710b 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use crate::*; +use crate::{xcm_config::LocationToAccountId, *}; use codec::{Decode, Encode}; use cumulus_pallet_parachain_system::RelaychainDataProvider; use cumulus_primitives_core::relay_chain; @@ -25,9 +25,15 @@ use frame_support::{ OnUnbalanced, }, }; -use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf}; +use pallet_broker::{ + CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, + TaskAccountInterface, TaskId, +}; use parachains_common::{AccountId, Balance, BlockNumber}; +use polkadot_runtime_parachains::{ensure_parachain, origin, Origin as ParaOrigin}; +use sp_runtime::traits::BadOrigin; use xcm::latest::prelude::*; +use xcm_executor::traits::ConvertLocation; pub struct CreditToCollatorPot; impl OnUnbalanced> for CreditToCollatorPot { @@ -229,6 +235,28 @@ impl CoretimeInterface for CoretimeAllocator { } } +impl origin::Config for Runtime {} + +pub struct TaskSovereignAccount; +impl TaskAccountInterface for TaskSovereignAccount { + type AccountId = AccountId; + type OuterOrigin = RuntimeOrigin; + type TaskOrigin = ParaOrigin; + + fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { + match ensure_parachain(o) { + Ok(para_id) => Ok(para_id.into()), + Err(e) => Err(e), + } + } + + fn sovereign_account(id: TaskId) -> Option { + // Currently all tasks are parachains. + let location = Location::new(1, [Parachain(id)]); + LocationToAccountId::convert_location(&location) + } +} + impl pallet_broker::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -246,4 +274,6 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type PriceAdapter = pallet_broker::Linear; + type SovereignAccountOf = TaskSovereignAccount; + type MaxAutoRenewals = ConstU32<10>; } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 61c7b6e49587..d7c207d2be9d 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -56,6 +56,7 @@ use parachains_common::{ AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; +use polkadot_runtime_parachains::origin; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] @@ -457,6 +458,7 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility = 40, Multisig: pallet_multisig = 41, + ParachainsOrigin: origin = 42, // The main stage. Broker: pallet_broker = 50, diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 18b0d0c31a4d..ca86d34ef2e4 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -73,6 +73,7 @@ use pallet_nis::WithMaximumOf; use pallet_session::historical as pallet_session_historical; // Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles // +use pallet_broker::{TaskAccountInterface, TaskId}; #[allow(deprecated)] pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; @@ -91,8 +92,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor, - OpaqueKeys, SaturatedConversion, StaticLookup, + self, AccountIdConversion, BadOrigin, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, + NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -2126,6 +2127,21 @@ impl CoretimeInterface for CoretimeProvider { } } +pub struct TaskSovereignAccount; +// Dummy implementation which converts `TaskId` to `AccountId`. +impl TaskAccountInterface for TaskSovereignAccount { + type AccountId = AccountId; + type OuterOrigin = RuntimeOrigin; + type TaskOrigin = frame_system::RawOrigin; + + fn ensure_task_sovereign_account(_o: RuntimeOrigin) -> Result { + Err(BadOrigin) + } + + fn sovereign_account(_task: TaskId) -> Option { + None + } +} impl pallet_broker::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -2139,6 +2155,8 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type PriceAdapter = pallet_broker::Linear; + type SovereignAccountOf = TaskSovereignAccount; + type MaxAutoRenewals = ConstU32<5>; } parameter_types! { From ee7e3c43a94b054175c76c1b444cfb3cdf61efac Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 17 May 2024 09:58:39 +0200 Subject: [PATCH 17/48] disable auto-renewal --- .../frame/broker/src/dispatchable_impls.rs | 19 +++++++++++++-- substrate/frame/broker/src/lib.rs | 24 +++++++++++++++---- substrate/frame/broker/src/tests.rs | 4 +++- substrate/frame/broker/src/tick_impls.rs | 11 +++++---- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index c7deebbab089..7470c906b465 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -519,9 +519,9 @@ impl Pallet { // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals - .binary_search_by(|r: &(CoreIndex, T::AccountId)| r.0.cmp(&core)) + .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) .unwrap_or_else(|e| e); - renewals.try_insert(pos, (core, sovereign_account)) + renewals.try_insert(pos, (core, task)) }) .map_err(|_| Error::::TooManyAutoRenewals)?; @@ -529,6 +529,21 @@ impl Pallet { Ok(()) } + pub(crate) fn do_disable_auto_renew(task: TaskId, core: CoreIndex) -> DispatchResult { + AutoRenewals::::try_mutate(|renewals| -> DispatchResult { + let pos = renewals + .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .map_err(|_| Error::::AutoRenewalNotEnabled)?; + + ensure!(Some(&(core, task)) == renewals.get(pos), Error::::NoPermission); + renewals.remove(pos); + Ok(()) + })?; + + Self::deposit_event(Event::AutoRenewalDisabled { core, task }); + Ok(()) + } + pub(crate) fn ensure_cores_for_sale( status: &StatusRecord, sale: &SaleInfoRecordOf, diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index a2dc471dcba1..dd481eeea22e 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -187,7 +187,7 @@ pub mod pallet { /// Sorted by `CoreIndex` to make the removal of cores from auto-renewal more efficient. #[pallet::storage] pub type AutoRenewals = - StorageValue<_, BoundedVec<(CoreIndex, T::AccountId), T::MaxAutoRenewals>, ValueQuery>; + StorageValue<_, BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals>, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] @@ -442,13 +442,21 @@ pub mod pallet { /// The task for which the renewal was enabled. task: TaskId, }, + AutoRenewalDisabled { + /// The core for which the renewal was disabled. + core: CoreIndex, + /// The task for which the renewal was disabled. + task: TaskId, + }, /// Failed to auto-renew a core, likely due to the payer account not being sufficiently /// funded. AutoRenewalFailed { /// The core for which the renewal failed. core: CoreIndex, /// The account which was supposed to pay for renewal. - payer: T::AccountId, + /// + /// If `None` it indicates that we failed to get the sovereign account of a task. + payer: Option, }, } @@ -524,6 +532,8 @@ pub mod pallet { NonTaskAutoRenewal, /// Failed to get the sovereign account of a task. SovereignAccountNotFound, + /// Attempted to disable auto-renewal for a core that didn't have it enabled. + AutoRenewalNotEnabled, } #[pallet::hooks] @@ -861,9 +871,15 @@ pub mod pallet { // Only the sovereign account of the task can enable auto-renewal. let task = T::SovereignAccountOf::ensure_task_sovereign_account(origin)?; Self::do_enable_auto_renew(task, core, workload_end_hint)?; + Ok(()) + } - // The caller must pay for the transaction otherwise spamming would be possible by - // turning auto-renewal on and off. + #[pallet::call_index(21)] + #[pallet::weight(T::WeightInfo::notify_core_count())] + pub fn disable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { + // Only the sovereign account of the task can disable auto-renewal. + let task = T::SovereignAccountOf::ensure_task_sovereign_account(origin)?; + Self::do_disable_auto_renew(task, core)?; Ok(()) } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 0f956c472654..00bfb5093b39 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1562,7 +1562,9 @@ fn auto_renewal_works() { .into(), ); // Sovereign account wasn't funded so it fails: - System::assert_has_event(Event::::AutoRenewalFailed { core: 1, payer: 1002 }.into()); + System::assert_has_event( + Event::::AutoRenewalFailed { core: 1, payer: Some(1002) }.into(), + ); System::assert_has_event( Event::::Renewed { who: 1003, // sovereign account diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index e3a1f8352b2a..5546be88bdf8 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -336,11 +336,14 @@ impl Pallet { /// Renews all the cores which have auto-renewal enabled. pub(crate) fn renew_cores() { let renewals = AutoRenewals::::get(); - renewals.into_iter().for_each(|(core, payer)| { + for (core, task) in renewals.into_iter() { + let Some(payer) = T::SovereignAccountOf::sovereign_account(task) else { + Self::deposit_event(Event::::AutoRenewalFailed { core, payer: None }); + continue; + }; if let Err(_) = Self::do_renew(payer.clone(), core) { - // TODO: no unwrap - Self::deposit_event(Event::::AutoRenewalFailed { core, payer }); + Self::deposit_event(Event::::AutoRenewalFailed { core, payer: Some(payer) }); } - }); + } } } From e0f1c71f6a521eed2897d6a8dcd948f591d28d91 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 17 May 2024 10:13:59 +0200 Subject: [PATCH 18/48] disable auto renew test --- substrate/frame/broker/src/tests.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 00bfb5093b39..4e3bd5d01f14 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1583,6 +1583,34 @@ fn auto_renewal_works() { }); } +#[test] +fn disable_auto_renew_works() { + TestExt::new().endow(1, 1000).limit_cores_offered(Some(10)).execute_with(|| { + assert_ok!(Broker::do_start_sales(100, 3)); + advance_to(2); + let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); + let record = Regions::::get(region_id).unwrap(); + + // Eligible for renewal after final assignment: + assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); + + // Cannot disable auto-renewal if we don't have it enabled. + assert_noop!(Broker::do_disable_auto_renew(1001, 0), Error::::AutoRenewalNotEnabled); + + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + + // Only the sovereign account can disable: + assert_noop!(Broker::do_disable_auto_renew(2001, 0), Error::::NoPermission); + assert_ok!(Broker::do_disable_auto_renew(1001, 0)); + + assert_eq!(AutoRenewals::::get().to_vec(), vec![]); + System::assert_has_event( + Event::::AutoRenewalDisabled { core: region_id.core, task: 1001 }.into(), + ); + }); +} + #[test] fn start_sales_sets_correct_core_count() { TestExt::new().endow(1, 1000).execute_with(|| { From 1a46abcf08652f9ae0e39c8fd8a7560619d77da4 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 17 May 2024 10:24:13 +0200 Subject: [PATCH 19/48] docs --- substrate/frame/broker/src/lib.rs | 8 +++++++- substrate/frame/broker/src/tests.rs | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index dd481eeea22e..973630f4c5bc 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -854,7 +854,7 @@ pub mod pallet { /// Extrinsic for enabling auto renewal. /// - /// Callable by the account associated with the task on the specified core. This account + /// Callable by the sovereign account of the task on the specified core. This account /// will be charged at the start of every bulk period for renewing core time. /// /// - `origin`: Must be the sovereign account of the task @@ -874,6 +874,12 @@ pub mod pallet { Ok(()) } + /// Extrinsic for disabling auto renewal. + /// + /// Callable by the sovereign account of the task on the specified core. + /// + /// - `origin`: Must be the sovereign account of the task. + /// - `core`: The core for which we want to enable auto renewal. #[pallet::call_index(21)] #[pallet::weight(T::WeightInfo::notify_core_count())] pub fn disable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 4e3bd5d01f14..bd48bb796081 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1589,7 +1589,6 @@ fn disable_auto_renew_works() { assert_ok!(Broker::do_start_sales(100, 3)); advance_to(2); let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); - let record = Regions::::get(region_id).unwrap(); // Eligible for renewal after final assignment: assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); From 2f17544ac3bd1b6e300bab3275e92be9c96fd871 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 11:15:16 +0200 Subject: [PATCH 20/48] account for changing core indices --- substrate/frame/broker/src/lib.rs | 5 +++++ substrate/frame/broker/src/tick_impls.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 973630f4c5bc..9eca26c13748 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -458,6 +458,11 @@ pub mod pallet { /// If `None` it indicates that we failed to get the sovereign account of a task. payer: Option, }, + /// The auto-renewal limit has been reduced, and we won't be able to keep auto-renewal for + /// all parachains. + /// + /// Hopefully, this should never happen. + AutoRenewalLimitReached, } #[pallet::error] diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 5546be88bdf8..d30fb685f9b6 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -336,14 +336,26 @@ impl Pallet { /// Renews all the cores which have auto-renewal enabled. pub(crate) fn renew_cores() { let renewals = AutoRenewals::::get(); + let mut successful_renewals: BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals> = + BoundedVec::new(); for (core, task) in renewals.into_iter() { let Some(payer) = T::SovereignAccountOf::sovereign_account(task) else { Self::deposit_event(Event::::AutoRenewalFailed { core, payer: None }); continue; }; - if let Err(_) = Self::do_renew(payer.clone(), core) { + + // The core index can change when renewing for several reasons. Because of this, we will + // update the core indices in the auto-renewal vector with the new appropriate values. + if let Ok(new_core_index) = Self::do_renew(payer.clone(), core) { + if successful_renewals.try_push((new_core_index, task)).is_err() { + // This can only happen if we reduce the auto-renewal limit between sale cycles. + Self::deposit_event(Event::::AutoRenewalLimitReached); + } + } else { Self::deposit_event(Event::::AutoRenewalFailed { core, payer: Some(payer) }); } } + + AutoRenewals::::set(successful_renewals); } } From 63b6f66e84400922f2280e912d7f9cb6d11404cf Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 11:57:36 +0200 Subject: [PATCH 21/48] fix --- substrate/frame/broker/src/lib.rs | 6 +++--- substrate/frame/broker/src/tests.rs | 6 +++++- substrate/frame/broker/src/tick_impls.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 9eca26c13748..0a426826a7a9 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -458,10 +458,10 @@ pub mod pallet { /// If `None` it indicates that we failed to get the sovereign account of a task. payer: Option, }, - /// The auto-renewal limit has been reduced, and we won't be able to keep auto-renewal for - /// all parachains. + /// The auto-renewal limit has been reached upon renewing cores. /// - /// Hopefully, this should never happen. + /// This should never happen, given that enable_auto_renew checks for this before enabling + /// auto-renewal. AutoRenewalLimitReached, } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index bd48bb796081..6b25b331e9cd 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1544,7 +1544,7 @@ fn auto_renewal_works() { // We skip funding the sovereign account of task 1002 on purpose. endow(1003, 1000); - // Next cycle starting at timeslice 7. + // Next cycle starting at 7. advance_to(7); System::assert_has_event( Event::::Renewed { @@ -1580,6 +1580,10 @@ fn auto_renewal_works() { } .into(), ); + + // Given that core #1 didn't get renewed due to the account not being sufficiently funded, + // Task (1003) will now be assigned to that core instead of core #2. + assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1003)]); }); } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index d30fb685f9b6..765d8d2fbdd4 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -348,7 +348,7 @@ impl Pallet { // update the core indices in the auto-renewal vector with the new appropriate values. if let Ok(new_core_index) = Self::do_renew(payer.clone(), core) { if successful_renewals.try_push((new_core_index, task)).is_err() { - // This can only happen if we reduce the auto-renewal limit between sale cycles. + // This should never happen. Self::deposit_event(Event::::AutoRenewalLimitReached); } } else { From aaba50d54123dcb01c5f1d21426518dc486997c6 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 13:06:01 +0200 Subject: [PATCH 22/48] bench enable_auto_renew --- substrate/frame/broker/src/benchmarking.rs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 7533e3dc68c4..50436a12055c 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -939,6 +939,43 @@ mod benches { Ok(()) } + #[benchmark] + fn enable_auto_renew() -> Result<(), BenchmarkError> { + let _core = setup_and_start_sale::()?; + + advance_to::(2); + + let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(2001) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); + + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_assign(region, None, 2001, Final) + .map_err(|_| BenchmarkError::Weightless)?; + // advance to next bulk sale: + advance_to::(6); + + // The most 'intensive' path is when we renew the core upon enabling auto-renewal. + + #[extrinsic_call] + _(RawOrigin::Signed(caller), region.core, None); + + assert_last_event::(Event::AutoRenewalEnabled { core: region.core, task: 2001 }.into()); + // Make sure we indeed renewed: + assert!(AllowedRenewals::::get(AllowedRenewalId { + core: region.core, + when: 10 // region end after renewal + }) + .is_some()); + + Ok(()) + } + // Implements a test for each benchmark. Execute with: // `cargo test -p pallet-broker --features runtime-benchmarks`. impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); From 7d682e67a3d744ed3da407386b25f33125522399 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 14:34:51 +0200 Subject: [PATCH 23/48] bench disable & auto_renew --- substrate/frame/broker/src/benchmarking.rs | 92 +++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 50436a12055c..5ae729fc2e1b 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -31,7 +31,7 @@ use frame_support::{ use frame_system::{Pallet as System, RawOrigin}; use sp_arithmetic::{traits::Zero, Perbill}; use sp_core::Get; -use sp_runtime::{traits::BlockNumberProvider, Saturating}; +use sp_runtime::{traits::BlockNumberProvider, SaturatedConversion, Saturating}; use sp_std::{vec, vec::Vec}; const SEED: u32 = 0; @@ -41,6 +41,10 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { frame_system::Pallet::::assert_last_event(generic_event.into()); } +fn assert_has_event(generic_event: ::RuntimeEvent) { + frame_system::Pallet::::assert_has_event(generic_event.into()); +} + fn new_config_record() -> ConfigRecordOf { ConfigRecord { advance_notice: 2u32.into(), @@ -976,6 +980,92 @@ mod benches { Ok(()) } + #[benchmark] + fn disable_auto_renew() -> Result<(), BenchmarkError> { + let _core = setup_and_start_sale::()?; + + advance_to::(2); + + let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(2001) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); + + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_assign(region, None, 2001, Final) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_enable_auto_renew(2001, region.core, None)?; + + #[extrinsic_call] + _(RawOrigin::Signed(caller), region.core); + + assert_last_event::(Event::AutoRenewalDisabled { core: region.core, task: 2001 }.into()); + + Ok(()) + } + + #[benchmark] + fn auto_renew() -> Result<(), BenchmarkError> { + let _core = setup_and_start_sale::()?; + + advance_to::(2); + + (0..T::MaxAutoRenewals::get()).try_for_each(|indx| -> Result<(), BenchmarkError> { + let task = 1000 + indx; + let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(task) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); + + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_assign(region, None, task, Final) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_enable_auto_renew(task, region.core, None)?; + + Ok(()) + })?; + + advance_to::(7); + #[block] + { + Broker::::do_tick(); + } + + // Make sure all cores got renewed: + (0..T::MaxAutoRenewals::get()).for_each(|indx| { + let task = 1000 + indx; + let who = T::SovereignAccountOf::sovereign_account(task) + .expect("Failed to get sovereign account"); + assert_has_event::( + Event::Renewed { + who, + old_core: 10 + indx as u16, // first ten cores are allocated to leases. + core: 10 + indx as u16, + price: 10u32.saturated_into(), + begin: 7, + duration: 3, + workload: Schedule::truncate_from(vec![ScheduleItem { + assignment: Task(task), + mask: CoreMask::complete(), + }]), + } + .into(), + ); + }); + + Ok(()) + } + // Implements a test for each benchmark. Execute with: // `cargo test -p pallet-broker --features runtime-benchmarks`. impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); From af8f109b0aa44797246b484ef311517d9614b92a Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 17:18:12 +0200 Subject: [PATCH 24/48] weights --- substrate/bin/node/runtime/src/lib.rs | 19 +- substrate/frame/broker/src/weights.rs | 495 ++++++++++++++++---------- 2 files changed, 319 insertions(+), 195 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index ca86d34ef2e4..ec59bc13def5 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2134,12 +2134,23 @@ impl TaskAccountInterface for TaskSovereignAccount { type OuterOrigin = RuntimeOrigin; type TaskOrigin = frame_system::RawOrigin; - fn ensure_task_sovereign_account(_o: RuntimeOrigin) -> Result { - Err(BadOrigin) + fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { + match o.into() { + Ok(frame_system::RawOrigin::Signed(account)) => { + let account_arr: [u8; 32] = account.try_into().map_err(|_| BadOrigin)?; + let encoded: [u8; 4] = account_arr[0..4].try_into().map_err(|_| BadOrigin)?; + + let task = u32::from_le_bytes(encoded); + Ok(task) + } + _ => Err(BadOrigin), + } } - fn sovereign_account(_task: TaskId) -> Option { - None + fn sovereign_account(task: TaskId) -> Option { + let mut account: [u8; 32] = [0; 32]; + account[..4].copy_from_slice(&task.to_le_bytes()); + Some(account.into()) } } impl pallet_broker::Config for Runtime { diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index 2aa1c282a41d..76a19f610e2e 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -18,13 +18,13 @@ //! Autogenerated weights for `pallet_broker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-04-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-anb7yjbi-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `sergej-B650-AORUS-ELITE-AX`, CPU: `AMD Ryzen 9 7900X3D 12-Core Processor` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/production/substrate-node +// ./target/release/substrate-node // benchmark // pallet // --chain=dev @@ -79,6 +79,9 @@ pub trait WeightInfo { fn notify_core_count() -> Weight; fn do_tick_base() -> Weight; fn swap_leases() -> Weight; + fn enable_auto_renew() -> Weight; + fn disable_auto_renew() -> Weight; + fn auto_renew() -> Weight; } /// Weights for `pallet_broker` using the Substrate node and recommended hardware. @@ -90,8 +93,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_624_000 picoseconds. - Weight::from_parts(2_804_000, 0) + // Minimum execution time: 1_703_000 picoseconds. + Weight::from_parts(1_803_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -100,8 +103,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 18_451_000 picoseconds. - Weight::from_parts(18_853_000, 7496) + // Minimum execution time: 12_904_000 picoseconds. + Weight::from_parts(13_445_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -111,8 +114,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 16_899_000 picoseconds. - Weight::from_parts(17_645_000, 7496) + // Minimum execution time: 11_852_000 picoseconds. + Weight::from_parts(12_283_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -122,19 +125,21 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 10_239_000 picoseconds. - Weight::from_parts(10_754_000, 1526) + // Minimum execution time: 7_074_000 picoseconds. + Weight::from_parts(7_314_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) - /// 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(6011), added: 6506, mode: `MaxEncodedLen`) /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) + /// Storage: `Broker::Reservations` (r:1 w:0) + /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(6011), added: 6506, mode: `MaxEncodedLen`) + /// Storage: `Broker::InstaPoolIo` (r:3 w:3) + /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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) @@ -146,11 +151,11 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 51_250_000 picoseconds. - Weight::from_parts(54_643_012, 8499) - // Standard Error: 147 - .saturating_add(Weight::from_parts(18, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(6_u64)) + // Minimum execution time: 21_421_000 picoseconds. + Weight::from_parts(41_055_954, 8499) + // Standard Error: 436 + .saturating_add(Weight::from_parts(2_287, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(16_u64)) } /// Storage: `Broker::Status` (r:1 w:0) @@ -162,13 +167,13 @@ impl WeightInfo for SubstrateWeight { /// Storage: `System::Digest` (r:1 w:0) /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// 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: `635` // Estimated: `2120` - // Minimum execution time: 43_660_000 picoseconds. - Weight::from_parts(45_543_000, 2120) + // Minimum execution time: 31_109_000 picoseconds. + Weight::from_parts(31_680_000, 2120) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -190,41 +195,41 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `753` // Estimated: `4698` - // Minimum execution time: 63_122_000 picoseconds. - Weight::from_parts(64_366_000, 4698) + // Minimum execution time: 42_220_000 picoseconds. + Weight::from_parts(43_272_000, 4698) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 17_552_000 picoseconds. - Weight::from_parts(18_251_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 11_252_000 picoseconds. + Weight::from_parts(11_712_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 18_551_000 picoseconds. - Weight::from_parts(19_727_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 12_985_000 picoseconds. + Weight::from_parts(13_746_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 20_636_000 picoseconds. - Weight::from_parts(21_060_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 13_736_000 picoseconds. + Weight::from_parts(14_618_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -233,22 +238,22 @@ impl WeightInfo for SubstrateWeight { /// 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: `740` + // Measured: `741` // Estimated: `4681` - // Minimum execution time: 32_394_000 picoseconds. - Weight::from_parts(33_324_000, 4681) + // Minimum execution time: 22_743_000 picoseconds. + Weight::from_parts(23_615_000, 4681) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// 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) @@ -257,10 +262,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Broker::InstaPoolContribution` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) fn pool() -> Weight { // Proof Size summary in bytes: - // Measured: `775` + // Measured: `776` // Estimated: `5996` - // Minimum execution time: 38_128_000 picoseconds. - Weight::from_parts(39_274_000, 5996) + // Minimum execution time: 26_951_000 picoseconds. + Weight::from_parts(27_563_000, 5996) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -273,12 +278,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `m` is `[1, 3]`. fn claim_revenue(m: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `859` + // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 70_453_000 picoseconds. - Weight::from_parts(70_652_822, 6196) - // Standard Error: 75_524 - .saturating_add(Weight::from_parts(2_335_289, 0).saturating_mul(m.into())) + // Minimum execution time: 51_848_000 picoseconds. + Weight::from_parts(52_867_177, 6196) + // Standard Error: 31_014 + .saturating_add(Weight::from_parts(915_210, 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)) @@ -290,21 +295,21 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 43_945_000 picoseconds. - Weight::from_parts(45_249_000, 3593) + // Minimum execution time: 33_373_000 picoseconds. + Weight::from_parts(33_774_000, 3593) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// 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: `603` - // Estimated: `3550` - // Minimum execution time: 30_680_000 picoseconds. - Weight::from_parts(32_995_000, 3550) + // Measured: `604` + // Estimated: `3551` + // Minimum execution time: 18_746_000 picoseconds. + Weight::from_parts(19_417_000, 3551) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -318,8 +323,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 48_053_000 picoseconds. - Weight::from_parts(51_364_000, 3533) + // Minimum execution time: 23_694_000 picoseconds. + Weight::from_parts(24_807_000, 3533) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -333,10 +338,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn drop_history() -> Weight { // Proof Size summary in bytes: - // Measured: `995` + // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 57_372_000 picoseconds. - Weight::from_parts(59_466_000, 3593) + // Minimum execution time: 29_366_000 picoseconds. + Weight::from_parts(30_007_000, 3593) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -348,8 +353,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 27_768_000 picoseconds. - Weight::from_parts(29_000_000, 4698) + // Minimum execution time: 16_641_000 picoseconds. + Weight::from_parts(17_193_000, 4698) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -358,20 +363,18 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_588_000 picoseconds. - Weight::from_parts(5_201_705, 0) + // Minimum execution time: 2_936_000 picoseconds. + Weight::from_parts(3_279_925, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn process_core_count(n: u32, ) -> Weight { + fn process_core_count(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_889_000 picoseconds. - Weight::from_parts(7_380_363, 1487) - // Standard Error: 21 - .saturating_add(Weight::from_parts(63, 0).saturating_mul(n.into())) + // Minimum execution time: 4_809_000 picoseconds. + Weight::from_parts(5_131_202, 1487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -387,10 +390,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: 50_156_000 picoseconds. - Weight::from_parts(51_610_000, 4437) + // Measured: `991` + // Estimated: `4456` + // Minimum execution time: 37_411_000 picoseconds. + Weight::from_parts(38_422_000, 4456) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -400,21 +403,21 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(6011), added: 6506, mode: `MaxEncodedLen`) /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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::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: 38_246_000 picoseconds. - Weight::from_parts(40_008_850, 8499) - // Standard Error: 94 - .saturating_add(Weight::from_parts(964, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(15_u64)) + // Minimum execution time: 31_079_000 picoseconds. + Weight::from_parts(32_597_774, 8499) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(16_u64)) } /// Storage: `Broker::InstaPoolIo` (r:1 w:0) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -424,8 +427,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 7_962_000 picoseconds. - Weight::from_parts(8_313_000, 3493) + // Minimum execution time: 5_581_000 picoseconds. + Weight::from_parts(5_731_000, 3493) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -437,8 +440,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 17_457_000 picoseconds. - Weight::from_parts(18_387_000, 4681) + // Minimum execution time: 10_701_000 picoseconds. + Weight::from_parts(10_941_000, 4681) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -446,8 +449,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 133_000 picoseconds. - Weight::from_parts(149_000, 0) + // Minimum execution time: 110_000 picoseconds. + Weight::from_parts(140_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -455,8 +458,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_407_000 picoseconds. - Weight::from_parts(2_634_000, 0) + // Minimum execution time: 1_553_000 picoseconds. + Weight::from_parts(1_643_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -471,8 +474,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 13_043_000 picoseconds. - Weight::from_parts(13_541_000, 4068) + // Minimum execution time: 9_348_000 picoseconds. + Weight::from_parts(9_618_000, 4068) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -482,11 +485,66 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 6_606_000 picoseconds. - Weight::from_parts(6_964_000, 1526) + // Minimum execution time: 4_839_000 picoseconds. + Weight::from_parts(5_149_000, 1526) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Broker::SaleInfo` (r:1 w:1) + /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) + /// Storage: `Broker::AllowedRenewals` (r:1 w:2) + /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) + /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Authorship::Author` (r:1 w:0) + /// Proof: `Authorship::Author` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Workplan` (r:0 w:1) + /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) + fn enable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `914` + // Estimated: `4698` + // Minimum execution time: 50_055_000 picoseconds. + Weight::from_parts(50_526_000, 4698) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + fn disable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `1516` + // Minimum execution time: 8_926_000 picoseconds. + Weight::from_parts(9_248_000, 1516) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// 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) + fn auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `1186` + // Estimated: `4651` + // Minimum execution time: 12_654_000 picoseconds. + Weight::from_parts(12_984_000, 4651) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } } // For backwards compatibility and tests. @@ -497,8 +555,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_624_000 picoseconds. - Weight::from_parts(2_804_000, 0) + // Minimum execution time: 1_703_000 picoseconds. + Weight::from_parts(1_803_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -507,8 +565,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 18_451_000 picoseconds. - Weight::from_parts(18_853_000, 7496) + // Minimum execution time: 12_904_000 picoseconds. + Weight::from_parts(13_445_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -518,8 +576,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 16_899_000 picoseconds. - Weight::from_parts(17_645_000, 7496) + // Minimum execution time: 11_852_000 picoseconds. + Weight::from_parts(12_283_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -529,19 +587,21 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 10_239_000 picoseconds. - Weight::from_parts(10_754_000, 1526) + // Minimum execution time: 7_074_000 picoseconds. + Weight::from_parts(7_314_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Configuration` (r:1 w:0) /// Proof: `Broker::Configuration` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) - /// 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(6011), added: 6506, mode: `MaxEncodedLen`) /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) + /// Storage: `Broker::Reservations` (r:1 w:0) + /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(6011), added: 6506, mode: `MaxEncodedLen`) + /// Storage: `Broker::InstaPoolIo` (r:3 w:3) + /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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) @@ -553,11 +613,11 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 51_250_000 picoseconds. - Weight::from_parts(54_643_012, 8499) - // Standard Error: 147 - .saturating_add(Weight::from_parts(18, 0).saturating_mul(n.into())) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + // Minimum execution time: 21_421_000 picoseconds. + Weight::from_parts(41_055_954, 8499) + // Standard Error: 436 + .saturating_add(Weight::from_parts(2_287, 0).saturating_mul(n.into())) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(16_u64)) } /// Storage: `Broker::Status` (r:1 w:0) @@ -569,13 +629,13 @@ impl WeightInfo for () { /// Storage: `System::Digest` (r:1 w:0) /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// 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: `635` // Estimated: `2120` - // Minimum execution time: 43_660_000 picoseconds. - Weight::from_parts(45_543_000, 2120) + // Minimum execution time: 31_109_000 picoseconds. + Weight::from_parts(31_680_000, 2120) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -597,41 +657,41 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `753` // Estimated: `4698` - // Minimum execution time: 63_122_000 picoseconds. - Weight::from_parts(64_366_000, 4698) + // Minimum execution time: 42_220_000 picoseconds. + Weight::from_parts(43_272_000, 4698) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 17_552_000 picoseconds. - Weight::from_parts(18_251_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 11_252_000 picoseconds. + Weight::from_parts(11_712_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 18_551_000 picoseconds. - Weight::from_parts(19_727_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 12_985_000 picoseconds. + Weight::from_parts(13_746_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// 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: `495` - // Estimated: `3550` - // Minimum execution time: 20_636_000 picoseconds. - Weight::from_parts(21_060_000, 3550) + // Measured: `496` + // Estimated: `3551` + // Minimum execution time: 13_736_000 picoseconds. + Weight::from_parts(14_618_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -640,22 +700,22 @@ impl WeightInfo for () { /// 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: `740` + // Measured: `741` // Estimated: `4681` - // Minimum execution time: 32_394_000 picoseconds. - Weight::from_parts(33_324_000, 4681) + // Minimum execution time: 22_743_000 picoseconds. + Weight::from_parts(23_615_000, 4681) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// 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) @@ -664,10 +724,10 @@ impl WeightInfo for () { /// Proof: `Broker::InstaPoolContribution` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) fn pool() -> Weight { // Proof Size summary in bytes: - // Measured: `775` + // Measured: `776` // Estimated: `5996` - // Minimum execution time: 38_128_000 picoseconds. - Weight::from_parts(39_274_000, 5996) + // Minimum execution time: 26_951_000 picoseconds. + Weight::from_parts(27_563_000, 5996) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -680,12 +740,12 @@ impl WeightInfo for () { /// The range of component `m` is `[1, 3]`. fn claim_revenue(m: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `859` + // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 70_453_000 picoseconds. - Weight::from_parts(70_652_822, 6196) - // Standard Error: 75_524 - .saturating_add(Weight::from_parts(2_335_289, 0).saturating_mul(m.into())) + // Minimum execution time: 51_848_000 picoseconds. + Weight::from_parts(52_867_177, 6196) + // Standard Error: 31_014 + .saturating_add(Weight::from_parts(915_210, 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,21 +757,21 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 43_945_000 picoseconds. - Weight::from_parts(45_249_000, 3593) + // Minimum execution time: 33_373_000 picoseconds. + Weight::from_parts(33_774_000, 3593) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// 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: `603` - // Estimated: `3550` - // Minimum execution time: 30_680_000 picoseconds. - Weight::from_parts(32_995_000, 3550) + // Measured: `604` + // Estimated: `3551` + // Minimum execution time: 18_746_000 picoseconds. + Weight::from_parts(19_417_000, 3551) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -725,8 +785,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 48_053_000 picoseconds. - Weight::from_parts(51_364_000, 3533) + // Minimum execution time: 23_694_000 picoseconds. + Weight::from_parts(24_807_000, 3533) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -740,10 +800,10 @@ impl WeightInfo for () { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn drop_history() -> Weight { // Proof Size summary in bytes: - // Measured: `995` + // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 57_372_000 picoseconds. - Weight::from_parts(59_466_000, 3593) + // Minimum execution time: 29_366_000 picoseconds. + Weight::from_parts(30_007_000, 3593) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -755,8 +815,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 27_768_000 picoseconds. - Weight::from_parts(29_000_000, 4698) + // Minimum execution time: 16_641_000 picoseconds. + Weight::from_parts(17_193_000, 4698) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -765,20 +825,18 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_588_000 picoseconds. - Weight::from_parts(5_201_705, 0) + // Minimum execution time: 2_936_000 picoseconds. + Weight::from_parts(3_279_925, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn process_core_count(n: u32, ) -> Weight { + fn process_core_count(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 6_889_000 picoseconds. - Weight::from_parts(7_380_363, 1487) - // Standard Error: 21 - .saturating_add(Weight::from_parts(63, 0).saturating_mul(n.into())) + // Minimum execution time: 4_809_000 picoseconds. + Weight::from_parts(5_131_202, 1487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -794,10 +852,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: 50_156_000 picoseconds. - Weight::from_parts(51_610_000, 4437) + // Measured: `991` + // Estimated: `4456` + // Minimum execution time: 37_411_000 picoseconds. + Weight::from_parts(38_422_000, 4456) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -807,21 +865,21 @@ impl WeightInfo for () { /// Proof: `Broker::Reservations` (`max_values`: Some(1), `max_size`: Some(6011), added: 6506, mode: `MaxEncodedLen`) /// Storage: `Broker::Leases` (r:1 w:1) /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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::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: 38_246_000 picoseconds. - Weight::from_parts(40_008_850, 8499) - // Standard Error: 94 - .saturating_add(Weight::from_parts(964, 0).saturating_mul(n.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(15_u64)) + // Minimum execution time: 31_079_000 picoseconds. + Weight::from_parts(32_597_774, 8499) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(16_u64)) } /// Storage: `Broker::InstaPoolIo` (r:1 w:0) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -831,8 +889,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 7_962_000 picoseconds. - Weight::from_parts(8_313_000, 3493) + // Minimum execution time: 5_581_000 picoseconds. + Weight::from_parts(5_731_000, 3493) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -844,8 +902,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 17_457_000 picoseconds. - Weight::from_parts(18_387_000, 4681) + // Minimum execution time: 10_701_000 picoseconds. + Weight::from_parts(10_941_000, 4681) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -853,8 +911,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 133_000 picoseconds. - Weight::from_parts(149_000, 0) + // Minimum execution time: 110_000 picoseconds. + Weight::from_parts(140_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -862,8 +920,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_407_000 picoseconds. - Weight::from_parts(2_634_000, 0) + // Minimum execution time: 1_553_000 picoseconds. + Weight::from_parts(1_643_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -878,8 +936,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 13_043_000 picoseconds. - Weight::from_parts(13_541_000, 4068) + // Minimum execution time: 9_348_000 picoseconds. + Weight::from_parts(9_618_000, 4068) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -889,9 +947,64 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 6_606_000 picoseconds. - Weight::from_parts(6_964_000, 1526) + // Minimum execution time: 4_839_000 picoseconds. + Weight::from_parts(5_149_000, 1526) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Broker::SaleInfo` (r:1 w:1) + /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) + /// Storage: `Broker::AllowedRenewals` (r:1 w:2) + /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) + /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Authorship::Author` (r:1 w:0) + /// Proof: `Authorship::Author` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Workplan` (r:0 w:1) + /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) + fn enable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `914` + // Estimated: `4698` + // Minimum execution time: 50_055_000 picoseconds. + Weight::from_parts(50_526_000, 4698) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + fn disable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `1516` + // Minimum execution time: 8_926_000 picoseconds. + Weight::from_parts(9_248_000, 1516) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// 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) + fn auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `1186` + // Estimated: `4651` + // Minimum execution time: 12_654_000 picoseconds. + Weight::from_parts(12_984_000, 4651) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } } From f22c45198245af09d58de71233be749d0c744433 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 17:25:58 +0200 Subject: [PATCH 25/48] fix --- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/broker/src/benchmarking.rs | 104 +++---- substrate/frame/broker/src/weights.rs | 331 +++++++++------------ 3 files changed, 183 insertions(+), 254 deletions(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index ec59bc13def5..2ac7c6a69fd0 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2142,7 +2142,7 @@ impl TaskAccountInterface for TaskSovereignAccount { let task = u32::from_le_bytes(encoded); Ok(task) - } + }, _ => Err(BadOrigin), } } diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 5ae729fc2e1b..388caf4dc283 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -775,7 +775,7 @@ mod benches { } #[benchmark] - fn rotate_sale(n: Linear<0, { MAX_CORE_COUNT.into() }>) { + fn rotate_sale(n: Linear<0, { MAX_CORE_COUNT.into() }>) -> Result<(), BenchmarkError> { let core_count = n.try_into().unwrap(); let config = new_config_record::(); @@ -809,6 +809,27 @@ mod benches { // Assume Leases to be filled for worst case setup_leases::(T::MaxLeasedCores::get(), 1, 10); + // Assume max auto renewals for worst case. + (0..T::MaxAutoRenewals::get()).try_for_each(|indx| -> Result<(), BenchmarkError> { + let task = 1000 + indx; + let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(task) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); + + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_assign(region, None, task, Final) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_enable_auto_renew(task, region.core, None)?; + + Ok(()) + })?; + #[block] { Broker::::rotate_sale(sale.clone(), &config, &status); @@ -832,6 +853,30 @@ mod benches { } .into(), ); + + // Make sure all cores got renewed: + (0..T::MaxAutoRenewals::get()).for_each(|indx| { + let task = 1000 + indx; + let who = T::SovereignAccountOf::sovereign_account(task) + .expect("Failed to get sovereign account"); + assert_has_event::( + Event::Renewed { + who, + old_core: 10 + indx as u16, // first ten cores are allocated to leases. + core: 10 + indx as u16, + price: 10u32.saturated_into(), + begin: 7, + duration: 3, + workload: Schedule::truncate_from(vec![ScheduleItem { + assignment: Task(task), + mask: CoreMask::complete(), + }]), + } + .into(), + ); + }); + + Ok(()) } #[benchmark] @@ -1009,63 +1054,6 @@ mod benches { Ok(()) } - #[benchmark] - fn auto_renew() -> Result<(), BenchmarkError> { - let _core = setup_and_start_sale::()?; - - advance_to::(2); - - (0..T::MaxAutoRenewals::get()).try_for_each(|indx| -> Result<(), BenchmarkError> { - let task = 1000 + indx; - let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(task) - .expect("Failed to get sovereign account"); - T::Currency::set_balance( - &caller.clone(), - T::Currency::minimum_balance().saturating_add(100u32.into()), - ); - - let region = Broker::::do_purchase(caller.clone(), 10u32.into()) - .map_err(|_| BenchmarkError::Weightless)?; - - Broker::::do_assign(region, None, task, Final) - .map_err(|_| BenchmarkError::Weightless)?; - - Broker::::do_enable_auto_renew(task, region.core, None)?; - - Ok(()) - })?; - - advance_to::(7); - #[block] - { - Broker::::do_tick(); - } - - // Make sure all cores got renewed: - (0..T::MaxAutoRenewals::get()).for_each(|indx| { - let task = 1000 + indx; - let who = T::SovereignAccountOf::sovereign_account(task) - .expect("Failed to get sovereign account"); - assert_has_event::( - Event::Renewed { - who, - old_core: 10 + indx as u16, // first ten cores are allocated to leases. - core: 10 + indx as u16, - price: 10u32.saturated_into(), - begin: 7, - duration: 3, - workload: Schedule::truncate_from(vec![ScheduleItem { - assignment: Task(task), - mask: CoreMask::complete(), - }]), - } - .into(), - ); - }); - - Ok(()) - } - // Implements a test for each benchmark. Execute with: // `cargo test -p pallet-broker --features runtime-benchmarks`. impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index 76a19f610e2e..ee27c62a5b0c 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -81,7 +81,6 @@ pub trait WeightInfo { fn swap_leases() -> Weight; fn enable_auto_renew() -> Weight; fn disable_auto_renew() -> Weight; - fn auto_renew() -> Weight; } /// Weights for `pallet_broker` using the Substrate node and recommended hardware. @@ -93,8 +92,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_703_000 picoseconds. - Weight::from_parts(1_803_000, 0) + // Minimum execution time: 1_824_000 picoseconds. + Weight::from_parts(1_894_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -103,8 +102,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 12_904_000 picoseconds. - Weight::from_parts(13_445_000, 7496) + // Minimum execution time: 12_714_000 picoseconds. + Weight::from_parts(13_085_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -114,8 +113,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 11_852_000 picoseconds. - Weight::from_parts(12_283_000, 7496) + // Minimum execution time: 11_783_000 picoseconds. + Weight::from_parts(12_294_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -125,8 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 7_074_000 picoseconds. - Weight::from_parts(7_314_000, 1526) + // Minimum execution time: 7_104_000 picoseconds. + Weight::from_parts(7_354_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -151,10 +150,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 21_421_000 picoseconds. - Weight::from_parts(41_055_954, 8499) - // Standard Error: 436 - .saturating_add(Weight::from_parts(2_287, 0).saturating_mul(n.into())) + // Minimum execution time: 21_611_000 picoseconds. + Weight::from_parts(40_010_482, 8499) + // Standard Error: 404 + .saturating_add(Weight::from_parts(2_591, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(16_u64)) } @@ -172,8 +171,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `635` // Estimated: `2120` - // Minimum execution time: 31_109_000 picoseconds. - Weight::from_parts(31_680_000, 2120) + // Minimum execution time: 30_939_000 picoseconds. + Weight::from_parts(31_540_000, 2120) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -195,8 +194,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `753` // Estimated: `4698` - // Minimum execution time: 42_220_000 picoseconds. - Weight::from_parts(43_272_000, 4698) + // Minimum execution time: 43_492_000 picoseconds. + Weight::from_parts(44_284_000, 4698) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -206,8 +205,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 11_252_000 picoseconds. - Weight::from_parts(11_712_000, 3551) + // Minimum execution time: 11_341_000 picoseconds. + Weight::from_parts(12_013_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -217,8 +216,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 12_985_000 picoseconds. - Weight::from_parts(13_746_000, 3551) + // Minimum execution time: 12_594_000 picoseconds. + Weight::from_parts(13_295_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -228,8 +227,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 13_736_000 picoseconds. - Weight::from_parts(14_618_000, 3551) + // Minimum execution time: 13_556_000 picoseconds. + Weight::from_parts(13_916_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -245,8 +244,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 22_743_000 picoseconds. - Weight::from_parts(23_615_000, 4681) + // Minimum execution time: 22_142_000 picoseconds. + Weight::from_parts(23_204_000, 4681) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -264,8 +263,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 26_951_000 picoseconds. - Weight::from_parts(27_563_000, 5996) + // Minimum execution time: 26_320_000 picoseconds. + Weight::from_parts(27_813_000, 5996) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -280,10 +279,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 51_848_000 picoseconds. - Weight::from_parts(52_867_177, 6196) - // Standard Error: 31_014 - .saturating_add(Weight::from_parts(915_210, 0).saturating_mul(m.into())) + // Minimum execution time: 50_726_000 picoseconds. + Weight::from_parts(53_226_499, 6196) + // Standard Error: 74_118 + .saturating_add(Weight::from_parts(672_768, 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)) @@ -295,8 +294,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 33_373_000 picoseconds. - Weight::from_parts(33_774_000, 3593) + // Minimum execution time: 33_404_000 picoseconds. + Weight::from_parts(34_125_000, 3593) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -308,8 +307,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 18_746_000 picoseconds. - Weight::from_parts(19_417_000, 3551) + // Minimum execution time: 17_994_000 picoseconds. + Weight::from_parts(18_635_000, 3551) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -323,8 +322,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 23_694_000 picoseconds. - Weight::from_parts(24_807_000, 3533) + // Minimum execution time: 22_312_000 picoseconds. + Weight::from_parts(25_118_000, 3533) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -340,8 +339,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 29_366_000 picoseconds. - Weight::from_parts(30_007_000, 3593) + // Minimum execution time: 29_637_000 picoseconds. + Weight::from_parts(30_528_000, 3593) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -353,18 +352,20 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 16_641_000 picoseconds. - Weight::from_parts(17_193_000, 4698) + // Minimum execution time: 18_184_000 picoseconds. + Weight::from_parts(21_201_000, 4698) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// 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: `0` // Estimated: `0` - // Minimum execution time: 2_936_000 picoseconds. - Weight::from_parts(3_279_925, 0) + // Minimum execution time: 3_036_000 picoseconds. + Weight::from_parts(3_417_250, 0) + // Standard Error: 91 + .saturating_add(Weight::from_parts(106, 0).saturating_mul(n.into())) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -373,8 +374,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 4_809_000 picoseconds. - Weight::from_parts(5_131_202, 1487) + // Minimum execution time: 4_879_000 picoseconds. + Weight::from_parts(5_413_035, 1487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -392,32 +393,18 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `991` // Estimated: `4456` - // Minimum execution time: 37_411_000 picoseconds. - Weight::from_parts(38_422_000, 4456) + // Minimum execution time: 37_982_000 picoseconds. + Weight::from_parts(38_703_000, 4456) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - /// 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(6011), added: 6506, mode: `MaxEncodedLen`) - /// Storage: `Broker::Leases` (r:1 w:1) - /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) - /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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::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 { // Proof Size summary in bytes: - // Measured: `6281` - // Estimated: `8499` - // Minimum execution time: 31_079_000 picoseconds. - Weight::from_parts(32_597_774, 8499) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(16_u64)) + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 0_000 picoseconds. + Weight::from_parts(0, 0) } /// Storage: `Broker::InstaPoolIo` (r:1 w:0) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -427,8 +414,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 5_581_000 picoseconds. - Weight::from_parts(5_731_000, 3493) + // Minimum execution time: 5_520_000 picoseconds. + Weight::from_parts(5_720_000, 3493) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -440,8 +427,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 10_701_000 picoseconds. - Weight::from_parts(10_941_000, 4681) + // Minimum execution time: 10_850_000 picoseconds. + Weight::from_parts(11_091_000, 4681) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -449,8 +436,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 110_000 picoseconds. - Weight::from_parts(140_000, 0) + // Minimum execution time: 111_000 picoseconds. + Weight::from_parts(131_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -459,7 +446,7 @@ impl WeightInfo for SubstrateWeight { // Measured: `0` // Estimated: `0` // Minimum execution time: 1_553_000 picoseconds. - Weight::from_parts(1_643_000, 0) + Weight::from_parts(1_683_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -474,8 +461,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 9_348_000 picoseconds. - Weight::from_parts(9_618_000, 4068) + // Minimum execution time: 9_619_000 picoseconds. + Weight::from_parts(9_929_000, 4068) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -485,8 +472,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 4_839_000 picoseconds. - Weight::from_parts(5_149_000, 1526) + // Minimum execution time: 5_029_000 picoseconds. + Weight::from_parts(5_220_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -512,8 +499,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `914` // Estimated: `4698` - // Minimum execution time: 50_055_000 picoseconds. - Weight::from_parts(50_526_000, 4698) + // Minimum execution time: 51_938_000 picoseconds. + Weight::from_parts(55_025_000, 4698) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } @@ -523,28 +510,11 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `480` // Estimated: `1516` - // Minimum execution time: 8_926_000 picoseconds. - Weight::from_parts(9_248_000, 1516) + // Minimum execution time: 9_628_000 picoseconds. + Weight::from_parts(10_400_000, 1516) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// 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) - fn auto_renew() -> Weight { - // Proof Size summary in bytes: - // Measured: `1186` - // Estimated: `4651` - // Minimum execution time: 12_654_000 picoseconds. - Weight::from_parts(12_984_000, 4651) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } } // For backwards compatibility and tests. @@ -555,8 +525,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_703_000 picoseconds. - Weight::from_parts(1_803_000, 0) + // Minimum execution time: 1_824_000 picoseconds. + Weight::from_parts(1_894_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -565,8 +535,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 12_904_000 picoseconds. - Weight::from_parts(13_445_000, 7496) + // Minimum execution time: 12_714_000 picoseconds. + Weight::from_parts(13_085_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -576,8 +546,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 11_852_000 picoseconds. - Weight::from_parts(12_283_000, 7496) + // Minimum execution time: 11_783_000 picoseconds. + Weight::from_parts(12_294_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -587,8 +557,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 7_074_000 picoseconds. - Weight::from_parts(7_314_000, 1526) + // Minimum execution time: 7_104_000 picoseconds. + Weight::from_parts(7_354_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -613,10 +583,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 21_421_000 picoseconds. - Weight::from_parts(41_055_954, 8499) - // Standard Error: 436 - .saturating_add(Weight::from_parts(2_287, 0).saturating_mul(n.into())) + // Minimum execution time: 21_611_000 picoseconds. + Weight::from_parts(40_010_482, 8499) + // Standard Error: 404 + .saturating_add(Weight::from_parts(2_591, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(16_u64)) } @@ -634,8 +604,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `635` // Estimated: `2120` - // Minimum execution time: 31_109_000 picoseconds. - Weight::from_parts(31_680_000, 2120) + // Minimum execution time: 30_939_000 picoseconds. + Weight::from_parts(31_540_000, 2120) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -657,8 +627,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `753` // Estimated: `4698` - // Minimum execution time: 42_220_000 picoseconds. - Weight::from_parts(43_272_000, 4698) + // Minimum execution time: 43_492_000 picoseconds. + Weight::from_parts(44_284_000, 4698) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -668,8 +638,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 11_252_000 picoseconds. - Weight::from_parts(11_712_000, 3551) + // Minimum execution time: 11_341_000 picoseconds. + Weight::from_parts(12_013_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -679,8 +649,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 12_985_000 picoseconds. - Weight::from_parts(13_746_000, 3551) + // Minimum execution time: 12_594_000 picoseconds. + Weight::from_parts(13_295_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -690,8 +660,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 13_736_000 picoseconds. - Weight::from_parts(14_618_000, 3551) + // Minimum execution time: 13_556_000 picoseconds. + Weight::from_parts(13_916_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -707,8 +677,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 22_743_000 picoseconds. - Weight::from_parts(23_615_000, 4681) + // Minimum execution time: 22_142_000 picoseconds. + Weight::from_parts(23_204_000, 4681) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -726,8 +696,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 26_951_000 picoseconds. - Weight::from_parts(27_563_000, 5996) + // Minimum execution time: 26_320_000 picoseconds. + Weight::from_parts(27_813_000, 5996) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -742,10 +712,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 51_848_000 picoseconds. - Weight::from_parts(52_867_177, 6196) - // Standard Error: 31_014 - .saturating_add(Weight::from_parts(915_210, 0).saturating_mul(m.into())) + // Minimum execution time: 50_726_000 picoseconds. + Weight::from_parts(53_226_499, 6196) + // Standard Error: 74_118 + .saturating_add(Weight::from_parts(672_768, 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)) @@ -757,8 +727,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 33_373_000 picoseconds. - Weight::from_parts(33_774_000, 3593) + // Minimum execution time: 33_404_000 picoseconds. + Weight::from_parts(34_125_000, 3593) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -770,8 +740,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 18_746_000 picoseconds. - Weight::from_parts(19_417_000, 3551) + // Minimum execution time: 17_994_000 picoseconds. + Weight::from_parts(18_635_000, 3551) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -785,8 +755,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 23_694_000 picoseconds. - Weight::from_parts(24_807_000, 3533) + // Minimum execution time: 22_312_000 picoseconds. + Weight::from_parts(25_118_000, 3533) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -802,8 +772,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 29_366_000 picoseconds. - Weight::from_parts(30_007_000, 3593) + // Minimum execution time: 29_637_000 picoseconds. + Weight::from_parts(30_528_000, 3593) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -815,18 +785,20 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 16_641_000 picoseconds. - Weight::from_parts(17_193_000, 4698) + // Minimum execution time: 18_184_000 picoseconds. + Weight::from_parts(21_201_000, 4698) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// 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: `0` // Estimated: `0` - // Minimum execution time: 2_936_000 picoseconds. - Weight::from_parts(3_279_925, 0) + // Minimum execution time: 3_036_000 picoseconds. + Weight::from_parts(3_417_250, 0) + // Standard Error: 91 + .saturating_add(Weight::from_parts(106, 0).saturating_mul(n.into())) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -835,8 +807,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 4_809_000 picoseconds. - Weight::from_parts(5_131_202, 1487) + // Minimum execution time: 4_879_000 picoseconds. + Weight::from_parts(5_413_035, 1487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -854,32 +826,18 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `991` // Estimated: `4456` - // Minimum execution time: 37_411_000 picoseconds. - Weight::from_parts(38_422_000, 4456) + // Minimum execution time: 37_982_000 picoseconds. + Weight::from_parts(38_703_000, 4456) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - /// 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(6011), added: 6506, mode: `MaxEncodedLen`) - /// Storage: `Broker::Leases` (r:1 w:1) - /// Proof: `Broker::Leases` (`max_values`: Some(1), `max_size`: Some(41), added: 536, mode: `MaxEncodedLen`) - /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, 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::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 { // Proof Size summary in bytes: - // Measured: `6281` - // Estimated: `8499` - // Minimum execution time: 31_079_000 picoseconds. - Weight::from_parts(32_597_774, 8499) - .saturating_add(RocksDbWeight::get().reads(6_u64)) - .saturating_add(RocksDbWeight::get().writes(16_u64)) + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 0_000 picoseconds. + Weight::from_parts(0, 0) } /// Storage: `Broker::InstaPoolIo` (r:1 w:0) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -889,8 +847,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 5_581_000 picoseconds. - Weight::from_parts(5_731_000, 3493) + // Minimum execution time: 5_520_000 picoseconds. + Weight::from_parts(5_720_000, 3493) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -902,8 +860,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 10_701_000 picoseconds. - Weight::from_parts(10_941_000, 4681) + // Minimum execution time: 10_850_000 picoseconds. + Weight::from_parts(11_091_000, 4681) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -911,8 +869,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 110_000 picoseconds. - Weight::from_parts(140_000, 0) + // Minimum execution time: 111_000 picoseconds. + Weight::from_parts(131_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -921,7 +879,7 @@ impl WeightInfo for () { // Measured: `0` // Estimated: `0` // Minimum execution time: 1_553_000 picoseconds. - Weight::from_parts(1_643_000, 0) + Weight::from_parts(1_683_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -936,8 +894,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 9_348_000 picoseconds. - Weight::from_parts(9_618_000, 4068) + // Minimum execution time: 9_619_000 picoseconds. + Weight::from_parts(9_929_000, 4068) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -947,8 +905,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 4_839_000 picoseconds. - Weight::from_parts(5_149_000, 1526) + // Minimum execution time: 5_029_000 picoseconds. + Weight::from_parts(5_220_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -974,8 +932,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `914` // Estimated: `4698` - // Minimum execution time: 50_055_000 picoseconds. - Weight::from_parts(50_526_000, 4698) + // Minimum execution time: 51_938_000 picoseconds. + Weight::from_parts(55_025_000, 4698) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } @@ -985,26 +943,9 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `480` // Estimated: `1516` - // Minimum execution time: 8_926_000 picoseconds. - Weight::from_parts(9_248_000, 1516) + // Minimum execution time: 9_628_000 picoseconds. + Weight::from_parts(10_400_000, 1516) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// 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) - fn auto_renew() -> Weight { - // Proof Size summary in bytes: - // Measured: `1186` - // Estimated: `4651` - // Minimum execution time: 12_654_000 picoseconds. - Weight::from_parts(12_984_000, 4651) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } } From a6c06762df396624ca24da0c4a8c9e548943b666 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 23 May 2024 17:44:27 +0200 Subject: [PATCH 26/48] dummy weights --- .../src/weights/pallet_broker.rs | 38 +++++++++++++++++++ .../src/weights/pallet_broker.rs | 38 +++++++++++++++++++ 2 files changed, 76 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 89b1c4c86632..95a88163c745 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 @@ -523,4 +523,42 @@ impl pallet_broker::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `Broker::SaleInfo` (r:1 w:1) + /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) + /// Storage: `Broker::AllowedRenewals` (r:1 w:2) + /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) + /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Authorship::Author` (r:1 w:0) + /// Proof: `Authorship::Author` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Workplan` (r:0 w:1) + /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) + fn enable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `914` + // Estimated: `4698` + // Minimum execution time: 51_938_000 picoseconds. + Weight::from_parts(55_025_000, 4698) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + fn disable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `1516` + // Minimum execution time: 9_628_000 picoseconds. + Weight::from_parts(10_400_000, 1516) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } 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 13d5fcf3898b..774c6596d9d5 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 @@ -523,4 +523,42 @@ impl pallet_broker::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `Broker::SaleInfo` (r:1 w:1) + /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) + /// Storage: `Broker::AllowedRenewals` (r:1 w:2) + /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) + /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Authorship::Author` (r:1 w:0) + /// Proof: `Authorship::Author` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Storage: `Broker::Workplan` (r:0 w:1) + /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) + fn enable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `914` + // Estimated: `4698` + // Minimum execution time: 51_938_000 picoseconds. + Weight::from_parts(55_025_000, 4698) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Broker::AutoRenewals` (r:1 w:1) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + fn disable_auto_renew() -> Weight { + // Proof Size summary in bytes: + // Measured: `480` + // Estimated: `1516` + // Minimum execution time: 9_628_000 picoseconds. + Weight::from_parts(10_400_000, 1516) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } From a4f3b6c1e6357e0ab2dd48a63761b8b041b82cdc Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 24 May 2024 11:49:32 +0200 Subject: [PATCH 27/48] don't auto renew when not needed --- .../frame/broker/src/dispatchable_impls.rs | 14 +++-- substrate/frame/broker/src/lib.rs | 2 +- substrate/frame/broker/src/tests.rs | 60 ++++++++++++++++--- substrate/frame/broker/src/tick_impls.rs | 36 ++++++++--- substrate/frame/broker/src/types.rs | 13 ++++ 5 files changed, 103 insertions(+), 22 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 7470c906b465..3a77fa51bedf 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -516,12 +516,13 @@ impl Pallet { return Err(Error::::NonTaskAutoRenewal.into()) }; + let renewal_begin = workload_end_hint.unwrap_or(sale.region_end); // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals - .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .binary_search_by(|r: &AutoRenewalRecord| r.core.cmp(&core)) .unwrap_or_else(|e| e); - renewals.try_insert(pos, (core, task)) + renewals.try_insert(pos, AutoRenewalRecord { core, task, begin: renewal_begin }) }) .map_err(|_| Error::::TooManyAutoRenewals)?; @@ -532,10 +533,15 @@ impl Pallet { pub(crate) fn do_disable_auto_renew(task: TaskId, core: CoreIndex) -> DispatchResult { AutoRenewals::::try_mutate(|renewals| -> DispatchResult { let pos = renewals - .binary_search_by(|r: &(CoreIndex, TaskId)| r.0.cmp(&core)) + .binary_search_by(|r: &AutoRenewalRecord| r.core.cmp(&core)) .map_err(|_| Error::::AutoRenewalNotEnabled)?; - ensure!(Some(&(core, task)) == renewals.get(pos), Error::::NoPermission); + let renewal_record = renewals.get(pos).ok_or(Error::::AutoRenewalNotEnabled)?; + + ensure!( + renewal_record.core == core && renewal_record.task == task, + Error::::NoPermission + ); renewals.remove(pos); Ok(()) })?; diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 0a426826a7a9..e6119ee93ab3 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -187,7 +187,7 @@ pub mod pallet { /// Sorted by `CoreIndex` to make the removal of cores from auto-renewal more efficient. #[pallet::storage] pub type AutoRenewals = - StorageValue<_, BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals>, ValueQuery>; + StorageValue<_, BoundedVec, ValueQuery>; #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 6b25b331e9cd..181739a5ee1d 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1440,7 +1440,10 @@ fn enable_auto_renew_works() { // Works when calling with the sovereign account: assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] + ); System::assert_has_event( Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), ); @@ -1453,7 +1456,14 @@ fn enable_auto_renew_works() { assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1002), (2, 1003)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![ + AutoRenewalRecord { core: 0, task: 1001, begin: 7 }, + AutoRenewalRecord { core: 1, task: 1002, begin: 7 }, + AutoRenewalRecord { core: 2, task: 1003, begin: 7 }, + ] + ); }); } @@ -1472,7 +1482,7 @@ fn enable_auto_renewal_with_end_hint_works() { ), }; // Each lease-holding parachain should be allowed to renew. Although the `when` field will - // likely be to a later timeslice. + // likely be set to a later timeslice. AllowedRenewals::::insert(AllowedRenewalId { core: 1, when: 20 }, &record); // Will fail if we don't provide the end hint since it expects it to be at next sale start @@ -1480,8 +1490,23 @@ fn enable_auto_renewal_with_end_hint_works() { assert_noop!(Broker::do_enable_auto_renew(2001, 1, None), Error::::NotAllowed); assert_ok!(Broker::do_enable_auto_renew(2001, 1, Some(20)),); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(1, 2001)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![AutoRenewalRecord { core: 1, task: 2001, begin: 20 },] + ); System::assert_has_event(Event::::AutoRenewalEnabled { core: 1, task: 2001 }.into()); + + // Even though we enabled auto renewal it shouldn't renew until ts 20. + + // Next cycle starting at 7. + advance_to(7); + + // Assert that it doesn't have this event: + /* + System::assert_has_event( + Event::::AutoRenewalFailed { core: 1, payer: Some(2001) }.into(), + ); + */ }); } @@ -1508,7 +1533,10 @@ fn enable_auto_renew_renews() { endow(1001, 1000); assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 }] + ); assert!(AllowedRenewals::::get(AllowedRenewalId { core: region_id.core, when: 10 // region end after renewal @@ -1537,7 +1565,14 @@ fn auto_renewal_works() { assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, None)); assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1002), (2, 1003)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![ + AutoRenewalRecord { core: 0, task: 1001, begin: 7 }, + AutoRenewalRecord { core: 1, task: 1002, begin: 7 }, + AutoRenewalRecord { core: 2, task: 1003, begin: 7 }, + ] + ); // We have to fund the sovereign account: endow(1001, 1000); @@ -1583,7 +1618,13 @@ fn auto_renewal_works() { // Given that core #1 didn't get renewed due to the account not being sufficiently funded, // Task (1003) will now be assigned to that core instead of core #2. - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001), (1, 1003)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![ + AutoRenewalRecord { core: 0, task: 1001, begin: 10 }, + AutoRenewalRecord { core: 1, task: 1003, begin: 10 }, + ] + ); }); } @@ -1601,7 +1642,10 @@ fn disable_auto_renew_works() { assert_noop!(Broker::do_disable_auto_renew(1001, 0), Error::::AutoRenewalNotEnabled); assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); - assert_eq!(AutoRenewals::::get().to_vec(), vec![(0, 1001)]); + assert_eq!( + AutoRenewals::::get().to_vec(), + vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] + ); // Only the sovereign account can disable: assert_noop!(Broker::do_disable_auto_renew(2001, 0), Error::::NoPermission); diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 765d8d2fbdd4..704384be8e9f 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -259,7 +259,7 @@ impl Pallet { }; SaleInfo::::put(&new_sale); - Self::renew_cores(); + Self::renew_cores(&new_sale); Self::deposit_event(Event::SaleInitialized { sale_start, @@ -334,25 +334,43 @@ impl Pallet { } /// Renews all the cores which have auto-renewal enabled. - pub(crate) fn renew_cores() { + pub(crate) fn renew_cores(sale: &SaleInfoRecordOf) { let renewals = AutoRenewals::::get(); - let mut successful_renewals: BoundedVec<(CoreIndex, TaskId), T::MaxAutoRenewals> = + let mut successful_renewals: BoundedVec = BoundedVec::new(); - for (core, task) in renewals.into_iter() { - let Some(payer) = T::SovereignAccountOf::sovereign_account(task) else { - Self::deposit_event(Event::::AutoRenewalFailed { core, payer: None }); + for record in renewals.into_iter() { + if sale.region_begin != record.begin { + // We skip the renewal for this core. + continue; + } + + let Some(payer) = T::SovereignAccountOf::sovereign_account(record.task) else { + Self::deposit_event(Event::::AutoRenewalFailed { + core: record.core, + payer: None, + }); continue; }; // The core index can change when renewing for several reasons. Because of this, we will // update the core indices in the auto-renewal vector with the new appropriate values. - if let Ok(new_core_index) = Self::do_renew(payer.clone(), core) { - if successful_renewals.try_push((new_core_index, task)).is_err() { + if let Ok(new_core_index) = Self::do_renew(payer.clone(), record.core) { + if successful_renewals + .try_push(AutoRenewalRecord { + core: new_core_index, + task: record.task, + begin: sale.region_end, + }) + .is_err() + { // This should never happen. Self::deposit_event(Event::::AutoRenewalLimitReached); } } else { - Self::deposit_event(Event::::AutoRenewalFailed { core, payer: Some(payer) }); + Self::deposit_event(Event::::AutoRenewalFailed { + core: record.core, + payer: Some(payer), + }); } } diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index f2cae9a41ad4..77b4f3400bc3 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -289,3 +289,16 @@ where Ok(()) } } + +/// A record containing information regarding auto-renewal for a specific core. +#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)] +pub struct AutoRenewalRecord { + /// The core for which auto renewal is enabled. + pub core: CoreIndex, + /// The task is assigned to the core. We keep track of it so we don't have to look it up when + /// performing auto-renewal. + pub task: TaskId, + /// Lease-holding parachains can also enable auto-renewal. They will start renewing only at the + /// end of the lease. This specifies the beginning timeslice from which we auto-renew. + pub begin: Timeslice, +} From 4f189492f9b10a9d6607848a61a645b3d3380766 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 24 May 2024 17:26:31 +0200 Subject: [PATCH 28/48] fix auto renewal --- substrate/frame/broker/src/tests.rs | 31 ++++++------ substrate/frame/broker/src/tick_impls.rs | 63 ++++++++++++------------ 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 181739a5ee1d..e2688ccef210 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1476,37 +1476,38 @@ fn enable_auto_renewal_with_end_hint_works() { let record = AllowedRenewalRecord { price: 100, completion: CompletionStatus::Complete( - vec![ScheduleItem { mask: CoreMask::complete(), assignment: Task(2001) }] + vec![ScheduleItem { mask: CoreMask::complete(), assignment: Task(1001) }] .try_into() .unwrap(), ), }; - // Each lease-holding parachain should be allowed to renew. Although the `when` field will + // Each lease-holding task should be allowed to renew. Although the `when` field will // likely be set to a later timeslice. - AllowedRenewals::::insert(AllowedRenewalId { core: 1, when: 20 }, &record); + AllowedRenewals::::insert(AllowedRenewalId { core: 1, when: 10 }, &record); + + endow(1001, 1000); // Will fail if we don't provide the end hint since it expects it to be at next sale start // or end. - assert_noop!(Broker::do_enable_auto_renew(2001, 1, None), Error::::NotAllowed); + assert_noop!(Broker::do_enable_auto_renew(1001, 1, None), Error::::NotAllowed); - assert_ok!(Broker::do_enable_auto_renew(2001, 1, Some(20)),); + assert_ok!(Broker::do_enable_auto_renew(1001, 1, Some(10))); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 1, task: 2001, begin: 20 },] + vec![AutoRenewalRecord { core: 1, task: 1001, begin: 10 },] ); - System::assert_has_event(Event::::AutoRenewalEnabled { core: 1, task: 2001 }.into()); - - // Even though we enabled auto renewal it shouldn't renew until ts 20. + System::assert_has_event(Event::::AutoRenewalEnabled { core: 1, task: 1001 }.into()); // Next cycle starting at 7. advance_to(7); - // Assert that it doesn't have this event: - /* - System::assert_has_event( - Event::::AutoRenewalFailed { core: 1, payer: Some(2001) }.into(), - ); - */ + // Ensure that the renewal didn't happen by checking that the balance remained the same, as + // the task has a lease until ts 13. + assert_eq!(balance(1001), 1000); + + // The next sale starts at 13. The renewal should happen now and the task should be charged. + advance_to(13); + assert_eq!(balance(1001), 900); }); } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 704384be8e9f..9df5e346aa63 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -336,44 +336,45 @@ impl Pallet { /// Renews all the cores which have auto-renewal enabled. pub(crate) fn renew_cores(sale: &SaleInfoRecordOf) { let renewals = AutoRenewals::::get(); - let mut successful_renewals: BoundedVec = - BoundedVec::new(); - for record in renewals.into_iter() { - if sale.region_begin != record.begin { - // We skip the renewal for this core. - continue; - } - let Some(payer) = T::SovereignAccountOf::sovereign_account(record.task) else { - Self::deposit_event(Event::::AutoRenewalFailed { - core: record.core, - payer: None, - }); - continue; - }; + let Ok(auto_renewals) = renewals + .into_iter() + .flat_map(|record| { + if sale.region_begin != record.begin { + // We skip the renewal for this core. + return Some(record) + } + + let Some(payer) = T::SovereignAccountOf::sovereign_account(record.task) else { + Self::deposit_event(Event::::AutoRenewalFailed { + core: record.core, + payer: None, + }); + return None + }; - // The core index can change when renewing for several reasons. Because of this, we will - // update the core indices in the auto-renewal vector with the new appropriate values. - if let Ok(new_core_index) = Self::do_renew(payer.clone(), record.core) { - if successful_renewals - .try_push(AutoRenewalRecord { + if let Ok(new_core_index) = Self::do_renew(payer.clone(), record.core) { + Some(AutoRenewalRecord { core: new_core_index, task: record.task, begin: sale.region_end, }) - .is_err() - { - // This should never happen. - Self::deposit_event(Event::::AutoRenewalLimitReached); + } else { + Self::deposit_event(Event::::AutoRenewalFailed { + core: record.core, + payer: Some(payer), + }); + + None } - } else { - Self::deposit_event(Event::::AutoRenewalFailed { - core: record.core, - payer: Some(payer), - }); - } - } + }) + .collect::>() + .try_into() + else { + Self::deposit_event(Event::::AutoRenewalLimitReached); + return; + }; - AutoRenewals::::set(successful_renewals); + AutoRenewals::::set(auto_renewals); } } From 5d29cd3bb22a3e4cbf2cd86b3b960098ac8238d9 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 24 May 2024 18:02:06 +0200 Subject: [PATCH 29/48] more checks --- substrate/frame/broker/src/tests.rs | 30 ++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index e2688ccef210..2d1a5dc5f43d 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1483,31 +1483,47 @@ fn enable_auto_renewal_with_end_hint_works() { }; // Each lease-holding task should be allowed to renew. Although the `when` field will // likely be set to a later timeslice. - AllowedRenewals::::insert(AllowedRenewalId { core: 1, when: 10 }, &record); + AllowedRenewals::::insert(AllowedRenewalId { core: 0, when: 10 }, &record); endow(1001, 1000); // Will fail if we don't provide the end hint since it expects it to be at next sale start // or end. - assert_noop!(Broker::do_enable_auto_renew(1001, 1, None), Error::::NotAllowed); + assert_noop!(Broker::do_enable_auto_renew(1001, 0, None), Error::::NotAllowed); - assert_ok!(Broker::do_enable_auto_renew(1001, 1, Some(10))); + assert_ok!(Broker::do_enable_auto_renew(1001, 0, Some(10))); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 1, task: 1001, begin: 10 },] + vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 },] ); - System::assert_has_event(Event::::AutoRenewalEnabled { core: 1, task: 1001 }.into()); + System::assert_has_event(Event::::AutoRenewalEnabled { core: 0, task: 1001 }.into()); // Next cycle starting at 7. advance_to(7); - // Ensure that the renewal didn't happen by checking that the balance remained the same, as - // the task has a lease until ts 13. + // Ensure that the renewal didn't happen by checking that the balance remained the same + // since it still has a lease. assert_eq!(balance(1001), 1000); // The next sale starts at 13. The renewal should happen now and the task should be charged. advance_to(13); assert_eq!(balance(1001), 900); + + System::assert_has_event( + Event::::Renewed { + who: 1001, // sovereign account + old_core: 0, + core: 0, + price: 100, + begin: 10, + duration: 3, + workload: Schedule::truncate_from(vec![ScheduleItem { + assignment: Task(1001), + mask: CoreMask::complete(), + }]), + } + .into(), + ); }); } From 0d9e91d174d5e5026c6c6f1f45ca548e6ce4a24d Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 27 May 2024 10:04:35 +0200 Subject: [PATCH 30/48] test fixes/improvements --- substrate/frame/broker/src/tests.rs | 26 ++++++++++++------------ substrate/frame/broker/src/tick_impls.rs | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 2d1a5dc5f43d..399bb0f977d0 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1481,14 +1481,14 @@ fn enable_auto_renewal_with_end_hint_works() { .unwrap(), ), }; - // Each lease-holding task should be allowed to renew. Although the `when` field will - // likely be set to a later timeslice. + // Each lease-holding task should be allowed to auto renew. Although the `when` field will + // likely be set to a later timeslice. For this reason renewals will only begin later. AllowedRenewals::::insert(AllowedRenewalId { core: 0, when: 10 }, &record); endow(1001, 1000); - // Will fail if we don't provide the end hint since it expects it to be at next sale start - // or end. + // Will fail if we don't provide the end hint since it expects renewal record to be at next + // sale start or end. assert_noop!(Broker::do_enable_auto_renew(1001, 0, None), Error::::NotAllowed); assert_ok!(Broker::do_enable_auto_renew(1001, 0, Some(10))); @@ -1501,14 +1501,16 @@ fn enable_auto_renewal_with_end_hint_works() { // Next cycle starting at 7. advance_to(7); - // Ensure that the renewal didn't happen by checking that the balance remained the same - // since it still has a lease. + // Ensure that the renewal didn't happen by checking that the balance remained the same, as + // there is still no need to renew. assert_eq!(balance(1001), 1000); - // The next sale starts at 13. The renewal should happen now and the task should be charged. + // The next sale starts at 13. The renewal should happen now and the account should be + // charged. advance_to(13); assert_eq!(balance(1001), 900); + // Make sure that the renewal happened: System::assert_has_event( Event::::Renewed { who: 1001, // sovereign account @@ -1538,7 +1540,8 @@ fn enable_auto_renew_renews() { // advance to next bulk sale: advance_to(6); - // Since we didn't renew for the next bulk period, enabling auto-renewal will renew. + // Since we didn't renew for the next bulk period, enabling auto-renewal will renew, + // ensuring the task continues execution. // Will fail because we didn't fund the sovereign account: assert_noop!( @@ -1554,11 +1557,8 @@ fn enable_auto_renew_renews() { AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 }] ); - assert!(AllowedRenewals::::get(AllowedRenewalId { - core: region_id.core, - when: 10 // region end after renewal - }) - .is_some()); + assert!(AllowedRenewals::::get(AllowedRenewalId { core: region_id.core, when: 10 }) + .is_some()); System::assert_has_event( Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 9df5e346aa63..728ede6d0e03 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -340,7 +340,7 @@ impl Pallet { let Ok(auto_renewals) = renewals .into_iter() .flat_map(|record| { - if sale.region_begin != record.begin { + if sale.region_begin < record.begin { // We skip the renewal for this core. return Some(record) } From 88c9ce1c6a9ac92bb04f27863e3f48d4fa3e91a2 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 30 May 2024 13:05:38 +0200 Subject: [PATCH 31/48] merge fix --- .../src/weights/pallet_broker.rs | 4 +- .../src/weights/pallet_broker.rs | 4 +- substrate/frame/broker/src/benchmarking.rs | 2 +- .../frame/broker/src/dispatchable_impls.rs | 6 +-- substrate/frame/broker/src/migration.rs | 6 +-- substrate/frame/broker/src/tests.rs | 13 +++--- substrate/frame/broker/src/weights.rs | 44 +++++-------------- 7 files changed, 31 insertions(+), 48 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 f8a1c018a61c..b34fa60d7c9a 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 @@ -525,8 +525,8 @@ impl pallet_broker::WeightInfo for WeightInfo { } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) - /// Storage: `Broker::AllowedRenewals` (r:1 w:2) - /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`) + /// Storage: `Broker::PotentialRenewals` (r:1 w:2) + /// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (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 ed95b764c317..6093b8d4446f 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 @@ -525,8 +525,8 @@ impl pallet_broker::WeightInfo for WeightInfo { } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) - /// Storage: `Broker::AllowedRenewals` (r:1 w:2) - /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`) + /// Storage: `Broker::PotentialRenewals` (r:1 w:2) + /// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index b06f916e8de1..02bd7839c99a 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -1016,7 +1016,7 @@ mod benches { assert_last_event::(Event::AutoRenewalEnabled { core: region.core, task: 2001 }.into()); // Make sure we indeed renewed: - assert!(AllowedRenewals::::get(AllowedRenewalId { + assert!(PotentialRenewals::::get(PotentialRenewalId { core: region.core, when: 10 // region end after renewal }) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index b9aa3e57f816..f364c8fa037f 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -487,12 +487,12 @@ impl Pallet { }; let record = if let Some(workload_end) = workload_end_hint { - AllowedRenewals::::get(AllowedRenewalId { core, when: workload_end }) + PotentialRenewals::::get(PotentialRenewalId { core, when: workload_end }) .ok_or(Error::::NotAllowed)? } else { // If the core hasn't been renewed yet we will renew it now. if let Some(record) = - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_begin }) + PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) { Self::do_renew(sovereign_account.clone(), core)?; record @@ -501,7 +501,7 @@ impl Pallet { // be able to find it for the upcoming bulk period. // // If not the core is not eligable for renewal. - AllowedRenewals::::get(AllowedRenewalId { core, when: sale.region_end }) + PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) .ok_or(Error::::NotAllowed)? } }; diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index f354e447fe84..1fd1675b078a 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -85,7 +85,7 @@ mod v2 { }; #[storage_alias] - pub type AllowedRenewals = StorageMap< + pub type PotentialRenewals = StorageMap< Pallet, Twox64Concat, PotentialRenewalId, @@ -98,7 +98,7 @@ mod v2 { impl UncheckedOnRuntimeUpgrade for MigrateToV2Impl { fn on_runtime_upgrade() -> frame_support::weights::Weight { let mut count = 0; - for (renewal_id, renewal) in AllowedRenewals::::drain() { + for (renewal_id, renewal) in PotentialRenewals::::drain() { PotentialRenewals::::insert(renewal_id, renewal); count += 1; } @@ -114,7 +114,7 @@ mod v2 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - Ok((AllowedRenewals::::iter_keys().count() as u32).encode()) + Ok((PotentialRenewals::::iter_keys().count() as u32).encode()) } #[cfg(feature = "try-runtime")] diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 579eda131622..6e74b0f790cf 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1496,7 +1496,7 @@ fn enable_auto_renew_works() { // Eligible for renewal after final assignment: assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); - assert!(AllowedRenewals::::get(AllowedRenewalId { + assert!(PotentialRenewals::::get(PotentialRenewalId { core: region_id.core, when: record.end }) @@ -1543,7 +1543,7 @@ fn enable_auto_renewal_with_end_hint_works() { assert_ok!(Broker::do_start_sales(100, 1)); advance_to(2); - let record = AllowedRenewalRecord { + let record = PotentialRenewalRecord { price: 100, completion: CompletionStatus::Complete( vec![ScheduleItem { mask: CoreMask::complete(), assignment: Task(1001) }] @@ -1553,7 +1553,7 @@ fn enable_auto_renewal_with_end_hint_works() { }; // Each lease-holding task should be allowed to auto renew. Although the `when` field will // likely be set to a later timeslice. For this reason renewals will only begin later. - AllowedRenewals::::insert(AllowedRenewalId { core: 0, when: 10 }, &record); + PotentialRenewals::::insert(PotentialRenewalId { core: 0, when: 10 }, &record); endow(1001, 1000); @@ -1627,8 +1627,11 @@ fn enable_auto_renew_renews() { AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 }] ); - assert!(AllowedRenewals::::get(AllowedRenewalId { core: region_id.core, when: 10 }) - .is_some()); + assert!(PotentialRenewals::::get(PotentialRenewalId { + core: region_id.core, + when: 10 + }) + .is_some()); System::assert_has_event( Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index abe3fb69d92c..81342e8536c1 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -27,16 +27,18 @@ // ./target/release/substrate-node // benchmark // pallet +// --chain=dev // --steps=50 // --repeat=20 +// --pallet=pallet_broker +// --no-storage-info +// --no-median-slopes +// --no-min-squares // --extrinsic=* // --wasm-execution=compiled // --heap-pages=4096 -// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=pallet_broker -// --chain=dev -// --header=./substrate/HEADER-APACHE2 // --output=./substrate/frame/broker/src/weights.rs +// --header=./substrate/HEADER-APACHE2 // --template=./substrate/.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -165,7 +167,6 @@ impl WeightInfo for SubstrateWeight { /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::Regions` (r:0 w:1) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `635` @@ -191,7 +192,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `769` + // Measured: `753` // Estimated: `4698` // Minimum execution time: 43_492_000 picoseconds. Weight::from_parts(44_284_000, 4698) @@ -200,7 +201,6 @@ impl WeightInfo for SubstrateWeight { } /// Storage: `Broker::Regions` (r:1 w:1) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -212,7 +212,6 @@ impl WeightInfo for SubstrateWeight { } /// Storage: `Broker::Regions` (r:1 w:2) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -224,7 +223,6 @@ impl WeightInfo for SubstrateWeight { } /// Storage: `Broker::Regions` (r:1 w:3) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -240,13 +238,11 @@ impl WeightInfo for SubstrateWeight { /// 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(86), added: 2561, 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: `741` - // Measured: `741` // Estimated: `4681` // Minimum execution time: 22_142_000 picoseconds. Weight::from_parts(23_204_000, 4681) @@ -257,7 +253,6 @@ impl WeightInfo for SubstrateWeight { /// 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(86), added: 2561, 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) @@ -267,7 +262,6 @@ impl WeightInfo for SubstrateWeight { fn pool() -> Weight { // Proof Size summary in bytes: // Measured: `776` - // Measured: `776` // Estimated: `5996` // Minimum execution time: 26_320_000 picoseconds. Weight::from_parts(27_813_000, 5996) @@ -309,7 +303,6 @@ impl WeightInfo for SubstrateWeight { /// 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(86), added: 2561, 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: `604` @@ -377,7 +370,6 @@ impl WeightInfo for SubstrateWeight { /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn process_core_count(_n: u32, ) -> Weight { fn process_core_count(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `404` @@ -407,7 +399,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(3_u64)) } /// 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: `0` @@ -488,8 +479,8 @@ impl WeightInfo for SubstrateWeight { } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) - /// Storage: `Broker::AllowedRenewals` (r:1 w:2) - /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`) + /// Storage: `Broker::PotentialRenewals` (r:1 w:2) + /// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) @@ -609,7 +600,6 @@ impl WeightInfo for () { /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::Regions` (r:0 w:1) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `635` @@ -635,7 +625,7 @@ impl WeightInfo for () { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `769` + // Measured: `753` // Estimated: `4698` // Minimum execution time: 43_492_000 picoseconds. Weight::from_parts(44_284_000, 4698) @@ -644,7 +634,6 @@ impl WeightInfo for () { } /// Storage: `Broker::Regions` (r:1 w:1) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -656,7 +645,6 @@ impl WeightInfo for () { } /// Storage: `Broker::Regions` (r:1 w:2) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -668,7 +656,6 @@ impl WeightInfo for () { } /// Storage: `Broker::Regions` (r:1 w:3) /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, 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: `496` @@ -684,13 +671,11 @@ impl WeightInfo for () { /// 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(86), added: 2561, 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: `741` - // Measured: `741` // Estimated: `4681` // Minimum execution time: 22_142_000 picoseconds. Weight::from_parts(23_204_000, 4681) @@ -701,7 +686,6 @@ impl WeightInfo for () { /// 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(86), added: 2561, 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) @@ -711,7 +695,6 @@ impl WeightInfo for () { fn pool() -> Weight { // Proof Size summary in bytes: // Measured: `776` - // Measured: `776` // Estimated: `5996` // Minimum execution time: 26_320_000 picoseconds. Weight::from_parts(27_813_000, 5996) @@ -753,7 +736,6 @@ impl WeightInfo for () { /// 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(86), added: 2561, 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: `604` @@ -821,7 +803,6 @@ impl WeightInfo for () { /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. - fn process_core_count(_n: u32, ) -> Weight { fn process_core_count(_n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `404` @@ -851,7 +832,6 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(3_u64)) } /// 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: `0` @@ -932,8 +912,8 @@ impl WeightInfo for () { } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) - /// Storage: `Broker::AllowedRenewals` (r:1 w:2) - /// Proof: `Broker::AllowedRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, mode: `MaxEncodedLen`) + /// Storage: `Broker::PotentialRenewals` (r:1 w:2) + /// Proof: `Broker::PotentialRenewals` (`max_values`: None, `max_size`: Some(1233), added: 3708, 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::Status` (r:1 w:0) From 17e0ee540ad963893b10430e1fd156b67f7fe551 Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 30 May 2024 17:15:41 +0200 Subject: [PATCH 32/48] cleanup | benchmarks: TODO --- Cargo.lock | 1 - .../coretime/coretime-rococo/src/coretime.rs | 25 +++--------- .../coretime/coretime-rococo/src/lib.rs | 2 - .../coretime/coretime-westend/Cargo.toml | 1 - .../coretime/coretime-westend/src/coretime.rs | 27 +++---------- .../coretime/coretime-westend/src/lib.rs | 2 - substrate/bin/node/runtime/src/lib.rs | 31 ++++----------- .../frame/broker/src/coretime_interface.rs | 24 +----------- .../frame/broker/src/dispatchable_impls.rs | 27 ++----------- substrate/frame/broker/src/lib.rs | 38 +++++++++++++------ substrate/frame/broker/src/mock.rs | 23 +++-------- substrate/frame/broker/src/tests.rs | 38 +++++++++++-------- substrate/frame/broker/src/tick_impls.rs | 4 +- 13 files changed, 80 insertions(+), 163 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff11e67396b7..73765da3c2d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3262,7 +3262,6 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", - "polkadot-runtime-parachains", "scale-info", "serde", "sp-api", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 7b2bd28b1224..070521a76433 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -26,12 +26,10 @@ use frame_support::{ }, }; use pallet_broker::{ - CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, - TaskAccountInterface, TaskId, + CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId, }; use parachains_common::{AccountId, Balance, BlockNumber}; -use polkadot_runtime_parachains::{ensure_parachain, origin, Origin as ParaOrigin}; -use sp_runtime::traits::BadOrigin; +use sp_runtime::traits::MaybeConvert; use xcm::latest::prelude::*; use xcm_executor::traits::ConvertLocation; @@ -225,20 +223,9 @@ impl CoretimeInterface for CoretimeAllocator { impl origin::Config for Runtime {} -pub struct TaskSovereignAccount; -impl TaskAccountInterface for TaskSovereignAccount { - type AccountId = AccountId; - type OuterOrigin = RuntimeOrigin; - type TaskOrigin = ParaOrigin; - - fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { - match ensure_parachain(o) { - Ok(para_id) => Ok(para_id.into()), - Err(e) => Err(e), - } - } - - fn sovereign_account(id: TaskId) -> Option { +pub struct SovereignAccountOf; +impl MaybeConvert for SovereignAccountOf { + fn maybe_convert(id: TaskId) -> Option { // Currently all tasks are parachains. let location = Location::new(1, [Parachain(id)]); LocationToAccountId::convert_location(&location) @@ -260,7 +247,7 @@ impl pallet_broker::Config for Runtime { type WeightInfo = weights::pallet_broker::WeightInfo; type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; - type SovereignAccountOf = TaskSovereignAccount; + type SovereignAccountOf = SovereignAccountOf; type MaxAutoRenewals = ConstU32<50>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 5776b89dbe0e..b78802790480 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -56,7 +56,6 @@ use parachains_common::{ AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use polkadot_runtime_parachains::origin; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] @@ -474,7 +473,6 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility = 40, Multisig: pallet_multisig = 41, - ParachainsOrigin: origin = 42, // The main stage. Broker: pallet_broker = 50, diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 3b4621afdb16..4611228da299 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -57,7 +57,6 @@ pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features pallet-xcm-benchmarks = { path = "../../../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false, optional = true } polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } -polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains", default-features = false } westend-runtime-constants = { path = "../../../../../polkadot/runtime/westend/constants", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 2fe3154507be..2a57eb807d67 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -26,12 +26,10 @@ use frame_support::{ }, }; use pallet_broker::{ - CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, - TaskAccountInterface, TaskId, + CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId, }; use parachains_common::{AccountId, Balance, BlockNumber}; -use polkadot_runtime_parachains::{ensure_parachain, origin, Origin as ParaOrigin}; -use sp_runtime::traits::BadOrigin; +use sp_runtime::traits::MaybeConvert; use xcm::latest::prelude::*; use xcm_executor::traits::ConvertLocation; @@ -235,22 +233,9 @@ impl CoretimeInterface for CoretimeAllocator { } } -impl origin::Config for Runtime {} - -pub struct TaskSovereignAccount; -impl TaskAccountInterface for TaskSovereignAccount { - type AccountId = AccountId; - type OuterOrigin = RuntimeOrigin; - type TaskOrigin = ParaOrigin; - - fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { - match ensure_parachain(o) { - Ok(para_id) => Ok(para_id.into()), - Err(e) => Err(e), - } - } - - fn sovereign_account(id: TaskId) -> Option { +pub struct SovereignAccountOf; +impl MaybeConvert for SovereignAccountOf { + fn maybe_convert(id: TaskId) -> Option { // Currently all tasks are parachains. let location = Location::new(1, [Parachain(id)]); LocationToAccountId::convert_location(&location) @@ -273,7 +258,7 @@ impl pallet_broker::Config for Runtime { type WeightInfo = weights::pallet_broker::WeightInfo; type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; - type SovereignAccountOf = TaskSovereignAccount; + type SovereignAccountOf = SovereignAccountOf; type MaxAutoRenewals = ConstU32<10>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 9ad78c0b8098..78b963e3b405 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -56,7 +56,6 @@ use parachains_common::{ AVERAGE_ON_INITIALIZE_RATIO, NORMAL_DISPATCH_RATIO, }; use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate}; -use polkadot_runtime_parachains::origin; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; #[cfg(any(feature = "std", test))] @@ -468,7 +467,6 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility = 40, Multisig: pallet_multisig = 41, - ParachainsOrigin: origin = 42, // The main stage. Broker: pallet_broker = 50, diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index c50fc6d07013..11c8ae4e1555 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -75,7 +75,7 @@ use pallet_nis::WithMaximumOf; use pallet_session::historical as pallet_session_historical; // Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles // -use pallet_broker::{TaskAccountInterface, TaskId}; +use pallet_broker::TaskId; #[allow(deprecated)] pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; @@ -94,8 +94,8 @@ use sp_runtime::{ curve::PiecewiseLinear, generic, impl_opaque_keys, traits::{ - self, AccountIdConversion, BadOrigin, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, - NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup, + self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, + MaybeConvert, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, @@ -2134,27 +2134,10 @@ impl CoretimeInterface for CoretimeProvider { } } -pub struct TaskSovereignAccount; +pub struct SovereignAccountOf; // Dummy implementation which converts `TaskId` to `AccountId`. -impl TaskAccountInterface for TaskSovereignAccount { - type AccountId = AccountId; - type OuterOrigin = RuntimeOrigin; - type TaskOrigin = frame_system::RawOrigin; - - fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { - match o.into() { - Ok(frame_system::RawOrigin::Signed(account)) => { - let account_arr: [u8; 32] = account.try_into().map_err(|_| BadOrigin)?; - let encoded: [u8; 4] = account_arr[0..4].try_into().map_err(|_| BadOrigin)?; - - let task = u32::from_le_bytes(encoded); - Ok(task) - }, - _ => Err(BadOrigin), - } - } - - fn sovereign_account(task: TaskId) -> Option { +impl MaybeConvert for SovereignAccountOf { + fn maybe_convert(task: TaskId) -> Option { let mut account: [u8; 32] = [0; 32]; account[..4].copy_from_slice(&task.to_le_bytes()); Some(account.into()) @@ -2172,7 +2155,7 @@ impl pallet_broker::Config for Runtime { type WeightInfo = (); type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; - type SovereignAccountOf = TaskSovereignAccount; + type SovereignAccountOf = SovereignAccountOf; type MaxAutoRenewals = ConstU32<5>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index cdc9ff8ed551..58efa7fa92bb 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -22,7 +22,7 @@ use frame_support::Parameter; use scale_info::TypeInfo; use sp_arithmetic::traits::AtLeast32BitUnsigned; use sp_core::RuntimeDebug; -use sp_runtime::traits::{BadOrigin, BlockNumberProvider}; +use sp_runtime::traits::BlockNumberProvider; use sp_std::vec::Vec; /// Index of a Polkadot Core. @@ -146,25 +146,3 @@ impl CoretimeInterface for () { #[cfg(feature = "runtime-benchmarks")] fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } - -/// Trait for getting the associated account and origin of a task. -/// -/// For parachains, this is the sovereign account, which is controlled by the parachain -/// itself. -pub trait TaskAccountInterface { - /// The type for representing accounts. - type AccountId; - - /// The overarching origin type. - type OuterOrigin: Into>; - - /// The custom task origin. Given that all tasks on Polkadot are parachains this will most - /// likely be the `Parachain` origin. - type TaskOrigin; - - /// Ensures that the origin is a task origin and returns the associated `TaskId`. - fn ensure_task_sovereign_account(o: Self::OuterOrigin) -> Result; - - /// Returns the associated account of a task. - fn sovereign_account(task: TaskId) -> Option; -} diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index f364c8fa037f..d414e0a9988c 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -477,16 +477,14 @@ impl Pallet { } pub(crate) fn do_enable_auto_renew( - task: TaskId, + sovereign_account: T::AccountId, core: CoreIndex, + task: TaskId, workload_end_hint: Option, ) -> DispatchResult { let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - let Some(sovereign_account) = T::SovereignAccountOf::sovereign_account(task) else { - return Err(Error::::SovereignAccountNotFound.into()); - }; - let record = if let Some(workload_end) = workload_end_hint { + let _renewal_record = if let Some(workload_end) = workload_end_hint { PotentialRenewals::::get(PotentialRenewalId { core, when: workload_end }) .ok_or(Error::::NotAllowed)? } else { @@ -506,23 +504,6 @@ impl Pallet { } }; - let workload = - record.completion.drain_complete().ok_or(Error::::IncompleteAssignment)?; - - // Given that only non-interlaced cores can be renewed, there should be only one - // assignment in the core's workload. - ensure!(workload.len() == 1, Error::::IncompleteAssignment); - let Some(schedule_item) = workload.get(0) else { - return Err(Error::::NotAllowed.into()) - }; - - if let CoreAssignment::Task(core_task) = schedule_item.assignment { - // Sovereign account of a task can only enable auto renewal for its own core. - ensure!(task == core_task, Error::::NoPermission); - } else { - return Err(Error::::NonTaskAutoRenewal.into()) - }; - let renewal_begin = workload_end_hint.unwrap_or(sale.region_end); // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { @@ -537,7 +518,7 @@ impl Pallet { Ok(()) } - pub(crate) fn do_disable_auto_renew(task: TaskId, core: CoreIndex) -> DispatchResult { + pub(crate) fn do_disable_auto_renew(core: CoreIndex, task: TaskId) -> DispatchResult { AutoRenewals::::try_mutate(|renewals| -> DispatchResult { let pos = renewals .binary_search_by(|r: &AutoRenewalRecord| r.core.cmp(&core)) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 3925ef8dfd94..46eed378e9c6 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -62,7 +62,7 @@ pub mod pallet { PalletId, }; use frame_system::pallet_prelude::*; - use sp_runtime::traits::{Convert, ConvertBack}; + use sp_runtime::traits::{Convert, ConvertBack, MaybeConvert}; use sp_std::vec::Vec; const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); @@ -101,10 +101,7 @@ pub mod pallet { /// Type used for getting the associated account of a task. This account is controlled by /// the task itself. - type SovereignAccountOf: TaskAccountInterface< - AccountId = Self::AccountId, - OuterOrigin = Self::RuntimeOrigin, - >; + type SovereignAccountOf: MaybeConvert; /// Identifier from which the internal Pot is generated. #[pallet::constant] @@ -865,6 +862,7 @@ pub mod pallet { /// /// - `origin`: Must be the sovereign account of the task /// - `core`: The core for which we want to enable auto renewal. + /// - `task`: The task for which we want to enable auto renewal. /// - `workload_end_hint` parameter should be used when enabling auto-renewal for /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. #[pallet::call_index(20)] @@ -872,11 +870,17 @@ pub mod pallet { pub fn enable_auto_renew( origin: OriginFor, core: CoreIndex, + task: TaskId, workload_end_hint: Option, ) -> DispatchResult { - // Only the sovereign account of the task can enable auto-renewal. - let task = T::SovereignAccountOf::ensure_task_sovereign_account(origin)?; - Self::do_enable_auto_renew(task, core, workload_end_hint)?; + let who = ensure_signed(origin)?; + + let sovereign_account = T::SovereignAccountOf::maybe_convert(task) + .ok_or(Error::::SovereignAccountNotFound)?; + // Only the sovereign account of a task can enable auto renewal for its own core. + ensure!(who == sovereign_account, Error::::NoPermission); + + Self::do_enable_auto_renew(sovereign_account, core, task, workload_end_hint)?; Ok(()) } @@ -885,13 +889,23 @@ pub mod pallet { /// Callable by the sovereign account of the task on the specified core. /// /// - `origin`: Must be the sovereign account of the task. - /// - `core`: The core for which we want to enable auto renewal. + /// - `core`: The core for which we want to disable auto renewal. + /// - `task`: The task for which we want to disable auto renewal. #[pallet::call_index(21)] #[pallet::weight(T::WeightInfo::notify_core_count())] - pub fn disable_auto_renew(origin: OriginFor, core: CoreIndex) -> DispatchResult { + pub fn disable_auto_renew( + origin: OriginFor, + core: CoreIndex, + task: TaskId, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + + let sovereign_account = T::SovereignAccountOf::maybe_convert(task) + .ok_or(Error::::SovereignAccountNotFound)?; // Only the sovereign account of the task can disable auto-renewal. - let task = T::SovereignAccountOf::ensure_task_sovereign_account(origin)?; - Self::do_disable_auto_renew(task, core)?; + ensure!(who == sovereign_account, Error::::NoPermission); + + Self::do_disable_auto_renew(core, task)?; Ok(()) } diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 5e361c0f4fd7..fdc4df38d4c1 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -27,11 +27,11 @@ use frame_support::{ }, PalletId, }; -use frame_system::{EnsureRoot, EnsureSignedBy, RawOrigin}; +use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_arithmetic::Perbill; use sp_core::{ConstU32, ConstU64, Get}; use sp_runtime::{ - traits::{BadOrigin, BlockNumberProvider, Identity}, + traits::{BlockNumberProvider, Identity, MaybeConvert}, BuildStorage, Saturating, }; use sp_std::collections::btree_map::BTreeMap; @@ -187,21 +187,10 @@ ord_parameter_types! { } type EnsureOneOrRoot = EitherOfDiverse, EnsureSignedBy>; -pub struct TaskSovereignAccount; // Dummy implementation which converts `TaskId` to `AccountId`. -impl TaskAccountInterface for TaskSovereignAccount { - type AccountId = u64; - type OuterOrigin = RuntimeOrigin; - type TaskOrigin = RawOrigin; - - fn ensure_task_sovereign_account(o: RuntimeOrigin) -> Result { - match o.into() { - Ok(RawOrigin::Signed(account)) => Ok(account as TaskId), - _ => Err(BadOrigin), - } - } - - fn sovereign_account(task: TaskId) -> Option { +pub struct SovereignAccountOf; +impl MaybeConvert for SovereignAccountOf { + fn maybe_convert(task: TaskId) -> Option { Some(task.into()) } } @@ -218,7 +207,7 @@ impl crate::Config for Test { type WeightInfo = (); type PalletId = TestBrokerId; type AdminOrigin = EnsureOneOrRoot; - type SovereignAccountOf = TaskSovereignAccount; + type SovereignAccountOf = SovereignAccountOf; type MaxAutoRenewals = ConstU32<5>; type PriceAdapter = CenterTargetPrice>; } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 6e74b0f790cf..55e5e3fcedf3 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1490,7 +1490,7 @@ fn enable_auto_renew_works() { // Cannot enable auto renewal with provisional finality: assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Provisional)); assert_noop!( - Broker::do_enable_auto_renew(1001, region_id.core, None), + Broker::do_enable_auto_renew(1001, region_id.core, 1001, None), Error::::NotAllowed ); @@ -1504,12 +1504,12 @@ fn enable_auto_renew_works() { // Only the task's sovereign account can enable auto renewal. assert_noop!( - Broker::do_enable_auto_renew(1, region_id.core, None), + Broker::enable_auto_renew(RuntimeOrigin::signed(1), region_id.core, 1001, None), Error::::NoPermission ); // Works when calling with the sovereign account: - assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] @@ -1523,8 +1523,8 @@ fn enable_auto_renew_works() { let region_3 = Broker::do_purchase(1, u64::max_value()).unwrap(); assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); - assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); - assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, None)); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, None)); assert_eq!( AutoRenewals::::get().to_vec(), @@ -1559,9 +1559,9 @@ fn enable_auto_renewal_with_end_hint_works() { // Will fail if we don't provide the end hint since it expects renewal record to be at next // sale start or end. - assert_noop!(Broker::do_enable_auto_renew(1001, 0, None), Error::::NotAllowed); + assert_noop!(Broker::do_enable_auto_renew(1001, 0, 1001, None), Error::::NotAllowed); - assert_ok!(Broker::do_enable_auto_renew(1001, 0, Some(10))); + assert_ok!(Broker::do_enable_auto_renew(1001, 0, 1001, Some(10))); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 },] @@ -1615,14 +1615,14 @@ fn enable_auto_renew_renews() { // Will fail because we didn't fund the sovereign account: assert_noop!( - Broker::do_enable_auto_renew(1001, region_id.core, None), + Broker::do_enable_auto_renew(1001, region_id.core, 1001, None), TokenError::FundsUnavailable ); // Will succeed after funding the sovereign account: endow(1001, 1000); - assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 }] @@ -1652,9 +1652,9 @@ fn auto_renewal_works() { assert_ok!(Broker::do_assign(region_1, Some(1), 1001, Final)); assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); - assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, None)); - assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, None)); - assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, 1001, None)); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, None)); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, None)); assert_eq!( AutoRenewals::::get().to_vec(), vec![ @@ -1729,17 +1729,23 @@ fn disable_auto_renew_works() { assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Final)); // Cannot disable auto-renewal if we don't have it enabled. - assert_noop!(Broker::do_disable_auto_renew(1001, 0), Error::::AutoRenewalNotEnabled); + assert_noop!( + Broker::do_disable_auto_renew(region_id.core, 1001), + Error::::AutoRenewalNotEnabled + ); - assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] ); // Only the sovereign account can disable: - assert_noop!(Broker::do_disable_auto_renew(2001, 0), Error::::NoPermission); - assert_ok!(Broker::do_disable_auto_renew(1001, 0)); + assert_noop!( + Broker::disable_auto_renew(RuntimeOrigin::signed(1), 0, 1001), + Error::::NoPermission + ); + assert_ok!(Broker::do_disable_auto_renew(0, 1001)); assert_eq!(AutoRenewals::::get().to_vec(), vec![]); System::assert_has_event( diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 5ac2e86982b0..7bea7e3e18ec 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -18,7 +18,7 @@ use super::*; use frame_support::{pallet_prelude::*, weights::WeightMeter}; use sp_arithmetic::traits::{One, SaturatedConversion, Saturating, Zero}; -use sp_runtime::traits::ConvertBack; +use sp_runtime::traits::{ConvertBack, MaybeConvert}; use sp_std::{vec, vec::Vec}; use CompletionStatus::Complete; @@ -335,7 +335,7 @@ impl Pallet { return Some(record) } - let Some(payer) = T::SovereignAccountOf::sovereign_account(record.task) else { + let Some(payer) = T::SovereignAccountOf::maybe_convert(record.task) else { Self::deposit_event(Event::::AutoRenewalFailed { core: record.core, payer: None, From 8be2d02e6e618bfd2ca2a7d52c8cffab71d1c8a2 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Fri, 31 May 2024 09:13:11 +0200 Subject: [PATCH 33/48] Update substrate/frame/broker/src/dispatchable_impls.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- substrate/frame/broker/src/dispatchable_impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index d414e0a9988c..45e7c43af8ee 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -498,7 +498,7 @@ impl Pallet { // If we couldn't find the renewal record for the current bulk period we should // be able to find it for the upcoming bulk period. // - // If not the core is not eligable for renewal. + // If not the core is not eligible for renewal. PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) .ok_or(Error::::NotAllowed)? } From c8fa5f8ecddaabc021c97fe56920f0e49f87201c Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Fri, 31 May 2024 09:13:24 +0200 Subject: [PATCH 34/48] Update substrate/frame/broker/src/types.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- substrate/frame/broker/src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index 297060a5c25b..dfab37bd415a 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -302,7 +302,7 @@ where pub struct AutoRenewalRecord { /// The core for which auto renewal is enabled. pub core: CoreIndex, - /// The task is assigned to the core. We keep track of it so we don't have to look it up when + /// The task assigned to the core. We keep track of it so we don't have to look it up when /// performing auto-renewal. pub task: TaskId, /// Lease-holding parachains can also enable auto-renewal. They will start renewing only at the From 7d887abee9a4695821a902b18d16e4586a0ed267 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Fri, 31 May 2024 09:13:43 +0200 Subject: [PATCH 35/48] Update substrate/frame/broker/src/lib.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- substrate/frame/broker/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 46eed378e9c6..e8ef730dd723 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -861,7 +861,7 @@ pub mod pallet { /// will be charged at the start of every bulk period for renewing core time. /// /// - `origin`: Must be the sovereign account of the task - /// - `core`: The core for which we want to enable auto renewal. + /// - `core`: The core to which the task to be renewed is currently assigned. /// - `task`: The task for which we want to enable auto renewal. /// - `workload_end_hint` parameter should be used when enabling auto-renewal for /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. From 78a203fea69523305af8b09661c5718bcd4eca1b Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 31 May 2024 09:17:36 +0200 Subject: [PATCH 36/48] resolve comments --- .../runtimes/coretime/coretime-rococo/src/coretime.rs | 2 +- .../runtimes/coretime/coretime-westend/src/coretime.rs | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/broker/src/migration.rs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 070521a76433..45156cd57ff7 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -248,6 +248,6 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type SovereignAccountOf = SovereignAccountOf; - type MaxAutoRenewals = ConstU32<50>; + type MaxAutoRenewals = ConstU32<100>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs index 2a57eb807d67..19795c458399 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/coretime.rs @@ -259,6 +259,6 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type SovereignAccountOf = SovereignAccountOf; - type MaxAutoRenewals = ConstU32<10>; + type MaxAutoRenewals = ConstU32<20>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 11c8ae4e1555..3ac6808e1516 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2156,7 +2156,7 @@ impl pallet_broker::Config for Runtime { type PalletId = BrokerPalletId; type AdminOrigin = EnsureRoot; type SovereignAccountOf = SovereignAccountOf; - type MaxAutoRenewals = ConstU32<5>; + type MaxAutoRenewals = ConstU32<10>; type PriceAdapter = pallet_broker::CenterTargetPrice; } diff --git a/substrate/frame/broker/src/migration.rs b/substrate/frame/broker/src/migration.rs index 1fd1675b078a..f354e447fe84 100644 --- a/substrate/frame/broker/src/migration.rs +++ b/substrate/frame/broker/src/migration.rs @@ -85,7 +85,7 @@ mod v2 { }; #[storage_alias] - pub type PotentialRenewals = StorageMap< + pub type AllowedRenewals = StorageMap< Pallet, Twox64Concat, PotentialRenewalId, @@ -98,7 +98,7 @@ mod v2 { impl UncheckedOnRuntimeUpgrade for MigrateToV2Impl { fn on_runtime_upgrade() -> frame_support::weights::Weight { let mut count = 0; - for (renewal_id, renewal) in PotentialRenewals::::drain() { + for (renewal_id, renewal) in AllowedRenewals::::drain() { PotentialRenewals::::insert(renewal_id, renewal); count += 1; } @@ -114,7 +114,7 @@ mod v2 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - Ok((PotentialRenewals::::iter_keys().count() as u32).encode()) + Ok((AllowedRenewals::::iter_keys().count() as u32).encode()) } #[cfg(feature = "try-runtime")] From 5f02e3266a15b7db6e0dd3c02cb39ff867bf40a8 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 31 May 2024 09:24:56 +0200 Subject: [PATCH 37/48] cleanup --- .../coretime/coretime-rococo/Cargo.toml | 1 - .../coretime/coretime-rococo/src/coretime.rs | 2 -- .../frame/broker/src/dispatchable_impls.rs | 21 ++++++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index c990f12f5ad5..ad85aab1f8ac 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -58,7 +58,6 @@ pallet-xcm = { path = "../../../../../polkadot/xcm/pallet-xcm", default-features pallet-xcm-benchmarks = { path = "../../../../../polkadot/xcm/pallet-xcm-benchmarks", default-features = false, optional = true } polkadot-parachain-primitives = { path = "../../../../../polkadot/parachain", default-features = false } polkadot-runtime-common = { path = "../../../../../polkadot/runtime/common", default-features = false } -polkadot-runtime-parachains = { path = "../../../../../polkadot/runtime/parachains", default-features = false } rococo-runtime-constants = { path = "../../../../../polkadot/runtime/rococo/constants", default-features = false } xcm = { package = "staging-xcm", path = "../../../../../polkadot/xcm", default-features = false } xcm-builder = { package = "staging-xcm-builder", path = "../../../../../polkadot/xcm/xcm-builder", default-features = false } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 45156cd57ff7..f8b3f5781b9c 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -221,8 +221,6 @@ impl CoretimeInterface for CoretimeAllocator { } } -impl origin::Config for Runtime {} - pub struct SovereignAccountOf; impl MaybeConvert for SovereignAccountOf { fn maybe_convert(id: TaskId) -> Option { diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 45e7c43af8ee..564fa2b862aa 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -484,23 +484,28 @@ impl Pallet { ) -> DispatchResult { let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - let _renewal_record = if let Some(workload_end) = workload_end_hint { - PotentialRenewals::::get(PotentialRenewalId { core, when: workload_end }) - .ok_or(Error::::NotAllowed)? + if let Some(workload_end) = workload_end_hint { + ensure!( + PotentialRenewals::::get(PotentialRenewalId { core, when: workload_end }) + .is_some(), + Error::::NotAllowed + ); } else { // If the core hasn't been renewed yet we will renew it now. - if let Some(record) = - PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) + if PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) + .is_some() { Self::do_renew(sovereign_account.clone(), core)?; - record } else { // If we couldn't find the renewal record for the current bulk period we should // be able to find it for the upcoming bulk period. // // If not the core is not eligible for renewal. - PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) - .ok_or(Error::::NotAllowed)? + ensure!( + PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) + .is_some(), + Error::::NotAllowed + ); } }; From b0aa9726df864df9551828782af19aa2a147d800 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 31 May 2024 09:32:33 +0200 Subject: [PATCH 38/48] rename --- Cargo.lock | 1 - .../frame/broker/src/dispatchable_impls.rs | 10 +++++-- substrate/frame/broker/src/tests.rs | 28 +++++++++---------- substrate/frame/broker/src/tick_impls.rs | 4 +-- substrate/frame/broker/src/types.rs | 6 ++-- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73765da3c2d5..781dba880cbe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3197,7 +3197,6 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-common", - "polkadot-runtime-parachains", "rococo-runtime-constants", "scale-info", "serde", diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 564fa2b862aa..e0e9465a5f8d 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -509,13 +509,19 @@ impl Pallet { } }; - let renewal_begin = workload_end_hint.unwrap_or(sale.region_end); // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals .binary_search_by(|r: &AutoRenewalRecord| r.core.cmp(&core)) .unwrap_or_else(|e| e); - renewals.try_insert(pos, AutoRenewalRecord { core, task, begin: renewal_begin }) + renewals.try_insert( + pos, + AutoRenewalRecord { + core, + task, + next_renewal: workload_end_hint.unwrap_or(sale.region_end), + }, + ) }) .map_err(|_| Error::::TooManyAutoRenewals)?; diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 55e5e3fcedf3..055b392b2071 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1512,7 +1512,7 @@ fn enable_auto_renew_works() { assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] + vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }] ); System::assert_has_event( Event::::AutoRenewalEnabled { core: region_id.core, task: 1001 }.into(), @@ -1529,9 +1529,9 @@ fn enable_auto_renew_works() { assert_eq!( AutoRenewals::::get().to_vec(), vec![ - AutoRenewalRecord { core: 0, task: 1001, begin: 7 }, - AutoRenewalRecord { core: 1, task: 1002, begin: 7 }, - AutoRenewalRecord { core: 2, task: 1003, begin: 7 }, + AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }, + AutoRenewalRecord { core: 1, task: 1002, next_renewal: 7 }, + AutoRenewalRecord { core: 2, task: 1003, next_renewal: 7 }, ] ); }); @@ -1551,8 +1551,8 @@ fn enable_auto_renewal_with_end_hint_works() { .unwrap(), ), }; - // Each lease-holding task should be allowed to auto renew. Although the `when` field will - // likely be set to a later timeslice. For this reason renewals will only begin later. + // For lease holding tasks, the renewal record is set for when the lease expires, which is + // likely further in the future than the start of the next sale. PotentialRenewals::::insert(PotentialRenewalId { core: 0, when: 10 }, &record); endow(1001, 1000); @@ -1564,7 +1564,7 @@ fn enable_auto_renewal_with_end_hint_works() { assert_ok!(Broker::do_enable_auto_renew(1001, 0, 1001, Some(10))); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 },] + vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 10 },] ); System::assert_has_event(Event::::AutoRenewalEnabled { core: 0, task: 1001 }.into()); @@ -1625,7 +1625,7 @@ fn enable_auto_renew_renews() { assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 0, task: 1001, begin: 10 }] + vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 10 }] ); assert!(PotentialRenewals::::get(PotentialRenewalId { core: region_id.core, @@ -1658,9 +1658,9 @@ fn auto_renewal_works() { assert_eq!( AutoRenewals::::get().to_vec(), vec![ - AutoRenewalRecord { core: 0, task: 1001, begin: 7 }, - AutoRenewalRecord { core: 1, task: 1002, begin: 7 }, - AutoRenewalRecord { core: 2, task: 1003, begin: 7 }, + AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }, + AutoRenewalRecord { core: 1, task: 1002, next_renewal: 7 }, + AutoRenewalRecord { core: 2, task: 1003, next_renewal: 7 }, ] ); @@ -1711,8 +1711,8 @@ fn auto_renewal_works() { assert_eq!( AutoRenewals::::get().to_vec(), vec![ - AutoRenewalRecord { core: 0, task: 1001, begin: 10 }, - AutoRenewalRecord { core: 1, task: 1003, begin: 10 }, + AutoRenewalRecord { core: 0, task: 1001, next_renewal: 10 }, + AutoRenewalRecord { core: 1, task: 1003, next_renewal: 10 }, ] ); }); @@ -1737,7 +1737,7 @@ fn disable_auto_renew_works() { assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); assert_eq!( AutoRenewals::::get().to_vec(), - vec![AutoRenewalRecord { core: 0, task: 1001, begin: 7 }] + vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }] ); // Only the sovereign account can disable: diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 7bea7e3e18ec..f7544fc80092 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -330,7 +330,7 @@ impl Pallet { let Ok(auto_renewals) = renewals .into_iter() .flat_map(|record| { - if sale.region_begin < record.begin { + if sale.region_begin < record.next_renewal { // We skip the renewal for this core. return Some(record) } @@ -347,7 +347,7 @@ impl Pallet { Some(AutoRenewalRecord { core: new_core_index, task: record.task, - begin: sale.region_end, + next_renewal: sale.region_end, }) } else { Self::deposit_event(Event::::AutoRenewalFailed { diff --git a/substrate/frame/broker/src/types.rs b/substrate/frame/broker/src/types.rs index dfab37bd415a..83da2b53e99d 100644 --- a/substrate/frame/broker/src/types.rs +++ b/substrate/frame/broker/src/types.rs @@ -305,7 +305,7 @@ pub struct AutoRenewalRecord { /// The task assigned to the core. We keep track of it so we don't have to look it up when /// performing auto-renewal. pub task: TaskId, - /// Lease-holding parachains can also enable auto-renewal. They will start renewing only at the - /// end of the lease. This specifies the beginning timeslice from which we auto-renew. - pub begin: Timeslice, + /// Specifies when the upcoming renewal should be performed. This is used for lease holding + /// tasks to ensure that the renewal process does not begin until the lease expires. + pub next_renewal: Timeslice, } From de89f30980d39a167f5241bea592e9fd41deae81 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 31 May 2024 09:37:38 +0200 Subject: [PATCH 39/48] comment --- substrate/frame/broker/src/tick_impls.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index f7544fc80092..b1720be413f6 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -330,8 +330,9 @@ impl Pallet { let Ok(auto_renewals) = renewals .into_iter() .flat_map(|record| { + // Check if the next renewal is scheduled further in the future than the start of + // the next region beginning. If so, we skip the renewal for this core. if sale.region_begin < record.next_renewal { - // We skip the renewal for this core. return Some(record) } From 7259f41db11dcead9c652f79fa9a47799bf32500 Mon Sep 17 00:00:00 2001 From: Sergej Date: Fri, 31 May 2024 10:00:33 +0200 Subject: [PATCH 40/48] fix benchmarks --- substrate/frame/broker/src/benchmarking.rs | 25 +- substrate/frame/broker/src/weights.rs | 294 ++++++++++----------- 2 files changed, 159 insertions(+), 160 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 02bd7839c99a..3190884aba16 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -31,7 +31,10 @@ use frame_support::{ use frame_system::{Pallet as System, RawOrigin}; use sp_arithmetic::{traits::Zero, Perbill}; use sp_core::Get; -use sp_runtime::{traits::BlockNumberProvider, SaturatedConversion, Saturating}; +use sp_runtime::{ + traits::{BlockNumberProvider, MaybeConvert}, + SaturatedConversion, Saturating, +}; use sp_std::{vec, vec::Vec}; const SEED: u32 = 0; @@ -812,7 +815,7 @@ mod benches { // Assume max auto renewals for worst case. (0..T::MaxAutoRenewals::get()).try_for_each(|indx| -> Result<(), BenchmarkError> { let task = 1000 + indx; - let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(task) + let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(task) .expect("Failed to get sovereign account"); T::Currency::set_balance( &caller.clone(), @@ -825,7 +828,7 @@ mod benches { Broker::::do_assign(region, None, task, Final) .map_err(|_| BenchmarkError::Weightless)?; - Broker::::do_enable_auto_renew(task, region.core, None)?; + Broker::::do_enable_auto_renew(caller, region.core, task, None)?; Ok(()) })?; @@ -857,7 +860,7 @@ mod benches { // Make sure all cores got renewed: (0..T::MaxAutoRenewals::get()).for_each(|indx| { let task = 1000 + indx; - let who = T::SovereignAccountOf::sovereign_account(task) + let who = T::SovereignAccountOf::maybe_convert(task) .expect("Failed to get sovereign account"); assert_has_event::( Event::Renewed { @@ -994,8 +997,8 @@ mod benches { advance_to::(2); - let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(2001) - .expect("Failed to get sovereign account"); + let caller: T::AccountId = + T::SovereignAccountOf::maybe_convert(2001).expect("Failed to get sovereign account"); T::Currency::set_balance( &caller.clone(), T::Currency::minimum_balance().saturating_add(100u32.into()), @@ -1012,7 +1015,7 @@ mod benches { // The most 'intensive' path is when we renew the core upon enabling auto-renewal. #[extrinsic_call] - _(RawOrigin::Signed(caller), region.core, None); + _(RawOrigin::Signed(caller), region.core, 2001, None); assert_last_event::(Event::AutoRenewalEnabled { core: region.core, task: 2001 }.into()); // Make sure we indeed renewed: @@ -1031,8 +1034,8 @@ mod benches { advance_to::(2); - let caller: T::AccountId = T::SovereignAccountOf::sovereign_account(2001) - .expect("Failed to get sovereign account"); + let caller: T::AccountId = + T::SovereignAccountOf::maybe_convert(2001).expect("Failed to get sovereign account"); T::Currency::set_balance( &caller.clone(), T::Currency::minimum_balance().saturating_add(100u32.into()), @@ -1044,10 +1047,10 @@ mod benches { Broker::::do_assign(region, None, 2001, Final) .map_err(|_| BenchmarkError::Weightless)?; - Broker::::do_enable_auto_renew(2001, region.core, None)?; + Broker::::do_enable_auto_renew(caller.clone(), region.core, 2001, None)?; #[extrinsic_call] - _(RawOrigin::Signed(caller), region.core); + _(RawOrigin::Signed(caller), region.core, 2001); assert_last_event::(Event::AutoRenewalDisabled { core: region.core, task: 2001 }.into()); diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index 81342e8536c1..673cc78ebbd5 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_broker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-05-23, 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: `sergej-B650-AORUS-ELITE-AX`, CPU: `AMD Ryzen 9 7900X3D 12-Core Processor` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` @@ -92,8 +92,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_824_000 picoseconds. - Weight::from_parts(1_894_000, 0) + // Minimum execution time: 1_593_000 picoseconds. + Weight::from_parts(1_703_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -102,8 +102,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 12_714_000 picoseconds. - Weight::from_parts(13_085_000, 7496) + // Minimum execution time: 12_864_000 picoseconds. + Weight::from_parts(13_174_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -113,8 +113,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 11_783_000 picoseconds. - Weight::from_parts(12_294_000, 7496) + // Minimum execution time: 12_284_000 picoseconds. + Weight::from_parts(13_566_000, 7496) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -124,8 +124,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 7_104_000 picoseconds. - Weight::from_parts(7_354_000, 1526) + // Minimum execution time: 6_743_000 picoseconds. + Weight::from_parts(7_094_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -138,7 +138,7 @@ impl WeightInfo for SubstrateWeight { /// Storage: `Broker::InstaPoolIo` (r:3 w:3) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, 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) @@ -150,10 +150,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 21_611_000 picoseconds. - Weight::from_parts(40_010_482, 8499) - // Standard Error: 404 - .saturating_add(Weight::from_parts(2_591, 0).saturating_mul(n.into())) + // Minimum execution time: 21_120_000 picoseconds. + Weight::from_parts(40_929_422, 8499) + // Standard Error: 471 + .saturating_add(Weight::from_parts(1_004, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(16_u64)) } @@ -169,10 +169,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn purchase() -> Weight { // Proof Size summary in bytes: - // Measured: `635` - // Estimated: `2120` - // Minimum execution time: 30_939_000 picoseconds. - Weight::from_parts(31_540_000, 2120) + // Measured: `651` + // Estimated: `2136` + // Minimum execution time: 31_169_000 picoseconds. + Weight::from_parts(32_271_000, 2136) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -192,10 +192,10 @@ impl WeightInfo for SubstrateWeight { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `753` + // Measured: `769` // Estimated: `4698` - // Minimum execution time: 43_492_000 picoseconds. - Weight::from_parts(44_284_000, 4698) + // Minimum execution time: 44_945_000 picoseconds. + Weight::from_parts(47_119_000, 4698) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } @@ -205,8 +205,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 11_341_000 picoseconds. - Weight::from_parts(12_013_000, 3551) + // Minimum execution time: 11_562_000 picoseconds. + Weight::from_parts(11_943_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -216,8 +216,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 12_594_000 picoseconds. - Weight::from_parts(13_295_000, 3551) + // Minimum execution time: 13_075_000 picoseconds. + Weight::from_parts(13_616_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -227,8 +227,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 13_556_000 picoseconds. - Weight::from_parts(13_916_000, 3551) + // Minimum execution time: 13_695_000 picoseconds. + Weight::from_parts(14_658_000, 3551) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -244,8 +244,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 22_142_000 picoseconds. - Weight::from_parts(23_204_000, 4681) + // Minimum execution time: 22_623_000 picoseconds. + Weight::from_parts(23_233_000, 4681) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -263,8 +263,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 26_320_000 picoseconds. - Weight::from_parts(27_813_000, 5996) + // Minimum execution time: 26_901_000 picoseconds. + Weight::from_parts(27_472_000, 5996) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -279,10 +279,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 50_726_000 picoseconds. - Weight::from_parts(53_226_499, 6196) - // Standard Error: 74_118 - .saturating_add(Weight::from_parts(672_768, 0).saturating_mul(m.into())) + // Minimum execution time: 51_778_000 picoseconds. + Weight::from_parts(53_726_731, 6196) + // Standard Error: 45_279 + .saturating_add(Weight::from_parts(677_769, 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)) @@ -294,8 +294,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 33_404_000 picoseconds. - Weight::from_parts(34_125_000, 3593) + // Minimum execution time: 31_790_000 picoseconds. + Weight::from_parts(32_601_000, 3593) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -307,8 +307,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 17_994_000 picoseconds. - Weight::from_parts(18_635_000, 3551) + // Minimum execution time: 18_465_000 picoseconds. + Weight::from_parts(21_050_000, 3551) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -322,8 +322,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 22_312_000 picoseconds. - Weight::from_parts(25_118_000, 3533) + // Minimum execution time: 23_825_000 picoseconds. + Weight::from_parts(26_250_000, 3533) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -339,8 +339,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 29_637_000 picoseconds. - Weight::from_parts(30_528_000, 3593) + // Minimum execution time: 28_103_000 picoseconds. + Weight::from_parts(32_622_000, 3593) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -352,20 +352,18 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 18_184_000 picoseconds. - Weight::from_parts(21_201_000, 4698) + // Minimum execution time: 16_751_000 picoseconds. + Weight::from_parts(17_373_000, 4698) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// 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: `0` // Estimated: `0` - // Minimum execution time: 3_036_000 picoseconds. - Weight::from_parts(3_417_250, 0) - // Standard Error: 91 - .saturating_add(Weight::from_parts(106, 0).saturating_mul(n.into())) + // Minimum execution time: 2_705_000 picoseconds. + Weight::from_parts(2_991_768, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -374,8 +372,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 4_879_000 picoseconds. - Weight::from_parts(5_413_035, 1487) + // Minimum execution time: 4_598_000 picoseconds. + Weight::from_parts(4_937_302, 1487) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -393,8 +391,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `991` // Estimated: `4456` - // Minimum execution time: 37_982_000 picoseconds. - Weight::from_parts(38_703_000, 4456) + // Minimum execution time: 37_601_000 picoseconds. + Weight::from_parts(38_262_000, 4456) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -414,8 +412,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 5_520_000 picoseconds. - Weight::from_parts(5_720_000, 3493) + // Minimum execution time: 5_391_000 picoseconds. + Weight::from_parts(5_630_000, 3493) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -427,8 +425,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 10_850_000 picoseconds. - Weight::from_parts(11_091_000, 4681) + // Minimum execution time: 10_249_000 picoseconds. + Weight::from_parts(10_529_000, 4681) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -436,8 +434,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 111_000 picoseconds. - Weight::from_parts(131_000, 0) + // Minimum execution time: 120_000 picoseconds. + Weight::from_parts(140_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -445,8 +443,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_553_000 picoseconds. - Weight::from_parts(1_683_000, 0) + // Minimum execution time: 1_402_000 picoseconds. + Weight::from_parts(1_513_000, 0) .saturating_add(T::DbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -461,8 +459,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 9_619_000 picoseconds. - Weight::from_parts(9_929_000, 4068) + // Minimum execution time: 8_897_000 picoseconds. + Weight::from_parts(9_218_000, 4068) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -472,8 +470,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_029_000 picoseconds. - Weight::from_parts(5_220_000, 1526) + // Minimum execution time: 4_678_000 picoseconds. + Weight::from_parts(4_920_000, 1526) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -492,26 +490,26 @@ impl WeightInfo for SubstrateWeight { /// Storage: `System::Digest` (r:1 w:0) /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:0 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn enable_auto_renew() -> Weight { // Proof Size summary in bytes: - // Measured: `914` + // Measured: `930` // Estimated: `4698` - // Minimum execution time: 51_938_000 picoseconds. - Weight::from_parts(55_025_000, 4698) + // Minimum execution time: 51_597_000 picoseconds. + Weight::from_parts(52_609_000, 4698) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(6_u64)) } /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, mode: `MaxEncodedLen`) fn disable_auto_renew() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `1516` - // Minimum execution time: 9_628_000 picoseconds. - Weight::from_parts(10_400_000, 1516) + // Measured: `484` + // Estimated: `1586` + // Minimum execution time: 8_907_000 picoseconds. + Weight::from_parts(9_167_000, 1586) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -525,8 +523,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_824_000 picoseconds. - Weight::from_parts(1_894_000, 0) + // Minimum execution time: 1_593_000 picoseconds. + Weight::from_parts(1_703_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Reservations` (r:1 w:1) @@ -535,8 +533,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `5016` // Estimated: `7496` - // Minimum execution time: 12_714_000 picoseconds. - Weight::from_parts(13_085_000, 7496) + // Minimum execution time: 12_864_000 picoseconds. + Weight::from_parts(13_174_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -546,8 +544,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6218` // Estimated: `7496` - // Minimum execution time: 11_783_000 picoseconds. - Weight::from_parts(12_294_000, 7496) + // Minimum execution time: 12_284_000 picoseconds. + Weight::from_parts(13_566_000, 7496) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -557,8 +555,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 7_104_000 picoseconds. - Weight::from_parts(7_354_000, 1526) + // Minimum execution time: 6_743_000 picoseconds. + Weight::from_parts(7_094_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -571,7 +569,7 @@ impl WeightInfo for () { /// Storage: `Broker::InstaPoolIo` (r:3 w:3) /// Proof: `Broker::InstaPoolIo` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, 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) @@ -583,10 +581,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `6330` // Estimated: `8499` - // Minimum execution time: 21_611_000 picoseconds. - Weight::from_parts(40_010_482, 8499) - // Standard Error: 404 - .saturating_add(Weight::from_parts(2_591, 0).saturating_mul(n.into())) + // Minimum execution time: 21_120_000 picoseconds. + Weight::from_parts(40_929_422, 8499) + // Standard Error: 471 + .saturating_add(Weight::from_parts(1_004, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(16_u64)) } @@ -602,10 +600,10 @@ impl WeightInfo for () { /// Proof: `Broker::Regions` (`max_values`: None, `max_size`: Some(86), added: 2561, mode: `MaxEncodedLen`) fn purchase() -> Weight { // Proof Size summary in bytes: - // Measured: `635` - // Estimated: `2120` - // Minimum execution time: 30_939_000 picoseconds. - Weight::from_parts(31_540_000, 2120) + // Measured: `651` + // Estimated: `2136` + // Minimum execution time: 31_169_000 picoseconds. + Weight::from_parts(32_271_000, 2136) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -625,10 +623,10 @@ impl WeightInfo for () { /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn renew() -> Weight { // Proof Size summary in bytes: - // Measured: `753` + // Measured: `769` // Estimated: `4698` - // Minimum execution time: 43_492_000 picoseconds. - Weight::from_parts(44_284_000, 4698) + // Minimum execution time: 44_945_000 picoseconds. + Weight::from_parts(47_119_000, 4698) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } @@ -638,8 +636,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 11_341_000 picoseconds. - Weight::from_parts(12_013_000, 3551) + // Minimum execution time: 11_562_000 picoseconds. + Weight::from_parts(11_943_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -649,8 +647,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 12_594_000 picoseconds. - Weight::from_parts(13_295_000, 3551) + // Minimum execution time: 13_075_000 picoseconds. + Weight::from_parts(13_616_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -660,8 +658,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `496` // Estimated: `3551` - // Minimum execution time: 13_556_000 picoseconds. - Weight::from_parts(13_916_000, 3551) + // Minimum execution time: 13_695_000 picoseconds. + Weight::from_parts(14_658_000, 3551) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -677,8 +675,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `741` // Estimated: `4681` - // Minimum execution time: 22_142_000 picoseconds. - Weight::from_parts(23_204_000, 4681) + // Minimum execution time: 22_623_000 picoseconds. + Weight::from_parts(23_233_000, 4681) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -696,8 +694,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `776` // Estimated: `5996` - // Minimum execution time: 26_320_000 picoseconds. - Weight::from_parts(27_813_000, 5996) + // Minimum execution time: 26_901_000 picoseconds. + Weight::from_parts(27_472_000, 5996) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -712,10 +710,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `878` // Estimated: `6196 + m * (2520 ±0)` - // Minimum execution time: 50_726_000 picoseconds. - Weight::from_parts(53_226_499, 6196) - // Standard Error: 74_118 - .saturating_add(Weight::from_parts(672_768, 0).saturating_mul(m.into())) + // Minimum execution time: 51_778_000 picoseconds. + Weight::from_parts(53_726_731, 6196) + // Standard Error: 45_279 + .saturating_add(Weight::from_parts(677_769, 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)) @@ -727,8 +725,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `103` // Estimated: `3593` - // Minimum execution time: 33_404_000 picoseconds. - Weight::from_parts(34_125_000, 3593) + // Minimum execution time: 31_790_000 picoseconds. + Weight::from_parts(32_601_000, 3593) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -740,8 +738,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `604` // Estimated: `3551` - // Minimum execution time: 17_994_000 picoseconds. - Weight::from_parts(18_635_000, 3551) + // Minimum execution time: 18_465_000 picoseconds. + Weight::from_parts(21_050_000, 3551) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -755,8 +753,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `601` // Estimated: `3533` - // Minimum execution time: 22_312_000 picoseconds. - Weight::from_parts(25_118_000, 3533) + // Minimum execution time: 23_825_000 picoseconds. + Weight::from_parts(26_250_000, 3533) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -772,8 +770,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1014` // Estimated: `3593` - // Minimum execution time: 29_637_000 picoseconds. - Weight::from_parts(30_528_000, 3593) + // Minimum execution time: 28_103_000 picoseconds. + Weight::from_parts(32_622_000, 3593) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -785,20 +783,18 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `661` // Estimated: `4698` - // Minimum execution time: 18_184_000 picoseconds. - Weight::from_parts(21_201_000, 4698) + // Minimum execution time: 16_751_000 picoseconds. + Weight::from_parts(17_373_000, 4698) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// 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: `0` // Estimated: `0` - // Minimum execution time: 3_036_000 picoseconds. - Weight::from_parts(3_417_250, 0) - // Standard Error: 91 - .saturating_add(Weight::from_parts(106, 0).saturating_mul(n.into())) + // Minimum execution time: 2_705_000 picoseconds. + Weight::from_parts(2_991_768, 0) } /// Storage: `Broker::CoreCountInbox` (r:1 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -807,8 +803,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `404` // Estimated: `1487` - // Minimum execution time: 4_879_000 picoseconds. - Weight::from_parts(5_413_035, 1487) + // Minimum execution time: 4_598_000 picoseconds. + Weight::from_parts(4_937_302, 1487) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -826,8 +822,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `991` // Estimated: `4456` - // Minimum execution time: 37_982_000 picoseconds. - Weight::from_parts(38_703_000, 4456) + // Minimum execution time: 37_601_000 picoseconds. + Weight::from_parts(38_262_000, 4456) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -847,8 +843,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `180` // Estimated: `3493` - // Minimum execution time: 5_520_000 picoseconds. - Weight::from_parts(5_720_000, 3493) + // Minimum execution time: 5_391_000 picoseconds. + Weight::from_parts(5_630_000, 3493) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -860,8 +856,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `1423` // Estimated: `4681` - // Minimum execution time: 10_850_000 picoseconds. - Weight::from_parts(11_091_000, 4681) + // Minimum execution time: 10_249_000 picoseconds. + Weight::from_parts(10_529_000, 4681) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -869,8 +865,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 111_000 picoseconds. - Weight::from_parts(131_000, 0) + // Minimum execution time: 120_000 picoseconds. + Weight::from_parts(140_000, 0) } /// Storage: `Broker::CoreCountInbox` (r:0 w:1) /// Proof: `Broker::CoreCountInbox` (`max_values`: Some(1), `max_size`: Some(2), added: 497, mode: `MaxEncodedLen`) @@ -878,8 +874,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_553_000 picoseconds. - Weight::from_parts(1_683_000, 0) + // Minimum execution time: 1_402_000 picoseconds. + Weight::from_parts(1_513_000, 0) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `Broker::Status` (r:1 w:1) @@ -894,8 +890,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `603` // Estimated: `4068` - // Minimum execution time: 9_619_000 picoseconds. - Weight::from_parts(9_929_000, 4068) + // Minimum execution time: 8_897_000 picoseconds. + Weight::from_parts(9_218_000, 4068) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -905,8 +901,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `239` // Estimated: `1526` - // Minimum execution time: 5_029_000 picoseconds. - Weight::from_parts(5_220_000, 1526) + // Minimum execution time: 4_678_000 picoseconds. + Weight::from_parts(4_920_000, 1526) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -925,26 +921,26 @@ impl WeightInfo for () { /// Storage: `System::Digest` (r:1 w:0) /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, mode: `MaxEncodedLen`) /// Storage: `Broker::Workplan` (r:0 w:1) /// Proof: `Broker::Workplan` (`max_values`: None, `max_size`: Some(1216), added: 3691, mode: `MaxEncodedLen`) fn enable_auto_renew() -> Weight { // Proof Size summary in bytes: - // Measured: `914` + // Measured: `930` // Estimated: `4698` - // Minimum execution time: 51_938_000 picoseconds. - Weight::from_parts(55_025_000, 4698) + // Minimum execution time: 51_597_000 picoseconds. + Weight::from_parts(52_609_000, 4698) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: `Broker::AutoRenewals` (r:1 w:1) - /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(31), added: 526, mode: `MaxEncodedLen`) + /// Proof: `Broker::AutoRenewals` (`max_values`: Some(1), `max_size`: Some(101), added: 596, mode: `MaxEncodedLen`) fn disable_auto_renew() -> Weight { // Proof Size summary in bytes: - // Measured: `480` - // Estimated: `1516` - // Minimum execution time: 9_628_000 picoseconds. - Weight::from_parts(10_400_000, 1516) + // Measured: `484` + // Estimated: `1586` + // Minimum execution time: 8_907_000 picoseconds. + Weight::from_parts(9_167_000, 1586) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } From 9a23b2fb2503e4883f28fba59a4abd886c4ba66e Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 3 Jun 2024 18:24:08 +0200 Subject: [PATCH 41/48] cleanup --- .../frame/broker/src/dispatchable_impls.rs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index e0e9465a5f8d..c9f89990d681 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -484,29 +484,28 @@ impl Pallet { ) -> DispatchResult { let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; - if let Some(workload_end) = workload_end_hint { + if PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) + .is_some() + { + // If the core expires in the upcoming bulk period we will renew it now. + Self::do_renew(sovereign_account.clone(), core)?; + } else if let Some(workload_end) = workload_end_hint { ensure!( PotentialRenewals::::get(PotentialRenewalId { core, when: workload_end }) .is_some(), Error::::NotAllowed ); } else { - // If the core hasn't been renewed yet we will renew it now. - if PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) - .is_some() - { - Self::do_renew(sovereign_account.clone(), core)?; - } else { - // If we couldn't find the renewal record for the current bulk period we should - // be able to find it for the upcoming bulk period. - // - // If not the core is not eligible for renewal. - ensure!( - PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) - .is_some(), - Error::::NotAllowed - ); - } + // If the user didn't provide a valid workload end hint and we couldn't find the renewal + // record for the current bulk period we should be able to find it for the upcoming bulk + // period. + // + // If not the core is not eligible for auto-renewal. + ensure!( + PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) + .is_some(), + Error::::NotAllowed + ); }; // We are keeping the auto-renewals sorted by `CoreIndex`. From 0c4e651088c8f0851118a499b06fd18bdf03c3de Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 3 Jun 2024 18:37:37 +0200 Subject: [PATCH 42/48] simplify logic --- substrate/frame/broker/src/benchmarking.rs | 1 + .../frame/broker/src/dispatchable_impls.rs | 13 ++-------- substrate/frame/broker/src/tests.rs | 25 +++++++++++-------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 3190884aba16..4e3afd0b7591 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -1047,6 +1047,7 @@ mod benches { Broker::::do_assign(region, None, 2001, Final) .map_err(|_| BenchmarkError::Weightless)?; + advance_to::(6); Broker::::do_enable_auto_renew(caller.clone(), region.core, 2001, None)?; #[extrinsic_call] diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index c9f89990d681..0eb651c60678 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -496,17 +496,8 @@ impl Pallet { Error::::NotAllowed ); } else { - // If the user didn't provide a valid workload end hint and we couldn't find the renewal - // record for the current bulk period we should be able to find it for the upcoming bulk - // period. - // - // If not the core is not eligible for auto-renewal. - ensure!( - PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_end }) - .is_some(), - Error::::NotAllowed - ); - }; + return Err(Error::::NotAllowed.into()) + } // We are keeping the auto-renewals sorted by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 055b392b2071..7b084ba531ca 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1490,7 +1490,7 @@ fn enable_auto_renew_works() { // Cannot enable auto renewal with provisional finality: assert_ok!(Broker::do_assign(region_id, Some(1), 1001, Provisional)); assert_noop!( - Broker::do_enable_auto_renew(1001, region_id.core, 1001, None), + Broker::do_enable_auto_renew(1001, region_id.core, 1001, Some(7)), Error::::NotAllowed ); @@ -1504,12 +1504,12 @@ fn enable_auto_renew_works() { // Only the task's sovereign account can enable auto renewal. assert_noop!( - Broker::enable_auto_renew(RuntimeOrigin::signed(1), region_id.core, 1001, None), + Broker::enable_auto_renew(RuntimeOrigin::signed(1), region_id.core, 1001, Some(7)), Error::::NoPermission ); // Works when calling with the sovereign account: - assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, Some(7))); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }] @@ -1523,8 +1523,8 @@ fn enable_auto_renew_works() { let region_3 = Broker::do_purchase(1, u64::max_value()).unwrap(); assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); - assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, None)); - assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, None)); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, Some(7))); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, Some(7))); assert_eq!( AutoRenewals::::get().to_vec(), @@ -1538,8 +1538,11 @@ fn enable_auto_renew_works() { } #[test] -fn enable_auto_renewal_with_end_hint_works() { +fn enable_auto_renewal_works_for_legacy_leases() { TestExt::new().endow(1, 1000).execute_with(|| { + // With this test, we ensure that we don't renew unnecessarily if the task has Coretime + // reserved (due to having a lease) + assert_ok!(Broker::do_start_sales(100, 1)); advance_to(2); @@ -1558,7 +1561,7 @@ fn enable_auto_renewal_with_end_hint_works() { endow(1001, 1000); // Will fail if we don't provide the end hint since it expects renewal record to be at next - // sale start or end. + // sale start. assert_noop!(Broker::do_enable_auto_renew(1001, 0, 1001, None), Error::::NotAllowed); assert_ok!(Broker::do_enable_auto_renew(1001, 0, 1001, Some(10))); @@ -1652,9 +1655,9 @@ fn auto_renewal_works() { assert_ok!(Broker::do_assign(region_1, Some(1), 1001, Final)); assert_ok!(Broker::do_assign(region_2, Some(1), 1002, Final)); assert_ok!(Broker::do_assign(region_3, Some(1), 1003, Final)); - assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, 1001, None)); - assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, None)); - assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_1.core, 1001, Some(7))); + assert_ok!(Broker::do_enable_auto_renew(1002, region_2.core, 1002, Some(7))); + assert_ok!(Broker::do_enable_auto_renew(1003, region_3.core, 1003, Some(7))); assert_eq!( AutoRenewals::::get().to_vec(), vec![ @@ -1734,7 +1737,7 @@ fn disable_auto_renew_works() { Error::::AutoRenewalNotEnabled ); - assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, None)); + assert_ok!(Broker::do_enable_auto_renew(1001, region_id.core, 1001, Some(7))); assert_eq!( AutoRenewals::::get().to_vec(), vec![AutoRenewalRecord { core: 0, task: 1001, next_renewal: 7 }] From ef9c4fbe8be47b84e6fd1c50014332ebada57ffc Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 1 Jul 2024 10:53:16 +0200 Subject: [PATCH 43/48] fix benchmarks --- substrate/frame/broker/src/benchmarking.rs | 62 ++++++++++++++++------ substrate/frame/broker/src/mock.rs | 2 +- substrate/frame/broker/src/tests.rs | 12 ++++- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 4e3afd0b7591..b0c5a52838ee 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -997,6 +997,27 @@ mod benches { advance_to::(2); + // We assume max auto renewals for worst case. + (0..T::MaxAutoRenewals::get()-1).try_for_each(|indx| -> Result<(), BenchmarkError> { + let task = 1000 + indx; + let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(task) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); + + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_assign(region, None, task, Final) + .map_err(|_| BenchmarkError::Weightless)?; + + Broker::::do_enable_auto_renew(caller, region.core, task, Some(7))?; + + Ok(()) + })?; + let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(2001).expect("Failed to get sovereign account"); T::Currency::set_balance( @@ -1004,15 +1025,15 @@ mod benches { T::Currency::minimum_balance().saturating_add(100u32.into()), ); + // The region for which we benchmark enable auto renew. let region = Broker::::do_purchase(caller.clone(), 10u32.into()) .map_err(|_| BenchmarkError::Weightless)?; - Broker::::do_assign(region, None, 2001, Final) .map_err(|_| BenchmarkError::Weightless)?; - // advance to next bulk sale: - advance_to::(6); // The most 'intensive' path is when we renew the core upon enabling auto-renewal. + // Therefore, we advance to next bulk sale: + advance_to::(6); #[extrinsic_call] _(RawOrigin::Signed(caller), region.core, 2001, None); @@ -1034,26 +1055,33 @@ mod benches { advance_to::(2); - let caller: T::AccountId = - T::SovereignAccountOf::maybe_convert(2001).expect("Failed to get sovereign account"); - T::Currency::set_balance( - &caller.clone(), - T::Currency::minimum_balance().saturating_add(100u32.into()), - ); + // We assume max auto renewals for worst case. + (0..T::MaxAutoRenewals::get()-1).try_for_each(|indx| -> Result<(), BenchmarkError> { + let task = 1000 + indx; + let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(task) + .expect("Failed to get sovereign account"); + T::Currency::set_balance( + &caller.clone(), + T::Currency::minimum_balance().saturating_add(100u32.into()), + ); - let region = Broker::::do_purchase(caller.clone(), 10u32.into()) - .map_err(|_| BenchmarkError::Weightless)?; + let region = Broker::::do_purchase(caller.clone(), 10u32.into()) + .map_err(|_| BenchmarkError::Weightless)?; - Broker::::do_assign(region, None, 2001, Final) - .map_err(|_| BenchmarkError::Weightless)?; + Broker::::do_assign(region, None, task, Final) + .map_err(|_| BenchmarkError::Weightless)?; - advance_to::(6); - Broker::::do_enable_auto_renew(caller.clone(), region.core, 2001, None)?; + Broker::::do_enable_auto_renew(caller, region.core, task, Some(7))?; + + Ok(()) + })?; + let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(1000) + .expect("Failed to get sovereign account"); #[extrinsic_call] - _(RawOrigin::Signed(caller), region.core, 2001); + _(RawOrigin::Signed(caller), _core, 1000); - assert_last_event::(Event::AutoRenewalDisabled { core: region.core, task: 2001 }.into()); + assert_last_event::(Event::AutoRenewalDisabled { core: _core, task: 1000 }.into()); Ok(()) } diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index fdc4df38d4c1..6cea8d487b78 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -208,7 +208,7 @@ impl crate::Config for Test { type PalletId = TestBrokerId; type AdminOrigin = EnsureOneOrRoot; type SovereignAccountOf = SovereignAccountOf; - type MaxAutoRenewals = ConstU32<5>; + type MaxAutoRenewals = ConstU32<3>; type PriceAdapter = CenterTargetPrice>; } diff --git a/substrate/frame/broker/src/tests.rs b/substrate/frame/broker/src/tests.rs index 7b084ba531ca..c815426d3f16 100644 --- a/substrate/frame/broker/src/tests.rs +++ b/substrate/frame/broker/src/tests.rs @@ -1482,7 +1482,7 @@ fn renewal_works_leases_ended_before_start_sales() { #[test] fn enable_auto_renew_works() { TestExt::new().endow(1, 1000).limit_cores_offered(Some(10)).execute_with(|| { - assert_ok!(Broker::do_start_sales(100, 3)); + assert_ok!(Broker::do_start_sales(100, 5)); advance_to(2); let region_id = Broker::do_purchase(1, u64::max_value()).unwrap(); let record = Regions::::get(region_id).unwrap(); @@ -1534,6 +1534,16 @@ fn enable_auto_renew_works() { AutoRenewalRecord { core: 2, task: 1003, next_renewal: 7 }, ] ); + + // Ensure that we cannot enable more auto renewals than `MaxAutoRenewals`. + // We already enabled it for three cores, and the limit is set to 3. + let region_4 = Broker::do_purchase(1, u64::max_value()).unwrap(); + assert_ok!(Broker::do_assign(region_4, Some(1), 1004, Final)); + + assert_noop!( + Broker::do_enable_auto_renew(1004, region_4.core, 1004, Some(7)), + Error::::TooManyAutoRenewals + ); }); } From 15d9e1b6c0aff5bd535d57c9b7ef15296014240f Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 1 Jul 2024 11:08:51 +0200 Subject: [PATCH 44/48] merge fixes --- .../coretime/coretime-rococo/src/coretime.rs | 4 ++- substrate/frame/broker/src/benchmarking.rs | 10 +++--- substrate/frame/broker/src/lib.rs | 30 ++++++++-------- substrate/frame/broker/src/weights.rs | 36 +++++++++++++++++++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs index 68bf8d522fcc..76ee06a87e8d 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/coretime.rs @@ -27,7 +27,9 @@ use frame_support::{ }, }; use frame_system::Pallet as System; -use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId}; +use pallet_broker::{ + CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600, RCBlockNumberOf, TaskId, +}; use parachains_common::{AccountId, Balance}; use rococo_runtime_constants::system_parachain::coretime; use sp_runtime::traits::{AccountIdConversion, MaybeConvert}; diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index f920338d8c38..d13a12bb0cda 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -1019,7 +1019,7 @@ mod benches { advance_to::(2); // We assume max auto renewals for worst case. - (0..T::MaxAutoRenewals::get()-1).try_for_each(|indx| -> Result<(), BenchmarkError> { + (0..T::MaxAutoRenewals::get() - 1).try_for_each(|indx| -> Result<(), BenchmarkError> { let task = 1000 + indx; let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(task) .expect("Failed to get sovereign account"); @@ -1077,7 +1077,7 @@ mod benches { advance_to::(2); // We assume max auto renewals for worst case. - (0..T::MaxAutoRenewals::get()-1).try_for_each(|indx| -> Result<(), BenchmarkError> { + (0..T::MaxAutoRenewals::get() - 1).try_for_each(|indx| -> Result<(), BenchmarkError> { let task = 1000 + indx; let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(task) .expect("Failed to get sovereign account"); @@ -1097,14 +1097,14 @@ mod benches { Ok(()) })?; - let caller: T::AccountId = T::SovereignAccountOf::maybe_convert(1000) - .expect("Failed to get sovereign account"); + let caller: T::AccountId = + T::SovereignAccountOf::maybe_convert(1000).expect("Failed to get sovereign account"); #[extrinsic_call] _(RawOrigin::Signed(caller), _core, 1000); assert_last_event::(Event::AutoRenewalDisabled { core: _core, task: 1000 }.into()); - Ok(()) + Ok(()) } fn on_new_timeslice() -> Result<(), BenchmarkError> { diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 30e96d03b142..d93742fc24cc 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -873,6 +873,17 @@ pub mod pallet { Ok(()) } + #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::notify_revenue())] + pub fn notify_revenue( + origin: OriginFor, + revenue: OnDemandRevenueRecordOf, + ) -> DispatchResult { + T::AdminOrigin::ensure_origin_or_root(origin)?; + Self::do_notify_revenue(revenue)?; + Ok(()) + } + /// Extrinsic for enabling auto renewal. /// /// Callable by the sovereign account of the task on the specified core. This account @@ -883,8 +894,8 @@ pub mod pallet { /// - `task`: The task for which we want to enable auto renewal. /// - `workload_end_hint` parameter should be used when enabling auto-renewal for /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. - #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::notify_core_count())] + #[pallet::call_index(21)] + #[pallet::weight(T::WeightInfo::enable_auto_renew())] pub fn enable_auto_renew( origin: OriginFor, core: CoreIndex, @@ -909,8 +920,8 @@ pub mod pallet { /// - `origin`: Must be the sovereign account of the task. /// - `core`: The core for which we want to disable auto renewal. /// - `task`: The task for which we want to disable auto renewal. - #[pallet::call_index(21)] - #[pallet::weight(T::WeightInfo::notify_core_count())] + #[pallet::call_index(22)] + #[pallet::weight(T::WeightInfo::disable_auto_renew())] pub fn disable_auto_renew( origin: OriginFor, core: CoreIndex, @@ -925,17 +936,6 @@ pub mod pallet { Self::do_disable_auto_renew(core, task)?; - Ok(()) - } - - #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::notify_revenue())] - pub fn notify_revenue( - origin: OriginFor, - revenue: OnDemandRevenueRecordOf, - ) -> DispatchResult { - T::AdminOrigin::ensure_origin_or_root(origin)?; - Self::do_notify_revenue(revenue)?; Ok(()) } diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index d2056e4560cd..2f25fddc2050 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -77,8 +77,10 @@ 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; + fn on_new_timeslice() -> Weight; fn enable_auto_renew() -> Weight; fn disable_auto_renew() -> Weight; } @@ -447,6 +449,16 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(1_513_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_902_000 picoseconds. + Weight::from_parts(2_116_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } /// 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) @@ -475,6 +487,13 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + fn on_new_timeslice() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 229_000 picoseconds. + Weight::from_parts(268_000, 0) + } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) /// Storage: `Broker::PotentialRenewals` (r:1 w:2) @@ -878,6 +897,16 @@ impl WeightInfo for () { Weight::from_parts(1_513_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_902_000 picoseconds. + Weight::from_parts(2_116_000, 0) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// 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) @@ -906,6 +935,13 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + fn on_new_timeslice() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 229_000 picoseconds. + Weight::from_parts(268_000, 0) + } /// Storage: `Broker::SaleInfo` (r:1 w:1) /// Proof: `Broker::SaleInfo` (`max_values`: Some(1), `max_size`: Some(57), added: 552, mode: `MaxEncodedLen`) /// Storage: `Broker::PotentialRenewals` (r:1 w:2) From eff4ee7925ffd4933ce7b0ad97f3fda5034ad3b8 Mon Sep 17 00:00:00 2001 From: Sergej Date: Mon, 1 Jul 2024 11:38:03 +0200 Subject: [PATCH 45/48] benchmark fix --- substrate/frame/broker/src/benchmarking.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index d13a12bb0cda..29c89396a720 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -1107,6 +1107,7 @@ mod benches { Ok(()) } + #[benchmark] fn on_new_timeslice() -> Result<(), BenchmarkError> { setup_and_start_sale::()?; From d2041f185c9b6235c14a82d0daf54f24800958df Mon Sep 17 00:00:00 2001 From: Sergej Date: Tue, 30 Jul 2024 09:54:50 +0200 Subject: [PATCH 46/48] prdoc --- prdoc/pr_4424.prdoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 prdoc/pr_4424.prdoc diff --git a/prdoc/pr_4424.prdoc b/prdoc/pr_4424.prdoc new file mode 100644 index 000000000000..7131ebfca274 --- /dev/null +++ b/prdoc/pr_4424.prdoc @@ -0,0 +1,20 @@ +# 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: Coretime auto renewal + +doc: + - audience: Runtime User + description: | + With the additions in this PR, any task that utilizes a core that can be auto-renewed + can enable auto-renewal. The renewal is paid from the task's sovereign account. + The two new extrinsics for controlling auto-renewal are `enable_auto_renew` and + `disable_auto_renew`. + +crates: + - name: pallet-broker + bump: major + - name: coretime-rococo-runtime + bump: minor + - name: coretime-westend-runtime + bump: minor From 7155233b93c56e99663d11d6afebe94c92ff4973 Mon Sep 17 00:00:00 2001 From: Sergej Date: Tue, 30 Jul 2024 10:04:58 +0200 Subject: [PATCH 47/48] improve docs --- substrate/frame/broker/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index 6c0a29cf5bb5..10745544fadf 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -894,8 +894,9 @@ pub mod pallet { /// - `origin`: Must be the sovereign account of the task /// - `core`: The core to which the task to be renewed is currently assigned. /// - `task`: The task for which we want to enable auto renewal. - /// - `workload_end_hint` parameter should be used when enabling auto-renewal for - /// the core which holds a legacy lease, as it would be inefficient to look it up otherwise. + /// - `workload_end_hint`: should be used when enabling auto-renewal for a core that is not + /// expiring in the upcoming bulk period (e.g., due to holding a lease) since it would be + /// inefficient to look up when the core expires to schedule the next renewal. #[pallet::call_index(21)] #[pallet::weight(T::WeightInfo::enable_auto_renew())] pub fn enable_auto_renew( From 9a90fbdd9809f3735a97200b3ea0a95ed867317e Mon Sep 17 00:00:00 2001 From: Sergej Date: Thu, 1 Aug 2024 15:08:37 +0200 Subject: [PATCH 48/48] improve comments --- substrate/frame/broker/src/dispatchable_impls.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index d2aac93502ab..5fbd957d7908 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -494,10 +494,13 @@ impl Pallet { ) -> DispatchResult { let sale = SaleInfo::::get().ok_or(Error::::NoSales)?; + // Check if the core is expiring in the next bulk period; if so, we will renew it now. + // + // In case we renew it now, we don't need to check the workload end since we know it is + // eligible for renewal. if PotentialRenewals::::get(PotentialRenewalId { core, when: sale.region_begin }) .is_some() { - // If the core expires in the upcoming bulk period we will renew it now. Self::do_renew(sovereign_account.clone(), core)?; } else if let Some(workload_end) = workload_end_hint { ensure!( @@ -509,7 +512,7 @@ impl Pallet { return Err(Error::::NotAllowed.into()) } - // We are keeping the auto-renewals sorted by `CoreIndex`. + // We are sorting auto renewals by `CoreIndex`. AutoRenewals::::try_mutate(|renewals| { let pos = renewals .binary_search_by(|r: &AutoRenewalRecord| r.core.cmp(&core))