Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/data-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ test("GET /api/v1/extrinsics/:ref skips the embedded-events query on an unresolv
test("GET /api/v1/accounts/:ss58 shapes the cross-subnet summary from two merged, re-capped bounded scans", async () => {
mockQueue.current = [
[], // SET
[], // SET LOCAL statement_timeout
[ACCOUNT_EVENT_ROW], // hotkeyScanRows
[{ ...ACCOUNT_EVENT_ROW, netuid: 5 }], // coldkeyScanRows
[{ netuid: 4, uid: 1, stake_tao: "10", validator_permit: 1, active: 1 }], // regRows
Expand Down Expand Up @@ -1375,6 +1376,7 @@ test("GET /api/v1/accounts/:ss58 shapes the cross-subnet summary from two merged
test("GET /api/v1/accounts/:ss58 ignores null netuid events in subnet_count", async () => {
mockQueue.current = [
[], // SET
[], // SET LOCAL statement_timeout
[ACCOUNT_EVENT_ROW], // hotkeyScanRows
[{ ...ACCOUNT_EVENT_ROW, netuid: null }], // coldkeyScanRows
[], // regRows
Expand Down Expand Up @@ -1423,6 +1425,7 @@ test("GET /api/v1/accounts/:ss58 merges, re-sorts, and re-caps events from BOTH
};
mockQueue.current = [
[], // SET
[], // SET LOCAL statement_timeout
[hotkeyRow], // hotkeyScanRows
[coldkeyRowNewer, coldkeyRowOlder], // coldkeyScanRows
[], // regRows
Expand Down Expand Up @@ -1468,6 +1471,7 @@ test("GET /api/v1/accounts/:ss58 breaks a same-block tie between branches by eve
};
mockQueue.current = [
[], // SET
[], // SET LOCAL statement_timeout
[hotkeyRow], // hotkeyScanRows
[coldkeyRow], // coldkeyScanRows
[], // regRows
Expand Down
15 changes: 15 additions & 0 deletions workers/data-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5377,6 +5377,21 @@ async function dispatchDataApiRequest(
// already re-derives the true block_number/event_index order
// afterward, so which order SQL fetches the top CAP+1 rows in
// doesn't change the final output (METAGRAPHED-6-class fix).
//
// Confirmed live 2026-07-25: even with that fix (no Sort node,
// idx_ae_hotkey_observed/idx_ae_coldkey_observed both used), this
// route still tripped the shared 3000ms default under real
// concurrent load -- two sequential 87-chunk scans per request,
// contending with this box's other concurrent readers/writers for
// buffer/CPU access, occasionally pushed total time past the
// blanket budget (pg_stat_activity + docker logs both showed
// `canceling statement due to statement timeout` still firing on
// this route's exact query text). The sibling
// /api/v1/accounts/:ss58/events route hit this same class of
// problem first and already widens its own budget below (10000ms)
// rather than raising the global default for every other, much
// lighter route in this dispatcher -- same fix, ported here.
await sql`SET LOCAL statement_timeout = '10000ms'`;
const hotkeyScanRows = await sql<AccountEventReadRow[]>`
SELECT block_number, event_index, event_kind, hotkey, coldkey, netuid, uid, amount_tao, alpha_amount, observed_at, extrinsic_index
FROM account_events WHERE hotkey = ${ss58}
Expand Down