Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

auto force authoring when runtime change #54

Merged
merged 1 commit into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion nimbus-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,28 @@ where
relay_parent: PHash,
validation_data: &PersistedValidationData,
) -> Option<ParachainCandidate<B>> {
let maybe_key = if self.skip_prediction {
// Determine if runtime change
let runtime_upgraded = if *parent.number() > sp_runtime::traits::Zero::zero() {
let at = BlockId::Hash(parent.hash());
let parent_at = BlockId::<B>::Hash(*parent.parent_hash());
use sp_api::Core as _;
let previous_runtime_version: sp_api::RuntimeVersion = self
.parachain_client
.runtime_api()
.version(&parent_at)
.expect("Runtime api access to not error.");
let runtime_version: sp_api::RuntimeVersion = self
.parachain_client
.runtime_api()
.version(&at)
.expect("Runtime api access to not error.");

previous_runtime_version != runtime_version
} else {
false
};

let maybe_key = if self.skip_prediction || runtime_upgraded {
first_available_key(&*self.keystore)
} else {
first_eligible_key::<B, ParaClient>(
Expand Down
4 changes: 2 additions & 2 deletions nimbus-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use sp_application_crypto::KeyTypeId;
use sp_runtime::traits::BlockNumberProvider;
use sp_runtime::ConsensusEngineId;
use sp_std::vec::Vec;
#[cfg(feature = "runtime-benchmarks")]
use sp_std::vec;
use sp_std::vec::Vec;

pub mod digests;
mod inherents;
Expand Down Expand Up @@ -94,7 +94,7 @@ pub trait CanAuthor<AuthorId> {
vec![]
}
#[cfg(feature = "runtime-benchmarks")]
fn set_eligible_author(_slot: &u32) {}
fn set_eligible_author(_slot: &u32) {}
}
/// Default implementation where anyone can author.
///
Expand Down
2 changes: 1 addition & 1 deletion pallets/author-inherent/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![cfg(feature = "runtime-benchmarks")]

use crate::{Call, Config, Pallet};
use frame_benchmarking::{benchmarks};
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;
use nimbus_primitives::CanAuthor;
use nimbus_primitives::SlotBeacon;
Expand Down
2 changes: 1 addition & 1 deletion pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub mod weights;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use crate::weights::WeightInfo;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use crate::weights::WeightInfo;

/// The Author Inherent pallet. The core of the nimbus consensus framework's runtime presence.
#[pallet::pallet]
Expand Down
9 changes: 4 additions & 5 deletions pallets/author-slot-filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ pub mod pallet {
eligible.contains(author)
}
#[cfg(feature = "runtime-benchmarks")]
fn get_authors(slot: &u32) -> Vec<T::AccountId> {
// Compute pseudo-random subset of potential authors
let (eligible, _) =
compute_pseudo_random_subset::<T>(T::PotentialAuthors::get(), slot);
eligible
fn get_authors(slot: &u32) -> Vec<T::AccountId> {
// Compute pseudo-random subset of potential authors
let (eligible, _) = compute_pseudo_random_subset::<T>(T::PotentialAuthors::get(), slot);
eligible
}
}

Expand Down