Skip to content

Ledger Close Time Estimator #547

Description

@Kingsman-99

Description

Features like payment expiry guards and reminder schedulers need to estimate when a future ledger sequence number will close. Stellar targets a ~5-second ledger close interval, but actual intervals vary. Without a data-driven estimate, expiresAt and timebounds.maxTime calculations are imprecise. A ledger close time estimator should compute a rolling average close interval from recent ledger history and project future close times.

Technical Context

Add src/ledgerCloseEstimator.ts. Uses @stellar/stellar-sdk Server.ledgers() to fetch the last N ledger records and extracts closed_at timestamps. Computes a rolling-average close interval. Exposes estimateCloseTime(targetLedger: number): Date and estimateLedgerAtTime(targetTime: Date): number. Integrates with src/deadlineEngine.ts and src/txBuilder.ts for timebounds computation.

Acceptance Criteria

  • LedgerCloseEstimator.calibrate(sampleSize = 20) fetches the last sampleSize ledgers from Horizon and computes the rolling-average close interval in milliseconds
  • estimateCloseTime(targetLedger) returns a Date object representing the projected close time for a future ledger sequence
  • estimateLedgerAtTime(targetTime) returns the projected ledger sequence that will be current at targetTime
  • Re-calibrates automatically every calibrationIntervalMs (configurable, default 5 minutes)
  • Unit tests mock ledger records with known timestamps and assert correct interval computation and projection
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions