Skip to content

Commit 2f6c6ec

Browse files
committed
rename keepMetadaNames to whitelistMetadataNames
1 parent 061745e commit 2f6c6ec

File tree

9 files changed

+59
-36
lines changed

9 files changed

+59
-36
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
268268
, enpHasShelley = True
269269
, enpHasMultiAssets = claHasMultiAssets
270270
, enpHasMetadata = claHasMetadata
271-
, enpKeepMetadataNames = []
271+
, enpWhitelistMetadataNames = []
272+
, enpWhitelistMAPolicies = []
272273
, enpHasPlutusExtra = True
273274
, enpHasGov = True
274275
, enpHasOffChainPoolData = True

cardano-db-sync/app/cardano-db-sync.hs

+19-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ pRunDbSyncNode =
8888
<*> pHasShelley
8989
<*> pHasMultiAssets
9090
<*> pHasMetadata
91-
<*> pKeepTxMetadata
91+
<*> pWhiteListTxMetadata
92+
<*> pWhiteListMAPolicies
9293
<*> pHasPlutusExtra
9394
<*> pHasGov
9495
<*> pHasOffChainPoolData
@@ -230,20 +231,28 @@ pSlotNo =
230231
<> Opt.metavar "WORD"
231232
)
232233

233-
pKeepTxMetadata :: Parser [Word64]
234-
pKeepTxMetadata =
234+
pWhiteListTxMetadata :: Parser [Word64]
235+
pWhiteListTxMetadata =
235236
Opt.option
236237
(parseCommaSeparated <$> Opt.str)
237-
( Opt.long "keep-tx-metadata"
238+
( Opt.long "whitelist-tx-metadata"
238239
<> Opt.value []
239240
<> Opt.help "Insert a specific set of tx metadata, based on the tx metadata key names"
240241
)
241-
where
242-
parseCommaSeparated :: String -> [Word64]
243-
parseCommaSeparated str =
244-
case traverse readMaybe (splitOn "," str) of
245-
Just values -> values
246-
Nothing -> error "Failed to parse comma-separated values"
242+
243+
pWhiteListMAPolicies :: Parser [Word64]
244+
pWhiteListMAPolicies =
245+
Opt.option
246+
(parseCommaSeparated <$> Opt.str)
247+
( Opt.long "whitelist-multi-asset-policy"
248+
<> Opt.help "Only insert a specific sellected list of multi-assets, based on the multi-asset's policy name"
249+
)
250+
251+
parseCommaSeparated :: String -> [Word64]
252+
parseCommaSeparated str =
253+
case traverse readMaybe (splitOn "," str) of
254+
Just values -> values
255+
Nothing -> error "Failed to parse comma-separated values"
247256

248257
pHasInOut :: Parser Bool
249258
pHasInOut =

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,13 @@ extractSyncOptions snp aop =
233233
, snapshotEveryLagging = enpSnEveryLagging snp
234234
}
235235
where
236-
maybeKeepMNames =
237-
if null (enpKeepMetadataNames snp)
236+
maybeWhitelistMDNames = whitelistToMaybe (enpWhitelistMetadataNames snp)
237+
maybeWhitelistMAPolicies = whitelistToMaybe (enpWhitelistMAPolicies snp)
238+
239+
whitelistToMaybe wList =
240+
if null wList
238241
then Strict.Nothing
239-
else Strict.Just (enpKeepMetadataNames snp)
242+
else Strict.Just wList
240243

241244
iopts
242245
| enpOnlyGov snp = onlyGovInsertOptions useLedger
@@ -251,7 +254,8 @@ extractSyncOptions snp aop =
251254
, ioRewards = True
252255
, ioMultiAssets = enpHasMultiAssets snp
253256
, ioMetadata = enpHasMetadata snp
254-
, ioKeepMetadataNames = maybeKeepMNames
257+
, ioWhitelistMetadataNames = maybeWhitelistMDNames
258+
, ioWhitelistMAPolicies = maybeWhitelistMAPolicies
255259
, ioPlutusExtra = enpHasPlutusExtra snp
256260
, ioOffChainPoolData = enpHasOffChainPoolData snp
257261
, ioGov = enpHasGov snp

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ fullInsertOptions useLedger =
208208
, ioRewards = True
209209
, ioMultiAssets = True
210210
, ioMetadata = True
211-
, ioKeepMetadataNames = Strict.Nothing
211+
, ioWhitelistMetadataNames = Strict.Nothing
212+
, ioWhitelistMAPolicies = Strict.Nothing
212213
, ioPlutusExtra = True
213214
, ioOffChainPoolData = True
214215
, ioGov = True
@@ -223,7 +224,8 @@ onlyUTxOInsertOptions =
223224
, ioRewards = False
224225
, ioMultiAssets = True
225226
, ioMetadata = False
226-
, ioKeepMetadataNames = Strict.Nothing
227+
, ioWhitelistMetadataNames = Strict.Nothing
228+
, ioWhitelistMAPolicies = Strict.Nothing
227229
, ioPlutusExtra = False
228230
, ioOffChainPoolData = False
229231
, ioGov = False
@@ -241,7 +243,8 @@ disableAllInsertOptions useLedger =
241243
, ioRewards = False
242244
, ioMultiAssets = False
243245
, ioMetadata = False
244-
, ioKeepMetadataNames = Strict.Nothing
246+
, ioWhitelistMetadataNames = Strict.Nothing
247+
, ioWhitelistMAPolicies = Strict.Nothing
245248
, ioPlutusExtra = False
246249
, ioOffChainPoolData = False
247250
, ioGov = False

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ prepareTxOut syncEnv txCache (TxIn txHash (TxIx index), txOut) = do
167167
let txHashByteString = Generic.safeHashToByteString $ unTxId txHash
168168
let genTxOut = fromTxOut index txOut
169169
txId <- queryTxIdWithCache txCache txHashByteString
170-
Insert.prepareTxOut trce cache iopts (txId, txHashByteString) genTxOut
170+
Insert.prepareTxOut syncEnv trce cache iopts (txId, txHashByteString) genTxOut
171171
where
172172
trce = getTrace syncEnv
173173
cache = envCache syncEnv

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ data InsertOptions = InsertOptions
7878
, ioRewards :: !Bool
7979
, ioMultiAssets :: !Bool
8080
, ioMetadata :: !Bool
81-
, ioKeepMetadataNames :: Strict.Maybe [Word64]
81+
, ioWhitelistMetadataNames :: Strict.Maybe [Word64]
82+
, ioWhitelistMAPolicies :: Strict.Maybe [Word64]
8283
, ioPlutusExtra :: !Bool
8384
, ioOffChainPoolData :: !Bool
8485
, ioGov :: !Bool

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ data SyncNodeParams = SyncNodeParams
7272
, enpHasShelley :: !Bool
7373
, enpHasMultiAssets :: !Bool
7474
, enpHasMetadata :: !Bool
75-
, enpKeepMetadataNames :: ![Word64]
75+
, enpWhitelistMetadataNames :: ![Word64]
76+
, enpWhitelistMAPolicies :: ![Word64]
7677
, enpHasPlutusExtra :: !Bool
7778
, enpHasGov :: !Bool
7879
, enpHasOffChainPoolData :: !Bool

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs

+16-11
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
320320

321321
if not (Generic.txValidContract tx)
322322
then do
323-
!txOutsGrouped <- mapM (prepareTxOut tracer cache iopts (txId, txHash)) (Generic.txOutputs tx)
323+
!txOutsGrouped <- mapM (prepareTxOut syncEnv tracer cache iopts (txId, txHash)) (Generic.txOutputs tx)
324324

325325
let !txIns = map (prepareTxIn txId Map.empty) resolvedInputs
326326
-- There is a custom semigroup instance for BlockGroupedData which uses addition for the values `fees` and `outSum`.
@@ -329,7 +329,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
329329
else do
330330
-- The following operations only happen if the script passes stage 2 validation (or the tx has
331331
-- no script).
332-
!txOutsGrouped <- mapM (prepareTxOut tracer cache iopts (txId, txHash)) (Generic.txOutputs tx)
332+
!txOutsGrouped <- mapM (prepareTxOut syncEnv tracer cache iopts (txId, txHash)) (Generic.txOutputs tx)
333333

334334
!redeemers <-
335335
Map.fromList
@@ -365,7 +365,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
365365

366366
maTxMint <-
367367
whenFalseMempty (ioMetadata iopts) $
368-
prepareMaTxMint tracer cache txId $
368+
prepareMaTxMint syncEnv tracer cache txId $
369369
Generic.txMint tx
370370

371371
when (ioPlutusExtra iopts) $
@@ -389,13 +389,14 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
389389

390390
prepareTxOut ::
391391
(MonadBaseControl IO m, MonadIO m) =>
392+
SyncEnv ->
392393
Trace IO Text ->
393394
Cache ->
394395
InsertOptions ->
395396
(DB.TxId, ByteString) ->
396397
Generic.TxOut ->
397398
ExceptT SyncNodeError (ReaderT SqlBackend m) (ExtendedTxOut, [MissingMaTxOut])
398-
prepareTxOut tracer cache iopts (txId, txHash) (Generic.TxOut index addr addrRaw value maMap mScript dt) = do
399+
prepareTxOut syncEnv tracer cache iopts (txId, txHash) (Generic.TxOut index addr addrRaw value maMap mScript dt) = do
399400
mSaId <- lift $ insertStakeAddressRefIfMissing tracer cache addr
400401
mDatumId <-
401402
whenFalseEmpty (ioPlutusExtra iopts) Nothing $
@@ -420,7 +421,7 @@ prepareTxOut tracer cache iopts (txId, txHash) (Generic.TxOut index addr addrRaw
420421
, DB.txOutReferenceScriptId = mScriptId
421422
}
422423
let !eutxo = ExtendedTxOut txHash txOut
423-
!maTxOuts <- whenFalseMempty (ioMultiAssets iopts) $ prepareMaTxOuts tracer cache maMap
424+
!maTxOuts <- whenFalseMempty (ioMultiAssets iopts) $ prepareMaTxOuts syncEnv tracer cache maMap
424425
pure (eutxo, maTxOuts)
425426
where
426427
hasScript :: Bool
@@ -1220,7 +1221,7 @@ prepareTxMetadata tracer txId inOpts mmetadata = do
12201221
(Word64, TxMetadataValue) ->
12211222
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe DB.TxMetadata)
12221223
prepare (key, md) = do
1223-
case ioKeepMetadataNames inOpts of
1224+
case ioWhitelistMetadataNames inOpts of
12241225
Strict.Just metadataNames -> do
12251226
let isMatchingKey = key `elem` metadataNames
12261227
if isMatchingKey
@@ -1327,12 +1328,14 @@ insertEpochParam _tracer blkId (EpochNo epoch) params nonce = do
13271328

13281329
prepareMaTxMint ::
13291330
(MonadBaseControl IO m, MonadIO m) =>
1331+
SyncEnv ->
13301332
Trace IO Text ->
13311333
Cache ->
13321334
DB.TxId ->
13331335
MultiAsset StandardCrypto ->
13341336
ExceptT SyncNodeError (ReaderT SqlBackend m) [DB.MaTxMint]
1335-
prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
1337+
prepareMaTxMint syncEnv _tracer cache txId (MultiAsset mintMap) =
1338+
-- TODO: VINCE HERE
13361339
concatMapM (lift . prepareOuter) $ Map.toList mintMap
13371340
where
13381341
prepareOuter ::
@@ -1348,7 +1351,7 @@ prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
13481351
(AssetName, Integer) ->
13491352
ReaderT SqlBackend m DB.MaTxMint
13501353
prepareInner policy (aname, amount) = do
1351-
maId <- insertMultiAsset cache policy aname
1354+
maId <- insertMultiAsset syncEnv cache policy aname
13521355
pure $
13531356
DB.MaTxMint
13541357
{ DB.maTxMintIdent = maId
@@ -1358,11 +1361,12 @@ prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
13581361

13591362
prepareMaTxOuts ::
13601363
(MonadBaseControl IO m, MonadIO m) =>
1364+
SyncEnv ->
13611365
Trace IO Text ->
13621366
Cache ->
13631367
Map (PolicyID StandardCrypto) (Map AssetName Integer) ->
13641368
ExceptT SyncNodeError (ReaderT SqlBackend m) [MissingMaTxOut]
1365-
prepareMaTxOuts _tracer cache maMap =
1369+
prepareMaTxOuts syncEnv _tracer cache maMap =
13661370
concatMapM (lift . prepareOuter) $ Map.toList maMap
13671371
where
13681372
prepareOuter ::
@@ -1378,7 +1382,7 @@ prepareMaTxOuts _tracer cache maMap =
13781382
(AssetName, Integer) ->
13791383
ReaderT SqlBackend m MissingMaTxOut
13801384
prepareInner policy (aname, amount) = do
1381-
maId <- insertMultiAsset cache policy aname
1385+
maId <- insertMultiAsset syncEnv cache policy aname
13821386
pure $
13831387
MissingMaTxOut
13841388
{ mmtoIdent = maId
@@ -1387,11 +1391,12 @@ prepareMaTxOuts _tracer cache maMap =
13871391

13881392
insertMultiAsset ::
13891393
(MonadBaseControl IO m, MonadIO m) =>
1394+
SyncEnv ->
13901395
Cache ->
13911396
PolicyID StandardCrypto ->
13921397
AssetName ->
13931398
ReaderT SqlBackend m DB.MultiAssetId
1394-
insertMultiAsset cache policy aName = do
1399+
insertMultiAsset _syncEnv cache policy aName = do
13951400
mId <- queryMAWithCache cache policy aName
13961401
case mId of
13971402
Right maId -> pure maId

doc/configuration.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ Some field are left empty when using this flag, like
155155

156156
Until the ledger state migration happens any restart requires reusing the `--bootstrap-tx-out` flag. After it's completed the flag can be omitted on restarts.
157157

158-
### --keep-tx-metadata
158+
### --whitelist-tx-metadata
159159

160-
This flag was introduced in v.13.2.0.0 as all postgres field with the type jsonb were removed to improve insertion performance.
161-
If they are required and you have database queries against jsonb then activate this flag to re-introduce the type jsonb.
162-
You can pass multiple values to the flag eg: `--keep-tx-metadata 1,2,3` make sure you are using commas between each key.
160+
To help improved database insert thoughput, user can chose to filter specific tx metadata they would like to keep and insert, ignore everything else.
161+
You can pass multiple values to the flag eg: `--whitelist-tx-metadata 1,2,3` make sure you are using commas between each key.

0 commit comments

Comments
 (0)