1+ {-# LANGUAGE ApplicativeDo #-}
12{-# LANGUAGE BangPatterns #-}
23{-# LANGUAGE FlexibleContexts #-}
34{-# LANGUAGE GADTs #-}
@@ -43,6 +44,7 @@ module Cardano.DbSync.Api (
4344 generateNewEpochEvents ,
4445 logDbState ,
4546 convertToPoint ,
47+ determineIsolationLevel ,
4648)
4749where
4850
@@ -245,7 +247,7 @@ getInsertOptions :: SyncEnv -> InsertOptions
245247getInsertOptions = soptInsertOptions . envOptions
246248
247249getSlotHash :: DB. DbEnv -> SlotNo -> IO [(SlotNo , ByteString )]
248- getSlotHash backend = DB. runDbDirectSilent backend . DB. querySlotHash
250+ getSlotHash backend slotNo = DB. runDbTransSilent backend DB. ReadCommitted ( DB. querySlotHash slotNo)
249251
250252hasLedgerState :: SyncEnv -> Bool
251253hasLedgerState syncEnv =
@@ -256,7 +258,7 @@ hasLedgerState syncEnv =
256258getDbLatestBlockInfo :: DB. DbEnv -> IO (Maybe TipInfo )
257259getDbLatestBlockInfo dbEnv = do
258260 runMaybeT $ do
259- block <- MaybeT $ DB. runDbDirectSilent dbEnv DB. queryLatestBlock
261+ block <- MaybeT $ DB. runDbTransSilent dbEnv DB. ReadCommitted DB. queryLatestBlock
260262 -- The EpochNo, SlotNo and BlockNo can only be zero for the Byron
261263 -- era, but we need to make the types match, hence `fromMaybe`.
262264 pure $
@@ -267,6 +269,14 @@ getDbLatestBlockInfo dbEnv = do
267269 , bBlockNo = BlockNo . fromMaybe 0 $ DB. blockBlockNo block
268270 }
269271
272+ -- | Determine isolation level based on sync state
273+ determineIsolationLevel :: SyncEnv -> IO (Maybe DB. IsolationLevel )
274+ determineIsolationLevel syncEnv = do
275+ syncState <- readTVarIO (envDbIsolationState syncEnv)
276+ pure $ case syncState of
277+ DB. SyncLagging -> Just DB. ReadCommitted
278+ DB. SyncFollowing -> Nothing
279+
270280getDbTipBlockNo :: SyncEnv -> IO (Point. WithOrigin BlockNo )
271281getDbTipBlockNo env = do
272282 mblk <- getDbLatestBlockInfo (envDbEnv env)
@@ -314,7 +324,7 @@ mkSyncEnv ::
314324 Bool ->
315325 IO SyncEnv
316326mkSyncEnv metricSetters trce dbEnv syncOptions protoInfo nw maxLovelaceSupply nwMagic systemStart syncNodeConfigFromFile syncNP runNearTipMigrationFnc isJsonbInSchema = do
317- dbCNamesVar <- newTVarIO =<< DB. runDbDirectSilent dbEnv DB. queryRewardAndEpochStakeConstraints
327+ dbCNamesVar <- newTVarIO =<< DB. runDbTransSilent dbEnv DB. ReadCommitted DB. queryRewardAndEpochStakeConstraints
318328 cache <-
319329 if soptCache syncOptions
320330 then
@@ -506,7 +516,7 @@ getBootstrapInProgress ::
506516 DB. DbEnv ->
507517 IO Bool
508518getBootstrapInProgress trce bootstrapFlag dbEnv = do
509- DB. runDbDirectSilent dbEnv $ do
519+ DB. runDbTransSilent dbEnv DB. ReadCommitted $ do
510520 ems <- DB. queryAllExtraMigrations
511521 let btsState = DB. bootstrapState ems
512522 case (bootstrapFlag, btsState) of
0 commit comments