Skip to content

Commit 7150a2d

Browse files
committed
do not (always) crash when failing to retrieve protocol parameters on startup.
This is only truly an issue for the cardano-node provider, not for Ogmios. In the latter case, the parameters are only needed to display health information regarding network synchronization. But failing to retrieve parameters likely mean that we fail to retrieve *anything*, and so this would be null anyway. So it's better to have those be part of the retry loop and repeatedly try to fetch parameters when requested; using an MVar to memoize a previous success.
1 parent db8c6ff commit 7150a2d

File tree

11 files changed

+273
-230
lines changed

11 files changed

+273
-230
lines changed

src/Kupo.hs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ import Kupo.App
5454
, readOnlyConsumer
5555
, rollForwardAll
5656
, rollForwardUntil
57+
, withExceptionHandler
5758
, withFetchBlockClient
5859
)
59-
import Kupo.App.ChainSync
60-
( withChainSyncExceptionHandler
61-
)
6260
import Kupo.App.Configuration
6361
( TraceConfiguration (..)
64-
, hydrateNetworkParameters
62+
, hydrateChainProducer
6563
, newPatternsCache
64+
, resolveNetworkParameters
6665
, startOrResume
6766
)
6867
import Kupo.App.Database
@@ -115,8 +114,7 @@ import Kupo.Data.ChainSync
115114
( ForcedRollbackHandler
116115
)
117116
import Kupo.Data.Configuration
118-
( ChainProducer (..)
119-
, Configuration (..)
117+
( Configuration (..)
120118
, DeferIndexesInstallation (..)
121119
, NetworkParameters
122120
, NodeTipHasBeenReachedException (..)
@@ -171,15 +169,9 @@ kupo tr = do
171169
}
172170
} <- ask
173171

174-
chainProducerWithParams <- liftIO (hydrateNetworkParameters chainProducer)
175-
176-
let networkParams = case chainProducerWithParams of
177-
CardanoNode{networkParameters} -> Just networkParameters
178-
Ogmios{networkParameters} -> Just networkParameters
179-
Hydra{} -> Nothing
180-
ReadOnlyReplica{} -> Nothing
172+
chainProducerWithParams <- liftIO $ hydrateChainProducer chainProducer
181173

182-
kupoWith tr networkParams
174+
kupoWith tr (resolveNetworkParameters chainProducerWithParams)
183175
(newProducer (tracerConfiguration tr) chainProducerWithParams)
184176
(withFetchBlockClient chainProducerWithParams)
185177
(newFetchTipClient chainProducerWithParams)
@@ -188,7 +180,7 @@ kupo tr = do
188180
kupoWith
189181
:: Tracers IO Concrete
190182

191-
-> Maybe NetworkParameters
183+
-> IO (Maybe NetworkParameters)
192184

193185
-> ( ( forall block. IsBlock block
194186
=> (Point -> ForcedRollbackHandler IO -> IO ())
@@ -309,7 +301,7 @@ kupoWith tr networkParameters withProducer withFetchBlock fetchTipClient =
309301
( if isReadOnlyReplica config then
310302
toggleConnected statusToggle *> idle
311303
else
312-
withChainSyncExceptionHandler (tracerChainSync tr) statusToggle $ do
304+
withExceptionHandler (tracerKupo tr) statusToggle $ do
313305
(mostRecentCheckpoint, checkpoints) <- startOrResume
314306
(tracerConfiguration tr)
315307
config

0 commit comments

Comments
 (0)