Skip to content

Guard estimatedCompletion against division-by-zero in IndexerService replay progress in src/indexer/service.ts #500

Description

@Jagadeeshftw

📌 Description

In src/indexer/service.ts, the replay progress reporting computes an estimated completion using a throughput rate. On the first progress tick (or when no rows have yet been replayed) the divisor can be zero, producing Infinity/NaN for estimatedCompletion, which then propagates into logs/metrics and any progress endpoint.

💡 Why it matters: NaN/Infinity ETAs corrupt dashboards and can break JSON serialization of progress; the estimate must degrade gracefully.

🧩 Requirements and context

  • Guard the estimatedCompletion computation against zero/negative rate and zero elapsed time.
  • Return null/omit the estimate when it cannot be computed instead of NaN/Infinity.
  • Ensure any progress metric/log handles the null case cleanly.
  • Add unit tests for the first-tick and zero-rate scenarios.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b fix/indexer-eta-divzero

2. Implement changes

  • Write/modify the relevant source: src/indexer/service.ts
  • Write comprehensive tests: tests/indexer-replay.test.ts
  • Add documentation: inline TSDoc on the estimate semantics
  • Include TSDoc doc comments
  • Validate security assumptions: no invalid numbers in serialized output

3. Test and commit

  • Run tests:
npm test
  • Cover edge cases: zero rows replayed, zero elapsed, normal progress
  • Include test output and security notes in the PR description.

Example commit message

fix(indexer): guard replay ETA against division by zero

✅ Acceptance criteria

  • No NaN/Infinity in estimatedCompletion
  • Estimate is null/omitted when uncomputable
  • Logs/metrics handle the null case
  • Tests cover first-tick/zero-rate

🔒 Security notes

Ensure invalid numeric values cannot break JSON responses consumed by clients.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issueStellar WaveIssues in the Stellar wave programbackendBackend service workbugBugobservabilityLogging / metrics / tracing

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions