Skip to content

Commit

Permalink
Merge pull request #3191 from autonomys/fix-benchmark-genesis-build
Browse files Browse the repository at this point in the history
Fix the consensus chain benchmark command
  • Loading branch information
NingLin-P authored Oct 30, 2024
2 parents a11f4a6 + d56314d commit e12c829
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
5 changes: 1 addition & 4 deletions crates/pallet-subspace/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ mod benchmarks {
EnableRewards::<T>::take();

#[extrinsic_call]
_(
RawOrigin::Root,
EnableRewardsAt::Height(Some(100u32.into())),
);
_(RawOrigin::Root, EnableRewardsAt::Height(100u32.into()));

assert_eq!(EnableRewards::<T>::get(), Some(100u32.into()));
}
Expand Down
19 changes: 7 additions & 12 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub mod pallet {
use sp_consensus_subspace::digests::CompatibleDigestItem;
use sp_consensus_subspace::inherents::{InherentError, InherentType, INHERENT_IDENTIFIER};
use sp_consensus_subspace::SignedVote;
use sp_runtime::traits::One;
use sp_runtime::DigestItem;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::num::NonZeroU32;
Expand Down Expand Up @@ -278,7 +279,7 @@ pub mod pallet {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EnableRewardsAt<BlockNumber> {
/// At specified height or next block if `None`
Height(Option<BlockNumber>),
Height(BlockNumber),
/// When solution range is below specified threshold
SolutionRange(u64),
/// Manually with an explicit extrinsic
Expand Down Expand Up @@ -307,7 +308,7 @@ pub mod pallet {
#[inline]
fn default() -> Self {
Self {
enable_rewards_at: EnableRewardsAt::Height(None),
enable_rewards_at: EnableRewardsAt::Height(BlockNumberFor::<T>::one()),
allow_authoring_by: AllowAuthoringBy::Anyone,
pot_slot_iterations: NonZeroU32::MIN,
phantom: PhantomData,
Expand All @@ -322,10 +323,8 @@ pub mod pallet {
{
fn build(&self) {
match self.enable_rewards_at {
EnableRewardsAt::Height(maybe_block_number) => {
EnableRewards::<T>::put(
maybe_block_number.unwrap_or_else(sp_runtime::traits::One::one),
);
EnableRewardsAt::Height(block_number) => {
EnableRewards::<T>::put(block_number);
}
EnableRewardsAt::SolutionRange(solution_range) => {
EnableRewardsBelowSolutionRange::<T>::put(solution_range);
Expand Down Expand Up @@ -1122,16 +1121,12 @@ impl<T: Config> Pallet<T> {
}

match enable_rewards_at {
EnableRewardsAt::Height(maybe_block_number) => {
EnableRewardsAt::Height(block_number) => {
// Enable rewards at a particular block height (default to the next block after
// this)
let next_block_number =
frame_system::Pallet::<T>::current_block_number() + One::one();
EnableRewards::<T>::put(
maybe_block_number
.unwrap_or(next_block_number)
.max(next_block_number),
);
EnableRewards::<T>::put(block_number.max(next_block_number));
}
EnableRewardsAt::SolutionRange(solution_range) => {
EnableRewardsBelowSolutionRange::<T>::put(solution_range);
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-subspace/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ pub fn new_test_ext(pot_extension: PotExtension) -> TestExternalities {
.unwrap();

pallet_subspace::GenesisConfig::<Test> {
enable_rewards_at: EnableRewardsAt::Height(Some(1)),
enable_rewards_at: EnableRewardsAt::Height(1),
allow_authoring_by: AllowAuthoringBy::Anyone,
pot_slot_iterations: NonZeroU32::new(100_000).unwrap(),
phantom: PhantomData,
Expand Down
4 changes: 1 addition & 3 deletions crates/pallet-subspace/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,7 @@ fn enabling_block_rewards_works() {
// Enable since next block only rewards
assert_ok!(Subspace::enable_rewards_at(
RuntimeOrigin::root(),
EnableRewardsAt::Height(Some(
frame_system::Pallet::<Test>::current_block_number() + 1,
)),
EnableRewardsAt::Height(frame_system::Pallet::<Test>::current_block_number() + 1,),
));
// No rewards yet
assert_matches!(Subspace::find_block_reward_address(), None);
Expand Down
5 changes: 3 additions & 2 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,9 @@ impl_runtime_apis! {
build_state::<RuntimeGenesisConfig>(config)
}

fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
get_preset::<RuntimeGenesisConfig>(id, |_| None)
fn get_preset(_id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> {
// By passing `None` the upstream `get_preset` will return the default value of `RuntimeGenesisConfig`
get_preset::<RuntimeGenesisConfig>(&None, |_| None)
}

fn preset_names() -> Vec<sp_genesis_builder::PresetId> {
Expand Down

0 comments on commit e12c829

Please sign in to comment.