Skip to content

M1.3 OPFS headers store + resume + tip reorg #9

Closed

Description

@melvincarvalho

Part of #1 (M1).

Goal

Persist validated headers to OPFS; resume from the stored tip on reload; handle small reorgs at the tip.

Benchmark / acceptance

  • Kill and resume mid-sync with no re-validation of already-stored headers.
  • Report storage footprint for the full header chain.
  • A tip reorg is detected and resolved to the most-work chain.

Activity

  1. melvincarvalho commented on Jun 18, 2026

    @melvincarvalho
    ContributorAuthor

    Done (headless, on testnet4).

    • src/store/header-store.js — HeaderStore interface + MemoryHeaderStore + FileHeaderStore. Shared index (hash→height, cumulative work), exponential block locator, truncate for rollback.
    • src/chain/header-sync.js — HeaderSync: resume from store, validate each header incrementally, reorg by the most-work rule, skip re-served prefixes. Depends only on the store interface + engine + a transport-agnostic fetchHeaders(locator).

    Tested: 10 headless unit tests (store index/truncate/locator/file round-trip; sync fresh/resume/prefix-overlap/heavier-fork-adopted/lighter-fork-rejected), all green. Live testnet4: fresh sync 140k headers all validated; resume from disk in 0.3s; tip cross-checked over p2p.

    Browser port is now two swaps: FileHeaderStore → OpfsHeaderStore, TCP Peer → WS-bridge Peer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions