mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +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:
@@ -98,7 +98,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default
|
||||
|
||||
[dev-dependencies]
|
||||
hex-literal = "0.3.4"
|
||||
tiny-keccak = "2.0.2"
|
||||
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
|
||||
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
separator = "0.4.1"
|
||||
|
||||
@@ -2171,3 +2171,128 @@ mod tests_fess {
|
||||
assert_eq_error_rate!(deposit, UNITS * 16 / 100, UNITS / 100);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod multiplier_tests {
|
||||
use super::*;
|
||||
use frame_support::{dispatch::GetDispatchInfo, traits::OnFinalize};
|
||||
use runtime_common::{MinimumMultiplier, TargetBlockFullness};
|
||||
use separator::Separatable;
|
||||
use sp_runtime::traits::Convert;
|
||||
|
||||
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 = BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
|
||||
let mut blocks = 0;
|
||||
let mut fees_paid = 0;
|
||||
|
||||
let call = frame_system::Call::<Runtime>::fill_block {
|
||||
ratio: Perbill::from_rational(
|
||||
block_weight,
|
||||
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(),
|
||||
),
|
||||
};
|
||||
println!("calling {:?}", call);
|
||||
let info = call.get_dispatch_info();
|
||||
// convert to outer call.
|
||||
let call = Call::System(call);
|
||||
let len = call.using_encoded(|e| e.len()) as u32;
|
||||
|
||||
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
|
||||
.build_storage::<Runtime>()
|
||||
.unwrap()
|
||||
.into();
|
||||
// set the minimum
|
||||
t.execute_with(|| {
|
||||
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::set(MinimumMultiplier::get());
|
||||
});
|
||||
|
||||
while multiplier <= Multiplier::from_u32(1) {
|
||||
t.execute_with(|| {
|
||||
// imagine this tx was called.
|
||||
let fee = TransactionPayment::compute_fee(len, &info, 0);
|
||||
fees_paid += fee;
|
||||
|
||||
// this will update the multiplier.
|
||||
System::set_block_consumed_resources(block_weight, 0);
|
||||
TransactionPayment::on_finalize(1);
|
||||
let next = TransactionPayment::next_fee_multiplier();
|
||||
|
||||
assert!(next > multiplier, "{:?} !>= {:?}", next, multiplier);
|
||||
multiplier = next;
|
||||
|
||||
println!(
|
||||
"block = {} / multiplier {:?} / fee = {:?} / fess so far {:?}",
|
||||
blocks,
|
||||
multiplier,
|
||||
fee.separated_string(),
|
||||
fees_paid.separated_string()
|
||||
);
|
||||
});
|
||||
blocks += 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn multiplier_cool_down_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 = Multiplier::from_u32(2);
|
||||
let mut blocks = 0;
|
||||
|
||||
let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default()
|
||||
.build_storage::<Runtime>()
|
||||
.unwrap()
|
||||
.into();
|
||||
// set the minimum
|
||||
t.execute_with(|| {
|
||||
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::set(multiplier);
|
||||
});
|
||||
|
||||
while multiplier > Multiplier::from_u32(0) {
|
||||
t.execute_with(|| {
|
||||
// this will update the multiplier.
|
||||
TransactionPayment::on_finalize(1);
|
||||
let next = TransactionPayment::next_fee_multiplier();
|
||||
|
||||
assert!(next < multiplier, "{:?} !>= {:?}", next, multiplier);
|
||||
multiplier = next;
|
||||
|
||||
println!("block = {} / multiplier {:?}", blocks, multiplier);
|
||||
});
|
||||
blocks += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user