hydra-node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Node.State

Synopsis

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

  • deposit :: Deposit tx
     
  • recordedAt :: ChainSlot

    Slot at which the deposit transaction was observed.

  • consumedAt :: Maybe ChainSlot

    Slot at which a consuming transaction (increment or recover) was observed, if any. A consumed deposit is no longer pending, but is retained for depositRetentionHorizon so a rollback can resurface it.

Instances

Instances details
IsTx tx => FromJSON (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

parseJSON :: Value -> Parser (TrackedDeposit tx)

parseJSONList :: Value -> Parser [TrackedDeposit tx]

omittedField :: Maybe (TrackedDeposit tx)

IsTx tx => ToJSON (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

toJSON :: TrackedDeposit tx -> Value

toEncoding :: TrackedDeposit tx -> Encoding

toJSONList :: [TrackedDeposit tx] -> Value

toEncodingList :: [TrackedDeposit tx] -> Encoding

omitField :: TrackedDeposit tx -> Bool

Generic (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep (TrackedDeposit tx) :: Type -> Type Source #

IsTx tx => Show (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

IsTx tx => FromCBOR (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s (TrackedDeposit tx)

label :: Proxy (TrackedDeposit tx) -> Text

IsTx tx => ToCBOR (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

toCBOR :: TrackedDeposit tx -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (TrackedDeposit tx) -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [TrackedDeposit tx] -> Size

IsTx tx => Eq (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

type Rep (TrackedDeposit tx) Source # 
Instance details

Defined in Hydra.Node.State

type Rep (TrackedDeposit tx) = D1 ('MetaData "TrackedDeposit" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "TrackedDeposit" 'PrefixI 'True) (S1 ('MetaSel ('Just "deposit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Deposit tx)) :*: (S1 ('MetaSel ('Just "recordedAt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ChainSlot) :*: S1 ('MetaSel ('Just "consumedAt") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Maybe ChainSlot)))))

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

Instances details
FromJSON ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

Methods

parseJSON :: Value -> Parser ChainPointTime

parseJSONList :: Value -> Parser [ChainPointTime]

omittedField :: Maybe ChainPointTime

ToJSON ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

Generic ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep ChainPointTime :: Type -> Type Source #

Show ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

FromCBOR ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s ChainPointTime

label :: Proxy ChainPointTime -> Text

ToCBOR ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

Methods

toCBOR :: ChainPointTime -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy ChainPointTime -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [ChainPointTime] -> Size

Eq ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

type Rep ChainPointTime Source # 
Instance details

Defined in Hydra.Node.State

type Rep ChainPointTime = D1 ('MetaData "ChainPointTime" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "ChainPointTime" 'PrefixI 'True) (S1 ('MetaSel ('Just "currentSlot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 ChainSlot) :*: (S1 ('MetaSel ('Just "currentChainTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 UTCTime) :*: S1 ('MetaSel ('Just "drift") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 NominalDiffTime))))

data NodeState tx Source #

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

Instances details
view ~ PendingDeposits tx => HasField "pendingDeposits" (NodeState tx) view Source #

Derived view, so record-dot access keeps working across the tracked representation.

Instance details

Defined in Hydra.Node.State

Methods

getField :: NodeState tx -> view Source #

(IsTx tx, FromJSON (ChainStateType tx)) => FromJSON (NodeState tx) Source #

Manual instance: lifecycle-tracked $sel:deposits:NodeInSync replaced the plain pending deposit map after NodeState shipped. A checkpoint persisted by an older version carries a "pendingDeposits" key instead, which is lifted via trackedFromPending.

Instance details

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 # 
Instance details

Defined in Hydra.Node.State

Methods

toJSON :: NodeState tx -> Value

toEncoding :: NodeState tx -> Encoding

toJSONList :: [NodeState tx] -> Value

toEncodingList :: [NodeState tx] -> Encoding

omitField :: NodeState tx -> Bool

Generic (NodeState tx) Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep (NodeState tx) :: Type -> Type Source #

Methods

from :: NodeState tx -> Rep (NodeState tx) x Source #

to :: Rep (NodeState tx) x -> NodeState tx Source #

(IsTx tx, Show (ChainStateType tx)) => Show (NodeState tx) Source # 
Instance details

Defined in Hydra.Node.State

IsChainState tx => FromCBOR (NodeState tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s (NodeState tx)

label :: Proxy (NodeState tx) -> Text

IsChainState tx => ToCBOR (NodeState tx) Source # 
Instance details

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 # 
Instance details

Defined in Hydra.Node.State

Methods

(==) :: NodeState tx -> NodeState tx -> Bool Source #

(/=) :: NodeState tx -> NodeState tx -> Bool Source #

type Rep (NodeState tx) Source # 
Instance details

Defined in Hydra.Node.State

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

Instances details
FromJSON SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

parseJSON :: Value -> Parser SyncedStatus

parseJSONList :: Value -> Parser [SyncedStatus]

omittedField :: Maybe SyncedStatus

ToJSON SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

toJSON :: SyncedStatus -> Value

toEncoding :: SyncedStatus -> Encoding

toJSONList :: [SyncedStatus] -> Value

toEncodingList :: [SyncedStatus] -> Encoding

omitField :: SyncedStatus -> Bool

Generic SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep SyncedStatus :: Type -> Type Source #

Show SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

FromCBOR SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s SyncedStatus

label :: Proxy SyncedStatus -> Text

ToCBOR SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

toCBOR :: SyncedStatus -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy SyncedStatus -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [SyncedStatus] -> Size

Eq SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

type Rep SyncedStatus Source # 
Instance details

Defined in Hydra.Node.State

type Rep SyncedStatus = D1 ('MetaData "SyncedStatus" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "InSync" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "CatchingUp" 'PrefixI 'False) (U1 :: Type -> Type))

data Deposit tx Source #

A deposit tracked by the protocol. The DepositStatus determines whether it may be used for an incremental commit or not.

Constructors

Deposit 

Fields

Instances

Instances details
IsTx tx => FromJSON (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

parseJSON :: Value -> Parser (Deposit tx)

parseJSONList :: Value -> Parser [Deposit tx]

omittedField :: Maybe (Deposit tx)

IsTx tx => ToJSON (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

toJSON :: Deposit tx -> Value

toEncoding :: Deposit tx -> Encoding

toJSONList :: [Deposit tx] -> Value

toEncodingList :: [Deposit tx] -> Encoding

omitField :: Deposit tx -> Bool

Generic (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep (Deposit tx) :: Type -> Type Source #

Methods

from :: Deposit tx -> Rep (Deposit tx) x Source #

to :: Rep (Deposit tx) x -> Deposit tx Source #

IsTx tx => Show (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

IsTx tx => FromCBOR (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s (Deposit tx)

label :: Proxy (Deposit tx) -> Text

IsTx tx => ToCBOR (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

toCBOR :: Deposit tx -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Deposit tx) -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Deposit tx] -> Size

IsTx tx => Eq (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

Methods

(==) :: Deposit tx -> Deposit tx -> Bool Source #

(/=) :: Deposit tx -> Deposit tx -> Bool Source #

type Rep (Deposit tx) Source # 
Instance details

Defined in Hydra.Node.State

type Rep (Deposit tx) = D1 ('MetaData "Deposit" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "Deposit" 'PrefixI 'True) ((S1 ('MetaSel ('Just "headId") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 HeadId) :*: S1 ('MetaSel ('Just "deposited") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (UTxOType tx))) :*: (S1 ('MetaSel ('Just "created") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 UTCTime) :*: (S1 ('MetaSel ('Just "deadline") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 UTCTime) :*: S1 ('MetaSel ('Just "status") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 DepositStatus)))))

data DepositStatus Source #

Constructors

Inactive 
Active 
Expired 

Instances

Instances details
FromJSON DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

parseJSON :: Value -> Parser DepositStatus

parseJSONList :: Value -> Parser [DepositStatus]

omittedField :: Maybe DepositStatus

ToJSON DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

Generic DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

Associated Types

type Rep DepositStatus :: Type -> Type Source #

Show DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

FromCBOR DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

fromCBOR :: Decoder s DepositStatus

label :: Proxy DepositStatus -> Text

ToCBOR DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

Methods

toCBOR :: DepositStatus -> Encoding

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy DepositStatus -> Size

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [DepositStatus] -> Size

Eq DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

type Rep DepositStatus Source # 
Instance details

Defined in Hydra.Node.State

type Rep DepositStatus = D1 ('MetaData "DepositStatus" "Hydra.Node.State" "hydra-node-2.4.1-Ld6araFLy8R3VgBqKXvTkN" 'False) (C1 ('MetaCons "Inactive" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Active" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Expired" 'PrefixI 'False) (U1 :: Type -> Type)))