Skip to content

Commit

Permalink
Merge branch 'ethereum:master' into portal
Browse files Browse the repository at this point in the history
  • Loading branch information
GrapeBaBa authored Apr 8, 2024
2 parents eb46343 + c170cc0 commit 75a9bc1
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion accounts/external/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
args.BlobHashes = tx.BlobHashes()
sidecar := tx.BlobTxSidecar()
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.Commitments = sidecar.Commitments
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/ethtest/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
if rbloom != header.Bloom {
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))
if receiptSha != header.ReceiptHash {
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
}

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)
Expand Down
4 changes: 2 additions & 2 deletions core/blockchain_sethead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package core
import (
"fmt"
"math/big"
"path"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -1966,7 +1966,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme

// Create a temporary persistent database
datadir := t.TempDir()
ancient := path.Join(datadir, "ancient")
ancient := filepath.Join(datadir, "ancient")

db, err := rawdb.Open(rawdb.OpenOptions{
Directory: datadir,
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
Config: &config,
GasLimit: gasLimit,
BaseFee: big.NewInt(params.InitialBaseFee),
Difficulty: big.NewInt(1),
Difficulty: big.NewInt(0),
Alloc: map[common.Address]types.Account{
common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
Expand Down
3 changes: 1 addition & 2 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -172,7 +171,7 @@ func resolveChainFreezerDir(ancient string) string {
// sub folder, if not then two possibilities:
// - chain freezer is not initialized
// - 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(ancient) {
// The entire ancient store is not initialized, still use the sub
Expand Down
13 changes: 6 additions & 7 deletions core/rawdb/freezer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"math/big"
"math/rand"
"os"
"path"
"path/filepath"
"sync"
"testing"
Expand Down Expand Up @@ -398,11 +397,11 @@ func TestRenameWindows(t *testing.T) {
if err != nil {
t.Fatal(err)
}
f2, err := os.Create(path.Join(dir1, fname2))
f2, err := os.Create(filepath.Join(dir1, fname2))
if err != nil {
t.Fatal(err)
}
f3, err := os.Create(path.Join(dir2, fname2))
f3, err := os.Create(filepath.Join(dir2, fname2))
if err != nil {
t.Fatal(err)
}
Expand All @@ -424,15 +423,15 @@ func TestRenameWindows(t *testing.T) {
if err := f3.Close(); err != nil {
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)
}
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)
}

// Check file contents
f, err = os.Open(path.Join(dir2, fname))
f, err = os.Open(filepath.Join(dir2, fname))
if err != nil {
t.Fatal(err)
}
Expand All @@ -446,7 +445,7 @@ func TestRenameWindows(t *testing.T) {
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 {
t.Fatal(err)
}
Expand Down
12 changes: 9 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if evm.chainRules.IsBerlin {
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)
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 {
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
}

return nil, common.Address{}, 0, ErrContractAddressCollision
}
// Create a new account on the state
Expand Down
1 change: 1 addition & 0 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type StateDB interface {
GetCommittedState(common.Address, common.Hash) common.Hash
GetState(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
SetTransientState(addr common.Address, key, value common.Hash)
Expand Down
2 changes: 1 addition & 1 deletion internal/build/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func UploadSFTP(identityFile, host, dir string, files []string) error {
}
in := io.MultiWriter(stdin, os.Stdout)
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")
// Some issue with the PPA sftp server makes it so the server does not
Expand Down
3 changes: 1 addition & 2 deletions internal/era/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package era

import (
"errors"
"fmt"
"io"
"math/big"

Expand Down Expand Up @@ -80,7 +79,7 @@ func (it *Iterator) Block() (*types.Block, error) {
// Receipts returns the receipts for the iterator's current position.
func (it *Iterator) Receipts() (types.Receipts, error) {
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
err := rlp.Decode(it.inner.Receipts, &receipts)
Expand Down
2 changes: 1 addition & 1 deletion log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func JSONHandler(wr io.Writer) slog.Handler {
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.
func JSONHandlerWithLevel(wr io.Writer, level slog.Level) slog.Handler {
return slog.NewJSONHandler(wr, &slog.HandlerOptions{
Expand Down
4 changes: 2 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type newPayloadResult struct {
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 {
timestamp uint64 // The timestamp for sealing task
forceTime bool // Flag whether the given timestamp is immutable or not
Expand Down Expand Up @@ -131,7 +131,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error)
if genParams.parentHash != (common.Hash{}) {
block := miner.chain.GetBlockByHash(genParams.parentHash)
if block == nil {
return nil, fmt.Errorf("missing parent")
return nil, errors.New("missing parent")
}
parent = block.Header()
}
Expand Down
4 changes: 2 additions & 2 deletions node/node_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"net/http"
"os"
"path"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -98,7 +98,7 @@ func TestAuthEndpoints(t *testing.T) {
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.
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 {
t.Fatalf("failed to prepare jwt secret file: %v", err)
}
Expand Down
13 changes: 3 additions & 10 deletions signer/core/apitypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"math/big"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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
func (typedData *TypedData) Dependencies(primaryType string, found []string) []string {
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
}
if typedData.Types[primaryType] == nil {
Expand All @@ -404,7 +397,7 @@ func (typedData *TypedData) Dependencies(primaryType string, found []string) []s
found = append(found, primaryType)
for _, field := range typedData.Types[primaryType] {
for _, dep := range typedData.Dependencies(field.Type, found) {
if !includes(found, dep) {
if !slices.Contains(found, dep) {
found = append(found, dep)
}
}
Expand Down
3 changes: 2 additions & 1 deletion signer/core/signed_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/big"
"os"
"path"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -411,7 +412,7 @@ func TestJsonFiles(t *testing.T) {
// crashes or hangs.
func TestFuzzerFiles(t *testing.T) {
t.Parallel()
corpusdir := path.Join("testdata", "fuzzing")
corpusdir := filepath.Join("testdata", "fuzzing")
testfiles, err := os.ReadDir(corpusdir)
if err != nil {
t.Fatalf("failed reading files: %v", err)
Expand Down
8 changes: 8 additions & 0 deletions tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestExecutionSpecBlocktests(t *testing.T) {
}
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) {
execBlockTest(t, bt, test)
})
Expand Down
13 changes: 13 additions & 0 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,22 @@ func initMatcher(st *testMatcher) {
// Uses 1GB RAM per tested fork
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:
// EOF is not part of cancun
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) {
Expand Down

0 comments on commit 75a9bc1

Please sign in to comment.