Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comments and shortcuts to Cardano.Slotting.EpochInfo.Impl
These shortcuts are used in eg the Consensus Layer mocks and tests.
- Loading branch information
Showing
1 changed file
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
-- | For use in trivial cases, such as in mocks, tests, etc. | ||
module Cardano.Slotting.EpochInfo.Impl | ||
( fixedEpochInfo, | ||
-- * Shortcuts | ||
fixedEpochInfoEpoch, | ||
fixedEpochInfoFirst, | ||
) | ||
where | ||
|
||
import Cardano.Slotting.EpochInfo.API | ||
import Cardano.Slotting.Slot (EpochNo (..), EpochSize (..), SlotNo (..)) | ||
import Cardano.Slotting.Time (RelativeTime (..), SlotLength, getSlotLength) | ||
|
||
-- | The 'EpochInfo' induced by assuming the epoch size and slot length are | ||
-- fixed for the entire system lifetime | ||
fixedEpochInfo :: Monad m => EpochSize -> SlotLength -> EpochInfo m | ||
fixedEpochInfo (EpochSize size) slotLength = EpochInfo | ||
{ epochInfoSize_ = \_ -> | ||
return $ EpochSize size, | ||
epochInfoFirst_ = \(EpochNo epochNo) -> | ||
return $ SlotNo (epochNo * size), | ||
epochInfoEpoch_ = \(SlotNo slot) -> | ||
return $ EpochNo (slot `div` size), | ||
epochInfoFirst_ = \e -> return $ fixedEpochInfoFirst (EpochSize size) e, | ||
epochInfoEpoch_ = \sl -> return $ fixedEpochInfoEpoch (EpochSize size) sl, | ||
epochInfoSlotToRelativeTime_ = \(SlotNo slot) -> | ||
return $ RelativeTime (fromIntegral slot * getSlotLength slotLength) | ||
} | ||
|
||
-- | The pure computation underlying 'epochInfoFirst' applied to | ||
-- 'fixedEpochInfo' | ||
fixedEpochInfoFirst :: EpochSize -> EpochNo -> SlotNo | ||
fixedEpochInfoFirst (EpochSize size) (EpochNo epochNo) = | ||
SlotNo (epochNo * size) | ||
|
||
-- | The pure computation underlying 'epochInfoEpoch' applied to | ||
-- 'fixedEpochInfo' | ||
fixedEpochInfoEpoch :: EpochSize -> SlotNo -> EpochNo | ||
fixedEpochInfoEpoch (EpochSize size) (SlotNo slot) = | ||
EpochNo (slot `div` size) |