all: rename internal 1559 gas fields (#23010)

This commit is contained in:
Daniel Liu 2024-05-24 12:03:03 +08:00
parent 5a31888b19
commit 4c096de9b0
19 changed files with 220 additions and 223 deletions

View file

@ -525,8 +525,8 @@ func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) CheckNonce() bool { return false } func (m callMsg) CheckNonce() bool { return false }
func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap } func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip } func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas } func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value } func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data } func (m callMsg) Data() []byte { return m.CallMsg.Data }

View file

@ -56,17 +56,17 @@ var (
// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a // ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
// transaction with a tip higher than the total fee cap. // transaction with a tip higher than the total fee cap.
ErrTipAboveFeeCap = errors.New("tip higher than fee cap") ErrTipAboveFeeCap = errors.New("max priority fee per gas higher than max fee per gas")
// ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified // ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified
// in the tip field. // in the tip field.
ErrTipVeryHigh = errors.New("tip higher than 2^256-1") ErrTipVeryHigh = errors.New("max priority fee per gas higher than 2^256-1")
// ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified // ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified
// in the fee cap field. // in the fee cap field.
ErrFeeCapVeryHigh = errors.New("fee cap higher than 2^256-1") ErrFeeCapVeryHigh = errors.New("max fee per gas higher than 2^256-1")
// ErrFeeCapTooLow is returned if the transaction fee cap is less than the // ErrFeeCapTooLow is returned if the transaction fee cap is less than the
// the base fee of the block. // the base fee of the block.
ErrFeeCapTooLow = errors.New("fee cap less than block base fee") ErrFeeCapTooLow = errors.New("max fee per gas less than block base fee")
) )

View file

@ -63,11 +63,11 @@ func TestStateProcessorErrors(t *testing.T) {
} }
return signedTx return signedTx
} }
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, tip, feeCap *big.Int) *types.Transaction { var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int) *types.Transaction {
tx, _ := types.SignTx(types.NewTx(&types.DynamicFeeTx{ tx, _ := types.SignTx(types.NewTx(&types.DynamicFeeTx{
Nonce: nonce, Nonce: nonce,
Tip: tip, GasTipCap: gasTipCap,
FeeCap: feeCap, GasFeeCap: gasFeeCap,
Gas: gasLimit, Gas: gasLimit,
To: &to, To: &to,
Value: big.NewInt(0), Value: big.NewInt(0),
@ -148,25 +148,25 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)), mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
}, },
want: "fee cap less than block base fee: address xdc71562b71999873DB5b286dF957af199Ec94617F7, feeCap: 0 baseFee: 875000000", want: "fee cap less than block base fee: address xdc71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000",
}, },
{ // ErrTipVeryHigh { // ErrTipVeryHigh
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)), mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)),
}, },
want: "tip higher than 2^256-1: address xdc71562b71999873DB5b286dF957af199Ec94617F7, tip bit length: 257", want: "max priority fee per gas higher than 2^256-1: address xdc71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas bit length: 257",
}, },
{ // ErrFeeCapVeryHigh { // ErrFeeCapVeryHigh
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), tooBigNumber), mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), tooBigNumber),
}, },
want: "fee cap higher than 2^256-1: address xdc71562b71999873DB5b286dF957af199Ec94617F7, feeCap bit length: 257", want: "max fee per gas higher than 2^256-1: address xdc71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas bit length: 257",
}, },
{ // ErrTipAboveFeeCap { // ErrTipAboveFeeCap
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(2), big.NewInt(1)), mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(2), big.NewInt(1)),
}, },
want: "tip higher than fee cap: address xdc71562b71999873DB5b286dF957af199Ec94617F7, tip: 1, feeCap: 2", want: "max priority fee per gas higher than max fee per gas: address xdc71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas: 2, maxFeePerGas: 1",
}, },
{ // ErrInsufficientFunds { // ErrInsufficientFunds
// Available balance: 1000000000000000000 // Available balance: 1000000000000000000

View file

@ -58,8 +58,8 @@ type StateTransition struct {
msg Message msg Message
gas uint64 gas uint64
gasPrice *big.Int gasPrice *big.Int
feeCap *big.Int gasFeeCap *big.Int
tip *big.Int gasTipCap *big.Int
initialGas uint64 initialGas uint64
value *big.Int value *big.Int
data []byte data []byte
@ -74,8 +74,8 @@ type Message interface {
To() *common.Address To() *common.Address
GasPrice() *big.Int GasPrice() *big.Int
FeeCap() *big.Int GasFeeCap() *big.Int
Tip() *big.Int GasTipCap() *big.Int
Gas() uint64 Gas() uint64
Value() *big.Int Value() *big.Int
@ -130,8 +130,8 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
evm: evm, evm: evm,
msg: msg, msg: msg,
gasPrice: msg.GasPrice(), gasPrice: msg.GasPrice(),
feeCap: msg.FeeCap(), gasFeeCap: msg.GasFeeCap(),
tip: msg.Tip(), gasTipCap: msg.GasTipCap(),
value: msg.Value(), value: msg.Value(),
data: msg.Data(), data: msg.Data(),
state: evm.StateDB, state: evm.StateDB,
@ -183,9 +183,9 @@ func (st *StateTransition) buyGas() error {
balanceTokenFee := st.balanceTokenFee() balanceTokenFee := st.balanceTokenFee()
if balanceTokenFee == nil { if balanceTokenFee == nil {
balanceCheck := mgval balanceCheck := mgval
if st.feeCap != nil { if st.gasFeeCap != nil {
balanceCheck = new(big.Int).SetUint64(st.msg.Gas()) balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
balanceCheck = balanceCheck.Mul(balanceCheck, st.feeCap) balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
} }
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 { if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want) return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
@ -221,25 +221,25 @@ func (st *StateTransition) preCheck() error {
msg.From().Hex(), stNonce) msg.From().Hex(), stNonce)
} }
} }
// Make sure that transaction feeCap is greater than the baseFee (post london) // Make sure that transaction gasFeeCap is greater than the baseFee (post london)
if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) { if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) {
if l := st.feeCap.BitLen(); l > 256 { if l := st.gasFeeCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, feeCap bit length: %d", ErrFeeCapVeryHigh, return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh,
msg.From().Hex(), l) msg.From().Hex(), l)
} }
if l := st.tip.BitLen(); l > 256 { if l := st.gasTipCap.BitLen(); l > 256 {
return fmt.Errorf("%w: address %v, tip bit length: %d", ErrTipVeryHigh, return fmt.Errorf("%w: address %v, maxPriorityFeePerGas bit length: %d", ErrTipVeryHigh,
msg.From().Hex(), l) msg.From().Hex(), l)
} }
if st.feeCap.Cmp(st.tip) < 0 { if st.gasFeeCap.Cmp(st.gasTipCap) < 0 {
return fmt.Errorf("%w: address %v, tip: %s, feeCap: %s", ErrTipAboveFeeCap, return fmt.Errorf("%w: address %v, maxPriorityFeePerGas: %s, maxFeePerGas: %s", ErrTipAboveFeeCap,
msg.From().Hex(), st.feeCap, st.tip) msg.From().Hex(), st.gasTipCap, st.gasFeeCap)
} }
// This will panic if baseFee is nil, but basefee presence is verified // This will panic if baseFee is nil, but basefee presence is verified
// as part of header validation. // as part of header validation.
if st.feeCap.Cmp(st.evm.Context.BaseFee) < 0 { if st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
return fmt.Errorf("%w: address %v, feeCap: %s baseFee: %s", ErrFeeCapTooLow, return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
msg.From().Hex(), st.feeCap, st.evm.Context.BaseFee) msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
} }
} }
return st.buyGas() return st.buyGas()
@ -275,12 +275,11 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
} }
msg := st.msg msg := st.msg
sender := st.from() // err checked in preCheck sender := st.from() // err checked in preCheck
homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber) homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber)
eip3529 := st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) eip3529 := st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber)
contractCreation := msg.To() == nil contractCreation := msg.To() == nil
// Pay intrinsic gas // Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead) gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead)
if err != nil { if err != nil {
return nil, 0, false, err, nil return nil, 0, false, err, nil
@ -339,7 +338,7 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
} else { } else {
effectiveTip := st.gasPrice effectiveTip := st.gasPrice
if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) { if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) {
effectiveTip = cmath.BigMin(st.tip, new(big.Int).Sub(st.feeCap, st.evm.Context.BaseFee)) effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
} }
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)) st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
} }

View file

@ -48,8 +48,8 @@ func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) CheckNonce() bool { return false } func (m callMsg) CheckNonce() bool { return false }
func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap } func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip } func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas } func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value } func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data } func (m callMsg) Data() []byte { return m.CallMsg.Data }

View file

@ -285,13 +285,13 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
return false, nil return false, nil
} }
if old != nil { if old != nil {
if old.FeeCapCmp(tx) >= 0 || old.TipCmp(tx) >= 0 { if old.GasFeeCapCmp(tx) >= 0 || old.GasTipCapCmp(tx) >= 0 {
return false, nil return false, nil
} }
// thresholdFeeCap = oldFC * (100 + priceBump) / 100 // thresholdFeeCap = oldFC * (100 + priceBump) / 100
a := big.NewInt(100 + int64(priceBump)) a := big.NewInt(100 + int64(priceBump))
aFeeCap := new(big.Int).Mul(a, old.FeeCap()) aFeeCap := new(big.Int).Mul(a, old.GasFeeCap())
aTip := a.Mul(a, old.Tip()) aTip := a.Mul(a, old.GasTipCap())
// thresholdTip = oldTip * (100 + priceBump) / 100 // thresholdTip = oldTip * (100 + priceBump) / 100
b := big.NewInt(100) b := big.NewInt(100)
@ -301,7 +301,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
// Have to ensure that either the new fee cap or tip is higher than the // Have to ensure that either the new fee cap or tip is higher than the
// old ones as well as checking the percentage threshold to ensure that // old ones as well as checking the percentage threshold to ensure that
// this is accurate for low (Wei-level) gas price replacements // this is accurate for low (Wei-level) gas price replacements
if tx.FeeCapIntCmp(thresholdFeeCap) < 0 || tx.TipIntCmp(thresholdTip) < 0 { if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
return false, nil return false, nil
} }
} }
@ -428,7 +428,7 @@ func (l *txList) LastElement() *types.Transaction {
// priceHeap is a heap.Interface implementation over transactions for retrieving // priceHeap is a heap.Interface implementation over transactions for retrieving
// price-sorted transactions to discard when the pool fills up. If baseFee is set // price-sorted transactions to discard when the pool fills up. If baseFee is set
// then the heap is sorted based on the effective tip based on the given base fee. // then the heap is sorted based on the effective tip based on the given base fee.
// If baseFee is nil then the sorting is based on feeCap. // If baseFee is nil then the sorting is based on gasFeeCap.
type priceHeap struct { type priceHeap struct {
baseFee *big.Int // heap should always be re-sorted after baseFee is changed baseFee *big.Int // heap should always be re-sorted after baseFee is changed
list []*types.Transaction list []*types.Transaction
@ -451,16 +451,16 @@ func (h *priceHeap) Less(i, j int) bool {
func (h *priceHeap) cmp(a, b *types.Transaction) int { func (h *priceHeap) cmp(a, b *types.Transaction) int {
if h.baseFee != nil { if h.baseFee != nil {
// Compare effective tips if baseFee is specified // Compare effective tips if baseFee is specified
if c := a.EffectiveTipCmp(b, h.baseFee); c != 0 { if c := a.EffectiveGasTipCmp(b, h.baseFee); c != 0 {
return c return c
} }
} }
// Compare fee caps if baseFee is not specified or effective tips are equal // Compare fee caps if baseFee is not specified or effective tips are equal
if c := a.FeeCapCmp(b); c != 0 { if c := a.GasFeeCapCmp(b); c != 0 {
return c return c
} }
// Compare tips if effective tips and fee caps are equal // Compare tips if effective tips and fee caps are equal
return a.TipCmp(b) return a.GasTipCapCmp(b)
} }
func (h *priceHeap) Push(x interface{}) { func (h *priceHeap) Push(x interface{}) {
@ -483,7 +483,7 @@ func (h *priceHeap) Pop() interface{} {
// will be considered for tracking, sorting, eviction, etc. // will be considered for tracking, sorting, eviction, etc.
// //
// Two heaps are used for sorting: the urgent heap (based on effective tip in the next // Two heaps are used for sorting: the urgent heap (based on effective tip in the next
// block) and the floating heap (based on feeCap). Always the bigger heap is chosen for // block) and the floating heap (based on gasFeeCap). Always the bigger heap is chosen for
// eviction. Transactions evicted from the urgent heap are first demoted into the floating heap. // eviction. Transactions evicted from the urgent heap are first demoted into the floating heap.
// In some cases (during a congestion, when blocks are full) the urgent heap can provide // In some cases (during a congestion, when blocks are full) the urgent heap can provide
// better candidates for inclusion while in other cases (at the top of the baseFee peak) // better candidates for inclusion while in other cases (at the top of the baseFee peak)

View file

@ -475,7 +475,7 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
pool.gasPrice = price pool.gasPrice = price
// if the min miner fee increased, remove transactions below the new threshold // if the min miner fee increased, remove transactions below the new threshold
if price.Cmp(old) > 0 { if price.Cmp(old) > 0 {
// pool.priced is sorted by FeeCap, so we have to iterate through pool.all instead // pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead
drop := pool.all.RemotesBelowTip(price) drop := pool.all.RemotesBelowTip(price)
for _, tx := range drop { for _, tx := range drop {
pool.removeTx(tx.Hash(), false) pool.removeTx(tx.Hash(), false)
@ -631,14 +631,14 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrGasLimit return ErrGasLimit
} }
// Sanity check for extremely large numbers // Sanity check for extremely large numbers
if tx.FeeCap().BitLen() > 256 { if tx.GasFeeCap().BitLen() > 256 {
return ErrFeeCapVeryHigh return ErrFeeCapVeryHigh
} }
if tx.Tip().BitLen() > 256 { if tx.GasTipCap().BitLen() > 256 {
return ErrTipVeryHigh return ErrTipVeryHigh
} }
// Ensure feeCap is greater than or equal to tip. // Ensure gasFeeCap is greater than or equal to gasTipCap.
if tx.FeeCapIntCmp(tx.Tip()) < 0 { if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 {
return ErrTipAboveFeeCap return ErrTipAboveFeeCap
} }
// Make sure the transaction is signed properly. // Make sure the transaction is signed properly.
@ -647,7 +647,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInvalidSender return ErrInvalidSender
} }
// Drop non-local transactions under our own minimal accepted gas price or tip // Drop non-local transactions under our own minimal accepted gas price or tip
if !local && tx.TipIntCmp(pool.gasPrice) < 0 { if !local && tx.GasTipCapIntCmp(pool.gasPrice) < 0 {
if !tx.IsSpecialTransaction() || (pool.IsSigner != nil && !pool.IsSigner(from)) { if !tx.IsSpecialTransaction() || (pool.IsSigner != nil && !pool.IsSigner(from)) {
return ErrUnderpriced return ErrUnderpriced
} }
@ -759,7 +759,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue { if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it // If the new transaction is underpriced, don't accept it
if !isLocal && pool.priced.Underpriced(tx) { if !isLocal && pool.priced.Underpriced(tx) {
log.Trace("Discarding underpriced transaction", "hash", hash, "tip", tx.Tip(), "feeCap", tx.FeeCap()) log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
underpricedTxMeter.Mark(1) underpricedTxMeter.Mark(1)
return false, ErrUnderpriced return false, ErrUnderpriced
} }
@ -776,7 +776,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
} }
// Kick out the underpriced remote transactions. // Kick out the underpriced remote transactions.
for _, tx := range drop { for _, tx := range drop {
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "tip", tx.Tip(), "feeCap", tx.FeeCap()) log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
underpricedTxMeter.Mark(1) underpricedTxMeter.Mark(1)
pool.removeTx(tx.Hash(), false) pool.removeTx(tx.Hash(), false)
} }
@ -1934,7 +1934,7 @@ func (t *txLookup) RemoteToLocals(locals *accountSet) int {
func (t *txLookup) RemotesBelowTip(threshold *big.Int) types.Transactions { func (t *txLookup) RemotesBelowTip(threshold *big.Int) types.Transactions {
found := make(types.Transactions, 0, 128) found := make(types.Transactions, 0, 128)
t.Range(func(hash common.Hash, tx *types.Transaction, local bool) bool { t.Range(func(hash common.Hash, tx *types.Transaction, local bool) bool {
if tx.TipIntCmp(threshold) < 0 { if tx.GasTipCapIntCmp(threshold) < 0 {
found = append(found, tx) found = append(found, tx)
} }
return true return true

View file

@ -116,8 +116,8 @@ func dynamicFeeTx(nonce uint64, gaslimit uint64, gasFee *big.Int, tip *big.Int,
tx, _ := types.SignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainId), &types.DynamicFeeTx{ tx, _ := types.SignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainId), &types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainId, ChainID: params.TestChainConfig.ChainId,
Nonce: nonce, Nonce: nonce,
Tip: tip, GasTipCap: tip,
FeeCap: gasFee, GasFeeCap: gasFee,
Gas: gaslimit, Gas: gaslimit,
To: &common.Address{}, To: &common.Address{},
Value: big.NewInt(100), Value: big.NewInt(100),
@ -2177,17 +2177,17 @@ func TestTransactionReplacementDynamicFee(t *testing.T) {
defer sub.Unsubscribe() defer sub.Unsubscribe()
// Add pending transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too) // Add pending transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too)
feeCap := int64(100) gasFeeCap := int64(100)
feeCapThreshold := (feeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100 feeCapThreshold := (gasFeeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100
tip := int64(60) gasTipCap := int64(60)
tipThreshold := (tip * (100 + int64(testTxPoolConfig.PriceBump))) / 100 tipThreshold := (gasTipCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100
// Run the following identical checks for both the pending and queue pools: // Run the following identical checks for both the pending and queue pools:
// 1. Send initial tx => accept // 1. Send initial tx => accept
// 2. Don't bump tip or fee cap => discard // 2. Don't bump tip or fee cap => discard
// 3. Bump both more than min => accept // 3. Bump both more than min => accept
// 4. Check events match expected (2 new executable txs during pending, 0 during queue) // 4. Check events match expected (2 new executable txs during pending, 0 during queue)
// 5. Send new tx with larger tip and feeCap => accept // 5. Send new tx with larger tip and gasFeeCap => accept
// 6. Bump tip max allowed so it's still underpriced => discard // 6. Bump tip max allowed so it's still underpriced => discard
// 7. Bump fee cap max allowed so it's still underpriced => discard // 7. Bump fee cap max allowed so it's still underpriced => discard
// 8. Bump tip min for acceptance => discard // 8. Bump tip min for acceptance => discard
@ -2227,27 +2227,27 @@ func TestTransactionReplacementDynamicFee(t *testing.T) {
t.Fatalf("cheap %s replacement event firing failed: %v", stage, err) t.Fatalf("cheap %s replacement event firing failed: %v", stage, err)
} }
// 5. Send new tx with larger tip and feeCap => accept // 5. Send new tx with larger tip and feeCap => accept
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tip), key) tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(gasTipCap), key)
if err := pool.addRemoteSync(tx); err != nil { if err := pool.addRemoteSync(tx); err != nil {
t.Fatalf("failed to add original proper %s transaction: %v", stage, err) t.Fatalf("failed to add original proper %s transaction: %v", stage, err)
} }
// 6. Bump tip max allowed so it's still underpriced => discard // 6. Bump tip max allowed so it's still underpriced => discard
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tipThreshold-1), key) tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold-1), key)
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced { if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
} }
// 7. Bump fee cap max allowed so it's still underpriced => discard // 7. Bump fee cap max allowed so it's still underpriced => discard
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(tip), key) tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(gasTipCap), key)
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced { if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
} }
// 8. Bump tip min for acceptance => accept // 8. Bump tip min for acceptance => accept
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tipThreshold), key) tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold), key)
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced { if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
} }
// 9. Bump fee cap min for acceptance => accept // 9. Bump fee cap min for acceptance => accept
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(tip), key) tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(gasTipCap), key)
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced { if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
} }

View file

@ -94,7 +94,6 @@ func (tx *AccessListTx) copy() TxData {
} }
// accessors for innerTx. // accessors for innerTx.
func (tx *AccessListTx) txType() byte { return AccessListTxType } func (tx *AccessListTx) txType() byte { return AccessListTxType }
func (tx *AccessListTx) chainID() *big.Int { return tx.ChainID } func (tx *AccessListTx) chainID() *big.Int { return tx.ChainID }
func (tx *AccessListTx) protected() bool { return true } func (tx *AccessListTx) protected() bool { return true }
@ -102,8 +101,8 @@ func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
func (tx *AccessListTx) data() []byte { return tx.Data } func (tx *AccessListTx) data() []byte { return tx.Data }
func (tx *AccessListTx) gas() uint64 { return tx.Gas } func (tx *AccessListTx) gas() uint64 { return tx.Gas }
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice } func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) tip() *big.Int { return tx.GasPrice } func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) feeCap() *big.Int { return tx.GasPrice } func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) value() *big.Int { return tx.Value } func (tx *AccessListTx) value() *big.Int { return tx.Value }
func (tx *AccessListTx) nonce() uint64 { return tx.Nonce } func (tx *AccessListTx) nonce() uint64 { return tx.Nonce }
func (tx *AccessListTx) to() *common.Address { return tx.To } func (tx *AccessListTx) to() *common.Address { return tx.To }

View file

@ -25,8 +25,8 @@ import (
type DynamicFeeTx struct { type DynamicFeeTx struct {
ChainID *big.Int ChainID *big.Int
Nonce uint64 Nonce uint64
Tip *big.Int GasTipCap *big.Int
FeeCap *big.Int GasFeeCap *big.Int
Gas uint64 Gas uint64
To *common.Address `rlp:"nil"` // nil means contract creation To *common.Address `rlp:"nil"` // nil means contract creation
Value *big.Int Value *big.Int
@ -50,8 +50,8 @@ func (tx *DynamicFeeTx) copy() TxData {
AccessList: make(AccessList, len(tx.AccessList)), AccessList: make(AccessList, len(tx.AccessList)),
Value: new(big.Int), Value: new(big.Int),
ChainID: new(big.Int), ChainID: new(big.Int),
Tip: new(big.Int), GasTipCap: new(big.Int),
FeeCap: new(big.Int), GasFeeCap: new(big.Int),
V: new(big.Int), V: new(big.Int),
R: new(big.Int), R: new(big.Int),
S: new(big.Int), S: new(big.Int),
@ -63,11 +63,11 @@ func (tx *DynamicFeeTx) copy() TxData {
if tx.ChainID != nil { if tx.ChainID != nil {
cpy.ChainID.Set(tx.ChainID) cpy.ChainID.Set(tx.ChainID)
} }
if tx.Tip != nil { if tx.GasTipCap != nil {
cpy.Tip.Set(tx.Tip) cpy.GasTipCap.Set(tx.GasTipCap)
} }
if tx.FeeCap != nil { if tx.GasFeeCap != nil {
cpy.FeeCap.Set(tx.FeeCap) cpy.GasFeeCap.Set(tx.GasFeeCap)
} }
if tx.V != nil { if tx.V != nil {
cpy.V.Set(tx.V) cpy.V.Set(tx.V)
@ -88,9 +88,9 @@ func (tx *DynamicFeeTx) protected() bool { return true }
func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList } func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList }
func (tx *DynamicFeeTx) data() []byte { return tx.Data } func (tx *DynamicFeeTx) data() []byte { return tx.Data }
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas } func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
func (tx *DynamicFeeTx) feeCap() *big.Int { return tx.FeeCap } func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) tip() *big.Int { return tx.Tip } func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.FeeCap } func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value } func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce } func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
func (tx *DynamicFeeTx) to() *common.Address { return tx.To } func (tx *DynamicFeeTx) to() *common.Address { return tx.To }

View file

@ -98,8 +98,8 @@ func (tx *LegacyTx) accessList() AccessList { return nil }
func (tx *LegacyTx) data() []byte { return tx.Data } func (tx *LegacyTx) data() []byte { return tx.Data }
func (tx *LegacyTx) gas() uint64 { return tx.Gas } func (tx *LegacyTx) gas() uint64 { return tx.Gas }
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice } func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) tip() *big.Int { return tx.GasPrice } func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) feeCap() *big.Int { return tx.GasPrice } func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) value() *big.Int { return tx.Value } func (tx *LegacyTx) value() *big.Int { return tx.Value }
func (tx *LegacyTx) nonce() uint64 { return tx.Nonce } func (tx *LegacyTx) nonce() uint64 { return tx.Nonce }
func (tx *LegacyTx) to() *common.Address { return tx.To } func (tx *LegacyTx) to() *common.Address { return tx.To }

View file

@ -43,9 +43,10 @@ var (
errInvalidYParity = errors.New("'yParity' field must be 0 or 1") errInvalidYParity = errors.New("'yParity' field must be 0 or 1")
errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match")
errVYParityMissing = errors.New("missing 'yParity' or 'v' field in transaction") errVYParityMissing = errors.New("missing 'yParity' or 'v' field in transaction")
ErrFeeCapTooLow = errors.New("fee cap less than base fee")
errEmptyTypedTx = errors.New("empty typed transaction bytes") errEmptyTypedTx = errors.New("empty typed transaction bytes")
errNoSigner = errors.New("missing signing methods") errNoSigner = errors.New("missing signing methods")
ErrFeeCapTooLow = errors.New("fee cap less than base fee")
skipNonceDestinationAddress = map[common.Address]bool{ skipNonceDestinationAddress = map[common.Address]bool{
common.XDCXAddrBinary: true, common.XDCXAddrBinary: true,
common.TradingStateAddrBinary: true, common.TradingStateAddrBinary: true,
@ -91,8 +92,8 @@ type TxData interface {
data() []byte data() []byte
gas() uint64 gas() uint64
gasPrice() *big.Int gasPrice() *big.Int
tip() *big.Int gasTipCap() *big.Int
feeCap() *big.Int gasFeeCap() *big.Int
value() *big.Int value() *big.Int
nonce() uint64 nonce() uint64
to() *common.Address to() *common.Address
@ -283,11 +284,11 @@ func (tx *Transaction) Gas() uint64 { return tx.inner.gas() }
// GasPrice returns the gas price of the transaction. // GasPrice returns the gas price of the transaction.
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) } func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) }
// Tip returns the tip per gas of the transaction. // GasTipCap returns the gasTipCap per gas of the transaction.
func (tx *Transaction) Tip() *big.Int { return new(big.Int).Set(tx.inner.tip()) } func (tx *Transaction) GasTipCap() *big.Int { return new(big.Int).Set(tx.inner.gasTipCap()) }
// FeeCap returns the fee cap per gas of the transaction. // GasFeeCap returns the fee cap per gas of the transaction.
func (tx *Transaction) FeeCap() *big.Int { return new(big.Int).Set(tx.inner.feeCap()) } func (tx *Transaction) GasFeeCap() *big.Int { return new(big.Int).Set(tx.inner.gasFeeCap()) }
// Value returns the ether amount of the transaction. // Value returns the ether amount of the transaction.
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) } func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) }
@ -334,62 +335,62 @@ func (tx *Transaction) RawSignatureValues() (v, r, s *big.Int) {
return tx.inner.rawSignatureValues() return tx.inner.rawSignatureValues()
} }
// FeeCapCmp compares the fee cap of two transactions. // GasFeeCapCmp compares the fee cap of two transactions.
func (tx *Transaction) FeeCapCmp(other *Transaction) int { func (tx *Transaction) GasFeeCapCmp(other *Transaction) int {
return tx.inner.feeCap().Cmp(other.inner.feeCap()) return tx.inner.gasFeeCap().Cmp(other.inner.gasFeeCap())
} }
// FeeCapIntCmp compares the fee cap of the transaction against the given fee cap. // GasFeeCapIntCmp compares the fee cap of the transaction against the given fee cap.
func (tx *Transaction) FeeCapIntCmp(other *big.Int) int { func (tx *Transaction) GasFeeCapIntCmp(other *big.Int) int {
return tx.inner.feeCap().Cmp(other) return tx.inner.gasFeeCap().Cmp(other)
} }
// TipCmp compares the tip of two transactions. // GasTipCapCmp compares the gasTipCap of two transactions.
func (tx *Transaction) TipCmp(other *Transaction) int { func (tx *Transaction) GasTipCapCmp(other *Transaction) int {
return tx.inner.tip().Cmp(other.inner.tip()) return tx.inner.gasTipCap().Cmp(other.inner.gasTipCap())
} }
// TipIntCmp compares the tip of the transaction against the given tip. // GasTipCapIntCmp compares the gasTipCap of the transaction against the given gasTipCap.
func (tx *Transaction) TipIntCmp(other *big.Int) int { func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int {
return tx.inner.tip().Cmp(other) return tx.inner.gasTipCap().Cmp(other)
} }
// EffectiveTip returns the effective miner tip for the given base fee. // EffectiveGasTip returns the effective miner gasTipCap for the given base fee.
// Note: if the effective tip is negative, this method returns both error // Note: if the effective gasTipCap is negative, this method returns both error
// the actual negative value, _and_ ErrFeeCapTooLow // the actual negative value, _and_ ErrGasFeeCapTooLow
func (tx *Transaction) EffectiveTip(baseFee *big.Int) (*big.Int, error) { func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) {
if baseFee == nil { if baseFee == nil {
return tx.Tip(), nil return tx.GasTipCap(), nil
} }
var err error var err error
feeCap := tx.FeeCap() gasFeeCap := tx.GasFeeCap()
if feeCap.Cmp(baseFee) == -1 { if gasFeeCap.Cmp(baseFee) == -1 {
err = ErrFeeCapTooLow err = ErrGasFeeCapTooLow
} }
return math.BigMin(tx.Tip(), feeCap.Sub(feeCap, baseFee)), err return math.BigMin(tx.GasTipCap(), gasFeeCap.Sub(gasFeeCap, baseFee)), err
} }
// EffectiveTipValue is identical to EffectiveTip, but does not return an // EffectiveGasTipValue is identical to EffectiveGasTip, but does not return an
// error in case the effective tip is negative // error in case the effective gasTipCap is negative
func (tx *Transaction) EffectiveTipValue(baseFee *big.Int) *big.Int { func (tx *Transaction) EffectiveGasTipValue(baseFee *big.Int) *big.Int {
effectiveTip, _ := tx.EffectiveTip(baseFee) effectiveTip, _ := tx.EffectiveGasTip(baseFee)
return effectiveTip return effectiveTip
} }
// EffectiveTipCmp compares the effective tip of two transactions assuming the given base fee. // EffectiveGasTipCmp compares the effective gasTipCap of two transactions assuming the given base fee.
func (tx *Transaction) EffectiveTipCmp(other *Transaction, baseFee *big.Int) int { func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int {
if baseFee == nil { if baseFee == nil {
return tx.TipCmp(other) return tx.GasTipCapCmp(other)
} }
return tx.EffectiveTipValue(baseFee).Cmp(other.EffectiveTipValue(baseFee)) return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
} }
// EffectiveTipIntCmp compares the effective tip of a transaction to the given tip. // EffectiveTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int { func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int {
if baseFee == nil { if baseFee == nil {
return tx.TipIntCmp(other) return tx.GasTipCapIntCmp(other)
} }
return tx.EffectiveTipValue(baseFee).Cmp(other) return tx.EffectiveGasTipValue(baseFee).Cmp(other)
} }
// Hash returns the transaction hash. // Hash returns the transaction hash.
@ -426,8 +427,8 @@ func (tx *Transaction) AsMessage(s Signer, balanceFee, blockNumber, baseFee *big
nonce: tx.Nonce(), nonce: tx.Nonce(),
gasLimit: tx.Gas(), gasLimit: tx.Gas(),
gasPrice: new(big.Int).Set(tx.GasPrice()), gasPrice: new(big.Int).Set(tx.GasPrice()),
feeCap: new(big.Int).Set(tx.FeeCap()), gasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
tip: new(big.Int).Set(tx.Tip()), gasTipCap: new(big.Int).Set(tx.GasTipCap()),
to: tx.To(), to: tx.To(),
amount: tx.Value(), amount: tx.Value(),
data: tx.Data(), data: tx.Data(),
@ -448,7 +449,7 @@ func (tx *Transaction) AsMessage(s Signer, balanceFee, blockNumber, baseFee *big
} }
} else if baseFee != nil { } else if baseFee != nil {
// If baseFee provided, set gasPrice to effectiveGasPrice. // If baseFee provided, set gasPrice to effectiveGasPrice.
msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.tip, baseFee), msg.feeCap) msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.gasTipCap, baseFee), msg.gasFeeCap)
} }
var err error var err error
@ -813,15 +814,15 @@ type Message struct {
amount *big.Int amount *big.Int
gasLimit uint64 gasLimit uint64
gasPrice *big.Int gasPrice *big.Int
feeCap *big.Int gasFeeCap *big.Int
tip *big.Int gasTipCap *big.Int
data []byte data []byte
accessList AccessList accessList AccessList
checkNonce bool checkNonce bool
balanceTokenFee *big.Int balanceTokenFee *big.Int
} }
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, feeCap, tip *big.Int, data []byte, accessList AccessList, checkNonce bool, balanceTokenFee *big.Int, number *big.Int) Message { func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, checkNonce bool, balanceTokenFee *big.Int, number *big.Int) Message {
if balanceTokenFee != nil { if balanceTokenFee != nil {
gasPrice = common.GetGasPrice(number) gasPrice = common.GetGasPrice(number)
} }
@ -832,8 +833,8 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
amount: amount, amount: amount,
gasLimit: gasLimit, gasLimit: gasLimit,
gasPrice: gasPrice, gasPrice: gasPrice,
feeCap: feeCap, gasFeeCap: gasFeeCap,
tip: tip, gasTipCap: gasTipCap,
data: data, data: data,
accessList: accessList, accessList: accessList,
checkNonce: checkNonce, checkNonce: checkNonce,
@ -845,8 +846,8 @@ func (m Message) From() common.Address { return m.from }
func (m Message) BalanceTokenFee() *big.Int { return m.balanceTokenFee } func (m Message) BalanceTokenFee() *big.Int { return m.balanceTokenFee }
func (m Message) To() *common.Address { return m.to } func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice } func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) FeeCap() *big.Int { return m.feeCap } func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
func (m Message) Tip() *big.Int { return m.tip } func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
func (m Message) Value() *big.Int { return m.amount } func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit } func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Nonce() uint64 { return m.nonce }

View file

@ -86,8 +86,8 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
enc.AccessList = &tx.AccessList enc.AccessList = &tx.AccessList
enc.Nonce = (*hexutil.Uint64)(&tx.Nonce) enc.Nonce = (*hexutil.Uint64)(&tx.Nonce)
enc.Gas = (*hexutil.Uint64)(&tx.Gas) enc.Gas = (*hexutil.Uint64)(&tx.Gas)
enc.MaxFeePerGas = (*hexutil.Big)(tx.FeeCap) enc.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap)
enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.Tip) enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap)
enc.Value = (*hexutil.Big)(tx.Value) enc.Value = (*hexutil.Big)(tx.Value)
enc.Data = (*hexutil.Bytes)(&tx.Data) enc.Data = (*hexutil.Bytes)(&tx.Data)
enc.To = t.To() enc.To = t.To()
@ -227,11 +227,11 @@ func (t *Transaction) UnmarshalJSON(input []byte) error {
if dec.MaxPriorityFeePerGas == nil { if dec.MaxPriorityFeePerGas == nil {
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata") return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
} }
itx.Tip = (*big.Int)(dec.MaxPriorityFeePerGas) itx.GasTipCap = (*big.Int)(dec.MaxPriorityFeePerGas)
if dec.MaxFeePerGas == nil { if dec.MaxFeePerGas == nil {
return errors.New("missing required field 'maxFeePerGas' for txdata") return errors.New("missing required field 'maxFeePerGas' for txdata")
} }
itx.FeeCap = (*big.Int)(dec.MaxFeePerGas) itx.GasFeeCap = (*big.Int)(dec.MaxFeePerGas)
if dec.Gas == nil { if dec.Gas == nil {
return errors.New("missing required field 'gas' for txdata") return errors.New("missing required field 'gas' for txdata")
} }

View file

@ -226,8 +226,8 @@ func (s londonSigner) Hash(tx *Transaction) common.Hash {
[]interface{}{ []interface{}{
s.chainId, s.chainId,
tx.Nonce(), tx.Nonce(),
tx.Tip(), tx.GasTipCap(),
tx.FeeCap(), tx.GasFeeCap(),
tx.Gas(), tx.Gas(),
tx.To(), tx.To(),
tx.Value(), tx.Value(),

View file

@ -219,8 +219,8 @@ func (s *txSorter) Swap(i, j int) {
func (s *txSorter) Less(i, j int) bool { func (s *txSorter) Less(i, j int) bool {
// It's okay to discard the error because a tx would never be // It's okay to discard the error because a tx would never be
// accepted into a block with an invalid effective tip. // accepted into a block with an invalid effective tip.
tip1, _ := s.txs[i].EffectiveTip(s.baseFee) tip1, _ := s.txs[i].EffectiveGasTip(s.baseFee)
tip2, _ := s.txs[j].EffectiveTip(s.baseFee) tip2, _ := s.txs[j].EffectiveGasTip(s.baseFee)
return tip1.Cmp(tip2) < 0 return tip1.Cmp(tip2) < 0
} }
@ -245,7 +245,7 @@ func (gpo *Oracle) getBlockValues(ctx context.Context, signer types.Signer, bloc
var prices []*big.Int var prices []*big.Int
for _, tx := range sorter.txs { for _, tx := range sorter.txs {
tip, _ := tx.EffectiveTip(block.BaseFee()) tip, _ := tx.EffectiveGasTip(block.BaseFee())
if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 { if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 {
continue continue
} }

View file

@ -84,8 +84,8 @@ func newTestBackend(t *testing.T, eip1559Block *big.Int) *testBackend {
Nonce: b.TxNonce(addr), Nonce: b.TxNonce(addr),
To: &common.Address{}, To: &common.Address{},
Gas: 30000, Gas: 30000,
FeeCap: big.NewInt(100 * params.GWei), GasFeeCap: big.NewInt(100 * params.GWei),
Tip: big.NewInt(int64(i+1) * params.GWei), GasTipCap: big.NewInt(int64(i+1) * params.GWei),
Data: []byte{}, Data: []byte{},
} }
tx = types.NewTx(txdata) tx = types.NewTx(txdata)

View file

@ -117,13 +117,12 @@ type CallMsg struct {
To *common.Address // the destination contract (nil for contract creation) To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio GasPrice *big.Int // wei <-> gas exchange ratio
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
GasTipCap *big.Int // EIP-1559 tip per gas.
Value *big.Int // amount of wei sent along with the call Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation Data []byte // input data, usually an ABI-encoded contract method invocation
BalanceTokenFee *big.Int BalanceTokenFee *big.Int
FeeCap *big.Int // EIP-1559 fee cap per gas.
Tip *big.Int // EIP-1559 tip per gas.
AccessList types.AccessList // EIP-2930 access list. AccessList types.AccessList // EIP-2930 access list.
} }

View file

@ -1803,8 +1803,8 @@ type RPCTransaction struct {
From common.Address `json:"from"` From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"` Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"` GasPrice *hexutil.Big `json:"gasPrice"`
FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
Hash common.Hash `json:"hash"` Hash common.Hash `json:"hash"`
Input hexutil.Bytes `json:"input"` Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"` Nonce hexutil.Uint64 `json:"nonce"`
@ -1862,12 +1862,12 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
al := tx.AccessList() al := tx.AccessList()
result.Accesses = &al result.Accesses = &al
result.ChainID = (*hexutil.Big)(tx.ChainId()) result.ChainID = (*hexutil.Big)(tx.ChainId())
result.FeeCap = (*hexutil.Big)(tx.FeeCap()) result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
result.Tip = (*hexutil.Big)(tx.Tip()) result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
// if the transaction has been mined, compute the effective gas price // if the transaction has been mined, compute the effective gas price
if baseFee != nil && blockHash != (common.Hash{}) { if baseFee != nil && blockHash != (common.Hash{}) {
// price = min(tip, feeCap - baseFee) + baseFee = min(tip + baseFee, feeCap) // price = min(tip, gasFeeCap - baseFee) + baseFee
price := math.BigMin(new(big.Int).Add(tx.Tip(), baseFee), tx.FeeCap()) price := math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee), tx.GasFeeCap())
result.GasPrice = (*hexutil.Big)(price) result.GasPrice = (*hexutil.Big)(price)
} else { } else {
result.GasPrice = nil result.GasPrice = nil

View file

@ -38,8 +38,8 @@ type TransactionArgs struct {
To *common.Address `json:"to"` To *common.Address `json:"to"`
Gas *hexutil.Uint64 `json:"gas"` Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"` GasPrice *hexutil.Big `json:"gasPrice"`
FeeCap *hexutil.Big `json:"maxFeePerGas"` MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
Tip *hexutil.Big `json:"maxPriorityFeePerGas"` MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
Value *hexutil.Big `json:"value"` Value *hexutil.Big `json:"value"`
Nonce *hexutil.Uint64 `json:"nonce"` Nonce *hexutil.Uint64 `json:"nonce"`
@ -75,31 +75,31 @@ func (arg *TransactionArgs) data() []byte {
// setDefaults fills in default values for unspecified tx fields. // setDefaults fills in default values for unspecified tx fields.
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error { func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
if args.GasPrice != nil && (args.FeeCap != nil || args.Tip != nil) { if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} }
// After london, default to 1559 unless gasPrice is set // After london, default to 1559 unless gasPrice is set
head := b.CurrentHeader() head := b.CurrentHeader()
if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil { if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil {
if args.Tip == nil { if args.MaxPriorityFeePerGas == nil {
tip, err := b.SuggestGasTipCap(ctx) tip, err := b.SuggestGasTipCap(ctx)
if err != nil { if err != nil {
return err return err
} }
args.Tip = (*hexutil.Big)(tip) args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
} }
if args.FeeCap == nil { if args.MaxFeePerGas == nil {
feeCap := new(big.Int).Add( gasFeeCap := new(big.Int).Add(
(*big.Int)(args.Tip), (*big.Int)(args.MaxPriorityFeePerGas),
new(big.Int).Mul(head.BaseFee, big.NewInt(2)), new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
) )
args.FeeCap = (*hexutil.Big)(feeCap) args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
} }
if args.FeeCap.ToInt().Cmp(args.Tip.ToInt()) < 0 { if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.FeeCap, args.Tip) return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
} }
} else { } else {
if args.FeeCap != nil || args.Tip != nil { if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet") return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
} }
if args.GasPrice == nil { if args.GasPrice == nil {
@ -138,8 +138,8 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
From: args.From, From: args.From,
To: args.To, To: args.To,
GasPrice: args.GasPrice, GasPrice: args.GasPrice,
FeeCap: args.FeeCap, MaxFeePerGas: args.MaxFeePerGas,
Tip: args.Tip, MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
Value: args.Value, Value: args.Value,
Data: (*hexutil.Bytes)(&data), Data: (*hexutil.Bytes)(&data),
AccessList: args.AccessList, AccessList: args.AccessList,
@ -162,7 +162,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
// ToMessage converts TransactionArgs to the Message type used by the core evm // ToMessage converts TransactionArgs to the Message type used by the core evm
func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64, baseFee *big.Int) (types.Message, error) { func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64, baseFee *big.Int) (types.Message, error) {
// Reject invalid combinations of pre- and post-1559 fee styles // Reject invalid combinations of pre- and post-1559 fee styles
if args.GasPrice != nil && (args.FeeCap != nil || args.Tip != nil) { if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
return types.Message{}, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified") return types.Message{}, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
} }
@ -191,8 +191,8 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap
var ( var (
gasPrice *big.Int gasPrice *big.Int
feeCap *big.Int gasFeeCap *big.Int
tip *big.Int gasTipCap *big.Int
) )
if baseFee == nil { if baseFee == nil {
// If there's no basefee, then it must be a non-1559 execution // If there's no basefee, then it must be a non-1559 execution
@ -203,22 +203,22 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap
if gasPrice.Sign() <= 0 { if gasPrice.Sign() <= 0 {
gasPrice = new(big.Int).SetUint64(defaultGasPrice) gasPrice = new(big.Int).SetUint64(defaultGasPrice)
} }
feeCap, tip = gasPrice, gasPrice gasFeeCap, gasTipCap = gasPrice, gasPrice
} else { } else {
// A basefee is provided, necessitating 1559-type execution // A basefee is provided, necessitating 1559-type execution
if args.GasPrice != nil { if args.GasPrice != nil {
gasPrice = args.GasPrice.ToInt() gasPrice = args.GasPrice.ToInt()
feeCap, tip = gasPrice, gasPrice gasFeeCap, gasTipCap = gasPrice, gasPrice
} else { } else {
feeCap = new(big.Int) gasFeeCap = new(big.Int)
if args.FeeCap != nil { if args.MaxFeePerGas != nil {
feeCap = args.FeeCap.ToInt() gasFeeCap = args.MaxFeePerGas.ToInt()
} }
tip = new(big.Int) gasTipCap = new(big.Int)
if args.Tip != nil { if args.MaxPriorityFeePerGas != nil {
tip = args.Tip.ToInt() gasTipCap = args.MaxPriorityFeePerGas.ToInt()
} }
gasPrice = math.BigMin(new(big.Int).Add(tip, baseFee), feeCap) gasPrice = math.BigMin(new(big.Int).Add(gasTipCap, baseFee), gasFeeCap)
} }
} }
value := new(big.Int) value := new(big.Int)
@ -231,8 +231,7 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap
accessList = *args.AccessList accessList = *args.AccessList
} }
// Create new call message msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, false, nil, number)
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, feeCap, tip, data, accessList, false, nil, number)
return msg, nil return msg, nil
} }
@ -241,7 +240,7 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap
func (args *TransactionArgs) toTransaction() *types.Transaction { func (args *TransactionArgs) toTransaction() *types.Transaction {
var data types.TxData var data types.TxData
switch { switch {
case args.FeeCap != nil: case args.MaxFeePerGas != nil:
al := types.AccessList{} al := types.AccessList{}
if args.AccessList != nil { if args.AccessList != nil {
al = *args.AccessList al = *args.AccessList
@ -251,8 +250,8 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
ChainID: (*big.Int)(args.ChainID), ChainID: (*big.Int)(args.ChainID),
Nonce: uint64(*args.Nonce), Nonce: uint64(*args.Nonce),
Gas: uint64(*args.Gas), Gas: uint64(*args.Gas),
FeeCap: (*big.Int)(args.FeeCap), GasFeeCap: (*big.Int)(args.MaxFeePerGas),
Tip: (*big.Int)(args.Tip), GasTipCap: (*big.Int)(args.MaxPriorityFeePerGas),
Value: (*big.Int)(args.Value), Value: (*big.Int)(args.Value),
Data: args.data(), Data: args.data(),
AccessList: al, AccessList: al,