Skip to content

Commit a7f7378

Browse files
add max-fee-per-data-gas to tx message (#25)
1 parent 773cfb2 commit a7f7378

File tree

8 files changed

+71
-61
lines changed

8 files changed

+71
-61
lines changed

core/types/access_list_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (tx *AccessListTx) gas() uint64 { return tx.Gas }
103103
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
104104
func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
105105
func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
106-
func (tx *AccessListTx) maxFeePerDataGas() *big.Int { return nil }
106+
func (tx *AccessListTx) maxFeePerDataGas() *big.Int { return new(big.Int) }
107107
func (tx *AccessListTx) value() *big.Int { return tx.Value }
108108
func (tx *AccessListTx) nonce() uint64 { return tx.Nonce }
109109
func (tx *AccessListTx) to() *common.Address { return tx.To }

core/types/dynamic_fee_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (tx *DynamicFeeTx) data() []byte { return tx.Data }
9090
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
9191
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
9292
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
93-
func (tx *DynamicFeeTx) maxFeePerDataGas() *big.Int { return nil }
93+
func (tx *DynamicFeeTx) maxFeePerDataGas() *big.Int { return new(big.Int) }
9494
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
9595
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
9696
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }

core/types/legacy_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (tx *LegacyTx) gas() uint64 { return tx.Gas }
100100
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
101101
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
102102
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
103-
func (tx *LegacyTx) maxFeePerDataGas() *big.Int { return nil }
103+
func (tx *LegacyTx) maxFeePerDataGas() *big.Int { return new(big.Int) }
104104
func (tx *LegacyTx) value() *big.Int { return tx.Value }
105105
func (tx *LegacyTx) nonce() uint64 { return tx.Nonce }
106106
func (tx *LegacyTx) to() *common.Address { return tx.To }

core/types/transaction.go

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -738,51 +738,54 @@ func (t *TransactionsByPriceAndNonce) Pop() {
738738
//
739739
// NOTE: In a future PR this will be removed.
740740
type Message struct {
741-
to *common.Address
742-
from common.Address
743-
nonce uint64
744-
amount *big.Int
745-
gasLimit uint64
746-
gasPrice *big.Int
747-
gasFeeCap *big.Int
748-
gasTipCap *big.Int
749-
data []byte
750-
accessList AccessList
751-
dataHashes []common.Hash
752-
isFake bool
753-
}
754-
755-
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, dataHashes []common.Hash, isFake bool) Message {
741+
to *common.Address
742+
from common.Address
743+
nonce uint64
744+
amount *big.Int
745+
gasLimit uint64
746+
gasPrice *big.Int
747+
gasFeeCap *big.Int
748+
gasTipCap *big.Int
749+
maxFeePerDataGas *big.Int
750+
data []byte
751+
accessList AccessList
752+
dataHashes []common.Hash
753+
isFake bool
754+
}
755+
756+
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap, maxFeePerDataGas *big.Int, data []byte, accessList AccessList, dataHashes []common.Hash, isFake bool) Message {
756757
return Message{
757-
from: from,
758-
to: to,
759-
nonce: nonce,
760-
amount: amount,
761-
gasLimit: gasLimit,
762-
gasPrice: gasPrice,
763-
gasFeeCap: gasFeeCap,
764-
gasTipCap: gasTipCap,
765-
data: data,
766-
accessList: accessList,
767-
dataHashes: dataHashes,
768-
isFake: isFake,
758+
from: from,
759+
to: to,
760+
nonce: nonce,
761+
amount: amount,
762+
gasLimit: gasLimit,
763+
gasPrice: gasPrice,
764+
gasFeeCap: gasFeeCap,
765+
gasTipCap: gasTipCap,
766+
maxFeePerDataGas: maxFeePerDataGas,
767+
data: data,
768+
accessList: accessList,
769+
dataHashes: dataHashes,
770+
isFake: isFake,
769771
}
770772
}
771773

772774
// AsMessage returns the transaction as a core.Message.
773775
func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
774776
msg := Message{
775-
nonce: tx.Nonce(),
776-
gasLimit: tx.Gas(),
777-
gasPrice: new(big.Int).Set(tx.GasPrice()),
778-
gasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
779-
gasTipCap: new(big.Int).Set(tx.GasTipCap()),
780-
to: tx.To(),
781-
amount: tx.Value(),
782-
data: tx.Data(),
783-
accessList: tx.AccessList(),
784-
dataHashes: tx.DataHashes(),
785-
isFake: false,
777+
nonce: tx.Nonce(),
778+
gasLimit: tx.Gas(),
779+
gasPrice: new(big.Int).Set(tx.GasPrice()),
780+
gasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
781+
gasTipCap: new(big.Int).Set(tx.GasTipCap()),
782+
maxFeePerDataGas: new(big.Int).Set(tx.MaxFeePerDataGas()),
783+
to: tx.To(),
784+
amount: tx.Value(),
785+
data: tx.Data(),
786+
accessList: tx.AccessList(),
787+
dataHashes: tx.DataHashes(),
788+
isFake: false,
786789
}
787790
// If baseFee provided, set gasPrice to effectiveGasPrice.
788791
if baseFee != nil {
@@ -793,18 +796,19 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
793796
return msg, err
794797
}
795798

796-
func (m Message) From() common.Address { return m.from }
797-
func (m Message) To() *common.Address { return m.to }
798-
func (m Message) GasPrice() *big.Int { return m.gasPrice }
799-
func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
800-
func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
801-
func (m Message) Value() *big.Int { return m.amount }
802-
func (m Message) Gas() uint64 { return m.gasLimit }
803-
func (m Message) Nonce() uint64 { return m.nonce }
804-
func (m Message) Data() []byte { return m.data }
805-
func (m Message) AccessList() AccessList { return m.accessList }
806-
func (m Message) DataHashes() []common.Hash { return m.dataHashes }
807-
func (m Message) IsFake() bool { return m.isFake }
799+
func (m Message) From() common.Address { return m.from }
800+
func (m Message) To() *common.Address { return m.to }
801+
func (m Message) GasPrice() *big.Int { return m.gasPrice }
802+
func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
803+
func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
804+
func (m Message) MaxFeePerDataGas() *big.Int { return m.maxFeePerDataGas }
805+
func (m Message) Value() *big.Int { return m.amount }
806+
func (m Message) Gas() uint64 { return m.gasLimit }
807+
func (m Message) Nonce() uint64 { return m.nonce }
808+
func (m Message) Data() []byte { return m.data }
809+
func (m Message) AccessList() AccessList { return m.accessList }
810+
func (m Message) DataHashes() []common.Hash { return m.dataHashes }
811+
func (m Message) IsFake() bool { return m.isFake }
808812

809813
// copyAddressPtr copies an address.
810814
func copyAddressPtr(a *common.Address) *common.Address {

internal/ethapi/transaction_args.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type TransactionArgs struct {
4242
GasPrice *hexutil.Big `json:"gasPrice"`
4343
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
4444
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
45+
MaxFeePerDataGas *hexutil.Big `json:"maxFeePerGas"`
4546
Value *hexutil.Big `json:"value"`
4647
Nonce *hexutil.Uint64 `json:"nonce"`
4748

@@ -224,9 +225,10 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
224225
gas = globalGasCap
225226
}
226227
var (
227-
gasPrice *big.Int
228-
gasFeeCap *big.Int
229-
gasTipCap *big.Int
228+
gasPrice *big.Int
229+
gasFeeCap *big.Int
230+
gasTipCap *big.Int
231+
maxFeePerDataGas *big.Int
230232
)
231233
if baseFee == nil {
232234
// If there's no basefee, then it must be a non-1559 execution
@@ -257,6 +259,9 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
257259
gasPrice = math.BigMin(new(big.Int).Add(gasTipCap, baseFee), gasFeeCap)
258260
}
259261
}
262+
if args.MaxFeePerDataGas != nil {
263+
maxFeePerDataGas = args.MaxFeePerDataGas.ToInt()
264+
}
260265
}
261266
value := new(big.Int)
262267
if args.Value != nil {
@@ -272,7 +277,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
272277
if args.Blobs != nil {
273278
fakeDataHashes = make([]common.Hash, len(args.Blobs))
274279
}
275-
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, fakeDataHashes, true)
280+
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, maxFeePerDataGas, data, accessList, fakeDataHashes, true)
276281
return msg, nil
277282
}
278283

les/odr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
135135
from := statedb.GetOrNewStateObject(bankAddr)
136136
from.SetBalance(math.MaxBig256)
137137

138-
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
138+
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), new(big.Int), data, nil, nil, true)}
139139

140140
context := core.NewEVMBlockContext(header, bc, nil)
141141
txContext := core.NewEVMTxContext(msg)
@@ -150,7 +150,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
150150
header := lc.GetHeaderByHash(bhash)
151151
state := light.NewState(ctx, header, lc.Odr())
152152
state.SetBalance(bankAddr, math.MaxBig256)
153-
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
153+
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), new(big.Int), data, nil, nil, true)}
154154
context := core.NewEVMBlockContext(header, lc, nil)
155155
txContext := core.NewEVMTxContext(msg)
156156
vmenv := vm.NewEVM(context, txContext, state, config, vm.Config{NoBaseFee: true})

light/odr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
194194

195195
// Perform read-only call.
196196
st.SetBalance(testBankAddress, math.MaxBig256)
197-
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), data, nil, nil, true)}
197+
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, big.NewInt(params.InitialBaseFee), big.NewInt(params.InitialBaseFee), new(big.Int), new(big.Int), data, nil, nil, true)}
198198
txContext := core.NewEVMTxContext(msg)
199199
context := core.NewEVMBlockContext(header, chain, nil)
200200
vmenv := vm.NewEVM(context, txContext, st, config, vm.Config{NoBaseFee: true})

tests/state_test_util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type stTransaction struct {
104104
GasPrice *big.Int `json:"gasPrice"`
105105
MaxFeePerGas *big.Int `json:"maxFeePerGas"`
106106
MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"`
107+
MaxFeePerDataGas *big.Int `json:"maxFeePerDataGas"`
107108
Nonce uint64 `json:"nonce"`
108109
To string `json:"to"`
109110
Data []string `json:"data"`
@@ -360,7 +361,7 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (core.Messa
360361
}
361362

362363
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, gasPrice,
363-
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, data, accessList, nil, false)
364+
tx.MaxFeePerGas, tx.MaxPriorityFeePerGas, tx.MaxFeePerDataGas, data, accessList, nil, false)
364365
return msg, nil
365366
}
366367

0 commit comments

Comments
 (0)