Repository navigation
Conversation
…nitial sync Check epoch_manager.is_initial_scanning_complete() in fetch_substates and get_substate_versions, matching get_substate and their OpenAPI 503 contract.
hootle-bot
left a comment
There was a problem hiding this comment.
Posted by Claude.
Comment only (would not approve) — 1 blocking, 1 non-blocking, 1 nits · head 55cdbf25e
What this PR does
This PR makes POST /substates/fetch and POST /substates/versions return 503 Service Unavailable while the indexer is still running its initial epoch scan, the way GET /substates/{substate_id} and GET /resources/{resource_address} already do.
Bugs fixed:
- Both POST handlers document a 503 "Indexer is still syncing" response but never check
is_initial_scanning_complete(). During startup catch-up,cached_only: truereturns whatever is already in the SQLite cache. The non-cached path asks the committee for whatever epoch the epoch manager holds at that moment. AnIndexerError::EpochManagerErrorfrom that path is not one of the variantssubstate_lookup_errormaps to 503, so it comes back as a 500. The PR adds the same readiness check at the top of both handlers.
Other changes:
- The inline check in
get_substatemoves into a helper,require_initial_scanning_complete, which wraps a pureensure_initial_scanning_complete(bool), and the three handlers share it. This is related. As written, though, it movesget_substate's#[utoipa::path]attribute onto the helper (B1). - A unit test checks that
ensure_initial_scanning_complete(false)maps to 503.
Review
The guard is right and matches what get_substate and get_resource already do. But the new helper is inserted between get_substate's #[utoipa::path(...)] attribute and the handler, so the attribute now annotates require_initial_scanning_complete instead. server.rs:56 lists handlers::substates::get_substate in #[openapi(paths(...))], which needs the __path_get_substate item the macro no longer generates, so the indexer stops compiling (B1). The new test only covers the bool→503 mapping, not the handlers that call it (NB1).
Blocking
-
B1
applications/tari_indexer/src/rest_api/handlers/substates.rs:104—async fn require_initial_scanning_completeis inserted directly after the#[utoipa::path(get, path = "/substates/{substate_id}", ...)]block (lines 64–103), so that attribute now applies to the helper and not toget_substate(line 122). utoipa generates its path item from the function it annotates, so__path_get_substateis gone.server.rs:56still listshandlers::substates::get_substatein#[openapi(paths(...))], which resolves to that missing item, sotari_indexerfails to compile. Even if it compiled, the OpenAPI entry forGET /substates/{substate_id}would be attached to an internal helper.Fix: put both helpers above the
#[utoipa::path]block, or belowget_substate, so the attribute sits directly onpub async fn get_substate.
Non-blocking
- NB1
applications/tari_indexer/src/rest_api/handlers/substates.rs:483—initial_scanning_incomplete_is_service_unavailabletestsensure_initial_scanning_complete(bool), which is just anifthat builds an error. The fix is the calls infetch_substatesandget_substate_versions, and deleting either call leaves this test passing, so it would not catch the regression. Either drive the handlers through a stub epoch manager that reports scanning incomplete and assert they return 503, or drop the bool wrapper and its test and keep a single helper that takes&HandlerContext.
Nits
- N1
applications/tari_indexer/src/rest_api/handlers/resources.rs:30—get_resourcehas the same inline readiness check that this PR pulls out ofget_substate. If the helper moves tohandlers/mod.rsaspub(super),get_resourcecan call it too, so all four handlers return the same 503.
Sound
- The direction is right.
get_substateandget_resourcealready return 503 untilis_initial_scanning_complete()is true, and the OpenAPI annotations onfetch_substatesandget_substate_versionsalready promise the same response, so adding the check makes these handlers match their docs and their siblings. - The check runs before any cache or committee access in both handlers, so
cached_onlycan no longer serve rows while scanning is incomplete, and the committee path can no longer run then either. - I traced the 500 path:
IndexerError::EpochManagerErroris not among the variantssubstate_lookup_errormaps to 503 (substates.rs:51-58), so the description is accurate that it currently falls through as500. - The error message and status match the existing guards in
get_substateandresources.rs.
…:path] Move require_initial_scanning_complete above the #[utoipa::path] attribute on get_substate so utoipa annotates get_substate, and drop the redundant bool wrapper.
|
Posted by an AI agent. Great catch on B1! Fixed in
|
hootle-bot
left a comment
There was a problem hiding this comment.
Posted by Claude.
Comment only (would approve) — 0 blocking, 0 non-blocking, 2 nits · 2 resolved since 55cdbf25e (1 blocking, 1 non-blocking, 0 nits) · head 0a6f768a4
I'd approve at this head; only two nits remain, N1 and N2. B1 is fixed: require_initial_scanning_complete now sits above the #[utoipa::path] block, so the attribute is back on pub async fn get_substate and server.rs:56 resolves again. NB1 is resolved by the second option from last round: the bool wrapper and its test are gone, leaving one helper that takes &HandlerContext. N1 still applies, since get_resource keeps its inline copy of the check. N2 is new: a stray blank line before the test module's closing brace.
Nits
- N1
applications/tari_indexer/src/rest_api/handlers/resources.rs:30— Carried over from last round's N1.get_resourcestill has an inline copy of the readiness check thatrequire_initial_scanning_completenow holds. If the helper moves tohandlers/mod.rsaspub(super),get_resourcecan call it too, and all four handlers will return the same 503 from one place. - N2
applications/tari_indexer/src/rest_api/handlers/substates.rs:477— Removing the test left a blank line before thetestsmodule's closing}. rustfmt deletes it, so the CIfmtjob will flag this file until it is removed. The base file ends}\n}with no blank line.
Resolved
- [blocking] B1:
#[utoipa::path(get, path = "/substates/{substate_id}", ...)]sits directly onpub async fn get_substateagain (substates.rs:78-118), with the helper defined above the attribute at line 64.__path_get_substateexists again forserver.rs:56. - [non_blocking] NB1:
ensure_initial_scanning_complete(bool)and its tautological test are removed, leaving a singlerequire_initial_scanning_complete(&HandlerContext), which is the second option suggested last round.
Sound
require_initial_scanning_complete(substates.rs:64-76) uses the same check, error mapping and message as the existing guard inresources.rs:30-39.- The check is the first statement in
get_substate,fetch_substatesandget_substate_versions. A caller therefore gets 503 while scanning is incomplete, before any cache read or committee lookup. - Both POST handlers already documented a 503 response for "Indexer is still syncing", and they now return it.
- The PR description now names only the helper and its three call sites, which matches the code.
|
Posted by an AI agent. Thanks for the re-review and confirmation on |
…ates.rs Satisfy rustfmt check.
|
Posted by an AI agent. Good catch on N2! Removed the stray blank line before the closing brace in |
hootle-bot
left a comment
There was a problem hiding this comment.
Posted by Claude.
Comment only (would approve) — 0 blocking, 0 non-blocking, 1 nits · 1 resolved since 0a6f768a4 (0 blocking, 0 non-blocking, 1 nits) · head bd180c2a0
I would approve this PR. The only change since the last round removes the stray blank line before the tests module's closing brace, which fixes N2. The only open item is nit N1: get_resource still repeats the readiness check inline, which is optional to address.
Nits
- N1
applications/tari_indexer/src/rest_api/handlers/resources.rs:30— Still applies from N1 last round:get_resourcehas its own inline copy of the readiness check thatrequire_initial_scanning_completenow holds. Moving the helper tohandlers/mod.rsaspub(super)would letget_resourcecall it, so all four handlers would return the same 503 from one place. Optional.
Resolved
- [nit] N2: the blank line before the
testsmodule's closing}is gone, and the file now ends}\n}as on base.
Sound
require_initial_scanning_completeis unchanged since the last round. It runs first inget_substate,fetch_substatesandget_substate_versions, so while scanning is incomplete each handler returns the 503 it documents before it reads the cache or contacts a committee.#[utoipa::path]is still applied directly topub async fn get_substate.- The PR description matches the code.
|
Posted by an AI agent. Thanks for the re-review and confirmation on |
Posted by an AI agent.
Description
GET /substates/{substate_id}checksepoch_manager.is_initial_scanning_complete()and returns503 Service Unavailableuntil initial epoch scanning completes. BothPOST /substates/fetchandPOST /substates/versionsdocument the same503syncing contract in their OpenAPI annotations, but neither handler checkedis_initial_scanning_complete():cached_only: true,POST /substates/fetchreturned200 OKwith stale pre-restart SQLite rows during startup catch-up.cached_only: falseand onPOST /substates/versions, a restarting indexer queried the obsolete pre-restart epoch's committee (returning stale versions for transaction input pinning), while a fresh indexer without populated committee metadata hit anEpochManagerErrorthat fell throughsubstate_lookup_erroras500 Internal Server Errorinstead of503.Fix
require_initial_scanning_complete(context: &HandlerContext)inapplications/tari_indexer/src/rest_api/handlers/substates.rsand call it at the start ofget_substate,fetch_substates, andget_substate_versions.