diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 4ef16cf9a58c..67f592d6c242 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -523,8 +523,8 @@ func (m callMsg) Nonce() uint64 { return 0 } func (m callMsg) CheckNonce() bool { return false } func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } -func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap } -func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip } +func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap } +func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap } func (m callMsg) Gas() uint64 { return m.CallMsg.Gas } func (m callMsg) Value() *big.Int { return m.CallMsg.Value } func (m callMsg) Data() []byte { return m.CallMsg.Data } diff --git a/core/error.go b/core/error.go index ffa07e23e50a..7616f4b3af27 100644 --- a/core/error.go +++ b/core/error.go @@ -52,17 +52,17 @@ var ( // ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a // 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 // 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 // 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 // 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") ) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 1327471c6a90..c07d3c50656d 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -63,14 +63,14 @@ func TestStateProcessorErrors(t *testing.T) { } 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{ - Nonce: nonce, - Tip: tip, - FeeCap: feeCap, - Gas: gasLimit, - To: &to, - Value: big.NewInt(0), + Nonce: nonce, + GasTipCap: gasTipCap, + GasFeeCap: gasFeeCap, + Gas: gasLimit, + To: &to, + Value: big.NewInt(0), }), signer, testKey) return tx } @@ -148,25 +148,25 @@ func TestStateProcessorErrors(t *testing.T) { txs: []*types.Transaction{ 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 txs: []*types.Transaction{ 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 txs: []*types.Transaction{ 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 txs: []*types.Transaction{ 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 // Available balance: 1000000000000000000 diff --git a/core/state_transition.go b/core/state_transition.go index 17dba21a8cd3..c7d746a99a85 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -58,8 +58,8 @@ type StateTransition struct { msg Message gas uint64 gasPrice *big.Int - feeCap *big.Int - tip *big.Int + gasFeeCap *big.Int + gasTipCap *big.Int initialGas uint64 value *big.Int data []byte @@ -74,8 +74,8 @@ type Message interface { To() *common.Address GasPrice() *big.Int - FeeCap() *big.Int - Tip() *big.Int + GasFeeCap() *big.Int + GasTipCap() *big.Int Gas() uint64 Value() *big.Int @@ -126,15 +126,15 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation, // NewStateTransition initialises and returns a new state transition object. func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition { return &StateTransition{ - gp: gp, - evm: evm, - msg: msg, - gasPrice: msg.GasPrice(), - feeCap: msg.FeeCap(), - tip: msg.Tip(), - value: msg.Value(), - data: msg.Data(), - state: evm.StateDB, + gp: gp, + evm: evm, + msg: msg, + gasPrice: msg.GasPrice(), + gasFeeCap: msg.GasFeeCap(), + gasTipCap: msg.GasTipCap(), + value: msg.Value(), + data: msg.Data(), + state: evm.StateDB, } } @@ -183,9 +183,9 @@ func (st *StateTransition) buyGas() error { balanceTokenFee := st.balanceTokenFee() if balanceTokenFee == nil { balanceCheck := mgval - if st.feeCap != nil { + if st.gasFeeCap != nil { 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 { return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want) @@ -217,25 +217,25 @@ func (st *StateTransition) preCheck() error { st.msg.From().Hex(), msgNonce, 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 l := st.feeCap.BitLen(); l > 256 { - return fmt.Errorf("%w: address %v, feeCap bit length: %d", ErrFeeCapVeryHigh, + if l := st.gasFeeCap.BitLen(); l > 256 { + return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh, st.msg.From().Hex(), l) } - if l := st.tip.BitLen(); l > 256 { - return fmt.Errorf("%w: address %v, tip bit length: %d", ErrTipVeryHigh, + if l := st.gasTipCap.BitLen(); l > 256 { + return fmt.Errorf("%w: address %v, maxPriorityFeePerGas bit length: %d", ErrTipVeryHigh, st.msg.From().Hex(), l) } - if st.feeCap.Cmp(st.tip) < 0 { - return fmt.Errorf("%w: address %v, tip: %s, feeCap: %s", ErrTipAboveFeeCap, - st.msg.From().Hex(), st.feeCap, st.tip) + if st.gasFeeCap.Cmp(st.gasTipCap) < 0 { + return fmt.Errorf("%w: address %v, maxPriorityFeePerGas: %s, maxFeePerGas: %s", ErrTipAboveFeeCap, + st.msg.From().Hex(), st.gasTipCap, st.gasFeeCap) } // This will panic if baseFee is nil, but basefee presence is verified // as part of header validation. - if st.feeCap.Cmp(st.evm.Context.BaseFee) < 0 { - return fmt.Errorf("%w: address %v, feeCap: %s baseFee: %s", ErrFeeCapTooLow, - st.msg.From().Hex(), st.feeCap, st.evm.Context.BaseFee) + if st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 { + return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow, + st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee) } } return st.buyGas() @@ -250,12 +250,11 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG } msg := st.msg sender := st.from() // err checked in preCheck - homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber) eip3529 := st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) 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) if err != nil { return nil, 0, false, err, nil @@ -314,7 +313,7 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG } else { effectiveTip := st.gasPrice 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.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)) } diff --git a/core/token_validator.go b/core/token_validator.go index 7532da8ebc8f..a60f60c7bcab 100644 --- a/core/token_validator.go +++ b/core/token_validator.go @@ -48,8 +48,8 @@ func (m callMsg) Nonce() uint64 { return 0 } func (m callMsg) CheckNonce() bool { return false } func (m callMsg) To() *common.Address { return m.CallMsg.To } func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice } -func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap } -func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip } +func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap } +func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap } func (m callMsg) Gas() uint64 { return m.CallMsg.Gas } func (m callMsg) Value() *big.Int { return m.CallMsg.Value } func (m callMsg) Data() []byte { return m.CallMsg.Data } diff --git a/core/tx_list.go b/core/tx_list.go index fd2985af7a95..8e92debe4934 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -285,13 +285,13 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran return false, 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 } // thresholdFeeCap = oldFC * (100 + priceBump) / 100 a := big.NewInt(100 + int64(priceBump)) - aFeeCap := new(big.Int).Mul(a, old.FeeCap()) - aTip := a.Mul(a, old.Tip()) + aFeeCap := new(big.Int).Mul(a, old.GasFeeCap()) + aTip := a.Mul(a, old.GasTipCap()) // thresholdTip = oldTip * (100 + priceBump) / 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 // old ones as well as checking the percentage threshold to ensure that // 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 } } @@ -428,7 +428,7 @@ func (l *txList) LastElement() *types.Transaction { // priceHeap is a heap.Interface implementation over transactions for retrieving // 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. -// 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 { baseFee *big.Int // heap should always be re-sorted after baseFee is changed list []*types.Transaction @@ -451,16 +451,16 @@ func (h *priceHeap) Less(i, j int) bool { func (h *priceHeap) cmp(a, b *types.Transaction) int { if h.baseFee != nil { // 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 } } // 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 } // Compare tips if effective tips and fee caps are equal - return a.TipCmp(b) + return a.GasTipCapCmp(b) } func (h *priceHeap) Push(x interface{}) { @@ -483,7 +483,7 @@ func (h *priceHeap) Pop() interface{} { // will be considered for tracking, sorting, eviction, etc. // // 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. // 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) diff --git a/core/tx_pool.go b/core/tx_pool.go index 0d910f594c83..a75fe08f34ae 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -475,7 +475,7 @@ func (pool *TxPool) SetGasPrice(price *big.Int) { pool.gasPrice = price // if the min miner fee increased, remove transactions below the new threshold 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) for _, tx := range drop { pool.removeTx(tx.Hash(), false) @@ -631,14 +631,14 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { return ErrGasLimit } // Sanity check for extremely large numbers - if tx.FeeCap().BitLen() > 256 { + if tx.GasFeeCap().BitLen() > 256 { return ErrFeeCapVeryHigh } - if tx.Tip().BitLen() > 256 { + if tx.GasTipCap().BitLen() > 256 { return ErrTipVeryHigh } - // Ensure feeCap is greater than or equal to tip. - if tx.FeeCapIntCmp(tx.Tip()) < 0 { + // Ensure gasFeeCap is greater than or equal to gasTipCap. + if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 { return ErrTipAboveFeeCap } // Make sure the transaction is signed properly. @@ -647,7 +647,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { return ErrInvalidSender } // 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)) { 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 the new transaction is underpriced, don't accept it 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) 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. 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) 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 { found := make(types.Transactions, 0, 128) 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) } return true diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 45b615689035..3e0bcb7b055a 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -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{ ChainID: params.TestChainConfig.ChainId, Nonce: nonce, - Tip: tip, - FeeCap: gasFee, + GasTipCap: tip, + GasFeeCap: gasFee, Gas: gaslimit, To: &common.Address{}, Value: big.NewInt(100), @@ -2177,17 +2177,17 @@ func TestTransactionReplacementDynamicFee(t *testing.T) { defer sub.Unsubscribe() // Add pending transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too) - feeCap := int64(100) - feeCapThreshold := (feeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100 - tip := int64(60) - tipThreshold := (tip * (100 + int64(testTxPoolConfig.PriceBump))) / 100 + gasFeeCap := int64(100) + feeCapThreshold := (gasFeeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100 + gasTipCap := int64(60) + tipThreshold := (gasTipCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100 // Run the following identical checks for both the pending and queue pools: // 1. Send initial tx => accept // 2. Don't bump tip or fee cap => discard // 3. Bump both more than min => accept // 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 // 7. Bump fee cap max allowed so it's still underpriced => 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) } // 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 { t.Fatalf("failed to add original proper %s transaction: %v", stage, err) } // 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 { 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 - 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 { t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) } // 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 { t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) } // 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 { t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced) } diff --git a/core/types/access_list_tx.go b/core/types/access_list_tx.go index 2131a743f113..265fd7545812 100644 --- a/core/types/access_list_tx.go +++ b/core/types/access_list_tx.go @@ -94,7 +94,6 @@ func (tx *AccessListTx) copy() TxData { } // accessors for innerTx. - func (tx *AccessListTx) txType() byte { return AccessListTxType } func (tx *AccessListTx) chainID() *big.Int { return tx.ChainID } 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) gas() uint64 { return tx.Gas } func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice } -func (tx *AccessListTx) tip() *big.Int { return tx.GasPrice } -func (tx *AccessListTx) feeCap() *big.Int { return tx.GasPrice } +func (tx *AccessListTx) gasTipCap() *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) nonce() uint64 { return tx.Nonce } func (tx *AccessListTx) to() *common.Address { return tx.To } diff --git a/core/types/dynamic_fee_tx.go b/core/types/dynamic_fee_tx.go index ef4c66f2f58c..7dfb2ad9f37a 100644 --- a/core/types/dynamic_fee_tx.go +++ b/core/types/dynamic_fee_tx.go @@ -25,8 +25,8 @@ import ( type DynamicFeeTx struct { ChainID *big.Int Nonce uint64 - Tip *big.Int - FeeCap *big.Int + GasTipCap *big.Int + GasFeeCap *big.Int Gas uint64 To *common.Address `rlp:"nil"` // nil means contract creation Value *big.Int @@ -50,8 +50,8 @@ func (tx *DynamicFeeTx) copy() TxData { AccessList: make(AccessList, len(tx.AccessList)), Value: new(big.Int), ChainID: new(big.Int), - Tip: new(big.Int), - FeeCap: new(big.Int), + GasTipCap: new(big.Int), + GasFeeCap: new(big.Int), V: new(big.Int), R: new(big.Int), S: new(big.Int), @@ -63,11 +63,11 @@ func (tx *DynamicFeeTx) copy() TxData { if tx.ChainID != nil { cpy.ChainID.Set(tx.ChainID) } - if tx.Tip != nil { - cpy.Tip.Set(tx.Tip) + if tx.GasTipCap != nil { + cpy.GasTipCap.Set(tx.GasTipCap) } - if tx.FeeCap != nil { - cpy.FeeCap.Set(tx.FeeCap) + if tx.GasFeeCap != nil { + cpy.GasFeeCap.Set(tx.GasFeeCap) } if tx.V != nil { 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) data() []byte { return tx.Data } func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas } -func (tx *DynamicFeeTx) feeCap() *big.Int { return tx.FeeCap } -func (tx *DynamicFeeTx) tip() *big.Int { return tx.Tip } -func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.FeeCap } +func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap } +func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap } +func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap } func (tx *DynamicFeeTx) value() *big.Int { return tx.Value } func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce } func (tx *DynamicFeeTx) to() *common.Address { return tx.To } diff --git a/core/types/legacy_tx.go b/core/types/legacy_tx.go index 5593f87b3100..819909a2a375 100644 --- a/core/types/legacy_tx.go +++ b/core/types/legacy_tx.go @@ -98,8 +98,8 @@ func (tx *LegacyTx) accessList() AccessList { return nil } func (tx *LegacyTx) data() []byte { return tx.Data } func (tx *LegacyTx) gas() uint64 { return tx.Gas } func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice } -func (tx *LegacyTx) tip() *big.Int { return tx.GasPrice } -func (tx *LegacyTx) feeCap() *big.Int { return tx.GasPrice } +func (tx *LegacyTx) gasTipCap() *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) nonce() uint64 { return tx.Nonce } func (tx *LegacyTx) to() *common.Address { return tx.To } diff --git a/core/types/transaction.go b/core/types/transaction.go index 5b785a69da87..7029b7750ee0 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -34,18 +34,19 @@ import ( //go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go var ( - ErrInvalidSig = errors.New("invalid transaction v, r, s values") - ErrUnexpectedProtection = errors.New("transaction type does not supported EIP-155 protected signatures") - ErrInvalidTxType = errors.New("transaction type not valid in this context") - ErrTxTypeNotSupported = errors.New("transaction type not supported") - ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") - errShortTypedTx = errors.New("typed transaction too short") - errInvalidYParity = errors.New("'yParity' field must be 0 or 1") - errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") - 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") - errNoSigner = errors.New("missing signing methods") + ErrInvalidSig = errors.New("invalid transaction v, r, s values") + ErrUnexpectedProtection = errors.New("transaction type does not supported EIP-155 protected signatures") + ErrInvalidTxType = errors.New("transaction type not valid in this context") + ErrTxTypeNotSupported = errors.New("transaction type not supported") + ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") + errShortTypedTx = errors.New("typed transaction too short") + errInvalidYParity = errors.New("'yParity' field must be 0 or 1") + errVYParityMismatch = errors.New("'v' and 'yParity' fields do not match") + errVYParityMissing = errors.New("missing 'yParity' or 'v' field in transaction") + errEmptyTypedTx = errors.New("empty typed transaction bytes") + errNoSigner = errors.New("missing signing methods") + ErrFeeCapTooLow = errors.New("fee cap less than base fee") + skipNonceDestinationAddress = map[common.Address]bool{ common.XDCXAddrBinary: true, common.TradingStateAddrBinary: true, @@ -91,8 +92,8 @@ type TxData interface { data() []byte gas() uint64 gasPrice() *big.Int - tip() *big.Int - feeCap() *big.Int + gasTipCap() *big.Int + gasFeeCap() *big.Int value() *big.Int nonce() uint64 to() *common.Address @@ -283,11 +284,11 @@ func (tx *Transaction) Gas() uint64 { return tx.inner.gas() } // GasPrice returns the gas price of the transaction. func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) } -// Tip returns the tip per gas of the transaction. -func (tx *Transaction) Tip() *big.Int { return new(big.Int).Set(tx.inner.tip()) } +// GasTipCap returns the gasTipCap per gas of the transaction. +func (tx *Transaction) GasTipCap() *big.Int { return new(big.Int).Set(tx.inner.gasTipCap()) } -// FeeCap returns the fee cap per gas of the transaction. -func (tx *Transaction) FeeCap() *big.Int { return new(big.Int).Set(tx.inner.feeCap()) } +// GasFeeCap returns the fee cap per gas of the transaction. +func (tx *Transaction) GasFeeCap() *big.Int { return new(big.Int).Set(tx.inner.gasFeeCap()) } // Value returns the ether amount of the transaction. 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() } -// FeeCapCmp compares the fee cap of two transactions. -func (tx *Transaction) FeeCapCmp(other *Transaction) int { - return tx.inner.feeCap().Cmp(other.inner.feeCap()) +// GasFeeCapCmp compares the fee cap of two transactions. +func (tx *Transaction) GasFeeCapCmp(other *Transaction) int { + return tx.inner.gasFeeCap().Cmp(other.inner.gasFeeCap()) } -// FeeCapIntCmp compares the fee cap of the transaction against the given fee cap. -func (tx *Transaction) FeeCapIntCmp(other *big.Int) int { - return tx.inner.feeCap().Cmp(other) +// GasFeeCapIntCmp compares the fee cap of the transaction against the given fee cap. +func (tx *Transaction) GasFeeCapIntCmp(other *big.Int) int { + return tx.inner.gasFeeCap().Cmp(other) } -// TipCmp compares the tip of two transactions. -func (tx *Transaction) TipCmp(other *Transaction) int { - return tx.inner.tip().Cmp(other.inner.tip()) +// GasTipCapCmp compares the gasTipCap of two transactions. +func (tx *Transaction) GasTipCapCmp(other *Transaction) int { + return tx.inner.gasTipCap().Cmp(other.inner.gasTipCap()) } -// TipIntCmp compares the tip of the transaction against the given tip. -func (tx *Transaction) TipIntCmp(other *big.Int) int { - return tx.inner.tip().Cmp(other) +// GasTipCapIntCmp compares the gasTipCap of the transaction against the given gasTipCap. +func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int { + return tx.inner.gasTipCap().Cmp(other) } -// EffectiveTip returns the effective miner tip for the given base fee. -// Note: if the effective tip is negative, this method returns both error -// the actual negative value, _and_ ErrFeeCapTooLow -func (tx *Transaction) EffectiveTip(baseFee *big.Int) (*big.Int, error) { +// EffectiveGasTip returns the effective miner gasTipCap for the given base fee. +// Note: if the effective gasTipCap is negative, this method returns both error +// the actual negative value, _and_ ErrGasFeeCapTooLow +func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) { if baseFee == nil { - return tx.Tip(), nil + return tx.GasTipCap(), nil } var err error - feeCap := tx.FeeCap() - if feeCap.Cmp(baseFee) == -1 { - err = ErrFeeCapTooLow + gasFeeCap := tx.GasFeeCap() + if gasFeeCap.Cmp(baseFee) == -1 { + 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 -// error in case the effective tip is negative -func (tx *Transaction) EffectiveTipValue(baseFee *big.Int) *big.Int { - effectiveTip, _ := tx.EffectiveTip(baseFee) +// EffectiveGasTipValue is identical to EffectiveGasTip, but does not return an +// error in case the effective gasTipCap is negative +func (tx *Transaction) EffectiveGasTipValue(baseFee *big.Int) *big.Int { + effectiveTip, _ := tx.EffectiveGasTip(baseFee) return effectiveTip } -// EffectiveTipCmp compares the effective tip of two transactions assuming the given base fee. -func (tx *Transaction) EffectiveTipCmp(other *Transaction, baseFee *big.Int) int { +// EffectiveGasTipCmp compares the effective gasTipCap of two transactions assuming the given base fee. +func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int { 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 { 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. @@ -426,8 +427,8 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int, balanceFee *big.Int nonce: tx.Nonce(), gasLimit: tx.Gas(), gasPrice: new(big.Int).Set(tx.GasPrice()), - feeCap: new(big.Int).Set(tx.FeeCap()), - tip: new(big.Int).Set(tx.Tip()), + gasFeeCap: new(big.Int).Set(tx.GasFeeCap()), + gasTipCap: new(big.Int).Set(tx.GasTipCap()), to: tx.To(), amount: tx.Value(), data: tx.Data(), @@ -437,7 +438,7 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int, balanceFee *big.Int } // If baseFee provided, set gasPrice to effectiveGasPrice. if baseFee != nil { - msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.tip, baseFee), msg.feeCap) + msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.gasTipCap, baseFee), msg.gasFeeCap) } if balanceFee != nil { if number.Cmp(common.BlockNumberGas50x) >= 0 { @@ -811,15 +812,15 @@ type Message struct { amount *big.Int gasLimit uint64 gasPrice *big.Int - feeCap *big.Int - tip *big.Int + gasFeeCap *big.Int + gasTipCap *big.Int data []byte accessList AccessList checkNonce bool 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 { gasPrice = common.GetGasPrice(number) } @@ -830,8 +831,8 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b amount: amount, gasLimit: gasLimit, gasPrice: gasPrice, - feeCap: feeCap, - tip: tip, + gasFeeCap: gasFeeCap, + gasTipCap: gasTipCap, data: data, accessList: accessList, checkNonce: checkNonce, @@ -843,8 +844,8 @@ func (m Message) From() common.Address { return m.from } func (m Message) BalanceTokenFee() *big.Int { return m.balanceTokenFee } func (m Message) To() *common.Address { return m.to } func (m Message) GasPrice() *big.Int { return m.gasPrice } -func (m Message) FeeCap() *big.Int { return m.feeCap } -func (m Message) Tip() *big.Int { return m.tip } +func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap } +func (m Message) GasTipCap() *big.Int { return m.gasTipCap } func (m Message) Value() *big.Int { return m.amount } func (m Message) Gas() uint64 { return m.gasLimit } func (m Message) Nonce() uint64 { return m.nonce } diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index 80b74d4b41ef..569350784d05 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -86,8 +86,8 @@ func (t *Transaction) MarshalJSON() ([]byte, error) { enc.AccessList = &tx.AccessList enc.Nonce = (*hexutil.Uint64)(&tx.Nonce) enc.Gas = (*hexutil.Uint64)(&tx.Gas) - enc.MaxFeePerGas = (*hexutil.Big)(tx.FeeCap) - enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.Tip) + enc.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap) + enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap) enc.Value = (*hexutil.Big)(tx.Value) enc.Data = (*hexutil.Bytes)(&tx.Data) enc.To = t.To() @@ -227,11 +227,11 @@ func (t *Transaction) UnmarshalJSON(input []byte) error { if dec.MaxPriorityFeePerGas == nil { 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 { 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 { return errors.New("missing required field 'gas' for txdata") } diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 2715e718f98d..b835e45af1ba 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -226,8 +226,8 @@ func (s londonSigner) Hash(tx *Transaction) common.Hash { []interface{}{ s.chainId, tx.Nonce(), - tx.Tip(), - tx.FeeCap(), + tx.GasTipCap(), + tx.GasFeeCap(), tx.Gas(), tx.To(), tx.Value(), diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index e868e6fdcf0a..4b58d2109125 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -219,8 +219,8 @@ func (s *txSorter) Swap(i, j int) { func (s *txSorter) Less(i, j int) bool { // It's okay to discard the error because a tx would never be // accepted into a block with an invalid effective tip. - tip1, _ := s.txs[i].EffectiveTip(s.baseFee) - tip2, _ := s.txs[j].EffectiveTip(s.baseFee) + tip1, _ := s.txs[i].EffectiveGasTip(s.baseFee) + tip2, _ := s.txs[j].EffectiveGasTip(s.baseFee) return tip1.Cmp(tip2) < 0 } @@ -245,7 +245,7 @@ func (gpo *Oracle) getBlockValues(ctx context.Context, signer types.Signer, bloc var prices []*big.Int for _, tx := range sorter.txs { - tip, _ := tx.EffectiveTip(block.BaseFee()) + tip, _ := tx.EffectiveGasTip(block.BaseFee()) if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 { continue } diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 0c200e095bcb..bdd04b2fa209 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -80,13 +80,13 @@ func newTestBackend(t *testing.T, eip1559Block *big.Int) *testBackend { var tx *types.Transaction if eip1559Block != nil && b.Number().Cmp(eip1559Block) >= 0 { txdata := &types.DynamicFeeTx{ - ChainID: gspec.Config.ChainId, - Nonce: b.TxNonce(addr), - To: &common.Address{}, - Gas: 30000, - FeeCap: big.NewInt(100 * params.GWei), - Tip: big.NewInt(int64(i+1) * params.GWei), - Data: []byte{}, + ChainID: gspec.Config.ChainId, + Nonce: b.TxNonce(addr), + To: &common.Address{}, + Gas: 30000, + GasFeeCap: big.NewInt(100 * params.GWei), + GasTipCap: big.NewInt(int64(i+1) * params.GWei), + Data: []byte{}, } tx = types.NewTx(txdata) } else { diff --git a/interfaces.go b/interfaces.go index 5d00baa5a0d7..74325fbe20a7 100644 --- a/interfaces.go +++ b/interfaces.go @@ -117,13 +117,12 @@ type CallMsg struct { To *common.Address // the destination contract (nil for contract creation) Gas uint64 // if 0, the call executes with near-infinite gas 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 Data []byte // input data, usually an ABI-encoded contract method invocation 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. } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6fe37f378817..e575613112e2 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1797,8 +1797,8 @@ type RPCTransaction struct { From common.Address `json:"from"` Gas hexutil.Uint64 `json:"gas"` GasPrice *hexutil.Big `json:"gasPrice"` - FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` - Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` + GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` + GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` Hash common.Hash `json:"hash"` Input hexutil.Bytes `json:"input"` Nonce hexutil.Uint64 `json:"nonce"` @@ -1856,12 +1856,12 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber al := tx.AccessList() result.Accesses = &al result.ChainID = (*hexutil.Big)(tx.ChainId()) - result.FeeCap = (*hexutil.Big)(tx.FeeCap()) - result.Tip = (*hexutil.Big)(tx.Tip()) + result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap()) + result.GasTipCap = (*hexutil.Big)(tx.GasTipCap()) // if the transaction has been mined, compute the effective gas price if baseFee != nil && blockHash != (common.Hash{}) { - // price = min(tip, feeCap - baseFee) + baseFee = min(tip + baseFee, feeCap) - price := math.BigMin(new(big.Int).Add(tx.Tip(), baseFee), tx.FeeCap()) + // price = min(tip, gasFeeCap - baseFee) + baseFee + price := math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee), tx.GasFeeCap()) result.GasPrice = (*hexutil.Big)(price) } else { result.GasPrice = nil diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index d9838ea577f8..80832054fb1c 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -34,14 +34,14 @@ import ( // TransactionArgs represents the arguments to construct a new transaction // or a message call. type TransactionArgs struct { - From *common.Address `json:"from"` - To *common.Address `json:"to"` - Gas *hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice"` - FeeCap *hexutil.Big `json:"maxFeePerGas"` - Tip *hexutil.Big `json:"maxPriorityFeePerGas"` - Value *hexutil.Big `json:"value"` - Nonce *hexutil.Uint64 `json:"nonce"` + From *common.Address `json:"from"` + To *common.Address `json:"to"` + Gas *hexutil.Uint64 `json:"gas"` + GasPrice *hexutil.Big `json:"gasPrice"` + MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"` + MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"` + Value *hexutil.Big `json:"value"` + Nonce *hexutil.Uint64 `json:"nonce"` // We accept "data" and "input" for backwards-compatibility reasons. // "input" is the newer name and should be preferred by clients. @@ -75,31 +75,31 @@ func (arg *TransactionArgs) data() []byte { // setDefaults fills in default values for unspecified tx fields. 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") } // After london, default to 1559 unless gasPrice is set head := b.CurrentHeader() if b.ChainConfig().IsEIP1559(head.Number) && args.GasPrice == nil { - if args.Tip == nil { + if args.MaxPriorityFeePerGas == nil { tip, err := b.SuggestGasTipCap(ctx) if err != nil { return err } - args.Tip = (*hexutil.Big)(tip) + args.MaxPriorityFeePerGas = (*hexutil.Big)(tip) } - if args.FeeCap == nil { - feeCap := new(big.Int).Add( - (*big.Int)(args.Tip), + if args.MaxFeePerGas == nil { + gasFeeCap := new(big.Int).Add( + (*big.Int)(args.MaxPriorityFeePerGas), 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 { - return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.FeeCap, args.Tip) + if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 { + return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas) } } 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") } if args.GasPrice == nil { @@ -135,14 +135,14 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error { // pass the pointer directly. data := args.data() callArgs := TransactionArgs{ - From: args.From, - To: args.To, - GasPrice: args.GasPrice, - FeeCap: args.FeeCap, - Tip: args.Tip, - Value: args.Value, - Data: (*hexutil.Bytes)(&data), - AccessList: args.AccessList, + From: args.From, + To: args.To, + GasPrice: args.GasPrice, + MaxFeePerGas: args.MaxFeePerGas, + MaxPriorityFeePerGas: args.MaxPriorityFeePerGas, + Value: args.Value, + Data: (*hexutil.Bytes)(&data), + AccessList: args.AccessList, } pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, nil, b.RPCGasCap()) @@ -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 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 - 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") } @@ -190,9 +190,9 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap } var ( - gasPrice *big.Int - feeCap *big.Int - tip *big.Int + gasPrice *big.Int + gasFeeCap *big.Int + gasTipCap *big.Int ) if baseFee == nil { // 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 { gasPrice = new(big.Int).SetUint64(defaultGasPrice) } - feeCap, tip = gasPrice, gasPrice + gasFeeCap, gasTipCap = gasPrice, gasPrice } else { // A basefee is provided, necessitating 1559-type execution if args.GasPrice != nil { gasPrice = args.GasPrice.ToInt() - feeCap, tip = gasPrice, gasPrice + gasFeeCap, gasTipCap = gasPrice, gasPrice } else { - feeCap = new(big.Int) - if args.FeeCap != nil { - feeCap = args.FeeCap.ToInt() + gasFeeCap = new(big.Int) + if args.MaxFeePerGas != nil { + gasFeeCap = args.MaxFeePerGas.ToInt() } - tip = new(big.Int) - if args.Tip != nil { - tip = args.Tip.ToInt() + gasTipCap = new(big.Int) + if args.MaxPriorityFeePerGas != nil { + 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) @@ -231,8 +231,7 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap accessList = *args.AccessList } - // Create new call message - msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, feeCap, tip, data, accessList, false, nil, number) + msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, false, nil, number) return msg, nil } @@ -241,7 +240,7 @@ func (args *TransactionArgs) ToMessage(b Backend, number *big.Int, globalGasCap func (args *TransactionArgs) toTransaction() *types.Transaction { var data types.TxData switch { - case args.FeeCap != nil: + case args.MaxFeePerGas != nil: al := types.AccessList{} if args.AccessList != nil { al = *args.AccessList @@ -251,8 +250,8 @@ func (args *TransactionArgs) toTransaction() *types.Transaction { ChainID: (*big.Int)(args.ChainID), Nonce: uint64(*args.Nonce), Gas: uint64(*args.Gas), - FeeCap: (*big.Int)(args.FeeCap), - Tip: (*big.Int)(args.Tip), + GasFeeCap: (*big.Int)(args.MaxFeePerGas), + GasTipCap: (*big.Int)(args.MaxPriorityFeePerGas), Value: (*big.Int)(args.Value), Data: args.data(), AccessList: al,