@@ -14,7 +14,7 @@ module Cardano.DbSync.Api (
14
14
isConsistent ,
15
15
getDisableInOutState ,
16
16
getRanIndexes ,
17
- runIndexesMigrations ,
17
+ runNearTipMigrations ,
18
18
initPruneConsumeMigration ,
19
19
runConsumedTxOutMigrationsMaybe ,
20
20
runAddJsonbToSchema ,
@@ -46,6 +46,13 @@ module Cardano.DbSync.Api (
46
46
)
47
47
where
48
48
49
+ import Cardano.BM.Trace (Trace , logInfo , logWarning )
50
+ import qualified Cardano.Chain.Genesis as Byron
51
+ import Cardano.Crypto.ProtocolMagic (ProtocolMagicId (.. ))
52
+ import qualified Cardano.Ledger.BaseTypes as Ledger
53
+ import qualified Cardano.Ledger.Shelley.Genesis as Shelley
54
+ import Cardano.Prelude
55
+ import Cardano.Slotting.Slot (EpochNo (.. ), SlotNo (.. ), WithOrigin (.. ))
49
56
import Control.Concurrent.Class.MonadSTM.Strict (
50
57
newTBQueueIO ,
51
58
newTVarIO ,
@@ -55,14 +62,6 @@ import Control.Concurrent.Class.MonadSTM.Strict (
55
62
)
56
63
import Control.Monad.Trans.Maybe (MaybeT (.. ))
57
64
import qualified Data.Strict.Maybe as Strict
58
-
59
- import Cardano.BM.Trace (Trace , logInfo , logWarning )
60
- import qualified Cardano.Chain.Genesis as Byron
61
- import Cardano.Crypto.ProtocolMagic (ProtocolMagicId (.. ))
62
- import qualified Cardano.Ledger.BaseTypes as Ledger
63
- import qualified Cardano.Ledger.Shelley.Genesis as Shelley
64
- import Cardano.Prelude
65
- import Cardano.Slotting.Slot (EpochNo (.. ), SlotNo (.. ), WithOrigin (.. ))
66
65
import Ouroboros.Consensus.Block.Abstract (BlockProtocol , HeaderHash , Point (.. ), fromRawHash )
67
66
import Ouroboros.Consensus.BlockchainTime.WallClock.Types (SystemStart (.. ))
68
67
import Ouroboros.Consensus.Config (SecurityParam (.. ), TopLevelConfig , configSecurityParam )
@@ -120,12 +119,12 @@ getRanIndexes :: SyncEnv -> IO Bool
120
119
getRanIndexes env = do
121
120
readTVarIO $ envIndexes env
122
121
123
- runIndexesMigrations :: SyncEnv -> IO ()
124
- runIndexesMigrations env = do
122
+ runNearTipMigrations :: SyncEnv -> IO ()
123
+ runNearTipMigrations env = do
125
124
haveRan <- readTVarIO $ envIndexes env
126
125
unless haveRan $ do
127
- envRunIndexesMigration env DB. Indexes
128
- logInfo (getTrace env) " Indexes were created "
126
+ envRunNearTipMigration env DB. NearTip
127
+ logInfo (getTrace env) " NearTip migrations were ran successfully. "
129
128
atomically $ writeTVar (envIndexes env) True
130
129
131
130
initPruneConsumeMigration :: Bool -> Bool -> Bool -> Bool -> DB. PruneConsumeMigration
@@ -297,53 +296,6 @@ getCurrentTipBlockNo env = do
297
296
Just tip -> pure $ At (bBlockNo tip)
298
297
Nothing -> pure Origin
299
298
300
- mkSyncEnvFromConfig ::
301
- Trace IO Text ->
302
- DB. DbEnv ->
303
- SyncOptions ->
304
- GenesisConfig ->
305
- SyncNodeConfig ->
306
- SyncNodeParams ->
307
- -- | run migration function
308
- RunMigration ->
309
- IO (Either SyncNodeError SyncEnv )
310
- mkSyncEnvFromConfig trce dbEnv syncOptions genCfg syncNodeConfigFromFile syncNodeParams runIndexesMigrationFnc =
311
- case genCfg of
312
- GenesisCardano _ bCfg sCfg _ _
313
- | unProtocolMagicId (Byron. configProtocolMagicId bCfg) /= Shelley. sgNetworkMagic (scConfig sCfg) ->
314
- pure
315
- . Left
316
- . SNErrCardanoConfig
317
- $ mconcat
318
- [ " ProtocolMagicId "
319
- , textShow (unProtocolMagicId $ Byron. configProtocolMagicId bCfg)
320
- , " /= "
321
- , textShow (Shelley. sgNetworkMagic $ scConfig sCfg)
322
- ]
323
- | Byron. gdStartTime (Byron. configGenesisData bCfg) /= Shelley. sgSystemStart (scConfig sCfg) ->
324
- pure
325
- . Left
326
- . SNErrCardanoConfig
327
- $ mconcat
328
- [ " SystemStart "
329
- , textShow (Byron. gdStartTime $ Byron. configGenesisData bCfg)
330
- , " /= "
331
- , textShow (Shelley. sgSystemStart $ scConfig sCfg)
332
- ]
333
- | otherwise ->
334
- Right
335
- <$> mkSyncEnv
336
- trce
337
- dbEnv
338
- syncOptions
339
- (fst $ mkProtocolInfoCardano genCfg [] )
340
- (Shelley. sgNetworkId $ scConfig sCfg)
341
- (NetworkMagic . unProtocolMagicId $ Byron. configProtocolMagicId bCfg)
342
- (SystemStart . Byron. gdStartTime $ Byron. configGenesisData bCfg)
343
- syncNodeConfigFromFile
344
- syncNodeParams
345
- runIndexesMigrationFnc
346
-
347
299
mkSyncEnv ::
348
300
Trace IO Text ->
349
301
DB. DbEnv ->
@@ -356,7 +308,7 @@ mkSyncEnv ::
356
308
SyncNodeParams ->
357
309
RunMigration ->
358
310
IO SyncEnv
359
- mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfigFromFile syncNP runIndexesMigrationFnc = do
311
+ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfigFromFile syncNP runNearTipMigrationFnc = do
360
312
dbCNamesVar <- newTVarIO =<< DB. runDbActionIO dbEnv DB. queryRewardAndEpochStakeConstraints
361
313
cache <-
362
314
if soptCache syncOptions
@@ -418,14 +370,61 @@ mkSyncEnv trce dbEnv syncOptions protoInfo nw nwMagic systemStart syncNodeConfig
418
370
, envOffChainVoteResultQueue = oarq
419
371
, envOffChainVoteWorkQueue = oawq
420
372
, envOptions = syncOptions
421
- , envRunIndexesMigration = runIndexesMigrationFnc
373
+ , envRunNearTipMigration = runNearTipMigrationFnc
422
374
, envSyncNodeConfig = syncNodeConfigFromFile
423
375
, envSystemStart = systemStart
424
376
}
425
377
where
426
378
hasLedger' = hasLedger . sioLedger . dncInsertOptions
427
379
isTxOutConsumedBootstrap' = isTxOutConsumedBootstrap . sioTxOut . dncInsertOptions
428
380
381
+ mkSyncEnvFromConfig ::
382
+ Trace IO Text ->
383
+ DB. DbEnv ->
384
+ SyncOptions ->
385
+ GenesisConfig ->
386
+ SyncNodeConfig ->
387
+ SyncNodeParams ->
388
+ -- | run migration function
389
+ RunMigration ->
390
+ IO (Either SyncNodeError SyncEnv )
391
+ mkSyncEnvFromConfig trce dbEnv syncOptions genCfg syncNodeConfigFromFile syncNodeParams runNearTipMigrationFnc =
392
+ case genCfg of
393
+ GenesisCardano _ bCfg sCfg _ _
394
+ | unProtocolMagicId (Byron. configProtocolMagicId bCfg) /= Shelley. sgNetworkMagic (scConfig sCfg) ->
395
+ pure
396
+ . Left
397
+ . SNErrCardanoConfig
398
+ $ mconcat
399
+ [ " ProtocolMagicId "
400
+ , textShow (unProtocolMagicId $ Byron. configProtocolMagicId bCfg)
401
+ , " /= "
402
+ , textShow (Shelley. sgNetworkMagic $ scConfig sCfg)
403
+ ]
404
+ | Byron. gdStartTime (Byron. configGenesisData bCfg) /= Shelley. sgSystemStart (scConfig sCfg) ->
405
+ pure
406
+ . Left
407
+ . SNErrCardanoConfig
408
+ $ mconcat
409
+ [ " SystemStart "
410
+ , textShow (Byron. gdStartTime $ Byron. configGenesisData bCfg)
411
+ , " /= "
412
+ , textShow (Shelley. sgSystemStart $ scConfig sCfg)
413
+ ]
414
+ | otherwise ->
415
+ Right
416
+ <$> mkSyncEnv
417
+ trce
418
+ dbEnv
419
+ syncOptions
420
+ (fst $ mkProtocolInfoCardano genCfg [] )
421
+ (Shelley. sgNetworkId $ scConfig sCfg)
422
+ (NetworkMagic . unProtocolMagicId $ Byron. configProtocolMagicId bCfg)
423
+ (SystemStart . Byron. gdStartTime $ Byron. configGenesisData bCfg)
424
+ syncNodeConfigFromFile
425
+ syncNodeParams
426
+ runNearTipMigrationFnc
427
+
429
428
-- | 'True' is for in memory points and 'False' for on disk
430
429
getLatestPoints :: SyncEnv -> IO [(CardanoPoint , Bool )]
431
430
getLatestPoints env = do
0 commit comments