Skip to content

Commit 6ce05b1

Browse files
committed
WIP return round length when converting from round number to slot
1 parent 353f9ee commit 6ce05b1

File tree

2 files changed

+20
-20
lines changed
  • ouroboros-consensus
    • src/ouroboros-consensus/Ouroboros/Consensus/HardFork/History
    • test/consensus-test/Test/Consensus/HardFork

2 files changed

+20
-20
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/HardFork/History/Qry.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ data Expr (f :: Type -> Type) :: Type -> Type where
240240
ESlotLength :: Expr f SlotNo -> Expr f SlotLength
241241
EEpochSize :: Expr f EpochNo -> Expr f EpochSize
242242
EGenesisWindow :: Expr f SlotNo -> Expr f GenesisWindow
243-
EPerasRoundLength :: Expr f SlotNo -> Expr f PerasRoundLength
243+
EPerasRoundLength :: Expr f PerasRoundNo -> Expr f PerasRoundLength
244244

245245
{-------------------------------------------------------------------------------
246246
Interpreter
@@ -362,11 +362,8 @@ evalExprInEra EraSummary{..} = \(ClosedExpr e) -> go e
362362
r <- go expr
363363
-- here we implicitly check that we are in Peras-enabled era,
364364
-- 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)
370367
go (ERelSlotToPerasRoundNo expr) = do
371368
s <- go expr
372369
-- here we implicitly check that we are in Peras-enabled era,
@@ -398,15 +395,12 @@ evalExprInEra EraSummary{..} = \(ClosedExpr e) -> go e
398395
guardEnd $ \end -> s < boundSlot end
399396
return eraGenesisWin
400397
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
410404
strictMaybeToMaybe eraPerasRoundLength
411405

412406
{-------------------------------------------------------------------------------
@@ -599,7 +593,7 @@ epochToSize absEpoch =
599593
-- | Translate 'PerasRoundNo' to the 'SlotNo' of the first slot in that Peras round
600594
--
601595
-- Additionally returns the length of the round.
602-
perasRoundNoToSlot :: PerasRoundNo -> Qry SlotNo
596+
perasRoundNoToSlot :: PerasRoundNo -> Qry (SlotNo, PerasRoundLength)
603597
perasRoundNoToSlot perasRoundNo = qryFromExpr (perasRoundNoToSlotExpr perasRoundNo)
604598

605599
-- | Translate 'SlotNo' to its corresponding 'PerasRoundNo'
@@ -659,13 +653,19 @@ slotToGenesisWindow :: SlotNo -> Expr f GenesisWindow
659653
slotToGenesisWindow absSlot =
660654
EGenesisWindow (ELit absSlot)
661655

662-
perasRoundNoToSlotExpr :: PerasRoundNo -> Expr f SlotNo
663-
perasRoundNoToSlotExpr absPerasRoundNo =
656+
perasRoundNoToSlotExpr' :: PerasRoundNo -> Expr f SlotNo
657+
perasRoundNoToSlotExpr' absPerasRoundNo =
664658
let relPerasRoundExpr = EAbsToRelPerasRoundNo (ELit absPerasRoundNo)
665659
startOfSlot = ELit (TimeInSlot 0)
666660
in ERelToAbsSlot (EPair (ERelPerasRoundNoToSlot relPerasRoundExpr) startOfSlot)
667661

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)
669669

670670
slotToPerasRoundNoExpr :: SlotNo -> Expr f PerasRoundNo
671671
slotToPerasRoundNoExpr absSlot = ERelToAbsPerasRoundNo (ERelSlotToPerasRoundNo (EAbsToRelSlot (ELit absSlot)))

ouroboros-consensus/test/consensus-test/Test/Consensus/HardFork/Summary.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ roundtripEpochSlot s@ArbitrarySummary{beforeHorizonEpoch = epoch} =
137137
roundtripPerasRoundSlot :: ArbitrarySummary -> Property
138138
roundtripPerasRoundSlot s@ArbitrarySummary{beforeHorizonPerasRoundNo = perasRoundNo} =
139139
noPastHorizonException s $ do
140-
slot <- HF.perasRoundNoToSlot perasRoundNo
140+
(slot, _roundLenght) <- HF.perasRoundNoToSlot perasRoundNo
141141
perasRoundNo' <- HF.slotToPerasRoundNo slot
142142
pure $
143143
conjoin

0 commit comments

Comments
 (0)