@@ -673,15 +673,18 @@ pub trait OnChargeEVMTransaction<T: Config> {
673
673
674
674
/// After the transaction was executed the actual fee can be calculated.
675
675
/// This function should refund any overpaid fees and optionally deposit
676
- /// the corrected amount.
676
+ /// the corrected amount, and handles the base fee rationing using the provided
677
+ /// `OnUnbalanced` implementation.
678
+ /// Returns the `NegativeImbalance` - if any - produced by the priority fee.
677
679
fn correct_and_deposit_fee (
678
680
who : & H160 ,
679
681
corrected_fee : U256 ,
682
+ base_fee : U256 ,
680
683
already_withdrawn : Self :: LiquidityInfo ,
681
- ) ;
684
+ ) -> Self :: LiquidityInfo ;
682
685
683
- /// Introduced in EIP1559 to handle the priority tip payment to the block Author .
684
- fn pay_priority_fee ( tip : U256 ) ;
686
+ /// Introduced in EIP1559 to handle the priority tip.
687
+ fn pay_priority_fee ( tip : Self :: LiquidityInfo ) ;
685
688
}
686
689
687
690
/// Implements the transaction payment for a pallet implementing the `Currency`
@@ -725,8 +728,9 @@ where
725
728
fn correct_and_deposit_fee (
726
729
who : & H160 ,
727
730
corrected_fee : U256 ,
731
+ base_fee : U256 ,
728
732
already_withdrawn : Self :: LiquidityInfo ,
729
- ) {
733
+ ) -> Self :: LiquidityInfo {
730
734
if let Some ( paid) = already_withdrawn {
731
735
let account_id = T :: AddressMapping :: into_account_id ( * who) ;
732
736
@@ -763,13 +767,21 @@ where
763
767
. offset ( refund_imbalance)
764
768
. same ( )
765
769
. unwrap_or_else ( |_| C :: NegativeImbalance :: zero ( ) ) ;
766
- OU :: on_unbalanced ( adjusted_paid) ;
770
+
771
+ let ( base_fee, tip) = adjusted_paid. split ( base_fee. low_u128 ( ) . unique_saturated_into ( ) ) ;
772
+ // Handle base fee. Can be either burned, rationed, etc ...
773
+ OU :: on_unbalanced ( base_fee) ;
774
+ return Some ( tip) ;
767
775
}
776
+ None
768
777
}
769
778
770
- fn pay_priority_fee ( tip : U256 ) {
771
- let account_id = T :: AddressMapping :: into_account_id ( <Pallet < T > >:: find_author ( ) ) ;
772
- let _ = C :: deposit_into_existing ( & account_id, tip. low_u128 ( ) . unique_saturated_into ( ) ) ;
779
+ fn pay_priority_fee ( tip : Self :: LiquidityInfo ) {
780
+ // Default Ethereum behaviour: issue the tip to the block author.
781
+ if let Some ( tip) = tip {
782
+ let account_id = T :: AddressMapping :: into_account_id ( <Pallet < T > >:: find_author ( ) ) ;
783
+ let _ = C :: deposit_into_existing ( & account_id, tip. peek ( ) ) ;
784
+ }
773
785
}
774
786
}
775
787
@@ -794,12 +806,13 @@ impl<T> OnChargeEVMTransaction<T> for ()
794
806
fn correct_and_deposit_fee (
795
807
who : & H160 ,
796
808
corrected_fee : U256 ,
809
+ base_fee : U256 ,
797
810
already_withdrawn : Self :: LiquidityInfo ,
798
- ) {
799
- <EVMCurrencyAdapter :: < <T as Config >:: Currency , ( ) > as OnChargeEVMTransaction < T > >:: correct_and_deposit_fee ( who, corrected_fee, already_withdrawn)
811
+ ) -> Self :: LiquidityInfo {
812
+ <EVMCurrencyAdapter :: < <T as Config >:: Currency , ( ) > as OnChargeEVMTransaction < T > >:: correct_and_deposit_fee ( who, corrected_fee, base_fee , already_withdrawn)
800
813
}
801
814
802
- fn pay_priority_fee ( tip : U256 ) {
815
+ fn pay_priority_fee ( tip : Self :: LiquidityInfo ) {
803
816
<EVMCurrencyAdapter :: < <T as Config >:: Currency , ( ) > as OnChargeEVMTransaction < T > >:: pay_priority_fee ( tip) ;
804
817
}
805
818
}
0 commit comments