Using github.com/ethereum/go-ethereum/params without alias

This commit is contained in:
art 2024-05-07 21:17:21 +03:00
parent 5252f2c0ef
commit 7547606e0c

View file

@ -18,13 +18,13 @@ package engine
import ( import (
"fmt" "fmt"
"math/big"
"slices"
"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"
"math/big"
"slices"
) )
// PayloadVersion denotes the version of PayloadAttributes used to request the // PayloadVersion denotes the version of PayloadAttributes used to request the
@ -193,21 +193,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 execParams.
func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) { func ExecutableDataToBlock(execParams ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (*types.Block, error) {
txs, err := decodeTransactions(params.Transactions) txs, err := decodeTransactions(execParams.Transactions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(params.ExtraData) > 32 { if len(execParams.ExtraData) > int(params.MaximumExtraDataSize) {
return nil, fmt.Errorf("invalid extradata length: %v", len(params.ExtraData)) return nil, fmt.Errorf("invalid extradata length: %v", len(execParams.ExtraData))
} }
if len(params.LogsBloom) != 256 { if len(execParams.LogsBloom) != 256 {
return nil, fmt.Errorf("invalid logsBloom length: %v", len(params.LogsBloom)) return nil, fmt.Errorf("invalid logsBloom length: %v", len(execParams.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 execParams.BaseFeePerGas != nil && (execParams.BaseFeePerGas.Sign() == -1 || execParams.BaseFeePerGas.BitLen() > 256) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas) return nil, fmt.Errorf("invalid baseFeePerGas: %v", execParams.BaseFeePerGas)
} }
var blobHashes []common.Hash var blobHashes []common.Hash
for _, tx := range txs { for _, tx := range txs {
@ -225,34 +225,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 execParams.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(params.Withdrawals), trie.NewStackTrie(nil)) h := types.DeriveSha(types.Withdrawals(execParams.Withdrawals), trie.NewStackTrie(nil))
withdrawalsRoot = &h withdrawalsRoot = &h
} }
header := &types.Header{ header := &types.Header{
ParentHash: params.ParentHash, ParentHash: execParams.ParentHash,
UncleHash: types.EmptyUncleHash, UncleHash: types.EmptyUncleHash,
Coinbase: params.FeeRecipient, Coinbase: execParams.FeeRecipient,
Root: params.StateRoot, Root: execParams.StateRoot,
TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)),
ReceiptHash: params.ReceiptsRoot, ReceiptHash: execParams.ReceiptsRoot,
Bloom: types.BytesToBloom(params.LogsBloom), Bloom: types.BytesToBloom(execParams.LogsBloom),
Difficulty: common.Big0, Difficulty: common.Big0,
Number: new(big.Int).SetUint64(params.Number), Number: new(big.Int).SetUint64(execParams.Number),
GasLimit: params.GasLimit, GasLimit: execParams.GasLimit,
GasUsed: params.GasUsed, GasUsed: execParams.GasUsed,
Time: params.Timestamp, Time: execParams.Timestamp,
BaseFee: params.BaseFeePerGas, BaseFee: execParams.BaseFeePerGas,
Extra: params.ExtraData, Extra: execParams.ExtraData,
MixDigest: params.Random, MixDigest: execParams.Random,
WithdrawalsHash: withdrawalsRoot, WithdrawalsHash: withdrawalsRoot,
ExcessBlobGas: params.ExcessBlobGas, ExcessBlobGas: execParams.ExcessBlobGas,
BlobGasUsed: params.BlobGasUsed, BlobGasUsed: execParams.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: execParams.Withdrawals})
if block.Hash() != params.BlockHash { if block.Hash() != execParams.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", execParams.BlockHash, block.Hash())
} }
return block, nil return block, nil
} }