mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
backport minimum weight to fee to master (#5739)
* propose fix fees * add tests to kusama runtime as well * better tests * last change * last update * Fix test * ignore tests again
This commit is contained in:
@@ -81,11 +81,11 @@ parameter_types! {
|
||||
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
||||
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
|
||||
/// change the fees more rapidly.
|
||||
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000);
|
||||
pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(75, 1000_000);
|
||||
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
|
||||
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
|
||||
/// See `multiplier_can_grow_from_zero`.
|
||||
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128);
|
||||
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10u128);
|
||||
/// Maximum length of block. Up to 5MB.
|
||||
pub BlockLength: limits::BlockLength =
|
||||
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
|
||||
@@ -244,116 +244,3 @@ macro_rules! prod_or_fast {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod multiplier_tests {
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
weights::{DispatchClass, Weight},
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, Convert, IdentityLookup, One},
|
||||
Perbill,
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
|
||||
type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}
|
||||
}
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
pub BlockLength: frame_system::limits::BlockLength =
|
||||
frame_system::limits::BlockLength::max(2 * 1024);
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::simple_max(1024);
|
||||
}
|
||||
|
||||
impl frame_system::Config for Runtime {
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type BlockWeights = BlockWeights;
|
||||
type BlockLength = ();
|
||||
type DbWeight = ();
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Call = Call;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
fn run_with_system_weight<F>(w: Weight, mut assertions: F)
|
||||
where
|
||||
F: FnMut() -> (),
|
||||
{
|
||||
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
|
||||
.build_storage::<Runtime>()
|
||||
.unwrap()
|
||||
.into();
|
||||
t.execute_with(|| {
|
||||
System::set_block_consumed_resources(w, 0);
|
||||
assertions()
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiplier_can_grow_from_zero() {
|
||||
let minimum_multiplier = MinimumMultiplier::get();
|
||||
let target = TargetBlockFullness::get() *
|
||||
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
|
||||
// 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, || {
|
||||
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier);
|
||||
assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn multiplier_growth_simulator() {
|
||||
// assume the multiplier is initially set to its minimum. We update it with values twice the
|
||||
//target (target is 25%, thus 50%) and we see at which point it reaches 1.
|
||||
let mut multiplier = MinimumMultiplier::get();
|
||||
let block_weight = TargetBlockFullness::get() *
|
||||
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap() *
|
||||
2;
|
||||
let mut blocks = 0;
|
||||
while multiplier <= Multiplier::one() {
|
||||
run_with_system_weight(block_weight, || {
|
||||
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(multiplier);
|
||||
// ensure that it is growing as well.
|
||||
assert!(next > multiplier, "{:?} !>= {:?}", next, multiplier);
|
||||
multiplier = next;
|
||||
});
|
||||
blocks += 1;
|
||||
println!("block = {} multiplier {:?}", blocks, multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user