Skip to content

Commit 94cbc9a

Browse files
authored
Merge pull request #1820 from IntersectMBO/1333-new-AddressDetail-table
1333 - add new AddressDetail table for TxOut
2 parents 161db86 + a234f98 commit 94cbc9a

File tree

89 files changed

+3706
-2737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3706
-2737
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

+35-22
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ module Test.Cardano.Db.Mock.Config (
5858
withCustomConfigAndLogs,
5959
withFullConfig',
6060
replaceConfigFile,
61+
txOutTableTypeFromConfig,
6162
) where
6263

6364
import Cardano.Api (NetworkMagic (..))
64-
import qualified Cardano.Db as Db
65+
import qualified Cardano.Db as DB
6566
import Cardano.DbSync
6667
import Cardano.DbSync.Config
6768
import Cardano.DbSync.Config.Cardano
@@ -224,16 +225,16 @@ pollDBSync env = do
224225
withDBSyncEnv :: IO DBSyncEnv -> (DBSyncEnv -> IO a) -> IO a
225226
withDBSyncEnv mkEnv = bracket mkEnv stopDBSyncIfRunning
226227

227-
getDBSyncPGPass :: DBSyncEnv -> Db.PGPassSource
228+
getDBSyncPGPass :: DBSyncEnv -> DB.PGPassSource
228229
getDBSyncPGPass = enpPGPassSource . dbSyncParams
229230

230231
queryDBSync :: DBSyncEnv -> ReaderT SqlBackend (NoLoggingT IO) a -> IO a
231-
queryDBSync env = Db.runWithConnectionNoLogging (getDBSyncPGPass env)
232+
queryDBSync env = DB.runWithConnectionNoLogging (getDBSyncPGPass env)
232233

233234
getPoolLayer :: DBSyncEnv -> IO PoolDataLayer
234235
getPoolLayer env = do
235-
pgconfig <- runOrThrowIO $ Db.readPGPass (enpPGPassSource $ dbSyncParams env)
236-
pool <- runNoLoggingT $ createPostgresqlPool (Db.toConnectionString pgconfig) 1 -- Pool size of 1 for tests
236+
pgconfig <- runOrThrowIO $ DB.readPGPass (enpPGPassSource $ dbSyncParams env)
237+
pool <- runNoLoggingT $ createPostgresqlPool (DB.toConnectionString pgconfig) 1 -- Pool size of 1 for tests
237238
pure $
238239
postgresqlPoolDataLayer
239240
nullTracer
@@ -274,15 +275,15 @@ mkShelleyCredentials bulkFile = do
274275
-- | staticDir can be shared by tests running in parallel. mutableDir not.
275276
mkSyncNodeParams :: FilePath -> FilePath -> CommandLineArgs -> IO SyncNodeParams
276277
mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
277-
pgconfig <- runOrThrowIO Db.readPGPassDefault
278+
pgconfig <- runOrThrowIO DB.readPGPassDefault
278279

279280
pure $
280281
SyncNodeParams
281282
{ enpConfigFile = mkConfigFile staticDir claConfigFilename
282283
, enpSocketPath = SocketPath $ mutableDir </> ".socket"
283284
, enpMaybeLedgerStateDir = Just $ LedgerStateDir $ mutableDir </> "ledger-states"
284285
, enpMigrationDir = MigrationDir "../schema"
285-
, enpPGPassSource = Db.PGPassCached pgconfig
286+
, enpPGPassSource = DB.PGPassCached pgconfig
286287
, enpEpochDisabled = claEpochDisabled
287288
, enpHasCache = claHasCache
288289
, enpSkipFix = claSkipFix
@@ -301,21 +302,21 @@ mkConfigFile :: FilePath -> FilePath -> ConfigFile
301302
mkConfigFile staticDir cliConfigFilename =
302303
ConfigFile $ staticDir </> cliConfigFilename
303304

304-
configPruneForceTxIn :: SyncNodeConfig -> SyncNodeConfig
305-
configPruneForceTxIn cfg = do
306-
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutPrune (ForceTxIn True)}}
305+
configPruneForceTxIn :: Bool -> SyncNodeConfig -> SyncNodeConfig
306+
configPruneForceTxIn useTxOutAddress cfg = do
307+
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumedPrune (ForceTxIn True) (UseTxOutAddress useTxOutAddress)}}
307308

308-
configPrune :: SyncNodeConfig -> SyncNodeConfig
309-
configPrune cfg = do
310-
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutPrune (ForceTxIn False)}}
309+
configPrune :: Bool -> SyncNodeConfig -> SyncNodeConfig
310+
configPrune useTxOutAddress cfg = do
311+
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumedPrune (ForceTxIn False) (UseTxOutAddress useTxOutAddress)}}
311312

312-
configConsume :: SyncNodeConfig -> SyncNodeConfig
313-
configConsume cfg = do
314-
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumed (ForceTxIn False)}}
313+
configConsume :: Bool -> SyncNodeConfig -> SyncNodeConfig
314+
configConsume useTxOutAddress cfg = do
315+
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumed (ForceTxIn False) (UseTxOutAddress useTxOutAddress)}}
315316

316-
configBootstrap :: SyncNodeConfig -> SyncNodeConfig
317-
configBootstrap cfg = do
318-
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutBootstrap (ForceTxIn False)}}
317+
configBootstrap :: Bool -> SyncNodeConfig -> SyncNodeConfig
318+
configBootstrap useTxOutAddress cfg = do
319+
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumedBootstrap (ForceTxIn False) (UseTxOutAddress useTxOutAddress)}}
319320

320321
configPlutusDisable :: SyncNodeConfig -> SyncNodeConfig
321322
configPlutusDisable cfg = do
@@ -574,12 +575,12 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
574575
-- we dont fork dbsync here. Just prepare it as an action
575576
withDBSyncEnv (mkDBSyncEnv dbsyncParams syncNodeConfig partialDbSyncRun) $ \dbSyncEnv -> do
576577
let pgPass = getDBSyncPGPass dbSyncEnv
577-
tableNames <- Db.getAllTablleNames pgPass
578+
tableNames <- DB.getAllTablleNames pgPass
578579
-- We only want to create the table schema once for the tests so here we check
579580
-- if there are any table names.
580581
if null tableNames || shouldDropDB
581-
then void . hSilence [stderr] $ Db.recreateDB pgPass
582-
else void . hSilence [stderr] $ Db.truncateTables pgPass tableNames
582+
then void . hSilence [stderr] $ DB.recreateDB pgPass
583+
else void . hSilence [stderr] $ DB.truncateTables pgPass tableNames
583584
action interpreter mockServer dbSyncEnv
584585
where
585586
mutableDir = mkMutableDir testLabelFilePath
@@ -605,3 +606,15 @@ replaceConfigFile newFilename dbSync@DBSyncEnv {..} = do
605606
configDir = mkConfigDir . takeDirectory . unConfigFile . enpConfigFile $ dbSyncParams
606607
newParams =
607608
dbSyncParams {enpConfigFile = ConfigFile $ configDir </> newFilename}
609+
610+
txOutTableTypeFromConfig :: DBSyncEnv -> DB.TxOutTableType
611+
txOutTableTypeFromConfig dbSyncEnv =
612+
case sioTxOut $ dncInsertOptions $ dbSyncConfig dbSyncEnv of
613+
TxOutDisable -> DB.TxOutCore
614+
TxOutEnable useTxOutAddress -> getTxOutTT useTxOutAddress
615+
TxOutConsumed _ useTxOutAddress -> getTxOutTT useTxOutAddress
616+
TxOutConsumedPrune _ useTxOutAddress -> getTxOutTT useTxOutAddress
617+
TxOutConsumedBootstrap _ useTxOutAddress -> getTxOutTT useTxOutAddress
618+
where
619+
getTxOutTT :: UseTxOutAddress -> DB.TxOutTableType
620+
getTxOutTT value = if unUseTxOutAddress value then DB.TxOutVariantAddress else DB.TxOutCore

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Plutus.hs

+19-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module Test.Cardano.Db.Mock.Unit.Alonzo.Plutus (
2929
) where
3030

3131
import qualified Cardano.Crypto.Hash as Crypto
32+
import Cardano.Db (TxOutTableType (..))
3233
import qualified Cardano.Db as DB
34+
import qualified Cardano.Db.Schema.Core.TxOut as C
35+
import qualified Cardano.Db.Schema.Variant.TxOut as V
3336
import Cardano.DbSync.Era.Shelley.Generic.Util (renderAddress)
3437
import Cardano.Ledger.Coin
3538
import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..), PolicyID (..))
@@ -90,10 +93,24 @@ simpleScript =
9093
Alonzo.mkLockByScriptTx (UTxOIndex 0) [True] 20000 20000
9194

9295
assertBlockNoBackoff dbSync (fromIntegral $ length a + 2)
93-
assertEqQuery dbSync (fmap getOutFields <$> DB.queryScriptOutputs) [expectedFields] "Unexpected script outputs"
96+
assertEqQuery dbSync (fmap getOutFields <$> DB.queryScriptOutputs TxOutCore) [expectedFields] "Unexpected script outputs"
9497
where
9598
testLabel = "simpleScript-alonzo"
96-
getOutFields txOut = (DB.txOutAddress txOut, DB.txOutAddressHasScript txOut, DB.txOutValue txOut, DB.txOutDataHash txOut)
99+
getOutFields txOutW = case txOutW of
100+
DB.CTxOutW txOut ->
101+
( C.txOutAddress txOut
102+
, C.txOutAddressHasScript txOut
103+
, C.txOutValue txOut
104+
, C.txOutDataHash txOut
105+
)
106+
DB.VTxOutW txout mAddress -> case mAddress of
107+
Just address ->
108+
( V.addressAddress address
109+
, V.addressHasScript address
110+
, V.txOutValue txout
111+
, V.txOutDataHash txout
112+
)
113+
Nothing -> error "AlonzoSimpleScript: expected an address"
97114
expectedFields =
98115
( renderAddress alwaysSucceedsScriptAddr
99116
, True

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs

+17-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ unitTests iom knownMigrations =
3434
[ testCase "default insert config" Config.defaultInsertConfig
3535
, testCase "insert config" Config.insertConfig
3636
, testGroup
37-
"consumed-tx-out and prune-tx-out"
38-
[ test "flag check" MigrateConsumedPruneTxOut.txConsumedColumnCheck
39-
, test "basic prune" MigrateConsumedPruneTxOut.basicPrune
37+
"tx-out"
38+
[ test "basic prune" MigrateConsumedPruneTxOut.basicPrune
39+
, test "basic prune with address table" MigrateConsumedPruneTxOut.basicPruneWithAddress
4040
, test "prune with simple rollback" MigrateConsumedPruneTxOut.pruneWithSimpleRollback
4141
, test "prune with full tx rollback" MigrateConsumedPruneTxOut.pruneWithFullTxRollback
4242
, test "pruning should keep some tx" MigrateConsumedPruneTxOut.pruningShouldKeepSomeTx
@@ -48,6 +48,20 @@ unitTests iom knownMigrations =
4848
, expectFailSilent "set prune flag, restart missing prune flag" $ MigrateConsumedPruneTxOut.pruneRestartMissingFlag iom knownMigrations
4949
, expectFailSilent "set bootstrap flag, restart missing bootstrap flag" $ MigrateConsumedPruneTxOut.bootstrapRestartMissingFlag iom knownMigrations
5050
]
51+
, testGroup
52+
"tx-out using Address table"
53+
[ test "basic prune with address table" MigrateConsumedPruneTxOut.basicPruneWithAddress
54+
, test "prune with simple rollback with address table" MigrateConsumedPruneTxOut.pruneWithSimpleRollbackWithAddress
55+
, test "prune with full tx rollback with address table" MigrateConsumedPruneTxOut.pruneWithFullTxRollbackWithAddress
56+
, test "pruning should keep some tx with address table" MigrateConsumedPruneTxOut.pruningShouldKeepSomeTxWithAddress
57+
, test "prune and rollback one block with address table" MigrateConsumedPruneTxOut.pruneAndRollBackOneBlockWithAddress
58+
, test "no pruning and rollback with address table" MigrateConsumedPruneTxOut.noPruneAndRollBackWithAddress
59+
, test "prune same block with address table" MigrateConsumedPruneTxOut.pruneSameBlockWithAddress
60+
, test "no pruning same block with address table" MigrateConsumedPruneTxOut.noPruneSameBlockWithAddress
61+
, expectFailSilent "restart with new consumed set to false, with address table" $ MigrateConsumedPruneTxOut.migrateAndPruneRestartWithAddress iom knownMigrations
62+
, expectFailSilent "set prune flag, restart missing prune flag, with address table" $ MigrateConsumedPruneTxOut.pruneRestartMissingFlagWithAddress iom knownMigrations
63+
, expectFailSilent "set bootstrap flag, restart missing bootstrap flag, with address table" $ MigrateConsumedPruneTxOut.bootstrapRestartMissingFlagWithAddress iom knownMigrations
64+
]
5165
]
5266
, testGroup
5367
"simple"

0 commit comments

Comments
 (0)