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
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,
expiresAtandtimebounds.maxTimecalculations 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-sdkServer.ledgers()to fetch the last N ledger records and extractsclosed_attimestamps. Computes a rolling-average close interval. ExposesestimateCloseTime(targetLedger: number): DateandestimateLedgerAtTime(targetTime: Date): number. Integrates withsrc/deadlineEngine.tsandsrc/txBuilder.tsfor timebounds computation.Acceptance Criteria
LedgerCloseEstimator.calibrate(sampleSize = 20)fetches the lastsampleSizeledgers from Horizon and computes the rolling-average close interval in millisecondsestimateCloseTime(targetLedger)returns aDateobject representing the projected close time for a future ledger sequenceestimateLedgerAtTime(targetTime)returns the projected ledger sequence that will be current attargetTimecalibrationIntervalMs(configurable, default 5 minutes)