Skip to content

Commit

Permalink
TOSQUASH last PR comments from Esgen
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Nov 30, 2023
1 parent f7a63d9 commit 137f887
Showing 1 changed file with 17 additions and 21 deletions.
Expand Up @@ -313,7 +313,7 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
(ServerUpdates serverUpdates) (InvalidBlocks invalidBlocks)
startSyncingAt = withRegistry $ \registry -> do

systemTime <- do
clientSystemTime <- do
initialIoSimClockValue <- getCurrentTime
pure SystemTime {
systemTimeWait = pure ()
Expand All @@ -329,7 +329,7 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
-
unClockSkew skew
}
let _ = systemTime :: SystemTime m
let _ = clientSystemTime :: SystemTime m

varCurrentLogicalTick <- uncheckedNewTVarM (Tick 0)
let clockUpdates :: Schedule NewMaxSlot
Expand All @@ -353,7 +353,7 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
(tracer', getTrace) <- recordingTracerTVar
let pairWithNow ev = do
logicalNow <- readTVarIO varCurrentLogicalTick
now <- systemTimeCurrent systemTime
now <- systemTimeCurrent clientSystemTime
pure (logicalNow, now, ev)
pure (contramapM pairWithNow tracer', getTrace)
let chainSyncTracer = contramap Left tracer
Expand Down Expand Up @@ -388,7 +388,7 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
}

inFutureCheck :: InFutureCheck.HeaderInFutureCheck m TestBlock
inFutureCheck = InFutureCheck.realHeaderInFutureCheck skew systemTime
inFutureCheck = InFutureCheck.realHeaderInFutureCheck skew clientSystemTime
-- Note that this tests passes in the exact difference between the
-- client's and server's clock as the tolerable clock skew.

Expand Down Expand Up @@ -422,7 +422,7 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)

NewMaxClientAndServerSlot cslot sslot ->
toOnset cslot `max` toSkewedOnset sslot
now <- systemTimeCurrent systemTime
now <- systemTimeCurrent clientSystemTime
threadDelay $ nominalDelay $ target `diffRelTime` now

_ -> error "impossible! bad mkClockUpdates"
Expand Down Expand Up @@ -496,11 +496,9 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
-- mishandled a block from the future.
let checkTipTime :: m ()
checkTipTime = do
(now, candidates) <- do
now <- systemTimeCurrent systemTime
candidates <-
atomically $ readTVar varCandidates >>= traverse readTVar
pure (now, candidates)
now <- systemTimeCurrent clientSystemTime
candidates <- atomically $
readTVar varCandidates >>= traverse readTVar
forM_ candidates $ \candidate -> do
let p = castPoint $ AF.headPoint candidate :: Point TestBlock
case pointSlot p of
Expand Down Expand Up @@ -556,12 +554,6 @@ runChainSync skew securityParam (ClientUpdates clientUpdates)
where
k = maxRollbacks securityParam

toOnset :: SlotNo -> RelativeTime
toOnset slot = RelativeTime $
scaleNominalDelay
(getSlotLength slotLength)
(unSlotNo slot)

toSkewedOnset :: SlotNo -> RelativeTime
toSkewedOnset slot =
let RelativeTime onset = toOnset slot
Expand Down Expand Up @@ -698,6 +690,13 @@ slotLengthInSeconds = 10
scaleNominalDelay :: Integral a => NominalDiffTime -> a -> NominalDiffTime
scaleNominalDelay dur i = dur * fromIntegral i

-- | The onset of the slot
toOnset :: SlotNo -> RelativeTime
toOnset slot = RelativeTime $
scaleNominalDelay
(getSlotLength slotLength)
(unSlotNo slot)

-- | Bundle dependent arguments for test generation
data ChainSyncClientSetup = ChainSyncClientSetup
{ securityParam :: SecurityParam
Expand Down Expand Up @@ -935,7 +934,7 @@ ppBlocks :: Point TestBlock -> [TestBlock] -> String
ppBlocks a bs = ppPoint a <> " ] " <> intercalate " :> " (map ppBlock bs)

ppTraceEvent :: TraceEvent -> String
ppTraceEvent (Tick n, m, ev) = show (n, m) <> " | " <> case ev of
ppTraceEvent (Tick n, RelativeTime t, ev) = show (n, t) <> " | " <> case ev of
Left cl -> "Client: " <> show cl
Right pt -> "Protocol: " <> show pt

Expand Down Expand Up @@ -984,10 +983,7 @@ tickArrivalTimeStats events =
tickArrivalTimes :: [TraceEvent] -> TickArrivalTimeStats (Set.Set Tick)
tickArrivalTimes = foldMap $ \case
(n, now, Left (TraceDownloadedHeader hdr)) ->
let onset = RelativeTime $
scaleNominalDelay
(getSlotLength slotLength)
(unSlotNo (blockSlot hdr))
let onset = toOnset (blockSlot hdr)
thisTick = Set.singleton n
in
if now < onset
Expand Down

0 comments on commit 137f887

Please sign in to comment.