mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 04:21:06 +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:
@@ -6,7 +6,7 @@ description = "Integration tests using the test-parachains"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tiny-keccak = "2.0.2"
|
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
|
||||||
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["derive"] }
|
parity-scale-codec = { version = "3.1.5", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
adder = { package = "test-parachain-adder", path = "adder" }
|
adder = { package = "test-parachain-adder", path = "adder" }
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ parameter_types! {
|
|||||||
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
|
||||||
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
|
/// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to
|
||||||
/// change the fees more rapidly.
|
/// 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
|
/// 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.
|
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
|
||||||
/// See `multiplier_can_grow_from_zero`.
|
/// 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.
|
/// Maximum length of block. Up to 5MB.
|
||||||
pub BlockLength: limits::BlockLength =
|
pub BlockLength: limits::BlockLength =
|
||||||
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.3.4"
|
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" }
|
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
separator = "0.4.1"
|
separator = "0.4.1"
|
||||||
|
|||||||
@@ -2171,3 +2171,128 @@ mod tests_fess {
|
|||||||
assert_eq_error_rate!(deposit, UNITS * 16 / 100, UNITS / 100);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.3.4"
|
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" }
|
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
trie-db = "0.23.1"
|
trie-db = "0.23.1"
|
||||||
|
|||||||
@@ -1998,11 +1998,11 @@ sp_api::impl_runtime_apis! {
|
|||||||
mod test_fees {
|
mod test_fees {
|
||||||
use super::*;
|
use super::*;
|
||||||
use frame_support::weights::{GetDispatchInfo, WeightToFee as WeightToFeeT};
|
use frame_support::weights::{GetDispatchInfo, WeightToFee as WeightToFeeT};
|
||||||
use keyring::Sr25519Keyring::Charlie;
|
use keyring::Sr25519Keyring::{Alice, Charlie};
|
||||||
use pallet_transaction_payment::Multiplier;
|
use pallet_transaction_payment::Multiplier;
|
||||||
use runtime_common::MinimumMultiplier;
|
use runtime_common::MinimumMultiplier;
|
||||||
use separator::Separatable;
|
use separator::Separatable;
|
||||||
use sp_runtime::{assert_eq_error_rate, FixedPointNumber};
|
use sp_runtime::{assert_eq_error_rate, FixedPointNumber, MultiAddress, MultiSignature};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn payout_weight_portion() {
|
fn payout_weight_portion() {
|
||||||
@@ -2023,20 +2023,25 @@ mod test_fees {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn block_cost() {
|
fn block_cost() {
|
||||||
let max_block_weight = BlockWeights::get().max_block;
|
let max_block_weight = BlockWeights::get().max_block;
|
||||||
let raw_fee = WeightToFee::weight_to_fee(&max_block_weight);
|
let raw_fee = WeightToFee::weight_to_fee(&max_block_weight);
|
||||||
|
|
||||||
println!(
|
let fee_with_multiplier = |m: Multiplier| {
|
||||||
"Full Block weight == {} // WeightToFee(full_block) == {} plank",
|
println!(
|
||||||
max_block_weight,
|
"Full Block weight == {} // multiplier: {:?} // WeightToFee(full_block) == {} plank",
|
||||||
raw_fee.separated_string(),
|
max_block_weight,
|
||||||
);
|
m,
|
||||||
|
m.saturating_mul_int(raw_fee).separated_string(),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
fee_with_multiplier(MinimumMultiplier::get());
|
||||||
|
fee_with_multiplier(Multiplier::from_rational(1, 2));
|
||||||
|
fee_with_multiplier(Multiplier::from_u32(1));
|
||||||
|
fee_with_multiplier(Multiplier::from_u32(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn transfer_cost_min_multiplier() {
|
fn transfer_cost_min_multiplier() {
|
||||||
let min_multiplier = MinimumMultiplier::get();
|
let min_multiplier = MinimumMultiplier::get();
|
||||||
let call = pallet_balances::Call::<Runtime>::transfer_keep_alive {
|
let call = pallet_balances::Call::<Runtime>::transfer_keep_alive {
|
||||||
@@ -2044,29 +2049,51 @@ mod test_fees {
|
|||||||
value: Default::default(),
|
value: Default::default(),
|
||||||
};
|
};
|
||||||
let info = call.get_dispatch_info();
|
let info = call.get_dispatch_info();
|
||||||
|
println!("call = {:?} / info = {:?}", call, info);
|
||||||
// convert to outer call.
|
// convert to outer call.
|
||||||
let call = Call::Balances(call);
|
let call = Call::Balances(call);
|
||||||
let len = call.using_encoded(|e| e.len()) as u32;
|
let extra: SignedExtra = (
|
||||||
|
frame_system::CheckNonZeroSender::<Runtime>::new(),
|
||||||
|
frame_system::CheckSpecVersion::<Runtime>::new(),
|
||||||
|
frame_system::CheckTxVersion::<Runtime>::new(),
|
||||||
|
frame_system::CheckGenesis::<Runtime>::new(),
|
||||||
|
frame_system::CheckMortality::<Runtime>::from(generic::Era::immortal()),
|
||||||
|
frame_system::CheckNonce::<Runtime>::from(1),
|
||||||
|
frame_system::CheckWeight::<Runtime>::new(),
|
||||||
|
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
|
||||||
|
claims::PrevalidateAttests::<Runtime>::new(),
|
||||||
|
);
|
||||||
|
let uxt = UncheckedExtrinsic {
|
||||||
|
function: call,
|
||||||
|
signature: Some((
|
||||||
|
MultiAddress::Id(Alice.to_account_id()),
|
||||||
|
MultiSignature::Sr25519(Alice.sign(b"foo")),
|
||||||
|
extra,
|
||||||
|
)),
|
||||||
|
};
|
||||||
|
let len = uxt.encoded_size();
|
||||||
|
|
||||||
let mut ext = sp_io::TestExternalities::new_empty();
|
let mut ext = sp_io::TestExternalities::new_empty();
|
||||||
let mut test_with_multiplier = |m| {
|
let mut test_with_multiplier = |m: Multiplier| {
|
||||||
ext.execute_with(|| {
|
ext.execute_with(|| {
|
||||||
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::put(m);
|
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::put(m);
|
||||||
let fee = TransactionPayment::compute_fee(len, &info, 0);
|
let fee = TransactionPayment::query_fee_details(uxt.clone(), len as u32);
|
||||||
println!(
|
println!(
|
||||||
"weight = {:?} // multiplier = {:?} // full transfer fee = {:?}",
|
"multiplier = {:?} // fee details = {:?} // final fee = {:?}",
|
||||||
info.weight.separated_string(),
|
|
||||||
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get(),
|
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get(),
|
||||||
fee.separated_string(),
|
fee,
|
||||||
|
fee.final_fee().separated_string(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
test_with_multiplier(min_multiplier);
|
test_with_multiplier(min_multiplier);
|
||||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1u128));
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1u128));
|
||||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000u128));
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_0u128));
|
||||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000u128));
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_00u128));
|
||||||
test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000_000u128));
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000u128));
|
||||||
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000u128));
|
||||||
|
test_with_multiplier(Multiplier::saturating_from_rational(1u128, 1_000_000_000u128));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2151,3 +2178,128 @@ mod test {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ xcm = { path = "../../xcm", default-features = false }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.3.4"
|
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" }
|
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
serde_json = "1.0.81"
|
serde_json = "1.0.81"
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
hex-literal = "0.3.4"
|
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" }
|
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||||
serde_json = "1.0.81"
|
serde_json = "1.0.81"
|
||||||
|
|||||||
Reference in New Issue
Block a user