Skip to content

Commit 1d1f852

Browse files
committed
Add disabled_validators in staging runtime api
1 parent dcda0e5 commit 1d1f852

File tree

8 files changed

+66
-2
lines changed

8 files changed

+66
-2
lines changed

polkadot/node/core/runtime-api/src/cache.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub(crate) struct RequestResultCache {
6565
LruMap<Hash, Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>>,
6666
key_ownership_proof:
6767
LruMap<(Hash, ValidatorId), Option<vstaging::slashing::OpaqueKeyOwnershipProof>>,
68+
disabled_validators: LruCache<Hash, Vec<ValidatorIndex>>,
6869

6970
staging_para_backing_state: LruMap<(Hash, ParaId), Option<vstaging::BackingState>>,
7071
staging_async_backing_params: LruMap<Hash, vstaging::AsyncBackingParams>,
@@ -97,6 +98,7 @@ impl Default for RequestResultCache {
9798
disputes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
9899
unapplied_slashes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
99100
key_ownership_proof: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
101+
disabled_validators: LruCache::new(DEFAULT_CACHE_CAP),
100102

101103
staging_para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
102104
staging_async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
@@ -434,6 +436,21 @@ impl RequestResultCache {
434436
None
435437
}
436438

439+
pub(crate) fn disabled_validators(
440+
&mut self,
441+
relay_parent: &Hash,
442+
) -> Option<&Vec<ValidatorIndex>> {
443+
self.disabled_validators.get(relay_parent)
444+
}
445+
446+
pub(crate) fn cache_disabled_validators(
447+
&mut self,
448+
relay_parent: Hash,
449+
disabled_validators: Vec<ValidatorIndex>,
450+
) {
451+
self.disabled_validators.put(relay_parent, disabled_validators);
452+
}
453+
437454
pub(crate) fn staging_para_backing_state(
438455
&mut self,
439456
key: (Hash, ParaId),
@@ -509,6 +526,7 @@ pub(crate) enum RequestResult {
509526
vstaging::slashing::OpaqueKeyOwnershipProof,
510527
Option<()>,
511528
),
529+
DisabledValidators(Hash, Vec<ValidatorIndex>),
512530

513531
StagingParaBackingState(Hash, ParaId, Option<vstaging::BackingState>),
514532
StagingAsyncBackingParams(Hash, vstaging::AsyncBackingParams),

polkadot/node/core/runtime-api/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ where
163163
.requests_cache
164164
.cache_key_ownership_proof((relay_parent, validator_id), key_ownership_proof),
165165
SubmitReportDisputeLost(_, _, _, _) => {},
166+
DisabledValidators(relay_parent, disabled_validators) =>
167+
self.requests_cache.cache_disabled_validators(relay_parent, disabled_validators),
166168

167169
StagingParaBackingState(relay_parent, para_id, constraints) => self
168170
.requests_cache
@@ -294,6 +296,8 @@ where
294296
Request::SubmitReportDisputeLost(dispute_proof, key_ownership_proof, sender)
295297
},
296298
),
299+
Request::DisabledValidators(sender) => query!(disabled_validators(), sender)
300+
.map(|sender| Request::DisabledValidators(sender)),
297301

298302
Request::StagingParaBackingState(para, sender) =>
299303
query!(staging_para_backing_state(para), sender)
@@ -551,6 +555,12 @@ where
551555
ver = Request::SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT,
552556
sender
553557
),
558+
Request::DisabledValidators(sender) => query!(
559+
DisabledValidators,
560+
disabled_validators(),
561+
ver = Request::DISABLED_VALIDATORS_RUNTIME_REQUIREMENT,
562+
sender
563+
),
554564

555565
Request::StagingParaBackingState(para, sender) => {
556566
query!(

polkadot/node/subsystem-types/src/messages.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ pub enum RuntimeApiRequest {
691691
slashing::OpaqueKeyOwnershipProof,
692692
RuntimeApiSender<Option<()>>,
693693
),
694+
/// Returns all disabled validators at a given block height.
695+
/// `V6`
696+
DisabledValidators(RuntimeApiSender<Vec<ValidatorIndex>>),
694697

695698
/// Get the backing state of the given para.
696699
/// This is a staging API that will not be available on production runtimes.
@@ -719,6 +722,9 @@ impl RuntimeApiRequest {
719722
/// `SubmitReportDisputeLost`
720723
pub const SUBMIT_REPORT_DISPUTE_LOST_RUNTIME_REQUIREMENT: u32 = 5;
721724

725+
/// `DisabledValidators`
726+
pub const DISABLED_VALIDATORS_RUNTIME_REQUIREMENT: u32 = 6;
727+
722728
/// Minimum version for backing state, required for async backing.
723729
///
724730
/// 99 for now, should be adjusted to VSTAGING/actual runtime version once released.

polkadot/node/subsystem-types/src/runtime_client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ pub trait RuntimeApiSubsystemClient {
232232
session_index: SessionIndex,
233233
) -> Result<Option<ExecutorParams>, ApiError>;
234234

235+
/// Gets the disabled validators at a specific block height
236+
async fn disabled_validators(&self, at: Hash) -> Result<Vec<ValidatorIndex>, ApiError>;
237+
235238
// === Asynchronous backing API ===
236239

237240
/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
@@ -473,6 +476,10 @@ where
473476
runtime_api.submit_report_dispute_lost(at, dispute_proof, key_ownership_proof)
474477
}
475478

479+
async fn disabled_validators(&self, at: Hash) -> Result<Vec<ValidatorIndex>, ApiError> {
480+
self.client.runtime_api().disabled_validators(at)
481+
}
482+
476483
async fn staging_para_backing_state(
477484
&self,
478485
at: Hash,

polkadot/node/subsystem-util/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ specialize_requests! {
226226
fn request_unapplied_slashes() -> Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>; UnappliedSlashes;
227227
fn request_key_ownership_proof(validator_id: ValidatorId) -> Option<slashing::OpaqueKeyOwnershipProof>; KeyOwnershipProof;
228228
fn request_submit_report_dispute_lost(dp: slashing::DisputeProof, okop: slashing::OpaqueKeyOwnershipProof) -> Option<()>; SubmitReportDisputeLost;
229+
fn request_disabled_validators() -> Vec<ValidatorIndex>; DisabledValidators;
229230

230231
fn request_staging_async_backing_params() -> vstaging_primitives::AsyncBackingParams; StagingAsyncBackingParams;
231232
}

polkadot/primitives/src/runtime_api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ sp_api::decl_runtime_apis! {
240240
key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof,
241241
) -> Option<()>;
242242

243+
/* Staging APIs */
244+
245+
/// Returns a sorted Vec with the `ValidatorIndex` of all disabled validators.
246+
#[api_version(6)]
247+
fn disabled_validators() -> Vec<ValidatorIndex>;
248+
243249
/***** Asynchronous backing *****/
244250

245251
/// Returns the state of parachain backing for a given para.

polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use primitives::{
2323
AsyncBackingParams, BackingState, CandidatePendingAvailability, Constraints,
2424
InboundHrmpLimitations, OutboundHrmpChannelLimitations,
2525
},
26-
Id as ParaId,
26+
Id as ParaId, ValidatorIndex,
2727
};
2828
use sp_std::prelude::*;
2929

@@ -118,3 +118,12 @@ pub fn backing_state<T: initializer::Config>(
118118
pub fn async_backing_params<T: configuration::Config>() -> AsyncBackingParams {
119119
<configuration::Pallet<T>>::config().async_backing_params
120120
}
121+
122+
/// Implementation for `DisabledValidators`
123+
pub fn disabled_validators<T: pallet_session::Config>() -> Vec<ValidatorIndex> {
124+
<pallet_session::Pallet<T>>::disabled_validators()
125+
.iter()
126+
.cloned()
127+
.map(|v| ValidatorIndex(v))
128+
.collect()
129+
}

polkadot/runtime/rococo/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ use runtime_parachains::{
4646
inclusion::{AggregateMessageOrigin, UmpQueueId},
4747
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
4848
paras_inherent as parachains_paras_inherent,
49-
runtime_api_impl::v5 as parachains_runtime_api_impl,
49+
runtime_api_impl::{
50+
v5 as parachains_runtime_api_impl, vstaging as parachains_staging_runtime_api_impl,
51+
},
5052
scheduler as parachains_scheduler, session_info as parachains_session_info,
5153
shared as parachains_shared,
5254
};
@@ -1714,6 +1716,7 @@ sp_api::impl_runtime_apis! {
17141716
}
17151717
}
17161718

1719+
#[api_version(6)]
17171720
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime {
17181721
fn validators() -> Vec<ValidatorId> {
17191722
parachains_runtime_api_impl::validators::<Runtime>()
@@ -1844,6 +1847,10 @@ sp_api::impl_runtime_apis! {
18441847
key_ownership_proof,
18451848
)
18461849
}
1850+
1851+
fn disabled_validators() -> Vec<ValidatorIndex> {
1852+
parachains_staging_runtime_api_impl::disabled_validators::<Runtime>()
1853+
}
18471854
}
18481855

18491856
#[api_version(3)]

0 commit comments

Comments
 (0)