Unverified Commit 175d7079 authored by Parth's avatar Parth Committed by GitHub
Browse files

Override RuntimeApi::authorities() to include past sessions (#2494)



* override authorities runtime call

* addressing feedback

* addressing feedback and restoring semantics

* updated helper function

* naming convention + comment
Co-authored-by: default avatarParity <parity2305@gmail.com>
parent aaea3a28
Pipeline #125412 canceled with stages
in 24 minutes and 39 seconds
......@@ -25,11 +25,12 @@ use primitives::v1::{
Id as ParaId, OccupiedCoreAssumption, SessionIndex, ValidationCode,
CommittedCandidateReceipt, ScheduledCore, OccupiedCore, CoreOccupied, CoreIndex,
GroupIndex, CandidateEvent, PersistedValidationData, SessionInfo,
InboundDownwardMessage, InboundHrmpMessage, Hash,
InboundDownwardMessage, InboundHrmpMessage, Hash, AuthorityDiscoveryId
};
use frame_support::debug;
use crate::{initializer, inclusion, scheduler, configuration, paras, session_info, dmp, hrmp, shared};
/// Implementation for the `validators` function of the runtime API.
pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
<inclusion::Module<T>>::validators()
......@@ -231,6 +232,27 @@ pub fn session_index_for_child<T: initializer::Config>() -> SessionIndex {
<shared::Module<T>>::session_index()
}
/// Implementation for the `AuthorityDiscoveryApi::authorities()` function of the runtime API.
/// It is a heavy call, but currently only used for authority discovery, so it is fine.
/// Gets next, current and some historical authority ids using session_info module.
pub fn relevant_authority_ids<T: initializer::Config + pallet_authority_discovery::Config>() -> Vec<AuthorityDiscoveryId> {
let current_session_index = session_index_for_child::<T>();
let earliest_stored_session = <session_info::Module<T>>::earliest_stored_session();
let mut authority_ids = <pallet_authority_discovery::Module<T>>::next_authorities();
for session_index in earliest_stored_session..=current_session_index {
let info = <session_info::Module<T>>::session_info(session_index);
if let Some(mut info) = info {
authority_ids.append(&mut info.discovery_keys);
}
}
authority_ids.sort();
authority_ids.dedup();
authority_ids
}
/// Implementation for the `validation_code` function of the runtime API.
pub fn validation_code<T: initializer::Config>(
para_id: ParaId,
......
......@@ -849,7 +849,7 @@ sp_api::impl_runtime_apis! {
impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
AuthorityDiscovery::authorities()
runtime_api_impl::relevant_authority_ids::<Runtime>()
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment