diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 849bc7ca6fb96..4d409a791ba25 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1993,7 +1993,6 @@ impl OnUnbalanced> for IntoAuthor { } parameter_types! { - pub storage CoreCount: Option = None; pub storage CoretimeRevenue: Option<(BlockNumber, Balance)> = None; } @@ -2012,21 +2011,12 @@ impl CoretimeInterface for CoretimeProvider { _end_hint: Option, ) { } - fn check_notify_core_count() -> Option { - let count = CoreCount::get(); - CoreCount::set(&None); - count - } fn check_notify_revenue_info() -> Option<(u32, Self::Balance)> { let revenue = CoretimeRevenue::get(); CoretimeRevenue::set(&None); revenue } #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_core_count(count: u16) { - CoreCount::set(&Some(count)); - } - #[cfg(feature = "runtime-benchmarks")] fn ensure_notify_revenue_info(when: u32, revenue: Self::Balance) { CoretimeRevenue::set(&Some((when, revenue))); } diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 8d97d94102297..fe8fcfda216e1 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -784,9 +784,7 @@ fn json_eval_value_at_key( path: &mut VecDeque<&str>, fun: &dyn Fn(&json::Value) -> bool, ) -> bool { - let Some(key) = path.pop_front() else { - return false; - }; + let Some(key) = path.pop_front() else { return false }; if path.is_empty() { doc.as_object().map_or(false, |o| o.get(key).map_or(false, |v| fun(v))) diff --git a/substrate/frame/broker/src/benchmarking.rs b/substrate/frame/broker/src/benchmarking.rs index 2cb4826f4acca..c57c4ccb8ce4a 100644 --- a/substrate/frame/broker/src/benchmarking.rs +++ b/substrate/frame/broker/src/benchmarking.rs @@ -705,7 +705,7 @@ mod benches { let core_count = n.try_into().unwrap(); - ::ensure_notify_core_count(core_count); + CoreCountInbox::::put(core_count); let mut status = Status::::get().ok_or(BenchmarkError::Weightless)?; diff --git a/substrate/frame/broker/src/coretime_interface.rs b/substrate/frame/broker/src/coretime_interface.rs index 9f23561ce9456..9e853e8f3fe0b 100644 --- a/substrate/frame/broker/src/coretime_interface.rs +++ b/substrate/frame/broker/src/coretime_interface.rs @@ -107,11 +107,6 @@ pub trait CoretimeInterface { end_hint: Option>, ); - /// Indicate that from this block onwards, the range of acceptable values of the `core` - /// parameter of `assign_core` message is `[0, count)`. `assign_core` will be a no-op if - /// provided with a value for `core` outside of this range. - fn check_notify_core_count() -> Option; - /// Provide the amount of revenue accumulated from Instantaneous Coretime Sales from Relay-chain /// block number `last_until` to `until`, not including `until` itself. `last_until` is defined /// as being the `until` argument of the last `notify_revenue` message sent, or zero for the @@ -123,12 +118,6 @@ pub trait CoretimeInterface { /// single revenue information destination exists. fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)>; - /// Ensure that core count is updated to the provided value. - /// - /// This is only used for benchmarking. - #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_core_count(count: u16); - /// Ensure that revenue information is updated to the provided value. /// /// This is only used for benchmarking. @@ -151,14 +140,9 @@ impl CoretimeInterface for () { _end_hint: Option>, ) { } - fn check_notify_core_count() -> Option { - None - } fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { None } #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_core_count(_count: u16) {} - #[cfg(feature = "runtime-benchmarks")] fn ensure_notify_revenue_info(_when: RCBlockNumberOf, _revenue: Self::Balance) {} } diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 0b08a7b665b75..b04e15b169bc5 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -37,6 +37,11 @@ impl Pallet { Ok(()) } + pub(crate) fn do_notify_core_count(core_count: CoreIndex) -> DispatchResult { + CoreCountInbox::::put(core_count); + Ok(()) + } + pub(crate) fn do_reserve(workload: Schedule) -> DispatchResult { let mut r = Reservations::::get(); let index = r.len() as u32; diff --git a/substrate/frame/broker/src/lib.rs b/substrate/frame/broker/src/lib.rs index ee3501d560715..38a5049005468 100644 --- a/substrate/frame/broker/src/lib.rs +++ b/substrate/frame/broker/src/lib.rs @@ -159,6 +159,10 @@ pub mod pallet { pub type InstaPoolHistory = StorageMap<_, Blake2_128Concat, Timeslice, InstaPoolHistoryRecordOf>; + /// Received core count change from the relay chain. + #[pallet::storage] + pub type CoreCountInbox = StorageValue<_, CoreIndex, OptionQuery>; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -774,5 +778,13 @@ pub mod pallet { Self::do_request_core_count(core_count)?; Ok(()) } + + #[pallet::call_index(19)] + #[pallet::weight(T::WeightInfo::notify_core_count())] + pub fn notify_core_count(origin: OriginFor, core_count: CoreIndex) -> DispatchResult { + T::AdminOrigin::ensure_origin_or_root(origin)?; + Self::do_notify_core_count(core_count)?; + Ok(()) + } } } diff --git a/substrate/frame/broker/src/mock.rs b/substrate/frame/broker/src/mock.rs index 7444040ec9b75..19c72340353c6 100644 --- a/substrate/frame/broker/src/mock.rs +++ b/substrate/frame/broker/src/mock.rs @@ -70,7 +70,6 @@ parameter_types! { pub static CoretimeWorkplan: BTreeMap<(u32, CoreIndex), Vec<(CoreAssignment, PartsOf57600)>> = Default::default(); pub static CoretimeUsage: BTreeMap> = Default::default(); pub static CoretimeInPool: CoreMaskBitCount = 0; - pub static NotifyCoreCount: Vec = Default::default(); pub static NotifyRevenueInfo: Vec<(u32, u64)> = Default::default(); } @@ -80,7 +79,7 @@ impl CoretimeInterface for TestCoretimeProvider { type Balance = u64; type RealyChainBlockNumberProvider = System; fn request_core_count(count: CoreIndex) { - NotifyCoreCount::mutate(|s| s.insert(0, count)); + CoreCountInbox::::put(count); } fn request_revenue_info_at(when: RCBlockNumberOf) { if when > RCBlockNumberProviderOf::::current_block_number() { @@ -126,17 +125,10 @@ impl CoretimeInterface for TestCoretimeProvider { ); CoretimeTrace::mutate(|v| v.push(item)); } - fn check_notify_core_count() -> Option { - NotifyCoreCount::mutate(|s| s.pop()) - } fn check_notify_revenue_info() -> Option<(RCBlockNumberOf, Self::Balance)> { NotifyRevenueInfo::mutate(|s| s.pop()).map(|v| (v.0 as _, v.1)) } #[cfg(feature = "runtime-benchmarks")] - fn ensure_notify_core_count(count: u16) { - NotifyCoreCount::mutate(|s| s.insert(0, count)); - } - #[cfg(feature = "runtime-benchmarks")] fn ensure_notify_revenue_info(when: RCBlockNumberOf, revenue: Self::Balance) { NotifyRevenueInfo::mutate(|s| s.push((when as u32, revenue))); } diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index 5f2be268b2289..8b7860c8e3af6 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -87,7 +87,7 @@ impl Pallet { } pub(crate) fn process_core_count(status: &mut StatusRecord) -> bool { - if let Some(core_count) = T::Coretime::check_notify_core_count() { + if let Some(core_count) = CoreCountInbox::::take() { status.core_count = core_count; Self::deposit_event(Event::::CoreCountChanged { core_count }); return true diff --git a/substrate/frame/broker/src/weights.rs b/substrate/frame/broker/src/weights.rs index b3a151c6062c4..a8f50eeee6e6c 100644 --- a/substrate/frame/broker/src/weights.rs +++ b/substrate/frame/broker/src/weights.rs @@ -74,6 +74,7 @@ pub trait WeightInfo { fn process_pool() -> Weight; fn process_core_schedule() -> Weight; fn request_revenue_info_at() -> Weight; + fn notify_core_count() -> Weight; fn do_tick_base() -> Weight; } @@ -447,6 +448,9 @@ impl WeightInfo for SubstrateWeight { // Minimum execution time: 147_000 picoseconds. Weight::from_parts(184_000, 0) } + fn notify_core_count() -> Weight { + T::DbWeight::get().reads_writes(1, 1) + } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0) @@ -835,6 +839,10 @@ impl WeightInfo for () { // Minimum execution time: 147_000 picoseconds. Weight::from_parts(184_000, 0) } + fn notify_core_count() -> Weight { + RocksDbWeight::get().reads(1) + .saturating_add(RocksDbWeight::get().writes(1)) + } /// Storage: `Broker::Status` (r:1 w:1) /// Proof: `Broker::Status` (`max_values`: Some(1), `max_size`: Some(18), added: 513, mode: `MaxEncodedLen`) /// Storage: `Broker::Configuration` (r:1 w:0)