Skip to content

Commit 100be78

Browse files
committed
retry when cached result isn't available
1 parent dff479f commit 100be78

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/core/src/Network/Ntp.hs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import Cardano.BM.Data.Tracer
2626
( HasPrivacyAnnotation (..), HasSeverityAnnotation (..) )
2727
import Cardano.Wallet.Api.Types
2828
( ApiNetworkClock (..), ApiNtpStatus (..), NtpSyncingStatus (..) )
29-
import Control.Monad.STM
30-
( atomically )
29+
import Control.Concurrent.STM
30+
( atomically, check )
3131
import Control.Tracer
3232
( Tracer )
3333
import Data.Quantity
@@ -130,12 +130,17 @@ getNtpStatus
130130
-> IO ApiNetworkClock
131131
getNtpStatus client forceCheck = (ApiNetworkClock . toStatus) <$>
132132
if forceCheck
133-
then ntpQueryBlocking client
134-
-- ^ Forces an NTP check / query on the central servers, use with care
135-
else atomically (ntpGetStatus client)
136-
-- ^ Reads a cached NTP status from an STM.TVar so we don't get
137-
-- blacklisted by the central NTP "authorities" for sending too many NTP
138-
-- requests.
133+
-- Forces an NTP check / query on the central servers, use with care
134+
then do
135+
ntpQueryBlocking client
136+
137+
else atomically $ do
138+
-- Reads a cached NTP status from an STM.TVar so we don't get
139+
-- blacklisted by the central NTP "authorities" for sending too many NTP
140+
-- requests.
141+
s <- ntpGetStatus client
142+
check (s /= NtpSyncPending)
143+
pure s
139144
where
140145
toStatus = \case
141146
NtpSyncPending ->

0 commit comments

Comments
 (0)