Skip to content

Commit

Permalink
adding more whitelists
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Jan 29, 2024
1 parent 33f2272 commit 68d4856
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 162 deletions.
1 change: 0 additions & 1 deletion cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
, enpHasMultiAssets = claHasMultiAssets
, enpHasMetadata = claHasMetadata
, enpWhitelistMetadataNames = []
, enpWhitelistMAPolicies = []
, enpHasPlutusExtra = True
, enpHasGov = True
, enpHasOffChainPoolData = True
Expand Down
9 changes: 0 additions & 9 deletions cardano-db-sync/app/cardano-db-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ pRunDbSyncNode =
<*> pHasMultiAssets
<*> pHasMetadata
<*> pWhiteListTxMetadata
<*> pWhiteListMAPolicies
<*> pHasPlutusExtra
<*> pHasGov
<*> pHasOffChainPoolData
Expand Down Expand Up @@ -240,14 +239,6 @@ pWhiteListTxMetadata =
<> Opt.help "Insert a specific set of tx metadata, based on the tx metadata key names"
)

pWhiteListMAPolicies :: Parser [Word64]
pWhiteListMAPolicies =
Opt.option
(parseCommaSeparated <$> Opt.str)
( Opt.long "whitelist-multi-asset-policy"
<> Opt.help "Only insert a specific sellected list of multi-assets, based on the multi-asset's policy name"
)

parseCommaSeparated :: String -> [Word64]
parseCommaSeparated str =
case traverse readMaybe (splitOn "," str) of
Expand Down
20 changes: 5 additions & 15 deletions cardano-db-sync/src/Cardano/DbSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Cardano.DbSync.Config.Types (
SocketPath (..),
SyncCommand (..),
SyncNodeConfig (..),
SyncNodeParams (..),
SyncNodeParams (..), MultiAssetConfig (..), MetadataConfig (..), PlutusConfig (..),
)
import Cardano.DbSync.Database
import Cardano.DbSync.DbAction
Expand All @@ -56,7 +56,6 @@ import Cardano.Prelude hiding (Nat, (%))
import Cardano.Slotting.Slot (EpochNo (..))
import Control.Concurrent.Async
import Control.Monad.Extra (whenJust)
import qualified Data.Strict.Maybe as Strict
import qualified Data.Text as Text
import Data.Version (showVersion)
import Database.Persist.Postgresql (ConnectionString, withPostgresqlConn)
Expand Down Expand Up @@ -233,14 +232,6 @@ extractSyncOptions snp aop =
, snapshotEveryLagging = enpSnEveryLagging snp
}
where
maybeWhitelistMDNames = whitelistToMaybe (enpWhitelistMetadataNames snp)
maybeWhitelistMAPolicies = whitelistToMaybe (enpWhitelistMAPolicies snp)

whitelistToMaybe wList =
if null wList
then Strict.Nothing
else Strict.Just wList

iopts
| enpOnlyGov snp = onlyGovInsertOptions useLedger
| enpOnlyUTxO snp = onlyUTxOInsertOptions
Expand All @@ -252,11 +243,10 @@ extractSyncOptions snp aop =
, ioUseLedger = useLedger
, ioShelley = enpHasShelley snp
, ioRewards = True
, ioMultiAssets = enpHasMultiAssets snp
, ioMetadata = enpHasMetadata snp
, ioWhitelistMetadataNames = maybeWhitelistMDNames
, ioWhitelistMAPolicies = maybeWhitelistMAPolicies
, ioPlutusExtra = enpHasPlutusExtra snp
-- TODO: cmdv: this is where we plug configs
, ioMultiAssets = MultiAssetDisable
, ioMetadata = MetadataDisable
, ioPlutusExtra = PlutusDisable
, ioOffChainPoolData = enpHasOffChainPoolData snp
, ioGov = enpHasGov snp
}
Expand Down
24 changes: 9 additions & 15 deletions cardano-db-sync/src/Cardano/DbSync/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ fullInsertOptions useLedger =
, ioUseLedger = useLedger
, ioShelley = True
, ioRewards = True
, ioMultiAssets = True
, ioMetadata = True
, ioWhitelistMetadataNames = Strict.Nothing
, ioWhitelistMAPolicies = Strict.Nothing
, ioPlutusExtra = True
, ioMultiAssets = MultiAssetEnable
, ioMetadata = MetadataEnable
, ioPlutusExtra = PlutusEnable
, ioOffChainPoolData = True
, ioGov = True
}
Expand All @@ -222,11 +220,9 @@ onlyUTxOInsertOptions =
, ioUseLedger = False
, ioShelley = False
, ioRewards = False
, ioMultiAssets = True
, ioMetadata = False
, ioWhitelistMetadataNames = Strict.Nothing
, ioWhitelistMAPolicies = Strict.Nothing
, ioPlutusExtra = False
, ioMultiAssets = MultiAssetEnable
, ioMetadata = MetadataDisable
, ioPlutusExtra = PlutusDisable
, ioOffChainPoolData = False
, ioGov = False
}
Expand All @@ -241,11 +237,9 @@ disableAllInsertOptions useLedger =
, ioUseLedger = useLedger
, ioShelley = False
, ioRewards = False
, ioMultiAssets = False
, ioMetadata = False
, ioWhitelistMetadataNames = Strict.Nothing
, ioWhitelistMAPolicies = Strict.Nothing
, ioPlutusExtra = False
, ioMultiAssets = MultiAssetEnable
, ioMetadata = MetadataDisable
, ioPlutusExtra = PlutusDisable
, ioOffChainPoolData = False
, ioGov = False
}
Expand Down
4 changes: 2 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Api/Ledger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ storePage ::
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
storePage syncEnv cache percQuantum (n, ls) = do
when (n `mod` 10 == 0) $ liftIO $ logInfo trce $ "Bootstrap in progress " <> prc <> "%"
txOuts <- mapM (prepareTxOut syncEnv cache) ls
txOuts <- mapMaybeM (prepareTxOut syncEnv cache) ls
txOutIds <- lift . DB.insertManyTxOutPlex True False $ etoTxOut . fst <$> txOuts
let maTxOuts = concatMap mkmaTxOuts $ zip txOutIds (snd <$> txOuts)
void . lift $ DB.insertManyMaTxOut maTxOuts
Expand All @@ -162,7 +162,7 @@ prepareTxOut ::
SyncEnv ->
TxCache ->
(TxIn StandardCrypto, BabbageTxOut era) ->
ExceptT SyncNodeError (ReaderT SqlBackend m) (ExtendedTxOut, [MissingMaTxOut])
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe (ExtendedTxOut, [MissingMaTxOut]))
prepareTxOut syncEnv txCache (TxIn txHash (TxIx index), txOut) = do
let txHashByteString = Generic.safeHashToByteString $ unTxId txHash
let genTxOut = fromTxOut index txOut
Expand Down
11 changes: 5 additions & 6 deletions cardano-db-sync/src/Cardano/DbSync/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Cardano.DbSync.Api.Types (

import qualified Cardano.Db as DB
import Cardano.DbSync.Cache.Types (Cache)
import Cardano.DbSync.Config.Types (MetadataConfig, MultiAssetConfig, PlutusConfig)
import Cardano.DbSync.Ledger.Types (HasLedgerEnv)
import Cardano.DbSync.LocalStateQuery (NoLedgerEnv)
import Cardano.DbSync.Types (
Expand All @@ -23,7 +24,7 @@ import Cardano.DbSync.Types (
OffChainVoteResult,
OffChainVoteWorkQueue,
)
import Cardano.Prelude (Bool, Eq, IO, Show, Word64)
import Cardano.Prelude (Bool (..), Eq, IO, Show, Word64)
import Cardano.Slotting.Slot (EpochNo (..))
import Control.Concurrent.Class.MonadSTM.Strict (
StrictTVar,
Expand Down Expand Up @@ -76,11 +77,9 @@ data InsertOptions = InsertOptions
, ioUseLedger :: !Bool
, ioShelley :: !Bool
, ioRewards :: !Bool
, ioMultiAssets :: !Bool
, ioMetadata :: !Bool
, ioWhitelistMetadataNames :: Strict.Maybe [Word64]
, ioWhitelistMAPolicies :: Strict.Maybe [Word64]
, ioPlutusExtra :: !Bool
, ioMultiAssets :: !MultiAssetConfig
, ioMetadata :: !MetadataConfig
, ioPlutusExtra :: !PlutusConfig
, ioOffChainPoolData :: !Bool
, ioGov :: !Bool
}
Expand Down
44 changes: 43 additions & 1 deletion cardano-db-sync/src/Cardano/DbSync/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
Expand All @@ -18,11 +19,17 @@ module Cardano.DbSync.Config.Types (
GenesisHashConway (..),
SyncNodeConfig (..),
SyncPreConfig (..),
MetadataConfig (..),
MultiAssetConfig (..),
PlutusConfig (..),
LedgerStateDir (..),
LogFileDir (..),
NetworkName (..),
NodeConfigFile (..),
SocketPath (..),
isMetaDataConfigEnabled,
isMultiAssetConfigEnabled,
isPlutusConfigEnabled,
adjustGenesisFilePath,
adjustNodeConfigFilePath,
pcNodeConfigFilePath,
Expand Down Expand Up @@ -73,7 +80,6 @@ data SyncNodeParams = SyncNodeParams
, enpHasMultiAssets :: !Bool
, enpHasMetadata :: !Bool
, enpWhitelistMetadataNames :: ![Word64]
, enpWhitelistMAPolicies :: ![Word64]
, enpHasPlutusExtra :: !Bool
, enpHasGov :: !Bool
, enpHasOffChainPoolData :: !Bool
Expand Down Expand Up @@ -132,6 +138,42 @@ data SyncPreConfig = SyncPreConfig
, pcPrometheusPort :: !Int
}

data MetadataConfig
= MetadataEnable
| MetadataDisable
| MetadataWhitelistKeys (NonEmpty ByteString)
deriving (Eq, Show)

isMetaDataConfigEnabled :: MetadataConfig -> Bool
isMetaDataConfigEnabled = \case
MetadataEnable -> True
MetadataDisable -> False
MetadataWhitelistKeys _ -> True

data MultiAssetConfig
= MultiAssetEnable
| MultiAssetDisable
| MultiAssetWhitelistPolicies (NonEmpty ByteString)
deriving (Eq, Show)

isMultiAssetConfigEnabled :: MultiAssetConfig -> Bool
isMultiAssetConfigEnabled = \case
MultiAssetEnable -> True
MultiAssetDisable -> False
MultiAssetWhitelistPolicies _ -> True

data PlutusConfig
= PlutusEnable
| PlutusDisable
| PlutusWhitelistScripts (NonEmpty ByteString)
deriving (Eq, Show)

isPlutusConfigEnabled :: PlutusConfig -> Bool
isPlutusConfigEnabled = \case
PlutusEnable -> True
PlutusDisable -> False
PlutusWhitelistScripts _ -> True

newtype GenesisFile = GenesisFile
{ unGenesisFile :: FilePath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Block (

import qualified Cardano.Crypto.Hash as Crypto
import qualified Cardano.Crypto.KES.Class as KES
import Cardano.DbSync.Config.Types (PlutusConfig)
import Cardano.DbSync.Era.Shelley.Generic.Tx
import Cardano.DbSync.Types
import Cardano.DbSync.Util.Bech32 (serialiseVerKeyVrfToBech32)
Expand Down Expand Up @@ -120,7 +121,7 @@ fromMaryBlock blk =
, blkTxs = map fromMaryTx (getTxs blk)
}

fromAlonzoBlock :: Bool -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
fromAlonzoBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
fromAlonzoBlock iope mprices blk =
Block
{ blkEra = Alonzo
Expand All @@ -137,7 +138,7 @@ fromAlonzoBlock iope mprices blk =
, blkTxs = map (fromAlonzoTx iope mprices) (getTxs blk)
}

fromBabbageBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
fromBabbageBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
fromBabbageBlock iope mprices blk =
Block
{ blkEra = Babbage
Expand All @@ -154,7 +155,7 @@ fromBabbageBlock iope mprices blk =
, blkTxs = map (fromBabbageTx iope mprices) (getTxs blk)
}

fromConwayBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardConway -> Block
fromConwayBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock PraosStandard StandardConway -> Block
fromConwayBlock iope mprices blk =
Block
{ blkEra = Conway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo (

import qualified Cardano.Crypto.Hash as Crypto
import Cardano.Db (ScriptType (..))
import Cardano.DbSync.Config.Types (PlutusConfig, isPlutusConfigEnabled)
import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.Script (fromTimelock)
import Cardano.DbSync.Era.Shelley.Generic.ScriptData (ScriptData (..))
Expand Down Expand Up @@ -65,7 +66,7 @@ import qualified Data.Set as Set
import Lens.Micro
import Ouroboros.Consensus.Cardano.Block (EraCrypto, StandardAlonzo, StandardCrypto)

fromAlonzoTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardAlonzo) -> Tx
fromAlonzoTx :: PlutusConfig -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardAlonzo) -> Tx
fromAlonzoTx ioExtraPlutus mprices (blkIndex, tx) =
Tx
{ txHash = txHashId tx
Expand Down Expand Up @@ -178,13 +179,13 @@ resolveRedeemers ::
, Core.EraTx era
, Alonzo.MaryEraTxBody era
) =>
Bool ->
PlutusConfig ->
Maybe Alonzo.Prices ->
Core.Tx era ->
(TxCert era -> Cert) ->
(RedeemerMaps, [(Word64, TxRedeemer)])
resolveRedeemers ioExtraPlutus mprices tx toCert =
if not ioExtraPlutus
if not $ isPlutusConfigEnabled ioExtraPlutus
then (initRedeemersMaps, [])
else
mkRdmrAndUpdateRec (initRedeemersMaps, []) $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Babbage (
fromTxOut,
) where

import Cardano.DbSync.Config.Types (PlutusConfig)
import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
Expand All @@ -36,7 +37,7 @@ import qualified Data.Map.Strict as Map
import Lens.Micro
import Ouroboros.Consensus.Shelley.Eras (StandardBabbage, StandardCrypto)

fromBabbageTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardBabbage) -> Tx
fromBabbageTx :: PlutusConfig -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardBabbage) -> Tx
fromBabbageTx ioExtraPlutus mprices (blkIndex, tx) =
Tx
{ txHash = txHashId tx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Conway (
fromConwayTx,
) where

import Cardano.DbSync.Config.Types (PlutusConfig)
import Cardano.DbSync.Era.Shelley.Generic.Metadata
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval)
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
Expand All @@ -26,7 +27,7 @@ import qualified Data.Map.Strict as Map
import Lens.Micro
import Ouroboros.Consensus.Cardano.Block (StandardConway)

fromConwayTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardConway) -> Tx
fromConwayTx :: PlutusConfig -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardConway) -> Tx
fromConwayTx ioExtraPlutus mprices (blkIndex, tx) =
Tx
{ txHash = txHashId tx
Expand Down
Loading

0 comments on commit 68d4856

Please sign in to comment.