fix(indexer): prevent liquidity snapshot coverage drops and harden provider failover #1453
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/cl8y-dex-terraclassic#1453
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem and scope
Make the cached liquidity feed reliable: independent pool-reserve observation, bounded multi-provider background ingestion/failover, and consistent publication to routing and /protocol history.
An anonymized report describes liquidity updating infrequently and implausible changes in the /protocol liquidity graph. Public read-only evidence identifies a temporary supported-pool coverage loss that can look like a withdrawal. This is a producer/cache reliability issue, linked to #1452, which requires all swap quotes in <250 ms using cached data and zero request-triggered RPC/LCD validation.
Do not publish reporter identities, conversations, screenshots, wallets or private transaction history.
Current codebase
Reviewed revision:
b26b762c4a870251d780715eac6eea4e2db5c14e.pair_reserves, one replaceable row per pair with raw amounts, fee bps, block height andsnapshot_at. Resting orders are mirrored separately.book_snapshot.rsruns a nonoverlapping ticker, default 10 s cadence, with skipped missed ticks, ≤8 concurrent jobs, 4 s pair deadlines, 2 s height deadline, response bounds and ≤1,000 orders per side. Each pair performs pool, fee and bid/ask queries plus book walking.snapshot_single_pairreads the pool first but commits reserves only after fee and both book walks succeed. A book failure or deadline can therefore discard a successful reserve observation. Prior amounts/time remain stored, but after the 20 s default freshness window consumers omit that pool. Existing preservation is not sufficient to keep pool-only observations current.protocol_tvl.rsvalues supported catalog pools from reserves and USD marks. Complete supported coverage is fresh; missing supported inputs produce partial subtotals or unavailable totals. USD value may legitimately change when prices/reserves change even without LP deposits/withdrawals.liquidity_snapshots.rsatomically publishes headline, pair stamps, source history and hourly/daily/monthly grains. Source history retains the last actual attempt in four-minute UTC slots; each chart bucket selects its terminal observation, never SUM or average.LcdClientalready supports configuredLCD_URLS, failover, endpoint cooldown and chain identity checking. Requests iterate endpoints in configured order;mark_failedapplies one configured fixed cooldown. Production configuration requires explicit endpoints but permits a single endpoint. Audit deployed configuration and failover behavior; do not claim failover is wholly absent.Public evidence
Read-only indexer API evidence on 2026-10-09 UTC:
stale_reserve: 1The expected supported-pool coverage identity stayed the same. This is evidence of a missing reserve contribution, not proof of an actual ~$38k withdrawal. Exact pool identity and historical chain balances remain to be reconciled. The same public observation showed overview quality stale/null with a 20 s age limit while the latest stored chart observation remained fresh at its original observation time; distinguish current and historical age semantics.
Public endpoints:
/api/v1/overview/api/v1/protocol/liquidity/daily?grain=hourly&limit=24/api/v1/protocol/liquidity/daily?grain=daily&limit=30Why a new implementation is needed
A healthy pool read must not be discarded because an unrelated book query failed. Ingestion must continue through flaky or rate-limited providers instead of repeatedly retrying the first endpoint and allowing useful cached reserves to age out. The chart and solver should consume observations maintained by one reliable background feed; neither may cause chain-query storms to compensate for cache misses.
Increasing TTLs, freezing USD values, hiding missing pools or treating a partial subtotal as proof of a withdrawal would conceal the underlying defect.
Relevant files
indexer/src/indexer/book_snapshot.rs,poller.rs: background scheduling, per-pair work and publication.indexer/src/lcd/mod.rs,lcd/chain_identity.rs,config.rs,indexer/.env.example: endpoint selection, failure classification, attestation and operational configuration.indexer/src/db/queries/pair_reserves.rs,resting_orders.rs: independently usable pool observations and consistent hybrid snapshots.indexer/src/indexer/protocol_tvl.rs,db/queries/hub_prices.rs,liquidity_snapshots.rs,protocol_liquidity.rs,pair_liquidity_usd.rs: valuation, generation and history.indexer/src/api/protocol_liquidity.rs,api/overview.rs: materialized reads and API caching.frontend-dapp/src/utils/protocolLiquidityQuality.ts,protocolVolumeGrain.ts,components/protocol/ProtocolGlobalStats.tsx,ProtocolVolumeDailyChart.tsx, and query hooks: retention and chart presentation.indexer/tests/book_snapshot_loop.rs,indexer_protocol_liquidity.rs,indexer_protocol_liquidity_series.rs,indexer_pair_discovery.rs; existing unit/browser tests.Recommended direction
Constraints and guardrails
Acceptance criteria
make verify-issue-<this issue>, meaningful failure/recovery and rate-budget tests, docs/config examples, and updated agent guidance. Retail behavior stays simple.Test plan: all functional paths
Test plan: attack, hack and abuse
Verification criteria
Record source/deployed revision, UTC times, deterministic fixture inputs, per-pair generation/height/age, provider attempt/circuit/rate counters, cache behavior and expected totals. Demonstrate healthy failover and recovery with mocked providers first; production checks are read-only and redact configuration secrets. Measure ingestion/publication/serving latency separately from the <250 ms quote target in #1452.
Completed before filing:
make verify-issue-1380: first run failed because the dedicated QA database credential was absent. After provisioning a new disposable loopback-only Postgres instance and dedicated QA role, the full retest finished 13 PASS / 0 FAIL / 2 SKIP. The skips are the unsupplied funded LocalTerra outage/LP-control fixture and deployed-revision/history acceptance; no production signing/mutation was attempted.make verify-issue-1394: first run had two database-dependent failures for the same missing QA credential; full isolated retest finished 23 PASS / 0 FAIL / 0 SKIP.make verify-issue-1398: 7 PASS / 0 FAIL / 0 SKIP.These passing baseline tests do not cover all newly requested decoupling, failover and latency behavior; add the scenarios above rather than treating existing tests as acceptance. Direct public LCD probes were unavailable (HTTP 403); exact historical chain reserves and actual production endpoint configuration remain unverified. Neither limitation blocks implementation or issue creation. Do not claim source tests establish production health.
PR #1454 is being consolidated with #1455 at the user's explicit request. CI is intentionally skipped. The combined-source sanity review found a semantic integration problem: #1452's new local mirror reader selected independent pool observations for book pricing. It now chooses the separately committed compatible hybrid generation without renewing its timestamp, falling back to current pool-only data when the hybrid is missing/stale. Both provider resilience and quote-ingestion budgets/tests are retained through the LCD merge conflict.
The normal
fj pr merge 1454attempt returned HTTP 405 despite a mergeable source branch. The CLI has no force-merge option; the requested admin override will use the authenticated Forgejo API after feasible local checks finish, without weakening branch protection or forging CI success. Full focused verifiers are running in an isolated worktree and dedicated disposable Postgres instance. Deployment of migration20261009145300, measured live recovery/latency and original-history reconstruction remain separate post-merge work; final results and tracking link will follow.Closing the merged liquidity-feed implementation after #1454 and #1455 were merged at the user's explicit request. Consolidated code revision:
4e84ee5e3b947714f33cbe5fe05a1e0fe734443e. Conflict resolution preserves independent pool/hybrid provenance, provider circuits and quote-ingestion pacing; the additional local mirror-generation regression passes twice.Post-merge migration/deployment, actual external quote latency, live provider failover/recovery and supported pool coverage, connected-wallet acceptance and evidence-supported historical reconciliation are now tracked in #1456. Existing DeFiLlama deployment/reconciliation remains #1449. This closure does not assert deployed acceptance or reconstruct the unknown historical contribution.
Combined-source checks are explicitly mixed:
verify-issue-1453is 10 PASS / 2 FAIL / 2 SKIP because the old request-time hybrid solver fixture suite has 8 failures per pass under the new uninitialized-local-cache fail-closed contract. Provider/feed/valuation/discovery library groups, the 73 dedicated liquidity/feed DB tests per pass, 97 frontend tests per pass and four browser checks pass. Those quote-fixture compatibility failures and unfinished quote implementation remain #1452. All executed failures, the browser timing outlier/retest and database-environment limits are preserved in the consolidation receipt.CI and unavailable review/verification holds were overridden per the explicit merge instruction without fabricating successful statuses or weakening branch protection. Operational follow-up lives in #1456; this implementation issue is not left open solely for verification.
PlasticDigits referenced this issue2026-10-10 11:10:08 +00:00