Skip to content

Commit 31a810c

Browse files
committed
simulation: guard against taking pred of first pipeline
1 parent 8cdd036 commit 31a810c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

simulation/src/LeiosProtocol/Short.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,9 @@ endorseBlocksToReference cfg@LeiosConfig{variant = Full} pl EndorseBlocksSnapsho
689689
]
690690

691691
pipelinesToReferenceFromEB :: Int -> PipelineNo -> Maybe (PipelineNo, PipelineNo)
692-
pipelinesToReferenceFromEB n pl =
693-
case fromEnum (pred pl) - maxStagesAfterEndorse of
692+
pipelinesToReferenceFromEB n pl = do
693+
predPl <- safePred pl
694+
case fromEnum predPl - maxStagesAfterEndorse of
694695
newestIx
695696
| newestIx < 0 -> Nothing
696697
| otherwise ->
@@ -700,6 +701,9 @@ pipelinesToReferenceFromEB n pl =
700701
)
701702
where
702703
maxStagesAfterEndorse = 2
704+
safePred x = do
705+
guard $ x > minBound
706+
pure $ pred x
703707

704708
shouldVoteOnEB ::
705709
LeiosConfig ->

0 commit comments

Comments
 (0)