Skip to content

Commit

Permalink
Fourmolize
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed May 30, 2023
1 parent 37c50fb commit 9738a34
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 140 deletions.
14 changes: 8 additions & 6 deletions cardano-db-sync/app/cardano-db-sync.hs
Expand Up @@ -264,9 +264,10 @@ pMigrateConsumed =
False
True
( Opt.long "consumed-tx-out"
<> Opt.help "Runs the tx_out migration, which adds a new field.If this is set once,\
\ then it must be always be set on following executions of db-sync, unless prune-tx-out\
\ is used instead."
<> Opt.help
"Runs the tx_out migration, which adds a new field.If this is set once,\
\ then it must be always be set on following executions of db-sync, unless prune-tx-out\
\ is used instead."
)

pPruneTxOut :: Parser Bool
Expand All @@ -275,9 +276,10 @@ pPruneTxOut =
False
True
( Opt.long "prune-tx-out"
<> Opt.help "Prunes the consumed tx_out periodically. This assumes \
\ consumed-tx-out is also set, even if it's not. If this is set once,\
\ then it must be always set on following executions of db-sync."
<> Opt.help
"Prunes the consumed tx_out periodically. This assumes \
\ consumed-tx-out is also set, even if it's not. If this is set once,\
\ then it must be always set on following executions of db-sync."
)

pVersionCommand :: Parser SyncCommand
Expand Down
3 changes: 2 additions & 1 deletion cardano-db-sync/src/Cardano/DbSync/Api.hs
Expand Up @@ -129,7 +129,8 @@ data ExtraMigrations = ExtraMigrations
{ emRan :: Bool
, emConsume :: Bool
, emPrune :: Bool
} deriving Show
}
deriving (Show)

setConsistentLevel :: SyncEnv -> ConsistentLevel -> IO ()
setConsistentLevel env cst = do
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync/Era.hs
Expand Up @@ -8,13 +8,13 @@ module Cardano.DbSync.Era (
insertValidateGenesisDist,
) where

import Cardano.DbSync.Api
import Cardano.DbSync.Config
import qualified Cardano.DbSync.Era.Byron.Genesis as Byron
import qualified Cardano.DbSync.Era.Shelley.Genesis as Shelley
import Cardano.DbSync.Era.Shelley.Offline as X
import Cardano.DbSync.Error
import Cardano.Prelude
import Cardano.DbSync.Api

insertValidateGenesisDist ::
SyncEnv ->
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync/Era/Byron/Genesis.hs
Expand Up @@ -17,6 +17,7 @@ import qualified Cardano.Chain.Genesis as Byron
import qualified Cardano.Chain.UTxO as Byron
import qualified Cardano.Crypto as Crypto
import qualified Cardano.Db as DB
import Cardano.DbSync.Api
import Cardano.DbSync.Config.Types
import qualified Cardano.DbSync.Era.Byron.Util as Byron
import Cardano.DbSync.Era.Util (liftLookupFail)
Expand All @@ -31,7 +32,6 @@ import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Database.Persist.Sql (SqlBackend)
import Paths_cardano_db_sync (version)
import Cardano.DbSync.Api

-- | Idempotent insert the initial Genesis distribution transactions into the DB.
-- If these transactions are already in the DB, they are validated.
Expand Down
6 changes: 4 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Era/Byron/Insert.hs
Expand Up @@ -225,7 +225,9 @@ insertTx syncEnv blkId tx blockIndex = do
lift $ zipWithM_ (insertTxOut tracer hasConsumed txId) [0 ..] (toList . Byron.txOutputs $ Byron.taTx tx)
txInIds <- mapM (insertTxIn tracer txId) resolvedInputs
whenConsumeTxOut syncEnv $
lift $ DB.updateListTxOutConsumedByTxInId $ zip (thrd3 <$> resolvedInputs) txInIds
lift $
DB.updateListTxOutConsumedByTxInId $
zip (thrd3 <$> resolvedInputs) txInIds
where
tracer :: Trace IO Text
tracer = getTrace syncEnv
Expand Down Expand Up @@ -266,7 +268,7 @@ insertTxIn ::
DB.TxId ->
(Byron.TxIn, DB.TxId, DB.TxOutId, DbLovelace) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) DB.TxInId
insertTxIn _tracer txInId (Byron.TxInUtxo _txHash inIndex, txOutTxId, _, _) = do
insertTxIn _tracer txInId (Byron.TxInUtxo _txHash inIndex, txOutTxId, _, _) = do
lift . DB.insertTxIn $
DB.TxIn
{ DB.txInTxInId = txInId
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs
Expand Up @@ -13,6 +13,7 @@ module Cardano.DbSync.Era.Shelley.Genesis (

import Cardano.BM.Trace (Trace, logError, logInfo)
import qualified Cardano.Db as DB
import Cardano.DbSync.Api
import Cardano.DbSync.Cache
import qualified Cardano.DbSync.Era.Shelley.Generic.Util as Generic
import Cardano.DbSync.Era.Shelley.Insert
Expand Down Expand Up @@ -47,7 +48,6 @@ import Ouroboros.Consensus.Shelley.Node (
emptyGenesisStaking,
)
import Paths_cardano_db_sync (version)
import Cardano.DbSync.Api

-- | Idempotent insert the initial Genesis distribution transactions into the DB.
-- If these transactions are already in the DB, they are validated.
Expand Down
13 changes: 7 additions & 6 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Expand Up @@ -387,12 +387,13 @@ prepareTxIn txInId redeemers (txIn, txOutId, mTxOutId, _lovelace) =
, etiTxOutId = mTxOutId
}
where
txInDB = DB.TxIn
{ DB.txInTxInId = txInId
, DB.txInTxOutId = txOutId
, DB.txInTxOutIndex = fromIntegral $ Generic.txInIndex txIn
, DB.txInRedeemerId = mlookup (Generic.txInRedeemerIndex txIn) redeemers
}
txInDB =
DB.TxIn
{ DB.txInTxInId = txInId
, DB.txInTxOutId = txOutId
, DB.txInTxOutIndex = fromIntegral $ Generic.txInIndex txIn
, DB.txInRedeemerId = mlookup (Generic.txInRedeemerIndex txIn) redeemers
}

insertCollateralTxIn ::
(MonadBaseControl IO m, MonadIO m) =>
Expand Down
19 changes: 10 additions & 9 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert/Grouped.hs
Expand Up @@ -16,16 +16,16 @@ module Cardano.DbSync.Era.Shelley.Insert.Grouped (
import Cardano.BM.Trace (Trace, logWarning)
import Cardano.Db (DbLovelace (..), minIdsToText, textShow)
import qualified Cardano.Db as DB
import Cardano.DbSync.Api
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
import Cardano.DbSync.Era.Shelley.Query
import Cardano.DbSync.Era.Util
import Cardano.DbSync.Error
import Cardano.Prelude
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Data.List as List
import Database.Persist.Sql (SqlBackend)
import qualified Data.Text as Text
import Cardano.DbSync.Api
import Database.Persist.Sql (SqlBackend)

-- | Group data within the same block, to insert them together in batches
--
Expand Down Expand Up @@ -62,7 +62,8 @@ data ExtendedTxOut = ExtendedTxOut
data ExtendedTxIn = ExtendedTxIn
{ etiTxIn :: !DB.TxIn
, etiTxOutId :: !(Either Generic.TxIn DB.TxOutId)
} deriving Show
}
deriving (Show)

instance Monoid BlockGroupedData where
mempty = BlockGroupedData [] [] [] []
Expand Down Expand Up @@ -141,10 +142,9 @@ resolveTxInputs ::
resolveTxInputs groupedOutputs txIn =
liftLookupFail ("resolveTxInputs " <> textShow txIn <> " ") $ do
qres <-
if True then
fmap convertnotFound <$> queryResolveInput txIn
else
fmap convertFound <$> queryResolveInput2 txIn
if True
then fmap convertnotFound <$> queryResolveInput txIn
else fmap convertFound <$> queryResolveInput2 txIn
case qres of
Right ret -> pure $ Right ret
Left err ->
Expand All @@ -168,8 +168,9 @@ resolveRemainingInputs etis mp =
where
f eti = case etiTxOutId eti of
Right _ -> pure eti
Left txIn | Just txOutId <- fst <$> find (matches txIn . snd) mp ->
pure eti {etiTxOutId = Right txOutId}
Left txIn
| Just txOutId <- fst <$> find (matches txIn . snd) mp ->
pure eti {etiTxOutId = Right txOutId}
_ -> pure eti

resolveScriptHash ::
Expand Down
2 changes: 1 addition & 1 deletion cardano-db/src/Cardano/Db.hs
Expand Up @@ -14,6 +14,7 @@ import Cardano.Db.Delete as X
import Cardano.Db.Error as X
import Cardano.Db.Insert as X
import Cardano.Db.Migration as X
import Cardano.Db.Migration.Extra.CosnumedTxOut.Queries (migrateTxOut)
import Cardano.Db.Migration.Version as X
import Cardano.Db.MinId as X
import Cardano.Db.Multiplex as X
Expand All @@ -25,4 +26,3 @@ import Cardano.Db.Schema.Types as X
import Cardano.Db.Text as X
import Cardano.Db.Types as X
import Cardano.Db.Version (gitRev)
import Cardano.Db.Migration.Extra.CosnumedTxOut.Queries (migrateTxOut)
11 changes: 9 additions & 2 deletions cardano-db/src/Cardano/Db/Delete.hs
Expand Up @@ -33,8 +33,15 @@ import Data.Text (Text)
import Data.Word (Word64)
import Database.Esqueleto.Experimental (PersistEntity, PersistField, persistIdField)
import Database.Persist.Class.PersistQuery (deleteWhere)
import Database.Persist.Sql (PersistEntityBackend, SqlBackend, delete, deleteWhereCount,
selectKeysList, (==.), (>=.))
import Database.Persist.Sql (
PersistEntityBackend,
SqlBackend,
delete,
deleteWhereCount,
selectKeysList,
(==.),
(>=.),
)

deleteBlocksSlotNoNoTrace :: MonadIO m => SlotNo -> ReaderT SqlBackend m Bool
deleteBlocksSlotNoNoTrace = deleteBlocksSlotNo nullTracer
Expand Down

0 comments on commit 9738a34

Please sign in to comment.