mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 18:11:10 +00:00
Disabled validators runtime API (#1257)
Exposes disabled validators list via a runtime API. --------- Co-authored-by: ordian <noreply@reusable.software> Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
committed by
GitHub
parent
f0e6d2ad52
commit
7aace06b3d
@@ -15,3 +15,30 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Put implementations of functions from staging APIs here.
|
||||
|
||||
use crate::shared;
|
||||
use primitives::ValidatorIndex;
|
||||
use sp_std::{collections::btree_map::BTreeMap, prelude::Vec};
|
||||
|
||||
/// Implementation for `DisabledValidators`
|
||||
// CAVEAT: this should only be called on the node side
|
||||
// as it might produce incorrect results on session boundaries
|
||||
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`
|
||||
// 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()
|
||||
.iter()
|
||||
.filter_map(|v| reverse_index.get(v).cloned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -49,7 +49,9 @@ use runtime_parachains::{
|
||||
inclusion::{AggregateMessageOrigin, UmpQueueId},
|
||||
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
|
||||
paras_inherent as parachains_paras_inherent,
|
||||
runtime_api_impl::v7 as parachains_runtime_api_impl,
|
||||
runtime_api_impl::{
|
||||
v7 as parachains_runtime_api_impl, vstaging as parachains_staging_runtime_api_impl,
|
||||
},
|
||||
scheduler as parachains_scheduler, session_info as parachains_session_info,
|
||||
shared as parachains_shared,
|
||||
};
|
||||
@@ -1585,7 +1587,7 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
#[api_version(7)]
|
||||
#[api_version(8)]
|
||||
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime {
|
||||
fn validators() -> Vec<ValidatorId> {
|
||||
parachains_runtime_api_impl::validators::<Runtime>()
|
||||
@@ -1728,6 +1730,11 @@ sp_api::impl_runtime_apis! {
|
||||
fn async_backing_params() -> primitives::AsyncBackingParams {
|
||||
parachains_runtime_api_impl::async_backing_params::<Runtime>()
|
||||
}
|
||||
|
||||
fn disabled_validators() -> Vec<ValidatorIndex> {
|
||||
parachains_staging_runtime_api_impl::disabled_validators::<Runtime>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[api_version(3)]
|
||||
|
||||
@@ -70,7 +70,9 @@ use runtime_parachains::{
|
||||
inclusion::{AggregateMessageOrigin, UmpQueueId},
|
||||
initializer as parachains_initializer, origin as parachains_origin, paras as parachains_paras,
|
||||
paras_inherent as parachains_paras_inherent, reward_points as parachains_reward_points,
|
||||
runtime_api_impl::v7 as parachains_runtime_api_impl,
|
||||
runtime_api_impl::{
|
||||
v7 as parachains_runtime_api_impl, vstaging as parachains_staging_runtime_api_impl,
|
||||
},
|
||||
scheduler as parachains_scheduler, session_info as parachains_session_info,
|
||||
shared as parachains_shared,
|
||||
};
|
||||
@@ -1695,7 +1697,7 @@ sp_api::impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
#[api_version(7)]
|
||||
#[api_version(8)]
|
||||
impl primitives::runtime_api::ParachainHost<Block, Hash, BlockNumber> for Runtime {
|
||||
fn validators() -> Vec<ValidatorId> {
|
||||
parachains_runtime_api_impl::validators::<Runtime>()
|
||||
@@ -1838,6 +1840,10 @@ sp_api::impl_runtime_apis! {
|
||||
fn async_backing_params() -> primitives::AsyncBackingParams {
|
||||
parachains_runtime_api_impl::async_backing_params::<Runtime>()
|
||||
}
|
||||
|
||||
fn disabled_validators() -> Vec<ValidatorIndex> {
|
||||
parachains_staging_runtime_api_impl::disabled_validators::<Runtime>()
|
||||
}
|
||||
}
|
||||
|
||||
impl beefy_primitives::BeefyApi<Block, BeefyId> for Runtime {
|
||||
|
||||
Reference in New Issue
Block a user