Skip to content

feat(api): /contracts/recent endpoint#10

Merged
satyakwok merged 4 commits into
mainfrom
feat/native-tx-shape-adapter
May 5, 2026
Merged

feat(api): /contracts/recent endpoint#10
satyakwok merged 4 commits into
mainfrom
feat/native-tx-shape-adapter

Conversation

@satyakwok
Copy link
Copy Markdown
Member

Pairs with the contract-detect worker from #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).

Caddy @indexer_paths + @indexer_paths_testnet matchers also updated to proxy /contracts/recent (snapshot in founder-private).

satyakwok added 4 commits May 5, 2026 16:41
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).
@satyakwok satyakwok merged commit ce700f1 into main May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant