fix(#252): use runtime-computed ledger tip in seed scripts - #342
Merged
Lost-Z merged 1 commit intoAug 31, 2026
Merged
Conversation
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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #252.
scripts/seed.sqlandscripts/seed.shpreviously used hardcoded ledger numbers around 1 000 000 — orders of magnitude below the current Stellar mainnet tip (~55 M+). This caused/healthto report alag_ledgersvalue 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.shSEED_LEDGERat 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.SEED_LEDGERenv-var override for reproducible test runs (e.g.SEED_LEDGER=55000000 ./scripts/seed.sh).seed.ledgersoseed.sqlcan read it portably without relying on psql\setsyntax.UPDATEtoindexer_cursor.last_processed_ledgerso/healthreports near-zerolag_ledgersimmediately after seeding.scripts/seed.sqlINSERTrows with a singleSELECT … UNION ALLblock that offsets ledger numbers relative to a_seed_cfgtemp table (populated by aDO $$block that reads theseed.ledgerGUC, or falls back to the same genesis-based formula so a barepsql … -f seed.sqlrun remains self-contained).indexer_cursorupsert to use the same computed ledger.seed.shwrapper.seed_ledgerin the final summarySELECTso callers can confirm which ledger was used.Before / After
lag_ledgersbeforelag_ledgersafterSEED_LEDGER=55000000explicitpsql -f seed.sqlTesting
DO $$block,CREATE TEMP TABLE,UNION ALLselects).SEED_LEDGERenv-var override path allows CI or snapshot tests to pin a known ledger for deterministic output.