From 677bb62421a64bf9508a90320e1cd5f78b0a119b Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sat, 29 Jan 2022 16:22:50 +0100 Subject: [PATCH] feat(runtimes): distribute tips to block author --- runtime/common/src/fees.rs | 4 ++-- runtime/common/src/pallets_config.rs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/fees.rs b/runtime/common/src/fees.rs index 4fe1d5fd4..aec304d1d 100644 --- a/runtime/common/src/fees.rs +++ b/runtime/common/src/fees.rs @@ -17,7 +17,7 @@ pub use frame_support::weights::{ Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }; -use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; +use sp_arithmetic::traits::{BaseArithmetic, Unsigned, Zero}; pub struct WeightToFeeImpl<T>(sp_std::marker::PhantomData<T>); @@ -36,7 +36,7 @@ where }) } // Force disable fees - fn calc(weight: &Weight) -> Self::Balance { + fn calc(_weight: &Weight) -> Self::Balance { Zero::zero() } } diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 08f5968ce..f24979285 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -163,8 +163,19 @@ macro_rules! pallets_config { type WeightInfo = common_runtime::weights::pallet_balances::WeightInfo<Runtime>; } + pub struct HandleFees; + type NegativeImbalance = <Balances as frame_support::traits::Currency<AccountId>>::NegativeImbalance; + impl frame_support::traits::OnUnbalanced<NegativeImbalance> for HandleFees { + fn on_nonzero_unbalanced(amount: NegativeImbalance) { + use frame_support::traits::Currency as _; + + if let Some(author) = Authorship::author() { + Balances::resolve_creating(&author, amount); + } + } + } impl pallet_transaction_payment::Config for Runtime { - type OnChargeTransaction = CurrencyAdapter<Balances, ()>; + type OnChargeTransaction = CurrencyAdapter<Balances, HandleFees>; type TransactionByteFee = TransactionByteFee; type OperationalFeeMultiplier = frame_support::traits::ConstU8<5>; type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>; -- GitLab