mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Add Event to Pallet Transaction Payment (#11618)
* add Event to Pallet Transaction Payment * Fix tests in Pallet Balance * Fix tests in Pallet Balance/Executive/Asset-tx-payment. * Fix * fmt * Fix * Fix * Update Cargo.lock * Fix tests in executor * Update frame/transaction-payment/src/lib.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * update the name of the event and fmt. Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
Generated
+1
@@ -4664,6 +4664,7 @@ dependencies = [
|
||||
"pallet-contracts",
|
||||
"pallet-im-online",
|
||||
"pallet-timestamp",
|
||||
"pallet-transaction-payment",
|
||||
"pallet-treasury",
|
||||
"parity-scale-codec",
|
||||
"sc-executor",
|
||||
|
||||
@@ -249,6 +249,7 @@ impl pallet_balances::Config for Runtime {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<Balance>;
|
||||
|
||||
@@ -135,9 +135,10 @@ impl core::Benchmark for ImportBenchmark {
|
||||
.inspect_state(|| {
|
||||
match self.block_type {
|
||||
BlockType::RandomTransfersKeepAlive => {
|
||||
// should be 7 per signed extrinsic + 1 per unsigned
|
||||
// should be 8 per signed extrinsic + 1 per unsigned
|
||||
// we have 1 unsigned and the rest are signed in the block
|
||||
// those 7 events per signed are:
|
||||
// those 8 events per signed are:
|
||||
// - transaction paid for the transaction payment
|
||||
// - withdraw (Balances::Withdraw) for charging the transaction fee
|
||||
// - new account (System::NewAccount) as we always transfer fund to
|
||||
// non-existent account
|
||||
@@ -148,7 +149,7 @@ impl core::Benchmark for ImportBenchmark {
|
||||
// - extrinsic success
|
||||
assert_eq!(
|
||||
node_runtime::System::events().len(),
|
||||
(self.block.extrinsics.len() - 1) * 7 + 1,
|
||||
(self.block.extrinsics.len() - 1) * 8 + 1,
|
||||
);
|
||||
},
|
||||
BlockType::Noop => {
|
||||
|
||||
@@ -36,6 +36,7 @@ pallet-contracts = { version = "4.0.0-dev", path = "../../../frame/contracts" }
|
||||
pallet-im-online = { version = "4.0.0-dev", path = "../../../frame/im-online" }
|
||||
pallet-timestamp = { version = "4.0.0-dev", path = "../../../frame/timestamp" }
|
||||
pallet-treasury = { version = "4.0.0-dev", path = "../../../frame/treasury" }
|
||||
pallet-transaction-payment = { version = "4.0.0-dev", path = "../../../frame/transaction-payment" }
|
||||
sp-application-crypto = { version = "6.0.0", path = "../../../primitives/application-crypto" }
|
||||
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
|
||||
sp-externalities = { version = "0.12.0", path = "../../../primitives/externalities" }
|
||||
|
||||
@@ -417,6 +417,17 @@ fn full_native_block_import_works() {
|
||||
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
who: alice().into(),
|
||||
actual_fee: fees,
|
||||
tip: 0,
|
||||
},
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess {
|
||||
@@ -488,6 +499,17 @@ fn full_native_block_import_works() {
|
||||
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
who: bob().into(),
|
||||
actual_fee: fees,
|
||||
tip: 0,
|
||||
},
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(1),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess {
|
||||
@@ -525,6 +547,17 @@ fn full_native_block_import_works() {
|
||||
event: Event::Treasury(pallet_treasury::Event::Deposit { value: fees * 8 / 10 }),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: Event::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
who: alice().into(),
|
||||
actual_fee: fees,
|
||||
tip: 0,
|
||||
},
|
||||
),
|
||||
topics: vec![],
|
||||
},
|
||||
EventRecord {
|
||||
phase: Phase::ApplyExtrinsic(2),
|
||||
event: Event::System(frame_system::Event::ExtrinsicSuccess {
|
||||
|
||||
@@ -447,6 +447,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
|
||||
type OperationalFeeMultiplier = OperationalFeeMultiplier;
|
||||
type WeightToFee = IdentityFee<Balance>;
|
||||
|
||||
@@ -106,7 +106,7 @@ impl<H: Clone + AsRef<[u8]>> Database<H> for DbAdapter {
|
||||
}
|
||||
return None
|
||||
},
|
||||
Change::Reference(col, key) =>
|
||||
Change::Reference(col, key) => {
|
||||
if ref_counted_column(col) {
|
||||
// FIXME accessing value is not strictly needed, optimize this in parity-db.
|
||||
let value = <Self as Database<H>>::get(self, col, key.as_ref());
|
||||
@@ -116,7 +116,8 @@ impl<H: Clone + AsRef<[u8]>> Database<H> for DbAdapter {
|
||||
not_ref_counted_column.push(col);
|
||||
}
|
||||
return None
|
||||
},
|
||||
}
|
||||
},
|
||||
Change::Release(col, key) =>
|
||||
if ref_counted_column(col) {
|
||||
(col as u8, key.as_ref().to_vec(), None)
|
||||
|
||||
@@ -158,6 +158,7 @@ mod tests;
|
||||
mod benchmarking;
|
||||
mod tests_composite;
|
||||
mod tests_local;
|
||||
#[cfg(test)]
|
||||
mod tests_reentrancy;
|
||||
pub mod weights;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -77,6 +77,7 @@ impl frame_system::Config for Test {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
|
||||
@@ -41,7 +41,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -78,6 +78,7 @@ impl frame_system::Config for Test {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::{self as pallet_balances, Config, Pallet};
|
||||
use crate::{self as pallet_balances, Config};
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU32, ConstU64, ConstU8, StorageMapShim},
|
||||
weights::IdentityFee,
|
||||
traits::{ConstU32, ConstU64, StorageMapShim},
|
||||
};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use sp_core::H256;
|
||||
use sp_io;
|
||||
use sp_runtime::{testing::Header, traits::IdentityLookup};
|
||||
@@ -83,14 +81,6 @@ impl frame_system::Config for Test {
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Test {
|
||||
type OnChargeTransaction = CurrencyAdapter<Pallet<Test>, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<u64>;
|
||||
type LengthToFee = IdentityFee<u64>;
|
||||
type FeeMultiplierUpdate = ();
|
||||
}
|
||||
|
||||
pub struct OnDustRemoval;
|
||||
impl OnUnbalanced<NegativeImbalance<Test>> for OnDustRemoval {
|
||||
fn on_nonzero_unbalanced(amount: NegativeImbalance<Test>) {
|
||||
|
||||
@@ -722,7 +722,7 @@ mod tests {
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
Custom: custom::{Pallet, Call, ValidateUnsigned, Inherent},
|
||||
}
|
||||
);
|
||||
@@ -783,6 +783,7 @@ mod tests {
|
||||
pub const TransactionByteFee: Balance = 0;
|
||||
}
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
||||
type OperationalFeeMultiplier = ConstU8<5>;
|
||||
type WeightToFee = IdentityFee<Balance>;
|
||||
|
||||
@@ -48,7 +48,7 @@ frame_support::construct_runtime!(
|
||||
{
|
||||
System: system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
|
||||
Authorship: pallet_authorship::{Pallet, Call, Storage},
|
||||
AssetTxPayment: pallet_asset_tx_payment::{Pallet},
|
||||
@@ -143,6 +143,7 @@ impl WeightToFeeT for TransactionByteFee {
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment::Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
|
||||
type WeightToFee = WeightToFee;
|
||||
type LengthToFee = TransactionByteFee;
|
||||
|
||||
@@ -249,6 +249,9 @@ pub mod pallet {
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
/// The overarching event type.
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Handler for withdrawing, refunding and depositing the transaction fee.
|
||||
/// Transaction fees are withdrawn before the transaction is executed.
|
||||
/// After the transaction was executed the transaction weight can be
|
||||
@@ -321,6 +324,14 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// A transaction fee `actual_fee`, of which `tip` was added to the minimum inclusion fee,
|
||||
/// has been paid by `who`.
|
||||
TransactionFeePaid { who: T::AccountId, actual_fee: BalanceOf<T>, tip: BalanceOf<T> },
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_finalize(_: T::BlockNumber) {
|
||||
@@ -734,6 +745,7 @@ where
|
||||
T::OnChargeTransaction::correct_and_deposit_fee(
|
||||
&who, info, post_info, actual_fee, tip, imbalance,
|
||||
)?;
|
||||
Pallet::<T>::deposit_event(Event::<T>::TransactionFeePaid { who, actual_fee, tip });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -790,7 +802,7 @@ mod tests {
|
||||
{
|
||||
System: system::{Pallet, Call, Config, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage},
|
||||
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -899,6 +911,7 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Config for Runtime {
|
||||
type Event = Event;
|
||||
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
|
||||
type OperationalFeeMultiplier = OperationalFeeMultiplier;
|
||||
type WeightToFee = WeightToFee;
|
||||
@@ -1407,8 +1420,14 @@ mod tests {
|
||||
&Ok(())
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&user), 0);
|
||||
// No events for such a scenario
|
||||
assert_eq!(System::events().len(), 0);
|
||||
// TransactionFeePaid Event
|
||||
System::assert_has_event(Event::TransactionPayment(
|
||||
pallet_transaction_payment::Event::TransactionFeePaid {
|
||||
who: user,
|
||||
actual_fee: 0,
|
||||
tip: 0,
|
||||
},
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user