Skip to content

Commit 82cf924

Browse files
add new maxFeePerDataGas field to blob tx message in preparation for latest eip-4844 fee market updates (ethereum#23)
1 parent f673a93 commit 82cf924

File tree

8 files changed

+99
-82
lines changed

8 files changed

+99
-82
lines changed

core/state_transition.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ The state transitioning model does all the necessary work to work out a valid ne
5050
6) Derive new state root
5151
*/
5252
type StateTransition struct {
53-
gp *GasPool
54-
msg Message
55-
gas uint64
56-
gasPrice *big.Int
57-
gasFeeCap *big.Int
58-
gasTipCap *big.Int
59-
initialGas uint64
60-
value *big.Int
61-
data []byte
62-
state vm.StateDB
63-
evm *vm.EVM
53+
gp *GasPool
54+
msg Message
55+
gas uint64
56+
gasPrice *big.Int
57+
gasFeeCap *big.Int
58+
gasTipCap *big.Int
59+
maxFeePerDataGas *big.Int
60+
initialGas uint64
61+
value *big.Int
62+
data []byte
63+
state vm.StateDB
64+
evm *vm.EVM
6465
}
6566

6667
// Message represents a message sent to a contract.

core/types/access_list_tx.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,19 @@ func (tx *AccessListTx) copy() TxData {
9494
}
9595

9696
// accessors for innerTx.
97-
func (tx *AccessListTx) txType() byte { return AccessListTxType }
98-
func (tx *AccessListTx) chainID() *big.Int { return tx.ChainID }
99-
func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
100-
func (tx *AccessListTx) dataHashes() []common.Hash { return nil }
101-
func (tx *AccessListTx) data() []byte { return tx.Data }
102-
func (tx *AccessListTx) gas() uint64 { return tx.Gas }
103-
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
104-
func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
105-
func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
106-
func (tx *AccessListTx) value() *big.Int { return tx.Value }
107-
func (tx *AccessListTx) nonce() uint64 { return tx.Nonce }
108-
func (tx *AccessListTx) to() *common.Address { return tx.To }
97+
func (tx *AccessListTx) txType() byte { return AccessListTxType }
98+
func (tx *AccessListTx) chainID() *big.Int { return tx.ChainID }
99+
func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
100+
func (tx *AccessListTx) dataHashes() []common.Hash { return nil }
101+
func (tx *AccessListTx) data() []byte { return tx.Data }
102+
func (tx *AccessListTx) gas() uint64 { return tx.Gas }
103+
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
104+
func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
105+
func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
106+
func (tx *AccessListTx) maxFeePerDataGas() *big.Int { return nil }
107+
func (tx *AccessListTx) value() *big.Int { return tx.Value }
108+
func (tx *AccessListTx) nonce() uint64 { return tx.Nonce }
109+
func (tx *AccessListTx) to() *common.Address { return tx.To }
109110

110111
func (tx *AccessListTx) rawSignatureValues() (v, r, s *big.Int) {
111112
return tx.V, tx.R, tx.S

core/types/data_blob_tx.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -316,37 +316,38 @@ func (alv AccessListView) HashTreeRoot(hFn tree.HashFn) tree.Root {
316316
}
317317

318318
type BlobTxMessage struct {
319-
ChainID Uint256View
320-
Nonce Uint64View
321-
GasTipCap Uint256View // a.k.a. maxPriorityFeePerGas
322-
GasFeeCap Uint256View // a.k.a. maxFeePerGas
323-
Gas Uint64View
324-
To AddressOptionalSSZ // nil means contract creation
325-
Value Uint256View
326-
Data TxDataView
327-
AccessList AccessListView
319+
ChainID Uint256View
320+
Nonce Uint64View
321+
GasTipCap Uint256View // a.k.a. maxPriorityFeePerGas
322+
GasFeeCap Uint256View // a.k.a. maxFeePerGas
323+
Gas Uint64View
324+
To AddressOptionalSSZ // nil means contract creation
325+
Value Uint256View
326+
Data TxDataView
327+
AccessList AccessListView
328+
MaxFeePerDataGas Uint256View
328329

329330
BlobVersionedHashes VersionedHashesView
330331
}
331332

332333
func (tx *BlobTxMessage) Deserialize(dr *codec.DecodingReader) error {
333-
return dr.Container(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.BlobVersionedHashes)
334+
return dr.Container(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.MaxFeePerDataGas, &tx.BlobVersionedHashes)
334335
}
335336

336337
func (tx *BlobTxMessage) Serialize(w *codec.EncodingWriter) error {
337-
return w.Container(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.BlobVersionedHashes)
338+
return w.Container(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.MaxFeePerDataGas, &tx.BlobVersionedHashes)
338339
}
339340

340341
func (tx *BlobTxMessage) ByteLength() uint64 {
341-
return codec.ContainerLength(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.BlobVersionedHashes)
342+
return codec.ContainerLength(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.MaxFeePerDataGas, &tx.BlobVersionedHashes)
342343
}
343344

344345
func (tx *BlobTxMessage) FixedLength() uint64 {
345346
return 0
346347
}
347348

348349
func (tx *BlobTxMessage) HashTreeRoot(hFn tree.HashFn) tree.Root {
349-
return hFn.HashTreeRoot(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.BlobVersionedHashes)
350+
return hFn.HashTreeRoot(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.MaxFeePerDataGas, &tx.BlobVersionedHashes)
350351
}
351352

352353
// copy creates a deep copy of the transaction data and initializes all fields.
@@ -361,6 +362,7 @@ func (tx *BlobTxMessage) copy() *BlobTxMessage {
361362
Value: tx.Value,
362363
Data: common.CopyBytes(tx.Data),
363364
AccessList: make([]AccessTuple, len(tx.AccessList)),
365+
MaxFeePerDataGas: tx.MaxFeePerDataGas,
364366
BlobVersionedHashes: make([]common.Hash, len(tx.BlobVersionedHashes)),
365367
}
366368
copy(cpy.AccessList, tx.AccessList)
@@ -416,18 +418,19 @@ func u256ToBig(v *Uint256View) *big.Int {
416418
}
417419

418420
// accessors for innerTx.
419-
func (stx *SignedBlobTx) txType() byte { return BlobTxType }
420-
func (stx *SignedBlobTx) chainID() *big.Int { return u256ToBig(&stx.Message.ChainID) }
421-
func (stx *SignedBlobTx) accessList() AccessList { return AccessList(stx.Message.AccessList) }
422-
func (stx *SignedBlobTx) dataHashes() []common.Hash { return stx.Message.BlobVersionedHashes }
423-
func (stx *SignedBlobTx) data() []byte { return stx.Message.Data }
424-
func (stx *SignedBlobTx) gas() uint64 { return uint64(stx.Message.Gas) }
425-
func (stx *SignedBlobTx) gasFeeCap() *big.Int { return u256ToBig(&stx.Message.GasFeeCap) }
426-
func (stx *SignedBlobTx) gasTipCap() *big.Int { return u256ToBig(&stx.Message.GasTipCap) }
427-
func (stx *SignedBlobTx) gasPrice() *big.Int { return u256ToBig(&stx.Message.GasFeeCap) }
428-
func (stx *SignedBlobTx) value() *big.Int { return u256ToBig(&stx.Message.Value) }
429-
func (stx *SignedBlobTx) nonce() uint64 { return uint64(stx.Message.Nonce) }
430-
func (stx *SignedBlobTx) to() *common.Address { return (*common.Address)(stx.Message.To.Address) }
421+
func (stx *SignedBlobTx) txType() byte { return BlobTxType }
422+
func (stx *SignedBlobTx) chainID() *big.Int { return u256ToBig(&stx.Message.ChainID) }
423+
func (stx *SignedBlobTx) accessList() AccessList { return AccessList(stx.Message.AccessList) }
424+
func (stx *SignedBlobTx) dataHashes() []common.Hash { return stx.Message.BlobVersionedHashes }
425+
func (stx *SignedBlobTx) data() []byte { return stx.Message.Data }
426+
func (stx *SignedBlobTx) gas() uint64 { return uint64(stx.Message.Gas) }
427+
func (stx *SignedBlobTx) gasFeeCap() *big.Int { return u256ToBig(&stx.Message.GasFeeCap) }
428+
func (stx *SignedBlobTx) gasTipCap() *big.Int { return u256ToBig(&stx.Message.GasTipCap) }
429+
func (stx *SignedBlobTx) maxFeePerDataGas() *big.Int { return u256ToBig(&stx.Message.MaxFeePerDataGas) }
430+
func (stx *SignedBlobTx) gasPrice() *big.Int { return u256ToBig(&stx.Message.GasFeeCap) }
431+
func (stx *SignedBlobTx) value() *big.Int { return u256ToBig(&stx.Message.Value) }
432+
func (stx *SignedBlobTx) nonce() uint64 { return uint64(stx.Message.Nonce) }
433+
func (stx *SignedBlobTx) to() *common.Address { return (*common.Address)(stx.Message.To.Address) }
431434

432435
func (stx *SignedBlobTx) rawSignatureValues() (v, r, s *big.Int) {
433436
return big.NewInt(int64(stx.Signature.V)), u256ToBig(&stx.Signature.R), u256ToBig(&stx.Signature.S)

core/types/dynamic_fee_tx.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ func (tx *DynamicFeeTx) copy() TxData {
8282
}
8383

8484
// accessors for innerTx.
85-
func (tx *DynamicFeeTx) txType() byte { return DynamicFeeTxType }
86-
func (tx *DynamicFeeTx) chainID() *big.Int { return tx.ChainID }
87-
func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList }
88-
func (tx *DynamicFeeTx) dataHashes() []common.Hash { return nil }
89-
func (tx *DynamicFeeTx) data() []byte { return tx.Data }
90-
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
91-
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
92-
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
93-
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
94-
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
95-
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
96-
func (tx *DynamicFeeTx) to() *common.Address { return tx.To }
85+
func (tx *DynamicFeeTx) txType() byte { return DynamicFeeTxType }
86+
func (tx *DynamicFeeTx) chainID() *big.Int { return tx.ChainID }
87+
func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList }
88+
func (tx *DynamicFeeTx) dataHashes() []common.Hash { return nil }
89+
func (tx *DynamicFeeTx) data() []byte { return tx.Data }
90+
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
91+
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
92+
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
93+
func (tx *DynamicFeeTx) maxFeePerDataGas() *big.Int { return nil }
94+
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
95+
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
96+
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
97+
func (tx *DynamicFeeTx) to() *common.Address { return tx.To }
9798

9899
func (tx *DynamicFeeTx) rawSignatureValues() (v, r, s *big.Int) {
99100
return tx.V, tx.R, tx.S

core/types/legacy_tx.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,19 @@ func (tx *LegacyTx) copy() TxData {
9191
}
9292

9393
// accessors for innerTx.
94-
func (tx *LegacyTx) txType() byte { return LegacyTxType }
95-
func (tx *LegacyTx) chainID() *big.Int { return deriveChainId(tx.V) }
96-
func (tx *LegacyTx) accessList() AccessList { return nil }
97-
func (tx *LegacyTx) dataHashes() []common.Hash { return nil }
98-
func (tx *LegacyTx) data() []byte { return tx.Data }
99-
func (tx *LegacyTx) gas() uint64 { return tx.Gas }
100-
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
101-
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
102-
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
103-
func (tx *LegacyTx) value() *big.Int { return tx.Value }
104-
func (tx *LegacyTx) nonce() uint64 { return tx.Nonce }
105-
func (tx *LegacyTx) to() *common.Address { return tx.To }
94+
func (tx *LegacyTx) txType() byte { return LegacyTxType }
95+
func (tx *LegacyTx) chainID() *big.Int { return deriveChainId(tx.V) }
96+
func (tx *LegacyTx) accessList() AccessList { return nil }
97+
func (tx *LegacyTx) dataHashes() []common.Hash { return nil }
98+
func (tx *LegacyTx) data() []byte { return tx.Data }
99+
func (tx *LegacyTx) gas() uint64 { return tx.Gas }
100+
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
101+
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
102+
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
103+
func (tx *LegacyTx) maxFeePerDataGas() *big.Int { return nil }
104+
func (tx *LegacyTx) value() *big.Int { return tx.Value }
105+
func (tx *LegacyTx) nonce() uint64 { return tx.Nonce }
106+
func (tx *LegacyTx) to() *common.Address { return tx.To }
106107

107108
func (tx *LegacyTx) rawSignatureValues() (v, r, s *big.Int) {
108109
return tx.V, tx.R, tx.S

core/types/transaction.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type TxWrapData interface {
102102

103103
// TxData is the underlying data of a transaction.
104104
//
105-
// This is implemented by DynamicFeeTx, LegacyTx and AccessListTx.
105+
// This is implemented by DynamicFeeTx, LegacyTx, AccessListTx & SignedBlobTx.
106106
type TxData interface {
107107
txType() byte // returns the type ID
108108
copy() TxData // creates a deep copy and initializes all fields
@@ -115,6 +115,7 @@ type TxData interface {
115115
gasPrice() *big.Int
116116
gasTipCap() *big.Int
117117
gasFeeCap() *big.Int
118+
maxFeePerDataGas() *big.Int
118119
value() *big.Int
119120
nonce() uint64
120121
to() *common.Address
@@ -385,6 +386,11 @@ func (tx *Transaction) GasTipCap() *big.Int { return new(big.Int).Set(tx.inner.g
385386
// GasFeeCap returns the fee cap per gas of the transaction.
386387
func (tx *Transaction) GasFeeCap() *big.Int { return new(big.Int).Set(tx.inner.gasFeeCap()) }
387388

389+
// MaxFeePerDataGas returns the max_fee_per_data_gas value for the transaction
390+
func (tx *Transaction) MaxFeePerDataGas() *big.Int {
391+
return new(big.Int).Set(tx.inner.maxFeePerDataGas())
392+
}
393+
388394
// Value returns the ether amount of the transaction.
389395
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) }
390396

interfaces.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,18 @@ type ChainSyncReader interface {
132132

133133
// CallMsg contains parameters for contract calls.
134134
type CallMsg struct {
135-
From common.Address // the sender of the 'transaction'
136-
To *common.Address // the destination contract (nil for contract creation)
137-
Gas uint64 // if 0, the call executes with near-infinite gas
138-
GasPrice *big.Int // wei <-> gas exchange ratio
139-
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
140-
GasTipCap *big.Int // EIP-1559 tip per gas.
141-
Value *big.Int // amount of wei sent along with the call
142-
Data []byte // input data, usually an ABI-encoded contract method invocation
135+
From common.Address // the sender of the 'transaction'
136+
To *common.Address // the destination contract (nil for contract creation)
137+
Gas uint64 // if 0, the call executes with near-infinite gas
138+
GasPrice *big.Int // wei <-> gas exchange ratio
139+
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
140+
GasTipCap *big.Int // EIP-1559 tip per gas.
141+
MaxFeePerDataGas *big.Int // EIP-4844 max_fee_per_data_gas
142+
Value *big.Int // amount of wei sent along with the call
143+
Data []byte // input data, usually an ABI-encoded contract method invocation
143144

144145
AccessList types.AccessList // EIP-2930 access list.
145-
DataHashes []common.Hash // versioned data hashes for mini-danksharding
146+
DataHashes []common.Hash // versioned data hashes for EIP-4844
146147
}
147148

148149
// A ContractCaller provides contract calls, essentially transactions that are executed by

internal/ethapi/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ func (s *TxPoolAPI) Inspect() map[string]map[string]map[string]string {
228228

229229
// Define a formatter to flatten a transaction into a string
230230
var format = func(tx *types.Transaction) string {
231+
// TODO: handle data gas for txs with blobs (EIP-4844)
231232
if to := tx.To(); to != nil {
232233
return fmt.Sprintf("%s: %v wei + %v gas × %v wei", tx.To().Hex(), tx.Value(), tx.Gas(), tx.GasPrice())
233234
}
@@ -1264,6 +1265,7 @@ type RPCTransaction struct {
12641265
Value *hexutil.Big `json:"value"`
12651266
Type hexutil.Uint64 `json:"type"`
12661267
Accesses *types.AccessList `json:"accessList,omitempty"`
1268+
MaxFeePerDataGas *hexutil.Big `json:"maxFeePerDataGas,omitempty"`
12671269
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
12681270
ChainID *hexutil.Big `json:"chainId,omitempty"`
12691271
V *hexutil.Big `json:"v"`
@@ -1313,6 +1315,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
13131315
result.ChainID = (*hexutil.Big)(tx.ChainId())
13141316
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
13151317
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
1318+
result.MaxFeePerDataGas = (*hexutil.Big)(tx.MaxFeePerDataGas())
13161319
// if the transaction has been mined, compute the effective gas price
13171320
if baseFee != nil && blockHash != (common.Hash{}) {
13181321
// price = min(tip, gasFeeCap - baseFee) + baseFee

0 commit comments

Comments
 (0)