Skip to content

Commit 168290d

Browse files
committed
stage 4
1 parent fd13fa4 commit 168290d

File tree

42 files changed

+861
-617
lines changed

Some content is hidden

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

42 files changed

+861
-617
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pruningShouldKeepSomeTx ioManager names = do
189189
initCfg
190190
{ dncInsertOptions =
191191
(dncInsertOptions initCfg)
192-
{ sioTxOut = TxOutPrune (ForceTxIn False)
192+
{ sioTxOut = TxOutConsumedPrune (ForceTxIn False) (UsedTxOutAddress False)
193193
}
194194
}
195195

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pruningShouldKeepSomeTx ioManager names = do
227227
initCfg
228228
{ dncInsertOptions =
229229
(dncInsertOptions initCfg)
230-
{ sioTxOut = TxOutPrune (ForceTxIn False)
230+
{ sioTxOut = TxOutConsumedPrune (ForceTxIn False)
231231
}
232232
}
233233

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ assertAddrValues ::
212212
assertAddrValues env ix expected sta = do
213213
addr <- assertRight $ resolveAddress ix sta
214214
let address = Ledger.serialiseAddr addr
215-
q = queryAddressOutputs address
215+
q = queryAddressOutputs address (env)
216216
assertEqBackoff env q expected defaultDelays "Unexpected Balance"
217217

218218
assertRight :: Show err => Either err a -> IO a

cardano-db-sync/src/Cardano/DbSync.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ extractSyncOptions :: SyncNodeParams -> Bool -> SyncNodeConfig -> SyncOptions
238238
extractSyncOptions snp aop snc =
239239
SyncOptions
240240
{ soptEpochAndCacheEnabled =
241-
not isTxOutBootstrap'
241+
not isTxOutConsumedBootstrap'
242242
&& ioInOut iopts
243243
&& not (enpEpochDisabled snp && enpHasCache snp)
244244
, soptAbortOnInvalid = aop
@@ -248,8 +248,8 @@ extractSyncOptions snp aop snc =
248248
, soptPruneConsumeMigration =
249249
initPruneConsumeMigration
250250
isTxOutConsumed'
251-
isTxOutPrune'
252-
isTxOutBootstrap'
251+
isTxOutConsumedPrune'
252+
isTxOutConsumedBootstrap'
253253
forceTxIn'
254254
, soptInsertOptions = iopts
255255
, snapshotEveryFollowing = enpSnEveryFollowing snp
@@ -278,7 +278,7 @@ extractSyncOptions snp aop snc =
278278
, ioPoolStats = isPoolStatsEnabled (sioPoolStats (dncInsertOptions snc))
279279
, ioGov = useGovernance
280280
, ioRemoveJsonbFromSchema = isRemoveJsonbFromSchemaEnabled (sioRemoveJsonbFromSchema (dncInsertOptions snc))
281-
, ioAddress = unTxOutTableTypeConfig (sioTxOutTableType (dncInsertOptions snc))
281+
, ioTxOutTableType = ioTxOutTableType'
282282
}
283283

284284
useLedger = sioLedger (dncInsertOptions snc) == LedgerEnable
@@ -288,10 +288,14 @@ extractSyncOptions snp aop snc =
288288
isGovernanceEnabled (sioGovernance (dncInsertOptions snc))
289289

290290
isTxOutConsumed' = isTxOutConsumed . sioTxOut . dncInsertOptions $ snc
291-
isTxOutPrune' = isTxOutPrune . sioTxOut . dncInsertOptions $ snc
292-
isTxOutBootstrap' = isTxOutBootstrap . sioTxOut . dncInsertOptions $ snc
291+
isTxOutConsumedPrune' = isTxOutConsumedPrune . sioTxOut . dncInsertOptions $ snc
292+
isTxOutConsumedBootstrap' = isTxOutConsumedBootstrap . sioTxOut . dncInsertOptions $ snc
293293
isTxOutEnabled' = isTxOutEnabled . sioTxOut . dncInsertOptions $ snc
294294
forceTxIn' = forceTxIn . sioTxOut . dncInsertOptions $ snc
295+
ioTxOutTableType' =
296+
if unTxOutTableTypeConfig . sioTxOutTableType . dncInsertOptions $ snc
297+
then TxOutCore
298+
else TxOutVariant
295299

296300
startupReport :: Trace IO Text -> Bool -> SyncNodeParams -> IO ()
297301
startupReport trce aop params = do

cardano-db-sync/src/Cardano/DbSync/Api.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Cardano.DbSync.Api (
2828
getPruneInterval,
2929
whenConsumeOrPruneTxOut,
3030
whenPruneTxOut,
31+
getTxOutTableType,
3132
getHasConsumedOrPruneTxOut,
3233
getSkipTxIn,
3334
getPrunes,
@@ -194,6 +195,9 @@ whenPruneTxOut :: (MonadIO m) => SyncEnv -> m () -> m ()
194195
whenPruneTxOut env =
195196
when (DB.pcmPruneTxOut $ getPruneConsume env)
196197

198+
getTxOutTableType :: SyncEnv -> DB.TxOutTableType
199+
getTxOutTableType syncEnv = ioTxOutTableType . soptInsertOptions $ envOptions syncEnv
200+
197201
getHasConsumedOrPruneTxOut :: SyncEnv -> Bool
198202
getHasConsumedOrPruneTxOut =
199203
DB.pcmConsumeOrPruneTxOut . getPruneConsume
@@ -344,7 +348,7 @@ mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemS
344348
consistentLevelVar <- newTVarIO Unchecked
345349
fixDataVar <- newTVarIO $ if ranMigrations then DataFixRan else NoneFixRan
346350
indexesVar <- newTVarIO $ enpForceIndexes syncNP
347-
bts <- getBootstrapInProgress trce (isTxOutBootstrap' syncNodeConfigFromFile) backend
351+
bts <- getBootstrapInProgress trce (isTxOutConsumedBootstrap' syncNodeConfigFromFile) backend
348352
bootstrapVar <- newTVarIO bts
349353
-- Offline Pool + Anchor queues
350354
opwq <- newTBQueueIO 1000
@@ -398,7 +402,7 @@ mkSyncEnv trce backend connectionString syncOptions protoInfo nw nwMagic systemS
398402
}
399403
where
400404
hasLedger' = hasLedger . sioLedger . dncInsertOptions
401-
isTxOutBootstrap' = isTxOutBootstrap . sioTxOut . dncInsertOptions
405+
isTxOutConsumedBootstrap' = isTxOutConsumedBootstrap . sioTxOut . dncInsertOptions
402406

403407
mkSyncEnvFromConfig ::
404408
Trace IO Text ->

cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ storePage syncEnv percQuantum (n, ls) = do
141141
when (n `mod` 10 == 0) $ liftIO $ logInfo trce $ "Bootstrap in progress " <> prc <> "%"
142142
txOuts <- mapM (prepareTxOut syncEnv) ls
143143
txOutIds <- lift . DB.insertManyTxOutPlex True False $ etoTxOut . fst <$> txOuts
144-
let maTxOuts = concatMap mkmaTxOuts $ zip txOutIds (snd <$> txOuts)
144+
let maTxOuts = concatMap (mkmaTxOuts txOutTableType) $ zip txOutIds (snd <$> txOuts)
145145
void . lift $ DB.insertManyMaTxOut maTxOuts
146146
where
147+
txOutTableType = getTxOutTableType syncEnv
147148
trce = getTrace syncEnv
148149
prc = Text.pack $ showGFloat (Just 1) (max 0 $ min 100.0 (fromIntegral n * percQuantum)) ""
149150

cardano-db-sync/src/Cardano/DbSync/Api/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ data InsertOptions = InsertOptions
8787
, ioPoolStats :: !Bool
8888
, ioGov :: !Bool
8989
, ioRemoveJsonbFromSchema :: !Bool
90-
, ioAddress :: !DB.TxOutTableType
90+
, ioTxOutTableType :: !DB.TxOutTableType
9191
}
9292
deriving (Show)
9393

cardano-db-sync/src/Cardano/DbSync/Config/Types.hs

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ module Cardano.DbSync.Config.Types (
5353
isMultiAssetEnabled,
5454
isMetadataEnabled,
5555
isPlutusEnabled,
56-
isTxOutBootstrap,
56+
isTxOutConsumedBootstrap,
5757
isTxOutConsumed,
58-
isTxOutPrune,
58+
isTxOutConsumedPrune,
5959
forceTxIn,
6060
fullInsertOptions,
6161
onlyUTxOInsertOptions,
@@ -184,7 +184,6 @@ data SyncInsertOptions = SyncInsertOptions
184184
, sioPoolStats :: PoolStatsConfig
185185
, sioJsonType :: JsonTypeConfig
186186
, sioRemoveJsonbFromSchema :: RemoveJsonbFromSchemaConfig
187-
, sioTxOutTableType :: TxOutTableTypeConfig
188187
}
189188
deriving (Eq, Show)
190189

@@ -199,17 +198,21 @@ newtype PoolStatsConfig = PoolStatsConfig
199198
deriving (Eq, Show)
200199

201200
data TxOutConfig
202-
= TxOutEnable
201+
= TxOutEnable UseTxOutAddress
203202
| TxOutDisable
204-
| TxOutConsumed ForceTxIn
205-
| TxOutPrune ForceTxIn
206-
| TxOutBootstrap ForceTxIn
203+
| TxOutConsumed ForceTxIn UseTxOutAddress
204+
| TxOutConsumedPrune ForceTxIn UseTxOutAddress
205+
| TxOutConsumedBootstrap ForceTxIn UseTxOutAddress
207206
deriving (Eq, Show)
208207

209208
newtype ForceTxIn = ForceTxIn {unForceTxIn :: Bool}
210209
deriving (Eq, Show)
211210
deriving newtype (ToJSON, FromJSON)
212211

212+
newtype UseTxOutAddress = UseTxOutAddress {unUseTxOutAddress :: Bool}
213+
deriving (Eq, Show)
214+
deriving newtype (ToJSON, FromJSON)
215+
213216
data LedgerInsertConfig
214217
= LedgerEnable
215218
| LedgerDisable
@@ -326,28 +329,28 @@ pcNodeConfigFilePath = unNodeConfigFile . pcNodeConfigFile
326329

327330
isTxOutEnabled :: TxOutConfig -> Bool
328331
isTxOutEnabled TxOutDisable = False
329-
isTxOutEnabled TxOutEnable = True
330-
isTxOutEnabled (TxOutConsumed _) = True
331-
isTxOutEnabled (TxOutPrune _) = True
332-
isTxOutEnabled (TxOutBootstrap _) = True
332+
isTxOutEnabled (TxOutEnable _) = True
333+
isTxOutEnabled (TxOutConsumed _ _) = True
334+
isTxOutEnabled (TxOutConsumedPrune _ _) = True
335+
isTxOutEnabled (TxOutConsumedBootstrap _ _) = True
333336

334-
isTxOutBootstrap :: TxOutConfig -> Bool
335-
isTxOutBootstrap (TxOutBootstrap _) = True
336-
isTxOutBootstrap _ = False
337+
isTxOutConsumedBootstrap :: TxOutConfig -> Bool
338+
isTxOutConsumedBootstrap (TxOutConsumedBootstrap _ _) = True
339+
isTxOutConsumedBootstrap _ = False
337340

338341
isTxOutConsumed :: TxOutConfig -> Bool
339-
isTxOutConsumed (TxOutConsumed _) = True
342+
isTxOutConsumed (TxOutConsumed _ _) = True
340343
isTxOutConsumed _ = False
341344

342-
isTxOutPrune :: TxOutConfig -> Bool
343-
isTxOutPrune (TxOutPrune _) = True
344-
isTxOutPrune _ = False
345+
isTxOutConsumedPrune :: TxOutConfig -> Bool
346+
isTxOutConsumedPrune (TxOutConsumedPrune _ _) = True
347+
isTxOutConsumedPrune _ = False
345348

346349
forceTxIn :: TxOutConfig -> Bool
347-
forceTxIn (TxOutConsumed f) = unForceTxIn f
348-
forceTxIn (TxOutPrune f) = unForceTxIn f
349-
forceTxIn (TxOutBootstrap f) = unForceTxIn f
350-
forceTxIn TxOutEnable = False
350+
forceTxIn (TxOutConsumed f _) = unForceTxIn f
351+
forceTxIn (TxOutConsumedPrune f _) = unForceTxIn f
352+
forceTxIn (TxOutConsumedBootstrap f _) = unForceTxIn f
353+
forceTxIn (TxOutEnable _) = False
351354
forceTxIn TxOutDisable = False
352355

353356
hasLedger :: LedgerInsertConfig -> Bool
@@ -446,7 +449,6 @@ parseOverrides obj baseOptions = do
446449
<*> obj .:? "pool_stats" .!= sioPoolStats baseOptions
447450
<*> obj .:? "json_type" .!= sioJsonType baseOptions
448451
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema baseOptions
449-
<*> obj .:? "use_address_table" .!= sioAddress baseOptions
450452

451453
instance ToJSON SyncInsertConfig where
452454
toJSON (SyncInsertConfig preset options) =
@@ -467,7 +469,6 @@ optionsToList SyncInsertOptions {..} =
467469
, toJsonIfSet "offchain_pool_data" sioOffchainPoolData
468470
, toJsonIfSet "pool_stats" sioPoolStats
469471
, toJsonIfSet "json_type" sioJsonType
470-
, toJsonIfSet "remove_jsonb_from_schema" sioRemoveJsonbFromSchema
471472
]
472473

473474
toJsonIfSet :: ToJSON a => Text -> a -> Maybe Pair
@@ -489,7 +490,6 @@ instance FromJSON SyncInsertOptions where
489490
<*> obj .:? "pool_stat" .!= sioPoolStats def
490491
<*> obj .:? "json_type" .!= sioJsonType def
491492
<*> obj .:? "remove_jsonb_from_schema" .!= sioRemoveJsonbFromSchema def
492-
<*> obj .:? "use_address_table" .!= sioAddress def
493493

494494
instance ToJSON SyncInsertOptions where
495495
toJSON SyncInsertOptions {..} =
@@ -534,33 +534,42 @@ instance ToJSON TxOutConfig where
534534
Aeson.object
535535
[ "value" .= value cfg
536536
, "force_tx_in" .= forceTxIn' cfg
537+
, "use_address_table" .= useTxOutAddress' cfg
537538
]
538539
where
539540
value :: TxOutConfig -> Text
540-
value TxOutEnable = "enable"
541+
value (TxOutEnable _) = "enable"
541542
value TxOutDisable = "disable"
542-
value (TxOutConsumed _) = "consumed"
543-
value (TxOutPrune _) = "prune"
544-
value (TxOutBootstrap _) = "bootstrap"
543+
value (TxOutConsumed _ _) = "consumed"
544+
value (TxOutConsumedPrune _ _) = "prune"
545+
value (TxOutConsumedBootstrap _ _) = "bootstrap"
545546

546547
forceTxIn' :: TxOutConfig -> Maybe Bool
547-
forceTxIn' TxOutEnable = Nothing
548+
forceTxIn' (TxOutEnable _) = Nothing
548549
forceTxIn' TxOutDisable = Nothing
549-
forceTxIn' (TxOutConsumed f) = Just (unForceTxIn f)
550-
forceTxIn' (TxOutPrune f) = Just (unForceTxIn f)
551-
forceTxIn' (TxOutBootstrap f) = Just (unForceTxIn f)
550+
forceTxIn' (TxOutConsumed f _) = Just (unForceTxIn f)
551+
forceTxIn' (TxOutConsumedPrune f _) = Just (unForceTxIn f)
552+
forceTxIn' (TxOutConsumedBootstrap f _) = Just (unForceTxIn f)
553+
554+
useTxOutAddress' :: TxOutConfig -> Maybe Bool
555+
useTxOutAddress' (TxOutEnable u) = Just (unUseTxOutAddress u)
556+
useTxOutAddress' TxOutDisable = Nothing
557+
useTxOutAddress' (TxOutConsumed _ u) = Just (unUseTxOutAddress u)
558+
useTxOutAddress' (TxOutConsumedPrune _ u) = Just (unUseTxOutAddress u)
559+
useTxOutAddress' (TxOutConsumedBootstrap _ u) = Just (unUseTxOutAddress u)
552560

553561
instance FromJSON TxOutConfig where
554562
parseJSON = Aeson.withObject "tx_out" $ \obj -> do
555563
val <- obj .: "value"
564+
useAddress' <- obj .: "use_address_table" .!= UseTxOutAddress False
556565
forceTxIn' <- obj .:? "force_tx_in" .!= ForceTxIn False
557566

558567
case val :: Text of
559-
"enable" -> pure TxOutEnable
568+
"enable" -> pure (TxOutEnable useAddress')
560569
"disable" -> pure TxOutDisable
561-
"consumed" -> pure (TxOutConsumed forceTxIn')
562-
"prune" -> pure (TxOutPrune forceTxIn')
563-
"bootstrap" -> pure (TxOutBootstrap forceTxIn')
570+
"consumed" -> pure (TxOutConsumed forceTxIn' useAddress')
571+
"prune" -> pure (TxOutConsumedPrune forceTxIn' useAddress')
572+
"bootstrap" -> pure (TxOutConsumedBootstrap forceTxIn' useAddress')
564573
other -> fail $ "unexpected tx_out: " <> show other
565574

566575
instance ToJSON LedgerInsertConfig where
@@ -714,7 +723,7 @@ instance Default SyncInsertOptions where
714723
def =
715724
SyncInsertOptions
716725
{ sioTxCBOR = TxCBORConfig False
717-
, sioTxOut = TxOutEnable
726+
, sioTxOut = TxOutEnable (UseTxOutAddress False)
718727
, sioLedger = LedgerEnable
719728
, sioShelley = ShelleyEnable
720729
, sioRewards = RewardsConfig True
@@ -726,14 +735,13 @@ instance Default SyncInsertOptions where
726735
, sioPoolStats = PoolStatsConfig False
727736
, sioJsonType = JsonTypeText
728737
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
729-
, sioTxOutTableType = TxOutTableTypeConfig False
730738
}
731739

732740
fullInsertOptions :: SyncInsertOptions
733741
fullInsertOptions =
734742
SyncInsertOptions
735743
{ sioTxCBOR = TxCBORConfig False
736-
, sioTxOut = TxOutEnable
744+
, sioTxOut = TxOutEnable (UseTxOutAddress False)
737745
, sioLedger = LedgerEnable
738746
, sioShelley = ShelleyEnable
739747
, sioRewards = RewardsConfig True
@@ -745,14 +753,13 @@ fullInsertOptions =
745753
, sioPoolStats = PoolStatsConfig True
746754
, sioJsonType = JsonTypeText
747755
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
748-
, sioTxOutTableType = TxOutTableTypeConfig False
749756
}
750757

751758
onlyUTxOInsertOptions :: SyncInsertOptions
752759
onlyUTxOInsertOptions =
753760
SyncInsertOptions
754761
{ sioTxCBOR = TxCBORConfig False
755-
, sioTxOut = TxOutBootstrap (ForceTxIn False)
762+
, sioTxOut = TxOutConsumedBootstrap (ForceTxIn False) (UseTxOutAddress False)
756763
, sioLedger = LedgerIgnore
757764
, sioShelley = ShelleyDisable
758765
, sioRewards = RewardsConfig True
@@ -764,7 +771,6 @@ onlyUTxOInsertOptions =
764771
, sioPoolStats = PoolStatsConfig False
765772
, sioJsonType = JsonTypeText
766773
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
767-
, sioTxOutTableType = TxOutTableTypeConfig False
768774
}
769775

770776
onlyGovInsertOptions :: SyncInsertOptions
@@ -791,16 +797,15 @@ disableAllInsertOptions =
791797
, sioGovernance = GovernanceConfig False
792798
, sioJsonType = JsonTypeText
793799
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
794-
, sioTxOutTableType = TxOutTableTypeConfig False
795800
}
796801

797802
addressTypeToEnableDisable :: IsString s => TxOutTableType -> s
798-
addressTypeToEnableDisable TxOutVariant = "enable"
803+
addressTypeToEnableDisable TxOutVariantAddress = "enable"
799804
addressTypeToEnableDisable TxOutCore = "disable"
800805

801806
enableDisableToTxOutTableType :: (Eq s, IsString s) => s -> Maybe TxOutTableType
802807
enableDisableToTxOutTableType = \case
803-
"enable" -> Just TxOutVariant
808+
"enable" -> Just TxOutVariantAddress
804809
"disable" -> Just TxOutCore
805810
_ -> Nothing
806811

0 commit comments

Comments
 (0)