Merge remote-tracking branch 'origin/const-block-head-extra' into const-block-head-extra

# Conflicts:
#	beacon/engine/types.go
This commit is contained in:
art 2024-05-07 21:09:30 +03:00
commit 5252f2c0ef
2 changed files with 28 additions and 29 deletions

View file

@ -18,7 +18,6 @@ package engine
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/params"
"math/big" "math/big"
"slices" "slices"
@ -195,20 +194,20 @@ 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 params.
func ExecutableDataToBlock(execParams ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) { func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) {
txs, err := decodeTransactions(execParams.Transactions) txs, err := decodeTransactions(params.Transactions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(execParams.ExtraData) > int(params.MaximumExtraDataSize) { if len(params.ExtraData) > 32 {
return nil, fmt.Errorf("invalid extradata length: %v", len(execParams.ExtraData)) return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData))
} }
if len(execParams.LogsBloom) != 256 { if len(params.LogsBloom) != 256 {
return nil, fmt.Errorf("invalid logsBloom length: %v", len(execParams.LogsBloom)) return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom))
} }
// Check that baseFeePerGas is not negative or too big // Check that baseFeePerGas is not negative or too big
if execParams.BaseFeePerGas != nil && (execParams.BaseFeePerGas.Sign() == -1 || execParams.BaseFeePerGas.BitLen() > 256) { if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", execParams.BaseFeePerGas) return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
} }
var blobHashes []common.Hash var blobHashes []common.Hash
for _, tx := range txs { for _, tx := range txs {
@ -226,34 +225,34 @@ func ExecutableDataToBlock(execParams ExecutableData, versionedHashes []common.H
// 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 execParams.Withdrawals != nil { if params.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(execParams.Withdrawals), trie.NewStackTrie(nil)) h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil))
withdrawalsRoot = &h withdrawalsRoot = &h
} }
header := &types.Header{ header := &types.Header{
ParentHash: execParams.ParentHash, ParentHash: params.ParentHash,
UncleHash: types.EmptyUncleHash, UncleHash: types.EmptyUncleHash,
Coinbase: execParams.FeeRecipient, Coinbase: params.FeeRecipient,
Root: execParams.StateRoot, Root: params.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: execParams.ReceiptsRoot, ReceiptHash: params.ReceiptsRoot,
Bloom: types.BytesToBloom(execParams.LogsBloom), Bloom: types.BytesToBloom(params.LogsBloom),
Difficulty: common.Big0, Difficulty: common.Big0,
Number: new(big.Int).SetUint64(execParams.Number), Number: new(big.Int).SetUint64(params.Number),
GasLimit: execParams.GasLimit, GasLimit: params.GasLimit,
GasUsed: execParams.GasUsed, GasUsed: params.GasUsed,
Time: execParams.Timestamp, Time: params.Timestamp,
BaseFee: execParams.BaseFeePerGas, BaseFee: params.BaseFeePerGas,
Extra: execParams.ExtraData, Extra: params.ExtraData,
MixDigest: execParams.Random, MixDigest: params.Random,
WithdrawalsHash: withdrawalsRoot, WithdrawalsHash: withdrawalsRoot,
ExcessBlobGas: execParams.ExcessBlobGas, ExcessBlobGas: params.ExcessBlobGas,
BlobGasUsed: execParams.BlobGasUsed, BlobGasUsed: params.BlobGasUsed,
ParentBeaconRoot: beaconRoot, ParentBeaconRoot: beaconRoot,
} }
block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: execParams.Withdrawals}) block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: params.Withdrawals})
if block.Hash() != execParams.BlockHash { if block.Hash() != params.BlockHash {
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", execParams.BlockHash, block.Hash()) return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", params.BlockHash, block.Hash())
} }
return block, nil return block, nil
} }

View file

@ -229,7 +229,7 @@ func (beacon *Beacon) VerifyUncles(chain consensus.ChainReader, block *types.Blo
// (c) the extradata is limited to 32 bytes // (c) the extradata is limited to 32 bytes
func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error { func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error {
// Ensure that the header's extra-data section is of a reasonable size // Ensure that the header's extra-data section is of a reasonable size
if len(header.Extra) > 32 { if len(header.Extra) > int(params.MaximumExtraDataSize) {
return fmt.Errorf("extra-data longer than 32 bytes (%d)", len(header.Extra)) return fmt.Errorf("extra-data longer than 32 bytes (%d)", len(header.Extra))
} }
// Verify the seal parts. Ensure the nonce and uncle hash are the expected value. // Verify the seal parts. Ensure the nonce and uncle hash are the expected value.