| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Hydra.Node.State
Synopsis
- type PendingDeposits tx = Map (TxIdType tx) (Deposit tx)
- data TrackedDeposit tx = TrackedDeposit {
- deposit :: Deposit tx
- recordedAt :: ChainSlot
- consumedAt :: Maybe ChainSlot
- type TrackedDeposits tx = Map (TxIdType tx) (TrackedDeposit tx)
- trackedFromPending :: PendingDeposits tx -> TrackedDeposits tx
- pendingDeposits :: NodeState tx -> PendingDeposits tx
- recordDeposit :: IsTx tx => ChainSlot -> TxIdType tx -> Deposit tx -> NodeState tx -> NodeState tx
- updateDeposit :: IsTx tx => TxIdType tx -> Deposit tx -> NodeState tx -> NodeState tx
- consumeDeposit :: IsTx tx => ChainSlot -> TxIdType tx -> NodeState tx -> NodeState tx
- rollbackDeposits :: ChainSlot -> NodeState tx -> NodeState tx
- pruneConsumedDeposits :: ChainSlot -> TrackedDeposits tx -> TrackedDeposits tx
- depositRetentionHorizon :: ChainSlot
- data ChainPointTime = ChainPointTime {
- currentSlot :: ChainSlot
- currentChainTime :: UTCTime
- drift :: NominalDiffTime
- data NodeState tx
- = NodeInSync {
- headState :: HeadState tx
- deposits :: TrackedDeposits tx
- chainPointTime :: ChainPointTime
- | NodeCatchingUp {
- headState :: HeadState tx
- deposits :: TrackedDeposits tx
- chainPointTime :: ChainPointTime
- = NodeInSync {
- nodeInSyncCBORTag :: Text
- nodeCatchingUpCBORTag :: Text
- nodeInSyncCBORTagV1 :: Text
- nodeCatchingUpCBORTagV1 :: Text
- initNodeState :: IsChainState tx => ChainStateType tx -> NodeState tx
- initialChainPointTime :: IsChainState tx => ChainStateType tx -> ChainPointTime
- initialChainTime :: UTCTime
- data SyncedStatus
- = InSync
- | CatchingUp
- syncedStatus :: NodeState tx -> SyncedStatus
- data Deposit tx = Deposit {}
- data DepositStatus
- depositsForHead :: HeadId -> PendingDeposits tx -> PendingDeposits tx
Documentation
type PendingDeposits tx = Map (TxIdType tx) (Deposit tx) Source #
data TrackedDeposit tx Source #
A deposit with its L1 lifecycle slots. Deposits are L1-derived state, so a
rollback must rewind the view (rollbackDeposits): a deposit recorded after
the rolled-back slot vanishes (its deposit transaction was erased), and a
consumption after it is undone (the erased increment or recover resurfaces
the deposit). Forward re-observation of the new chain then converges the view
again. Only L1-derived state may rewind like this; L2 state (snapshots,
signatures) never rolls back.
Constructors
| TrackedDeposit | |
Fields
| |
Instances
type TrackedDeposits tx = Map (TxIdType tx) (TrackedDeposit tx) Source #
trackedFromPending :: PendingDeposits tx -> TrackedDeposits tx Source #
Track the given deposits with a fresh lifecycle (recorded at slot 0, unconsumed). Used to lift state serialized before lifecycle tracking existed, reproducing the old (rollback unaware) behavior for those deposits.
pendingDeposits :: NodeState tx -> PendingDeposits tx Source #
Deposits pending as observed on chain: the tracked deposits not consumed yet.
recordDeposit :: IsTx tx => ChainSlot -> TxIdType tx -> Deposit tx -> NodeState tx -> NodeState tx Source #
Record a newly observed deposit at the given slot. Re-recording an id (its deposit transaction re-landed after a rollback) starts a fresh lifecycle.
updateDeposit :: IsTx tx => TxIdType tx -> Deposit tx -> NodeState tx -> NodeState tx Source #
Update a tracked deposit (e.g. on status changes); its lifecycle slots are unaffected. Unknown ids are ignored.
consumeDeposit :: IsTx tx => ChainSlot -> TxIdType tx -> NodeState tx -> NodeState tx Source #
Mark a deposit consumed at the given slot: its increment or recover was observed on chain. Re-consuming (the consuming transaction re-landed after a rollback) re-stamps the slot, so a rollback of the re-landed transaction still resurfaces the deposit.
rollbackDeposits :: ChainSlot -> NodeState tx -> NodeState tx Source #
Rewind the deposit view to the given (rolled back) slot, see
TrackedDeposit.
pruneConsumedDeposits :: ChainSlot -> TrackedDeposits tx -> TrackedDeposits tx Source #
Drop consumed deposits beyond depositRetentionHorizon: no rollback can
resurface them anymore, so retaining them would only grow persisted state
with every deposit ever settled. Called on the deposit write paths, which is
enough because only deposit churn creates consumed entries. Unconsumed
deposits are never pruned — an expired deposit stays recoverable
indefinitely.
depositRetentionHorizon :: ChainSlot Source #
How long consumed deposits are retained for rollbacks: sized to cover the deepest rollback Cardano can produce (the security parameter k = 2160 blocks, roughly 12 hours at one block per 20 slots) with a three-fold margin.
data ChainPointTime Source #
Constructors
| ChainPointTime | |
Fields
| |
Instances
Constructors
| NodeInSync | Normal operation of the node where it is connected and has a recent view of the chain. |
Fields
| |
| NodeCatchingUp | Node is catching up on its view of the chain and should behave differently. |
Fields
| |
Instances
| view ~ PendingDeposits tx => HasField "pendingDeposits" (NodeState tx) view Source # | Derived view, so record-dot access keeps working across the tracked representation. |
Defined in Hydra.Node.State | |
| (IsTx tx, FromJSON (ChainStateType tx)) => FromJSON (NodeState tx) Source # | Manual instance: lifecycle-tracked |
Defined in Hydra.Node.State Methods parseJSON :: Value -> Parser (NodeState tx) parseJSONList :: Value -> Parser [NodeState tx] omittedField :: Maybe (NodeState tx) | |
| (IsTx tx, ToJSON (ChainStateType tx)) => ToJSON (NodeState tx) Source # | |
Defined in Hydra.Node.State Methods toJSON :: NodeState tx -> Value toEncoding :: NodeState tx -> Encoding toJSONList :: [NodeState tx] -> Value toEncodingList :: [NodeState tx] -> Encoding | |
| Generic (NodeState tx) Source # | |
| (IsTx tx, Show (ChainStateType tx)) => Show (NodeState tx) Source # | |
| IsChainState tx => FromCBOR (NodeState tx) Source # | |
| IsChainState tx => ToCBOR (NodeState tx) Source # | |
Defined in Hydra.Node.State Methods toCBOR :: NodeState tx -> Encoding encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (NodeState tx) -> Size encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [NodeState tx] -> Size | |
| (IsTx tx, Eq (ChainStateType tx)) => Eq (NodeState tx) Source # | |
| type Rep (NodeState tx) Source # | |
Defined in Hydra.Node.State type Rep (NodeState tx) = D1 ('MetaData "NodeState" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "NodeInSync" 'PrefixI 'True) (S1 ('MetaSel ('Just "headState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HeadState tx)) :*: (S1 ('MetaSel ('Just "deposits") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (TrackedDeposits tx)) :*: S1 ('MetaSel ('Just "chainPointTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ChainPointTime))) :+: C1 ('MetaCons "NodeCatchingUp" 'PrefixI 'True) (S1 ('MetaSel ('Just "headState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (HeadState tx)) :*: (S1 ('MetaSel ('Just "deposits") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (TrackedDeposits tx)) :*: S1 ('MetaSel ('Just "chainPointTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ChainPointTime)))) | |
nodeInSyncCBORTag :: Text Source #
Tags of the current on-disk/wire layout, which tracks deposit lifecycles
(TrackedDeposits). The fields are a bare concatenation with no length
prefix, so a layout change is only decodable when the tag distinguishes it:
the V1 tags name the layout with a plain pending deposit map written before
lifecycle tracking existed and are still accepted, lifted via
trackedFromPending like the FromJSON instance above.
nodeCatchingUpCBORTag :: Text Source #
Tags of the current on-disk/wire layout, which tracks deposit lifecycles
(TrackedDeposits). The fields are a bare concatenation with no length
prefix, so a layout change is only decodable when the tag distinguishes it:
the V1 tags name the layout with a plain pending deposit map written before
lifecycle tracking existed and are still accepted, lifted via
trackedFromPending like the FromJSON instance above.
nodeInSyncCBORTagV1 :: Text Source #
Tags of the layout without deposit lifecycles. Decoded, never written.
nodeCatchingUpCBORTagV1 :: Text Source #
Tags of the layout without deposit lifecycles. Decoded, never written.
initNodeState :: IsChainState tx => ChainStateType tx -> NodeState tx Source #
initialChainPointTime :: IsChainState tx => ChainStateType tx -> ChainPointTime Source #
data SyncedStatus Source #
Constructors
| InSync | |
| CatchingUp |
Instances
syncedStatus :: NodeState tx -> SyncedStatus Source #
A deposit tracked by the protocol. The DepositStatus determines whether
it may be used for an incremental commit or not.
Constructors
| Deposit | |
Instances
data DepositStatus Source #
Instances
depositsForHead :: HeadId -> PendingDeposits tx -> PendingDeposits tx Source #