@@ -24,6 +24,7 @@ import (
24
24
"github.com/ethereum/go-ethereum/common/math"
25
25
"github.com/ethereum/go-ethereum/consensus/ethash"
26
26
"github.com/ethereum/go-ethereum/consensus/misc"
27
+ "github.com/ethereum/go-ethereum/consensus/misc/eip4844"
27
28
"github.com/ethereum/go-ethereum/core"
28
29
"github.com/ethereum/go-ethereum/core/rawdb"
29
30
"github.com/ethereum/go-ethereum/core/state"
@@ -46,17 +47,19 @@ type Prestate struct {
46
47
// ExecutionResult contains the execution status after running a state test, any
47
48
// error that might have occurred and a dump of the final state if requested.
48
49
type ExecutionResult struct {
49
- StateRoot common.Hash `json:"stateRoot"`
50
- TxRoot common.Hash `json:"txRoot"`
51
- ReceiptRoot common.Hash `json:"receiptsRoot"`
52
- LogsHash common.Hash `json:"logsHash"`
53
- Bloom types.Bloom `json:"logsBloom" gencodec:"required"`
54
- Receipts types.Receipts `json:"receipts"`
55
- Rejected []* rejectedTx `json:"rejected,omitempty"`
56
- Difficulty * math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
57
- GasUsed math.HexOrDecimal64 `json:"gasUsed"`
58
- BaseFee * math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
59
- WithdrawalsRoot * common.Hash `json:"withdrawalsRoot,omitempty"`
50
+ StateRoot common.Hash `json:"stateRoot"`
51
+ TxRoot common.Hash `json:"txRoot"`
52
+ ReceiptRoot common.Hash `json:"receiptsRoot"`
53
+ LogsHash common.Hash `json:"logsHash"`
54
+ Bloom types.Bloom `json:"logsBloom" gencodec:"required"`
55
+ Receipts types.Receipts `json:"receipts"`
56
+ Rejected []* rejectedTx `json:"rejected,omitempty"`
57
+ Difficulty * math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
58
+ GasUsed math.HexOrDecimal64 `json:"gasUsed"`
59
+ BaseFee * math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
60
+ WithdrawalsRoot * common.Hash `json:"withdrawalsRoot,omitempty"`
61
+ CurrentExcessBlobGas * math.HexOrDecimal64 `json:"currentExcessBlobGas,omitempty"`
62
+ CurrentBlobGasUsed * math.HexOrDecimal64 `json:"currentBlobGasUsed,omitempty"`
60
63
}
61
64
62
65
type ommer struct {
@@ -66,37 +69,43 @@ type ommer struct {
66
69
67
70
//go:generate go run github.com/fjl/gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
68
71
type stEnv struct {
69
- Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
70
- Difficulty * big.Int `json:"currentDifficulty"`
71
- Random * big.Int `json:"currentRandom"`
72
- ParentDifficulty * big.Int `json:"parentDifficulty"`
73
- ParentBaseFee * big.Int `json:"parentBaseFee,omitempty"`
74
- ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
75
- ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
76
- GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
77
- Number uint64 `json:"currentNumber" gencodec:"required"`
78
- Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
79
- ParentTimestamp uint64 `json:"parentTimestamp,omitempty"`
80
- BlockHashes map [math.HexOrDecimal64 ]common.Hash `json:"blockHashes,omitempty"`
81
- Ommers []ommer `json:"ommers,omitempty"`
82
- Withdrawals []* types.Withdrawal `json:"withdrawals,omitempty"`
83
- BaseFee * big.Int `json:"currentBaseFee,omitempty"`
84
- ParentUncleHash common.Hash `json:"parentUncleHash"`
72
+ Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
73
+ Difficulty * big.Int `json:"currentDifficulty"`
74
+ Random * big.Int `json:"currentRandom"`
75
+ ParentDifficulty * big.Int `json:"parentDifficulty"`
76
+ ParentBaseFee * big.Int `json:"parentBaseFee,omitempty"`
77
+ ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
78
+ ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
79
+ GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
80
+ Number uint64 `json:"currentNumber" gencodec:"required"`
81
+ Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
82
+ ParentTimestamp uint64 `json:"parentTimestamp,omitempty"`
83
+ BlockHashes map [math.HexOrDecimal64 ]common.Hash `json:"blockHashes,omitempty"`
84
+ Ommers []ommer `json:"ommers,omitempty"`
85
+ Withdrawals []* types.Withdrawal `json:"withdrawals,omitempty"`
86
+ BaseFee * big.Int `json:"currentBaseFee,omitempty"`
87
+ ParentUncleHash common.Hash `json:"parentUncleHash"`
88
+ ExcessBlobGas * uint64 `json:"excessBlobGas,omitempty"`
89
+ ParentExcessBlobGas * uint64 `json:"parentExcessBlobGas,omitempty"`
90
+ ParentBlobGasUsed * uint64 `json:"parentBlobGasUsed,omitempty"`
85
91
}
86
92
87
93
type stEnvMarshaling struct {
88
- Coinbase common.UnprefixedAddress
89
- Difficulty * math.HexOrDecimal256
90
- Random * math.HexOrDecimal256
91
- ParentDifficulty * math.HexOrDecimal256
92
- ParentBaseFee * math.HexOrDecimal256
93
- ParentGasUsed math.HexOrDecimal64
94
- ParentGasLimit math.HexOrDecimal64
95
- GasLimit math.HexOrDecimal64
96
- Number math.HexOrDecimal64
97
- Timestamp math.HexOrDecimal64
98
- ParentTimestamp math.HexOrDecimal64
99
- BaseFee * math.HexOrDecimal256
94
+ Coinbase common.UnprefixedAddress
95
+ Difficulty * math.HexOrDecimal256
96
+ Random * math.HexOrDecimal256
97
+ ParentDifficulty * math.HexOrDecimal256
98
+ ParentBaseFee * math.HexOrDecimal256
99
+ ParentGasUsed math.HexOrDecimal64
100
+ ParentGasLimit math.HexOrDecimal64
101
+ GasLimit math.HexOrDecimal64
102
+ Number math.HexOrDecimal64
103
+ Timestamp math.HexOrDecimal64
104
+ ParentTimestamp math.HexOrDecimal64
105
+ BaseFee * math.HexOrDecimal256
106
+ ExcessBlobGas * math.HexOrDecimal64
107
+ ParentExcessBlobGas * math.HexOrDecimal64
108
+ ParentBlobGasUsed * math.HexOrDecimal64
100
109
}
101
110
102
111
type rejectedTx struct {
@@ -153,15 +162,34 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
153
162
rnd := common .BigToHash (pre .Env .Random )
154
163
vmContext .Random = & rnd
155
164
}
165
+ // If excessBlobGas is defined, add it to the vmContext.
166
+ if pre .Env .ExcessBlobGas != nil {
167
+ vmContext .ExcessBlobGas = pre .Env .ExcessBlobGas
168
+ } else {
169
+ // If it is not explicitly defined, but we have the parent values, we try
170
+ // to calculate it ourselves.
171
+ parentExcessBlobGas := pre .Env .ParentExcessBlobGas
172
+ parentBlobGasUsed := pre .Env .ParentBlobGasUsed
173
+ if parentExcessBlobGas != nil && parentBlobGasUsed != nil {
174
+ excessBlobGas := eip4844 .CalcExcessBlobGas (* parentExcessBlobGas , * parentBlobGasUsed )
175
+ vmContext .ExcessBlobGas = & excessBlobGas
176
+ }
177
+ }
156
178
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's
157
179
// done in StateProcessor.Process(block, ...), right before transactions are applied.
158
180
if chainConfig .DAOForkSupport &&
159
181
chainConfig .DAOForkBlock != nil &&
160
182
chainConfig .DAOForkBlock .Cmp (new (big.Int ).SetUint64 (pre .Env .Number )) == 0 {
161
183
misc .ApplyDAOHardFork (statedb )
162
184
}
163
-
185
+ var blobGasUsed uint64
164
186
for i , tx := range txs {
187
+ if tx .Type () == types .BlobTxType && vmContext .ExcessBlobGas == nil {
188
+ errMsg := "blob tx used but field env.ExcessBlobGas missing"
189
+ log .Warn ("rejected tx" , "index" , i , "hash" , tx .Hash (), "error" , errMsg )
190
+ rejectedTxs = append (rejectedTxs , & rejectedTx {i , errMsg })
191
+ continue
192
+ }
165
193
msg , err := core .TransactionToMessage (tx , signer , pre .Env .BaseFee )
166
194
if err != nil {
167
195
log .Warn ("rejected tx" , "index" , i , "hash" , tx .Hash (), "error" , err )
@@ -191,6 +219,9 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
191
219
gaspool .SetGas (prevGas )
192
220
continue
193
221
}
222
+ if tx .Type () == types .BlobTxType {
223
+ blobGasUsed += params .BlobTxBlobGasPerBlob
224
+ }
194
225
includedTxs = append (includedTxs , tx )
195
226
if hashError != nil {
196
227
return nil , nil , NewError (ErrorMissingBlockhash , hashError )
@@ -286,6 +317,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
286
317
h := types .DeriveSha (types .Withdrawals (pre .Env .Withdrawals ), trie .NewStackTrie (nil ))
287
318
execRs .WithdrawalsRoot = & h
288
319
}
320
+ if vmContext .ExcessBlobGas != nil {
321
+ execRs .CurrentExcessBlobGas = (* math .HexOrDecimal64 )(vmContext .ExcessBlobGas )
322
+ execRs .CurrentBlobGasUsed = (* math .HexOrDecimal64 )(& blobGasUsed )
323
+ }
289
324
// Re-create statedb instance with new root upon the updated database
290
325
// for accessing latest states.
291
326
statedb , err = state .New (root , statedb .Database (), nil )
0 commit comments