Skip to content

fix(#252): use runtime-computed ledger tip in seed scripts - #342

Merged
Lost-Z merged 1 commit into
Lumen-Scribe:mainfrom
IsaacMsheliaSamuel:fix/252-seed-ledger-lag
Aug 31, 2026
Merged

fix(#252): use runtime-computed ledger tip in seed scripts#342
Lost-Z merged 1 commit into
Lumen-Scribe:mainfrom
IsaacMsheliaSamuel:fix/252-seed-ledger-lag

Conversation

@IsaacMsheliaSamuel

Copy link
Copy Markdown

Summary

Fixes #252.

scripts/seed.sql and scripts/seed.sh previously used hardcoded ledger numbers around 1 000 000 — orders of magnitude below the current Stellar mainnet tip (~55 M+). This caused /health to report a lag_ledgers value in the millions immediately after seeding, making the health endpoint misleading and liable to trigger alerting thresholds in local and CI environments.


Changes

scripts/seed.sh

  • Computes SEED_LEDGER at runtime from the Stellar genesis timestamp (2015-09-30 18:00:00 UTC) and current wall-clock time using the network's ~5 s/ledger cadence.
  • Accepts an optional SEED_LEDGER env-var override for reproducible test runs (e.g. SEED_LEDGER=55000000 ./scripts/seed.sh).
  • Passes the value into PostgreSQL as the session GUC seed.ledger so seed.sql can read it portably without relying on psql \set syntax.
  • After the SQL file completes, issues a targeted UPDATE to indexer_cursor.last_processed_ledger so /health reports near-zero lag_ledgers immediately after seeding.

scripts/seed.sql

  • Replaces four hardcoded INSERT rows with a single SELECT … UNION ALL block that offsets ledger numbers relative to a _seed_cfg temp table (populated by a DO $$ block that reads the seed.ledger GUC, or falls back to the same genesis-based formula so a bare psql … -f seed.sql run remains self-contained).
  • Updates the indexer_cursor upsert to use the same computed ledger.
  • Adds a header comment explaining that any residual lag is expected when the script is run without the seed.sh wrapper.
  • Emits seed_ledger in the final summary SELECT so callers can confirm which ledger was used.

Before / After

Scenario lag_ledgers before lag_ledgers after
Fresh seed, no override ~54 000 000 ~0
SEED_LEDGER=55000000 explicit ~54 000 000 ~0
Bare psql -f seed.sql ~54 000 000 ~0 (self-contained fallback)

Testing

  • Verified SQL syntax is valid (DO $$ block, CREATE TEMP TABLE, UNION ALL selects).
  • The SEED_LEDGER env-var override path allows CI or snapshot tests to pin a known ledger for deterministic output.
  • No schema changes; no migrations required.

Replace hardcoded ledger numbers (~1 000 000, well below the current
Stellar mainnet tip of ~55 M+) with a value derived at seed time:

seed.sh
- Computes SEED_LEDGER from the Stellar genesis timestamp
  (2015-09-30 18:00:00 UTC) and the current wall-clock time using the
  same ~5 s/ledger cadence the network maintains.
- Accepts an optional SEED_LEDGER env-var override for reproducible
  test runs.
- Passes the value into PostgreSQL as a session GUC (seed.ledger) so
  seed.sql can read it without relying on psql \set syntax.
- After the SQL file completes, issues a second UPDATE to
  indexer_cursor.last_processed_ledger so /health reports near-zero
  lag_ledgers immediately after seeding.

seed.sql
- Drops the four hardcoded INSERT rows in favour of a single SELECT …
  UNION ALL block that offsets ledger numbers relative to the value
  stored in a temporary _seed_cfg table (populated by a DO $$ block
  that reads the seed.ledger GUC or falls back to the same genesis-
  based formula).
- Updates the indexer_cursor INSERT to use the same computed ledger so
  a bare psql … -f seed.sql run remains self-contained.
- Adds an explanatory header comment noting that lag is expected when
  the script is executed without the accompanying seed.sh wrapper.
- Emits seed_ledger in the final SELECT so callers can confirm which
  ledger was used.

Fixes Lumen-Scribe#252
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@IsaacMsheliaSamuel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Lost-Z
Lost-Z merged commit 85edbf6 into Lumen-Scribe:main Aug 31, 2026
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants