Skip to content

Commit

Permalink
remove migration fix related code
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Jan 13, 2025
1 parent 52ada06 commit 3b89ea1
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 132 deletions.
6 changes: 0 additions & 6 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ data CommandLineArgs = CommandLineArgs
, claEpochDisabled :: Bool
, claHasCache :: Bool
, claHasLedger :: Bool
, claSkipFix :: Bool
, claOnlyFix :: Bool
, claForceIndexes :: Bool
, claHasMultiAssets :: Bool
, claHasMetadata :: Bool
Expand Down Expand Up @@ -286,8 +284,6 @@ mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
, enpPGPassSource = DB.PGPassCached pgconfig
, enpEpochDisabled = claEpochDisabled
, enpHasCache = claHasCache
, enpSkipFix = claSkipFix
, enpOnlyFix = claOnlyFix
, enpForceIndexes = claForceIndexes
, enpHasInOut = True
, enpSnEveryFollowing = 35
Expand Down Expand Up @@ -361,8 +357,6 @@ initCommandLineArgs =
, claEpochDisabled = True
, claHasCache = True
, claHasLedger = True
, claSkipFix = True
, claOnlyFix = False
, claForceIndexes = False
, claHasMultiAssets = True
, claHasMetadata = True
Expand Down
25 changes: 1 addition & 24 deletions cardano-db-sync/app/cardano-db-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ main = do
-- Or to ignore ledger and not specify the state
(Nothing, LedgerIgnore) -> error stateDirErrorMsg
-- Otherwise, it's OK
_ -> pure ()
_otherwise -> pure ()

let prometheusPort = dncPrometheusPort syncNodeConfigFromFile
withMetricSetters prometheusPort $ \metricsSetters ->
Expand Down Expand Up @@ -87,8 +87,6 @@ pRunDbSyncNode = do
<*> pPGPassSource
<*> pEpochDisabled
<*> pHasCache
<*> pSkipFix
<*> pOnlyFix
<*> pForceIndexes
<*> pHasInOut
<*> pure 500
Expand Down Expand Up @@ -144,15 +142,6 @@ pEpochDisabled =
<> Opt.help "Makes epoch table remain empty"
)

pSkipFix :: Parser Bool
pSkipFix =
Opt.flag
False
True
( Opt.long "skip-fix"
<> Opt.help "Disables the db-sync fix procedure for the wrong datum and redeemer_data bytes."
)

pForceIndexes :: Parser Bool
pForceIndexes =
Opt.flag
Expand All @@ -162,18 +151,6 @@ pForceIndexes =
<> Opt.help "Forces the Index creation at the start of db-sync. Normally they're created later."
)

pOnlyFix :: Parser Bool
pOnlyFix =
Opt.flag
False
True
( Opt.long "fix-only"
<> Opt.help
"Runs only the db-sync fix procedure for the wrong datum, redeemer_data and plutus script bytes and exits. \
\This doesn't run any migrations. This can also be ran on previous schema, ie 13.0 13.1 to fix the issues without \
\bumping the schema version minor number."
)

pHasCache :: Parser Bool
pHasCache =
Opt.flag
Expand Down
8 changes: 1 addition & 7 deletions cardano-db-sync/src/Cardano/DbSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ runDbSync metricsSetters knownMigrations iomgr trce params syncNodeConfigFromFil
trce
iomgr
connectionString
ranMigrations
(void . runMigration)
syncNodeConfigFromFile
params
Expand Down Expand Up @@ -153,15 +152,13 @@ runSyncNode ::
Trace IO Text ->
IOManager ->
ConnectionString ->
-- | migrations were ran on startup
Bool ->
-- | run migration function
RunMigration ->
SyncNodeConfig ->
SyncNodeParams ->
SyncOptions ->
IO ()
runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc syncNodeConfigFromFile syncNodeParams syncOptions = do
runSyncNode metricsSetters trce iomgr dbConnString runMigrationFnc syncNodeConfigFromFile syncNodeParams syncOptions = do
whenJust maybeLedgerDir $
\enpLedgerStateDir -> do
createDirectoryIfMissing True (unLedgerStateDir enpLedgerStateDir)
Expand All @@ -188,7 +185,6 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
genCfg
syncNodeConfigFromFile
syncNodeParams
ranMigrations
runMigrationFnc

-- Warn the user that jsonb datatypes are being removed from the database schema.
Expand Down Expand Up @@ -246,8 +242,6 @@ extractSyncOptions snp aop snc =
&& not (enpEpochDisabled snp || not (enpHasCache snp))
, soptAbortOnInvalid = aop
, soptCache = enpHasCache snp
, soptSkipFix = enpSkipFix snp
, soptOnlyFix = enpOnlyFix snp
, soptPruneConsumeMigration =
initPruneConsumeMigration
isTxOutConsumed'
Expand Down
35 changes: 2 additions & 33 deletions cardano-db-sync/src/Cardano/DbSync/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ module Cardano.DbSync.Api (
getConsistentLevel,
isConsistent,
getIsConsumedFixed,
noneFixed,
isDataFixed,
getIsSyncFixed,
setIsFixed,
setIsFixedAndMigrate,
getDisableInOutState,
getRanIndexes,
runIndexMigrations,
Expand Down Expand Up @@ -125,26 +120,6 @@ getIsConsumedFixed env =
pcm = soptPruneConsumeMigration $ envOptions env
backend = envBackend env

noneFixed :: FixesRan -> Bool
noneFixed NoneFixRan = True
noneFixed _ = False

isDataFixed :: FixesRan -> Bool
isDataFixed DataFixRan = True
isDataFixed _ = False

getIsSyncFixed :: SyncEnv -> IO FixesRan
getIsSyncFixed = readTVarIO . envIsFixed

setIsFixed :: SyncEnv -> FixesRan -> IO ()
setIsFixed env fr = do
atomically $ writeTVar (envIsFixed env) fr

setIsFixedAndMigrate :: SyncEnv -> FixesRan -> IO ()
setIsFixedAndMigrate env fr = do
envRunDelayedMigration env DB.Fix
atomically $ writeTVar (envIsFixed env) fr

getDisableInOutState :: SyncEnv -> IO Bool
getDisableInOutState syncEnv = do
bst <- readTVarIO $ envBootstrap syncEnv
Expand Down Expand Up @@ -343,10 +318,9 @@ mkSyncEnv ::
SystemStart ->
SyncNodeConfig ->
SyncNodeParams ->
Bool ->
RunMigration ->
IO SyncEnv
mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemStart syncNodeConfigFromFile syncNP ranMigrations runMigrationFnc = do
mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemStart syncNodeConfigFromFile syncNP runMigrationFnc = do
dbCNamesVar <- newTVarIO =<< dbConstraintNamesExists backend
cache <-
if soptCache syncOptions
Expand All @@ -360,7 +334,6 @@ mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemS
}
else pure useNoCache
consistentLevelVar <- newTVarIO Unchecked
fixDataVar <- newTVarIO $ if ranMigrations then DataFixRan else NoneFixRan
indexesVar <- newTVarIO $ enpForceIndexes syncNP
bts <- getBootstrapInProgress trce (isTxOutConsumedBootstrap' syncNodeConfigFromFile) backend
bootstrapVar <- newTVarIO bts
Expand Down Expand Up @@ -402,7 +375,6 @@ mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemS
, envCurrentEpochNo = epochVar
, envEpochSyncTime = epochSyncTime
, envIndexes = indexesVar
, envIsFixed = fixDataVar
, envLedgerEnv = ledgerEnvType
, envNetworkMagic = nwMagic
, envOffChainPoolResultQueue = oprq
Expand All @@ -426,12 +398,10 @@ mkSyncEnvFromConfig ::
GenesisConfig ->
SyncNodeConfig ->
SyncNodeParams ->
-- | migrations were ran on startup
Bool ->
-- | run migration function
RunMigration ->
IO (Either SyncNodeError SyncEnv)
mkSyncEnvFromConfig trce backend connectionString syncOptions genCfg syncNodeConfigFromFile syncNodeParams ranMigration runMigrationFnc =
mkSyncEnvFromConfig trce backend connectionString syncOptions genCfg syncNodeConfigFromFile syncNodeParams runMigrationFnc =
case genCfg of
GenesisCardano _ bCfg sCfg _ _
| unProtocolMagicId (Byron.configProtocolMagicId bCfg) /= Shelley.sgNetworkMagic (scConfig sCfg) ->
Expand Down Expand Up @@ -467,7 +437,6 @@ mkSyncEnvFromConfig trce backend connectionString syncOptions genCfg syncNodeCon
(SystemStart . Byron.gdStartTime $ Byron.configGenesisData bCfg)
syncNodeConfigFromFile
syncNodeParams
ranMigration
runMigrationFnc

-- | 'True' is for in memory points and 'False' for on disk
Expand Down
6 changes: 0 additions & 6 deletions cardano-db-sync/src/Cardano/DbSync/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Cardano.DbSync.Api.Types (
InsertOptions (..),
LedgerEnv (..),
RunMigration,
FixesRan (..),
ConsistentLevel (..),
CurrentEpochNo (..),
) where
Expand Down Expand Up @@ -46,7 +45,6 @@ data SyncEnv = SyncEnv
, envCurrentEpochNo :: !(StrictTVar IO CurrentEpochNo)
, envEpochSyncTime :: !(StrictTVar IO UTCTime)
, envIndexes :: !(StrictTVar IO Bool)
, envIsFixed :: !(StrictTVar IO FixesRan)
, envBootstrap :: !(StrictTVar IO Bool)
, envLedgerEnv :: !LedgerEnv
, envNetworkMagic :: !NetworkMagic
Expand All @@ -64,8 +62,6 @@ data SyncOptions = SyncOptions
{ soptEpochAndCacheEnabled :: !Bool
, soptAbortOnInvalid :: !Bool
, soptCache :: !Bool
, soptSkipFix :: !Bool
, soptOnlyFix :: !Bool
, soptPruneConsumeMigration :: !DB.PruneConsumeMigration
, soptInsertOptions :: !InsertOptions
, snapshotEveryFollowing :: !Word64
Expand Down Expand Up @@ -98,8 +94,6 @@ data LedgerEnv where

type RunMigration = DB.MigrationToRun -> IO ()

data FixesRan = NoneFixRan | DataFixRan | AllFixRan

data ConsistentLevel = Consistent | DBAheadOfLedger | Unchecked
deriving (Show, Eq)

Expand Down
2 changes: 0 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ data SyncNodeParams = SyncNodeParams
, enpPGPassSource :: !PGPassSource
, enpEpochDisabled :: !Bool
, enpHasCache :: !Bool
, enpSkipFix :: !Bool
, enpOnlyFix :: !Bool
, enpForceIndexes :: !Bool
, enpHasInOut :: !Bool
, enpSnEveryFollowing :: !Word64
Expand Down
50 changes: 24 additions & 26 deletions cardano-db-sync/src/Cardano/DbSync/Sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,33 +201,31 @@ dbSyncProtocols syncEnv metricsSetters tc codecConfig version bversion =
localChainSyncPtcl = InitiatorProtocolOnly $
MiniProtocolCb $ \_ctx channel ->
liftIO . logException tracer "ChainSyncWithBlocksPtcl: " $ do
when True $ do
logInfo tracer "Starting ChainSync client"
setConsistentLevel syncEnv Unchecked
logInfo tracer "Starting ChainSync client"
setConsistentLevel syncEnv Unchecked

(latestPoints, currentTip) <- waitRestartState tc
let (inMemory, onDisk) = List.span snd latestPoints
logInfo tracer $
mconcat
[ "Suggesting intersection points from memory: "
, textShow (fst <$> inMemory)
, " and from disk: "
, textShow (fst <$> onDisk)
]
void $
runPipelinedPeer
localChainSyncTracer
(cChainSyncCodec codecs)
channel
( chainSyncClientPeerPipelined $
chainSyncClient metricsSetters tracer (fst <$> latestPoints) currentTip tc
)
atomically $ writeDbActionQueue tc DbFinish
-- We should return leftover bytes returned by 'runPipelinedPeer', but
-- client application do not care about them (it's only important if one
-- would like to restart a protocol on the same mux and thus bearer).
pure ()
pure ((), Nothing)
(latestPoints, currentTip) <- waitRestartState tc
let (inMemory, onDisk) = List.span snd latestPoints
logInfo tracer $
mconcat
[ "Suggesting intersection points from memory: "
, textShow (fst <$> inMemory)
, " and from disk: "
, textShow (fst <$> onDisk)
]
void $
runPipelinedPeer
localChainSyncTracer
(cChainSyncCodec codecs)
channel
( chainSyncClientPeerPipelined $
chainSyncClient metricsSetters tracer (fst <$> latestPoints) currentTip tc
)
atomically $ writeDbActionQueue tc DbFinish
-- We should return leftover bytes returned by 'runPipelinedPeer', but
-- client application do not care about them (it's only important if one
-- would like to restart a protocol on the same mux and thus bearer).
pure ()

dummylocalTxSubmit :: RunMiniProtocolWithMinimalCtx 'InitiatorMode LocalAddress BSL.ByteString IO () Void
dummylocalTxSubmit =
Expand Down
2 changes: 0 additions & 2 deletions cardano-db-sync/test/Cardano/DbSync/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ syncNodeParams =
<*> Gen.bool
<*> Gen.bool
<*> Gen.bool
<*> Gen.bool
<*> Gen.bool
<*> Gen.word64 (Range.linear 0 1000)
<*> Gen.word64 (Range.linear 0 1000)
<*> pure Nothing
Expand Down
22 changes: 2 additions & 20 deletions cardano-db-tool/app/cardano-db-tool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data Command
= CmdCreateMigration !MigrationDir !TxOutTableType
| CmdReport !Report !TxOutTableType
| CmdRollback !SlotNo !TxOutTableType
| CmdRunMigrations !MigrationDir !Bool !Bool !(Maybe LogFileDir) !TxOutTableType
| CmdRunMigrations !MigrationDir !Bool !(Maybe LogFileDir) !TxOutTableType
| CmdTxOutMigration !TxOutTableType
| CmdUtxoSetAtBlock !Word64 !TxOutTableType
| CmdPrepareSnapshot !PrepareSnapshotArgs
Expand All @@ -51,7 +51,7 @@ runCommand cmd =
CmdCreateMigration mdir txOutAddressType -> runCreateMigration mdir txOutAddressType
CmdReport report txOutAddressType -> runReport report txOutAddressType
CmdRollback slotNo txOutAddressType -> runRollback slotNo txOutAddressType
CmdRunMigrations mdir forceIndexes mockFix mldir txOutTabletype -> do
CmdRunMigrations mdir forceIndexes mldir txOutTabletype -> do
pgConfig <- runOrThrowIODb (readPGPass PGPassDefaultEnv)
unofficial <- snd <$> runMigrations pgConfig False mdir mldir Initial txOutTabletype
unless (null unofficial) $
Expand All @@ -60,9 +60,6 @@ runCommand cmd =
when forceIndexes $
void $
runMigrations pgConfig False mdir mldir Indexes txOutTabletype
when mockFix $
void $
runMigrations pgConfig False mdir mldir Fix txOutTabletype
CmdTxOutMigration txOutTableType -> do
runWithConnectionNoLogging PGPassDefaultEnv $ migrateTxOutDbTool txOutTableType
CmdUtxoSetAtBlock blkid txOutAddressType -> utxoSetAtSlot txOutAddressType blkid
Expand Down Expand Up @@ -170,7 +167,6 @@ pCommand =
CmdRunMigrations
<$> pMigrationDir
<*> pForceIndexes
<*> pMockFix
<*> optional pLogFileDir
<*> pTxOutTableType

Expand Down Expand Up @@ -232,20 +228,6 @@ pForceIndexes =
)
)

pMockFix :: Parser Bool
pMockFix =
Opt.flag
False
True
( Opt.long "mock-fix"
<> Opt.help
( mconcat
[ "Mocks the execution of the fix chainsync procedure"
, " By using this flag, db-sync later won't run the fixing procedures."
]
)
)

pTxOutTableType :: Parser TxOutTableType
pTxOutTableType =
Opt.flag
Expand Down
Loading

0 comments on commit 3b89ea1

Please sign in to comment.