Skip to content

Commit

Permalink
Fix invalid sync percentage display in query tip
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Jul 29, 2024
1 parent e77529e commit 8c95e9f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ runQueryProtocolParametersCmd
shelleyBasedEraConstraints sbe $
encodePretty pparams

-- | Calculate the percentage sync rendered as text.
-- | Calculate the percentage sync rendered as text: @min 1 (tipTime/nowTime)@
percentage
:: RelativeTime
-- ^ 'tolerance'. If 'b' - 'a' < 'tolerance', then 100% is reported. This even if we are 'tolerance' seconds
-- ^ @tolerance@. If @b - a < tolerance@, then 100% is reported. This even if we are @tolerance@ seconds
-- behind, we are still considered fully synced.
-> RelativeTime
-- ^ 'nowTime'. The time of the most recently synced block.
-- ^ @tipTime@ The time of the most recently synced block.
-> RelativeTime
-- ^ 'tipTime'. The time of the tip of the block chain to which we need to sync.
-- ^ @nowTime@ The time of the tip of the block chain to which we need to sync.
-> Text
percentage tolerance a b = Text.pack (printf "%.2f" pc)
where
Expand All @@ -211,10 +211,10 @@ percentage tolerance a b = Text.pack (printf "%.2f" pc)
ua = min (sa + t) sb
ub = sb
-- Final percentage to render as text.
pc = id @Double (fromIntegral ua / fromIntegral ub) * 100.0
pc = (fromIntegral ua / fromIntegral ub) * 100.0 :: Double

relativeTimeSeconds :: RelativeTime -> Integer
relativeTimeSeconds (RelativeTime dt) = floor (nominalDiffTimeToSeconds dt)
relativeTimeSeconds :: RelativeTime -> Integer
relativeTimeSeconds (RelativeTime dt) = floor (nominalDiffTimeToSeconds dt)

-- | Query the chain tip via the chain sync protocol.
--
Expand Down Expand Up @@ -299,7 +299,7 @@ runQueryTipCmd

let tolerance = RelativeTime (secondsToNominalDiffTime 600)

return $ percentage tolerance nowSeconds tipTimeResult
return $ percentage tolerance tipTimeResult nowSeconds

mSyncProgress <- hushM syncProgressResult $ \e -> do
liftIO . LT.hPutStrLn IO.stderr $
Expand Down

0 comments on commit 8c95e9f

Please sign in to comment.