Skip to content

Feature/json rpc api improvements - #793

Merged
renatomaia merged 43 commits into
next/2.0from
feature/JsonRpcApiImprovements
Aug 24, 2026
Merged

Feature/json rpc api improvements#793
renatomaia merged 43 commits into
next/2.0from
feature/JsonRpcApiImprovements

Conversation

@renatomaia

@renatomaia renatomaia commented Jul 30, 2026

Copy link
Copy Markdown

JSON-RPC API Improvements

This PR implements nine improvements identified as F1 to F9 as described here, and other improvements described in reviews here and here.

Divergences from Proposed Fixes

  1. H1 requires empty batches and batches over 100 entries to return error code -32600. The implementation instead defines and returns -32040 as suggested here to indicate invalid batch request.
  2. Y5 in the review requested true one-round-trip implementation, however the proposed fix was not possible because the repository queries still return COUNT(*) rather than ErrNotFound for an unknown application.
  3. Y7 in the review explicitly requested moving single-request path logging the client-controlled method name from Info level to Debug level, but the original behavior was kept because one Info line was allowed per batch in the description of feature F1.
  4. F2 and F6 describe the use of error codes -32001 for missing resources and -32002 for unknown applications from the original implementation. But such codes were replaced by -31001 and -31002 to avoid reserved server error codes as suggested here.

Commit relation to Features and Improvements

The table below lists the commits, and column ID indicates which improvement is introduced.

ID Commit Change Component Description
F1 733a8f4 feat jsonrpc add support for JSON-RPC 2.0 batch requests
H6 e954e1a feat jsonrpc impose the same response size budget of batch requests to single requests
af29738 refactor jsonrpc remove unused field 'data' from error responses
F2 da49cc4 feat jsonrpc add operation to get epoch by a virtual contiguous index
F3 d9bd698 feat jsonrpc add operation to get Node info like its chain ID, version, and default block
F4 dca7255 feat jsonrpc add inclusive index ranges to list epochs, inputs, outputs, and reports
F5 28ecb42 feat jsonrpc allows to filter output by execution and multiple selectors
H2 2037500 perf repository add DB index to improve filter output by execution
8f63de2 feat cli allows to filter output by execution and multiple selectors
F6 77448ea feat jsonrpc add methods to get the count of executed and pending outputs
F7 f294cdc feat jsonrpc support listing epochs with multiple statuses
c12dd7b feat cli support listing epochs with multiple statuses
F8 94d954b fix jsonrpc report 256-bit integer fields in OpenRPC specification
F9 4906bcd refactor jsonrpc rename cartesi_getMatchAdvanced as cartesi_getMatchAdvance
31568e8 test jsonrpc add tests for positional decoding of parameters
Y1 3a769b3 fix repository avoid invalid SQL when listing outputs with empty type list
Y6 9ba37ea test jsonrpc add tests for some use cases of listing operations
Y7#5 bb9906e perf jsonrpc parse JSON-RPC API spec on service initialization
Y7#7 2911c1b docs repository add comment to clarify expected behavior of module API
H1 2451ced docs jsonrpc add warnings and recommendations on how to use the API
H4 7531899 docs jsonrpc improve documentation on response size limit
65f2d40 fix jsonrpc skip ignored fields on positional decoding of parameters
Y6 ebb3d95 test jsonrpc add more tests on parsing parameters
Y7#8 9bcb40d style cli avoid line length violation
Y7#9 d79b075 test jsonrpc add test to enforce log of method call
H6 54231ee feat jsonrpc impose the same listed items limit for all requests in a batch
N1 ac78085 feat jsonrpc add a dispatch timeout to prevent reaching the write timeout to avoid incomplete responses
N2 f8c1723 fix jsonrpc refuse offsets that are too large to be handled correctly
N3 96c0a14 fix jsonrpc avoid logging canceled context errors due to disconnected clients
N4 7c6012d feat jsonrpc truncate long method names to avoid flooding the log
N5 01aeb98 feat jsonrpc report panic errors of individual methods in a request batch
N6 4e9f329 feat jsonrpc avoid overlogging decoding errors of DApps inputs/outputs
N7 17f1542 fix jsonrpc avoid response with different ID value due to decoding errors
N8 726d844 docs jsonrpc document the potential costs of DB transversal due to large offsets
R1 d4ea032 test jsonrpc add endpoint-level tests for 'cartesi_listOutputs'
R3 b79a998 perf jsonrpc add DB index to improve filter of executed outputs
R4 55a3eb0 docs jsonrpc document wort-case memory scenario for responses
R8 2cdb69b test jsonrpc avoid different test package setup to interfere with one another
72003b4 style jsonrpc avoid lint errors
R2 a89cd03 style cli avoid lint errors
4308df9 fix jsonrpc report JSON contents even on incomplete/malformed responses
57f4449 fix jsonrpc avoid corrupting the offset maximum reported by 'rpc.discover'
7558af6 fix jsonrpc improve error messages reported to the client

@renatomaia
renatomaia requested review from mpolitzer and vfusco July 30, 2026 13:51
@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch from 13bd7c4 to 31e82e1 Compare July 30, 2026 13:55
@renatomaia renatomaia self-assigned this Aug 3, 2026
@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch from 31e82e1 to fc36dae Compare August 11, 2026 14:36
@vfusco
vfusco requested a balanced review from Copilot August 11, 2026 19:48
@vfusco vfusco added this to the 2.0.0 milestone Aug 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Expands the JSON-RPC API with batching, additional queries, richer filtering, updated schemas, and corresponding CLI support.

Changes:

  • Adds batch dispatching with response budgeting and centralized error handling.
  • Adds node information, virtual epoch lookup, output counts, ranges, and multi-value filters.
  • Updates OpenRPC documentation, CLI commands, repository queries, and tests.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/repository/repotest/report_test_cases.go Tests report index ranges.
internal/repository/repotest/output_test_cases.go Tests output ranges and filters.
internal/repository/repotest/input_test_cases.go Tests input index ranges.
internal/repository/repotest/epoch_test_cases.go Tests epoch index ranges.
internal/repository/repository.go Extends repository filters.
internal/repository/postgres/report.go Implements report range filtering.
internal/repository/postgres/output.go Implements output filtering and counts.
internal/repository/postgres/input.go Implements input range filtering.
internal/repository/postgres/epoch.go Implements epoch range filtering.
internal/jsonrpc/util_test.go Closes test repositories.
internal/jsonrpc/types.go Refactors JSON-RPC response encoding.
internal/jsonrpc/limitedwriter.go Adds batch response budgeting.
internal/jsonrpc/jsonrpc.go Adds methods, filters, and batch dispatch.
internal/jsonrpc/jsonrpc-discover.json Updates the OpenRPC specification.
internal/jsonrpc/jsonrpc_test.go Tests new API behavior.
internal/jsonrpc/batchcalls_test.go Tests batch request handling.
internal/jsonrpc/api/response.go Defines node information responses.
internal/jsonrpc/api/params.go Adds parameters and positional decoding.
internal/jsonrpc/api/params_test.go Tests parameter decoding.
cmd/cartesi-rollups-cli/root/read/service/types.go Updates read-service parameter types.
cmd/cartesi-rollups-cli/root/read/service/repository.go Supports multi-value repository filters.
cmd/cartesi-rollups-cli/root/read/service/jsonrpc.go Updates JSON-RPC client validation.
cmd/cartesi-rollups-cli/root/read/outputs/outputs.go Adds output filter flags.
cmd/cartesi-rollups-cli/root/read/matchadvances/matchadvances.go Uses renamed match-advance parameters.
cmd/cartesi-rollups-cli/root/read/epochs/epochs.go Adds repeated status filters.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc-discover.json Outdated
Comment thread cmd/cartesi-rollups-cli/root/read/service/repository.go Outdated
@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch 3 times, most recently from 0f77172 to ea9ccde Compare August 14, 2026 01:22
@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch 8 times, most recently from 3a737ab to 2cbf0a5 Compare August 19, 2026 21:16
@mpolitzer
mpolitzer requested a balanced review from Copilot August 19, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 67 out of 67 changed files in this pull request and generated no new comments.

Suppressed comments (4)

internal/jsonrpc/service.go:45

  • discoverSpec is decoded through any, so JSON numbers become float64. The newly documented offset maximum 9223372036854775807 is not exactly representable and rpc.discover re-encodes it as a different value. Store the parsed document as json.RawMessage (which json.Unmarshal validates and preserves) or decode with UseNumber.
    internal/jsonrpc/limitedwriter.go:13
  • This budget only covers each encoded RPC object. Batch delimiters and every -31003 replacement response are written directly to the underlying http.ResponseWriter, so the complete HTTP body can exceed MAX_RESPONSE_SIZE despite the new documented 10 MiB per-request cap. Route the envelope and fallback responses through the request-level budget, or reserve their bytes before committing entries.
    internal/jsonrpc/types.go:47
  • Changing this helper to io.Writer removed its Content-Type assignment. In the single-object parse-error path, the error is written before handleRPC sets any header, so malformed {... requests now return JSON with an auto-detected non-JSON content type. Set application/json before parsing/switching on the body (and add a regression assertion).
    internal/repository/postgres/schema/migrations/000001_create_initial_schema.up.sql:447
  • Adding these indexes to migration 000001 does not install them on databases already recorded at schema version 1: Upgrade() sees no newer migration and returns no change (schema.go:24,77-81). Those deployments will still scan the full output history for the new count/filter queries. Add a new migration version for the indexes and bump ExpectedVersion rather than editing only the already-applied migration.

@renatomaia

Copy link
Copy Markdown
Author

I added two commits addressing the first and third issues of the Copilot review above.

I’m deferring the second issue for now. The 10 MiB response budget is intended as a practical memory bound rather than a byte-exact HTTP body limit. Batch delimiters and replacement error responses may add a small, bounded overhead, which we consider negligible for the current purpose.

I’m also deferring the fourth issue. We have decided not to introduce a new database migration at this time, based on our current deployment and usage patterns. Fresh databases will include the indexes, but existing schema-version-1 databases will not receive them automatically. We can add a versioned migration later if supporting those upgrades becomes necessary.

@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch from c6b2f9e to d8921d1 Compare August 21, 2026 18:57

@mpolitzer mpolitzer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Found a couple nits, will finish the review monday

Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc.go
Comment thread internal/jsonrpc/jsonrpc.go
Comment thread internal/jsonrpc/jsonrpc.go Outdated
Comment thread internal/jsonrpc/jsonrpc.go
Comment thread internal/jsonrpc/jsonrpc.go
Comment thread internal/jsonrpc/jsonrpc.go
- Omitted params
- Top-level params: null
- Empty positional arrays
- Positional over-arity
- Struct fields marked json:"-"
… a batch

The JSON-RPC server now:

- Calculates 'sum(limit)' for every list operation before dispatching a batch.
- Normalizes limits consistently with handlers:
    - Omitted or zero → 50
    - Above 10,000 → 10,000

- Allows a cumulative limit of exactly 10,000.
- Rejects totals above 10,000 before any handler or database query runs.
- Returns one batch-level -31003 error: Batch list item limit exceeded.
- Supports both named and positional parameters across every list method.
- Includes a registry coverage test so future list methods cannot silently
  bypass the budget.

The client contract is documented in 'jsonrpc-discover.json', and operator
guidance—including the residual unbounded 'COUNT(*)' cost—is documented in
'docs/http-posture.md'.
…imeout to avoid incomplete responses

- Added a 25-second JSON-RPC dispatch timeout, leaving five seconds before the HTTP 30-second WriteTimeout.
- Applied the deadline at the top of handleRPC, propagating it through request dispatch.
- Added an integration-style regression test through the actual server handler, verifying remaining batch entries receive -32070 responses.
- Focused JSON-RPC regression tests pass.
- Added shared validation rejecting list offsets above math.MaxInt64 with JSON-RPC -32602 / "Invalid offset".
- Validation occurs before repository access, preventing negative int64 conversion and erroneous operator alarms.
- Covers all ten list methods plus named and positional parameters.
- Updated every OpenRPC offset schema with maximum: 9223372036854775807.
…ed clients

- Added a shared repository-error handler that passes wrapped context.Canceled errors through without Error logging.
- Updated all JSON-RPC repository failure paths to use it.
- Request dispatch now silently stops on cancellation without writing an internal-error response.
- context.DeadlineExceeded retains existing logging and response behavior.
- Added regression coverage for cancellation during an active repository operation.
- RPC method names are now capped at 64 bytes in every log path.
- Truncation preserves valid UTF-8.
- Single-request method visibility remains at Info.
- Batch-entry method logging remains at Debug.
- Updated and added tests verifying long method names are truncated and never logged in full.
… batch

- Added per-entry panic recovery around dispatchOneRequest.
- Panics are logged at Error with the method, panic value, and stack trace.
- The affected entry receives JSON-RPC -32603.
- Its private response buffer is discarded.
- Remaining batch entries continue normally.
- Added regression coverage proving the batch remains valid after a middle-entry panic.
- List input/output decoding failures now log per-row details at Debug instead of Error.
- Each list operation emits one aggregate Warn containing:
    - Application
    - Failure count
    - First failing index
- Malformed rows remain in responses as partial decoded structures.
- Added regression coverage verifying four malformed rows produce four Debug logs, two aggregate Warns, and no Error logs.
…errors

- Request and response IDs now use json.RawMessage.
- Numeric and string IDs are echoed without decoding or precision loss.
- Validation still accepts omitted, null, string, and numeric IDs.
- Boolean, array, and object IDs remain invalid and receive a null response ID.
- Updated existing batch assertions for raw IDs.
- Added exact round-trip coverage for:
    - 9007199254740993
    - Values beyond uint64
    - String IDs
    - Both success and error responses
…large offsets

- Updated docs/http-posture.md to clarify that the batch budget does not meter offset traversal.
- Updated the OpenRPC x-batch-list-work-budget description with the same caveat.
- Documented that traversal cost is bounded by the filtered set size, not the numeric offset, while PostgreSQL may still scan and discard matching rows.
- Added partial index output_executed_idx on input_epoch_application_id.
- The index contains only rows where execution_transaction_hash IS NOT NULL.
- Added the corresponding down-migration statement.
The memory model now documents:

- 64 MiB of JSON-RPC request buffers.
- Up to 640 MiB of response buffers.
- Approximately 704 MiB combined.
- Additional unbounded working memory from repository rows and decoded objects materialized before response-size enforcement.
…ne another

- Added a PostgreSQL advisory lock held for the full test-process lifetime.
- Applied it to all three schema-resetting packages:
    - internal/jsonrpc
    - internal/repository/postgres
    - test/validator

- JSON-RPC services now clone the handler dispatch table.
- Test handlers modify only their service instance, not the package-global map.
- Added a regression test proving handler overrides do not leak across services.
`revive`'s `var-naming` rule reports the package-name violation only once per
package, but the diagnostic location is not tied to one stable source file.

When we added `//nolint:revive` to the reported package declaration, that file
was excluded from the analysis and `revive` emitted the same package-level
warning against another file's `package api` or `package jsonrpc` declaration.
Meanwhile, `nolintlint` saw no diagnostic on the original line and reported the
directive as unused.

So a source directive caused this cycle:

1. Suppress the warning in one file.
2. revive reports it against another file in the same package.
3. nolintlint reports the first suppression as unused.

The `.golangci.yml` exclusions instead match the diagnostic across the entire
relevant package path and only for the two precise warning texts. Other `revive`
checks remain enabled:

- `internal/jsonrpc/api`: permits the established `api` name.
- `internal/jsonrpc`: permits the established `jsonrpc` name despite its
  collision with a standard-library package name.

Renaming the packages would also remove the warnings, but that would require a
broad, unnecessary API and import change solely to satisfy a naming preference.
…nses

- Sets Content-Type: application/json before switching/parsing the request body.
- Removes redundant branch-specific assignments.
- Adds a regression test for malformed single-object input.
…scover'

- Changed Service.discoverSpec from any to json.RawMessage.
- Retained json.Unmarshal, validating and copying the embedded JSON without converting numbers to float64.
- Added a regression test asserting rpc.discover returns the exact literal 9223372036854775807.
- Added specific messages for invalid IDs and unsupported JSON-RPC versions.
- Preserved empty-method validation as -32600.
- Normalized standard messages to Parse error and Invalid Request.
- Added regression assertions for the new messages.
@renatomaia
renatomaia force-pushed the feature/JsonRpcApiImprovements branch from e0942ca to 7558af6 Compare August 24, 2026 16:21

@mpolitzer mpolitzer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is great work!

@renatomaia
renatomaia merged commit 7558af6 into next/2.0 Aug 24, 2026
20 checks passed
@renatomaia
renatomaia deleted the feature/JsonRpcApiImprovements branch August 24, 2026 17:33
@github-project-automation github-project-automation Bot moved this from Waiting Merge to Done in Rollups SDK Aug 24, 2026
tuler pushed a commit to cartesi/rollups-ts that referenced this pull request Aug 24, 2026
Mirror the node API changes of cartesi/rollups-node#793 in @cartesi/rpc,
and bubble them down to @cartesi/client and @cartesi/react.

New methods:

- cartesi_getEpochByVirtualIndex, fetching an epoch by its dense
  insertion rank (getEpochByVirtualIndex / useEpochByVirtualIndex)
- cartesi_getExecutedOutputCount and
  cartesi_getPendingExecutableOutputCount (getExecutedOutputCount /
  useExecutedOutputCount, getPendingExecutableOutputCount /
  usePendingExecutableOutputCount)
- cartesi_getNodeInfo, returning the chain id, the node version and the
  node's default block tag in one call (getNodeInfo / useNodeInfo). It
  replaces cartesi_getChainId and cartesi_getNodeVersion, which the node
  deprecated and which are now marked @deprecated here too.

New listing filters:

- from/to inclusive index ranges on listEpochs, listInputs, listOutputs
  and listReports
- a list of statuses on listEpochs, and a list of output types plus the
  new executed flag on listOutputs

Breaking changes:

- cartesi_getMatchAdvanced is now cartesi_getMatchAdvance, so the
  getMatchAdvanced action is getMatchAdvance, the useMatchAdvanced hook
  is useMatchAdvance and the GetMatchAdvanced* types are GetMatchAdvance*
- the node's application-level error codes moved out of the JSON-RPC
  reserved range (-31001/-31002 instead of -32001/-32002); they are now
  exported from @cartesi/rpc as errorCodes, along with the new batch,
  timeout and response-size-limit codes

Also reformats four @cartesi/react hooks that biome was already
reporting as unformatted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJpa3KXxvUarBGpHvW8Qdb
tuler pushed a commit to cartesi/rollups-ts that referenced this pull request Aug 24, 2026
Mirror the JSON-RPC API changes of the Cartesi node in @cartesi/rpc, and
bubble them down to @cartesi/client and @cartesi/react.

Derived from cartesi/rollups-node#793, which has since merged into
next/2.0 as 7558af6, so this is no longer a forward-looking port. It was
verified against the merged jsonrpc-discover.json rather than the pull
request diff: @cartesi/rpc declares exactly the 28 methods the merged
specification defines, and every schema and parameter change between the
pre-793 base (9bdd988) and merged next/2.0 is reflected here.
Cross-checked against internal/jsonrpc/api/params.go,
internal/jsonrpc/jsonrpc.go and internal/model/models.go.

New methods:

- cartesi_getEpochByVirtualIndex, fetching an epoch by its dense
  insertion rank (getEpochByVirtualIndex / useEpochByVirtualIndex)
- cartesi_getExecutedOutputCount and
  cartesi_getPendingExecutableOutputCount (getExecutedOutputCount /
  useExecutedOutputCount, getPendingExecutableOutputCount /
  usePendingExecutableOutputCount). The executed count is monotone and
  meant to be polled for change detection; the pending count is a gauge
  and is not.
- cartesi_getNodeInfo, returning the chain id, the node version and the
  node's default block tag in one call (getNodeInfo / useNodeInfo). It
  replaces cartesi_getChainId and cartesi_getNodeVersion, which the node
  deprecated and which are now marked @deprecated here too.

New listing filters:

- from/to inclusive index ranges on listEpochs, listInputs, listOutputs
  and listReports
- a list of statuses on listEpochs, and a list of output types plus the
  new executed flag on listOutputs

The node rejects an empty status or output_type list with invalid
params, so the list-valued filters are typed as NonEmptyArray<T> rather
than T[]: `status: []` and `outputType: []` are compile errors instead
of failed requests. listOutputs maps the output types to selectors
through the head of the list separately, so the result stays non-empty
for the type checker, which Array.prototype.map would widen back to
Hex[]. The constraint is guarded by a *.test-d.ts suite in
@cartesi/client, which needed vitest type testing enabled there — CI
runs `pnpm test` but no `tsc --noEmit` over the test files, so without
it the constraint would go unchecked.

Input completion changes, which landed on next/2.0 alongside but not as
part of #793:

- InputStatus loses its resource-limit members. The node collapsed
  OUTPUTS_LIMIT_EXCEEDED, REPORTS_LIMIT_EXCEEDED, CYCLE_LIMIT_EXCEEDED,
  TIME_LIMIT_EXCEEDED and PAYLOAD_LENGTH_LIMIT_EXCEEDED into the
  remaining outcomes, leaving NONE, ACCEPTED, REJECTED, EXCEPTION and
  MACHINE_HALTED. waitForInput listed four of them under rejectErrors;
  it now aborts on EXCEPTION, MACHINE_HALTED and REJECTED, which is
  every terminal status other than ACCEPTED — and no longer omits a
  failure status the way the old list omitted REPORTS_LIMIT_EXCEEDED.
- Input gains exception_data / exceptionData, the raw guest-provided
  CMIO exception payload, non-null only when the status is EXCEPTION and
  empty-encoded as 0x. The bytes are passed through undecoded, matching
  how raw_data is handled.

Breaking changes:

- cartesi_getMatchAdvanced is now cartesi_getMatchAdvance, so the
  getMatchAdvanced action is getMatchAdvance, the useMatchAdvanced hook
  is useMatchAdvance and the GetMatchAdvanced* types are GetMatchAdvance*
- the node's application-level error codes moved out of the JSON-RPC
  reserved range (-31001/-31002 instead of -32001/-32002); they are now
  exported from @cartesi/rpc as errorCodes, along with the new batch
  (-32040), timeout (-32070), response-size-limit (-31003) and
  batch-list-work (-31004) codes, plus the maxBatchSize (100),
  maxBatchListWork (10000) and defaultListLimit (50) constants that
  bound a batch
- InputStatus shrank, as described above

Batch requests needed no transport change — the underlying json-rpc-2.0
client already batches — so they are documented rather than implemented,
including the two budgets that apply beyond the entry count: the
response-size budget closes once exhausted, so every later entry gets
-31003 even if its response would still have fit, and the list-work
budget rejects the whole batch with a single -31004 before dispatching
anything. Neither meters the COUNT queries behind pagination nor offset
traversal, so a deep offset over a broad filter can still make the
database scan and discard rows before the requested page.

Two OpenRPC typing fixes needed no code change: prev_randao and voucher
value are now UnsignedInteger256 in the specification, and both were
already 256-bit-safe here.

Also reformats four @cartesi/react hooks that biome was already
reporting as unformatted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJpa3KXxvUarBGpHvW8Qdb
tuler pushed a commit to cartesi/rollups-ts that referenced this pull request Aug 24, 2026
Mirror the JSON-RPC API changes of the Cartesi node in @cartesi/rpc, and
bubble them down to @cartesi/client and @cartesi/react.

Derived from cartesi/rollups-node#793, which has since merged into
next/2.0 as 7558af6, so this is no longer a forward-looking port. It was
verified against the merged jsonrpc-discover.json rather than the pull
request diff: @cartesi/rpc declares exactly the 28 methods the merged
specification defines, and every schema and parameter change between the
pre-793 base (9bdd988) and merged next/2.0 is reflected here.
Cross-checked against internal/jsonrpc/api/params.go,
internal/jsonrpc/jsonrpc.go and internal/model/models.go.

New methods:

- cartesi_getEpochByVirtualIndex, fetching an epoch by its dense
  insertion rank (getEpochByVirtualIndex / useEpochByVirtualIndex)
- cartesi_getExecutedOutputCount and
  cartesi_getPendingExecutableOutputCount (getExecutedOutputCount /
  useExecutedOutputCount, getPendingExecutableOutputCount /
  usePendingExecutableOutputCount). The executed count is monotone and
  meant to be polled for change detection; the pending count is a gauge
  and is not.
- cartesi_getNodeInfo, returning the chain id, the node version and the
  node's default block tag in one call (getNodeInfo / useNodeInfo). It
  replaces cartesi_getChainId and cartesi_getNodeVersion, which the node
  deprecated and which are now marked @deprecated here too.

New listing filters:

- from/to inclusive index ranges on listEpochs, listInputs, listOutputs
  and listReports
- a list of statuses on listEpochs, and a list of output types plus the
  new executed flag on listOutputs

The node rejects an empty status or output_type list with invalid
params, so the list-valued filters are typed as NonEmptyArray<T> rather
than T[]: `status: []` and `outputType: []` are compile errors instead
of failed requests. listOutputs maps the output types to selectors
through the head of the list separately, so the result stays non-empty
for the type checker, which Array.prototype.map would widen back to
Hex[]. The constraint is guarded by a *.test-d.ts suite in
@cartesi/client, which needed vitest type testing enabled there — CI
runs `pnpm test` but no `tsc --noEmit` over the test files, so without
it the constraint would go unchecked.

Input completion changes, which landed on next/2.0 alongside but not as
part of #793:

- InputStatus loses its resource-limit members. The node collapsed
  OUTPUTS_LIMIT_EXCEEDED, REPORTS_LIMIT_EXCEEDED, CYCLE_LIMIT_EXCEEDED,
  TIME_LIMIT_EXCEEDED and PAYLOAD_LENGTH_LIMIT_EXCEEDED into the
  remaining outcomes, leaving NONE, ACCEPTED, REJECTED, EXCEPTION and
  MACHINE_HALTED. waitForInput listed four of them under rejectErrors;
  it now aborts on EXCEPTION, MACHINE_HALTED and REJECTED, which is
  every terminal status other than ACCEPTED — and no longer omits a
  failure status the way the old list omitted REPORTS_LIMIT_EXCEEDED.
- Input gains exception_data / exceptionData, the raw guest-provided
  CMIO exception payload, non-null only when the status is EXCEPTION and
  empty-encoded as 0x. The bytes are passed through undecoded, matching
  how raw_data is handled.

Breaking changes:

- cartesi_getMatchAdvanced is now cartesi_getMatchAdvance, so the
  getMatchAdvanced action is getMatchAdvance, the useMatchAdvanced hook
  is useMatchAdvance and the GetMatchAdvanced* types are GetMatchAdvance*
- the node's application-level error codes moved out of the JSON-RPC
  reserved range (-31001/-31002 instead of -32001/-32002); they are now
  exported from @cartesi/rpc as errorCodes, along with the new batch
  (-32040), timeout (-32070), response-size-limit (-31003) and
  batch-list-work (-31004) codes, plus the maxBatchSize (100),
  maxBatchListWork (10000) and defaultListLimit (50) constants that
  bound a batch
- InputStatus shrank, as described above

Batch requests needed no transport change — the underlying json-rpc-2.0
client already batches — so they are documented rather than implemented,
including the two budgets that apply beyond the entry count: the
response-size budget closes once exhausted, so every later entry gets
-31003 even if its response would still have fit, and the list-work
budget rejects the whole batch with a single -31004 before dispatching
anything. Neither meters the COUNT queries behind pagination nor offset
traversal, so a deep offset over a broad filter can still make the
database scan and discard rows before the requested page.

Two OpenRPC typing fixes needed no code change: prev_randao and voucher
value are now UnsignedInteger256 in the specification, and both were
already 256-bit-safe here.

Also reformats four @cartesi/react hooks that biome was already
reporting as unformatted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJpa3KXxvUarBGpHvW8Qdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants