Skip to content

Commit

Permalink
Restore execution-spec-tests submodule and revert PR #12925 (#12976)
Browse files Browse the repository at this point in the history
Submodule `execution-spec-tests` was inadvertently deleted by PR #10915
and then PR #12925 broke the tests, which went unnoticed because of the
submodule deletion.
  • Loading branch information
yperbasis authored Dec 3, 2024
1 parent ba13e5d commit 172fba9
Show file tree
Hide file tree
Showing 49 changed files with 680 additions and 1,604 deletions.
25 changes: 8 additions & 17 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (b *SimulatedBackend) CodeAt(ctx context.Context, contract libcommon.Addres
}
defer tx.Rollback()
stateDB := b.stateByBlockNumber(tx, blockNumber)
return stateDB.GetCode(contract)
return stateDB.GetCode(contract), nil
}

// BalanceAt returns the wei balance of a certain account in the blockchain.
Expand All @@ -220,7 +220,7 @@ func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract libcommon.Add
}
defer tx.Rollback()
stateDB := b.stateByBlockNumber(tx, blockNumber)
return stateDB.GetBalance(contract)
return stateDB.GetBalance(contract), nil
}

// NonceAt returns the nonce of a certain account in the blockchain.
Expand All @@ -234,7 +234,7 @@ func (b *SimulatedBackend) NonceAt(ctx context.Context, contract libcommon.Addre
defer tx.Rollback()

stateDB := b.stateByBlockNumber(tx, blockNumber)
return stateDB.GetNonce(contract)
return stateDB.GetNonce(contract), nil
}

// StorageAt returns the value of key in the storage of an account in the blockchain.
Expand Down Expand Up @@ -518,7 +518,7 @@ func (b *SimulatedBackend) PendingCodeAt(ctx context.Context, contract libcommon
b.mu.Lock()
defer b.mu.Unlock()

return b.pendingState.GetCode(contract)
return b.pendingState.GetCode(contract), nil
}

func newRevertError(result *evmtypes.ExecutionResult) *revertError {
Expand Down Expand Up @@ -600,7 +600,7 @@ func (b *SimulatedBackend) PendingNonceAt(ctx context.Context, account libcommon
b.mu.Lock()
defer b.mu.Unlock()

return b.pendingState.GetNonce(account)
return b.pendingState.GetNonce(account), nil
}

// SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated
Expand Down Expand Up @@ -628,10 +628,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
}
// Recap the highest gas allowance with account's balance.
if call.GasPrice != nil && !call.GasPrice.IsZero() {
balance, err := b.pendingState.GetBalance(call.From) // from can't be nil
if err != nil {
return 0, err
}
balance := b.pendingState.GetBalance(call.From) // from can't be nil
available := balance.ToBig()
if call.Value != nil {
if call.Value.ToBig().Cmp(available) >= 0 {
Expand Down Expand Up @@ -727,10 +724,7 @@ func (b *SimulatedBackend) callContract(_ context.Context, call ethereum.CallMsg
call.Value = new(uint256.Int)
}
// Set infinite balance to the fake caller account.
from, err := statedb.GetOrNewStateObject(call.From)
if err != nil {
return nil, err
}
from := statedb.GetOrNewStateObject(call.From)
from.SetBalance(uint256.NewInt(0).SetAllOne(), tracing.BalanceChangeUnspecified)
// Execute the call.
msg := callMsg{call}
Expand Down Expand Up @@ -758,10 +752,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, txn types.Transa
if senderErr != nil {
return fmt.Errorf("invalid transaction: %w", senderErr)
}
nonce, err := b.pendingState.GetNonce(sender)
if err != nil {
return err
}
nonce := b.pendingState.GetNonce(sender)
if txn.GetNonce() != nonce {
return fmt.Errorf("invalid transaction nonce: got %d, want %d", txn.GetNonce(), nonce)
}
Expand Down
5 changes: 1 addition & 4 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ func TestNewSimulatedBackend(t *testing.T) {
}

statedb := sim.stateByBlockNumber(tx, new(big.Int).SetUint64(num+1))
bal, err := statedb.GetBalance(testAddr)
if err != nil {
t.Fatal(err)
}
bal := statedb.GetBalance(testAddr)
if !bal.Eq(expectedBal) {
t.Errorf("expected balance for test address not received. expected: %v actual: %v", expectedBal, bal)
}
Expand Down
1 change: 0 additions & 1 deletion cl/beacon/handler/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (a *ApiHandler) PostEthV1ValidatorSyncCommitteeSubscriptions(w http.Respons
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//cn()
}

// subscribe to subnets
Expand Down
1 change: 1 addition & 0 deletions cl/phase1/forkchoice/on_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (f *ForkChoiceStore) OnAttestation(
return err
}
}

var attestationIndicies []uint64
var err error
target := data.Target
Expand Down
1 change: 1 addition & 0 deletions cl/phase1/forkchoice/on_attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (f *ForkChoiceStore) onProcessAttesterSlashing(attesterSlashing *cltypes.At
if !cltypes.IsSlashableAttestationData(attestation1.Data, attestation2.Data) {
return errors.New("attestation data is not slashable")
}

attestation1PublicKeys, err := getIndexedAttestationPublicKeys(s, attestation1)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cl/phase1/network/services/block_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (b *blockService) ProcessMessage(ctx context.Context, _ *uint64, msg *cltyp
if msg.Block.Body.BlobKzgCommitments.Len() > int(b.beaconCfg.MaxBlobsPerBlock) {
return ErrInvalidCommitmentsCount
}

b.publishBlockGossipEvent(msg)
// the rest of the validation is done in the forkchoice store
if err := b.processAndStoreBlock(ctx, msg); err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func (rw *Worker) ResetTx(chainTx kv.Tx) {

func (rw *Worker) Run() error {
for txTask, ok := rw.in.Next(rw.ctx); ok; txTask, ok = rw.in.Next(rw.ctx) {
//fmt.Println("RTX", txTask.BlockNum, txTask.TxIndex, txTask.TxNum, txTask.Final)
rw.RunTxTask(txTask, rw.isMining)
if err := rw.resultCh.Add(rw.ctx, txTask); err != nil {
return err
Expand Down
9 changes: 3 additions & 6 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,9 @@ type PoW interface {
}

// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db evmtypes.IntraBlockState, sender, recipient libcommon.Address, amount *uint256.Int, bailout bool) error {
func Transfer(db evmtypes.IntraBlockState, sender, recipient libcommon.Address, amount *uint256.Int, bailout bool) {
if !bailout {
err := db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
if err != nil {
return err
}
db.SubBalance(sender, amount, tracing.BalanceChangeTransfer)
}
return db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
db.AddBalance(recipient, amount, tracing.BalanceChangeTransfer)
}
15 changes: 3 additions & 12 deletions consensus/misc/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,15 @@ func VerifyDAOHeaderExtraData(config *chain.Config, header *types.Header) error
// ApplyDAOHardFork modifies the state database according to the DAO hard-fork
// rules, transferring all balances of a set of DAO accounts to a single refund
// contract.
func ApplyDAOHardFork(statedb *state.IntraBlockState) error {
func ApplyDAOHardFork(statedb *state.IntraBlockState) {
// Retrieve the contract to refund balances into
exist, err := statedb.Exist(params.DAORefundContract)
if err != nil {
return err
}
if !exist {
if !statedb.Exist(params.DAORefundContract) {
statedb.CreateAccount(params.DAORefundContract, false)
}

// Move every DAO account and extra-balance account funds into the refund contract
for _, addr := range params.DAODrainList() {
balance, err := statedb.GetBalance(addr)
if err != nil {
return err
}
statedb.AddBalance(params.DAORefundContract, balance, tracing.BalanceIncreaseDaoContract)
statedb.AddBalance(params.DAORefundContract, statedb.GetBalance(addr), tracing.BalanceIncreaseDaoContract)
statedb.SetBalance(addr, new(uint256.Int), tracing.BalanceDecreaseDaoAccount)
}
return nil
}
18 changes: 7 additions & 11 deletions consensus/misc/eip2935.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@ import (
"github.com/erigontech/erigon/params"
)

func StoreBlockHashesEip2935(header *types.Header, state *state.IntraBlockState, config *chain.Config, headerReader consensus.ChainHeaderReader) error {
codeSize, err := state.GetCodeSize(params.HistoryStorageAddress)
if err != nil {
return err
}
if codeSize == 0 {
func StoreBlockHashesEip2935(header *types.Header, state *state.IntraBlockState, config *chain.Config, headerReader consensus.ChainHeaderReader) {
if state.GetCodeSize(params.HistoryStorageAddress) == 0 {
log.Debug("[EIP-2935] No code deployed to HistoryStorageAddress before call to store EIP-2935 history")
return nil
return
}
headerNum := header.Number.Uint64()
if headerNum == 0 { // Activation of fork at Genesis
return nil
return
}
return storeHash(headerNum-1, header.ParentHash, state)
storeHash(headerNum-1, header.ParentHash, state)
}

func storeHash(num uint64, hash libcommon.Hash, state *state.IntraBlockState) error {
func storeHash(num uint64, hash libcommon.Hash, state *state.IntraBlockState) {
slotNum := num % params.BlockHashHistoryServeWindow
storageSlot := libcommon.BytesToHash(uint256.NewInt(slotNum).Bytes())
parentHashInt := uint256.NewInt(0).SetBytes32(hash.Bytes())
return state.SetState(params.HistoryStorageAddress, &storageSlot, *parentHashInt)
state.SetState(params.HistoryStorageAddress, &storageSlot, *parentHashInt)
}
12 changes: 2 additions & 10 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,10 @@ func (b *BlockGen) AddUncheckedReceipt(receipt *types.Receipt) {
// TxNonce returns the next valid transaction nonce for the
// account at addr. It panics if the account does not exist.
func (b *BlockGen) TxNonce(addr libcommon.Address) uint64 {
exist, err := b.ibs.Exist(addr)
if err != nil {
panic(fmt.Sprintf("can't get account: %s", err))
}
if !exist {
if !b.ibs.Exist(addr) {
panic("account does not exist")
}
nonce, err := b.ibs.GetNonce(addr)
if err != nil {
panic(fmt.Sprintf("can't get account: %s", err))
}
return nonce
return b.ibs.GetNonce(addr)
}

// AddUncle adds an uncle header to the generated block.
Expand Down
8 changes: 2 additions & 6 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ func GetHashFn(ref *types.Header, getHeader func(hash libcommon.Hash, number uin

// CanTransfer checks whether there are enough funds in the address' account to make a transfer.
// This does not take the necessary gas in to account to make the transfer valid.
func CanTransfer(db evmtypes.IntraBlockState, addr libcommon.Address, amount *uint256.Int) (bool, error) {
balance, err := db.GetBalance(addr)
if err != nil {
return false, err
}
return !balance.Lt(amount), nil
func CanTransfer(db evmtypes.IntraBlockState, addr libcommon.Address, amount *uint256.Int) bool {
return !db.GetBalance(addr).Lt(amount)
}
6 changes: 2 additions & 4 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ func TestAllocConstructor(t *testing.T) {
reader, err := rpchelper.CreateHistoryStateReader(tx, rawdbv3.TxNums, 1, 0, genSpec.Config.ChainName)
require.NoError(err)
state := state.New(reader)
balance, err := state.GetBalance(address)
assert.NoError(err)
balance := state.GetBalance(address)
assert.Equal(funds, balance.ToBig())
code, err := state.GetCode(address)
assert.NoError(err)
code := state.GetCode(address)
assert.Equal(common.FromHex("5f355f55"), code)

key0 := libcommon.HexToHash("0000000000000000000000000000000000000000000000000000000000000000")
Expand Down
Loading

0 comments on commit 172fba9

Please sign in to comment.