diff --git a/crates/pallet-subspace/src/benchmarking.rs b/crates/pallet-subspace/src/benchmarking.rs index 16d0603d6b..85da2df23b 100644 --- a/crates/pallet-subspace/src/benchmarking.rs +++ b/crates/pallet-subspace/src/benchmarking.rs @@ -107,10 +107,7 @@ mod benchmarks { EnableRewards::::take(); #[extrinsic_call] - _( - RawOrigin::Root, - EnableRewardsAt::Height(Some(100u32.into())), - ); + _(RawOrigin::Root, EnableRewardsAt::Height(100u32.into())); assert_eq!(EnableRewards::::get(), Some(100u32.into())); } diff --git a/crates/pallet-subspace/src/lib.rs b/crates/pallet-subspace/src/lib.rs index b5f297986f..5c68ababc0 100644 --- a/crates/pallet-subspace/src/lib.rs +++ b/crates/pallet-subspace/src/lib.rs @@ -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; @@ -278,7 +279,7 @@ pub mod pallet { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum EnableRewardsAt { /// At specified height or next block if `None` - Height(Option), + Height(BlockNumber), /// When solution range is below specified threshold SolutionRange(u64), /// Manually with an explicit extrinsic @@ -307,7 +308,7 @@ pub mod pallet { #[inline] fn default() -> Self { Self { - enable_rewards_at: EnableRewardsAt::Height(None), + enable_rewards_at: EnableRewardsAt::Height(BlockNumberFor::::one()), allow_authoring_by: AllowAuthoringBy::Anyone, pot_slot_iterations: NonZeroU32::MIN, phantom: PhantomData, @@ -322,10 +323,8 @@ pub mod pallet { { fn build(&self) { match self.enable_rewards_at { - EnableRewardsAt::Height(maybe_block_number) => { - EnableRewards::::put( - maybe_block_number.unwrap_or_else(sp_runtime::traits::One::one), - ); + EnableRewardsAt::Height(block_number) => { + EnableRewards::::put(block_number); } EnableRewardsAt::SolutionRange(solution_range) => { EnableRewardsBelowSolutionRange::::put(solution_range); @@ -1122,16 +1121,12 @@ impl Pallet { } 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::::current_block_number() + One::one(); - EnableRewards::::put( - maybe_block_number - .unwrap_or(next_block_number) - .max(next_block_number), - ); + EnableRewards::::put(block_number.max(next_block_number)); } EnableRewardsAt::SolutionRange(solution_range) => { EnableRewardsBelowSolutionRange::::put(solution_range); diff --git a/crates/pallet-subspace/src/mock.rs b/crates/pallet-subspace/src/mock.rs index ef665d8bc4..a696b63bc9 100644 --- a/crates/pallet-subspace/src/mock.rs +++ b/crates/pallet-subspace/src/mock.rs @@ -250,7 +250,7 @@ pub fn new_test_ext(pot_extension: PotExtension) -> TestExternalities { .unwrap(); pallet_subspace::GenesisConfig:: { - 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, diff --git a/crates/pallet-subspace/src/tests.rs b/crates/pallet-subspace/src/tests.rs index 933d0f27be..0b7c0f118c 100644 --- a/crates/pallet-subspace/src/tests.rs +++ b/crates/pallet-subspace/src/tests.rs @@ -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::::current_block_number() + 1, - )), + EnableRewardsAt::Height(frame_system::Pallet::::current_block_number() + 1,), )); // No rewards yet assert_matches!(Subspace::find_block_reward_address(), None); diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index bacffe350b..25a58197c9 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -1534,8 +1534,9 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + fn get_preset(_id: &Option) -> Option> { + // By passing `None` the upstream `get_preset` will return the default value of `RuntimeGenesisConfig` + get_preset::(&None, |_| None) } fn preset_names() -> Vec {