Merge branch 'ethereum:master' into portal

This commit is contained in:
Chen Kai 2024-04-08 21:53:47 +08:00 committed by GitHub
commit 75a9bc1b54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 57 additions and 38 deletions

View file

@ -239,7 +239,7 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
args.BlobHashes = tx.BlobHashes() args.BlobHashes = tx.BlobHashes()
sidecar := tx.BlobTxSidecar() sidecar := tx.BlobTxSidecar()
if sidecar == nil { if sidecar == nil {
return nil, fmt.Errorf("blobs must be present for signing") return nil, errors.New("blobs must be present for signing")
} }
args.Blobs = sidecar.Blobs args.Blobs = sidecar.Blobs
args.Commitments = sidecar.Commitments args.Commitments = sidecar.Commitments

View file

@ -102,7 +102,7 @@ func (s *Suite) sendTxs(t *utesting.T, txs []*types.Transaction) error {
} }
} }
return fmt.Errorf("timed out waiting for txs") return errors.New("timed out waiting for txs")
} }
func (s *Suite) sendInvalidTxs(t *utesting.T, txs []*types.Transaction) error { func (s *Suite) sendInvalidTxs(t *utesting.T, txs []*types.Transaction) error {

View file

@ -132,7 +132,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
if rbloom != header.Bloom { if rbloom != header.Bloom {
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom)
} }
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]])) // The receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil)) receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
if receiptSha != header.ReceiptHash { if receiptSha != header.ReceiptHash {
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)

View file

@ -439,7 +439,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
} }
if alloc == nil { if alloc == nil {
return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set") return nil, errors.New("live blockchain tracer requires genesis alloc to be set")
} }
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc) bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)

View file

@ -22,7 +22,7 @@ package core
import ( import (
"fmt" "fmt"
"math/big" "math/big"
"path" "path/filepath"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -1966,7 +1966,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
// Create a temporary persistent database // Create a temporary persistent database
datadir := t.TempDir() datadir := t.TempDir()
ancient := path.Join(datadir, "ancient") ancient := filepath.Join(datadir, "ancient")
db, err := rawdb.Open(rawdb.OpenOptions{ db, err := rawdb.Open(rawdb.OpenOptions{
Directory: datadir, Directory: datadir,

View file

@ -582,7 +582,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
Config: &config, Config: &config,
GasLimit: gasLimit, GasLimit: gasLimit,
BaseFee: big.NewInt(params.InitialBaseFee), BaseFee: big.NewInt(params.InitialBaseFee),
Difficulty: big.NewInt(1), Difficulty: big.NewInt(0),
Alloc: map[common.Address]types.Account{ Alloc: map[common.Address]types.Account{
common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256 common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256

View file

@ -21,7 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
@ -172,7 +171,7 @@ func resolveChainFreezerDir(ancient string) string {
// sub folder, if not then two possibilities: // sub folder, if not then two possibilities:
// - chain freezer is not initialized // - chain freezer is not initialized
// - chain freezer exists in legacy location (root ancient folder) // - chain freezer exists in legacy location (root ancient folder)
freezer := path.Join(ancient, ChainFreezerName) freezer := filepath.Join(ancient, ChainFreezerName)
if !common.FileExist(freezer) { if !common.FileExist(freezer) {
if !common.FileExist(ancient) { if !common.FileExist(ancient) {
// The entire ancient store is not initialized, still use the sub // The entire ancient store is not initialized, still use the sub

View file

@ -23,7 +23,6 @@ import (
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
"path"
"path/filepath" "path/filepath"
"sync" "sync"
"testing" "testing"
@ -398,11 +397,11 @@ func TestRenameWindows(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
f2, err := os.Create(path.Join(dir1, fname2)) f2, err := os.Create(filepath.Join(dir1, fname2))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
f3, err := os.Create(path.Join(dir2, fname2)) f3, err := os.Create(filepath.Join(dir2, fname2))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -424,15 +423,15 @@ func TestRenameWindows(t *testing.T) {
if err := f3.Close(); err != nil { if err := f3.Close(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := os.Rename(f.Name(), path.Join(dir2, fname)); err != nil { if err := os.Rename(f.Name(), filepath.Join(dir2, fname)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := os.Rename(f2.Name(), path.Join(dir2, fname2)); err != nil { if err := os.Rename(f2.Name(), filepath.Join(dir2, fname2)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Check file contents // Check file contents
f, err = os.Open(path.Join(dir2, fname)) f, err = os.Open(filepath.Join(dir2, fname))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -446,7 +445,7 @@ func TestRenameWindows(t *testing.T) {
t.Errorf("unexpected file contents. Got %v\n", buf) t.Errorf("unexpected file contents. Got %v\n", buf)
} }
f, err = os.Open(path.Join(dir2, fname2)) f, err = os.Open(filepath.Join(dir2, fname2))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -439,13 +439,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if evm.chainRules.IsBerlin { if evm.chainRules.IsBerlin {
evm.StateDB.AddAddressToAccessList(address) evm.StateDB.AddAddressToAccessList(address)
} }
// Ensure there's no existing contract already at the designated address // Ensure there's no existing contract already at the designated address.
// Account is regarded as existent if any of these three conditions is met:
// - the nonce is nonzero
// - the code is non-empty
// - the storage is non-empty
contractHash := evm.StateDB.GetCodeHash(address) contractHash := evm.StateDB.GetCodeHash(address)
if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) { storageRoot := evm.StateDB.GetStorageRoot(address)
if evm.StateDB.GetNonce(address) != 0 ||
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
(storageRoot != (common.Hash{}) && storageRoot != types.EmptyRootHash) { // non-empty storage
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil { if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution) evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
} }
return nil, common.Address{}, 0, ErrContractAddressCollision return nil, common.Address{}, 0, ErrContractAddressCollision
} }
// Create a new account on the state // Create a new account on the state

View file

@ -49,6 +49,7 @@ type StateDB interface {
GetCommittedState(common.Address, common.Hash) common.Hash GetCommittedState(common.Address, common.Hash) common.Hash
GetState(common.Address, common.Hash) common.Hash GetState(common.Address, common.Hash) common.Hash
SetState(common.Address, common.Hash, common.Hash) SetState(common.Address, common.Hash, common.Hash)
GetStorageRoot(addr common.Address) common.Hash
GetTransientState(addr common.Address, key common.Hash) common.Hash GetTransientState(addr common.Address, key common.Hash) common.Hash
SetTransientState(addr common.Address, key, value common.Hash) SetTransientState(addr common.Address, key, value common.Hash)

View file

@ -175,7 +175,7 @@ func UploadSFTP(identityFile, host, dir string, files []string) error {
} }
in := io.MultiWriter(stdin, os.Stdout) in := io.MultiWriter(stdin, os.Stdout)
for _, f := range files { for _, f := range files {
fmt.Fprintln(in, "put", f, path.Join(dir, filepath.Base(f))) fmt.Fprintln(in, "put", f, filepath.Join(dir, filepath.Base(f)))
} }
fmt.Fprintln(in, "exit") fmt.Fprintln(in, "exit")
// Some issue with the PPA sftp server makes it so the server does not // Some issue with the PPA sftp server makes it so the server does not

View file

@ -18,7 +18,6 @@ package era
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"math/big" "math/big"
@ -80,7 +79,7 @@ func (it *Iterator) Block() (*types.Block, error) {
// Receipts returns the receipts for the iterator's current position. // Receipts returns the receipts for the iterator's current position.
func (it *Iterator) Receipts() (types.Receipts, error) { func (it *Iterator) Receipts() (types.Receipts, error) {
if it.inner.Receipts == nil { if it.inner.Receipts == nil {
return nil, fmt.Errorf("receipts must be non-nil") return nil, errors.New("receipts must be non-nil")
} }
var receipts types.Receipts var receipts types.Receipts
err := rlp.Decode(it.inner.Receipts, &receipts) err := rlp.Decode(it.inner.Receipts, &receipts)

View file

@ -118,7 +118,7 @@ func JSONHandler(wr io.Writer) slog.Handler {
return JSONHandlerWithLevel(wr, levelMaxVerbosity) return JSONHandlerWithLevel(wr, levelMaxVerbosity)
} }
// JSONHandler returns a handler which prints records in JSON format that are less than or equal to // JSONHandlerWithLevel returns a handler which prints records in JSON format that are less than or equal to
// the specified verbosity level. // the specified verbosity level.
func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler { func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler {
return slog.NewJSONHandler(wr, &slog.HandlerOptions{ return slog.NewJSONHandler(wr, &slog.HandlerOptions{

View file

@ -75,7 +75,7 @@ type newPayloadResult struct {
receipts []*types.Receipt // Receipts collected during construction receipts []*types.Receipt // Receipts collected during construction
} }
// generateParams wraps various of settings for generating sealing task. // generateParams wraps various settings for generating sealing task.
type generateParams struct { type generateParams struct {
timestamp uint64 // The timestamp for sealing task timestamp uint64 // The timestamp for sealing task
forceTime bool // Flag whether the given timestamp is immutable or not forceTime bool // Flag whether the given timestamp is immutable or not
@ -131,7 +131,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error)
if genParams.parentHash != (common.Hash{}) { if genParams.parentHash != (common.Hash{}) {
block := miner.chain.GetBlockByHash(genParams.parentHash) block := miner.chain.GetBlockByHash(genParams.parentHash)
if block == nil { if block == nil {
return nil, fmt.Errorf("missing parent") return nil, errors.New("missing parent")
} }
parent = block.Header() parent = block.Header()
} }

View file

@ -22,7 +22,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"path" "path/filepath"
"testing" "testing"
"time" "time"
@ -98,7 +98,7 @@ func TestAuthEndpoints(t *testing.T) {
t.Fatalf("failed to create jwt secret: %v", err) t.Fatalf("failed to create jwt secret: %v", err)
} }
// Geth must read it from a file, and does not support in-memory JWT secrets, so we create a temporary file. // Geth must read it from a file, and does not support in-memory JWT secrets, so we create a temporary file.
jwtPath := path.Join(t.TempDir(), "jwt_secret") jwtPath := filepath.Join(t.TempDir(), "jwt_secret")
if err := os.WriteFile(jwtPath, []byte(hexutil.Encode(secret[:])), 0600); err != nil { if err := os.WriteFile(jwtPath, []byte(hexutil.Encode(secret[:])), 0600); err != nil {
t.Fatalf("failed to prepare jwt secret file: %v", err) t.Fatalf("failed to prepare jwt secret file: %v", err)
} }

View file

@ -25,6 +25,7 @@ import (
"math/big" "math/big"
"reflect" "reflect"
"regexp" "regexp"
"slices"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -386,16 +387,8 @@ func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage
// Dependencies returns an array of custom types ordered by their hierarchical reference tree // Dependencies returns an array of custom types ordered by their hierarchical reference tree
func (typedData *TypedData) Dependencies(primaryType string, found []string) []string { func (typedData *TypedData) Dependencies(primaryType string, found []string) []string {
primaryType = strings.TrimSuffix(primaryType, "[]") primaryType = strings.TrimSuffix(primaryType, "[]")
includes := func(arr []string, str string) bool {
for _, obj := range arr {
if obj == str {
return true
}
}
return false
}
if includes(found, primaryType) { if slices.Contains(found, primaryType) {
return found return found
} }
if typedData.Types[primaryType] == nil { if typedData.Types[primaryType] == nil {
@ -404,7 +397,7 @@ func (typedData *TypedData) Dependencies(primaryType string, found []string) []s
found = append(found, primaryType) found = append(found, primaryType)
for _, field := range typedData.Types[primaryType] { for _, field := range typedData.Types[primaryType] {
for _, dep := range typedData.Dependencies(field.Type, found) { for _, dep := range typedData.Dependencies(field.Type, found) {
if !includes(found, dep) { if !slices.Contains(found, dep) {
found = append(found, dep) found = append(found, dep)
} }
} }

View file

@ -24,6 +24,7 @@ import (
"math/big" "math/big"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"testing" "testing"
@ -411,7 +412,7 @@ func TestJsonFiles(t *testing.T) {
// crashes or hangs. // crashes or hangs.
func TestFuzzerFiles(t *testing.T) { func TestFuzzerFiles(t *testing.T) {
t.Parallel() t.Parallel()
corpusdir := path.Join("testdata", "fuzzing") corpusdir := filepath.Join("testdata", "fuzzing")
testfiles, err := os.ReadDir(corpusdir) testfiles, err := os.ReadDir(corpusdir)
if err != nil { if err != nil {
t.Fatalf("failed reading files: %v", err) t.Fatalf("failed reading files: %v", err)

View file

@ -64,6 +64,14 @@ func TestExecutionSpecBlocktests(t *testing.T) {
} }
bt := new(testMatcher) bt := new(testMatcher)
// These tests fail as of https://github.com/ethereum/go-ethereum/pull/28666, since we
// no longer delete "leftover storage" when deploying a contract.
bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/self_destructing_initcode_create_tx.json`)
bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/self_destructing_initcode.json`)
bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/recreate_self_destructed_contract_different_txs.json`)
bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/delegatecall_from_new_contract_to_pre_existing_contract.json`)
bt.skipLoad(`^cancun/eip6780_selfdestruct/selfdestruct/create_selfdestruct_same_tx.json`)
bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) { bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
execBlockTest(t, bt, test) execBlockTest(t, bt, test)
}) })

View file

@ -54,9 +54,22 @@ func initMatcher(st *testMatcher) {
// Uses 1GB RAM per tested fork // Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`) st.skipLoad(`^stStaticCall/static_Call1MB`)
// These tests fail as of https://github.com/ethereum/go-ethereum/pull/28666, since we
// no longer delete "leftover storage" when deploying a contract.
st.skipLoad(`^stSStoreTest/InitCollision\.json`)
st.skipLoad(`^stRevertTest/RevertInCreateInInit\.json`)
st.skipLoad(`^stExtCodeHash/dynamicAccountOverwriteEmpty\.json`)
st.skipLoad(`^stCreate2/create2collisionStorage\.json`)
st.skipLoad(`^stCreate2/RevertInCreateInInitCreate2\.json`)
// Broken tests: // Broken tests:
// EOF is not part of cancun // EOF is not part of cancun
st.skipLoad(`^stEOF/`) st.skipLoad(`^stEOF/`)
// The tests under Pyspecs are the ones that are published as execution-spec tests.
// We run these tests separately, no need to _also_ run them as part of the
// reference tests.
st.skipLoad(`^Pyspecs/`)
} }
func TestState(t *testing.T) { func TestState(t *testing.T) {