feat: track the rollups-node JSON-RPC API changes - #161
Draft
tuler wants to merge 3 commits into
Draft
Conversation
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
🦋 Changeset detectedLatest commit: fcff0f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The node rejects an empty `status` or `output_type` list with invalid params, so type the list-valued filters as `NonEmptyArray<T>` rather than `T[]`: `status: []` and `outputType: []` are now compile errors instead of failed requests. `listOutputs` maps the output types to selectors through the head of the list separately, so the result stays a non-empty array for the type checker, which `Array.prototype.map` would widen back to `Hex[]`. 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. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UJpa3KXxvUarBGpHvW8Qdb
The upstream branch was force-pushed (ea9ccde -> a5d2cef), squashing the
fixups and adding a batch list-work budget on top.
- new error code -31004 (batch list item limit exceeded), exported as
`errorCodes.batchListItemLimitExceeded`, with the `maxBatchListWork`
(10000) and `defaultListLimit` (50) constants that define the budget:
the node sums the effective limit of every list entry in a batch and
rejects the whole batch before dispatching any of it
- the response-size budget is now documented as closing once exhausted,
so every later entry of the batch gets -31003 too, even one whose
response would still have fit
- the executed-output sync pattern gained a step: on a change of
`getExecutedOutputCount`, diff the pending set from `listOutputs`
against its previous result, rather than just re-reading it. The node
documents a race-free execution cursor as future work
- the epoch watch pattern now separates discovery (advance `from`) from
refresh (filter seen epochs by non-terminal status)
- `default_block` is documented as the node's finality contract
No wire-shape change: the two output counts got their own result schemas
upstream, but both are `{ data: UnsignedInteger }`, which the separate
return types here already matched. The API still rejects empty `status`
and `output_type` lists, so `NonEmptyArray` stands; the upstream
repository fix for empty type lists sits below that check.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UJpa3KXxvUarBGpHvW8Qdb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors the node API changes of cartesi/rollups-node#793 in
@cartesi/rpc, and bubbles them down to@cartesi/clientand@cartesi/react.Derived from the
internal/jsonrpc/jsonrpc-discover.jsondiff against that PR's base (next/2.0), cross-checked againstinternal/jsonrpc/api/params.goandinternal/jsonrpc/jsonrpc.go. Tracked up to upstream heada5d2cef(the branch was force-pushed after the first commit here; the second sync is the third commit).New methods
@cartesi/client@cartesi/reactcartesi_getEpochByVirtualIndexgetEpochByVirtualIndexuseEpochByVirtualIndexcartesi_getExecutedOutputCountgetExecutedOutputCountuseExecutedOutputCountcartesi_getPendingExecutableOutputCountgetPendingExecutableOutputCountusePendingExecutableOutputCountcartesi_getNodeInfogetNodeInfouseNodeInfogetNodeInforeturns the chain id, the semantic node version and the node's default block tag in a single call. It replacesgetChainIdandgetNodeVersion, which the node deprecated and which are now marked@deprecatedhere too — they still work.defaultBlockis documented as the node's finality contract: everything the node exposes carries that tag's stability guarantees.New listing filters
from/to, an inclusive index range, onlistEpochs,listInputs,listOutputsandlistReports.listEpochstakes a list of statuses (status?: EpochStatus | NonEmptyArray<EpochStatus>).listOutputstakes a list of output types (outputType?: OutputType | NonEmptyArray<OutputType>) and a newexecuted?: booleanfilter.The node rejects an empty filter list with invalid params, so both list-valued filters use a new
NonEmptyArray<T> = [T, ...T[]]type exported by@cartesi/rpcand re-exported by@cartesi/client:status: []andoutputType: []are compile errors rather than failed requests. Note this is stricter than a plain array in both directions — it also rejects anEpochStatus[]-typed variable, so callers building lists dynamically should type them asNonEmptyArray<EpochStatus>.Synchronization patterns
These are the node's documented patterns, mirrored in the JSDoc and docs pages of all three packages:
fromto the next unseen epoch index to discover new epochs, and refresh the epochs already seen by filtering them on the non-terminal statuses. Terminal statuses never regress, so a settled epoch leaves the refresh set for good.getExecutedOutputCount(monotone) and, when it changes, re-query the bounded executable-output working set withexecuted: falseandoutputType: ["Voucher", "DelegateCallVoucher"], then diff that pending set against the previous result to identify the executions.getPendingExecutableOutputCountis a gauge and must not be used for change detection.No resume cursor over the
executedfilter is sound — not an output index, a pagination offset, or the executed count — because executions are observed out of output-index order. The node documents a race-free execution cursor as expected in a future ingestion API.Breaking changes
cartesi_getMatchAdvancedwas renamed tocartesi_getMatchAdvance, following the node. The action is nowgetMatchAdvance, the hook isuseMatchAdvance(withmatchAdvanceOptions/matchAdvanceQueryKey), andGetMatchAdvancedParams/GetMatchAdvancedReturnTypeare nowGetMatchAdvanceParams/GetMatchAdvanceReturnType. No back-compat aliases were kept — these packages are on2.0.0-alphaprereleases and the node made the same break. The entity typeMatchAdvancedkeeps its name, matching the node'sMatchAdvancedGetResultschema.-31002(was-32002) and resource not found is now-31001(was-32001).Error codes and batch limits
@cartesi/rpcnow exports the node's codes aserrorCodes, including the new batch (-32040), timeout (-32070), response-size-limit (-31003) and batch-list-work (-31004) ones, alongside the constants that bound a batch:maxBatchSize(100),maxBatchListWork(10 000) anddefaultListLimit(50).Two budgets apply to a batch beyond its entry count:
-31003; the budget then closes, so every later entry gets-31003too, even one that would still have fit.limitof every list entry, counting an omitted or zero limit asdefaultListLimitand capping each entry atmaxBatchListWork. A total abovemaxBatchListWorkrejects the whole batch with a single-31004and dispatches nothing.Notes
json-rpc-2.0client already batches — so they are documented rather than implemented.{ data: UnsignedInteger }, which the separate return types here already matched. No wire-shape change.statusandoutput_typelists with invalid params, soNonEmptyArraycontinues to match node behavior.prev_randaoand vouchervalueare now typed as 256-bit hex in the spec, which is what the wire types and converters already assumed.chainIdinNodeInfois anumber, matching what the existinggetChainIdaction returns.listOutputsmaps output types to selectors through the head of the list separately, becauseArray.prototype.mapwould widen the tuple back toHex[]. That keeps non-emptiness proven rather than asserted.@cartesi/reacthooks (useApplication,useCommitments,useTournaments,useWithdrawals) were already failingbiome checkon the base branch for import formatting; this branch lets biome fix them sopnpm lintpasses.Testing
pnpm lintclean across the workspace.@cartesi/client(11),@cartesi/react(122),@cartesi/codec(70) and@cartesi/rollup(24) suites pass. Coverage added for the newnodeInfoConverter, the renamed match-advance query keys, and the stringification of the newfrom/tobigints in every listing query key.__tests__/params.test-d.tstype suite, which required enabling vitest type testing in@cartesi/client— CI runspnpm testbut notsc --noEmitover test files, so without it a regression would go unnoticed. Verified non-vacuous: reverting the type toEpochStatus[]makes the suite fail, includingUnused '@ts-expect-error' directive.@cartesi/machine's suite is not run here — it needs an installed cartesi-machine emulator — and is untouched by this change.A changeset marking all three packages
majoris included.