mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
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:
@@ -48,6 +48,7 @@ pub(crate) struct RequestResultCache {
|
||||
validation_code: LruMap<(Hash, ParaId, OccupiedCoreAssumption), Option<ValidationCode>>,
|
||||
validation_code_by_hash: LruMap<ValidationCodeHash, Option<ValidationCode>>,
|
||||
candidate_pending_availability: LruMap<(Hash, ParaId), Option<CommittedCandidateReceipt>>,
|
||||
candidates_pending_availability: LruMap<(Hash, ParaId), Vec<CommittedCandidateReceipt>>,
|
||||
candidate_events: LruMap<Hash, Vec<CandidateEvent>>,
|
||||
session_executor_params: LruMap<SessionIndex, Option<ExecutorParams>>,
|
||||
session_info: LruMap<SessionIndex, SessionInfo>,
|
||||
@@ -86,6 +87,7 @@ impl Default for RequestResultCache {
|
||||
validation_code: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
validation_code_by_hash: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
candidate_pending_availability: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
candidates_pending_availability: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
candidate_events: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
session_executor_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
session_info: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
|
||||
@@ -261,6 +263,21 @@ impl RequestResultCache {
|
||||
self.candidate_pending_availability.insert(key, value);
|
||||
}
|
||||
|
||||
pub(crate) fn candidates_pending_availability(
|
||||
&mut self,
|
||||
key: (Hash, ParaId),
|
||||
) -> Option<&Vec<CommittedCandidateReceipt>> {
|
||||
self.candidates_pending_availability.get(&key).map(|v| &*v)
|
||||
}
|
||||
|
||||
pub(crate) fn cache_candidates_pending_availability(
|
||||
&mut self,
|
||||
key: (Hash, ParaId),
|
||||
value: Vec<CommittedCandidateReceipt>,
|
||||
) {
|
||||
self.candidates_pending_availability.insert(key, value);
|
||||
}
|
||||
|
||||
pub(crate) fn candidate_events(&mut self, relay_parent: &Hash) -> Option<&Vec<CandidateEvent>> {
|
||||
self.candidate_events.get(relay_parent).map(|v| &*v)
|
||||
}
|
||||
@@ -591,4 +608,5 @@ pub(crate) enum RequestResult {
|
||||
AsyncBackingParams(Hash, async_backing::AsyncBackingParams),
|
||||
NodeFeatures(SessionIndex, NodeFeatures),
|
||||
ClaimQueue(Hash, BTreeMap<CoreIndex, VecDeque<ParaId>>),
|
||||
CandidatesPendingAvailability(Hash, ParaId, Vec<CommittedCandidateReceipt>),
|
||||
}
|
||||
|
||||
@@ -133,6 +133,9 @@ where
|
||||
CandidatePendingAvailability(relay_parent, para_id, candidate) => self
|
||||
.requests_cache
|
||||
.cache_candidate_pending_availability((relay_parent, para_id), candidate),
|
||||
CandidatesPendingAvailability(relay_parent, para_id, candidates) => self
|
||||
.requests_cache
|
||||
.cache_candidates_pending_availability((relay_parent, para_id), candidates),
|
||||
CandidateEvents(relay_parent, events) =>
|
||||
self.requests_cache.cache_candidate_events(relay_parent, events),
|
||||
SessionExecutorParams(_relay_parent, session_index, index) =>
|
||||
@@ -252,6 +255,9 @@ where
|
||||
Request::CandidatePendingAvailability(para, sender) =>
|
||||
query!(candidate_pending_availability(para), sender)
|
||||
.map(|sender| Request::CandidatePendingAvailability(para, sender)),
|
||||
Request::CandidatesPendingAvailability(para, sender) =>
|
||||
query!(candidates_pending_availability(para), sender)
|
||||
.map(|sender| Request::CandidatesPendingAvailability(para, sender)),
|
||||
Request::CandidateEvents(sender) =>
|
||||
query!(candidate_events(), sender).map(|sender| Request::CandidateEvents(sender)),
|
||||
Request::SessionExecutorParams(session_index, sender) => {
|
||||
@@ -531,6 +537,12 @@ where
|
||||
ver = 1,
|
||||
sender
|
||||
),
|
||||
Request::CandidatesPendingAvailability(para, sender) => query!(
|
||||
CandidatesPendingAvailability,
|
||||
candidates_pending_availability(para),
|
||||
ver = Request::CANDIDATES_PENDING_AVAILABILITY_RUNTIME_REQUIREMENT,
|
||||
sender
|
||||
),
|
||||
Request::CandidateEvents(sender) => {
|
||||
query!(CandidateEvents, candidate_events(), ver = 1, sender)
|
||||
},
|
||||
|
||||
@@ -47,6 +47,7 @@ struct MockSubsystemClient {
|
||||
validation_outputs_results: HashMap<ParaId, bool>,
|
||||
session_index_for_child: SessionIndex,
|
||||
candidate_pending_availability: HashMap<ParaId, CommittedCandidateReceipt>,
|
||||
candidates_pending_availability: HashMap<ParaId, Vec<CommittedCandidateReceipt>>,
|
||||
dmq_contents: HashMap<ParaId, Vec<InboundDownwardMessage>>,
|
||||
hrmp_channels: HashMap<ParaId, BTreeMap<ParaId, Vec<InboundHrmpMessage>>>,
|
||||
validation_code_by_hash: HashMap<ValidationCodeHash, ValidationCode>,
|
||||
@@ -140,6 +141,14 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
|
||||
Ok(self.candidate_pending_availability.get(¶_id).cloned())
|
||||
}
|
||||
|
||||
async fn candidates_pending_availability(
|
||||
&self,
|
||||
_: Hash,
|
||||
para_id: ParaId,
|
||||
) -> Result<Vec<CommittedCandidateReceipt<Hash>>, ApiError> {
|
||||
Ok(self.candidates_pending_availability.get(¶_id).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
async fn candidate_events(&self, _: Hash) -> Result<Vec<CandidateEvent<Hash>>, ApiError> {
|
||||
Ok(self.candidate_events.clone())
|
||||
}
|
||||
|
||||
@@ -670,7 +670,7 @@ pub enum RuntimeApiRequest {
|
||||
/// Get validation code by its hash, either past, current or future code can be returned, as
|
||||
/// long as state is still available.
|
||||
ValidationCodeByHash(ValidationCodeHash, RuntimeApiSender<Option<ValidationCode>>),
|
||||
/// Get a the candidate pending availability for a particular parachain by parachain / core
|
||||
/// Get the candidate pending availability for a particular parachain by parachain / core
|
||||
/// index
|
||||
CandidatePendingAvailability(ParaId, RuntimeApiSender<Option<CommittedCandidateReceipt>>),
|
||||
/// Get all events concerning candidates (backing, inclusion, time-out) in the parent of
|
||||
@@ -739,6 +739,9 @@ pub enum RuntimeApiRequest {
|
||||
/// Fetch the `ClaimQueue` from scheduler pallet
|
||||
/// `V11`
|
||||
ClaimQueue(RuntimeApiSender<BTreeMap<CoreIndex, VecDeque<ParaId>>>),
|
||||
/// Get the candidates pending availability for a particular parachain
|
||||
/// `V11`
|
||||
CandidatesPendingAvailability(ParaId, RuntimeApiSender<Vec<CommittedCandidateReceipt>>),
|
||||
}
|
||||
|
||||
impl RuntimeApiRequest {
|
||||
@@ -776,6 +779,9 @@ impl RuntimeApiRequest {
|
||||
|
||||
/// `ClaimQueue`
|
||||
pub const CLAIM_QUEUE_RUNTIME_REQUIREMENT: u32 = 11;
|
||||
|
||||
/// `candidates_pending_availability`
|
||||
pub const CANDIDATES_PENDING_AVAILABILITY_RUNTIME_REQUIREMENT: u32 = 11;
|
||||
}
|
||||
|
||||
/// A message to the Runtime API subsystem.
|
||||
|
||||
@@ -333,6 +333,14 @@ pub trait RuntimeApiSubsystemClient {
|
||||
// == v11: Claim queue ==
|
||||
/// Fetch the `ClaimQueue` from scheduler pallet
|
||||
async fn claim_queue(&self, at: Hash) -> Result<BTreeMap<CoreIndex, VecDeque<Id>>, ApiError>;
|
||||
|
||||
// == v11: Elastic scaling support ==
|
||||
/// Get the receipts of all candidates pending availability for a `ParaId`.
|
||||
async fn candidates_pending_availability(
|
||||
&self,
|
||||
at: Hash,
|
||||
para_id: Id,
|
||||
) -> Result<Vec<CommittedCandidateReceipt<Hash>>, ApiError>;
|
||||
}
|
||||
|
||||
/// Default implementation of [`RuntimeApiSubsystemClient`] using the client.
|
||||
@@ -428,6 +436,14 @@ where
|
||||
self.client.runtime_api().candidate_pending_availability(at, para_id)
|
||||
}
|
||||
|
||||
async fn candidates_pending_availability(
|
||||
&self,
|
||||
at: Hash,
|
||||
para_id: Id,
|
||||
) -> Result<Vec<CommittedCandidateReceipt<Hash>>, ApiError> {
|
||||
self.client.runtime_api().candidates_pending_availability(at, para_id)
|
||||
}
|
||||
|
||||
async fn candidate_events(&self, at: Hash) -> Result<Vec<CandidateEvent<Hash>>, ApiError> {
|
||||
self.client.runtime_api().candidate_events(at)
|
||||
}
|
||||
|
||||
@@ -296,6 +296,7 @@ specialize_requests! {
|
||||
fn request_validation_code(para_id: ParaId, assumption: OccupiedCoreAssumption) -> Option<ValidationCode>; ValidationCode;
|
||||
fn request_validation_code_by_hash(validation_code_hash: ValidationCodeHash) -> Option<ValidationCode>; ValidationCodeByHash;
|
||||
fn request_candidate_pending_availability(para_id: ParaId) -> Option<CommittedCandidateReceipt>; CandidatePendingAvailability;
|
||||
fn request_candidates_pending_availability(para_id: ParaId) -> Vec<CommittedCandidateReceipt>; CandidatesPendingAvailability;
|
||||
fn request_candidate_events() -> Vec<CandidateEvent>; CandidateEvents;
|
||||
fn request_session_info(index: SessionIndex) -> Option<SessionInfo>; SessionInfo;
|
||||
fn request_validation_code_hash(para_id: ParaId, assumption: OccupiedCoreAssumption)
|
||||
|
||||
Reference in New Issue
Block a user