@@ -240,7 +240,7 @@ data Expr (f :: Type -> Type) :: Type -> Type where
240
240
ESlotLength :: Expr f SlotNo -> Expr f SlotLength
241
241
EEpochSize :: Expr f EpochNo -> Expr f EpochSize
242
242
EGenesisWindow :: Expr f SlotNo -> Expr f GenesisWindow
243
- EPerasRoundLength :: Expr f SlotNo -> Expr f PerasRoundLength
243
+ EPerasRoundLength :: Expr f PerasRoundNo -> Expr f PerasRoundLength
244
244
245
245
{- ------------------------------------------------------------------------------
246
246
Interpreter
@@ -362,11 +362,8 @@ evalExprInEra EraSummary{..} = \(ClosedExpr e) -> go e
362
362
r <- go expr
363
363
-- here we implicitly check that we are in Peras-enabled era,
364
364
-- i.e. the round length is not Nothing
365
- slot <-
366
- (*)
367
- <$> Just (getPerasRoundNoInEra r)
368
- <*> (unPerasRoundLength <$> strictMaybeToMaybe eraPerasRoundLength)
369
- pure (SlotInEra slot)
365
+ perasRoundLength <- unPerasRoundLength <$> strictMaybeToMaybe eraPerasRoundLength
366
+ pure $ SlotInEra (getPerasRoundNoInEra r * perasRoundLength)
370
367
go (ERelSlotToPerasRoundNo expr) = do
371
368
s <- go expr
372
369
-- here we implicitly check that we are in Peras-enabled era,
@@ -398,15 +395,12 @@ evalExprInEra EraSummary{..} = \(ClosedExpr e) -> go e
398
395
guardEnd $ \ end -> s < boundSlot end
399
396
return eraGenesisWin
400
397
go (EPerasRoundLength expr) = do
401
- s <- go expr
402
- guard $ s >= boundSlot eraStart
403
- guardEnd $ \ end -> s < boundSlot end
404
- ((_, _), es) <- go $ slotToEpochExpr s
405
- -- here we implicitly check that we are in Peras-enabled era,
406
- -- i.e. the round length is not Nothing
407
- roundLength <- strictMaybeToMaybe eraPerasRoundLength
408
- -- additionally, we check that Peras round length divides epoch size
409
- guard $ (unEpochSize es) `mod` (unPerasRoundLength roundLength) == 0
398
+ r <- go expr
399
+ firstPerasRound <- strictMaybeToMaybe $ boundPerasRound eraStart
400
+ guard $ r >= firstPerasRound
401
+ guardEndM $ \ end -> do
402
+ lastPerasRound <- strictMaybeToMaybe $ boundPerasRound end
403
+ pure $ r < lastPerasRound
410
404
strictMaybeToMaybe eraPerasRoundLength
411
405
412
406
{- ------------------------------------------------------------------------------
@@ -599,7 +593,7 @@ epochToSize absEpoch =
599
593
-- | Translate 'PerasRoundNo' to the 'SlotNo' of the first slot in that Peras round
600
594
--
601
595
-- Additionally returns the length of the round.
602
- perasRoundNoToSlot :: PerasRoundNo -> Qry SlotNo
596
+ perasRoundNoToSlot :: PerasRoundNo -> Qry ( SlotNo , PerasRoundLength )
603
597
perasRoundNoToSlot perasRoundNo = qryFromExpr (perasRoundNoToSlotExpr perasRoundNo)
604
598
605
599
-- | Translate 'SlotNo' to its corresponding 'PerasRoundNo'
@@ -659,13 +653,19 @@ slotToGenesisWindow :: SlotNo -> Expr f GenesisWindow
659
653
slotToGenesisWindow absSlot =
660
654
EGenesisWindow (ELit absSlot)
661
655
662
- perasRoundNoToSlotExpr :: PerasRoundNo -> Expr f SlotNo
663
- perasRoundNoToSlotExpr absPerasRoundNo =
656
+ perasRoundNoToSlotExpr' :: PerasRoundNo -> Expr f SlotNo
657
+ perasRoundNoToSlotExpr' absPerasRoundNo =
664
658
let relPerasRoundExpr = EAbsToRelPerasRoundNo (ELit absPerasRoundNo)
665
659
startOfSlot = ELit (TimeInSlot 0 )
666
660
in ERelToAbsSlot (EPair (ERelPerasRoundNoToSlot relPerasRoundExpr) startOfSlot)
667
661
668
- -- SlotNo -> SlotInEra -> PerasRoundNoInEra -> PerasRoundNo
662
+ perasRoundNoToSlotExpr :: PerasRoundNo -> Expr f (SlotNo , PerasRoundLength )
663
+ perasRoundNoToSlotExpr absPerasRoundNo =
664
+ EPair (perasRoundNoToSlotExpr' absPerasRoundNo) (perasRoundNoPerasRoundLengthExpr absPerasRoundNo)
665
+
666
+ perasRoundNoPerasRoundLengthExpr :: PerasRoundNo -> Expr f PerasRoundLength
667
+ perasRoundNoPerasRoundLengthExpr absPerasRoundNo =
668
+ EPerasRoundLength (ELit absPerasRoundNo)
669
669
670
670
slotToPerasRoundNoExpr :: SlotNo -> Expr f PerasRoundNo
671
671
slotToPerasRoundNoExpr absSlot = ERelToAbsPerasRoundNo (ERelSlotToPerasRoundNo (EAbsToRelSlot (ELit absSlot)))
0 commit comments