@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie"
)
)
@ -193,21 +194,21 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
//
//
// and that the blockhash of the constructed block matches the parameters. Nil
// and that the blockhash of the constructed block matches the parameters. Nil
// Withdrawals value will propagate through the returned block. Empty
// Withdrawals value will propagate through the returned block. Empty
// Withdrawals value must be passed via non-nil, length 0 value in params .
// Withdrawals value must be passed via non-nil, length 0 value in data .
func ExecutableDataToBlock ( params ExecutableData , versionedHashes [ ] common . Hash , beaconRoot * common . Hash ) ( * types . Block , error ) {
func ExecutableDataToBlock ( data ExecutableData , versionedHashes [ ] common . Hash , beaconRoot * common . Hash ) ( * types . Block , error ) {
txs , err := decodeTransactions ( params . Transactions )
txs , err := decodeTransactions ( data . Transactions )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
if len ( params . ExtraData ) > 32 {
if len ( data . ExtraData ) > int ( params . MaximumExtraDataSize ) {
return nil , fmt . Errorf ( "invalid extradata length: %v" , len ( params . ExtraData ) )
return nil , fmt . Errorf ( "invalid extradata length: %v" , len ( data . ExtraData ) )
}
}
if len ( params . LogsBloom ) != 256 {
if len ( data . LogsBloom ) != 256 {
return nil , fmt . Errorf ( "invalid logsBloom length: %v" , len ( params . LogsBloom ) )
return nil , fmt . Errorf ( "invalid logsBloom length: %v" , len ( data . LogsBloom ) )
}
}
// Check that baseFeePerGas is not negative or too big
// Check that baseFeePerGas is not negative or too big
if params . BaseFeePerGas != nil && ( params . BaseFeePerGas . Sign ( ) == - 1 || params . BaseFeePerGas . BitLen ( ) > 256 ) {
if data . BaseFeePerGas != nil && ( data . BaseFeePerGas . Sign ( ) == - 1 || data . BaseFeePerGas . BitLen ( ) > 256 ) {
return nil , fmt . Errorf ( "invalid baseFeePerGas: %v" , params . BaseFeePerGas )
return nil , fmt . Errorf ( "invalid baseFeePerGas: %v" , data . BaseFeePerGas )
}
}
var blobHashes = make ( [ ] common . Hash , 0 , len ( txs ) )
var blobHashes = make ( [ ] common . Hash , 0 , len ( txs ) )
for _ , tx := range txs {
for _ , tx := range txs {
@ -225,34 +226,34 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
// ExecutableData before withdrawals are enabled by marshaling
// ExecutableData before withdrawals are enabled by marshaling
// Withdrawals as the json null value.
// Withdrawals as the json null value.
var withdrawalsRoot * common . Hash
var withdrawalsRoot * common . Hash
if params . Withdrawals != nil {
if data . Withdrawals != nil {
h := types . DeriveSha ( types . Withdrawals ( params . Withdrawals ) , trie . NewStackTrie ( nil ) )
h := types . DeriveSha ( types . Withdrawals ( data . Withdrawals ) , trie . NewStackTrie ( nil ) )
withdrawalsRoot = & h
withdrawalsRoot = & h
}
}
header := & types . Header {
header := & types . Header {
ParentHash : params . ParentHash ,
ParentHash : data . ParentHash ,
UncleHash : types . EmptyUncleHash ,
UncleHash : types . EmptyUncleHash ,
Coinbase : params . FeeRecipient ,
Coinbase : data . FeeRecipient ,
Root : params . StateRoot ,
Root : data . StateRoot ,
TxHash : types . DeriveSha ( types . Transactions ( txs ) , trie . NewStackTrie ( nil ) ) ,
TxHash : types . DeriveSha ( types . Transactions ( txs ) , trie . NewStackTrie ( nil ) ) ,
ReceiptHash : params . ReceiptsRoot ,
ReceiptHash : data . ReceiptsRoot ,
Bloom : types . BytesToBloom ( params . LogsBloom ) ,
Bloom : types . BytesToBloom ( data . LogsBloom ) ,
Difficulty : common . Big0 ,
Difficulty : common . Big0 ,
Number : new ( big . Int ) . SetUint64 ( params . Number ) ,
Number : new ( big . Int ) . SetUint64 ( data . Number ) ,
GasLimit : params . GasLimit ,
GasLimit : data . GasLimit ,
GasUsed : params . GasUsed ,
GasUsed : data . GasUsed ,
Time : params . Timestamp ,
Time : data . Timestamp ,
BaseFee : params . BaseFeePerGas ,
BaseFee : data . BaseFeePerGas ,
Extra : params . ExtraData ,
Extra : data . ExtraData ,
MixDigest : params . Random ,
MixDigest : data . Random ,
WithdrawalsHash : withdrawalsRoot ,
WithdrawalsHash : withdrawalsRoot ,
ExcessBlobGas : params . ExcessBlobGas ,
ExcessBlobGas : data . ExcessBlobGas ,
BlobGasUsed : params . BlobGasUsed ,
BlobGasUsed : data . BlobGasUsed ,
ParentBeaconRoot : beaconRoot ,
ParentBeaconRoot : beaconRoot ,
}
}
block := types . NewBlockWithHeader ( header ) . WithBody ( types . Body { Transactions : txs , Uncles : nil , Withdrawals : params . Withdrawals } )
block := types . NewBlockWithHeader ( header ) . WithBody ( types . Body { Transactions : txs , Uncles : nil , Withdrawals : data . Withdrawals } )
if block . Hash ( ) != params . BlockHash {
if block . Hash ( ) != data . BlockHash {
return nil , fmt . Errorf ( "blockhash mismatch, want %x, got %x" , params . BlockHash , block . Hash ( ) )
return nil , fmt . Errorf ( "blockhash mismatch, want %x, got %x" , data . BlockHash , block . Hash ( ) )
}
}
return block , nil
return block , nil
}
}