gRPC: honour `FieldMask` in UTxO RPC requests in cardano-rpc
Maintainer thường phản hồi trong vòng 2 ngày
@carbolymer đang làm issue này rồi.
Từ ngày 30/7/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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).
- Ngôn ngữ chính
- Haskell
- Star
- 41
- Fork
- 33
- Merge trung bình
- 3 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 15
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của IntersectMBO/cardano-api
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
IntersectMBO/cardano-api#1434 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`Prelude.maximum: empty list` crash in fee estimation for empty `RequireAnyOf` (`{"type": "any", "scripts": []}`) scriptsCó thể đã có người làm @Jimbo4350 đã nhận 8 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
IntersectMBO/cardano-api#1424 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 53/100
IntersectMBO/cardano-api#1431 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
type: enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
IntersectMBO/cardano-api#1423 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Add a dedicated transaction viewing type to the experimental APICó thể đã có người làm @palas đã nhận 21 ngày trước. Đang mởtype: enhancement
IntersectMBO/cardano-api#1416 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của IntersectMBO/cardano-api
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
haskell/bytestring#730 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
seal-harness/seal-harness#399 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
add previously overlooked rulesĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
fmidue/codeworld-tasks#124 ·
-
allow haskell-src-exts-1.24Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
reflex-frp/reflex#563 ·