Skip to content

Commit 7aace06

Browse files
tdimitrovordianordian
authored
Disabled validators runtime API (#1257)
Exposes disabled validators list via a runtime API. --------- Co-authored-by: ordian <[email protected]> Co-authored-by: ordian <[email protected]>
1 parent f0e6d2a commit 7aace06

File tree

13 files changed

+115
-8
lines changed

13 files changed

+115
-8
lines changed

cumulus/client/relay-chain-minimal-node/src/blockchain_rpc_client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient {
346346
Ok(self.rpc_client.parachain_host_minimum_backing_votes(at, session_index).await?)
347347
}
348348

349+
async fn disabled_validators(
350+
&self,
351+
at: Hash,
352+
) -> Result<Vec<polkadot_primitives::ValidatorIndex>, ApiError> {
353+
Ok(self.rpc_client.parachain_host_disabled_validators(at).await?)
354+
}
355+
349356
async fn async_backing_params(&self, at: Hash) -> Result<AsyncBackingParams, ApiError> {
350357
Ok(self.rpc_client.parachain_host_async_backing_params(at).await?)
351358
}

cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,14 @@ impl RelayChainRpcClient {
597597
.await
598598
}
599599

600+
pub async fn parachain_host_disabled_validators(
601+
&self,
602+
at: RelayHash,
603+
) -> Result<Vec<ValidatorIndex>, RelayChainError> {
604+
self.call_remote_runtime_function("ParachainHost_disabled_validators", at, None::<()>)
605+
.await
606+
}
607+
600608
#[allow(missing_docs)]
601609
pub async fn parachain_host_async_backing_params(
602610
&self,

cumulus/parachains/integration-tests/emulated/common/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use xcm_emulator::{
3333
};
3434

3535
decl_test_relay_chains! {
36-
#[api_version(7)]
36+
#[api_version(8)]
3737
pub struct Westend {
3838
genesis = westend::genesis(),
3939
on_init = (),
@@ -50,7 +50,7 @@ decl_test_relay_chains! {
5050
AssetRate: westend_runtime::AssetRate,
5151
}
5252
},
53-
#[api_version(7)]
53+
#[api_version(8)]
5454
pub struct Rococo {
5555
genesis = rococo::genesis(),
5656
on_init = (),
@@ -65,7 +65,7 @@ decl_test_relay_chains! {
6565
Balances: rococo_runtime::Balances,
6666
}
6767
},
68-
#[api_version(7)]
68+
#[api_version(8)]
6969
pub struct Wococo {
7070
genesis = rococo::genesis(),
7171
on_init = (),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub(crate) struct RequestResultCache {
6464
unapplied_slashes: LruMap<Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>>,
6565
key_ownership_proof: LruMap<(Hash, ValidatorId), Option<slashing::OpaqueKeyOwnershipProof>>,
6666
minimum_backing_votes: LruMap<SessionIndex, u32>,
67+
disabled_validators: LruMap<Hash, Vec<ValidatorIndex>>,
6768
para_backing_state: LruMap<(Hash, ParaId), Option<async_backing::BackingState>>,
6869
async_backing_params: LruMap<Hash, async_backing::AsyncBackingParams>,
6970
}
@@ -96,6 +97,7 @@ impl Default for RequestResultCache {
9697
unapplied_slashes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
9798
key_ownership_proof: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
9899
minimum_backing_votes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
100+
disabled_validators: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
99101
para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
100102
async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
101103
}
@@ -444,6 +446,21 @@ impl RequestResultCache {
444446
self.minimum_backing_votes.insert(session_index, minimum_backing_votes);
445447
}
446448

449+
pub(crate) fn disabled_validators(
450+
&mut self,
451+
relay_parent: &Hash,
452+
) -> Option<&Vec<ValidatorIndex>> {
453+
self.disabled_validators.get(relay_parent).map(|v| &*v)
454+
}
455+
456+
pub(crate) fn cache_disabled_validators(
457+
&mut self,
458+
relay_parent: Hash,
459+
disabled_validators: Vec<ValidatorIndex>,
460+
) {
461+
self.disabled_validators.insert(relay_parent, disabled_validators);
462+
}
463+
447464
pub(crate) fn para_backing_state(
448465
&mut self,
449466
key: (Hash, ParaId),
@@ -520,6 +537,7 @@ pub(crate) enum RequestResult {
520537
slashing::OpaqueKeyOwnershipProof,
521538
Option<()>,
522539
),
540+
DisabledValidators(Hash, Vec<ValidatorIndex>),
523541
ParaBackingState(Hash, ParaId, Option<async_backing::BackingState>),
524542
AsyncBackingParams(Hash, async_backing::AsyncBackingParams),
525543
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ where
166166
.requests_cache
167167
.cache_key_ownership_proof((relay_parent, validator_id), key_ownership_proof),
168168
SubmitReportDisputeLost(_, _, _, _) => {},
169+
DisabledValidators(relay_parent, disabled_validators) =>
170+
self.requests_cache.cache_disabled_validators(relay_parent, disabled_validators),
169171
ParaBackingState(relay_parent, para_id, constraints) => self
170172
.requests_cache
171173
.cache_para_backing_state((relay_parent, para_id), constraints),
@@ -296,6 +298,8 @@ where
296298
Request::SubmitReportDisputeLost(dispute_proof, key_ownership_proof, sender)
297299
},
298300
),
301+
Request::DisabledValidators(sender) => query!(disabled_validators(), sender)
302+
.map(|sender| Request::DisabledValidators(sender)),
299303
Request::ParaBackingState(para, sender) => query!(para_backing_state(para), sender)
300304
.map(|sender| Request::ParaBackingState(para, sender)),
301305
Request::AsyncBackingParams(sender) => query!(async_backing_params(), sender)
@@ -565,6 +569,12 @@ where
565569
ver = Request::MINIMUM_BACKING_VOTES_RUNTIME_REQUIREMENT,
566570
sender
567571
),
572+
Request::DisabledValidators(sender) => query!(
573+
DisabledValidators,
574+
disabled_validators(),
575+
ver = Request::DISABLED_VALIDATORS_RUNTIME_REQUIREMENT,
576+
sender
577+
),
568578
Request::ParaBackingState(para, sender) => {
569579
query!(
570580
ParaBackingState,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
268268
async fn minimum_backing_votes(&self, _: Hash, _: SessionIndex) -> Result<u32, ApiError> {
269269
todo!("Not required for tests")
270270
}
271+
272+
async fn disabled_validators(&self, _: Hash) -> Result<Vec<ValidatorIndex>, ApiError> {
273+
todo!("Not required for tests")
274+
}
271275
}
272276

273277
#[test]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ pub enum RuntimeApiRequest {
695695
),
696696
/// Get the minimum required backing votes.
697697
MinimumBackingVotes(SessionIndex, RuntimeApiSender<u32>),
698+
/// Returns all disabled validators at a given block height.
699+
DisabledValidators(RuntimeApiSender<Vec<ValidatorIndex>>),
698700
/// Get the backing state of the given para.
699701
ParaBackingState(ParaId, RuntimeApiSender<Option<async_backing::BackingState>>),
700702
/// Get candidate's acceptance limitations for asynchronous backing for a relay parent.
@@ -726,6 +728,9 @@ impl RuntimeApiRequest {
726728

727729
/// Minimum version to enable asynchronous backing: `AsyncBackingParams` and `ParaBackingState`.
728730
pub const ASYNC_BACKING_STATE_RUNTIME_REQUIREMENT: u32 = 7;
731+
732+
/// `DisabledValidators`
733+
pub const DISABLED_VALIDATORS_RUNTIME_REQUIREMENT: u32 = 8;
729734
}
730735

731736
/// A message to the Runtime API subsystem.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ pub trait RuntimeApiSubsystemClient {
255255
at: Hash,
256256
para_id: Id,
257257
) -> Result<Option<async_backing::BackingState>, ApiError>;
258+
259+
// === v8 ===
260+
/// Gets the disabled validators at a specific block height
261+
async fn disabled_validators(&self, at: Hash) -> Result<Vec<ValidatorIndex>, ApiError>;
258262
}
259263

260264
/// Default implementation of [`RuntimeApiSubsystemClient`] using the client.
@@ -497,11 +501,14 @@ where
497501
self.client.runtime_api().para_backing_state(at, para_id)
498502
}
499503

500-
/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
501504
async fn async_backing_params(
502505
&self,
503506
at: Hash,
504507
) -> Result<async_backing::AsyncBackingParams, ApiError> {
505508
self.client.runtime_api().async_backing_params(at)
506509
}
510+
511+
async fn disabled_validators(&self, at: Hash) -> Result<Vec<ValidatorIndex>, ApiError> {
512+
self.client.runtime_api().disabled_validators(at)
513+
}
507514
}

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
fn request_async_backing_params() -> AsyncBackingParams; AsyncBackingParams;
230231
}
231232

polkadot/primitives/src/runtime_api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ sp_api::decl_runtime_apis! {
248248
#[api_version(6)]
249249
fn minimum_backing_votes() -> u32;
250250

251+
251252
/***** Added in v7: Asynchronous backing *****/
252253

253254
/// Returns the state of parachain backing for a given para.
@@ -257,5 +258,11 @@ sp_api::decl_runtime_apis! {
257258
/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
258259
#[api_version(7)]
259260
fn async_backing_params() -> AsyncBackingParams;
261+
262+
/***** Added in v8 *****/
263+
264+
/// Returns a list of all disabled validators at the given block.
265+
#[api_version(8)]
266+
fn disabled_validators() -> Vec<ValidatorIndex>;
260267
}
261268
}

0 commit comments

Comments
 (0)