| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Hydra.Tx.ContestationPeriod
Synopsis
- newtype ContestationPeriod = UnsafeContestationPeriod Natural
- fromNominalDiffTime :: MonadFail m => NominalDiffTime -> m ContestationPeriod
- toNominalDiffTime :: ContestationPeriod -> NominalDiffTime
- toChain :: ContestationPeriod -> ContestationPeriod
- fromChain :: ContestationPeriod -> Either Text ContestationPeriod
Documentation
newtype ContestationPeriod Source #
A positive, non-zero number of seconds. Use fromInteger on positive
literals, fromEnum via [1..] syntax or fromNominalDiffTime to create
values of unknown sign.
NOTE: FromJSON is deliberately newtype-derived and therefore total: it also
decodes the persisted event log, where a value an older node legitimately
wrote has to stay decodable or the node could never start again. A configured
period is validated at the configuration boundary instead, see
parseCardanoChainConfig.
Constructors
| UnsafeContestationPeriod Natural |
Instances
fromNominalDiffTime :: MonadFail m => NominalDiffTime -> m ContestationPeriod Source #
Create a ContestationPeriod from a NominalDiffTime. This will fail if a
negative NominalDiffTime is provided and truncates to 1s if values < 1s are given.
toChain :: ContestationPeriod -> ContestationPeriod Source #
Convert an off-chain contestation period to its on-chain representation.
fromChain :: ContestationPeriod -> Either Text ContestationPeriod Source #
Convert an on-chain contestation period to its off-chain representation,
accepting exactly the values toChain can produce: a positive whole number of
seconds.
The on-chain representation is a signed number of milliseconds and nothing
constrains it, so an observed datum can carry a value this type cannot hold.
Rejecting rather than rounding matters beyond the obvious underflow: the node
decides whether to join a head by comparing this value against its own
configuration, and then writes toChain of it back into the closing datum,
which the head validator requires to equal what the opening datum held. A
period that only survives the trip approximately would pass the comparison and
then fail that equality forever, leaving a head that can never be closed.