Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiply tx len and base fee component by max number of remarks per block, in the fees calculation of congested_chain_simulation test #536

Merged
merged 3 commits into from
May 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions runtime/calamari/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ impl WeightToFeePolynomial for WeightToFee {

#[cfg(test)]
mod multiplier_tests {
use crate::{Runtime, RuntimeBlockWeights as BlockWeights, System, TransactionPayment, KMA};
use crate::{
Call, Runtime, RuntimeBlockWeights as BlockWeights, System, TransactionPayment, KMA,
};
use codec::Encode;
use frame_support::weights::{DispatchClass, Weight, WeightToFeePolynomial};
use frame_system::WeightInfo;
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use polkadot_runtime_common::{AdjustmentVariable, MinimumMultiplier, TargetBlockFullness};
use sp_runtime::{
Expand Down Expand Up @@ -106,7 +110,7 @@ mod multiplier_tests {
// Consider the daily cost to fully congest our network to be defined as:
// `target_daily_congestion_cost_usd = inclusion_fee * blocks_per_day * kma_price`
// Where:
// `inclusion_fee = fee_adjustment * (weight_to_fee_coeff * (block_weight ^ degree)) + base_fee + length_fee`
// `inclusion_fee = fee_adjustment * (weight_to_fee_coeff * (block_weight ^ degree)) + base_fee + (weight_to_fee_coeff * length_fee)`
// Where:
// `fee_adjustment` and `weight_to_fee_coeff` are configurable in a runtime via `FeeMultiplierUpdate` and `WeightToFee`
// `fee_adjustment` is also variable depending on previous block's fullness
Expand All @@ -128,9 +132,21 @@ mod multiplier_tests {
.max_total
.unwrap() - 10;

let base_fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
&frame_support::weights::constants::ExtrinsicBaseWeight::get(),
);
let remark = Call::System(frame_system::Call::<Runtime>::remark_with_event {
ghzlatarev marked this conversation as resolved.
Show resolved Hide resolved
remark: vec![1, 2, 3],
});
let len: u32 = remark.clone().encode().len() as u32;
let remark_weight: Weight =
<Runtime as frame_system::Config>::SystemWeightInfo::remark(len);
let max_number_of_remarks_per_block = (block_weight / remark_weight) as u128;
let per_byte = <Runtime as pallet_transaction_payment::Config>::TransactionByteFee::get();
// length fee. this is not adjusted.
let len_fee = max_number_of_remarks_per_block * per_byte.saturating_mul(len as u128);
ghzlatarev marked this conversation as resolved.
Show resolved Hide resolved
ghzlatarev marked this conversation as resolved.
Show resolved Hide resolved

let base_fee = max_number_of_remarks_per_block
* <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
&frame_support::weights::constants::ExtrinsicBaseWeight::get(),
);

run_with_system_weight(block_weight, || {
// initial value configured on module
Expand All @@ -150,11 +166,12 @@ mod multiplier_tests {
let fee = <Runtime as pallet_transaction_payment::Config>::WeightToFee::calc(
&block_weight,
);
// base_fee is not adjusted
let adjusted_fee = fee_adjustment.saturating_mul_acc_int(fee) + base_fee;

// base_fee and len_fee are not adjusted
let adjusted_fee = fee_adjustment.saturating_mul_acc_int(fee) + base_fee + len_fee;
accumulated_fee += adjusted_fee;
println!(
"Iteration {}, New fee_adjustment = {:?}. Adjusted Fee: {} KMA, Total Fee: {} KMA, Dollar Vlaue: {}",
"Iteration {}, New fee_adjustment = {:?}. Adjusted Fee: {} KMA, Total Fee: {} KMA, Dollar Value: {}",
iteration,
fee_adjustment,
adjusted_fee / KMA,
Expand Down