@@ -24,6 +24,7 @@ import (
2424 "github.com/ethereum/go-ethereum/common"
2525 "github.com/ethereum/go-ethereum/common/hexutil"
2626 "github.com/ethereum/go-ethereum/core/types"
27+ "github.com/ethereum/go-ethereum/params"
2728 "github.com/ethereum/go-ethereum/trie"
2829)
2930
@@ -193,21 +194,21 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
193194//
194195// and that the blockhash of the constructed block matches the parameters. Nil
195196// 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 )
199200 if err != nil {
200201 return nil , err
201202 }
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 ))
204205 }
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 ))
207208 }
208209 // 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 )
211212 }
212213 var blobHashes = make ([]common.Hash , 0 , len (txs ))
213214 for _ , tx := range txs {
@@ -225,34 +226,34 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
225226 // ExecutableData before withdrawals are enabled by marshaling
226227 // Withdrawals as the json null value.
227228 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 ))
230231 withdrawalsRoot = & h
231232 }
232233 header := & types.Header {
233- ParentHash : params .ParentHash ,
234+ ParentHash : data .ParentHash ,
234235 UncleHash : types .EmptyUncleHash ,
235- Coinbase : params .FeeRecipient ,
236- Root : params .StateRoot ,
236+ Coinbase : data .FeeRecipient ,
237+ Root : data .StateRoot ,
237238 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 ),
240241 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 ,
248249 WithdrawalsHash : withdrawalsRoot ,
249- ExcessBlobGas : params .ExcessBlobGas ,
250- BlobGasUsed : params .BlobGasUsed ,
250+ ExcessBlobGas : data .ExcessBlobGas ,
251+ BlobGasUsed : data .BlobGasUsed ,
251252 ParentBeaconRoot : beaconRoot ,
252253 }
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 ())
256257 }
257258 return block , nil
258259}
0 commit comments