Skip to content

feat(indexer): allow starting from a configured start ledger on cold start - #31

Open
jdjioe5-cpu wants to merge 1 commit into
YieldAnchor:mainfrom
jdjioe5-cpu:feat/issue-7-start-ledger
Open

jdjioe5-cpu wants to merge 1 commit into
YieldAnchor:mainfrom
jdjioe5-cpu:feat/issue-7-start-ledger

Conversation

@jdjioe5-cpu

Copy link
Copy Markdown

Closes #7

Summary of Changes

  1. Environment Configuration (\packages/validation):

    • Added
      onNegativeIntegerSchema\ to validate non-negative safe integers.
    • Added optional \INDEXER_START_LEDGER\ parsing to \parseIndexerEnv\ falling back to
      ull\ and reporting invalid values consistently with existing settings.
    • Added unit tests in \packages/validation/test/env.test.ts\ verifying valid integers, trims, empty strings, and reporting of invalid formats.
  2. Indexer Configuration & Precedence (\services/indexer):

    • Updated \IndexerConfig\ in \services/indexer/src/config.ts\ to carry \startLedger: number | null.
    • Introduced pure function
      esolveStartCursor(checkpoint, configuredStartLedger, tipLedger)\ in \services/indexer/src/watcher.ts.
    • Enforced precedence:
      1. Stored checkpoint always wins if present (cold-start config never rewinds or displaces an active cursor).
      2. Configured \INDEXER_START_LEDGER\ is used on a cold start when no checkpoint is stored.
      3. Unconfigured cold starts continue to fall back to the ledger tip via \server.getLatestLedger().
    • Logged exact start source (\ rom checkpoint cursor, \ rom configured ledger, or \ rom ledger tip).
    • Skipped unnecessary \getLatestLedger()\ RPC round-trip when checkpoint or configured start ledger is present.
  3. Documentation:

    • Updated .env.example\ with documented \INDEXER_START_LEDGER=\ setting.
  4. Automated Testing & Verification:

    • Added tests in \services/indexer/test/watcher.test.ts\ verifying precedence rules, cold-start configuration, checkpoint retention, and logging.
    • All workspace tests (\pnpm test), \pnpm run lint, and \pnpm run typecheck\ passed cleanly.

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.

feat: let the indexer start from a chosen ledger so it can backfill missed events

1 participant