Skip to content

Commit

Permalink
fix(runtime): Fix staking payout call weight; impl test (#4218)
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Sep 3, 2024
1 parent c1dd6f1 commit 007cce6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/src/pallet_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ macro_rules! impl_pallet_staking_inner {
// 8 eras for unbonding
pub const BondingDuration: u32 = 8;
pub const SlashDeferDuration: u32 = 7;
pub const MaxExposurePageSize: u32 = 512;
pub const MaxExposurePageSize: u32 = 256;
pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17);
pub const HistoryDepth: u32 = 84;
pub const MaxNominations: u32 = 16;
Expand Down
2 changes: 1 addition & 1 deletion runtime/vara/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ parameter_types! {
pub const BondingDuration: sp_staking::EraIndex = 14;
// 41 eras during which slashes can be cancelled (slightly less than 7 days)
pub const SlashDeferDuration: sp_staking::EraIndex = 13;
pub const MaxExposurePageSize: u32 = 512;
pub const MaxExposurePageSize: u32 = 256;
// Note: this is not really correct as Max Nominators is (MaxExposurePageSize * page_count) but
// this is an unbounded number. We just set it to a reasonably high value, 1 full page
// of nominators.
Expand Down
37 changes: 36 additions & 1 deletion runtime/vara/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

use super::*;
use crate::Runtime;
use frame_support::traits::StorageInstance;
use frame_support::{dispatch::GetDispatchInfo, traits::StorageInstance};
use frame_system::limits::WeightsPerClass;
use gear_core::costs::LazyPagesCosts;
use pallet_gear::{InstructionWeights, MemoryWeights, SyscallWeights};
use pallet_staking::WeightInfo as _;
use runtime_common::weights::{
check_instructions_weights, check_lazy_pages_costs, check_pages_costs, check_syscall_weights,
PagesCosts,
};
use sp_runtime::AccountId32;

#[cfg(feature = "dev")]
#[test]
Expand Down Expand Up @@ -71,6 +74,38 @@ fn bridge_session_timer_is_correct() {
);
}

#[test]
fn payout_stakers_fits_in_block() {
let expected_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
<Runtime as pallet_staking::Config>::MaxExposurePageSize::get(),
);

let call: <Runtime as frame_system::Config>::RuntimeCall =
RuntimeCall::Staking(pallet_staking::Call::payout_stakers {
validator_stash: AccountId32::new(Default::default()),
era: Default::default(),
});

let dispatch_info = call.get_dispatch_info();

assert_eq!(dispatch_info.class, DispatchClass::Normal);
assert_eq!(dispatch_info.weight, expected_weight);

let block_weights = <Runtime as frame_system::Config>::BlockWeights::get();

let normal_class_weights: WeightsPerClass =
block_weights.per_class.get(DispatchClass::Normal).clone();

let normal_ref_time = normal_class_weights
.max_extrinsic
.unwrap_or(Weight::MAX)
.ref_time();
let base_weight = normal_class_weights.base_extrinsic.ref_time();

assert!(normal_ref_time - base_weight > expected_weight.ref_time());
}

#[test]
fn normal_dispatch_length_suits_minimal() {
const MB: u32 = 1024 * 1024;
Expand Down

0 comments on commit 007cce6

Please sign in to comment.