Skip to content

Add zkApp command range query#162

Draft
Hebilicious wants to merge 1 commit into
o1-labs:mainfrom
Hebilicious:branch/ext-21-zkapp-command-range-query
Draft

Add zkApp command range query#162
Hebilicious wants to merge 1 commit into
o1-labs:mainfrom
Hebilicious:branch/ext-21-zkapp-command-range-query

Conversation

@Hebilicious

@Hebilicious Hebilicious commented Jun 8, 2026

Copy link
Copy Markdown

Closes #161.

Adds Query.zkappCommands for fetching successful zkApp commands over an explicit block range, including block info, fee payer data, and ordered account updates with actions, events, app state, and preconditions.

Guardrails:

  • requires explicit from and to; there is no implicit latest-range scan
  • enforces ZKAPP_COMMAND_RANGE_SIZE for this heavier query, defaulting to 1000
  • runs a preflight expanded account-update count and rejects ranges above ZKAPP_COMMAND_ACCOUNT_UPDATE_LIMIT, defaulting to 5000
  • uses array cardinality for the unfiltered count path, and only joins account-update tables for accountPublicKey / tokenId filtered counts

Also adds service tests for the range and account-update guardrails.

@Hebilicious Hebilicious force-pushed the branch/ext-21-zkapp-command-range-query branch from 23d7ca3 to 5a4b75a Compare June 8, 2026 17:32
@dkijania

dkijania commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@Hebilicious thanks for contribution! I just briefly looked at it.. will review this PR fully shortly. Looks like our CI has some issueswith running pr on forks

Comment thread src/db/sql/zkapp-commands/queries.ts Outdated
import { BlockStatusFilter } from '../../../blockchain/types.js';
import type { ZkappCommandDatabaseRow } from './types.js';

export function getZkappCommandsQuery(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 250-line query isn't executed by any test, from what i see. The unit tests only cover the pure rowsToZkappCommands and the guard functions, and the integration fixture has only failed zkApp commands (tests/integration/integration.test.ts:10), so with the status <> 'failed' filter it returns empty here.

Can you add test ?

ON b.id = bzkc.block_id
AND bzkc.status <> 'failed'
JOIN zkapp_commands zkc ON bzkc.zkapp_command_id = zkc.id
JOIN zkapp_fee_payer_body fpb ON zkc.zkapp_fee_payer_body_id = fpb.id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zkapp_fee_payer_body is the one table this query JOINs that isn't in USED_TABLES (src/db/sql/events-actions/queries.ts:427). Please add it to USED_TABLES so a missing table is caught at boot rather than first query.

WHERE
b.height >= ${from}
AND b.height < ${to}
${

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. This filters purely on b.height and b.chain_status, unlike events/actions which run the recursive pending_chain walk to resolve the true chain. For CANONICAL that's fine, but for the default ALL and for PENDING, competing/orphaned blocks at the same height all come through. Either use canonical resolution logic or document this on the schema field.

FROM block_range b
JOIN blocks_zkapp_commands bzkc
ON b.id = bzkc.block_id
AND bzkc.status <> 'failed'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are filtering out failed commands, so the status is always 'applied' and failureReason always null. The two output fields are effectively constant and looks like there is no point returning them . Given the PR scope is "successful" commands, simplest is to drop both fields.

Comment thread src/resolvers.ts
tracingState: new TracingState(graphQLSpan),
});
},
zkappCommands: async (_, { input }, context) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

events/block-details are gated behind ENABLE_BLOCK_TRANSACTION_DETAILS; this heavier query is exposed ungated. is it intentional?

Comment thread schema.graphql Outdated
"""
Mina block height to filter zkApp commands to, exclusive
"""
to: Int!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: from before to reads more naturally.

@dkijania

Copy link
Copy Markdown
Contributor

@Hebilicious overall looking good! Just couple comments

@Hebilicious

Copy link
Copy Markdown
Author

@dkijania thanks for the review, I will make the changes you suggest and we will test this on our archive internally.

@Hebilicious Hebilicious marked this pull request as draft June 19, 2026 16:25
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.

Add zkApp command range query with account update details

2 participants