Skip to content

Commit 74b4c0b

Browse files
committed
rename keepMetadaNames to whitelistMetadataNames
1 parent 045330d commit 74b4c0b

File tree

9 files changed

+59
-35
lines changed

9 files changed

+59
-35
lines changed

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ pRunDbSyncNode = do
9090
<*> pHasShelley
9191
<*> pHasMultiAssets
9292
<*> pHasMetadata
93-
<*> pKeepTxMetadata
93+
<*> pWhiteListTxMetadata
94+
<*> pWhiteListMAPolicies
9495
<*> pHasPlutusExtra
9596
<*> pHasGov
9697
<*> pHasOffChainPoolData
@@ -232,20 +233,28 @@ pSlotNo =
232233
<> Opt.metavar "WORD"
233234
)
234235

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

250259
pHasInOut :: Parser Bool
251260
pHasInOut =

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,13 @@ extractSyncOptions snp aop =
232232
, snapshotEveryLagging = enpSnEveryLagging snp
233233
}
234234
where
235-
maybeKeepMNames =
236-
if null (enpKeepMetadataNames snp)
235+
maybeWhitelistMDNames = whitelistToMaybe (enpWhitelistMetadataNames snp)
236+
maybeWhitelistMAPolicies = whitelistToMaybe (enpWhitelistMAPolicies snp)
237+
238+
whitelistToMaybe wList =
239+
if null wList
237240
then Strict.Nothing
238-
else Strict.Just (enpKeepMetadataNames snp)
241+
else Strict.Just wList
239242

240243
iopts
241244
| enpOnlyGov snp = onlyGovInsertOptions useLedger
@@ -250,7 +253,8 @@ extractSyncOptions snp aop =
250253
, ioRewards = True
251254
, ioMultiAssets = enpHasMultiAssets snp
252255
, ioMetadata = enpHasMetadata snp
253-
, ioKeepMetadataNames = maybeKeepMNames
256+
, ioWhitelistMetadataNames = maybeWhitelistMDNames
257+
, ioWhitelistMAPolicies = maybeWhitelistMAPolicies
254258
, ioPlutusExtra = enpHasPlutusExtra snp
255259
, ioOffChainPoolData = enpHasOffChainPoolData snp
256260
, ioGov = enpHasGov snp

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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ data InsertOptions = InsertOptions
8080
, ioRewards :: !Bool
8181
, ioMultiAssets :: !Bool
8282
, ioMetadata :: !Bool
83-
, ioKeepMetadataNames :: Strict.Maybe [Word64]
83+
, ioWhitelistMetadataNames :: Strict.Maybe [Word64]
84+
, ioWhitelistMAPolicies :: Strict.Maybe [Word64]
8485
, ioPlutusExtra :: !Bool
8586
, ioOffChainPoolData :: !Bool
8687
, ioGov :: !Bool

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 16 additions & 11 deletions
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 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 $
@@ -419,7 +420,7 @@ prepareTxOut tracer cache iopts (txId, txHash) (Generic.TxOut index addr value m
419420
, DB.txOutReferenceScriptId = mScriptId
420421
}
421422
let !eutxo = ExtendedTxOut txHash txOut
422-
!maTxOuts <- whenFalseMempty (ioMultiAssets iopts) $ prepareMaTxOuts tracer cache maMap
423+
!maTxOuts <- whenFalseMempty (ioMultiAssets iopts) $ prepareMaTxOuts syncEnv tracer cache maMap
423424
pure (eutxo, maTxOuts)
424425
where
425426
hasScript :: Bool
@@ -1228,7 +1229,7 @@ prepareTxMetadata tracer txId inOpts mmetadata = do
12281229
(Word64, TxMetadataValue) ->
12291230
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe DB.TxMetadata)
12301231
prepare (key, md) = do
1231-
case ioKeepMetadataNames inOpts of
1232+
case ioWhitelistMetadataNames inOpts of
12321233
Strict.Just metadataNames -> do
12331234
let isMatchingKey = key `elem` metadataNames
12341235
if isMatchingKey
@@ -1335,12 +1336,14 @@ insertEpochParam _tracer blkId (EpochNo epoch) params nonce = do
13351336

13361337
prepareMaTxMint ::
13371338
(MonadBaseControl IO m, MonadIO m) =>
1339+
SyncEnv ->
13381340
Trace IO Text ->
13391341
Cache ->
13401342
DB.TxId ->
13411343
MultiAsset StandardCrypto ->
13421344
ExceptT SyncNodeError (ReaderT SqlBackend m) [DB.MaTxMint]
1343-
prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
1345+
prepareMaTxMint syncEnv _tracer cache txId (MultiAsset mintMap) =
1346+
-- TODO: VINCE HERE
13441347
concatMapM (lift . prepareOuter) $ Map.toList mintMap
13451348
where
13461349
prepareOuter ::
@@ -1356,7 +1359,7 @@ prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
13561359
(AssetName, Integer) ->
13571360
ReaderT SqlBackend m DB.MaTxMint
13581361
prepareInner policy (aname, amount) = do
1359-
maId <- insertMultiAsset cache policy aname
1362+
maId <- insertMultiAsset syncEnv cache policy aname
13601363
pure $
13611364
DB.MaTxMint
13621365
{ DB.maTxMintIdent = maId
@@ -1366,11 +1369,12 @@ prepareMaTxMint _tracer cache txId (MultiAsset mintMap) =
13661369

13671370
prepareMaTxOuts ::
13681371
(MonadBaseControl IO m, MonadIO m) =>
1372+
SyncEnv ->
13691373
Trace IO Text ->
13701374
Cache ->
13711375
Map (PolicyID StandardCrypto) (Map AssetName Integer) ->
13721376
ExceptT SyncNodeError (ReaderT SqlBackend m) [MissingMaTxOut]
1373-
prepareMaTxOuts _tracer cache maMap =
1377+
prepareMaTxOuts syncEnv _tracer cache maMap =
13741378
concatMapM (lift . prepareOuter) $ Map.toList maMap
13751379
where
13761380
prepareOuter ::
@@ -1386,7 +1390,7 @@ prepareMaTxOuts _tracer cache maMap =
13861390
(AssetName, Integer) ->
13871391
ReaderT SqlBackend m MissingMaTxOut
13881392
prepareInner policy (aname, amount) = do
1389-
maId <- insertMultiAsset cache policy aname
1393+
maId <- insertMultiAsset syncEnv cache policy aname
13901394
pure $
13911395
MissingMaTxOut
13921396
{ mmtoIdent = maId
@@ -1395,11 +1399,12 @@ prepareMaTxOuts _tracer cache maMap =
13951399

13961400
insertMultiAsset ::
13971401
(MonadBaseControl IO m, MonadIO m) =>
1402+
SyncEnv ->
13981403
Cache ->
13991404
PolicyID StandardCrypto ->
14001405
AssetName ->
14011406
ReaderT SqlBackend m DB.MultiAssetId
1402-
insertMultiAsset cache policy aName = do
1407+
insertMultiAsset _syncEnv cache policy aName = do
14031408
mId <- queryMAWithCache cache policy aName
14041409
case mId of
14051410
Right maId -> pure maId

doc/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +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-
It keeps only metadata with the specified keys.
161-
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)