Skip to content

Commit 801b110

Browse files
committed
TOSQUASH fourmolu
1 parent 37257f9 commit 801b110

File tree

3 files changed

+67
-70
lines changed

3 files changed

+67
-70
lines changed

simulation/src/LeiosProtocol/Short.hs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,17 @@ stageRangeOf cfg pl stage =
480480
-- in the first iteration (ie @'PipelineNo' 0@)
481481
pipelineOf :: forall p. IsPipeline p => LeiosConfig -> Stage p -> SlotNo -> PipelineNo
482482
pipelineOf cfg stage sl =
483-
maybe err cnv $ stageStart cfg stage sl minBound
484-
where
485-
cnv = toEnum . (`div` cfg.sliceLength) . fromEnum
483+
maybe err cnv $ stageStart cfg stage sl minBound
484+
where
485+
cnv = toEnum . (`div` cfg.sliceLength) . fromEnum
486486

487-
err = error $ show (cfg.sliceLength, x, stage, sl)
487+
err = error $ show (cfg.sliceLength, x, stage, sl)
488488

489-
x :: String
490-
x = case cfg of LeiosConfig{pipeline} -> case pipeline of
491-
SingSingleVote -> "SingleVote"
492-
SingSplitVote -> "SplitVote"
489+
x :: String
490+
x = case cfg of
491+
LeiosConfig{pipeline} -> case pipeline of
492+
SingSingleVote -> "SingleVote"
493+
SingSplitVote -> "SplitVote"
493494

494495
forEachPipeline :: (forall p. Stage p) -> (forall p. IsPipeline p => Stage p -> a) -> [a]
495496
forEachPipeline s k = [k @SingleVote s, k @SplitVote s]
@@ -687,20 +688,18 @@ data EndorseBlocksSnapshot = EndorseBlocksSnapshot
687688
--
688689
-- IBs that are delivered later than any of these options are discarded,
689690
-- ignored.
690-
data IbDeliveryStage =
691-
IbDuringProposeOrDeliver1
692-
-- ^ The node will not vote for an EB that excludes IBs that arrived during
691+
data IbDeliveryStage
692+
= -- | The node will not vote for an EB that excludes IBs that arrived during
693693
-- Propose or Deliver1.
694694
--
695695
-- The node will include IBs that arrived during Propose or Deliver1 in an
696696
-- EB it makes.
697-
|
697+
IbDuringProposeOrDeliver1
698+
| -- | The node will include IBs that arrived during Deliver2 in an EB it makes.
698699
IbDuringDeliver2
699-
-- ^ The node will include IBs that arrived during Deliver2 in an EB it makes.
700-
|
701-
IbDuringEndorse
702-
-- ^ The node will not vote for an EB that includes IBs that arrived later
700+
| -- | The node will not vote for an EB that includes IBs that arrived later
703701
-- than Endorse.
702+
IbDuringEndorse
704703
deriving (Bounded, Enum, Eq, Ord, Show)
705704

706705
-- | Both constraints are inclusive.
@@ -718,16 +717,16 @@ ibWasDeliveredLate cfg slotCfg sl deliveryTime =
718717

719718
ibDeliveryStage :: LeiosConfig -> SlotConfig -> SlotNo -> UTCTime -> Maybe IbDeliveryStage
720719
ibDeliveryStage
721-
cfg@LeiosConfig {pipeline = _ :: SingPipeline p}
722-
slotCfg
723-
ibSlot
724-
deliveryTime
725-
| before loPropose = Nothing -- TODO future blocks?
726-
| before loDeliver2 = Just IbDuringProposeOrDeliver1
727-
| before loEndorse = Just IbDuringDeliver2
728-
| before (succ hiEndorse) = Just IbDuringEndorse
729-
| otherwise = Nothing -- TODO late blocks?
730-
where
720+
cfg@LeiosConfig{pipeline = _ :: SingPipeline p}
721+
slotCfg
722+
ibSlot
723+
deliveryTime
724+
| before loPropose = Nothing -- TODO future blocks?
725+
| before loDeliver2 = Just IbDuringProposeOrDeliver1
726+
| before loEndorse = Just IbDuringDeliver2
727+
| before (succ hiEndorse) = Just IbDuringEndorse
728+
| otherwise = Nothing -- TODO late blocks?
729+
where
731730
p = pipelineOf @p cfg Propose ibSlot
732731

733732
before sl = deliveryTime < slotTime slotCfg sl
@@ -743,14 +742,14 @@ inputBlocksToEndorse ::
743742
InputBlocksSnapshot ->
744743
[InputBlockId]
745744
inputBlocksToEndorse cfg@LeiosConfig{pipeline = _ :: SingPipeline p} current buffer =
746-
buffer.validInputBlocks
747-
InputBlocksQuery
748-
{ generatedBetween = (lo, hi)
749-
, receivedBy = IbDuringDeliver2
750-
}
751-
where
752-
hi = pipelineOf @p cfg Endorse current
753-
lo = if cfg.lateIbInclusion then pipelineMonus hi 2 else hi
745+
buffer.validInputBlocks
746+
InputBlocksQuery
747+
{ generatedBetween = (lo, hi)
748+
, receivedBy = IbDuringDeliver2
749+
}
750+
where
751+
hi = pipelineOf @p cfg Endorse current
752+
lo = if cfg.lateIbInclusion then pipelineMonus hi 2 else hi
754753

755754
-- | Returns possible EBs to reference from current pipeline EB.
756755
endorseBlocksToReference ::
@@ -809,9 +808,9 @@ shouldVoteOnEB cfg@LeiosConfig{voteSendStage} _ slot _buffers _
809808
shouldVoteOnEB cfg@LeiosConfig{voteSendStage = voteSendStage :: Stage p} slotConfig slot buffers ebuffers = cond
810809
where
811810
generatedBetween = (lo, hi)
812-
where
813-
hi = pipelineOf @p cfg voteSendStage slot
814-
lo = if cfg.lateIbInclusion then pipelineMonus hi 2 else hi
811+
where
812+
hi = pipelineOf @p cfg voteSendStage slot
813+
lo = if cfg.lateIbInclusion then pipelineMonus hi 2 else hi
815814
receivedByEndorse =
816815
buffers.validInputBlocks
817816
InputBlocksQuery

simulation/src/LeiosProtocol/Short/Node.hs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,23 @@ data LeiosNodeConfig = LeiosNodeConfig
122122
data LeiosNodeState m = LeiosNodeState
123123
{ praosState :: !(PraosNode.PraosNodeState RankingBlockBody m)
124124
, relayIBState :: !(RelayIBState m)
125-
-- ^ validated IBs that are still young enough to be diffusing
125+
-- ^ validated IBs that are still young enough to be diffusing
126126
, iBsForEBsAndVotesVar :: !(TVar m (Map PipelineNo (Map InputBlockId IbDeliveryStage)))
127-
-- ^ IBs that are relevant to an EB or Vote this node might need to issue
128-
--
129-
-- Each of these IBs arrived during its contemporary Propose, Deliver1,
130-
-- Deliver2, or Endorse stages, has been validated, and is not too old.
131-
--
132-
-- INVARIANT: In basic Short Leios, none of these IBs are older than
133-
-- @4*'sliceLength'@. With the @leios-late-ib-inclusion@ extension enabled,
134-
-- none of these IBs are older than @(4+2)*'sliceLength'@.
135-
--
136-
-- Note that some IBs that are too old to be included in this variable
137-
-- might still be needed in order to apply some RB.
138-
--
139-
-- INVARIANT: @all (\_k v -> not $ null v)@.
140-
--
141-
-- INVARIANT: @all (\k v -> all ((k ==) . pipelineOf cfg Propose) v)@.
127+
-- ^ IBs that are relevant to an EB or Vote this node might need to issue
128+
--
129+
-- Each of these IBs arrived during its contemporary Propose, Deliver1,
130+
-- Deliver2, or Endorse stages, has been validated, and is not too old.
131+
--
132+
-- INVARIANT: In basic Short Leios, none of these IBs are older than
133+
-- @4*'sliceLength'@. With the @leios-late-ib-inclusion@ extension enabled,
134+
-- none of these IBs are older than @(4+2)*'sliceLength'@.
135+
--
136+
-- Note that some IBs that are too old to be included in this variable
137+
-- might still be needed in order to apply some RB.
138+
--
139+
-- INVARIANT: @all (\_k v -> not $ null v)@.
140+
--
141+
-- INVARIANT: @all (\k v -> all ((k ==) . pipelineOf cfg Propose) v)@.
142142
, relayEBState :: !(RelayEBState m)
143143
, prunedUnadoptedEBStateToVar :: !(TVar m SlotNo)
144144
, prunedUncertifiedEBStateToVar :: !(TVar m SlotNo)
@@ -445,7 +445,7 @@ leiosNode tracer cfg followers peers = do
445445
let submitIB xs deliveryTime completion = do
446446
traceReceived xs $ EventIB . uncurry InputBlock
447447
let annotate x = (,) x <$> ibDeliveryStage cfg.leios cfg.slotConfig (fst x).slot deliveryTime
448-
let xs' = mapMaybe annotate xs -- TODO what to do with early/late arrivals?
448+
let xs' = mapMaybe annotate xs -- TODO what to do with early/late arrivals?
449449
unless (null xs') $ dispatch $! ValidateIBs xs' completion
450450
let submitVote (map snd -> xs) deliveryTime completion = do
451451
traceReceived xs EventVote
@@ -816,7 +816,7 @@ adoptIB :: MonadSTM m => LeiosConfig -> LeiosNodeState m -> InputBlock -> IbDeli
816816
adoptIB cfg leiosState ib deliveryStage = do
817817
let !ibSlot = ib.header.slot
818818
!p = case cfg of
819-
LeiosConfig {pipeline = _ :: SingPipeline p} ->
819+
LeiosConfig{pipeline = _ :: SingPipeline p} ->
820820
pipelineOf @p cfg Short.Propose ibSlot
821821
modifyTVar'
822822
leiosState.iBsForEBsAndVotesVar
@@ -1025,23 +1025,21 @@ mkBuffersView cfg st = BuffersView{..}
10251025
ibs = do
10261026
let splitLE k m =
10271027
let (lt, mbEq, _gt) = Map.splitLookup k m
1028-
in
1029-
case mbEq of
1030-
Nothing -> lt
1031-
Just eq -> Map.insert k eq lt
1028+
in case mbEq of
1029+
Nothing -> lt
1030+
Just eq -> Map.insert k eq lt
10321031
splitGE k m =
10331032
let (_lt, mbEq, gt) = Map.splitLookup k m
1034-
in
1035-
case mbEq of
1036-
Nothing -> gt
1037-
Just eq -> Map.insert k eq gt
1033+
in case mbEq of
1034+
Nothing -> gt
1035+
Just eq -> Map.insert k eq gt
10381036
generatedCheck (lo, hi) =
1039-
Map.unions
1040-
. splitGE lo
1041-
. splitLE hi
1037+
Map.unions
1038+
. splitGE lo
1039+
. splitLE hi
10421040
receivedByCheck hi =
1043-
mapMaybe (\(ibId, deliveryStage) -> do guard (deliveryStage <= hi); Just ibId)
1044-
. Map.toList
1041+
mapMaybe (\(ibId, deliveryStage) -> do guard (deliveryStage <= hi); Just ibId)
1042+
. Map.toList
10451043
xs <- readTVar st.iBsForEBsAndVotesVar
10461044
let validInputBlocks q = receivedByCheck q.receivedBy . generatedCheck q.generatedBetween $ xs
10471045
return InputBlocksSnapshot{..}

simulation/test/Test/ShortToFull.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tests =
2525
data Test_leiosLateIbInclusion = Test_leiosLateIbInclusion
2626
{ ibTable :: [(Int, Short.PipelineNo, Short.IbDeliveryStage)] -- the Int is @zip [0..]@, /before shrinking/
2727
, ebLo :: SlotNo
28-
-- ^ this first slot in which an EB could actually exist
28+
-- ^ this first slot in which an EB could actually exist
2929
, ebSlot :: SlotNo
3030
}
3131
deriving (Show)
@@ -41,7 +41,7 @@ instance Q.Arbitrary Test_leiosLateIbInclusion where
4141
n <- Q.choose (0, 1000)
4242
gens <- Q.vectorOf n $ fmap toEnum $ Q.choose (0, 20)
4343
delays <- Q.vectorOf n $ Q.elements [minBound .. maxBound]
44-
pure $ [ (i, gen, delay) | i <- [0..] | gen <- sort gens | delay <- delays ]
44+
pure $ [(i, gen, delay) | i <- [0 ..] | gen <- sort gens | delay <- delays]
4545
pure Test_leiosLateIbInclusion{..}
4646

4747
shrink testSetup =

0 commit comments

Comments
 (0)