Skip to content

Commit

Permalink
Make everything cheaper (#1658)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin <[email protected]>
  • Loading branch information
kostekIV and Marcin-Radecki authored Mar 19, 2024
1 parent 2664b3b commit f43fd90
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions bin/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
ConstBool, ConstU32, Contains, EqualPrivilegeOnly, EstimateNextSessionRotation,
InstanceFilter, SortedMembers, WithdrawReasons,
},
weights::constants::WEIGHT_REF_TIME_PER_MILLIS,
weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, WeightToFee},
PalletId,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
Expand Down Expand Up @@ -59,7 +59,7 @@ use sp_runtime::{
AccountIdLookup, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, One, OpaqueKeys,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, RuntimeDebug,
ApplyExtrinsicResult, FixedU128, RuntimeDebug, SaturatedConversion,
};
pub use sp_runtime::{FixedPointNumber, Perbill, Permill};
use sp_staking::{currency_to_vote::U128CurrencyToVote, EraIndex};
Expand Down Expand Up @@ -261,8 +261,8 @@ parameter_types! {
// a "virtual tip" that's equal to the `OperationalFeeMultiplier * final_fee`.
// follows polkadot : https://github.com/paritytech/polkadot/blob/9ce5f7ef5abb1a4291454e8c9911b304d80679f9/runtime/polkadot/src/lib.rs#L369
pub const OperationalFeeMultiplier: u8 = 5;
// We expect that on average 25% of the normal capacity will be occupied with normal txs.
pub const TargetSaturationLevel: Perquintill = Perquintill::from_percent(25);
// We expect that on average 50% of the normal capacity will be occupied with normal txs.
pub const TargetSaturationLevel: Perquintill = Perquintill::from_percent(50);
// During 20 blocks the fee may not change more than by 100%. This, together with the
// `TargetSaturationLevel` value, results in variability ~0.067. For the corresponding
// formulas please refer to Substrate code at `frame/transaction-payment/src/lib.rs`.
Expand All @@ -272,11 +272,21 @@ parameter_types! {
pub MaximumMultiplier: Multiplier = Bounded::max_value();
}

pub struct DivideFeeBy<const N: Balance>;

impl<const N: Balance> WeightToFee for DivideFeeBy<N> {
type Balance = Balance;

fn weight_to_fee(weight: &Weight) -> Self::Balance {
Balance::saturated_from(weight.ref_time()).saturating_div(N)
}
}

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = CurrencyAdapter<Balances, EverythingToTheTreasury>;
type LengthToFee = IdentityFee<Balance>;
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = DivideFeeBy<10>;
type WeightToFee = DivideFeeBy<10>;
type FeeMultiplierUpdate = TargetedFeeAdjustment<
Self,
TargetSaturationLevel,
Expand Down

0 comments on commit f43fd90

Please sign in to comment.