Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid sync percentage display in query tip #851

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so the arguments needed to be swapped.


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