@@ -24,6 +24,7 @@ import (
24
24
"github.com/ethereum/go-ethereum/common"
25
25
"github.com/ethereum/go-ethereum/common/hexutil"
26
26
"github.com/ethereum/go-ethereum/core/types"
27
+ "github.com/ethereum/go-ethereum/params"
27
28
"github.com/ethereum/go-ethereum/trie"
28
29
)
29
30
@@ -193,21 +194,21 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
193
194
//
194
195
// and that the blockhash of the constructed block matches the parameters. Nil
195
196
// Withdrawals value will propagate through the returned block. Empty
196
- // Withdrawals value must be passed via non-nil, length 0 value in params .
197
- func ExecutableDataToBlock (params ExecutableData , versionedHashes []common.Hash , beaconRoot * common.Hash ) (* types.Block , error ) {
198
- txs , err := decodeTransactions (params .Transactions )
197
+ // Withdrawals value must be passed via non-nil, length 0 value in data .
198
+ func ExecutableDataToBlock (data ExecutableData , versionedHashes []common.Hash , beaconRoot * common.Hash ) (* types.Block , error ) {
199
+ txs , err := decodeTransactions (data .Transactions )
199
200
if err != nil {
200
201
return nil , err
201
202
}
202
- if len (params .ExtraData ) > 32 {
203
- return nil , fmt .Errorf ("invalid extradata length: %v" , len (params .ExtraData ))
203
+ if len (data .ExtraData ) > int ( params . MaximumExtraDataSize ) {
204
+ return nil , fmt .Errorf ("invalid extradata length: %v" , len (data .ExtraData ))
204
205
}
205
- if len (params .LogsBloom ) != 256 {
206
- return nil , fmt .Errorf ("invalid logsBloom length: %v" , len (params .LogsBloom ))
206
+ if len (data .LogsBloom ) != 256 {
207
+ return nil , fmt .Errorf ("invalid logsBloom length: %v" , len (data .LogsBloom ))
207
208
}
208
209
// Check that baseFeePerGas is not negative or too big
209
- if params .BaseFeePerGas != nil && (params .BaseFeePerGas .Sign () == - 1 || params .BaseFeePerGas .BitLen () > 256 ) {
210
- return nil , fmt .Errorf ("invalid baseFeePerGas: %v" , params .BaseFeePerGas )
210
+ if data .BaseFeePerGas != nil && (data .BaseFeePerGas .Sign () == - 1 || data .BaseFeePerGas .BitLen () > 256 ) {
211
+ return nil , fmt .Errorf ("invalid baseFeePerGas: %v" , data .BaseFeePerGas )
211
212
}
212
213
var blobHashes = make ([]common.Hash , 0 , len (txs ))
213
214
for _ , tx := range txs {
@@ -225,34 +226,34 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
225
226
// ExecutableData before withdrawals are enabled by marshaling
226
227
// Withdrawals as the json null value.
227
228
var withdrawalsRoot * common.Hash
228
- if params .Withdrawals != nil {
229
- h := types .DeriveSha (types .Withdrawals (params .Withdrawals ), trie .NewStackTrie (nil ))
229
+ if data .Withdrawals != nil {
230
+ h := types .DeriveSha (types .Withdrawals (data .Withdrawals ), trie .NewStackTrie (nil ))
230
231
withdrawalsRoot = & h
231
232
}
232
233
header := & types.Header {
233
- ParentHash : params .ParentHash ,
234
+ ParentHash : data .ParentHash ,
234
235
UncleHash : types .EmptyUncleHash ,
235
- Coinbase : params .FeeRecipient ,
236
- Root : params .StateRoot ,
236
+ Coinbase : data .FeeRecipient ,
237
+ Root : data .StateRoot ,
237
238
TxHash : types .DeriveSha (types .Transactions (txs ), trie .NewStackTrie (nil )),
238
- ReceiptHash : params .ReceiptsRoot ,
239
- Bloom : types .BytesToBloom (params .LogsBloom ),
239
+ ReceiptHash : data .ReceiptsRoot ,
240
+ Bloom : types .BytesToBloom (data .LogsBloom ),
240
241
Difficulty : common .Big0 ,
241
- Number : new (big.Int ).SetUint64 (params .Number ),
242
- GasLimit : params .GasLimit ,
243
- GasUsed : params .GasUsed ,
244
- Time : params .Timestamp ,
245
- BaseFee : params .BaseFeePerGas ,
246
- Extra : params .ExtraData ,
247
- MixDigest : params .Random ,
242
+ Number : new (big.Int ).SetUint64 (data .Number ),
243
+ GasLimit : data .GasLimit ,
244
+ GasUsed : data .GasUsed ,
245
+ Time : data .Timestamp ,
246
+ BaseFee : data .BaseFeePerGas ,
247
+ Extra : data .ExtraData ,
248
+ MixDigest : data .Random ,
248
249
WithdrawalsHash : withdrawalsRoot ,
249
- ExcessBlobGas : params .ExcessBlobGas ,
250
- BlobGasUsed : params .BlobGasUsed ,
250
+ ExcessBlobGas : data .ExcessBlobGas ,
251
+ BlobGasUsed : data .BlobGasUsed ,
251
252
ParentBeaconRoot : beaconRoot ,
252
253
}
253
- block := types .NewBlockWithHeader (header ).WithBody (types.Body {Transactions : txs , Uncles : nil , Withdrawals : params .Withdrawals })
254
- if block .Hash () != params .BlockHash {
255
- return nil , fmt .Errorf ("blockhash mismatch, want %x, got %x" , params .BlockHash , block .Hash ())
254
+ block := types .NewBlockWithHeader (header ).WithBody (types.Body {Transactions : txs , Uncles : nil , Withdrawals : data .Withdrawals })
255
+ if block .Hash () != data .BlockHash {
256
+ return nil , fmt .Errorf ("blockhash mismatch, want %x, got %x" , data .BlockHash , block .Hash ())
256
257
}
257
258
return block , nil
258
259
}
0 commit comments