Skip to content

Commit c503f98

Browse files
authored
all: rename internal 1559 gas fields, add support for graphql (#23010)
* all: rename internal 1559 gas fields, add support for graphql * cmd/evm/testdata, core: use public 1559 gas names on API surfaces
1 parent 248572e commit c503f98

27 files changed

+329
-262
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ func (m callMsg) Nonce() uint64 { return 0 }
716716
func (m callMsg) CheckNonce() bool { return false }
717717
func (m callMsg) To() *common.Address { return m.CallMsg.To }
718718
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
719-
func (m callMsg) FeeCap() *big.Int { return m.CallMsg.FeeCap }
720-
func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip }
719+
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
720+
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
721721
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
722722
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
723723
func (m callMsg) Data() []byte { return m.CallMsg.Data }

cmd/evm/testdata/10/txs.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
1212
"chainId" : "0x1",
1313
"type" : "0x2",
14-
"feeCap" : "0xfa0",
15-
"tip" : "0x0",
14+
"maxFeePerGas" : "0xfa0",
15+
"maxPriorityFeePerGas" : "0x0",
1616
"accessList" : [
1717
]
1818
},
@@ -28,8 +28,8 @@
2828
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
2929
"chainId" : "0x1",
3030
"type" : "0x2",
31-
"feeCap" : "0xfa0",
32-
"tip" : "0x0",
31+
"maxFeePerGas" : "0xfa0",
32+
"maxPriorityFeePerGas" : "0x0",
3333
"accessList" : [
3434
]
3535
},
@@ -45,8 +45,8 @@
4545
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
4646
"chainId" : "0x1",
4747
"type" : "0x2",
48-
"feeCap" : "0xfa0",
49-
"tip" : "0x0",
48+
"maxFeePerGas" : "0xfa0",
49+
"maxPriorityFeePerGas" : "0x0",
5050
"accessList" : [
5151
]
5252
},
@@ -62,8 +62,8 @@
6262
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
6363
"chainId" : "0x1",
6464
"type" : "0x2",
65-
"feeCap" : "0xfa0",
66-
"tip" : "0x0",
65+
"maxFeePerGas" : "0xfa0",
66+
"maxPriorityFeePerGas" : "0x0",
6767
"accessList" : [
6868
]
6969
}

cmd/evm/testdata/9/txs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[
22
{
33
"gas": "0x4ef00",
4-
"tip": "0x2",
5-
"feeCap": "0x12A05F200",
4+
"maxPriorityFeePerGas": "0x2",
5+
"maxFeePerGas": "0x12A05F200",
66
"chainId": "0x1",
77
"input": "0x",
88
"nonce": "0x0",

core/blockchain_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,13 +3116,13 @@ func TestEIP2718Transition(t *testing.T) {
31163116

31173117
// TestEIP1559Transition tests the following:
31183118
//
3119-
// 1. A tranaction whose feeCap is greater than the baseFee is valid.
3119+
// 1. A transaction whose gasFeeCap is greater than the baseFee is valid.
31203120
// 2. Gas accounting for access lists on EIP-1559 transactions is correct.
31213121
// 3. Only the transaction's tip will be received by the coinbase.
31223122
// 4. The transaction sender pays for both the tip and baseFee.
31233123
// 5. The coinbase receives only the partially realized tip when
3124-
// feeCap - tip < baseFee.
3125-
// 6. Legacy transaction behave as expected (e.g. gasPrice = feeCap = tip).
3124+
// gasFeeCap - gasTipCap < baseFee.
3125+
// 6. Legacy transaction behave as expected (e.g. gasPrice = gasFeeCap = gasTipCap).
31263126
func TestEIP1559Transition(t *testing.T) {
31273127
var (
31283128
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
@@ -3176,8 +3176,8 @@ func TestEIP1559Transition(t *testing.T) {
31763176
Nonce: 0,
31773177
To: &aa,
31783178
Gas: 30000,
3179-
FeeCap: newGwei(5),
3180-
Tip: big.NewInt(2),
3179+
GasFeeCap: newGwei(5),
3180+
GasTipCap: big.NewInt(2),
31813181
AccessList: accesses,
31823182
Data: []byte{},
31833183
}
@@ -3212,7 +3212,7 @@ func TestEIP1559Transition(t *testing.T) {
32123212
// 3: Ensure that miner received only the tx's tip.
32133213
actual := state.GetBalance(block.Coinbase())
32143214
expected := new(big.Int).Add(
3215-
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].Tip().Uint64()),
3215+
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()),
32163216
ethash.ConstantinopleBlockReward,
32173217
)
32183218
if actual.Cmp(expected) != 0 {
@@ -3221,7 +3221,7 @@ func TestEIP1559Transition(t *testing.T) {
32213221

32223222
// 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
32233223
actual = new(big.Int).Sub(funds, state.GetBalance(addr1))
3224-
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].Tip().Uint64() + block.BaseFee().Uint64()))
3224+
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64()))
32253225
if actual.Cmp(expected) != 0 {
32263226
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)
32273227
}
@@ -3247,7 +3247,7 @@ func TestEIP1559Transition(t *testing.T) {
32473247

32483248
block = chain.GetBlockByNumber(2)
32493249
state, _ = chain.State()
3250-
effectiveTip := block.Transactions()[0].Tip().Uint64() - block.BaseFee().Uint64()
3250+
effectiveTip := block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64()
32513251

32523252
// 6+5: Ensure that miner received only the tx's effective tip.
32533253
actual = state.GetBalance(block.Coinbase())

core/error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ var (
7474

7575
// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
7676
// transaction with a tip higher than the total fee cap.
77-
ErrTipAboveFeeCap = errors.New("tip higher than fee cap")
77+
ErrTipAboveFeeCap = errors.New("max priority fee per gas higher than max fee per gas")
7878

7979
// ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified
8080
// in the tip field.
81-
ErrTipVeryHigh = errors.New("tip higher than 2^256-1")
81+
ErrTipVeryHigh = errors.New("max priority fee per gas higher than 2^256-1")
8282

8383
// ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified
8484
// in the fee cap field.
85-
ErrFeeCapVeryHigh = errors.New("fee cap higher than 2^256-1")
85+
ErrFeeCapVeryHigh = errors.New("max fee per gas higher than 2^256-1")
8686

8787
// ErrFeeCapTooLow is returned if the transaction fee cap is less than the
8888
// the base fee of the block.
89-
ErrFeeCapTooLow = errors.New("fee cap less than block base fee")
89+
ErrFeeCapTooLow = errors.New("max fee per gas less than block base fee")
9090
)

core/state_processor_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ func TestStateProcessorErrors(t *testing.T) {
6161
tx, _ := types.SignTx(types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data), signer, testKey)
6262
return tx
6363
}
64-
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, tip, feeCap *big.Int) *types.Transaction {
64+
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int) *types.Transaction {
6565
tx, _ := types.SignTx(types.NewTx(&types.DynamicFeeTx{
66-
Nonce: nonce,
67-
Tip: tip,
68-
FeeCap: feeCap,
69-
Gas: gasLimit,
70-
To: &to,
71-
Value: big.NewInt(0),
66+
Nonce: nonce,
67+
GasTipCap: gasTipCap,
68+
GasFeeCap: gasFeeCap,
69+
Gas: gasLimit,
70+
To: &to,
71+
Value: big.NewInt(0),
7272
}), signer, testKey)
7373
return tx
7474
}
@@ -146,25 +146,25 @@ func TestStateProcessorErrors(t *testing.T) {
146146
txs: []*types.Transaction{
147147
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
148148
},
149-
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: fee cap less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, feeCap: 0 baseFee: 875000000",
149+
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000",
150150
},
151151
{ // ErrTipVeryHigh
152152
txs: []*types.Transaction{
153153
mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)),
154154
},
155-
want: "could not apply tx 0 [0x15b8391b9981f266b32f3ab7da564bbeb3d6c21628364ea9b32a21139f89f712]: tip higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tip bit length: 257",
155+
want: "could not apply tx 0 [0x15b8391b9981f266b32f3ab7da564bbeb3d6c21628364ea9b32a21139f89f712]: max priority fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas bit length: 257",
156156
},
157157
{ // ErrFeeCapVeryHigh
158158
txs: []*types.Transaction{
159159
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), tooBigNumber),
160160
},
161-
want: "could not apply tx 0 [0x48bc299b83fdb345c57478f239e89814bb3063eb4e4b49f3b6057a69255c16bd]: fee cap higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, feeCap bit length: 257",
161+
want: "could not apply tx 0 [0x48bc299b83fdb345c57478f239e89814bb3063eb4e4b49f3b6057a69255c16bd]: max fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas bit length: 257",
162162
},
163163
{ // ErrTipAboveFeeCap
164164
txs: []*types.Transaction{
165165
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(2), big.NewInt(1)),
166166
},
167-
want: "could not apply tx 0 [0xf987a31ff0c71895780a7612f965a0c8b056deb54e020bb44fa478092f14c9b4]: tip higher than fee cap: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tip: 1, feeCap: 2",
167+
want: "could not apply tx 0 [0xf987a31ff0c71895780a7612f965a0c8b056deb54e020bb44fa478092f14c9b4]: max priority fee per gas higher than max fee per gas: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas: 2, maxFeePerGas: 1",
168168
},
169169
{ // ErrInsufficientFunds
170170
// Available balance: 1000000000000000000

core/state_transition.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ type StateTransition struct {
5050
msg Message
5151
gas uint64
5252
gasPrice *big.Int
53-
feeCap *big.Int
54-
tip *big.Int
53+
gasFeeCap *big.Int
54+
gasTipCap *big.Int
5555
initialGas uint64
5656
value *big.Int
5757
data []byte
@@ -65,8 +65,8 @@ type Message interface {
6565
To() *common.Address
6666

6767
GasPrice() *big.Int
68-
FeeCap() *big.Int
69-
Tip() *big.Int
68+
GasFeeCap() *big.Int
69+
GasTipCap() *big.Int
7070
Gas() uint64
7171
Value() *big.Int
7272

@@ -155,15 +155,15 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
155155
// NewStateTransition initialises and returns a new state transition object.
156156
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
157157
return &StateTransition{
158-
gp: gp,
159-
evm: evm,
160-
msg: msg,
161-
gasPrice: msg.GasPrice(),
162-
feeCap: msg.FeeCap(),
163-
tip: msg.Tip(),
164-
value: msg.Value(),
165-
data: msg.Data(),
166-
state: evm.StateDB,
158+
gp: gp,
159+
evm: evm,
160+
msg: msg,
161+
gasPrice: msg.GasPrice(),
162+
gasFeeCap: msg.GasFeeCap(),
163+
gasTipCap: msg.GasTipCap(),
164+
value: msg.Value(),
165+
data: msg.Data(),
166+
state: evm.StateDB,
167167
}
168168
}
169169

@@ -190,9 +190,9 @@ func (st *StateTransition) buyGas() error {
190190
mgval := new(big.Int).SetUint64(st.msg.Gas())
191191
mgval = mgval.Mul(mgval, st.gasPrice)
192192
balanceCheck := mgval
193-
if st.feeCap != nil {
193+
if st.gasFeeCap != nil {
194194
balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
195-
balanceCheck = balanceCheck.Mul(balanceCheck, st.feeCap)
195+
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
196196
}
197197
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
198198
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
@@ -219,25 +219,25 @@ func (st *StateTransition) preCheck() error {
219219
st.msg.From().Hex(), msgNonce, stNonce)
220220
}
221221
}
222-
// Make sure that transaction feeCap is greater than the baseFee (post london)
222+
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
223223
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) {
224-
if l := st.feeCap.BitLen(); l > 256 {
225-
return fmt.Errorf("%w: address %v, feeCap bit length: %d", ErrFeeCapVeryHigh,
224+
if l := st.gasFeeCap.BitLen(); l > 256 {
225+
return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh,
226226
st.msg.From().Hex(), l)
227227
}
228-
if l := st.tip.BitLen(); l > 256 {
229-
return fmt.Errorf("%w: address %v, tip bit length: %d", ErrTipVeryHigh,
228+
if l := st.gasTipCap.BitLen(); l > 256 {
229+
return fmt.Errorf("%w: address %v, maxPriorityFeePerGas bit length: %d", ErrTipVeryHigh,
230230
st.msg.From().Hex(), l)
231231
}
232-
if st.feeCap.Cmp(st.tip) < 0 {
233-
return fmt.Errorf("%w: address %v, tip: %s, feeCap: %s", ErrTipAboveFeeCap,
234-
st.msg.From().Hex(), st.feeCap, st.tip)
232+
if st.gasFeeCap.Cmp(st.gasTipCap) < 0 {
233+
return fmt.Errorf("%w: address %v, maxPriorityFeePerGas: %s, maxFeePerGas: %s", ErrTipAboveFeeCap,
234+
st.msg.From().Hex(), st.gasTipCap, st.gasFeeCap)
235235
}
236236
// This will panic if baseFee is nil, but basefee presence is verified
237237
// as part of header validation.
238-
if st.feeCap.Cmp(st.evm.Context.BaseFee) < 0 {
239-
return fmt.Errorf("%w: address %v, feeCap: %s baseFee: %s", ErrFeeCapTooLow,
240-
st.msg.From().Hex(), st.feeCap, st.evm.Context.BaseFee)
238+
if st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
239+
return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
240+
st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
241241
}
242242
}
243243
return st.buyGas()
@@ -317,7 +317,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
317317
}
318318
effectiveTip := st.gasPrice
319319
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) {
320-
effectiveTip = cmath.BigMin(st.tip, new(big.Int).Sub(st.feeCap, st.evm.Context.BaseFee))
320+
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
321321
}
322322
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
323323

core/tx_list.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
280280
// If there's an older better transaction, abort
281281
old := l.txs.Get(tx.Nonce())
282282
if old != nil {
283-
if old.FeeCapCmp(tx) >= 0 || old.TipCmp(tx) >= 0 {
283+
if old.GasFeeCapCmp(tx) >= 0 || old.GasTipCapCmp(tx) >= 0 {
284284
return false, nil
285285
}
286286
// thresholdFeeCap = oldFC * (100 + priceBump) / 100
287287
a := big.NewInt(100 + int64(priceBump))
288-
aFeeCap := new(big.Int).Mul(a, old.FeeCap())
289-
aTip := a.Mul(a, old.Tip())
288+
aFeeCap := new(big.Int).Mul(a, old.GasFeeCap())
289+
aTip := a.Mul(a, old.GasTipCap())
290290

291291
// thresholdTip = oldTip * (100 + priceBump) / 100
292292
b := big.NewInt(100)
@@ -296,7 +296,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
296296
// Have to ensure that either the new fee cap or tip is higher than the
297297
// old ones as well as checking the percentage threshold to ensure that
298298
// this is accurate for low (Wei-level) gas price replacements
299-
if tx.FeeCapIntCmp(thresholdFeeCap) < 0 || tx.TipIntCmp(thresholdTip) < 0 {
299+
if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
300300
return false, nil
301301
}
302302
}
@@ -417,7 +417,7 @@ func (l *txList) LastElement() *types.Transaction {
417417
// priceHeap is a heap.Interface implementation over transactions for retrieving
418418
// price-sorted transactions to discard when the pool fills up. If baseFee is set
419419
// then the heap is sorted based on the effective tip based on the given base fee.
420-
// If baseFee is nil then the sorting is based on feeCap.
420+
// If baseFee is nil then the sorting is based on gasFeeCap.
421421
type priceHeap struct {
422422
baseFee *big.Int // heap should always be re-sorted after baseFee is changed
423423
list []*types.Transaction
@@ -440,16 +440,16 @@ func (h *priceHeap) Less(i, j int) bool {
440440
func (h *priceHeap) cmp(a, b *types.Transaction) int {
441441
if h.baseFee != nil {
442442
// Compare effective tips if baseFee is specified
443-
if c := a.EffectiveTipCmp(b, h.baseFee); c != 0 {
443+
if c := a.EffectiveGasTipCmp(b, h.baseFee); c != 0 {
444444
return c
445445
}
446446
}
447447
// Compare fee caps if baseFee is not specified or effective tips are equal
448-
if c := a.FeeCapCmp(b); c != 0 {
448+
if c := a.GasFeeCapCmp(b); c != 0 {
449449
return c
450450
}
451451
// Compare tips if effective tips and fee caps are equal
452-
return a.TipCmp(b)
452+
return a.GasTipCapCmp(b)
453453
}
454454

455455
func (h *priceHeap) Push(x interface{}) {
@@ -472,7 +472,7 @@ func (h *priceHeap) Pop() interface{} {
472472
// will be considered for tracking, sorting, eviction, etc.
473473
//
474474
// Two heaps are used for sorting: the urgent heap (based on effective tip in the next
475-
// block) and the floating heap (based on feeCap). Always the bigger heap is chosen for
475+
// block) and the floating heap (based on gasFeeCap). Always the bigger heap is chosen for
476476
// eviction. Transactions evicted from the urgent heap are first demoted into the floating heap.
477477
// In some cases (during a congestion, when blocks are full) the urgent heap can provide
478478
// better candidates for inclusion while in other cases (at the top of the baseFee peak)

0 commit comments

Comments
 (0)