Skip to content

refactor(blockchain): extract sync status tracker#436

Open
dicethedev wants to merge 2 commits into
lambdaclass:mainfrom
dicethedev:refactor/extract-sync-status-tracker
Open

refactor(blockchain): extract sync status tracker#436
dicethedev wants to merge 2 commits into
lambdaclass:mainfrom
dicethedev:refactor/extract-sync-status-tracker

Conversation

@dicethedev

@dicethedev dicethedev commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🗒️ Description / Motivation

What Changed

  • Added crates/blockchain/src/sync_status.rs.
  • Moved SyncStatusTracker into the new module.
  • Moved the sync lag, network stall, and hysteresis constants.
  • Moved all six sync-status tests.
  • Updated lib.rs to import and use the extracted tracker.

Correctness / Behavior Guarantees

  • This is a code-organization refactor only.
  • The sync-status heuristic and thresholds are unchanged.
  • Tracker state transitions and metric values remain unchanged.
  • The module remains private, with only the required tracker API exposed as pub(crate).

Tests Added / Run

  • No new tests were added; the existing tests were moved with the implementation.
  • Ran cargo fmt --all — clean.
  • Ran cargo test -p ethlambda-blockchain --lib sync_status --locked — 6 passed.
  • Ran cargo clippy -p ethlambda-blockchain --all-targets --locked -- -D warnings — clean.
  • Ran git diff --check — clean.

Related Issues / PRs

✅ Verification Checklist

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

@greptile-apps

greptile-apps Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts the sync-status heuristic from crates/blockchain/src/lib.rs into a dedicated crates/blockchain/src/sync_status.rs module, following feedback from #417. The implementation, constants, and all six tests are moved verbatim; no logic is altered.

  • SyncStatusTracker, the three threshold constants (SYNC_LAG_THRESHOLD, NETWORK_STALL_THRESHOLD, SYNC_HYSTERESIS_BAND), and the full test suite are relocated to sync_status.rs with appropriate pub(crate) visibility.
  • lib.rs drops the original definitions and instead imports SyncStatusTracker via use crate::sync_status::SyncStatusTracker;, keeping the module private (mod sync_status;).

Confidence Score: 5/5

Safe to merge — this is a pure code-organisation change with no behavioural differences.

Every moved item (struct, constants, method body, tests) is byte-for-byte identical to what was in lib.rs. Module visibility is correctly narrowed to pub(crate), the new module is private to the crate, and all six existing tests continue to cover the same logic paths as before.

No files require special attention.

Important Files Changed

Filename Overview
crates/blockchain/src/sync_status.rs New module containing the extracted SyncStatusTracker, its three constants, update logic, and all six tests — identical to what was removed from lib.rs.
crates/blockchain/src/lib.rs Removes the inline SyncStatusTracker definition and its tests; adds mod sync_status and the corresponding use import. No other logic changed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[BlockChainServer] -->|calls| B[SyncStatusTracker::update]
    B --> C{network_lag > NETWORK_STALL_THRESHOLD?}
    C -->|Yes| D[syncing = false\nSyncStatus::Synced]
    C -->|No| E{currently syncing?}
    E -->|Yes - hysteresis| F{head_lag > THRESHOLD - BAND?}
    E -->|No| G{head_lag > THRESHOLD?}
    F -->|Yes| H[syncing = true\nSyncStatus::Syncing]
    F -->|No| I[syncing = false\nSyncStatus::Synced]
    G -->|Yes| H
    G -->|No| I

    subgraph sync_status.rs
        B
        C
        D
        E
        F
        G
        H
        I
    end
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into refactor/extrac..." | Re-trigger Greptile

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.

1 participant