referrerpolicy=no-referrer-when-downgrade

polkadot_node_core_runtime_api/
cache.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use std::collections::{btree_map::BTreeMap, VecDeque};
18
19use schnellru::{ByLength, LruMap};
20use sp_consensus_babe::Epoch;
21
22use polkadot_primitives::{
23	async_backing::{self, Constraints},
24	slashing, ApprovalVotingParams, AuthorityDiscoveryId, BlockNumber, CandidateCommitments,
25	CandidateEvent, CandidateHash, CommittedCandidateReceiptV2 as CommittedCandidateReceipt,
26	CoreIndex, CoreState, DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id as ParaId,
27	InboundDownwardMessage, InboundHrmpMessage, NodeFeatures, OccupiedCoreAssumption,
28	PersistedValidationData, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode,
29	ValidationCodeHash, ValidatorId, ValidatorIndex,
30};
31
32/// For consistency we have the same capacity for all caches. We use 128 as we'll only need that
33/// much if finality stalls (we only query state for unfinalized blocks + maybe latest finalized).
34/// In any case, a cache is an optimization. We should avoid a situation where having a large cache
35/// leads to OOM or puts pressure on other important stuff like PVF execution/preparation.
36const DEFAULT_CACHE_CAP: u32 = 128;
37
38pub(crate) struct RequestResultCache {
39	authorities: LruMap<Hash, Vec<AuthorityDiscoveryId>>,
40	validators: LruMap<Hash, Vec<ValidatorId>>,
41	validator_groups: LruMap<Hash, (Vec<Vec<ValidatorIndex>>, GroupRotationInfo)>,
42	availability_cores: LruMap<Hash, Vec<CoreState>>,
43	persisted_validation_data:
44		LruMap<(Hash, ParaId, OccupiedCoreAssumption), Option<PersistedValidationData>>,
45	assumed_validation_data:
46		LruMap<(ParaId, Hash), Option<(PersistedValidationData, ValidationCodeHash)>>,
47	check_validation_outputs: LruMap<(Hash, ParaId, CandidateCommitments), bool>,
48	session_index_for_child: LruMap<Hash, SessionIndex>,
49	validation_code: LruMap<(Hash, ParaId, OccupiedCoreAssumption), Option<ValidationCode>>,
50	validation_code_by_hash: LruMap<ValidationCodeHash, Option<ValidationCode>>,
51	candidate_pending_availability: LruMap<(Hash, ParaId), Option<CommittedCandidateReceipt>>,
52	candidates_pending_availability: LruMap<(Hash, ParaId), Vec<CommittedCandidateReceipt>>,
53	candidate_events: LruMap<Hash, Vec<CandidateEvent>>,
54	session_executor_params: LruMap<SessionIndex, Option<ExecutorParams>>,
55	session_info: LruMap<SessionIndex, SessionInfo>,
56	dmq_contents: LruMap<(Hash, ParaId), Vec<InboundDownwardMessage<BlockNumber>>>,
57	inbound_hrmp_channels_contents:
58		LruMap<(Hash, ParaId), BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>>>,
59	current_babe_epoch: LruMap<Hash, Epoch>,
60	on_chain_votes: LruMap<Hash, Option<ScrapedOnChainVotes>>,
61	pvfs_require_precheck: LruMap<Hash, Vec<ValidationCodeHash>>,
62	validation_code_hash:
63		LruMap<(Hash, ParaId, OccupiedCoreAssumption), Option<ValidationCodeHash>>,
64	version: LruMap<Hash, u32>,
65	disputes: LruMap<Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>>,
66	unapplied_slashes: LruMap<Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>>,
67	key_ownership_proof: LruMap<(Hash, ValidatorId), Option<slashing::OpaqueKeyOwnershipProof>>,
68	minimum_backing_votes: LruMap<SessionIndex, u32>,
69	disabled_validators: LruMap<Hash, Vec<ValidatorIndex>>,
70	para_backing_state: LruMap<(Hash, ParaId), Option<async_backing::BackingState>>,
71	async_backing_params: LruMap<Hash, async_backing::AsyncBackingParams>,
72	node_features: LruMap<SessionIndex, NodeFeatures>,
73	approval_voting_params: LruMap<SessionIndex, ApprovalVotingParams>,
74	claim_queue: LruMap<Hash, BTreeMap<CoreIndex, VecDeque<ParaId>>>,
75	backing_constraints: LruMap<(Hash, ParaId), Option<Constraints>>,
76	scheduling_lookahead: LruMap<SessionIndex, u32>,
77	validation_code_bomb_limits: LruMap<SessionIndex, u32>,
78	para_ids: LruMap<SessionIndex, Vec<ParaId>>,
79}
80
81impl Default for RequestResultCache {
82	fn default() -> Self {
83		Self {
84			authorities: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
85			validators: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
86			validator_groups: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
87			availability_cores: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
88			persisted_validation_data: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
89			assumed_validation_data: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
90			check_validation_outputs: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
91			session_index_for_child: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
92			validation_code: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
93			validation_code_by_hash: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
94			candidate_pending_availability: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
95			candidates_pending_availability: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
96			candidate_events: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
97			session_executor_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
98			session_info: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
99			dmq_contents: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
100			inbound_hrmp_channels_contents: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
101			current_babe_epoch: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
102			on_chain_votes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
103			pvfs_require_precheck: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
104			validation_code_hash: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
105			version: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
106			disputes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
107			unapplied_slashes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
108			key_ownership_proof: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
109			minimum_backing_votes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
110			approval_voting_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
111			disabled_validators: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
112			para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
113			async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
114			node_features: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
115			claim_queue: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
116			backing_constraints: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
117			scheduling_lookahead: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
118			validation_code_bomb_limits: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
119			para_ids: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
120		}
121	}
122}
123
124impl RequestResultCache {
125	pub(crate) fn authorities(
126		&mut self,
127		relay_parent: &Hash,
128	) -> Option<&Vec<AuthorityDiscoveryId>> {
129		self.authorities.get(relay_parent).map(|v| &*v)
130	}
131
132	pub(crate) fn cache_authorities(
133		&mut self,
134		relay_parent: Hash,
135		authorities: Vec<AuthorityDiscoveryId>,
136	) {
137		self.authorities.insert(relay_parent, authorities);
138	}
139
140	pub(crate) fn validators(&mut self, relay_parent: &Hash) -> Option<&Vec<ValidatorId>> {
141		self.validators.get(relay_parent).map(|v| &*v)
142	}
143
144	pub(crate) fn cache_validators(&mut self, relay_parent: Hash, validators: Vec<ValidatorId>) {
145		self.validators.insert(relay_parent, validators);
146	}
147
148	pub(crate) fn validator_groups(
149		&mut self,
150		relay_parent: &Hash,
151	) -> Option<&(Vec<Vec<ValidatorIndex>>, GroupRotationInfo)> {
152		self.validator_groups.get(relay_parent).map(|v| &*v)
153	}
154
155	pub(crate) fn cache_validator_groups(
156		&mut self,
157		relay_parent: Hash,
158		groups: (Vec<Vec<ValidatorIndex>>, GroupRotationInfo),
159	) {
160		self.validator_groups.insert(relay_parent, groups);
161	}
162
163	pub(crate) fn availability_cores(&mut self, relay_parent: &Hash) -> Option<&Vec<CoreState>> {
164		self.availability_cores.get(relay_parent).map(|v| &*v)
165	}
166
167	pub(crate) fn cache_availability_cores(&mut self, relay_parent: Hash, cores: Vec<CoreState>) {
168		self.availability_cores.insert(relay_parent, cores);
169	}
170
171	pub(crate) fn persisted_validation_data(
172		&mut self,
173		key: (Hash, ParaId, OccupiedCoreAssumption),
174	) -> Option<&Option<PersistedValidationData>> {
175		self.persisted_validation_data.get(&key).map(|v| &*v)
176	}
177
178	pub(crate) fn cache_persisted_validation_data(
179		&mut self,
180		key: (Hash, ParaId, OccupiedCoreAssumption),
181		data: Option<PersistedValidationData>,
182	) {
183		self.persisted_validation_data.insert(key, data);
184	}
185
186	pub(crate) fn assumed_validation_data(
187		&mut self,
188		key: (Hash, ParaId, Hash),
189	) -> Option<&Option<(PersistedValidationData, ValidationCodeHash)>> {
190		self.assumed_validation_data.get(&(key.1, key.2)).map(|v| &*v)
191	}
192
193	pub(crate) fn cache_assumed_validation_data(
194		&mut self,
195		key: (ParaId, Hash),
196		data: Option<(PersistedValidationData, ValidationCodeHash)>,
197	) {
198		self.assumed_validation_data.insert(key, data);
199	}
200
201	pub(crate) fn check_validation_outputs(
202		&mut self,
203		key: (Hash, ParaId, CandidateCommitments),
204	) -> Option<&bool> {
205		self.check_validation_outputs.get(&key).map(|v| &*v)
206	}
207
208	pub(crate) fn cache_check_validation_outputs(
209		&mut self,
210		key: (Hash, ParaId, CandidateCommitments),
211		value: bool,
212	) {
213		self.check_validation_outputs.insert(key, value);
214	}
215
216	pub(crate) fn session_index_for_child(&mut self, relay_parent: &Hash) -> Option<&SessionIndex> {
217		self.session_index_for_child.get(relay_parent).map(|v| &*v)
218	}
219
220	pub(crate) fn cache_session_index_for_child(
221		&mut self,
222		relay_parent: Hash,
223		index: SessionIndex,
224	) {
225		self.session_index_for_child.insert(relay_parent, index);
226	}
227
228	pub(crate) fn validation_code(
229		&mut self,
230		key: (Hash, ParaId, OccupiedCoreAssumption),
231	) -> Option<&Option<ValidationCode>> {
232		self.validation_code.get(&key).map(|v| &*v)
233	}
234
235	pub(crate) fn cache_validation_code(
236		&mut self,
237		key: (Hash, ParaId, OccupiedCoreAssumption),
238		value: Option<ValidationCode>,
239	) {
240		self.validation_code.insert(key, value);
241	}
242
243	// the actual key is `ValidationCodeHash` (`Hash` is ignored),
244	// but we keep the interface that way to keep the macro simple
245	pub(crate) fn validation_code_by_hash(
246		&mut self,
247		key: (Hash, ValidationCodeHash),
248	) -> Option<&Option<ValidationCode>> {
249		self.validation_code_by_hash.get(&key.1).map(|v| &*v)
250	}
251
252	pub(crate) fn cache_validation_code_by_hash(
253		&mut self,
254		key: ValidationCodeHash,
255		value: Option<ValidationCode>,
256	) {
257		self.validation_code_by_hash.insert(key, value);
258	}
259
260	pub(crate) fn candidate_pending_availability(
261		&mut self,
262		key: (Hash, ParaId),
263	) -> Option<&Option<CommittedCandidateReceipt>> {
264		self.candidate_pending_availability.get(&key).map(|v| &*v)
265	}
266
267	pub(crate) fn cache_candidate_pending_availability(
268		&mut self,
269		key: (Hash, ParaId),
270		value: Option<CommittedCandidateReceipt>,
271	) {
272		self.candidate_pending_availability.insert(key, value);
273	}
274
275	pub(crate) fn candidates_pending_availability(
276		&mut self,
277		key: (Hash, ParaId),
278	) -> Option<&Vec<CommittedCandidateReceipt>> {
279		self.candidates_pending_availability.get(&key).map(|v| &*v)
280	}
281
282	pub(crate) fn cache_candidates_pending_availability(
283		&mut self,
284		key: (Hash, ParaId),
285		value: Vec<CommittedCandidateReceipt>,
286	) {
287		self.candidates_pending_availability.insert(key, value);
288	}
289
290	pub(crate) fn candidate_events(&mut self, relay_parent: &Hash) -> Option<&Vec<CandidateEvent>> {
291		self.candidate_events.get(relay_parent).map(|v| &*v)
292	}
293
294	pub(crate) fn cache_candidate_events(
295		&mut self,
296		relay_parent: Hash,
297		events: Vec<CandidateEvent>,
298	) {
299		self.candidate_events.insert(relay_parent, events);
300	}
301
302	pub(crate) fn session_info(&mut self, key: SessionIndex) -> Option<&SessionInfo> {
303		self.session_info.get(&key).map(|v| &*v)
304	}
305
306	pub(crate) fn cache_session_info(&mut self, key: SessionIndex, value: SessionInfo) {
307		self.session_info.insert(key, value);
308	}
309
310	pub(crate) fn session_executor_params(
311		&mut self,
312		session_index: SessionIndex,
313	) -> Option<&Option<ExecutorParams>> {
314		self.session_executor_params.get(&session_index).map(|v| &*v)
315	}
316
317	pub(crate) fn cache_session_executor_params(
318		&mut self,
319		session_index: SessionIndex,
320		value: Option<ExecutorParams>,
321	) {
322		self.session_executor_params.insert(session_index, value);
323	}
324
325	pub(crate) fn dmq_contents(
326		&mut self,
327		key: (Hash, ParaId),
328	) -> Option<&Vec<InboundDownwardMessage<BlockNumber>>> {
329		self.dmq_contents.get(&key).map(|v| &*v)
330	}
331
332	pub(crate) fn cache_dmq_contents(
333		&mut self,
334		key: (Hash, ParaId),
335		value: Vec<InboundDownwardMessage<BlockNumber>>,
336	) {
337		self.dmq_contents.insert(key, value);
338	}
339
340	pub(crate) fn inbound_hrmp_channels_contents(
341		&mut self,
342		key: (Hash, ParaId),
343	) -> Option<&BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>>> {
344		self.inbound_hrmp_channels_contents.get(&key).map(|v| &*v)
345	}
346
347	pub(crate) fn cache_inbound_hrmp_channel_contents(
348		&mut self,
349		key: (Hash, ParaId),
350		value: BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>>,
351	) {
352		self.inbound_hrmp_channels_contents.insert(key, value);
353	}
354
355	pub(crate) fn current_babe_epoch(&mut self, relay_parent: &Hash) -> Option<&Epoch> {
356		self.current_babe_epoch.get(relay_parent).map(|v| &*v)
357	}
358
359	pub(crate) fn cache_current_babe_epoch(&mut self, relay_parent: Hash, epoch: Epoch) {
360		self.current_babe_epoch.insert(relay_parent, epoch);
361	}
362
363	pub(crate) fn on_chain_votes(
364		&mut self,
365		relay_parent: &Hash,
366	) -> Option<&Option<ScrapedOnChainVotes>> {
367		self.on_chain_votes.get(relay_parent).map(|v| &*v)
368	}
369
370	pub(crate) fn cache_on_chain_votes(
371		&mut self,
372		relay_parent: Hash,
373		scraped: Option<ScrapedOnChainVotes>,
374	) {
375		self.on_chain_votes.insert(relay_parent, scraped);
376	}
377
378	pub(crate) fn pvfs_require_precheck(
379		&mut self,
380		relay_parent: &Hash,
381	) -> Option<&Vec<ValidationCodeHash>> {
382		self.pvfs_require_precheck.get(relay_parent).map(|v| &*v)
383	}
384
385	pub(crate) fn cache_pvfs_require_precheck(
386		&mut self,
387		relay_parent: Hash,
388		pvfs: Vec<ValidationCodeHash>,
389	) {
390		self.pvfs_require_precheck.insert(relay_parent, pvfs);
391	}
392
393	pub(crate) fn validation_code_hash(
394		&mut self,
395		key: (Hash, ParaId, OccupiedCoreAssumption),
396	) -> Option<&Option<ValidationCodeHash>> {
397		self.validation_code_hash.get(&key).map(|v| &*v)
398	}
399
400	pub(crate) fn cache_validation_code_hash(
401		&mut self,
402		key: (Hash, ParaId, OccupiedCoreAssumption),
403		value: Option<ValidationCodeHash>,
404	) {
405		self.validation_code_hash.insert(key, value);
406	}
407
408	pub(crate) fn version(&mut self, relay_parent: &Hash) -> Option<&u32> {
409		self.version.get(relay_parent).map(|v| &*v)
410	}
411
412	pub(crate) fn cache_version(&mut self, key: Hash, value: u32) {
413		self.version.insert(key, value);
414	}
415
416	pub(crate) fn disputes(
417		&mut self,
418		relay_parent: &Hash,
419	) -> Option<&Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>> {
420		self.disputes.get(relay_parent).map(|v| &*v)
421	}
422
423	pub(crate) fn cache_disputes(
424		&mut self,
425		relay_parent: Hash,
426		value: Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>,
427	) {
428		self.disputes.insert(relay_parent, value);
429	}
430
431	pub(crate) fn unapplied_slashes(
432		&mut self,
433		relay_parent: &Hash,
434	) -> Option<&Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>> {
435		self.unapplied_slashes.get(relay_parent).map(|v| &*v)
436	}
437
438	pub(crate) fn cache_unapplied_slashes(
439		&mut self,
440		relay_parent: Hash,
441		value: Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>,
442	) {
443		self.unapplied_slashes.insert(relay_parent, value);
444	}
445
446	pub(crate) fn key_ownership_proof(
447		&mut self,
448		key: (Hash, ValidatorId),
449	) -> Option<&Option<slashing::OpaqueKeyOwnershipProof>> {
450		self.key_ownership_proof.get(&key).map(|v| &*v)
451	}
452
453	pub(crate) fn cache_key_ownership_proof(
454		&mut self,
455		key: (Hash, ValidatorId),
456		value: Option<slashing::OpaqueKeyOwnershipProof>,
457	) {
458		self.key_ownership_proof.insert(key, value);
459	}
460
461	// This request is never cached, hence always returns `None`.
462	pub(crate) fn submit_report_dispute_lost(
463		&mut self,
464		_key: (Hash, slashing::DisputeProof, slashing::OpaqueKeyOwnershipProof),
465	) -> Option<&Option<()>> {
466		None
467	}
468
469	pub(crate) fn minimum_backing_votes(&mut self, session_index: SessionIndex) -> Option<u32> {
470		self.minimum_backing_votes.get(&session_index).copied()
471	}
472
473	pub(crate) fn cache_minimum_backing_votes(
474		&mut self,
475		session_index: SessionIndex,
476		minimum_backing_votes: u32,
477	) {
478		self.minimum_backing_votes.insert(session_index, minimum_backing_votes);
479	}
480
481	pub(crate) fn node_features(&mut self, session_index: SessionIndex) -> Option<&NodeFeatures> {
482		self.node_features.get(&session_index).map(|f| &*f)
483	}
484
485	pub(crate) fn cache_node_features(
486		&mut self,
487		session_index: SessionIndex,
488		features: NodeFeatures,
489	) {
490		self.node_features.insert(session_index, features);
491	}
492
493	pub(crate) fn disabled_validators(
494		&mut self,
495		relay_parent: &Hash,
496	) -> Option<&Vec<ValidatorIndex>> {
497		self.disabled_validators.get(relay_parent).map(|v| &*v)
498	}
499
500	pub(crate) fn cache_disabled_validators(
501		&mut self,
502		relay_parent: Hash,
503		disabled_validators: Vec<ValidatorIndex>,
504	) {
505		self.disabled_validators.insert(relay_parent, disabled_validators);
506	}
507
508	pub(crate) fn para_backing_state(
509		&mut self,
510		key: (Hash, ParaId),
511	) -> Option<&Option<async_backing::BackingState>> {
512		self.para_backing_state.get(&key).map(|v| &*v)
513	}
514
515	pub(crate) fn cache_para_backing_state(
516		&mut self,
517		key: (Hash, ParaId),
518		value: Option<async_backing::BackingState>,
519	) {
520		self.para_backing_state.insert(key, value);
521	}
522
523	pub(crate) fn async_backing_params(
524		&mut self,
525		key: &Hash,
526	) -> Option<&async_backing::AsyncBackingParams> {
527		self.async_backing_params.get(key).map(|v| &*v)
528	}
529
530	pub(crate) fn cache_async_backing_params(
531		&mut self,
532		key: Hash,
533		value: async_backing::AsyncBackingParams,
534	) {
535		self.async_backing_params.insert(key, value);
536	}
537
538	pub(crate) fn approval_voting_params(
539		&mut self,
540		key: (Hash, SessionIndex),
541	) -> Option<&ApprovalVotingParams> {
542		self.approval_voting_params.get(&key.1).map(|v| &*v)
543	}
544
545	pub(crate) fn cache_approval_voting_params(
546		&mut self,
547		session_index: SessionIndex,
548		value: ApprovalVotingParams,
549	) {
550		self.approval_voting_params.insert(session_index, value);
551	}
552
553	pub(crate) fn claim_queue(
554		&mut self,
555		relay_parent: &Hash,
556	) -> Option<&BTreeMap<CoreIndex, VecDeque<ParaId>>> {
557		self.claim_queue.get(relay_parent).map(|v| &*v)
558	}
559
560	pub(crate) fn cache_claim_queue(
561		&mut self,
562		relay_parent: Hash,
563		value: BTreeMap<CoreIndex, VecDeque<ParaId>>,
564	) {
565		self.claim_queue.insert(relay_parent, value);
566	}
567
568	pub(crate) fn backing_constraints(
569		&mut self,
570		key: (Hash, ParaId),
571	) -> Option<&Option<Constraints>> {
572		self.backing_constraints.get(&key).map(|v| &*v)
573	}
574
575	pub(crate) fn cache_backing_constraints(
576		&mut self,
577		key: (Hash, ParaId),
578		value: Option<Constraints>,
579	) {
580		self.backing_constraints.insert(key, value);
581	}
582
583	pub(crate) fn scheduling_lookahead(&mut self, session_index: SessionIndex) -> Option<u32> {
584		self.scheduling_lookahead.get(&session_index).copied()
585	}
586
587	pub(crate) fn cache_scheduling_lookahead(
588		&mut self,
589		session_index: SessionIndex,
590		scheduling_lookahead: u32,
591	) {
592		self.scheduling_lookahead.insert(session_index, scheduling_lookahead);
593	}
594
595	/// Cache the validation code bomb limit for a session
596	pub(crate) fn cache_validation_code_bomb_limit(&mut self, session: SessionIndex, limit: u32) {
597		self.validation_code_bomb_limits.insert(session, limit);
598	}
599
600	/// Get the validation code bomb limit for a session if cached
601	pub(crate) fn validation_code_bomb_limit(&mut self, session: SessionIndex) -> Option<u32> {
602		self.validation_code_bomb_limits.get(&session).copied()
603	}
604
605	pub(crate) fn para_ids(&mut self, session_index: SessionIndex) -> Option<&Vec<ParaId>> {
606		self.para_ids.get(&session_index).map(|v| &*v)
607	}
608
609	pub(crate) fn cache_para_ids(&mut self, session_index: SessionIndex, value: Vec<ParaId>) {
610		self.para_ids.insert(session_index, value);
611	}
612}
613
614pub(crate) enum RequestResult {
615	Authorities(Hash, Vec<AuthorityDiscoveryId>),
616	Validators(Hash, Vec<ValidatorId>),
617	MinimumBackingVotes(SessionIndex, u32),
618	ValidatorGroups(Hash, (Vec<Vec<ValidatorIndex>>, GroupRotationInfo)),
619	AvailabilityCores(Hash, Vec<CoreState>),
620	PersistedValidationData(Hash, ParaId, OccupiedCoreAssumption, Option<PersistedValidationData>),
621	AssumedValidationData(
622		Hash,
623		ParaId,
624		Hash,
625		Option<(PersistedValidationData, ValidationCodeHash)>,
626	),
627	CheckValidationOutputs(Hash, ParaId, CandidateCommitments, bool),
628	SessionIndexForChild(Hash, SessionIndex),
629	ValidationCode(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCode>),
630	ValidationCodeByHash(Hash, ValidationCodeHash, Option<ValidationCode>),
631	CandidatePendingAvailability(Hash, ParaId, Option<CommittedCandidateReceipt>),
632	CandidateEvents(Hash, Vec<CandidateEvent>),
633	SessionExecutorParams(Hash, SessionIndex, Option<ExecutorParams>),
634	SessionInfo(Hash, SessionIndex, Option<SessionInfo>),
635	DmqContents(Hash, ParaId, Vec<InboundDownwardMessage<BlockNumber>>),
636	InboundHrmpChannelsContents(
637		Hash,
638		ParaId,
639		BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumber>>>,
640	),
641	CurrentBabeEpoch(Hash, Epoch),
642	FetchOnChainVotes(Hash, Option<ScrapedOnChainVotes>),
643	PvfsRequirePrecheck(Hash, Vec<ValidationCodeHash>),
644	// This is a request with side-effects and no result, hence ().
645	#[allow(dead_code)]
646	SubmitPvfCheckStatement(()),
647	ValidationCodeHash(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCodeHash>),
648	Version(Hash, u32),
649	Disputes(Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>),
650	UnappliedSlashes(Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>),
651	KeyOwnershipProof(Hash, ValidatorId, Option<slashing::OpaqueKeyOwnershipProof>),
652	// This is a request with side-effects.
653	#[allow(dead_code)]
654	SubmitReportDisputeLost(Option<()>),
655	ApprovalVotingParams(Hash, SessionIndex, ApprovalVotingParams),
656	DisabledValidators(Hash, Vec<ValidatorIndex>),
657	ParaBackingState(Hash, ParaId, Option<async_backing::BackingState>),
658	AsyncBackingParams(Hash, async_backing::AsyncBackingParams),
659	NodeFeatures(SessionIndex, NodeFeatures),
660	ClaimQueue(Hash, BTreeMap<CoreIndex, VecDeque<ParaId>>),
661	CandidatesPendingAvailability(Hash, ParaId, Vec<CommittedCandidateReceipt>),
662	BackingConstraints(Hash, ParaId, Option<Constraints>),
663	SchedulingLookahead(SessionIndex, u32),
664	ValidationCodeBombLimit(SessionIndex, u32),
665	ParaIds(SessionIndex, Vec<ParaId>),
666}