Skip to content

Commit 11ea5e8

Browse files
committed
Changes from comments on PR ethereum#2007
- Use `pytest.mark.verify_sync` instead of the previous `verify_sync` flag on the blockchain test. - Remove the syncing periodic checks as when the forkchoice_updated response is `VALID`, we can break. - Update all files according to changes above.
1 parent 80f154e commit 11ea5e8

File tree

8 files changed

+151
-229
lines changed

8 files changed

+151
-229
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Users can select any of the artifacts depending on their testing needs for their
8080
- ✨ Generate unique addresses with Python for compatible static tests, instead of using hard-coded addresses from legacy static test fillers ([#1781](https://github.com/ethereum/execution-spec-tests/pull/1781)).
8181
- ✨ Added support for the `--benchmark-gas-values` flag in the `fill` command, allowing a single genesis file to be used across different gas limit settings when generating fixtures. ([#1895](https://github.com/ethereum/execution-spec-tests/pull/1895)).
8282
- ✨ Static tests can now specify a maximum fork where they should be filled for ([#1977](https://github.com/ethereum/execution-spec-tests/pull/1977)).
83-
- ✨ Add support for `BlockchainEngineSyncFixture` format for tests with `verify_sync=True` to enable client synchronization testing via `consume sync` command ([#2007](https://github.com/ethereum/execution-spec-tests/pull/2007)).
83+
- ✨ Add support for `BlockchainEngineSyncFixture` format for tests marked with `pytest.mark.verify_sync` to enable client synchronization testing via `consume sync` command ([#2007](https://github.com/ethereum/execution-spec-tests/pull/2007)).
8484

8585
#### `consume`
8686

docs/running_tests/test_formats/blockchain_test_sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The Blockchain Engine Sync Test fixture format tests are included in the fixtures subdirectory `blockchain_tests_sync`, and use Engine API directives to test client synchronization capabilities after fixtures are executed with valid payloads.
44

5-
These are produced by the `BlockchainTest` test spec when `verify_sync=True` is specified.
5+
These are produced by the `BlockchainTest` test spec when `pytest.mark.verify_sync` is used as a test marker.
66

77
## Description
88

src/ethereum_test_fixtures/blockchain.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ class BlockchainEngineFixture(BlockchainEngineFixtureCommon):
542542
genesis: FixtureHeader = Field(..., alias="genesisBlockHeader")
543543
post_state: Alloc | None = Field(None)
544544
payloads: List[FixtureEngineNewPayload] = Field(..., alias="engineNewPayloads")
545-
sync_payload: FixtureEngineNewPayload | None = None
546545

547546

548547
@post_state_validator(alternate_field="post_state_diff")
@@ -566,11 +565,8 @@ class BlockchainEngineXFixture(BlockchainEngineFixtureCommon):
566565
payloads: List[FixtureEngineNewPayload] = Field(..., alias="engineNewPayloads")
567566
"""Engine API payloads for blockchain execution."""
568567

569-
sync_payload: FixtureEngineNewPayload | None = None
570-
"""Optional sync payload for blockchain synchronization."""
571-
572568

573-
class BlockchainEngineSyncFixture(BlockchainEngineFixtureCommon):
569+
class BlockchainEngineSyncFixture(BlockchainEngineFixture):
574570
"""
575571
Engine Sync specific test fixture information.
576572
@@ -584,8 +580,4 @@ class BlockchainEngineSyncFixture(BlockchainEngineFixtureCommon):
584580
description: ClassVar[str] = (
585581
"Tests that generate a blockchain test fixture for Engine API testing with client sync."
586582
)
587-
pre: Alloc
588-
genesis: FixtureHeader = Field(..., alias="genesisBlockHeader")
589-
post_state: Alloc | None = Field(None)
590-
payloads: List[FixtureEngineNewPayload] = Field(..., alias="engineNewPayloads")
591583
sync_payload: FixtureEngineNewPayload | None = None

src/ethereum_test_specs/blockchain.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,6 @@ class BlockchainTest(BaseTest):
404404
post: Alloc
405405
blocks: List[Block]
406406
genesis_environment: Environment = Field(default_factory=Environment)
407-
# If set to True, generate a BlockchainEngineSyncFixture to
408-
# verify syncing between clients.
409-
verify_sync: bool = False
410407
chain_id: int = 1
411408
exclude_full_post_state_in_output: bool = False
412409
"""
@@ -443,13 +440,14 @@ def discard_fixture_format_by_marks(
443440
"""Discard a fixture format from filling if the appropriate marker is used."""
444441
marker_names = [m.name for m in markers]
445442

446-
if "blockchain_test_only" in marker_names:
447-
return fixture_format != BlockchainFixture
448-
if "blockchain_test_engine_only" in marker_names:
449-
return fixture_format != BlockchainEngineFixture
450-
451-
# Exception tests cannot be used for sync testing
452-
if "exception_test" in marker_names and fixture_format == BlockchainEngineSyncFixture:
443+
if "blockchain_test_only" in marker_names and fixture_format != BlockchainFixture:
444+
return True
445+
if (
446+
"blockchain_test_engine_only" in marker_names
447+
and fixture_format != BlockchainEngineFixture
448+
):
449+
return True
450+
if fixture_format == BlockchainEngineSyncFixture and "verify_sync" not in marker_names:
453451
return True
454452

455453
return False
@@ -833,10 +831,6 @@ def generate(
833831
fixture_format: FixtureFormat,
834832
) -> BaseFixture:
835833
"""Generate the BlockchainTest fixture."""
836-
# Skip sync fixture generation if verify_sync is False
837-
if fixture_format == BlockchainEngineSyncFixture and not self.verify_sync:
838-
raise pytest.skip(f"Skipping sync fixture, verify_sync={self.verify_sync}")
839-
840834
t8n.reset_traces()
841835
if fixture_format in [
842836
BlockchainEngineFixture,

src/pytest_plugins/consume/simulators/simulator_logic/test_via_sync.py

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ def test_blockchain_via_sync(
369369
break
370370

371371
if last_valid_payload:
372+
last_valid_block_forkchoice_state = ForkchoiceState(
373+
head_block_hash=last_valid_block_hash,
374+
safe_block_hash=last_valid_block_hash,
375+
finalized_block_hash=fixture.genesis.block_hash,
376+
)
377+
372378
try:
373379
version = last_valid_payload.new_payload_version # log version used for debugging
374380
logger.info(f"Sending target payload via engine_newPayloadV{version}")
@@ -384,11 +390,7 @@ def test_blockchain_via_sync(
384390
# send forkchoice update pointing to latest block
385391
logger.info("Sending forkchoice update with last valid block to trigger sync...")
386392
sync_forkchoice_response = sync_engine_rpc.forkchoice_updated(
387-
forkchoice_state=ForkchoiceState(
388-
head_block_hash=last_valid_block_hash,
389-
safe_block_hash=last_valid_block_hash,
390-
finalized_block_hash=fixture.genesis.block_hash,
391-
),
393+
forkchoice_state=last_valid_block_forkchoice_state,
392394
payload_attributes=None,
393395
version=last_valid_payload.forkchoice_updated_version,
394396
)
@@ -437,9 +439,6 @@ def test_blockchain_via_sync(
437439

438440
# Start monitoring sync progress
439441
sync_start_time = time.time()
440-
last_sync_block_number = 0
441-
sync_check_interval = 1.0
442-
last_check_time = time.time()
443442
last_forkchoice_time = time.time()
444443
forkchoice_interval = 2.0 # Send forkchoice updates every 2 seconds
445444

@@ -450,55 +449,19 @@ def test_blockchain_via_sync(
450449
# Send forkchoice update to sync client to trigger/maintain sync
451450
assert sync_engine_rpc is not None, "sync_engine_rpc is required"
452451
sync_fc_response = sync_engine_rpc.forkchoice_updated(
453-
forkchoice_state=ForkchoiceState(
454-
head_block_hash=last_valid_block_hash,
455-
safe_block_hash=last_valid_block_hash,
456-
finalized_block_hash=fixture.genesis.block_hash,
457-
),
452+
forkchoice_state=last_valid_block_forkchoice_state,
458453
payload_attributes=None,
459454
version=fixture.sync_payload.forkchoice_updated_version
460455
if fixture.sync_payload
461456
else fixture.payloads[-1].forkchoice_updated_version,
462457
)
463458
status = sync_fc_response.payload_status.status
464459
logger.debug(f"Periodic forkchoice update status: {status}")
460+
if status.VALID:
461+
break
465462
last_forkchoice_time = time.time()
466463
except Exception as fc_err:
467464
logger.debug(f"Periodic forkchoice update failed: {fc_err}")
468-
469-
# Check sync progress periodically
470-
if time.time() - last_check_time >= sync_check_interval:
471-
try:
472-
# Check current sync status
473-
assert sync_eth_rpc is not None, "sync_eth_rpc is required"
474-
sync_latest = sync_eth_rpc.get_block_by_number("latest")
475-
if sync_latest:
476-
sync_block_number = int(sync_latest["number"], 16)
477-
if sync_block_number > last_sync_block_number:
478-
hash_val = sync_latest["hash"]
479-
logger.info(
480-
f"Sync progress: block #{sync_block_number} (hash: {hash_val})"
481-
)
482-
last_sync_block_number = sync_block_number
483-
484-
# Check if we've reached the target
485-
if sync_latest["hash"] == last_valid_block_hash:
486-
logger.info("Sync client successfully synchronized to target block!")
487-
break
488-
489-
# try to get the target block directly, via hash
490-
sync_block = sync_eth_rpc.get_block_by_hash(last_valid_block_hash)
491-
if sync_block is not None:
492-
logger.info(
493-
f"Sync client has target block! Number: {sync_block['number']}"
494-
)
495-
break
496-
497-
except Exception as e:
498-
logger.debug(f"Error checking sync status: {e}")
499-
500-
last_check_time = time.time()
501-
502465
time.sleep(0.5)
503466
else:
504467
raise LoggedError(

src/pytest_plugins/filler/tests/test_blockchain_sync_marker.py

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)