Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5e583be
simulators/ethereum/pyspec: running with EngineAPI.
spencer-tb Feb 23, 2023
2114867
simulators/ethereum/pyspec: Update types file (post-review change).
spencer-tb Feb 24, 2023
e42d8c0
simulators/ethereum/pyspec: Add INVALID/VALID status checks, Dockefil…
spencer-tb Feb 25, 2023
7db8027
simulators/ethereum/pyspec: remove simulator code description
fjl Feb 27, 2023
06f5b54
simulators/ethereum/pyspec: Correctly use gencodec for types (post-re…
spencer-tb Feb 27, 2023
cee1f37
simulators/ethereum/engine: add method to get storage from multiple a…
marioevz Feb 27, 2023
77e0488
simulators/ethereum: workspace
marioevz Feb 27, 2023
e5f2a6f
simulators/ethereum: workspace go.work.sum
marioevz Feb 27, 2023
8416f75
Merge pull request #1 from marioevz/rpc-engine-api-fix
spencer-tb Feb 27, 2023
7f63884
simulators/ethereum/pyspec: update custom hive_rpc function to Storag…
spencer-tb Feb 28, 2023
30ed88c
simulators/ethereum/pyspec: address comments, use StorageAtKeys for b…
spencer-tb Feb 28, 2023
86b8a48
simulators/ethereum/pyspec: add option to exclude or run specific tes…
spencer-tb Feb 28, 2023
f87efa3
simulators/ethereum/pyspec: remove go work files in ethereum/*.
spencer-tb Feb 28, 2023
5bdc185
simulators/ethereum/pyspec: re-add go work files in ethereum/* with a…
spencer-tb Feb 28, 2023
e36b0d8
simulators/ethereum/pyspec: get --sim-limit working within simulator.
spencer-tb Feb 28, 2023
b4f3f08
simulators/ethereum/pyspec: testname update, working on geth, erigon,…
spencer-tb Mar 1, 2023
931b1e8
small tweak to fixture names, failed tests are output at the end of s…
spencer-tb Mar 6, 2023
bcee88d
Address comments for types.go, add all fields for transactions.
spencer-tb Mar 15, 2023
286c3b3
.
spencer-tb Mar 15, 2023
200d6f9
Fix for transaction marshalling.
spencer-tb Mar 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions simulators/ethereum/engine/client/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Eth interface {
SendTransaction(ctx context.Context, tx *types.Transaction) error
SendTransactions(ctx context.Context, txs []*types.Transaction) []error
StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
StorageAtKeys(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) (map[common.Hash]*common.Hash, error)
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
Expand Down
35 changes: 35 additions & 0 deletions simulators/ethereum/engine/client/hive_rpc/hive_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethereum/hive/simulators/ethereum/engine/globals"
"github.com/ethereum/hive/simulators/ethereum/engine/helper"
"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"
)

type HiveRPCEngineStarter struct {
Expand Down Expand Up @@ -228,6 +229,40 @@ func toBlockNumArg(number *big.Int) string {
return hexutil.EncodeBig(number)
}

func (ec *HiveRPCEngineClient) StorageAtKeys(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) (map[common.Hash]*common.Hash, error) {
reqs := make([]rpc.BatchElem, 0, len(keys))
results := make(map[common.Hash]*common.Hash, len(keys))
var blockNumberString string
if blockNumber == nil {
blockNumberString = "latest"
} else {
blockNumberString = hexutil.EncodeBig(blockNumber)
}
for _, key := range keys {
valueResult := &common.Hash{}
reqs = append(reqs, rpc.BatchElem{
Method: "eth_getStorageAt",
Args: []interface{}{account, key, blockNumberString},
Result: valueResult,
})
results[key] = valueResult
}

if err := ec.PrepareDefaultAuthCallToken(); err != nil {
return nil, err
}
if err := ec.c.BatchCallContext(ctx, reqs); err != nil {
return nil, err
}
for i, req := range reqs {
if req.Error != nil {
return nil, errors.Wrap(req.Error, fmt.Sprintf("request for storage at index %d failed", i))
}
}

return results, nil
}

func (ec *HiveRPCEngineClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
var header *types.Header
err := ec.cEth.CallContext(ctx, &header, "eth_getBlockByNumber", toBlockNumArg(number), false)
Expand Down
4 changes: 4 additions & 0 deletions simulators/ethereum/engine/client/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ func (n *GethNode) StorageAt(ctx context.Context, account common.Address, key co
return stateDB.GetState(account, key).Bytes(), nil
}

func (n *GethNode) StorageAtKeys(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) (map[common.Hash]*common.Hash, error) {
return nil, fmt.Errorf("StorageAtKeys not implemented")
}

func (n *GethNode) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
return nil, fmt.Errorf("TransactionReceipt not implemented")
}
Expand Down
2 changes: 1 addition & 1 deletion simulators/ethereum/engine/client/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ func (edv1 *ExecutableDataV1) FromExecutableData(ed *beacon.ExecutableData) {
edv1.BaseFeePerGas = ed.BaseFeePerGas
edv1.BlockHash = ed.BlockHash
edv1.Transactions = ed.Transactions
}
}
11 changes: 11 additions & 0 deletions simulators/ethereum/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
go 1.19

use (
./consensus
./engine
./graphql
./pyspec
./rpc
./rpc-compat
./sync
)
938 changes: 938 additions & 0 deletions simulators/ethereum/go.work.sum

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions simulators/ethereum/pyspec/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ---------------------------------------------------------------#
# This simulation runs the Ethereum python execution-spec-tests. #
# ---------------------------------------------------------------#

# 1) Create pyspec builder container.
FROM golang:1-alpine as builder
RUN apk add --update git ca-certificates gcc musl-dev linux-headers

# Build the pyspec simulator executable.
ADD . /source
WORKDIR /source/pyspec
RUN go build -v .

# 2) Create the simulator container.
FROM alpine:latest as simulator
RUN apk add --update wget
ADD ./pyspec /pyspec
WORKDIR /pyspec
COPY --from=builder /source/pyspec/pyspec .

# Download the latest fixture release.
RUN wget https://github.com/ethereum/execution-spec-tests/releases/latest/download/fixtures.tar.gz

# Extract the latest fixtures.
RUN tar -xzvf fixtures.tar.gz
RUN mv fixtures /fixtures

# Point to executable and test fixtures.
ENV TESTPATH /fixtures
ENTRYPOINT ["./pyspec"]
40 changes: 40 additions & 0 deletions simulators/ethereum/pyspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Hive Pyspec

This is a `simulator` for running the python [execution-spec-tests](https://github.com/ethereum/execution-spec-tests) within [`hive`](https://github.com/ethereum/hive), based on the `consensus` simulator. It differs mostly by using the `Engine API` to feed blocks into clients.

The simulator is only valid for post `Merge` forks (>= `Merge`).

It can be run from the `hive` root directory simply:
```sh
./hive --client go-ethereum --sim ethereum/pyspec
```

The `pyspec simulator` uses the latest test fixtures from the
most recent execution-spec-tests [release](https://github.com/ethereum/execution-spec-tests/releases).


### Running Specific Test Fixtures

By default all test fixtures will run. To run a specific test or set of test fixtures the regex `--sim-limit /<pattern>` option can be used.

This can utilised in `pyspec` for running tests exclusive to a specific fork. The pattern must match at least one hive simulation test name within the `pyspec` suite.

Test names are of the type `<path-to-json>_<fixture-name>` omiting `fixtures` from the path. For example, the fixture test `000_push0_key_sstore_shanghai` within `push0.json` will have a hive test name of: `eips_eip3855_000_push0_key_sstore_shanghai`.

1) To run only this test, an example pattern could be:
- `./hive --sim ethereum/pyspec --sim.limit /0_push0_key_sstore`

2) To run every withdrawals test in the suite:
- `./hive --sim ethereum/pyspec --sim.limit /withdrawals`

3) To run only tests exclusive to the `Shanghai` fork:
- `./hive --sim ethereum/pyspec --sim.limit /shanghai`

For a better understand of how to utilise the regex pattern please browse the folder structure of the latest fixture [release](https://github.com/ethereum/execution-spec-tests/releases).


### Excluding Test Fixtures

To exclude a file or set of files, partial paths can be added to `excludePaths := []string{"example/"}` within \
the first code section of `runner.go/LoadFixtureTests()`. By default we exclude all files within the path `fixtures/example/example/*`.

45 changes: 45 additions & 0 deletions simulators/ethereum/pyspec/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

var envForks = map[string]map[string]int{
"Merge": {
"HIVE_FORK_HOMESTEAD": 0,
"HIVE_FORK_TANGERINE": 0,
"HIVE_FORK_SPURIOUS": 0,
"HIVE_FORK_BYZANTIUM": 0,
"HIVE_FORK_CONSTANTINOPLE": 0,
"HIVE_FORK_PETERSBURG": 0,
"HIVE_FORK_ISTANBUL": 0,
"HIVE_FORK_BERLIN": 0,
"HIVE_FORK_LONDON": 0,
"HIVE_FORK_MERGE": 0,
"HIVE_TERMINAL_TOTAL_DIFFICULTY": 0,
},
"Shanghai": {
"HIVE_FORK_HOMESTEAD": 0,
"HIVE_FORK_TANGERINE": 0,
"HIVE_FORK_SPURIOUS": 0,
"HIVE_FORK_BYZANTIUM": 0,
"HIVE_FORK_CONSTANTINOPLE": 0,
"HIVE_FORK_PETERSBURG": 0,
"HIVE_FORK_ISTANBUL": 0,
"HIVE_FORK_BERLIN": 0,
"HIVE_FORK_LONDON": 0,
"HIVE_FORK_MERGE": 0,
"HIVE_TERMINAL_TOTAL_DIFFICULTY": 0,
"HIVE_SHANGHAI_TIMESTAMP": 0,
},
"MergeToShanghaiAtTime15k": {
"HIVE_FORK_HOMESTEAD": 0,
"HIVE_FORK_TANGERINE": 0,
"HIVE_FORK_SPURIOUS": 0,
"HIVE_FORK_BYZANTIUM": 0,
"HIVE_FORK_CONSTANTINOPLE": 0,
"HIVE_FORK_PETERSBURG": 0,
"HIVE_FORK_ISTANBUL": 0,
"HIVE_FORK_BERLIN": 0,
"HIVE_FORK_LONDON": 0,
"HIVE_FORK_MERGE": 0,
"HIVE_TERMINAL_TOTAL_DIFFICULTY": 0,
"HIVE_SHANGHAI_TIMESTAMP": 15000,
},
}
160 changes: 160 additions & 0 deletions simulators/ethereum/pyspec/gen_bh.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading