mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Properly set the max proof size weight on defaults and tests (#12383)
* Properly set the max proof size weight on defaults and tests * cargo fmt * Set proper max proof size for contracts pallet tests * Properly set max proof size for node * Properly set max proof size for frame system mock * Update test expectations * Update test expectations * Properly set max proof size for balances mock * Update test expectations * Update test expectations * Properly set max proof size for democracy mock * Properly set max proof size for scheduler mock * Properly set max proof size for fast unstake mock * Properly set max proof size for tx payment mock * Properly set max proof size for elections phragmen mock * Properly set max proof size for node template
This commit is contained in:
@@ -139,8 +139,11 @@ parameter_types! {
|
||||
pub const BlockHashCount: BlockNumber = 2400;
|
||||
pub const Version: RuntimeVersion = VERSION;
|
||||
/// We allow for 2 seconds of compute with a 6 second average block time.
|
||||
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
|
||||
::with_sensible_defaults(2u64 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::with_sensible_defaults(
|
||||
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
|
||||
NORMAL_DISPATCH_RATIO,
|
||||
);
|
||||
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
|
||||
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||
pub const SS58Prefix: u8 = 42;
|
||||
|
||||
@@ -224,7 +224,7 @@ mod multiplier_tests {
|
||||
fn multiplier_can_grow_from_zero() {
|
||||
// if the min is too small, then this will not change, and we are doomed forever.
|
||||
// the weight is 1/100th bigger than target.
|
||||
run_with_system_weight(target() * 101 / 100, || {
|
||||
run_with_system_weight(target().set_ref_time(target().ref_time() * 101 / 100), || {
|
||||
let next = runtime_multiplier_update(min_multiplier());
|
||||
assert!(next > min_multiplier(), "{:?} !>= {:?}", next, min_multiplier());
|
||||
})
|
||||
|
||||
@@ -170,8 +170,8 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
|
||||
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
|
||||
/// by Operational extrinsics.
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
/// We allow for 2 seconds of compute with a 6 second average block time.
|
||||
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);
|
||||
/// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size.
|
||||
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(u64::MAX);
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: BlockNumber = 2400;
|
||||
|
||||
@@ -47,7 +47,9 @@ frame_support::construct_runtime!(
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
|
||||
);
|
||||
pub static ExistentialDeposit: u64 = 0;
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -48,7 +48,9 @@ frame_support::construct_runtime!(
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
|
||||
);
|
||||
pub static ExistentialDeposit: u64 = 0;
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -51,7 +51,9 @@ frame_support::construct_runtime!(
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
|
||||
);
|
||||
pub static ExistentialDeposit: u64 = 0;
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -279,7 +279,9 @@ impl RegisteredChainExtension<Test> for TempStorageExtension {
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND);
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
|
||||
);
|
||||
pub static ExistentialDeposit: u64 = 1;
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
@@ -413,7 +415,7 @@ pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
|
||||
pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]);
|
||||
pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]);
|
||||
|
||||
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000);
|
||||
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000).set_proof_size(u64::MAX);
|
||||
|
||||
pub struct ExtBuilder {
|
||||
existential_deposit: u64,
|
||||
@@ -628,7 +630,7 @@ fn deposit_event_max_value_limit() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer,
|
||||
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer,
|
||||
None,
|
||||
<Test as Config>::Schedule::get().limits.payload_len.encode(),
|
||||
));
|
||||
@@ -769,7 +771,7 @@ fn storage_max_value_limit() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
addr.clone(),
|
||||
0,
|
||||
GAS_LIMIT * 2, // we are copying a huge buffer
|
||||
GAS_LIMIT.set_ref_time(GAS_LIMIT.ref_time() * 2), // we are copying a huge buffer
|
||||
None,
|
||||
<Test as Config>::Schedule::get().limits.payload_len.encode(),
|
||||
));
|
||||
@@ -2543,7 +2545,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
ALICE,
|
||||
addr_caller,
|
||||
0,
|
||||
Weight::from_ref_time(result.gas_required),
|
||||
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
|
||||
Some(result.storage_deposit.charge_or_zero()),
|
||||
input,
|
||||
false,
|
||||
@@ -2613,7 +2615,7 @@ fn gas_estimation_call_runtime() {
|
||||
ALICE,
|
||||
addr_caller,
|
||||
0,
|
||||
Weight::from_ref_time(result.gas_required),
|
||||
Weight::from_ref_time(result.gas_required).set_proof_size(u64::MAX),
|
||||
None,
|
||||
call.encode(),
|
||||
false,
|
||||
|
||||
@@ -78,7 +78,9 @@ impl Contains<RuntimeCall> for BaseFilter {
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1_000_000));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
Weight::from_ref_time(1_000_000).set_proof_size(u64::MAX),
|
||||
);
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
type BaseCallFilter = BaseFilter;
|
||||
|
||||
@@ -1011,10 +1011,8 @@ pub mod pallet {
|
||||
// unlikely to ever return an error: if phase is signed, snapshot will exist.
|
||||
let size = Self::snapshot_metadata().ok_or(Error::<T>::MissingSnapshotMetadata)?;
|
||||
|
||||
// TODO: account for proof size weight
|
||||
ensure!(
|
||||
Self::solution_weight_of(&raw_solution, size).ref_time() <
|
||||
T::SignedMaxWeight::get().ref_time(),
|
||||
Self::solution_weight_of(&raw_solution, size).all_lt(T::SignedMaxWeight::get()),
|
||||
Error::<T>::SignedTooMuchWeight,
|
||||
);
|
||||
|
||||
@@ -2342,9 +2340,8 @@ mod tests {
|
||||
};
|
||||
|
||||
let mut active = 1;
|
||||
// TODO: account for proof size weight
|
||||
while weight_with(active).ref_time() <=
|
||||
<Runtime as frame_system::Config>::BlockWeights::get().max_block.ref_time() ||
|
||||
while weight_with(active)
|
||||
.all_lte(<Runtime as frame_system::Config>::BlockWeights::get().max_block) ||
|
||||
active == all_voters
|
||||
{
|
||||
active += 1;
|
||||
|
||||
@@ -26,7 +26,7 @@ pub use frame_support::{assert_noop, assert_ok, pallet_prelude::GetDefault};
|
||||
use frame_support::{
|
||||
bounded_vec, parameter_types,
|
||||
traits::{ConstU32, Hooks},
|
||||
weights::Weight,
|
||||
weights::{constants, Weight},
|
||||
BoundedVec,
|
||||
};
|
||||
use multi_phase::unsigned::{IndexAssignmentOf, VoterOf};
|
||||
@@ -227,7 +227,10 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
parameter_types! {
|
||||
pub const ExistentialDeposit: u64 = 1;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
|
||||
::with_sensible_defaults(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
|
||||
::with_sensible_defaults(
|
||||
Weight::from_components(2u64 * constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX),
|
||||
NORMAL_DISPATCH_RATIO,
|
||||
);
|
||||
}
|
||||
|
||||
impl pallet_balances::Config for Runtime {
|
||||
|
||||
@@ -957,7 +957,7 @@ mod tests {
|
||||
#[test]
|
||||
fn cannot_consume_too_much_future_weight() {
|
||||
ExtBuilder::default()
|
||||
.signed_weight(Weight::from_ref_time(40))
|
||||
.signed_weight(Weight::from_ref_time(40).set_proof_size(u64::MAX))
|
||||
.mock_weight_info(MockedWeightInfo::Basic)
|
||||
.build_and_execute(|| {
|
||||
roll_to(15);
|
||||
@@ -973,11 +973,14 @@ mod tests {
|
||||
// default solution will have 5 edges (5 * 5 + 10)
|
||||
assert_eq!(solution_weight, Weight::from_ref_time(35));
|
||||
assert_eq!(raw.solution.voter_count(), 5);
|
||||
assert_eq!(<Runtime as Config>::SignedMaxWeight::get(), Weight::from_ref_time(40));
|
||||
assert_eq!(
|
||||
<Runtime as Config>::SignedMaxWeight::get(),
|
||||
Weight::from_ref_time(40).set_proof_size(u64::MAX)
|
||||
);
|
||||
|
||||
assert_ok!(MultiPhase::submit(RuntimeOrigin::signed(99), Box::new(raw.clone())));
|
||||
|
||||
<SignedMaxWeight>::set(Weight::from_ref_time(30));
|
||||
<SignedMaxWeight>::set(Weight::from_ref_time(30).set_proof_size(u64::MAX));
|
||||
|
||||
// note: resubmitting the same solution is technically okay as long as the queue has
|
||||
// space.
|
||||
|
||||
@@ -638,8 +638,7 @@ impl<T: MinerConfig> Miner<T> {
|
||||
};
|
||||
|
||||
let next_voters = |current_weight: Weight, voters: u32, step: u32| -> Result<u32, ()> {
|
||||
// TODO: account for proof size weight
|
||||
if current_weight.ref_time() < max_weight.ref_time() {
|
||||
if current_weight.all_lt(max_weight) {
|
||||
let next_voters = voters.checked_add(step);
|
||||
match next_voters {
|
||||
Some(voters) if voters < max_voters => Ok(voters),
|
||||
@@ -674,8 +673,7 @@ impl<T: MinerConfig> Miner<T> {
|
||||
|
||||
// Time to finish. We might have reduced less than expected due to rounding error. Increase
|
||||
// one last time if we have any room left, the reduce until we are sure we are below limit.
|
||||
// TODO: account for proof size weight
|
||||
while voters < max_voters && weight_with(voters + 1).ref_time() < max_weight.ref_time() {
|
||||
while voters < max_voters && weight_with(voters + 1).all_lt(max_weight) {
|
||||
voters += 1;
|
||||
}
|
||||
while voters.checked_sub(1).is_some() && weight_with(voters).any_gt(max_weight) {
|
||||
@@ -683,9 +681,8 @@ impl<T: MinerConfig> Miner<T> {
|
||||
}
|
||||
|
||||
let final_decision = voters.min(size.voters);
|
||||
// TODO: account for proof size weight
|
||||
debug_assert!(
|
||||
weight_with(final_decision).ref_time() <= max_weight.ref_time(),
|
||||
weight_with(final_decision).all_lte(max_weight),
|
||||
"weight_with({}) <= {}",
|
||||
final_decision,
|
||||
max_weight,
|
||||
@@ -703,151 +700,346 @@ mod max_weight {
|
||||
fn find_max_voter_binary_search_works() {
|
||||
let w = SolutionOrSnapshotSize { voters: 10, targets: 0 };
|
||||
MockWeightInfo::set(crate::mock::MockedWeightInfo::Complex);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::zero()), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::zero().set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1990).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2990).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2999).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3000).set_proof_size(u64::MAX)
|
||||
),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(5500)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(5500).set_proof_size(u64::MAX)
|
||||
),
|
||||
5
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(7777)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(7777).set_proof_size(u64::MAX)
|
||||
),
|
||||
7
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(9999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(9999).set_proof_size(u64::MAX)
|
||||
),
|
||||
9
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(10_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(10_999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(10_999).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(11_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(11_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(22_000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(22_000).set_proof_size(u64::MAX)
|
||||
),
|
||||
10
|
||||
);
|
||||
|
||||
let w = SolutionOrSnapshotSize { voters: 1, targets: 0 };
|
||||
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(0).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1990)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1990).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
|
||||
let w = SolutionOrSnapshotSize { voters: 2, targets: 0 };
|
||||
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(0)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1)), 0);
|
||||
assert_eq!(Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(999)), 0);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(0).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(999).set_proof_size(u64::MAX)
|
||||
),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1000).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1001).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(1999)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(1999).set_proof_size(u64::MAX)
|
||||
),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2000)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2000).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2001)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2001).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(2010)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(2010).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
assert_eq!(
|
||||
Miner::<Runtime>::maximum_voter_for_weight(0, w, Weight::from_ref_time(3333)),
|
||||
Miner::<Runtime>::maximum_voter_for_weight(
|
||||
0,
|
||||
w,
|
||||
Weight::from_ref_time(3333).set_proof_size(u64::MAX)
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
@@ -1131,7 +1323,7 @@ mod tests {
|
||||
#[test]
|
||||
fn miner_trims_weight() {
|
||||
ExtBuilder::default()
|
||||
.miner_weight(Weight::from_ref_time(100))
|
||||
.miner_weight(Weight::from_ref_time(100).set_proof_size(u64::MAX))
|
||||
.mock_weight_info(crate::mock::MockedWeightInfo::Basic)
|
||||
.build_and_execute(|| {
|
||||
roll_to(25);
|
||||
@@ -1149,7 +1341,7 @@ mod tests {
|
||||
assert_eq!(raw.solution.voter_count(), 5);
|
||||
|
||||
// now reduce the max weight
|
||||
<MinerMaxWeight>::set(Weight::from_ref_time(25));
|
||||
<MinerMaxWeight>::set(Weight::from_ref_time(25).set_proof_size(u64::MAX));
|
||||
|
||||
let (raw, witness) = MultiPhase::mine_solution().unwrap();
|
||||
let solution_weight = <Runtime as MinerConfig>::solution_weight(
|
||||
|
||||
@@ -1174,7 +1174,9 @@ mod tests {
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
frame_support::weights::Weight::from_ref_time(1024).set_proof_size(u64::MAX),
|
||||
);
|
||||
}
|
||||
|
||||
impl frame_system::Config for Test {
|
||||
|
||||
@@ -459,8 +459,7 @@ where
|
||||
let max_weight = <System::BlockWeights as frame_support::traits::Get<_>>::get().max_block;
|
||||
let remaining_weight = max_weight.saturating_sub(weight.total());
|
||||
|
||||
// TODO: account for proof size weight
|
||||
if remaining_weight.ref_time() > 0 {
|
||||
if remaining_weight.all_gt(Weight::zero()) {
|
||||
let used_weight = <AllPalletsWithSystem as OnIdle<System::BlockNumber>>::on_idle(
|
||||
block_number,
|
||||
remaining_weight,
|
||||
@@ -768,7 +767,7 @@ mod tests {
|
||||
frame_system::limits::BlockWeights::builder()
|
||||
.base_block(Weight::from_ref_time(10))
|
||||
.for_class(DispatchClass::all(), |weights| weights.base_extrinsic = Weight::from_ref_time(5))
|
||||
.for_class(DispatchClass::non_mandatory(), |weights| weights.max_total = Weight::from_ref_time(1024).into())
|
||||
.for_class(DispatchClass::non_mandatory(), |weights| weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into())
|
||||
.build_or_panic();
|
||||
pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight {
|
||||
read: 10,
|
||||
|
||||
@@ -32,7 +32,9 @@ pub type T = Runtime;
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND);
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX),
|
||||
);
|
||||
}
|
||||
|
||||
impl frame_system::Config for Runtime {
|
||||
|
||||
@@ -856,8 +856,7 @@ fn valid_equivocation_reports_dont_pay_fees() {
|
||||
.get_dispatch_info();
|
||||
|
||||
// it should have non-zero weight and the fee has to be paid.
|
||||
// TODO: account for proof size weight
|
||||
assert!(info.weight.ref_time() > 0);
|
||||
assert!(info.weight.any_gt(Weight::zero()));
|
||||
assert_eq!(info.pays_fee, Pays::Yes);
|
||||
|
||||
// report the equivocation.
|
||||
|
||||
@@ -118,7 +118,9 @@ impl Contains<RuntimeCall> for BaseFilter {
|
||||
|
||||
parameter_types! {
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(2_000_000_000_000));
|
||||
frame_system::limits::BlockWeights::simple_max(
|
||||
Weight::from_ref_time(2_000_000_000_000).set_proof_size(u64::MAX),
|
||||
);
|
||||
}
|
||||
impl system::Config for Test {
|
||||
type BaseCallFilter = BaseFilter;
|
||||
|
||||
@@ -310,7 +310,7 @@ mod tests {
|
||||
check(|max, len| {
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(max, len));
|
||||
assert_eq!(System::block_weight().total(), Weight::MAX);
|
||||
assert!(System::block_weight().total().all_gt(block_weight_limit()));
|
||||
assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time());
|
||||
});
|
||||
check(|max, len| {
|
||||
assert_ok!(CheckWeight::<Test>::do_validate(max, len));
|
||||
@@ -367,7 +367,7 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
System::register_extra_weight_unchecked(Weight::MAX, DispatchClass::Normal);
|
||||
assert_eq!(System::block_weight().total(), Weight::MAX);
|
||||
assert!(System::block_weight().total().all_gt(block_weight_limit()));
|
||||
assert!(System::block_weight().total().ref_time() > block_weight_limit().ref_time());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -392,8 +392,8 @@ mod tests {
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
|
||||
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&rest_operational, len));
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
|
||||
assert_eq!(System::block_weight().total(), block_weight_limit());
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
|
||||
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
|
||||
// Checking single extrinsic should not take current block weight into account.
|
||||
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&rest_operational), Ok(()));
|
||||
});
|
||||
@@ -417,8 +417,8 @@ mod tests {
|
||||
// Extra 20 here from block execution + base extrinsic weight
|
||||
assert_eq!(System::block_weight().total(), Weight::from_ref_time(266));
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
|
||||
assert_eq!(System::block_weight().total(), block_weight_limit());
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
|
||||
assert_eq!(System::block_weight().total(), block_weight_limit().set_proof_size(0));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -669,7 +669,7 @@ mod tests {
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&max_normal, len));
|
||||
assert_eq!(System::block_weight().total(), Weight::from_ref_time(768));
|
||||
assert_ok!(CheckWeight::<Test>::do_pre_dispatch(&mandatory, len));
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024));
|
||||
assert_eq!(block_weight_limit(), Weight::from_ref_time(1024).set_proof_size(u64::MAX));
|
||||
assert_eq!(System::block_weight().total(), Weight::from_ref_time(1024 + 768));
|
||||
assert_eq!(CheckWeight::<Test>::check_extrinsic_weight(&mandatory), Ok(()));
|
||||
});
|
||||
@@ -682,11 +682,11 @@ mod tests {
|
||||
.base_block(Weight::zero())
|
||||
.for_class(DispatchClass::non_mandatory(), |w| {
|
||||
w.base_extrinsic = Weight::zero();
|
||||
w.max_total = Some(Weight::from_ref_time(20));
|
||||
w.max_total = Some(Weight::from_ref_time(20).set_proof_size(u64::MAX));
|
||||
})
|
||||
.for_class(DispatchClass::Mandatory, |w| {
|
||||
w.base_extrinsic = Weight::zero();
|
||||
w.reserved = Some(Weight::from_ref_time(5));
|
||||
w.reserved = Some(Weight::from_ref_time(5).set_proof_size(u64::MAX));
|
||||
w.max_total = None;
|
||||
})
|
||||
.build_or_panic();
|
||||
@@ -695,7 +695,7 @@ mod tests {
|
||||
DispatchClass::Operational => Weight::from_ref_time(10),
|
||||
DispatchClass::Mandatory => Weight::zero(),
|
||||
});
|
||||
assert_eq!(maximum_weight.max_block, all_weight.total());
|
||||
assert_eq!(maximum_weight.max_block, all_weight.total().set_proof_size(u64::MAX));
|
||||
|
||||
// fits into reserved
|
||||
let mandatory1 = DispatchInfo {
|
||||
|
||||
@@ -207,7 +207,10 @@ pub struct BlockWeights {
|
||||
|
||||
impl Default for BlockWeights {
|
||||
fn default() -> Self {
|
||||
Self::with_sensible_defaults(1u64 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
|
||||
Self::with_sensible_defaults(
|
||||
Weight::from_components(constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX),
|
||||
DEFAULT_NORMAL_RATIO,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +227,6 @@ impl BlockWeights {
|
||||
}
|
||||
let mut error = ValidationErrors::default();
|
||||
|
||||
// TODO: account for proof size weight in the assertions below
|
||||
for class in DispatchClass::all() {
|
||||
let weights = self.per_class.get(*class);
|
||||
let max_for_class = or_max(weights.max_total);
|
||||
@@ -233,16 +235,18 @@ impl BlockWeights {
|
||||
// Make sure that if total is set it's greater than base_block &&
|
||||
// base_for_class
|
||||
error_assert!(
|
||||
(max_for_class.ref_time() > self.base_block.ref_time() && max_for_class.ref_time() > base_for_class.ref_time())
|
||||
|| max_for_class.ref_time() == 0,
|
||||
(max_for_class.all_gt(self.base_block) && max_for_class.all_gt(base_for_class))
|
||||
|| max_for_class == Weight::zero(),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (total) has to be greater than {:?} (base block) & {:?} (base extrinsic)",
|
||||
class, max_for_class, self.base_block, base_for_class,
|
||||
);
|
||||
// Max extrinsic can't be greater than max_for_class.
|
||||
error_assert!(
|
||||
weights.max_extrinsic.unwrap_or(Weight::zero()).ref_time() <=
|
||||
max_for_class.saturating_sub(base_for_class).ref_time(),
|
||||
weights
|
||||
.max_extrinsic
|
||||
.unwrap_or(Weight::zero())
|
||||
.all_lte(max_for_class.saturating_sub(base_for_class)),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max_extrinsic) can't be greater than {:?} (max for class)",
|
||||
class,
|
||||
@@ -251,14 +255,14 @@ impl BlockWeights {
|
||||
);
|
||||
// Max extrinsic should not be 0
|
||||
error_assert!(
|
||||
weights.max_extrinsic.unwrap_or_else(Weight::max_value).ref_time() > 0,
|
||||
weights.max_extrinsic.unwrap_or_else(Weight::max_value).all_gt(Weight::zero()),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max_extrinsic) must not be 0. Check base cost and average initialization cost.",
|
||||
class, weights.max_extrinsic,
|
||||
);
|
||||
// Make sure that if reserved is set it's greater than base_for_class.
|
||||
error_assert!(
|
||||
reserved.ref_time() > base_for_class.ref_time() || reserved.ref_time() == 0,
|
||||
reserved.all_gt(base_for_class) || reserved == Weight::zero(),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (reserved) has to be greater than {:?} (base extrinsic) if set",
|
||||
class,
|
||||
@@ -267,7 +271,7 @@ impl BlockWeights {
|
||||
);
|
||||
// Make sure max block is greater than max_total if it's set.
|
||||
error_assert!(
|
||||
self.max_block.ref_time() >= weights.max_total.unwrap_or(Weight::zero()).ref_time(),
|
||||
self.max_block.all_gte(weights.max_total.unwrap_or(Weight::zero())),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max block) has to be greater than {:?} (max for class)",
|
||||
class,
|
||||
@@ -276,7 +280,7 @@ impl BlockWeights {
|
||||
);
|
||||
// Make sure we can fit at least one extrinsic.
|
||||
error_assert!(
|
||||
self.max_block.ref_time() > (base_for_class + self.base_block).ref_time(),
|
||||
self.max_block.all_gt(base_for_class + self.base_block),
|
||||
&mut error,
|
||||
"[{:?}] {:?} (max block) must fit at least one extrinsic {:?} (base weight)",
|
||||
class,
|
||||
|
||||
@@ -41,7 +41,7 @@ frame_support::construct_runtime!(
|
||||
);
|
||||
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024);
|
||||
const MAX_BLOCK_WEIGHT: Weight = Weight::from_ref_time(1024).set_proof_size(u64::MAX);
|
||||
|
||||
parameter_types! {
|
||||
pub Version: RuntimeVersion = RuntimeVersion {
|
||||
|
||||
@@ -71,7 +71,7 @@ impl Get<frame_system::limits::BlockWeights> for BlockWeights {
|
||||
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
|
||||
})
|
||||
.for_class(DispatchClass::non_mandatory(), |weights| {
|
||||
weights.max_total = Weight::from_ref_time(1024).into();
|
||||
weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into();
|
||||
})
|
||||
.build_or_panic()
|
||||
}
|
||||
|
||||
@@ -889,7 +889,7 @@ mod tests {
|
||||
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
|
||||
})
|
||||
.for_class(DispatchClass::non_mandatory(), |weights| {
|
||||
weights.max_total = Weight::from_ref_time(1024).into();
|
||||
weights.max_total = Weight::from_ref_time(1024).set_proof_size(u64::MAX).into();
|
||||
})
|
||||
.build_or_panic()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user