| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Cardano.Rpc.Server.Internal.UtxoRpc.Sync
Description
Handlers for the UTxO RPC SyncService - synchronising chain data
(fetching blocks, dumping history, following the tip).
Synopsis
- fetchBlockMethod :: MonadRpc e m => Proto FetchBlockRequest -> m (Proto FetchBlockResponse)
- fetchBlockResponse :: MonadIO m => (CardanoBlockComponent (m AnyChainBlock) -> SlotNo -> Hash BlockHeader -> m (Maybe (m AnyChainBlock))) -> (SlotNo -> m UTCTime) -> FieldMaskTree FetchBlockResponse -> [(SlotNo, Hash BlockHeader)] -> m FetchBlockResponse
- followTipMethod :: MonadRpc e m => Proto FollowTipRequest -> (NextElem (Proto FollowTipResponse) -> IO ()) -> m ()
- followTipAppliedRead :: Applicative m => (SlotNo -> m UTCTime) -> FieldMaskTree FollowTipResponse -> CardanoBlockComponent ((SlotNo, Hash BlockHeader), m AnyChainBlock)
- followTipUndoneRead :: Applicative m => (SlotNo -> m UTCTime) -> FieldMaskTree FollowTipResponse -> CardanoBlockComponent (m AnyChainBlock)
- followTipStream :: (HasCallStack, MonadIO m) => ChainFollower ((SlotNo, Hash BlockHeader), m AnyChainBlock) -> m (Maybe BlockRef) -> (ChainPoint -> m (Maybe (m AnyChainBlock))) -> Int -> FieldMaskTree FollowTipResponse -> (NextElem (Proto FollowTipResponse) -> IO ()) -> [ChainPoint] -> m ()
- readTipMethod :: MonadRpc e m => Proto ReadTipRequest -> m (Proto ReadTipResponse)
Documentation
Arguments
| :: MonadRpc e m | |
| => Proto FetchBlockRequest | Request containing block references (slot + hash) |
| -> m (Proto FetchBlockResponse) | Response containing the fetched blocks with raw CBOR and cardano header |
Handle the FetchBlock SyncService RPC method.
Fetches blocks from ChainDB by slot and header hash.
Byron-era transactions carry no fee: Byron fees are implicit (inputs minus
outputs) and computing them needs UTxO lookups this handler does not do.
Returns NOT_FOUND if any requested block is missing, whatever the field mask selects.
Returns INVALID_ARGUMENT if a block reference has an invalid hash.
Honours the field mask: see fetchBlockResponse.
Arguments
| :: MonadIO m | |
| => (CardanoBlockComponent (m AnyChainBlock) -> SlotNo -> Hash BlockHeader -> m (Maybe (m AnyChainBlock))) | Read block components from ChainDB by slot and header hash, |
| -> (SlotNo -> m UTCTime) | Convert a slot to its wall-clock timestamp |
| -> FieldMaskTree FetchBlockResponse | Selects the fields to fill |
| -> [(SlotNo, Hash BlockHeader)] | The slot and header hash of each requested block |
| -> m FetchBlockResponse |
The FetchBlock response for the requested blocks. Each block reads only the
components its selected fields need (see anyChainBlockRead). A missing block
is reported whatever the mask selects: with no block field selected, ChainDB
only checks that the block exists.
Arguments
| :: MonadRpc e m | |
| => Proto FollowTipRequest | Request containing optional intersection points (slot + hash) |
| -> (NextElem (Proto FollowTipResponse) -> IO ()) | Callback used to send each streamed response |
| -> m () |
Handle the FollowTip SyncService RPC method: stream fully parsed
blocks as the chain advances.
Where the stream starts: at the first of the request's intersection points found on the chain, in client preference order. A block ref with an empty hash means origin. An empty intersect list means the current tip.
What the client receives: first a reset announcing the start point,
then an apply per adopted block. A rollback becomes undo actions
carrying the rolled-back blocks, re-fetched from ChainDB and streamed
newest first. When the blocks can no longer be re-fetched, because
garbage collection won the race against the client, the rollback
becomes a reset carrying the rollback point's BlockRef instead,
slot and hash only, like ChainSync's MsgRollBackward. The tracked
window is sized to the node's security parameter k, so no rollback
consensus can produce falls outside it (see
securityParam).
Every response also carries the current chain tip.
Honours the field mask on every response: a block reads only the components its
selected fields need (see followTipAppliedRead), and the tip is read only for tip.
Errors: INVALID_ARGUMENT if an intersection block ref has an invalid
hash, NOT_FOUND if none of the intersection points are on the chain.
Runs until the client disconnects or the stream is otherwise closed;
withFollowerReading closes the follower on every exit path.
Arguments
| :: Applicative m | |
| => (SlotNo -> m UTCTime) | Convert a slot to its wall-clock timestamp |
| -> FieldMaskTree FollowTipResponse | The field mask of the request |
| -> CardanoBlockComponent ((SlotNo, Hash BlockHeader), m AnyChainBlock) |
What a FollowTip stream reads of each block it applies: the block's point,
which the stream tracks for undo, and the components its apply payload needs.
Arguments
| :: Applicative m | |
| => (SlotNo -> m UTCTime) | Convert a slot to its wall-clock timestamp |
| -> FieldMaskTree FollowTipResponse | The field mask of the request |
| -> CardanoBlockComponent (m AnyChainBlock) |
What a FollowTip stream re-reads of each block it undoes: the components its
undo payload needs. With undo unselected, ChainDB still checks the block is there.
Arguments
| :: (HasCallStack, MonadIO m) | |
| => ChainFollower ((SlotNo, Hash BlockHeader), m AnyChainBlock) | Follower to stream changes from. Each applied block comes with its point
and the action that builds its |
| -> m (Maybe BlockRef) | Read the current chain tip, projected into a |
| -> (ChainPoint -> m (Maybe (m AnyChainBlock))) | Re-fetch a block by point, to reconstruct |
| -> Int | How many applied points to track for undo re-fetch. In production
this is the node's security parameter k
( |
| -> FieldMaskTree FollowTipResponse | Selects the fields of every streamed response |
| -> (NextElem (Proto FollowTipResponse) -> IO ()) | Callback used to send each streamed response |
| -> [ChainPoint] | Resolved, non-empty intersection points, in client preference order |
| -> m () |
The FollowTip streaming loop. Finds the intersection with the given
points, then streams chain changes as they arrive.
The collaborators are plain arguments rather than a NodeKernelAccess
so tests can drive the loop with a scripted follower and stubbed
capabilities, no live ChainDB required (see
Test.Cardano.Rpc.FollowTipStream, the first unit coverage of this
loop). MonadIO is enough for all of them, including the gRPC error
path (throwGrpcErrorWithMessage).
How a rollback is delivered, by case:
- The target is within the tracked window, meaning it is one of the
last
trackingCapapplied points or the window floor (the stream's start point, on which a rollback undoes everything tracked). Each rolled-back block is re-fetched by point and emitted asundo, newest first. - A re-fetch misses mid-undo because garbage collection won the race:
a single
resetat the rollback target. Partial undo followed by reset is coherent becauseresetis absolute positioning. - The target is outside the window, either deeper than the cap or the
initial rollback-to-intersection when nothing is tracked yet: a
single
reset, as in 2.
Every emitted message, apply or undo or reset, carries the current tip, and is trimmed to the field mask.
Throws NOT_FOUND if none of the intersection points are on the chain.
Runs until the client disconnects or the stream is otherwise closed;
follower cleanup is the caller's responsibility (see withFollowerReading).
readTipMethod :: MonadRpc e m => Proto ReadTipRequest -> m (Proto ReadTipResponse) Source #
Handle the ReadTip SyncService RPC method.
Reads the current chain tip from ChainDB and returns it as slot, block
header hash, block height and slot timestamp.
When the chain is at origin, the tip field is left unset.