Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled validators runtime API #1257

Merged
merged 13 commits into from
Oct 12, 2023
1 change: 0 additions & 1 deletion polkadot/node/subsystem-types/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ pub trait RuntimeApiSubsystemClient {
session_index: SessionIndex,
) -> Result<u32, ApiError>;


// === v7: Asynchronous backing API ===

/// Returns candidate's acceptance limitations for asynchronous backing for a relay parent.
Expand Down
34 changes: 22 additions & 12 deletions polkadot/runtime/parachains/src/runtime_api_impl/vstaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,28 @@

//! Put implementations of functions from staging APIs here.

use primitives::{
ValidatorIndex,
};
use sp_std::prelude::*;
use crate::shared;
use primitives::ValidatorIndex;
use sp_std::prelude::Vec;
use sp_std::collections::btree_map::BTreeMap;

/// Implementation for `DisabledValidators`
pub fn disabled_validators<T: pallet_session::Config>() -> Vec<ValidatorIndex> {
// <pallet_session::Pallet<T>>::disabled_validators()
// .iter()
// .cloned()
// .map(|v| ValidatorIndex(v))
// .collect()
// TODO
Vec::new()
pub fn disabled_validators<T>() -> Vec<ValidatorIndex>
where
T: pallet_session::Config + shared::Config,
{
let shuffled_indices = <shared::Pallet<T>>::active_validator_indices();
// mapping from raw validator index to `ValidatorIndex`
Overkillus marked this conversation as resolved.
Show resolved Hide resolved
// this computation is the same within a session, but should be cheap
let reverse_index = shuffled_indices
.iter()
.enumerate()
.map(|(i, v)| (v.0, ValidatorIndex(i as u32)))
.collect::<BTreeMap<u32, ValidatorIndex>>();

// we might have disabled validators who are not parachain validators
<pallet_session::Pallet<T>>::disabled_validators()
Overkillus marked this conversation as resolved.
Show resolved Hide resolved
.iter()
.filter_map(|v| reverse_index.get(v).cloned())
.collect()
}