From 2aa85a2257d1e6fc2ae583a2bf9fad6a33796727 Mon Sep 17 00:00:00 2001 From: Spencer Taylor-Brown Date: Wed, 20 Sep 2023 19:17:20 +0000 Subject: [PATCH] simulators/ethereum/pyspec: Refactor to use new fixture format. --- simulators/ethereum/pyspec/gen_bh.go | 160 -------------------------- simulators/ethereum/pyspec/gen_gb.go | 100 ++++++++++++++++ simulators/ethereum/pyspec/gen_txs.go | 130 --------------------- simulators/ethereum/pyspec/gen_wds.go | 55 --------- simulators/ethereum/pyspec/runner.go | 70 ++++++----- simulators/ethereum/pyspec/types.go | 128 ++++++--------------- 6 files changed, 166 insertions(+), 477 deletions(-) delete mode 100644 simulators/ethereum/pyspec/gen_bh.go create mode 100644 simulators/ethereum/pyspec/gen_gb.go delete mode 100644 simulators/ethereum/pyspec/gen_txs.go delete mode 100644 simulators/ethereum/pyspec/gen_wds.go diff --git a/simulators/ethereum/pyspec/gen_bh.go b/simulators/ethereum/pyspec/gen_bh.go deleted file mode 100644 index f6152712f5..0000000000 --- a/simulators/ethereum/pyspec/gen_bh.go +++ /dev/null @@ -1,160 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -import ( - "encoding/json" - "math/big" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/core/types" -) - -var _ = (*blockHeaderUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (b blockHeader) MarshalJSON() ([]byte, error) { - type blockHeader struct { - ParentHash common.Hash `json:"parentHash"` - UncleHash common.Hash `json:"uncleHash"` - Coinbase common.Address `json:"coinbase"` - StateRoot common.Hash `json:"stateRoot"` - TransactionTrie common.Hash `json:"transactionTrie"` - ReceiptTrie common.Hash `json:"receiptTrie"` - Bloom types.Bloom `json:"bloom"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` - GasLimit math.HexOrDecimal64 `json:"gasLimit"` - GasUsed math.HexOrDecimal64 `json:"gasUsed"` - Timestamp *math.HexOrDecimal256 `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extraData"` - MixHash common.Hash `json:"mixHash"` - Nonce types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - WithdrawalsRoot common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` - Hash common.Hash `json:"hash"` - } - var enc blockHeader - enc.ParentHash = b.ParentHash - enc.UncleHash = b.UncleHash - enc.Coinbase = b.Coinbase - enc.StateRoot = b.StateRoot - enc.TransactionTrie = b.TransactionTrie - enc.ReceiptTrie = b.ReceiptTrie - enc.Bloom = b.Bloom - enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty) - enc.Number = (*math.HexOrDecimal256)(b.Number) - enc.GasLimit = math.HexOrDecimal64(b.GasLimit) - enc.GasUsed = math.HexOrDecimal64(b.GasUsed) - enc.Timestamp = (*math.HexOrDecimal256)(b.Timestamp) - enc.ExtraData = b.ExtraData - enc.MixHash = b.MixHash - enc.Nonce = b.Nonce - enc.BaseFee = (*math.HexOrDecimal256)(b.BaseFee) - enc.WithdrawalsRoot = b.WithdrawalsRoot - enc.BlobGasUsed = (*math.HexOrDecimal64)(b.BlobGasUsed) - enc.ExcessBlobGas = (*math.HexOrDecimal64)(b.ExcessBlobGas) - enc.BeaconRoot = b.BeaconRoot - enc.Hash = b.Hash - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (b *blockHeader) UnmarshalJSON(input []byte) error { - type blockHeader struct { - ParentHash *common.Hash `json:"parentHash"` - UncleHash *common.Hash `json:"uncleHash"` - Coinbase *common.Address `json:"coinbase"` - StateRoot *common.Hash `json:"stateRoot"` - TransactionTrie *common.Hash `json:"transactionTrie"` - ReceiptTrie *common.Hash `json:"receiptTrie"` - Bloom *types.Bloom `json:"bloom"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` - GasLimit *math.HexOrDecimal64 `json:"gasLimit"` - GasUsed *math.HexOrDecimal64 `json:"gasUsed"` - Timestamp *math.HexOrDecimal256 `json:"timestamp"` - ExtraData *hexutil.Bytes `json:"extraData"` - MixHash *common.Hash `json:"mixHash"` - Nonce *types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - WithdrawalsRoot *common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` - Hash *common.Hash `json:"hash"` - } - var dec blockHeader - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.ParentHash != nil { - b.ParentHash = *dec.ParentHash - } - if dec.UncleHash != nil { - b.UncleHash = *dec.UncleHash - } - if dec.Coinbase != nil { - b.Coinbase = *dec.Coinbase - } - if dec.StateRoot != nil { - b.StateRoot = *dec.StateRoot - } - if dec.TransactionTrie != nil { - b.TransactionTrie = *dec.TransactionTrie - } - if dec.ReceiptTrie != nil { - b.ReceiptTrie = *dec.ReceiptTrie - } - if dec.Bloom != nil { - b.Bloom = *dec.Bloom - } - if dec.Difficulty != nil { - b.Difficulty = (*big.Int)(dec.Difficulty) - } - if dec.Number != nil { - b.Number = (*big.Int)(dec.Number) - } - if dec.GasLimit != nil { - b.GasLimit = uint64(*dec.GasLimit) - } - if dec.GasUsed != nil { - b.GasUsed = uint64(*dec.GasUsed) - } - if dec.Timestamp != nil { - b.Timestamp = (*big.Int)(dec.Timestamp) - } - if dec.ExtraData != nil { - b.ExtraData = *dec.ExtraData - } - if dec.MixHash != nil { - b.MixHash = *dec.MixHash - } - if dec.Nonce != nil { - b.Nonce = *dec.Nonce - } - if dec.BaseFee != nil { - b.BaseFee = (*big.Int)(dec.BaseFee) - } - if dec.WithdrawalsRoot != nil { - b.WithdrawalsRoot = *dec.WithdrawalsRoot - } - if dec.BlobGasUsed != nil { - b.BlobGasUsed = (*uint64)(dec.BlobGasUsed) - } - if dec.ExcessBlobGas != nil { - b.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) - } - if dec.BeaconRoot != nil { - b.BeaconRoot = dec.BeaconRoot - } - if dec.Hash != nil { - b.Hash = *dec.Hash - } - return nil -} diff --git a/simulators/ethereum/pyspec/gen_gb.go b/simulators/ethereum/pyspec/gen_gb.go new file mode 100644 index 0000000000..09b9e4bea6 --- /dev/null +++ b/simulators/ethereum/pyspec/gen_gb.go @@ -0,0 +1,100 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package main + +import ( + "encoding/json" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/core/types" +) + +var _ = (*genesisBlockUnmarshaling)(nil) + +// MarshalJSON marshals as JSON. +func (g genesisBlock) MarshalJSON() ([]byte, error) { + type genesisBlock struct { + Coinbase common.Address `json:"coinbase"` + Difficulty *math.HexOrDecimal256 `json:"difficulty"` + GasLimit math.HexOrDecimal64 `json:"gasLimit"` + Timestamp *math.HexOrDecimal256 `json:"timestamp"` + ExtraData hexutil.Bytes `json:"extraData"` + MixHash common.Hash `json:"mixHash"` + Nonce types.BlockNonce `json:"nonce"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + Hash common.Hash `json:"hash"` + } + var enc genesisBlock + enc.Coinbase = g.Coinbase + enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) + enc.GasLimit = math.HexOrDecimal64(g.GasLimit) + enc.Timestamp = (*math.HexOrDecimal256)(g.Timestamp) + enc.ExtraData = g.ExtraData + enc.MixHash = g.MixHash + enc.Nonce = g.Nonce + enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee) + enc.BlobGasUsed = (*math.HexOrDecimal64)(g.BlobGasUsed) + enc.ExcessBlobGas = (*math.HexOrDecimal64)(g.ExcessBlobGas) + enc.Hash = g.Hash + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (g *genesisBlock) UnmarshalJSON(input []byte) error { + type genesisBlock struct { + Coinbase *common.Address `json:"coinbase"` + Difficulty *math.HexOrDecimal256 `json:"difficulty"` + GasLimit *math.HexOrDecimal64 `json:"gasLimit"` + Timestamp *math.HexOrDecimal256 `json:"timestamp"` + ExtraData *hexutil.Bytes `json:"extraData"` + MixHash *common.Hash `json:"mixHash"` + Nonce *types.BlockNonce `json:"nonce"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + Hash *common.Hash `json:"hash"` + } + var dec genesisBlock + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.Coinbase != nil { + g.Coinbase = *dec.Coinbase + } + if dec.Difficulty != nil { + g.Difficulty = (*big.Int)(dec.Difficulty) + } + if dec.GasLimit != nil { + g.GasLimit = uint64(*dec.GasLimit) + } + if dec.Timestamp != nil { + g.Timestamp = (*big.Int)(dec.Timestamp) + } + if dec.ExtraData != nil { + g.ExtraData = *dec.ExtraData + } + if dec.MixHash != nil { + g.MixHash = *dec.MixHash + } + if dec.Nonce != nil { + g.Nonce = *dec.Nonce + } + if dec.BaseFee != nil { + g.BaseFee = (*big.Int)(dec.BaseFee) + } + if dec.BlobGasUsed != nil { + g.BlobGasUsed = (*uint64)(dec.BlobGasUsed) + } + if dec.ExcessBlobGas != nil { + g.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) + } + if dec.Hash != nil { + g.Hash = *dec.Hash + } + return nil +} diff --git a/simulators/ethereum/pyspec/gen_txs.go b/simulators/ethereum/pyspec/gen_txs.go deleted file mode 100644 index db7278dd30..0000000000 --- a/simulators/ethereum/pyspec/gen_txs.go +++ /dev/null @@ -1,130 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -import ( - "encoding/json" - "math/big" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/common/math" - "github.com/ethereum/go-ethereum/core/types" -) - -var _ = (*transactionUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (t transaction) MarshalJSON() ([]byte, error) { - type transaction struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce math.HexOrDecimal64 `json:"nonce"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - To string `json:"to"` - Gas math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input hexutil.Bytes `json:"data"` - AccessList *types.AccessList `json:"accessList"` - MaxFeePerBlobGas *math.HexOrDecimal256 `json:"maxFeePerBlobGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` - Sender common.Address `json:"sender"` - } - var enc transaction - enc.Type = (*math.HexOrDecimal64)(t.Type) - enc.ChainId = (*math.HexOrDecimal256)(t.ChainId) - enc.Nonce = math.HexOrDecimal64(t.Nonce) - enc.MaxPriorityFeePerGas = (*math.HexOrDecimal256)(t.MaxPriorityFeePerGas) - enc.MaxFeePerGas = (*math.HexOrDecimal256)(t.MaxFeePerGas) - enc.To = t.To - enc.Gas = math.HexOrDecimal64(t.Gas) - enc.Value = (*math.HexOrDecimal256)(t.Value) - enc.Input = t.Input - enc.AccessList = t.AccessList - enc.MaxFeePerBlobGas = (*math.HexOrDecimal256)(t.MaxFeePerBlobGas) - enc.BlobVersionedHashes = t.BlobVersionedHashes - enc.V = (*math.HexOrDecimal256)(t.V) - enc.R = (*math.HexOrDecimal256)(t.R) - enc.S = (*math.HexOrDecimal256)(t.S) - enc.Sender = t.Sender - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (t *transaction) UnmarshalJSON(input []byte) error { - type transaction struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce *math.HexOrDecimal64 `json:"nonce"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - To *string `json:"to"` - Gas *math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input *hexutil.Bytes `json:"data"` - AccessList *types.AccessList `json:"accessList"` - MaxFeePerBlobGas *math.HexOrDecimal256 `json:"maxFeePerBlobGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` - Sender *common.Address `json:"sender"` - } - var dec transaction - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Type != nil { - t.Type = (*uint64)(dec.Type) - } - if dec.ChainId != nil { - t.ChainId = (*big.Int)(dec.ChainId) - } - if dec.Nonce != nil { - t.Nonce = uint64(*dec.Nonce) - } - if dec.MaxPriorityFeePerGas != nil { - t.MaxPriorityFeePerGas = (*big.Int)(dec.MaxPriorityFeePerGas) - } - if dec.MaxFeePerGas != nil { - t.MaxFeePerGas = (*big.Int)(dec.MaxFeePerGas) - } - if dec.To != nil { - t.To = *dec.To - } - if dec.Gas != nil { - t.Gas = uint64(*dec.Gas) - } - if dec.Value != nil { - t.Value = (*big.Int)(dec.Value) - } - if dec.Input != nil { - t.Input = *dec.Input - } - if dec.AccessList != nil { - t.AccessList = dec.AccessList - } - if dec.MaxFeePerBlobGas != nil { - t.MaxFeePerBlobGas = (*big.Int)(dec.MaxFeePerBlobGas) - } - if dec.BlobVersionedHashes != nil { - t.BlobVersionedHashes = dec.BlobVersionedHashes - } - if dec.V != nil { - t.V = (*big.Int)(dec.V) - } - if dec.R != nil { - t.R = (*big.Int)(dec.R) - } - if dec.S != nil { - t.S = (*big.Int)(dec.S) - } - if dec.Sender != nil { - t.Sender = *dec.Sender - } - return nil -} diff --git a/simulators/ethereum/pyspec/gen_wds.go b/simulators/ethereum/pyspec/gen_wds.go deleted file mode 100644 index 44bbf8084f..0000000000 --- a/simulators/ethereum/pyspec/gen_wds.go +++ /dev/null @@ -1,55 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -import ( - "encoding/json" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" -) - -var _ = (*withdrawalsUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (w withdrawals) MarshalJSON() ([]byte, error) { - type withdrawals struct { - Index math.HexOrDecimal64 `json:"index"` - ValidatorIndex math.HexOrDecimal64 `json:"validatorIndex"` - Address common.Address `json:"address"` - Amount math.HexOrDecimal64 `json:"amount"` - } - var enc withdrawals - enc.Index = math.HexOrDecimal64(w.Index) - enc.ValidatorIndex = math.HexOrDecimal64(w.ValidatorIndex) - enc.Address = w.Address - enc.Amount = math.HexOrDecimal64(w.Amount) - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (w *withdrawals) UnmarshalJSON(input []byte) error { - type withdrawals struct { - Index *math.HexOrDecimal64 `json:"index"` - ValidatorIndex *math.HexOrDecimal64 `json:"validatorIndex"` - Address *common.Address `json:"address"` - Amount *math.HexOrDecimal64 `json:"amount"` - } - var dec withdrawals - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Index != nil { - w.Index = uint64(*dec.Index) - } - if dec.ValidatorIndex != nil { - w.ValidatorIndex = uint64(*dec.ValidatorIndex) - } - if dec.Address != nil { - w.Address = *dec.Address - } - if dec.Amount != nil { - w.Amount = uint64(*dec.Amount) - } - return nil -} diff --git a/simulators/ethereum/pyspec/runner.go b/simulators/ethereum/pyspec/runner.go index bf0373d166..82e916441f 100644 --- a/simulators/ethereum/pyspec/runner.go +++ b/simulators/ethereum/pyspec/runner.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "context" "errors" "fmt" @@ -20,6 +19,8 @@ import ( "github.com/ethereum/hive/hivesim" "github.com/ethereum/hive/simulators/ethereum/engine/client/hive_rpc" "github.com/ethereum/hive/simulators/ethereum/engine/globals" + + typ "github.com/ethereum/hive/simulators/ethereum/engine/types" ) // loadFixtureTests extracts tests from fixture.json files in a given directory, @@ -123,27 +124,21 @@ func (tc *testcase) run(t *hivesim.T) { // send payloads and check response latestValidHash := common.Hash{} - for i, engineNewPayload := range tc.payloads { - // execute fixture block payload - ed, err := engineNewPayload.ToExecutableData() - if err != nil { - tc.failedErr = err - t.Fatalf("unable to convert engineNewPayload to executableData: %v", err) - } + for _, engineNewPayload := range tc.engineNewPayloads { plStatus, plErr := engineClient.NewPayload( context.Background(), int(engineNewPayload.Version), - ed, + engineNewPayload.HiveExecutionPayload, ) // check for rpc errors and compare error codes - fxErrCode := int(tc.fixture.json.Blocks[i].EngineNewPayload.ErrorCode) - if fxErrCode != 0 { - checkRPCErrors(plErr, fxErrCode, t, tc) + errCode := int(engineNewPayload.ErrorCode) + if errCode != 0 { + checkRPCErrors(plErr, errCode, t, tc) continue } // set expected payload return status expectedStatus := "VALID" - if tc.fixture.json.Blocks[i].Exception != "" { + if errCode != 0 { expectedStatus = "INVALID" } // check payload status matches expected @@ -211,8 +206,7 @@ func (tc *testcase) run(t *hivesim.T) { for _, key := range keys { if genesisAccount.Storage[key] != *gotStorage[key] { tc.failedErr = errors.New("storage recieved doesn't match expected from fixture") - t.Errorf(`storage recieved from account %v doesn't match expected from fixture in test %s: - from storage address: %v + t.Errorf(`storage recieved from account %v doesn't match expected from fixture in test %s: from storage address: %v recieved from block: %v expected in fixture: %v`, account, tc.name, key, gotStorage[key], genesisAccount.Storage[key]) } @@ -244,33 +238,19 @@ func (tc *testcase) updateEnv(env hivesim.Params) { // extractFixtureFields extracts the genesis, post allocation and payload // fields from the given fixture test and stores them in the testcase struct. -func (tc *testcase) extractFixtureFields(fixture fixtureJSON) error { - var err error - tc.genesis, err = extractGenesis(fixture) - if err != nil { - return err +func (tc *testcase) extractFixtureFields(fixture fixtureJSON) (err error) { + if tc.genesis, err = extractGenesis(fixture); err != nil { + return fmt.Errorf("failed to extract genesis: %w", err) } - tc.postAlloc = &fixture.Post - var engineNewPayloads []*engineNewPayload - for _, bl := range fixture.Blocks { - if bl.EngineNewPayload == nil { - return errors.New("engineNewPayload is nil") - } - engineNewPayloads = append(engineNewPayloads, bl.EngineNewPayload) + if tc.engineNewPayloads, err = extractEngineNewPayloads(fixture); err != nil { + return fmt.Errorf("failed to extract engineNewPayloads: %w", err) } - tc.payloads = engineNewPayloads + tc.postAlloc = &fixture.Post return nil } -// extractGenesis extracts the genesis block information from the given fixture -// and returns a core.Genesis struct containing the extracted information. +// extracts the genesis block information from the given fixture. func extractGenesis(fixture fixtureJSON) (*core.Genesis, error) { - if fixture.Genesis.BeaconRoot != nil { - emptyHash := common.Hash{} - if !bytes.Equal(fixture.Genesis.BeaconRoot[:], emptyHash[:]) { - return nil, errors.New("beacon root in genesis is not empty") - } - } genesis := &core.Genesis{ Config: tests.Forks[fixture.Fork], Coinbase: fixture.Genesis.Coinbase, @@ -288,7 +268,23 @@ func extractGenesis(fixture fixtureJSON) (*core.Genesis, error) { return genesis, nil } -// checkRPCErrors checks for RPC errors and compares error codes if expected. +// extracts all the engineNewPayload information from the given fixture. +func extractEngineNewPayloads(fixture fixtureJSON) ([]engineNewPayload, error) { + var engineNewPayloads []engineNewPayload + for _, engineNewPayload := range fixture.EngineNewPayloads { + hiveExecutionPayload, err := typ.FromBeaconExecutableData(engineNewPayload.ExecutionPayload) + if err != nil { + return nil, errors.New("executionPayload param within engineNewPayload is invalid") + } + hiveExecutionPayload.VersionedHashes = &engineNewPayload.BlobVersionedHashes + hiveExecutionPayload.ParentBeaconBlockRoot = engineNewPayload.ParentBeaconBlockRoot + engineNewPayload.HiveExecutionPayload = &hiveExecutionPayload + engineNewPayloads = append(engineNewPayloads, engineNewPayload) + } + return engineNewPayloads, nil +} + +// checks for RPC errors and compares error codes if expected. func checkRPCErrors(plErr error, fxErrCode int, t *hivesim.T, tc *testcase) { rpcErr, isRpcErr := plErr.(rpc.Error) if isRpcErr { diff --git a/simulators/ethereum/pyspec/types.go b/simulators/ethereum/pyspec/types.go index ccb84587a1..62ac62155f 100644 --- a/simulators/ethereum/pyspec/types.go +++ b/simulators/ethereum/pyspec/types.go @@ -4,11 +4,14 @@ import ( "encoding/json" "math/big" + api "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + + typ "github.com/ethereum/hive/simulators/ethereum/engine/types" ) type testcase struct { @@ -18,10 +21,10 @@ type testcase struct { clientType string failedErr error // test fixture data - fixture fixtureTest - genesis *core.Genesis - postAlloc *core.GenesisAlloc - payloads []*engineNewPayload + fixture fixtureTest + genesis *core.Genesis + postAlloc *core.GenesisAlloc + engineNewPayloads []engineNewPayload } type fixtureTest struct { @@ -35,57 +38,34 @@ func (t *fixtureTest) UnmarshalJSON(in []byte) error { return nil } -//go:generate go run github.com/fjl/gencodec -type blockHeader -field-override blockHeaderUnmarshaling -out gen_bh.go -//go:generate go run github.com/fjl/gencodec -type transaction -field-override transactionUnmarshaling -out gen_txs.go -//go:generate go run github.com/fjl/gencodec -type withdrawals -field-override withdrawalsUnmarshaling -out gen_wds.go type fixtureJSON struct { - Blocks []block `json:"blocks"` - Genesis blockHeader `json:"genesisBlockHeader"` - Pre core.GenesisAlloc `json:"pre"` - Post core.GenesisAlloc `json:"postState"` - Fork string `json:"network"` - EngineFcuVersion math.HexOrDecimal64 `json:"engineFcuVersion"` + Fork string `json:"network"` + Genesis genesisBlock `json:"genesisBlockHeader"` + EngineNewPayloads []engineNewPayload `json:"engineNewPayloads"` + EngineFcuVersion math.HexOrDecimal64 `json:"engineFcuVersion"` + Pre core.GenesisAlloc `json:"pre"` + Post core.GenesisAlloc `json:"postState"` } -type block struct { - Rlp string `json:"rlp"` - BlockHeader *blockHeader `json:"blockHeader"` - Transactions []transaction `json:"transactions"` - UncleHeaders []byte `json:"uncleHeaders"` - Withdrawals []withdrawals `json:"withdrawals"` - Exception string `json:"expectException"` - EngineNewPayload *engineNewPayload `json:"engineNewPayload"` -} +//go:generate go run github.com/fjl/gencodec -type genesisBlock -field-override genesisBlockUnmarshaling -out gen_gb.go +type genesisBlock struct { + Coinbase common.Address `json:"coinbase"` + Difficulty *big.Int `json:"difficulty"` + GasLimit uint64 `json:"gasLimit"` + Timestamp *big.Int `json:"timestamp"` + ExtraData []byte `json:"extraData"` + MixHash common.Hash `json:"mixHash"` + Nonce types.BlockNonce `json:"nonce"` + BaseFee *big.Int `json:"baseFeePerGas"` + BlobGasUsed *uint64 `json:"blobGasUsed"` + ExcessBlobGas *uint64 `json:"excessBlobGas"` -type blockHeader struct { - ParentHash common.Hash `json:"parentHash"` - UncleHash common.Hash `json:"uncleHash"` - Coinbase common.Address `json:"coinbase"` - StateRoot common.Hash `json:"stateRoot"` - TransactionTrie common.Hash `json:"transactionTrie"` - ReceiptTrie common.Hash `json:"receiptTrie"` - Bloom types.Bloom `json:"bloom"` - Difficulty *big.Int `json:"difficulty"` - Number *big.Int `json:"number"` - GasLimit uint64 `json:"gasLimit"` - GasUsed uint64 `json:"gasUsed"` - Timestamp *big.Int `json:"timestamp"` - ExtraData []byte `json:"extraData"` - MixHash common.Hash `json:"mixHash"` - Nonce types.BlockNonce `json:"nonce"` - BaseFee *big.Int `json:"baseFeePerGas"` - WithdrawalsRoot common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *uint64 `json:"blobGasUsed"` - ExcessBlobGas *uint64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` - Hash common.Hash `json:"hash"` + Hash common.Hash `json:"hash"` } -type blockHeaderUnmarshaling struct { +type genesisBlockUnmarshaling struct { Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` GasLimit math.HexOrDecimal64 `json:"gasLimit"` - GasUsed math.HexOrDecimal64 `json:"gasUsed"` Timestamp *math.HexOrDecimal256 `json:"timestamp"` ExtraData hexutil.Bytes `json:"extraData"` BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` @@ -93,57 +73,15 @@ type blockHeaderUnmarshaling struct { ExcessBlobGas *math.HexOrDecimal64 `json:"excessDataGas"` } -type transaction struct { - Type *uint64 `json:"type"` - ChainId *big.Int `json:"chainId"` - Nonce uint64 `json:"nonce"` - MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"` - MaxFeePerGas *big.Int `json:"maxFeePerGas"` - To string `json:"to"` - Gas uint64 `json:"gasLimit"` - Value *big.Int `json:"value"` - Input []byte `json:"data"` - AccessList *types.AccessList `json:"accessList"` - MaxFeePerBlobGas *big.Int `json:"maxFeePerBlobGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` - V *big.Int `json:"v"` - R *big.Int `json:"r"` - S *big.Int `json:"s"` - Sender common.Address `json:"sender"` -} - -type transactionUnmarshaling struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce math.HexOrDecimal64 `json:"nonce"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - Gas math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input hexutil.Bytes `json:"data"` - MaxFeePerBlobGas *math.HexOrDecimal256 `json:"maxFeePerBlobGas"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` -} - -type withdrawals struct { - Index uint64 `json:"index"` - ValidatorIndex uint64 `json:"validatorIndex"` - Address common.Address `json:"address"` - Amount uint64 `json:"amount"` -} - -type withdrawalsUnmarshaling struct { - Index math.HexOrDecimal64 `json:"index"` - ValidatorIndex math.HexOrDecimal64 `json:"validatorIndex"` - Amount math.HexOrDecimal64 `json:"amount"` -} - type engineNewPayload struct { - Payload interface{} `json:"executionPayload"` + ExecutionPayload *api.ExecutableData `json:"executionPayload"` BlobVersionedHashes []common.Hash `json:"expectedBlobVersionedHashes"` ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` Version math.HexOrDecimal64 `json:"version"` ErrorCode int64 `json:"errorCode,string"` + + HiveExecutionPayload *typ.ExecutableData +} +type engineNewPayloadUnmarshaling struct { + Version math.HexOrDecimal64 `json:"version"` }