ITADN

gRPC: Populate timestamp field in ChainPoint RPC responses

#1133Closedcarbolymer 创建于 2026-03-13
C
carbolymercommented
## Problem The UTxO RPC `ChainPoint` proto message defines a `timestamp` field (field 4, `uint64`, milliseconds), but it is never populated by `mkChainPointMsg`. It always defaults to `0`. This affects all RPC responses that include a `ledgerTip`, specifically `readParams` and `readUtxos`. The test at `Cardano.Testnet.Test.Rpc.Query` (line 102) documents this: ```haskell pparamsResponse ^. U5c.ledgerTip . U5c.timestamp === 0 -- not possible to implement at this moment ``` ## Proposed solution The information needed to compute the timestamp is available via existing local state queries. The RPC handler methods (`readParamsMethod`, `readUtxosMethod`) already call `executeLocalStateQueryExpr` — two additional queries can be added to the same expression: 1. `querySystemStart` → `SystemStart` (chain genesis `UTCTime`) 2. `queryEraHistory` → `EraHistory` (era boundaries and slot lengths) With those, the conversion is: ```haskell import Cardano.Api (getProgress, EraHistory) import Cardano.Slotting.Time (fromRelativeTime, SystemStart) slotToUTCTime :: SystemStart -> EraHistory -> SlotNo -> Either PastHorizonException UTCTime slotToUTCTime systemStart eraHistory slotNo = do (relTime, _slotLen) <- getProgress slotNo eraHistory pure $ fromRelativeTime systemStart relTime ``` The resulting `UTCTime` then needs to be converted to POSIX milliseconds (`Word64`) for the proto field. ## Changes required - **`Cardano.Rpc.Server.Internal.UtxoRpc.Query`** — add `querySystemStart` and `queryEraHistory` to the `executeLocalStateQueryExpr` blocks in `readParamsMethod` and `readUtxosMethod`; compute the timestamp and pass it to `mkChainPointMsg` - **`Cardano.Rpc.Server.Internal.UtxoRpc.Type`** — update `mkChainPointMsg` signature to accept the computed timestamp (or `SystemStart` + `EraHistory`) and set the `U5c.timestamp` field - **`Cardano.Testnet.Test.Rpc.Query`** (in `cardano-node`) — update the assertion on line 102 to check the actual expected timestamp instead of `0`
关闭于 2026-03-31 0 条评论