forked from cerc-io/laconicd-deprecated
fix: use EffectiveGasPrice in ante handler for dynamic fee tx (#817)
* Use effectiveGasPrice in ante handler for dynamic fee tx Closes: #814 Solution: - use effectiveGasPrice when check minimal-gas-prices, and deduct fee in ante handler - implement an EthMempoolFeeDecorator * add effectiveGasPrice to tx receipt * changelog * fix unit test * fix comments * add comments * Apply suggestions from code review Co-authored-by: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com> * review suggestions Co-authored-by: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
Thomas Nguy
Federico Kunze Küllmer
parent
50e463725e
commit
ccc6f5b53d
@@ -229,3 +229,13 @@ func (tx AccessListTx) Fee() *big.Int {
|
||||
func (tx AccessListTx) Cost() *big.Int {
|
||||
return cost(tx.Fee(), tx.GetValue())
|
||||
}
|
||||
|
||||
// EffectiveFee is the same as Fee for AccessListTx
|
||||
func (tx AccessListTx) EffectiveFee(baseFee *big.Int) *big.Int {
|
||||
return tx.Fee()
|
||||
}
|
||||
|
||||
// EffectiveCost is the same as Cost for AccessListTx
|
||||
func (tx AccessListTx) EffectiveCost(baseFee *big.Int) *big.Int {
|
||||
return tx.Cost()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/tharsis/ethermint/types"
|
||||
@@ -256,10 +257,25 @@ func (tx DynamicFeeTx) Validate() error {
|
||||
|
||||
// Fee returns gasprice * gaslimit.
|
||||
func (tx DynamicFeeTx) Fee() *big.Int {
|
||||
return fee(tx.GetGasPrice(), tx.GasLimit)
|
||||
return fee(tx.GetGasFeeCap(), tx.GasLimit)
|
||||
}
|
||||
|
||||
// Cost returns amount + gasprice * gaslimit.
|
||||
func (tx DynamicFeeTx) Cost() *big.Int {
|
||||
return cost(tx.Fee(), tx.GetValue())
|
||||
}
|
||||
|
||||
// GetEffectiveGasPrice returns the effective gas price
|
||||
func (tx *DynamicFeeTx) GetEffectiveGasPrice(baseFee *big.Int) *big.Int {
|
||||
return math.BigMin(new(big.Int).Add(tx.GasTipCap.BigInt(), baseFee), tx.GasFeeCap.BigInt())
|
||||
}
|
||||
|
||||
// EffectiveFee returns effective_gasprice * gaslimit.
|
||||
func (tx DynamicFeeTx) EffectiveFee(baseFee *big.Int) *big.Int {
|
||||
return fee(tx.GetEffectiveGasPrice(baseFee), tx.GasLimit)
|
||||
}
|
||||
|
||||
// EffectiveCost returns amount + effective_gasprice * gaslimit.
|
||||
func (tx DynamicFeeTx) EffectiveCost(baseFee *big.Int) *big.Int {
|
||||
return cost(tx.EffectiveFee(baseFee), tx.GetValue())
|
||||
}
|
||||
|
||||
@@ -200,3 +200,13 @@ func (tx LegacyTx) Fee() *big.Int {
|
||||
func (tx LegacyTx) Cost() *big.Int {
|
||||
return cost(tx.Fee(), tx.GetValue())
|
||||
}
|
||||
|
||||
// EffectiveFee is the same as Fee for LegacyTx
|
||||
func (tx LegacyTx) EffectiveFee(baseFee *big.Int) *big.Int {
|
||||
return tx.Fee()
|
||||
}
|
||||
|
||||
// EffectiveCost is the same as Cost for LegacyTx
|
||||
func (tx LegacyTx) EffectiveCost(baseFee *big.Int) *big.Int {
|
||||
return tx.Cost()
|
||||
}
|
||||
|
||||
@@ -245,6 +245,24 @@ func (msg MsgEthereumTx) GetGas() uint64 {
|
||||
return txData.GetGas()
|
||||
}
|
||||
|
||||
// GetFee returns the fee for non dynamic fee tx
|
||||
func (msg MsgEthereumTx) GetFee() *big.Int {
|
||||
txData, err := UnpackTxData(msg.Data)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return txData.Fee()
|
||||
}
|
||||
|
||||
// GetEffectiveFee returns the fee for dynamic fee tx
|
||||
func (msg MsgEthereumTx) GetEffectiveFee(baseFee *big.Int) *big.Int {
|
||||
txData, err := UnpackTxData(msg.Data)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return txData.EffectiveFee(baseFee)
|
||||
}
|
||||
|
||||
// GetFrom loads the ethereum sender address from the sigcache and returns an
|
||||
// sdk.AccAddress from its bytes
|
||||
func (msg *MsgEthereumTx) GetFrom() sdk.AccAddress {
|
||||
|
||||
@@ -36,8 +36,14 @@ type TxData interface {
|
||||
|
||||
AsEthereumData() ethtypes.TxData
|
||||
Validate() error
|
||||
|
||||
// static fee
|
||||
Fee() *big.Int
|
||||
Cost() *big.Int
|
||||
|
||||
// effective fee according to current base fee
|
||||
EffectiveFee(baseFee *big.Int) *big.Int
|
||||
EffectiveCost(baseFee *big.Int) *big.Int
|
||||
}
|
||||
|
||||
func NewTxDataFromTx(tx *ethtypes.Transaction) (TxData, error) {
|
||||
|
||||
Reference in New Issue
Block a user