From 91858a3d68dd5ed6645a724babeb0dbe09939e6d Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Thu, 8 Feb 2024 15:06:51 +0000 Subject: [PATCH 1/5] feat(fw): add optional `verify_sync` flag to hive blockchain tests --- .../spec/blockchain/blockchain_test.py | 11 +++++++++++ src/ethereum_test_tools/spec/blockchain/types.py | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py index ddda651e27f..08b249101bb 100644 --- a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py +++ b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py @@ -101,6 +101,7 @@ class BlockchainTest(BaseTest): post: Mapping blocks: List[Block] genesis_environment: Environment = field(default_factory=Environment) + verify_sync: Optional[bool] = None tag: str = "" chain_id: int = 1 @@ -393,6 +394,7 @@ def make_hive_fixture( pre, _, genesis = self.make_genesis(t8n, fork) alloc = to_json(pre) env = environment_from_parent_header(genesis) + head_hash = genesis.hash for block in self.blocks: header, _, txs, new_alloc, new_env = self.generate_block_data( @@ -412,6 +414,7 @@ def make_hive_fixture( if block.exception is None: alloc = new_alloc env = apply_new_parent(env, header) + head_hash = header.hash fcu_version = fork.engine_forkchoice_updated_version(header.number, header.timestamp) assert ( fcu_version is not None @@ -419,6 +422,13 @@ def make_hive_fixture( " never try to execute this test case." self.verify_post_state(t8n, alloc) + + if self.verify_sync: + # Test is marked for syncing verification. + assert ( + genesis.hash != head_hash + ), "Invalid payload tests negative test via sync is not supported yet." + return HiveFixture( fork=self.network_info(fork, eips), genesis=genesis, @@ -426,6 +436,7 @@ def make_hive_fixture( fcu_version=fcu_version, pre_state=pre, post_state=alloc_to_accounts(alloc), + verify_sync=self.verify_sync, name=self.tag, ) diff --git a/src/ethereum_test_tools/spec/blockchain/types.py b/src/ethereum_test_tools/spec/blockchain/types.py index 958adad6919..31dd864bb3d 100644 --- a/src/ethereum_test_tools/spec/blockchain/types.py +++ b/src/ethereum_test_tools/spec/blockchain/types.py @@ -1122,6 +1122,12 @@ class HiveFixture(FixtureCommon): name="engineFcuVersion", ), ) + verify_sync: Optional[bool] = field( + default=None, + json_encoder=JSONEncoder.Field( + name="verifySync", + ), + ) pre_state: Mapping[str, Account] = field( json_encoder=JSONEncoder.Field( name="pre", From 308fc6e6f9504ac15c0de039912ea5e7509ee531 Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Thu, 8 Feb 2024 15:16:34 +0000 Subject: [PATCH 2/5] fix: Don't convert flag to a string --- src/ethereum_test_tools/spec/blockchain/types.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ethereum_test_tools/spec/blockchain/types.py b/src/ethereum_test_tools/spec/blockchain/types.py index 31dd864bb3d..101288c91d5 100644 --- a/src/ethereum_test_tools/spec/blockchain/types.py +++ b/src/ethereum_test_tools/spec/blockchain/types.py @@ -1126,6 +1126,7 @@ class HiveFixture(FixtureCommon): default=None, json_encoder=JSONEncoder.Field( name="verifySync", + skip_string_convert=True, ), ) pre_state: Mapping[str, Account] = field( From 3ccb0e636145e34872dc238a068ec44fe19730cc Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Thu, 8 Feb 2024 21:28:20 +0000 Subject: [PATCH 3/5] fix: Add a sync payload instead --- .../spec/blockchain/blockchain_test.py | 23 ++++++++++++++++++- .../spec/blockchain/types.py | 6 ++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py index 08b249101bb..2dbeba67416 100644 --- a/src/ethereum_test_tools/spec/blockchain/blockchain_test.py +++ b/src/ethereum_test_tools/spec/blockchain/blockchain_test.py @@ -423,12 +423,33 @@ def make_hive_fixture( self.verify_post_state(t8n, alloc) + sync_payload: Optional[FixtureEngineNewPayload] = None if self.verify_sync: # Test is marked for syncing verification. assert ( genesis.hash != head_hash ), "Invalid payload tests negative test via sync is not supported yet." + # Most clients require the header to start the sync process, so we create an empty + # block on top of the last block of the test to send it as new payload and trigger the + # sync process. + sync_header, _, _, _, _ = self.generate_block_data( + t8n=t8n, + fork=fork, + block=Block(), + previous_env=env, + previous_alloc=alloc, + eips=eips, + ) + sync_payload = FixtureEngineNewPayload.from_fixture_header( + fork=fork, + header=sync_header, + transactions=[], + withdrawals=[], + validation_error=None, + error_code=None, + ) + return HiveFixture( fork=self.network_info(fork, eips), genesis=genesis, @@ -436,7 +457,7 @@ def make_hive_fixture( fcu_version=fcu_version, pre_state=pre, post_state=alloc_to_accounts(alloc), - verify_sync=self.verify_sync, + sync_payload=sync_payload, name=self.tag, ) diff --git a/src/ethereum_test_tools/spec/blockchain/types.py b/src/ethereum_test_tools/spec/blockchain/types.py index 101288c91d5..27c4042381d 100644 --- a/src/ethereum_test_tools/spec/blockchain/types.py +++ b/src/ethereum_test_tools/spec/blockchain/types.py @@ -1122,11 +1122,11 @@ class HiveFixture(FixtureCommon): name="engineFcuVersion", ), ) - verify_sync: Optional[bool] = field( + sync_payload: Optional[FixtureEngineNewPayload] = field( default=None, json_encoder=JSONEncoder.Field( - name="verifySync", - skip_string_convert=True, + name="syncPayload", + to_json=True, ), ) pre_state: Mapping[str, Account] = field( From 31ee9ad7e13a6bb664385a8e161def16ac263111 Mon Sep 17 00:00:00 2001 From: spencer-tb Date: Sat, 9 Mar 2024 10:34:07 +0800 Subject: [PATCH 4/5] chore: add changelog. --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0ede655aab8..039d736d135 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -22,6 +22,7 @@ Test fixtures for use by clients are available for each release on the [Github r - 🔀 Locally calculate state root for the genesis blocks in the blockchain tests instead of calling t8n ([#450](https://github.com/ethereum/execution-spec-tests/pull/450)). - 🐞 Fix bug that causes an exception during test collection because the fork parameter contains `None` ([#452](https://github.com/ethereum/execution-spec-tests/pull/452)). - ✨ The `_info` field in the test fixtures now contains a `hash` field, which is the hash of the test fixture, and a `hasher` script has been added which prints and performs calculations on top of the hashes of all fixtures (see `hasher -h`) ([#454](https://github.com/ethereum/execution-spec-tests/pull/454)). +- ✨ Adds an optional `verify_sync` field to hive blockchain tests (EngineAPI). When set to true a second client attempts to sync to the first client that executed the tests.([#431](https://github.com/ethereum/execution-spec-tests/pull/431)). ### 🔧 EVM Tools From 9adc877fd194025c3a69d2e6b963a3650cb495a0 Mon Sep 17 00:00:00 2001 From: spencer-tb Date: Sat, 9 Mar 2024 10:44:52 +0800 Subject: [PATCH 5/5] chore: fix spelling in changelog :P --- whitelist.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/whitelist.txt b/whitelist.txt index 05108084a4b..50993c40c80 100644 --- a/whitelist.txt +++ b/whitelist.txt @@ -81,6 +81,7 @@ eip eips EIPs endianness +EngineAPI enum env eof