Skip to content
Snippets Groups Projects
Unverified Commit 9565800e authored by bgallois's avatar bgallois
Browse files

remove transaction fees

parent 88c80b7d
No related branches found
No related tags found
No related merge requests found
Pipeline #37146 passed
......@@ -22,10 +22,11 @@
pub use frame_support::weights::{Weight, WeightToFee};
use sp_arithmetic::traits::{BaseArithmetic, Unsigned};
use sp_core::Get;
#[cfg(not(feature = "constant-fees"))]
use {
crate::weights::extrinsic_weights::ExtrinsicBaseWeight,
frame_support::pallet_prelude::DispatchClass,
frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
},
......@@ -35,18 +36,32 @@ use {
sp_runtime::SaturatedConversion,
};
pub struct LengthToFeeImpl<T>(sp_std::marker::PhantomData<T>);
pub struct LengthToFeeImpl<T, U, X>(
sp_std::marker::PhantomData<T>,
sp_std::marker::PhantomData<U>,
sp_std::marker::PhantomData<X>,
);
impl<T> WeightToFee for LengthToFeeImpl<T>
impl<T, U, X> WeightToFee for LengthToFeeImpl<T, U, X>
where
T: BaseArithmetic + From<u32> + Copy + Unsigned,
U: frame_system::Config,
X: Get<Weight>,
{
type Balance = T;
#[cfg(not(feature = "constant-fees"))]
fn weight_to_fee(length_in_bytes: &Weight) -> Self::Balance {
let current_block_weight = <frame_system::Pallet<U>>::block_weight();
if current_block_weight
.get(DispatchClass::Normal)
.any_lt(X::get())
{
0u32.into()
} else {
Self::Balance::saturated_from(length_in_bytes.ref_time() / 100u64)
}
}
#[cfg(feature = "constant-fees")]
fn weight_to_fee(_length_in_bytes: &Weight) -> Self::Balance {
......@@ -54,16 +69,34 @@ where
}
}
pub struct WeightToFeeImpl<T>(sp_std::marker::PhantomData<T>);
pub struct WeightToFeeImpl<T, U, X>(
sp_std::marker::PhantomData<T>,
sp_std::marker::PhantomData<U>,
sp_std::marker::PhantomData<X>,
);
#[cfg(not(feature = "constant-fees"))]
impl<T> WeightToFeePolynomial for WeightToFeeImpl<T>
impl<T, U, X> WeightToFeePolynomial for WeightToFeeImpl<T, U, X>
where
T: BaseArithmetic + From<u64> + Copy + Unsigned + From<u32> + MultiplyRational,
U: frame_system::Config,
X: Get<Weight>,
{
type Balance = T;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
let current_block_weight = <frame_system::Pallet<U>>::block_weight();
if current_block_weight
.get(DispatchClass::Normal)
.any_lt(X::get())
{
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
coeff_frac: Perbill::zero(),
coeff_integer: Self::Balance::zero(),
}]
} else {
// The extrinsic base weight (smallest non-zero weight) is mapped to 5 cent
let p: Self::Balance = 5u64.into();
let q: Self::Balance = Self::Balance::from(ExtrinsicBaseWeight::get().ref_time());
......@@ -75,9 +108,10 @@ where
}]
}
}
}
#[cfg(feature = "constant-fees")]
impl<T> WeightToFee for WeightToFeeImpl<T>
impl<T, U, X> WeightToFee for WeightToFeeImpl<T, U, X>
where
T: BaseArithmetic + From<u32> + Copy + Unsigned,
{
......
......@@ -191,16 +191,17 @@ macro_rules! pallets_config {
parameter_types! {
pub FeeMultiplier: Multiplier = Multiplier::one();
pub TargetWeight: Weight = Perbill::from_percent(10) * BlockWeights::get().max_block;
}
impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate =
pallet_transaction_payment::ConstFeeMultiplier<FeeMultiplier>;
type LengthToFee = common_runtime::fees::LengthToFeeImpl<Balance>;
type LengthToFee = common_runtime::fees::LengthToFeeImpl<Balance, Self, TargetWeight>;
// does a filter on the call
type OnChargeTransaction = OneshotAccount;
type OperationalFeeMultiplier = frame_support::traits::ConstU8<5>;
type RuntimeEvent = RuntimeEvent;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance, Self, TargetWeight>;
}
impl pallet_oneshot_account::Config for Runtime {
type Currency = Balances;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment