Skip to content

Commit

Permalink
chore: bump runtime api version to v11 (#5824)
Browse files Browse the repository at this point in the history
A change that I missed to add in
#5525 .

---------

Signed-off-by: Andrei Sandu <[email protected]>
  • Loading branch information
sandreim authored Sep 26, 2024
1 parent c77095f commit 1f3e397
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 67 deletions.
2 changes: 1 addition & 1 deletion polkadot/runtime/parachains/src/runtime_api_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
//! 2. Move methods from `vstaging` to `v3`. The new stable version should include all methods from
//! `vstaging` tagged with the new version number (e.g. all `v3` methods).
pub mod v10;
pub mod v11;
pub mod vstaging;
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
//! A module exporting runtime API implementation functions for all runtime APIs using `v5`
//! primitives.
//!
//! Runtimes implementing the v10 runtime API are recommended to forward directly to these
//! Runtimes implementing the v11 runtime API are recommended to forward directly to these
//! functions.
use crate::{
configuration, disputes, dmp, hrmp, inclusion, initializer, paras, paras_inherent,
scheduler::{self, CoreOccupied},
session_info, shared,
};
use alloc::{collections::btree_map::BTreeMap, vec, vec::Vec};
use alloc::{
collections::{btree_map::BTreeMap, vec_deque::VecDeque},
vec,
vec::Vec,
};
use frame_support::traits::{GetStorageVersion, StorageVersion};
use frame_system::pallet_prelude::*;
use polkadot_primitives::{
Expand Down Expand Up @@ -547,3 +551,38 @@ pub fn node_features<T: initializer::Config>() -> NodeFeatures {
pub fn approval_voting_params<T: initializer::Config>() -> ApprovalVotingParams {
configuration::ActiveConfig::<T>::get().approval_voting_params
}

/// Returns the claimqueue from the scheduler
pub fn claim_queue<T: scheduler::Config>() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
let now = <frame_system::Pallet<T>>::block_number() + One::one();

// This is needed so that the claim queue always has the right size (equal to
// scheduling_lookahead). Otherwise, if a candidate is backed in the same block where the
// previous candidate is included, the claim queue will have already pop()-ed the next item
// from the queue and the length would be `scheduling_lookahead - 1`.
<scheduler::Pallet<T>>::free_cores_and_fill_claim_queue(Vec::new(), now);
let config = configuration::ActiveConfig::<T>::get();
// Extra sanity, config should already never be smaller than 1:
let n_lookahead = config.scheduler_params.lookahead.max(1);

scheduler::ClaimQueue::<T>::get()
.into_iter()
.map(|(core_index, entries)| {
// on cores timing out internal claim queue size may be temporarily longer than it
// should be as the timed out assignment might got pushed back to an already full claim
// queue:
(
core_index,
entries.into_iter().map(|e| e.para_id()).take(n_lookahead as usize).collect(),
)
})
.collect()
}

/// Returns all the candidates that are pending availability for a given `ParaId`.
/// Deprecates `candidate_pending_availability` in favor of supporting elastic scaling.
pub fn candidates_pending_availability<T: initializer::Config>(
para_id: ParaId,
) -> Vec<CommittedCandidateReceipt<T::Hash>> {
<inclusion::Pallet<T>>::candidates_pending_availability(para_id)
}
45 changes: 0 additions & 45 deletions polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,3 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Put implementations of functions from staging APIs here.
use crate::{configuration, inclusion, initializer, scheduler};
use alloc::{
collections::{btree_map::BTreeMap, vec_deque::VecDeque},
vec::Vec,
};
use polkadot_primitives::{
vstaging::CommittedCandidateReceiptV2 as CommittedCandidateReceipt, CoreIndex, Id as ParaId,
};
use sp_runtime::traits::One;

/// Returns the claimqueue from the scheduler
pub fn claim_queue<T: scheduler::Config>() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
let now = <frame_system::Pallet<T>>::block_number() + One::one();

// This is needed so that the claim queue always has the right size (equal to
// scheduling_lookahead). Otherwise, if a candidate is backed in the same block where the
// previous candidate is included, the claim queue will have already pop()-ed the next item
// from the queue and the length would be `scheduling_lookahead - 1`.
<scheduler::Pallet<T>>::free_cores_and_fill_claim_queue(Vec::new(), now);
let config = configuration::ActiveConfig::<T>::get();
// Extra sanity, config should already never be smaller than 1:
let n_lookahead = config.scheduler_params.lookahead.max(1);

scheduler::ClaimQueue::<T>::get()
.into_iter()
.map(|(core_index, entries)| {
// on cores timing out internal claim queue size may be temporarily longer than it
// should be as the timed out assignment might got pushed back to an already full claim
// queue:
(
core_index,
entries.into_iter().map(|e| e.para_id()).take(n_lookahead as usize).collect(),
)
})
.collect()
}

/// Returns all the candidates that are pending availability for a given `ParaId`.
/// Deprecates `candidate_pending_availability` in favor of supporting elastic scaling.
pub fn candidates_pending_availability<T: initializer::Config>(
para_id: ParaId,
) -> Vec<CommittedCandidateReceipt<T::Hash>> {
<inclusion::Pallet<T>>::candidates_pending_availability(para_id)
}
8 changes: 3 additions & 5 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ use polkadot_runtime_parachains::{
initializer as parachains_initializer, on_demand as parachains_on_demand,
origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent,
runtime_api_impl::{
v10 as parachains_runtime_api_impl, vstaging as vstaging_parachains_runtime_api_impl,
},
runtime_api_impl::v11 as parachains_runtime_api_impl,
scheduler as parachains_scheduler, session_info as parachains_session_info,
shared as parachains_shared,
};
Expand Down Expand Up @@ -2057,11 +2055,11 @@ sp_api::impl_runtime_apis! {
}

fn claim_queue() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
vstaging_parachains_runtime_api_impl::claim_queue::<Runtime>()
parachains_runtime_api_impl::claim_queue::<Runtime>()
}

fn candidates_pending_availability(para_id: ParaId) -> Vec<CommittedCandidateReceipt<Hash>> {
vstaging_parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
}
}

Expand Down
16 changes: 7 additions & 9 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ use pallet_transaction_payment::FungibleAdapter;
use polkadot_runtime_parachains::{
assigner_parachains as parachains_assigner_parachains,
configuration as parachains_configuration,
configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio,
disputes as parachains_disputes,
disputes::slashing as parachains_slashing,
dmp as parachains_dmp, hrmp as parachains_hrmp, inclusion as parachains_inclusion,
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent,
runtime_api_impl::{v10 as runtime_impl, vstaging as vstaging_parachains_runtime_api_impl},
configuration::ActiveConfigHrmpChannelSizeAndCapacityRatio, disputes as parachains_disputes,
disputes::slashing as parachains_slashing, dmp as parachains_dmp, hrmp as parachains_hrmp,
inclusion as parachains_inclusion, initializer as parachains_initializer,
origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent, runtime_api_impl::v11 as runtime_impl,
scheduler as parachains_scheduler, session_info as parachains_session_info,
shared as parachains_shared,
};
Expand Down Expand Up @@ -1003,11 +1001,11 @@ sp_api::impl_runtime_apis! {
}

fn claim_queue() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
vstaging_parachains_runtime_api_impl::claim_queue::<Runtime>()
runtime_impl::claim_queue::<Runtime>()
}

fn candidates_pending_availability(para_id: ParaId) -> Vec<CommittedCandidateReceipt<Hash>> {
vstaging_parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
runtime_impl::candidates_pending_availability::<Runtime>(para_id)
}
}

Expand Down
8 changes: 3 additions & 5 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ use polkadot_runtime_parachains::{
initializer as parachains_initializer, on_demand as parachains_on_demand,
origin as parachains_origin, paras as parachains_paras,
paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points,
runtime_api_impl::{
v10 as parachains_runtime_api_impl, vstaging as vstaging_parachains_runtime_api_impl,
},
runtime_api_impl::v11 as parachains_runtime_api_impl,
scheduler as parachains_scheduler, session_info as parachains_session_info,
shared as parachains_shared,
};
Expand Down Expand Up @@ -2088,11 +2086,11 @@ sp_api::impl_runtime_apis! {
}

fn claim_queue() -> BTreeMap<CoreIndex, VecDeque<ParaId>> {
vstaging_parachains_runtime_api_impl::claim_queue::<Runtime>()
parachains_runtime_api_impl::claim_queue::<Runtime>()
}

fn candidates_pending_availability(para_id: ParaId) -> Vec<CommittedCandidateReceipt<Hash>> {
vstaging_parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
parachains_runtime_api_impl::candidates_pending_availability::<Runtime>(para_id)
}
}

Expand Down
17 changes: 17 additions & 0 deletions prdoc/pr_5824.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: "Bump parachains runtime API to v11"

doc:
- audience: [ Node Dev, Runtime Dev ]
description: |
This PR promotes all staging methods in v10 to stable and releases v11 stable runtime
APIs.

crates:
- name: polkadot-runtime-parachains
bump: major
- name: rococo-runtime
bump: patch
- name: westend-runtime
bump: patch
- name: polkadot-test-runtime
bump: patch

0 comments on commit 1f3e397

Please sign in to comment.