Skip to content

Commit

Permalink
Add ConstFeeMultiplier to the transaction payment pallet (paritytec…
Browse files Browse the repository at this point in the history
…h#12222)

* fix: FeeMultiplierUpdate

* fix: cargo fmt

* fix: rustdoc

* Revert "fix: rustdoc"

This reverts commit 96b6ad8.

* Revert "fix: cargo fmt"

This reverts commit 1301652.

* Revert "fix: FeeMultiplierUpdate"

This reverts commit 2cbddd0.

* feat: add ConstFeeMultiplier

* fix: use cConstFeeMultiplier in the template node
  • Loading branch information
mrshiposha authored and ark0f committed Feb 27, 2023
1 parent 453a0b6 commit 3ac7f22
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
12 changes: 9 additions & 3 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, Verify},
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
};
Expand All @@ -38,7 +40,7 @@ pub use frame_support::{
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
use pallet_transaction_payment::{ConstFeeMultiplier, CurrencyAdapter, Multiplier};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};
Expand Down Expand Up @@ -251,13 +253,17 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub FeeMultiplier: Multiplier = Multiplier::one();
}

impl pallet_transaction_payment::Config for Runtime {
type Event = Event;
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = IdentityFee<Balance>;
type LengthToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
}

impl pallet_sudo::Config for Runtime {
Expand Down
27 changes: 26 additions & 1 deletion frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,30 @@ where
}
}

/// A struct to make the fee multiplier a constant
pub struct ConstFeeMultiplier<M: Get<Multiplier>>(sp_std::marker::PhantomData<M>);

impl<M: Get<Multiplier>> MultiplierUpdate for ConstFeeMultiplier<M> {
fn min() -> Multiplier {
M::get()
}
fn target() -> Perquintill {
Default::default()
}
fn variability() -> Multiplier {
Default::default()
}
}

impl<M> Convert<Multiplier, Multiplier> for ConstFeeMultiplier<M>
where
M: Get<Multiplier>,
{
fn convert(_previous: Multiplier) -> Multiplier {
Self::min()
}
}

/// Storage releases of the pallet.
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
enum Releases {
Expand Down Expand Up @@ -371,7 +395,8 @@ pub mod pallet {
// add 1 percent;
let addition = target / 100;
if addition == Weight::zero() {
// this is most likely because in a test setup we set everything to ().
// this is most likely because in a test setup we set everything to ()
// or to `ConstFeeMultiplier`.
return
}

Expand Down

0 comments on commit 3ac7f22

Please sign in to comment.