Skip to content

Commit 9c15d59

Browse files
authored
(Fix #207) simulation: use simpler sortition for [ib|eb]-gen-probability <= 1. (#211)
1 parent 0553f78 commit 9c15d59

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

simulation/src/LeiosProtocol/Short.hs

+22-9
Original file line numberDiff line numberDiff line change
@@ -532,19 +532,32 @@ splitIntoSubSlots (NetworkRate r)
532532
replicate q fq
533533

534534
inputBlockRate :: LeiosConfig -> StakeFraction -> SlotNo -> Maybe (Double -> Word64)
535-
inputBlockRate cfg@LeiosConfig{inputBlockFrequencyPerSlot, pipeline = _ :: SingPipeline p} stake = \slot ->
536-
assert (isStage @p cfg Propose slot) $ Just f
535+
inputBlockRate cfg@LeiosConfig{inputBlockFrequencyPerSlot, pipeline = _ :: SingPipeline p} stake
536+
| inputBlockFrequencyPerSlot > 1 =
537+
case sortition stake networkRate of
538+
Sortition f -> checkSlot f
539+
| otherwise =
540+
case nodeRate stake networkRate of
541+
NodeRate r -> checkSlot (\p -> if p <= r then 1 else 0)
537542
where
538-
!(Sortition f) = sortition stake $ NetworkRate inputBlockFrequencyPerSlot
543+
networkRate = NetworkRate inputBlockFrequencyPerSlot
544+
checkSlot g slot = assert (isStage @p cfg Propose slot) $ Just g
539545

540546
endorseBlockRate :: LeiosConfig -> StakeFraction -> SlotNo -> Maybe (Double -> Word64)
541-
endorseBlockRate cfg@LeiosConfig{pipeline = _ :: SingPipeline p} stake = \slot -> do
542-
guard $ isStage @p cfg Endorse slot
543-
startEndorse <- stageStart @p cfg Endorse slot Endorse
544-
guard $ startEndorse == slot
545-
return $ min 1 . f
547+
endorseBlockRate cfg@LeiosConfig{pipeline = _ :: SingPipeline p} stake
548+
| cfg.endorseBlockFrequencyPerStage > 1 =
549+
case sortition stake networkRate of
550+
Sortition f -> checkSlot f
551+
| otherwise =
552+
case nodeRate stake networkRate of
553+
NodeRate r -> checkSlot (\p -> if p <= r then 1 else 0)
546554
where
547-
!(Sortition f) = sortition stake $ NetworkRate cfg.endorseBlockFrequencyPerStage
555+
networkRate = NetworkRate cfg.endorseBlockFrequencyPerStage
556+
checkSlot f = \slot -> do
557+
guard $ isStage @p cfg Endorse slot
558+
startEndorse <- stageStart @p cfg Endorse slot Endorse
559+
guard $ startEndorse == slot
560+
return $ min 1 . f
548561

549562
votingRanges :: LeiosConfig -> [(SlotNo, SlotNo)]
550563
votingRanges cfg@LeiosConfig{voteSendStage} = go 0

0 commit comments

Comments
 (0)