-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send priority fees to collators (#3120)
* feat: send eth tips to collator * style: fix import order * fix: tests * fix: tests * style: fix formatting * test: fix test * test: fix test * style: formatting * fix: test * fix: test * fix: test * fix: parameters tests. * fix: contract tests. * fix: fix test-eth-pool-resubmit-txn.ts * fix: fix test-eth-pool-error.ts * fix: Update balance transfer tests to use CHARLETH_ADDRESS in tests * style: fix * fix: Refactor xtokens test and disable tip fee burning * fix: fix test-contract tests * fix: commands in update-local-types * refactor: fee calculation logic and improve modularity. * fix: FeesTreasuryProportion test logic and helpers * fix: argument order in calculateFeePortions function call * test: Add verification for latest block fees and add a check for tips. * refactor: separate fee and tip calculation * fix: fee and tip handling logic for clarity and correctness * refactor: clean up unused imports in Moonbeam runtime * style: correct indentation in runtime lib.rs * test: also check LatestBlockFees in eth transactions * tmp: check if all tests pass * refactor: remove unnecessary console logs in tests * tmp: change default value * Revert "tmp: change default value" This reverts commit 7b16ab2. * tmp: change default value * tmp: change default value * test: add comment explaining test file * Revert "tmp: change default value" This reverts commit 56b62d3. * Revert "tmp: change default value" This reverts commit fdab76f. * feature: send substrate tips to block author * fix: incorrect generics * style: fix formatting * test: refine fee and tip handling logic for runtime tests * test(runtime): fix incorrect runtime references in tests * refactor: move all deal with fees logic into common crate * refactor: remove unused imports * style: add copyright * Update runtime/common/src/deal_with_fees.rs * test: fix test --------- Co-authored-by: Rodrigo Quelhas <[email protected]>
- Loading branch information
Showing
25 changed files
with
756 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2024 Moonbeam foundation | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use frame_support::__private::Get; | ||
use frame_support::pallet_prelude::TypedGet; | ||
use frame_support::traits::fungible::Credit; | ||
use frame_support::traits::tokens::imbalance::ResolveTo; | ||
use frame_support::traits::Imbalance; | ||
use frame_support::traits::OnUnbalanced; | ||
use pallet_treasury::TreasuryAccountId; | ||
use sp_runtime::Perbill; | ||
|
||
/// Deal with substrate based fees and tip. This should be used with pallet_transaction_payment. | ||
pub struct DealWithSubstrateFeesAndTip<R, FeesTreasuryProportion>( | ||
sp_std::marker::PhantomData<(R, FeesTreasuryProportion)>, | ||
); | ||
impl<R, FeesTreasuryProportion> DealWithSubstrateFeesAndTip<R, FeesTreasuryProportion> | ||
where | ||
R: pallet_balances::Config + pallet_treasury::Config + pallet_author_inherent::Config, | ||
pallet_author_inherent::Pallet<R>: Get<R::AccountId>, | ||
FeesTreasuryProportion: Get<Perbill>, | ||
{ | ||
fn deal_with_fees(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) { | ||
// Balances pallet automatically burns dropped Credits by decreasing | ||
// total_supply accordingly | ||
let treasury_proportion = FeesTreasuryProportion::get(); | ||
let treasury_part = treasury_proportion.deconstruct(); | ||
let burn_part = Perbill::one().deconstruct() - treasury_part; | ||
let (_, to_treasury) = amount.ration(burn_part, treasury_part); | ||
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(to_treasury); | ||
} | ||
|
||
fn deal_with_tip(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) { | ||
ResolveTo::<BlockAuthorAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(amount); | ||
} | ||
} | ||
|
||
impl<R, FeesTreasuryProportion> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> | ||
for DealWithSubstrateFeesAndTip<R, FeesTreasuryProportion> | ||
where | ||
R: pallet_balances::Config + pallet_treasury::Config + pallet_author_inherent::Config, | ||
pallet_author_inherent::Pallet<R>: Get<R::AccountId>, | ||
FeesTreasuryProportion: Get<Perbill>, | ||
{ | ||
fn on_unbalanceds( | ||
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>, | ||
) { | ||
if let Some(fees) = fees_then_tips.next() { | ||
Self::deal_with_fees(fees); | ||
if let Some(tip) = fees_then_tips.next() { | ||
Self::deal_with_tip(tip); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Deal with ethereum based fees. To handle tips/priority fees, use DealWithEthereumPriorityFees. | ||
pub struct DealWithEthereumBaseFees<R, FeesTreasuryProportion>( | ||
sp_std::marker::PhantomData<(R, FeesTreasuryProportion)>, | ||
); | ||
impl<R, FeesTreasuryProportion> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> | ||
for DealWithEthereumBaseFees<R, FeesTreasuryProportion> | ||
where | ||
R: pallet_balances::Config + pallet_treasury::Config, | ||
FeesTreasuryProportion: Get<Perbill>, | ||
{ | ||
fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) { | ||
// Balances pallet automatically burns dropped Credits by decreasing | ||
// total_supply accordingly | ||
let treasury_proportion = FeesTreasuryProportion::get(); | ||
let treasury_part = treasury_proportion.deconstruct(); | ||
let burn_part = Perbill::one().deconstruct() - treasury_part; | ||
let (_, to_treasury) = amount.ration(burn_part, treasury_part); | ||
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(to_treasury); | ||
} | ||
} | ||
|
||
pub struct BlockAuthorAccountId<R>(sp_std::marker::PhantomData<R>); | ||
impl<R> TypedGet for BlockAuthorAccountId<R> | ||
where | ||
R: frame_system::Config + pallet_author_inherent::Config, | ||
pallet_author_inherent::Pallet<R>: Get<R::AccountId>, | ||
{ | ||
type Type = R::AccountId; | ||
fn get() -> Self::Type { | ||
<pallet_author_inherent::Pallet<R> as Get<R::AccountId>>::get() | ||
} | ||
} | ||
|
||
/// Deal with ethereum based priority fees/tips. See DealWithEthereumBaseFees for base fees. | ||
pub struct DealWithEthereumPriorityFees<R>(sp_std::marker::PhantomData<R>); | ||
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> | ||
for DealWithEthereumPriorityFees<R> | ||
where | ||
R: pallet_balances::Config + pallet_author_inherent::Config, | ||
pallet_author_inherent::Pallet<R>: Get<R::AccountId>, | ||
{ | ||
fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) { | ||
ResolveTo::<BlockAuthorAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.