gRPC: honour `FieldMask` in UTxO RPC requests in cardano-rpc
Maintainers usually reply within 2 days
@carbolymer is already working on this.
Since Jul 30, 2026.
Assessment
This issue has not been assessed yet.
Description
Context
Every UTxO RPC service includes a google.protobuf.FieldMask in its request messages, letting clients select which response fields the server should materialise.
cardano-rpc currently ignores it everywhere; the only trace is a TODO in readParamsMethod (Cardano/Rpc/Server/Internal/UtxoRpc/Query.hs), which notes that masks need to be normalised before use, following the semantics of protobuf's FieldMaskTree.
Request messages carrying a field_mask:
| Service | Message | Method implemented today |
|---|---|---|
| QueryService | ReadParamsRequest |
yes |
| QueryService | ReadUtxosRequest |
yes |
| QueryService | SearchUtxosRequest |
yes |
| QueryService | ReadGenesisRequest |
yes |
| QueryService | ReadEraSummaryRequest |
no |
| QueryService | ReadDataRequest |
no |
| QueryService | ReadTxRequest |
no |
| SyncService | FetchBlockRequest |
yes |
| SyncService | FollowTipRequest |
yes (#1268) |
| SyncService | DumpHistoryRequest |
no |
| SubmitService | WatchMempoolRequest |
no |
Motivation
Two distinct wins:
- Bandwidth: responses like
AnyChainBlockcarry both raw CBOR (native_bytes) and the fully parsedcardanoblock.
A client interested only in headers, or only in raw bytes, currently receives everything.
#1219 already flags this ("FieldMaskbecomes valuable for letting clients request only headers, or only transaction hashes"). - Server-side cost: raised in review of #1268 (https://github.com/IntersectMBO/cardano-api/pull/1268#discussion_r3676653326) -
FetchBlockand everyFollowTipstream fetch two block components per block,GetRawBlockandGetBlock, and theGetBlockdecode is paid unconditionally.
A mask excluding the parsedcardanofields would let the server select theBlockComponentper request and skip block deserialisation entirely.
Proposed behaviour
- An absent or empty mask means "return all fields" (standard
FieldMaskread semantics); current behaviour is therefore already correct for clients that send no mask. - A non-empty mask is normalised first (deduplicate, drop paths covered by an ancestor path), following the semantics of protobuf's
FieldMaskTreelinked above. - The mask drives response construction, not post-hoc pruning: handlers consult the mask before doing the work behind each field, so data that is masked out is never fetched, decoded, or converted in the first place.
Building the full response and then stripping fields would deliver the bandwidth win but none of the server-side cost win, which is the harder and more valuable half. - Invalid paths: follow the protobuf recommendation for read masks - ignore unknown paths rather than failing the request (to be confirmed against what other UTxO RPC servers, e.g. Dolos, do).
Implementation sketch
- A shared mask-query helper in cardano-rpc: normalise a
FieldMaskinto a path tree and expose "is this path (or any child of it) requested?" for handlers to branch on. - Wire it into the implemented handlers (
ReadParams,ReadUtxos,SearchUtxos,ReadGenesis,FetchBlock,FollowTip): each expensive field (protocol parameter conversion, UTxO parsing, tx conversion) is computed only when its path is requested. FollowTip/FetchBlockfetch-avoidance: when the mask excludes all parsedcardano.*paths, fetch onlyGetRawBlockand skipGetBlock; when it excludesnative_bytes, fetch onlyGetBlock.
This changes theBlockComponentselected inNodeKernelAccess, so the follower/fetch component becomes a function of the request.- Unmentioned future handlers (
ReadEraSummary,ReadData,ReadTx,DumpHistory,WatchMempool) apply the same helper when they land.
Acceptance criteria
- Empty/absent mask returns full responses (no behaviour change for existing clients).
- Masked unary responses contain only the requested paths, with mask normalisation applied.
-
FollowTipandFetchBlockskip the block decode when the mask excludes all parsed block fields, and skip raw-bytes fetch when the mask excludesnative_bytes. - Unknown mask paths are handled per the documented policy (ignored or rejected - decided and documented).
- Unit tests cover mask normalisation and masked response construction; conformance checked against another UTxO RPC server (e.g. Dolos) via the existing comparison tooling.
- README coverage table updated to note
FieldMasksupport.
Out of scope
- Field masks on methods not yet implemented (they inherit the helper when implemented).
- Write masks / update semantics (
FieldMaskis used purely as a read mask in UTxO RPC).
- Dominant language
- Haskell
- Stars
- 41
- Forks
- 33
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 15
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from IntersectMBO/cardano-api
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cardano-api#1434 ·
Maintainers usually reply within 2 days
-
`Prelude.maximum: empty list` crash in fee estimation for empty `RequireAnyOf` (`{"type": "any", "scripts": []}`) scriptsPossibly taken @Jimbo4350 claimed this 8 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-api#1424 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 53/100
IntersectMBO/cardano-api#1431 ·
Maintainers usually reply within 2 days
-
type: enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
IntersectMBO/cardano-api#1423 ·
Maintainers usually reply within 2 days
-
Add a dedicated transaction viewing type to the experimental APIPossibly taken @palas claimed this 21 days ago. Opentype: enhancement
IntersectMBO/cardano-api#1416 · 1 assignee ·
Maintainers usually reply within 2 days
All issues in IntersectMBO/cardano-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
haskell/bytestring#730 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
seal-harness/seal-harness#399 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
fmidue/codeworld-tasks#124 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
reflex-frp/reflex#563 ·