Skip to content

refactor(test): unify Hive and spec-test fork-choice runner - #524

Merged
MegaRedHand merged 1 commit into
lambdaclass:mainfrom
dicethedev:refactor/490-unify-hive-spec-runner
Jul 17, 2026
Merged

refactor(test): unify Hive and spec-test fork-choice runner#524
MegaRedHand merged 1 commit into
lambdaclass:mainfrom
dicethedev:refactor/490-unify-hive-spec-runner

Conversation

@dicethedev

@dicethedev dicethedev commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

🗒️ Description / Motivation

  • Moves fork-choice fixture execution into a shared runner used by both the Hive HTTP test driver and the offline blockchain spec-test suite.
  • Removes duplicated step-processing logic that could drift as leanSpec fixtures evolve.
  • Ensures both test entry points handle ticks, blocks, attestations, aggregated attestations, mocked proofs, and checks-only steps consistently.

What Changed

  • Added crates/blockchain/src/spec_test_runner.rs
    • Introduces the shared apply_fork_choice_step function.
    • Centralizes tick timestamp calculation and block-time advancement.
    • Centralizes block importing and block-attestation reaggregation.
    • Centralizes gossip attestation and aggregated-attestation processing.
    • Supports both fixture-level mocked-proof settings and Hive mocked-proof prefix detection.
    • Treats checks-only steps as execution no-ops.
  • Updated crates/blockchain/tests/forkchoice_spectests.rs
    • Replaced its duplicated fork-choice step dispatcher with the shared runner.
    • Retains offline-only fixture validation, block-label tracking, and store assertions.
  • Updated crates/net/rpc/src/test_driver.rs
    • Replaced the Hive-specific fork-choice step dispatcher with the shared runner.
    • Retains HTTP request handling, response serialization, and store snapshots.
  • Updated crates/blockchain/src/lib.rs
    • Exposes the shared spec-test runner module.
  • Updated crates/blockchain/Cargo.toml
    • Promotes ethlambda-test-fixtures from a development-only dependency because the shared runner consumes fixture step types.

Correctness / Behavior Guarantees

  • Both Hive and offline spec tests now execute fork-choice steps through the same implementation.
  • Existing store mutation behavior is preserved:
    • Tick steps use the fixture timestamp or interval.
    • Block steps optionally advance the store clock before import.
    • Successfully imported block attestations are added to the known aggregate pool.
    • Fork-choice head calculation is refreshed after block-attestation insertion.
    • Individual and aggregated gossip attestations use the existing store APIs.
  • Offline vectors continue using proofSetting to determine whether proofs are mocked.
  • Hive steps continue detecting mocked proofs through the leanSpec sentinel prefix.
  • Transport-specific Hive responses and offline-only assertions remain separate.
  • No production consensus behavior is changed; this refactors test-fixture execution.

Tests Added / Run

No new fixture cases were added. Existing blockchain spec tests and RPC test-driver tests cover the shared behavior.
Commands run:

  • cargo fmt --all -- --check
  • cargo check -p ethlambda-blockchain --tests

The full lint and release workspace test suites should be run before marking the remaining checklist items complete.

Related Issues / PRs

✅ Verification Checklist

  • Ran make fmt / equivalent cargo fmt --all -- --check — clean
  • Ran make lint (clippy with -D warnings) — clean
  • Ran cargo test --workspace --release — all passing

@greptile-apps

greptile-apps Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves fork-choice fixture execution into one shared runner. The main changes are:

  • Shares tick, block, attestation, and aggregate processing between offline and Hive tests.
  • Keeps fixture assertions and HTTP response handling in their existing callers.
  • Exposes the runner from the blockchain crate.
  • Promotes the fixture crate to a regular blockchain dependency.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • Failed block imports return before block attestations are inserted.
  • The new dependency direction remains acyclic.
  • Both callers preserve their existing mocked-proof behavior.

Important Files Changed

Filename Overview
crates/blockchain/Cargo.toml Promotes the fixture crate to a regular dependency required by the shared runner.
crates/blockchain/src/lib.rs Exports the new shared fixture runner module.
crates/blockchain/src/spec_test_runner.rs Centralizes fork-choice fixture step execution and mocked-proof selection.
crates/blockchain/tests/forkchoice_spectests.rs Uses the shared runner while retaining offline fixture checks and block-label tracking.
crates/net/rpc/src/test_driver.rs Uses the shared runner while retaining Hive request handling and store snapshots.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Offline spec tests] -->|Fixture proof setting| C[Shared fork-choice runner]
    B[Hive HTTP driver] -->|Proof-prefix detection| C
    C --> D[Tick store]
    C --> E[Import block]
    C --> F[Process attestation]
    C --> G[Process aggregate]
    E --> H[Insert block attestations]
    H --> I[Update fork-choice head]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart LR
    A[Offline spec tests] -->|Fixture proof setting| C[Shared fork-choice runner]
    B[Hive HTTP driver] -->|Proof-prefix detection| C
    C --> D[Tick store]
    C --> E[Import block]
    C --> F[Process attestation]
    C --> G[Process aggregate]
    E --> H[Insert block attestations]
    H --> I[Update fork-choice head]
Loading

Reviews (1): Last reviewed commit: "refactor(test): unify Hive and spec-test..." | Re-trigger Greptile

@MegaRedHand MegaRedHand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 🚀

@MegaRedHand
MegaRedHand merged commit 831d0b5 into lambdaclass:main Jul 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify Hive test driver and spec-test runner

2 participants