Skip to content

Commit 9164d4a

Browse files
sgillespiekderme
authored andcommitted
feature(cardano-db-sync): Add new fields to insert options
* force_tx_in * preset
1 parent 9be8ac8 commit 9164d4a

File tree

27 files changed

+503
-259
lines changed

27 files changed

+503
-259
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ data CommandLineArgs = CommandLineArgs
117117
, claMigrateConsumed :: Bool
118118
, claPruneTxOut :: Bool
119119
, claBootstrap :: Bool
120-
, claForceTxIn :: Bool
121120
}
122121

123122
data WithConfigArgs = WithConfigArgs
@@ -275,7 +274,6 @@ mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
275274
, enpOnlyFix = claOnlyFix
276275
, enpForceIndexes = claForceIndexes
277276
, enpHasInOut = True
278-
, enpForceTxIn = claForceTxIn
279277
, enpSnEveryFollowing = 35
280278
, enpSnEveryLagging = 35
281279
, enpMaybeRollback = Nothing
@@ -304,7 +302,6 @@ initCommandLineArgs =
304302
, claMigrateConsumed = False
305303
, claPruneTxOut = False
306304
, claBootstrap = False
307-
, claForceTxIn = False
308305
}
309306

310307
emptyMetricsSetters :: MetricSetters

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ import Prelude ()
1414
defaultInsertConfig :: Assertion
1515
defaultInsertConfig = do
1616
cfg <- mkSyncNodeConfig alonzoConfigDir initCommandLineArgs
17-
dncInsertConfig cfg @?= def
17+
dncInsertOptions cfg @?= def
1818

1919
insertConfig :: Assertion
2020
insertConfig = do
2121
cfg <- mkSyncNodeConfig configDir initCommandLineArgs
2222
let expected =
23-
SyncInsertConfig
24-
{ spcTxOut = TxOutDisable
25-
, spcLedger = LedgerDisable
26-
, spcShelley = ShelleyDisable
27-
, spcMultiAsset = MultiAssetDisable
28-
, spcMetadata = MetadataDisable
29-
, spcPlutus = PlutusDisable
30-
, spcGovernance = GovernanceConfig False
31-
, spcOffchainPoolData = OffchainPoolDataConfig False
32-
, spcJsonType = JsonTypeDisable
23+
SyncInsertOptions
24+
{ sioTxOut = TxOutDisable
25+
, sioLedger = LedgerDisable
26+
, sioShelley = ShelleyDisable
27+
, sioMultiAsset = MultiAssetDisable
28+
, sioMetadata = MetadataDisable
29+
, sioPlutus = PlutusDisable
30+
, sioGovernance = GovernanceConfig False
31+
, sioOffchainPoolData = OffchainPoolDataConfig False
32+
, sioJsonType = JsonTypeDisable
3333
}
3434

35-
dncInsertConfig cfg @?= expected
35+
dncInsertOptions cfg @?= expected
3636
where
3737
configDir = "config-alonzo-insert-options"

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Test.Cardano.Db.Mock.Unit.Babbage.Config.MigrateConsumedPruneTxOut (
1616
) where
1717

1818
import qualified Cardano.Db as DB
19+
import Cardano.DbSync.Config.Types
1920
import Cardano.Mock.ChainSync.Server (IOManager, addBlock)
2021
import Cardano.Mock.Forging.Interpreter (forgeNext)
2122
import qualified Cardano.Mock.Forging.Tx.Babbage as Babbage
@@ -29,6 +30,7 @@ import Test.Cardano.Db.Mock.Config (
2930
CommandLineArgs (..),
3031
babbageConfigDir,
3132
initCommandLineArgs,
33+
mkSyncNodeConfig,
3234
replaceConfigFile,
3335
startDBSync,
3436
stopDBSync,
@@ -88,7 +90,6 @@ basicPrune = do
8890
cmdLineArgs =
8991
initCommandLineArgs
9092
{ claConfigFilename = "test-db-sync-config-prune.json"
91-
, claForceTxIn = True
9293
}
9394
testLabel = "configPrune"
9495

@@ -117,7 +118,6 @@ pruneWithSimpleRollback = do
117118
cmdLineArgs =
118119
initCommandLineArgs
119120
{ claConfigFilename = "test-db-sync-config-prune.json"
120-
, claForceTxIn = True
121121
}
122122
testLabel = "configPruneSimpleRollback"
123123

@@ -148,15 +148,16 @@ pruneWithFullTxRollback = do
148148
cmdLineArgs =
149149
initCommandLineArgs
150150
{ claConfigFilename = "test-db-sync-config-prune.json"
151-
, claForceTxIn = True
152151
}
153152
testLabel = "configPruneOnFullRollback"
154153

155154
-- The tx in the last, 2 x securityParam worth of blocks should not be pruned.
156155
-- In these tests, 2 x securityParam = 20 blocks.
157156
pruningShouldKeepSomeTx :: IOManager -> [(Text, Text)] -> Assertion
158-
pruningShouldKeepSomeTx = do
159-
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
157+
pruningShouldKeepSomeTx ioManager names = do
158+
syncNodeConfig <- mkSyncNodeConfig'
159+
160+
withConfig' syncNodeConfig $ \interpreter mockServer dbSyncEnv -> do
160161
startDBSync dbSyncEnv
161162
b1 <- forgeAndSubmitBlocks interpreter mockServer 80
162163
-- these two blocs + tx will fall withing the last 20 blocks so should not be pruned
@@ -173,6 +174,20 @@ pruningShouldKeepSomeTx = do
173174
assertTxInCount dbSyncEnv 0
174175
assertEqQuery dbSyncEnv DB.queryTxOutConsumedCount 0 "Unexpected TxOutConsumedByTxId count after prune"
175176
where
177+
withConfig' cfg f =
178+
withCustomConfig cmdLineArgs (Just cfg) babbageConfigDir testLabel f ioManager names
179+
180+
mkSyncNodeConfig' :: IO SyncNodeConfig
181+
mkSyncNodeConfig' = do
182+
initCfg <- mkSyncNodeConfig babbageConfigDir cmdLineArgs
183+
pure $
184+
initCfg
185+
{ dncInsertOptions =
186+
(dncInsertOptions initCfg)
187+
{ sioTxOut = TxOutPrune (ForceTxIn False)
188+
}
189+
}
190+
176191
cmdLineArgs =
177192
initCommandLineArgs
178193
{ claConfigFilename = "test-db-sync-config-prune.json"

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ import Prelude ()
1414
defaultInsertConfig :: Assertion
1515
defaultInsertConfig = do
1616
cfg <- mkSyncNodeConfig babbageConfigDir initCommandLineArgs
17-
dncInsertConfig cfg @?= def
17+
dncInsertOptions cfg @?= def
1818

1919
insertConfig :: Assertion
2020
insertConfig = do
2121
cfg <- mkSyncNodeConfig configDir initCommandLineArgs
2222
let expected =
23-
SyncInsertConfig
24-
{ spcTxOut = TxOutDisable
25-
, spcLedger = LedgerDisable
26-
, spcShelley = ShelleyDisable
27-
, spcMultiAsset = MultiAssetDisable
28-
, spcMetadata = MetadataDisable
29-
, spcPlutus = PlutusDisable
30-
, spcGovernance = GovernanceConfig False
31-
, spcOffchainPoolData = OffchainPoolDataConfig False
32-
, spcJsonType = JsonTypeDisable
23+
SyncInsertOptions
24+
{ sioTxOut = TxOutDisable
25+
, sioLedger = LedgerDisable
26+
, sioShelley = ShelleyDisable
27+
, sioMultiAsset = MultiAssetDisable
28+
, sioMetadata = MetadataDisable
29+
, sioPlutus = PlutusDisable
30+
, sioGovernance = GovernanceConfig False
31+
, sioOffchainPoolData = OffchainPoolDataConfig False
32+
, sioJsonType = JsonTypeDisable
3333
}
3434

35-
dncInsertConfig cfg @?= expected
35+
dncInsertOptions cfg @?= expected
3636
where
3737
configDir = "config-babbage-insert-options"

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut (
1616
) where
1717

1818
import qualified Cardano.Db as DB
19-
import Cardano.DbSync.Config (SyncNodeConfig (..))
19+
import Cardano.DbSync.Config.Types
2020
import Cardano.Mock.ChainSync.Server (IOManager (), addBlock)
2121
import Cardano.Mock.Forging.Interpreter (forgeNext)
2222
import qualified Cardano.Mock.Forging.Tx.Conway as Conway
@@ -99,7 +99,6 @@ basicPrune = do
9999
args =
100100
initCommandLineArgs
101101
{ claConfigFilename = "test-db-sync-config-prune.json"
102-
, claForceTxIn = True
103102
}
104103
testLabel = "conwayConfigPrune"
105104
fullBlockSize b = fromIntegral $ length b + 2
@@ -140,7 +139,6 @@ pruneWithSimpleRollback =
140139
cmdLineArgs =
141140
initCommandLineArgs
142141
{ claConfigFilename = "test-db-sync-config-prune.json"
143-
, claForceTxIn = True
144142
}
145143
testLabel = "conwayConfigPruneSimpleRollback"
146144
fullBlockSize b = fromIntegral $ length b + 4
@@ -181,14 +179,15 @@ pruneWithFullTxRollback =
181179
cmdLineArgs =
182180
initCommandLineArgs
183181
{ claConfigFilename = "test-db-sync-config-prune.json"
184-
, claForceTxIn = True
185182
}
186183
testLabel = "conwayConfigPruneOnFullRollback"
187184

188185
-- The transactions in the last `2 * securityParam` blocks should not be pruned
189186
pruningShouldKeepSomeTx :: IOManager -> [(Text, Text)] -> Assertion
190-
pruningShouldKeepSomeTx =
191-
withCustomConfig cmdLineArgs Nothing conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
187+
pruningShouldKeepSomeTx ioManager names = do
188+
syncNodeConfig <- mkSyncNodeConfig'
189+
190+
withConfig' syncNodeConfig $ \interpreter mockServer dbSync -> do
192191
startDBSync dbSync
193192

194193
-- Forge some blocks
@@ -213,6 +212,20 @@ pruningShouldKeepSomeTx =
213212
assertTxInCount dbSync 0
214213
assertEqQuery dbSync DB.queryTxOutConsumedCount 0 "Unexpected TxOutConsumedByTxId count after prune"
215214
where
215+
withConfig' cfg f =
216+
withCustomConfig cmdLineArgs (Just cfg) conwayConfigDir testLabel f ioManager names
217+
218+
mkSyncNodeConfig' :: IO SyncNodeConfig
219+
mkSyncNodeConfig' = do
220+
initCfg <- mkSyncNodeConfig conwayConfigDir cmdLineArgs
221+
pure $
222+
initCfg
223+
{ dncInsertOptions =
224+
(dncInsertOptions initCfg)
225+
{ sioTxOut = TxOutPrune (ForceTxIn False)
226+
}
227+
}
228+
216229
cmdLineArgs =
217230
initCommandLineArgs
218231
{ claConfigFilename = "test-db-sync-config-prune.json"

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

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE NumericUnderscores #-}
21
{-# LANGUAGE OverloadedStrings #-}
32

43
module Test.Cardano.Db.Mock.Unit.Conway.Config.Parse (
@@ -9,22 +8,15 @@ module Test.Cardano.Db.Mock.Unit.Conway.Config.Parse (
98
wrongConwayGenesisHash,
109
insertConfig,
1110
defaultInsertConfig,
12-
basicPrune,
1311
) where
1412

15-
import qualified Cardano.Db as DB
1613
import Cardano.DbSync.Config
1714
import Cardano.DbSync.Config.Types
1815
import Cardano.DbSync.Error
19-
import Cardano.Mock.ChainSync.Server (IOManager ())
20-
import qualified Cardano.Mock.Forging.Tx.Conway as Conway
21-
import Cardano.Mock.Forging.Types (UTxOIndex (..))
2216
import Cardano.Prelude hiding (from, isNothing)
2317
import qualified Data.Aeson as Aeson
2418
import Data.Default.Class (Default (..))
2519
import Test.Cardano.Db.Mock.Config
26-
import Test.Cardano.Db.Mock.UnifiedApi
27-
import Test.Cardano.Db.Mock.Validate
2820
import Test.Tasty.HUnit (Assertion (), assertBool, (@?=))
2921
import Prelude ()
3022

@@ -90,64 +82,26 @@ isConwayConfigError = either isConwayConfigError' (const False)
9082
defaultInsertConfig :: Assertion
9183
defaultInsertConfig = do
9284
cfg <- mkSyncNodeConfig configDir initCommandLineArgs
93-
dncInsertConfig cfg @?= def
85+
dncInsertOptions cfg @?= def
9486
where
9587
configDir = "config-conway"
9688

9789
insertConfig :: Assertion
9890
insertConfig = do
9991
cfg <- mkSyncNodeConfig configDir initCommandLineArgs
10092
let expected =
101-
SyncInsertConfig
102-
{ spcTxOut = TxOutDisable
103-
, spcLedger = LedgerDisable
104-
, spcShelley = ShelleyDisable
105-
, spcMultiAsset = MultiAssetDisable
106-
, spcMetadata = MetadataDisable
107-
, spcPlutus = PlutusDisable
108-
, spcGovernance = GovernanceConfig False
109-
, spcOffchainPoolData = OffchainPoolDataConfig False
110-
, spcJsonType = JsonTypeDisable
93+
SyncInsertOptions
94+
{ sioTxOut = TxOutDisable
95+
, sioLedger = LedgerDisable
96+
, sioShelley = ShelleyDisable
97+
, sioMultiAsset = MultiAssetDisable
98+
, sioMetadata = MetadataDisable
99+
, sioPlutus = PlutusDisable
100+
, sioGovernance = GovernanceConfig False
101+
, sioOffchainPoolData = OffchainPoolDataConfig False
102+
, sioJsonType = JsonTypeDisable
111103
}
112104

113-
dncInsertConfig cfg @?= expected
105+
dncInsertOptions cfg @?= expected
114106
where
115107
configDir = "config-conway-insert-options"
116-
117-
basicPrune :: IOManager -> [(Text, Text)] -> Assertion
118-
basicPrune = do
119-
withCustomConfigAndDropDB args Nothing cfgDir testLabel $ \interpreter mockServer dbSync -> do
120-
startDBSync dbSync
121-
122-
-- Add some blocks
123-
blks <- forgeAndSubmitBlocks interpreter mockServer 50
124-
125-
-- Add blocks with transactions
126-
void $
127-
withConwayFindLeaderAndSubmitTx interpreter mockServer $
128-
Conway.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10_000 10_000
129-
void $
130-
withConwayFindLeaderAndSubmitTx interpreter mockServer $
131-
Conway.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10_000 10_000
132-
133-
-- Check tx-out count before pruning
134-
assertBlockNoBackoff dbSync (fullBlockSize blks)
135-
assertEqQuery dbSync DB.queryTxOutCount 14 "new epoch didn't prune tx_out column that are null"
136-
137-
blks' <- forgeAndSubmitBlocks interpreter mockServer 48
138-
assertBlockNoBackoff dbSync (fullBlockSize $ blks <> blks')
139-
140-
-- Check that tx_out was pruned
141-
assertEqQuery dbSync DB.queryTxOutCount 12 "the pruning didn't work correctly as the tx-out count is incorrect"
142-
-- Check unspent tx
143-
assertUnspentTx dbSync
144-
where
145-
args =
146-
initCommandLineArgs
147-
{ claConfigFilename = "test-db-sync-config-prune.json"
148-
, claMigrateConsumed = True
149-
, claPruneTxOut = True
150-
}
151-
testLabel = "conwayConfigPrune"
152-
fullBlockSize b = fromIntegral $ length b + 2
153-
cfgDir = conwayConfigDir

cardano-chain-gen/test/testfiles/config-alonzo-insert-options/test-db-sync-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@
112112
}
113113
],
114114
"insert_options": {
115-
"tx_out": "disable",
115+
"tx_out": {
116+
"value": "disable"
117+
},
116118
"ledger": "disable",
117119
"shelley": {
118120
"enable": false,

cardano-chain-gen/test/testfiles/config-babbage-insert-options/test-db-sync-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@
112112
}
113113
],
114114
"insert_options": {
115-
"tx_out": "disable",
115+
"tx_out": {
116+
"value": "disable"
117+
},
116118
"ledger": "disable",
117119
"shelley": {
118120
"enable": false,

cardano-chain-gen/test/testfiles/config-conway-insert-options/test-db-sync-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@
112112
}
113113
],
114114
"insert_options": {
115-
"tx_out": "disable",
115+
"tx_out": {
116+
"value": "disable",
117+
},
116118
"ledger": "disable",
117119
"shelley": {
118120
"enable": false,

cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-bootstrap.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
}
113113
],
114114
"insert_options": {
115-
"tx_out": "bootstrap"
115+
"tx_out": {
116+
"value": "bootstrap"
117+
}
116118
}
117119
}

0 commit comments

Comments
 (0)