feat(api): /contracts/recent endpoint#10
Merged
Conversation
Image `wget`s 127.0.0.1:8081/health (api) and 127.0.0.1:8082/health
(worker) by default — that's the mainnet stack's port layout. Testnet
relocates both via API_PORT=8083 + INDEXER_HEALTH_PORT=8084 to share
the host with the mainnet stack, but the bake-time healthcheck still
hit the old ports → exit 1 → docker reported unhealthy even though
both services were happily serving 200s on testnet-api.sentrixchain.com.
Add explicit `healthcheck:` blocks on each compose service that point
at the relocated ports. Same interval / timeout / retries as the
Dockerfile defaults so behaviour matches mainnet otherwise.
Verified: post-recreate, `docker inspect -f '{{.State.Health.Status}}'`
returns healthy on both `sentrix-indexer-testnet-{api,worker}` within
seconds of start_period elapsing.
indexBlock was writing blocks/transactions/logs/token_transfers but never upserting into the addresses table — so addresses sat empty even after 50K+ indexed txs. Any UI/API that lists "addresses we've seen" (eg /contracts/stats, scan recent-deployments feed) returned nothing. Adds per-tx upsert of from + to (when non-null), tracking first_seen_block / last_seen_block. Coinbase sentinel skipped on the from side so the all-zero address doesn't claim a row from validator rewards. is_contract stays false at insert time; a separate eth_getCode pass marks it true for addresses with non-empty code (cheap, lazy, out of the hot write path). Surfaced by PR #8266 reviewer asking why a deployed contract didn't appear in any list — the contract is on-chain and readable via eth_getCode, but our indexer's address-derived endpoints had no row to return.
Two follow-ups to the addresses-table fix (PR #8): 1. **Contract detection worker** (`apps/indexer/src/contract-detect.ts`). The hot tx-insertion path in sync.ts upserts addresses with is_contract=false + code_hash=NULL because doing eth_getCode mid-batch would dominate runtime. This worker runs in the background, picks up addresses with code_hash IS NULL, and flips the flag based on whether the chain reports any deployed code. Slow cadence (10 addrs / 4s) so a fresh boot doesn't fire 1000+ getCode calls in one second. Uses a "0x" sentinel for code_hash on EOAs so we never re-probe them. 2. **Backfill batch size 50 -> 500** in `docker-compose.testnet.yml`. Testnet sits 2.5M blocks ahead of the indexer's main cursor; at 50/batch the catch-up ETA was ~70h. 500/batch trims that to ~7h with no observed RPC pressure increase (chain has retry429 handling). 3. `SentrixClient.getCode(address)` thin wrapper around viem's `getBytecode`. Returns "0x" when the address is an EOA so the detector worker can use a string sentinel rather than special-case undefined. Surfaced by the PR #8266 audit: even after the addresses-table fix (commit 037662d), `/contracts/stats` returned empty because every new row had is_contract=false by default and only one address (manually upserted) was flipped. With the auto-detector running, every contract deployed across the chain will surface in addresses-table queries within seconds of being indexed.
Pairs with the contract-detect worker (PR #9): once an address gets flipped to is_contract=true, this endpoint surfaces it ordered by first_seen_block DESC. Doesn't depend on the transactions table — unlike /contracts/stats which INNER JOINs on indexed call history and lags the addresses table by hours during backfill catch-up. Surfaced by PR #8266 reviewer feedback: a deployed contract should appear in the explorer's contracts list immediately, not just via direct address lookup. Schema returns rank, address, first_seen_block, last_seen_block, code_hash. limit clamped to MAX_PAGE (100).
4 tasks
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.
Pairs with the contract-detect worker from #9: once an address gets flipped to
is_contract=true, this endpoint surfaces it ordered byfirst_seen_block DESC. Doesn't depend on the transactions table (unlike/contracts/statswhich INNER JOINs on indexed call history and lags the addresses table by hours during backfill catch-up).Surfaced by PR #8266 reviewer feedback: a deployed contract should appear in the explorer's contracts list immediately, not just via direct address lookup.
Schema returns
rank,address,first_seen_block,last_seen_block,code_hash.limitclamped toMAX_PAGE(100).Caddy
@indexer_paths+@indexer_paths_testnetmatchers also updated to proxy/contracts/recent(snapshot in founder-private).