Runtime API: introduce candidates_pending_availability (#4027)

Fixes https://github.com/paritytech/polkadot-sdk/issues/3576

Required by elastic scaling collators.
Deprecates old API: `candidate_pending_availability`.

TODO:
- [x] PRDoc

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
Andrei Sandu
2024-04-12 13:50:13 +03:00
committed by GitHub
parent a1cb2a5123
commit 2dfe5f745c
18 changed files with 191 additions and 16 deletions
@@ -1104,6 +1104,24 @@ impl<T: Config> Pallet<T> {
})
}
/// Returns all the `CommittedCandidateReceipt` pending availability for the para provided, if
/// any.
pub(crate) fn candidates_pending_availability(
para: ParaId,
) -> Vec<CommittedCandidateReceipt<T::Hash>> {
<PendingAvailability<T>>::get(&para)
.map(|candidates| {
candidates
.into_iter()
.map(|candidate| CommittedCandidateReceipt {
descriptor: candidate.descriptor.clone(),
commitments: candidate.commitments.clone(),
})
.collect()
})
.unwrap_or_default()
}
/// Returns the metadata around the first candidate pending availability for the
/// para provided, if any.
pub(crate) fn pending_availability(
@@ -301,6 +301,10 @@ pub fn validation_code<T: initializer::Config>(
}
/// Implementation for the `candidate_pending_availability` function of the runtime API.
#[deprecated(
note = "`candidate_pending_availability` will be removed. Use `candidates_pending_availability` to query
all candidates pending availability"
)]
pub fn candidate_pending_availability<T: initializer::Config>(
para_id: ParaId,
) -> Option<CommittedCandidateReceipt<T::Hash>> {
@@ -16,8 +16,8 @@
//! Put implementations of functions from staging APIs here.
use crate::scheduler;
use primitives::{CoreIndex, Id as ParaId};
use crate::{inclusion, initializer, scheduler};
use primitives::{CommittedCandidateReceipt, CoreIndex, Id as ParaId};
use sp_runtime::traits::One;
use sp_std::{
collections::{btree_map::BTreeMap, vec_deque::VecDeque},
@@ -41,3 +41,11 @@ pub fn claim_queue<T: scheduler::Config>() -> BTreeMap<CoreIndex, VecDeque<ParaI
})
.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)
}