Skip to content

Commit e723143

Browse files
committed
Extendend whitelist options
1 parent f8e1a62 commit e723143

File tree

18 files changed

+336
-222
lines changed

18 files changed

+336
-222
lines changed

cardano-db-sync/cardano-db-sync.cabal

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ library
6363
Cardano.DbSync.Era.Byron.Util
6464
Cardano.DbSync.Era.Cardano.Insert
6565
Cardano.DbSync.Era.Cardano.Util
66+
Cardano.DbSync.Era.Conway.Insert.GovAction
6667
Cardano.DbSync.Era.Shelley.Generic
6768
Cardano.DbSync.Era.Shelley.Generic.Block
6869
Cardano.DbSync.Era.Shelley.Generic.EpochUpdate
@@ -83,19 +84,18 @@ library
8384
Cardano.DbSync.Era.Shelley.Generic.Tx.Types
8485
Cardano.DbSync.Era.Shelley.Generic.Util
8586
Cardano.DbSync.Era.Shelley.Generic.Witness
86-
Cardano.DbSync.Era.Shelley.Genesis
8787
Cardano.DbSync.Era.Shelley.Query
8888
Cardano.DbSync.Era.Universal.Adjust
8989
Cardano.DbSync.Era.Universal.Block
9090
Cardano.DbSync.Era.Universal.Epoch
91-
Cardano.DbSync.Era.Universal.Validate
91+
Cardano.DbSync.Era.Universal.Genesis
9292
Cardano.DbSync.Era.Universal.Insert.Certificate
93-
Cardano.DbSync.Era.Universal.Insert.GovAction
9493
Cardano.DbSync.Era.Universal.Insert.Grouped
9594
Cardano.DbSync.Era.Universal.Insert.LedgerEvent
9695
Cardano.DbSync.Era.Universal.Insert.Other
9796
Cardano.DbSync.Era.Universal.Insert.Pool
9897
Cardano.DbSync.Era.Universal.Insert.Tx
98+
Cardano.DbSync.Era.Universal.Validate
9999

100100

101101
-- Temporary debugging validation
@@ -141,6 +141,7 @@ library
141141
Cardano.DbSync.Util.Bech32
142142
Cardano.DbSync.Util.Cbor
143143
Cardano.DbSync.Util.Constraint
144+
Cardano.DbSync.Util.Whitelist
144145

145146
Paths_cardano_db_sync
146147

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

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import Cardano.Prelude hiding (Nat, (%))
4747
import Cardano.Slotting.Slot (EpochNo (..))
4848
import Control.Concurrent.Async
4949
import Control.Monad.Extra (whenJust)
50-
import qualified Data.Strict.Maybe as Strict
5150
import qualified Data.Text as Text
5251
import Data.Version (showVersion)
5352
import Database.Persist.Postgresql (ConnectionString, withPostgresqlConn)
@@ -160,8 +159,7 @@ runSyncNode ::
160159
IO ()
161160
runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc syncNodeConfigFromFile syncNodeParams syncOptions = do
162161
whenJust maybeLedgerDir $
163-
\enpLedgerStateDir -> do
164-
createDirectoryIfMissing True (unLedgerStateDir enpLedgerStateDir)
162+
\enpLedgerStateDir -> createDirectoryIfMissing True (unLedgerStateDir enpLedgerStateDir)
165163
logInfo trce $ "Using byron genesis file from: " <> (show . unGenesisFile $ dncByronGenesisFile syncNodeConfigFromFile)
166164
logInfo trce $ "Using shelley genesis file from: " <> (show . unGenesisFile $ dncShelleyGenesisFile syncNodeConfigFromFile)
167165
logInfo trce $ "Using alonzo genesis file from: " <> (show . unGenesisFile $ dncAlonzoGenesisFile syncNodeConfigFromFile)
@@ -170,39 +168,38 @@ runSyncNode metricsSetters trce iomgr dbConnString ranMigrations runMigrationFnc
170168

171169
Db.runIohkLogging trce $
172170
withPostgresqlConn dbConnString $
173-
\backend -> liftIO $ do
174-
runOrThrowIO $ runExceptT $ do
175-
genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
176-
logProtocolMagicId trce $ genesisProtocolMagicId genCfg
177-
syncEnv <-
178-
ExceptT $
179-
mkSyncEnvFromConfig
180-
trce
181-
backend
182-
dbConnString
183-
syncOptions
184-
genCfg
185-
syncNodeConfigFromFile
186-
syncNodeParams
187-
ranMigrations
188-
runMigrationFnc
189-
liftIO $ runExtraMigrationsMaybe syncEnv
190-
unless useLedger $ liftIO $ do
191-
logInfo trce "Migrating to a no ledger schema"
192-
Db.noLedgerMigrations backend trce
193-
insertValidateGenesisDist syncEnv (dncNetworkName syncNodeConfigFromFile) genCfg (useShelleyInit syncNodeConfigFromFile)
171+
\backend -> liftIO $ runOrThrowIO $ runExceptT $ do
172+
genCfg <- readCardanoGenesisConfig syncNodeConfigFromFile
173+
logProtocolMagicId trce $ genesisProtocolMagicId genCfg
174+
syncEnv <-
175+
ExceptT $
176+
mkSyncEnvFromConfig
177+
trce
178+
backend
179+
dbConnString
180+
syncOptions
181+
genCfg
182+
syncNodeConfigFromFile
183+
syncNodeParams
184+
ranMigrations
185+
runMigrationFnc
186+
liftIO $ runExtraMigrationsMaybe syncEnv
187+
unless useLedger $ liftIO $ do
188+
logInfo trce "Migrating to a no ledger schema"
189+
Db.noLedgerMigrations backend trce
190+
insertValidateGenesisDist syncEnv (dncNetworkName syncNodeConfigFromFile) genCfg (useShelleyInit syncNodeConfigFromFile)
194191

195-
-- communication channel between datalayer thread and chainsync-client thread
196-
threadChannels <- liftIO newThreadChannels
197-
liftIO $
198-
mapConcurrently_
199-
id
200-
[ runDbThread syncEnv metricsSetters threadChannels
201-
, runSyncNodeClient metricsSetters syncEnv iomgr trce threadChannels (enpSocketPath syncNodeParams)
202-
, runFetchOffChainPoolThread syncEnv
203-
, runFetchOffChainVoteThread syncEnv
204-
, runLedgerStateWriteThread (getTrace syncEnv) (envLedgerEnv syncEnv)
205-
]
192+
-- communication channel between datalayer thread and chainsync-client thread
193+
threadChannels <- liftIO newThreadChannels
194+
liftIO $
195+
mapConcurrently_
196+
id
197+
[ runDbThread syncEnv metricsSetters threadChannels
198+
, runSyncNodeClient metricsSetters syncEnv iomgr trce threadChannels (enpSocketPath syncNodeParams)
199+
, runFetchOffChainPoolThread syncEnv
200+
, runFetchOffChainVoteThread syncEnv
201+
, runLedgerStateWriteThread (getTrace syncEnv) (envLedgerEnv syncEnv)
202+
]
206203
where
207204
useShelleyInit :: SyncNodeConfig -> Bool
208205
useShelleyInit cfg =
@@ -245,23 +242,16 @@ extractSyncOptions snp aop snc =
245242
, snapshotEveryLagging = enpSnEveryLagging snp
246243
}
247244
where
248-
maybeKeepMNames =
249-
case sioMetadata (dncInsertOptions snc) of
250-
MetadataKeys ks -> Strict.Just (map fromIntegral $ toList ks)
251-
MetadataEnable -> Strict.Nothing
252-
MetadataDisable -> Strict.Nothing
253-
254245
iopts =
255246
InsertOptions
256247
{ ioInOut = isTxOutEnabled'
257248
, ioUseLedger = useLedger
258249
, ioShelley = isShelleyEnabled (sioShelley (dncInsertOptions snc))
259250
, -- Rewards are only disabled on "disable_all" and "only_gov" presets
260251
ioRewards = True
261-
, ioMultiAssets = isMultiAssetEnabled (sioMultiAsset (dncInsertOptions snc))
262-
, ioMetadata = isMetadataEnabled (sioMetadata (dncInsertOptions snc))
263-
, ioKeepMetadataNames = maybeKeepMNames
264-
, ioPlutusExtra = isPlutusEnabled (sioPlutus (dncInsertOptions snc))
252+
, ioMultiAssets = sioMultiAsset (dncInsertOptions snc)
253+
, ioMetadata = sioMetadata (dncInsertOptions snc)
254+
, ioPlutus = sioPlutus (dncInsertOptions snc)
265255
, ioOffChainPoolData = useOffchainPoolData
266256
, ioGov = useGovernance
267257
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Cardano.DbSync.Api.Types (
1515

1616
import qualified Cardano.Db as DB
1717
import Cardano.DbSync.Cache.Types (Cache)
18-
import Cardano.DbSync.Config.Types (SyncNodeConfig)
18+
import Cardano.DbSync.Config.Types (MetadataConfig, MultiAssetConfig, PlutusConfig, SyncNodeConfig)
1919
import Cardano.DbSync.Ledger.Types (HasLedgerEnv)
2020
import Cardano.DbSync.LocalStateQuery (NoLedgerEnv)
2121
import Cardano.DbSync.Types (
@@ -74,16 +74,15 @@ data SyncOptions = SyncOptions
7474
deriving (Show)
7575

7676
data InsertOptions = InsertOptions
77-
{ ioInOut :: !Bool
78-
, ioUseLedger :: !Bool
79-
, ioShelley :: !Bool
80-
, ioRewards :: !Bool
81-
, ioMultiAssets :: !Bool
82-
, ioMetadata :: !Bool
83-
, ioKeepMetadataNames :: Strict.Maybe [Word64]
84-
, ioPlutusExtra :: !Bool
77+
{ ioGov :: !Bool
78+
, ioInOut :: !Bool
79+
, ioMetadata :: !MetadataConfig
80+
, ioMultiAssets :: !MultiAssetConfig
8581
, ioOffChainPoolData :: !Bool
86-
, ioGov :: !Bool
82+
, ioPlutus :: !PlutusConfig
83+
, ioRewards :: !Bool
84+
, ioShelley :: !Bool
85+
, ioUseLedger :: !Bool
8786
}
8887
deriving (Show)
8988

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ data LedgerInsertConfig
189189
data ShelleyInsertConfig
190190
= ShelleyEnable
191191
| ShelleyDisable
192-
| ShelleyStakeAddrs (NonEmpty ShortByteString)
192+
| -- Whitelist of Shelley stake addresses
193+
ShelleyStakeAddrs (NonEmpty ShortByteString)
193194
deriving (Eq, Show)
194195

195196
newtype RewardsConfig = RewardsConfig
@@ -199,19 +200,22 @@ newtype RewardsConfig = RewardsConfig
199200
data MultiAssetConfig
200201
= MultiAssetEnable
201202
| MultiAssetDisable
202-
| MultiAssetPolicies (NonEmpty ShortByteString)
203+
| -- | Whitelist of multiAsset policy IDs
204+
MultiAssetPolicies (NonEmpty ShortByteString)
203205
deriving (Eq, Show)
204206

205207
data MetadataConfig
206208
= MetadataEnable
207209
| MetadataDisable
208-
| MetadataKeys (NonEmpty Word)
210+
| -- | Whitelist of metadata keys
211+
MetadataKeys (NonEmpty Word)
209212
deriving (Eq, Show)
210213

211214
data PlutusConfig
212215
= PlutusEnable
213216
| PlutusDisable
214-
| PlutusScripts (NonEmpty ShortByteString)
217+
| -- | Whitelist of plutus script hashes
218+
PlutusScripts (NonEmpty ShortByteString)
215219
deriving (Eq, Show)
216220

217221
newtype GovernanceConfig = GovernanceConfig

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Cardano.DbSync.Api.Ledger
1818
import Cardano.DbSync.Api.Types (ConsistentLevel (..), InsertOptions (..), LedgerEnv (..), SyncEnv (..), SyncOptions (..))
1919
import Cardano.DbSync.Epoch (epochHandler)
2020
import Cardano.DbSync.Era.Byron.Insert (insertByronBlock)
21+
2122
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
2223
import Cardano.DbSync.Era.Universal.Block (insertBlockUniversal)
2324
import Cardano.DbSync.Era.Universal.Epoch (hasEpochStartEvent, hasNewEpochEvent)
@@ -165,15 +166,15 @@ insertBlock syncEnv cblk applyRes firstAfterRollback tookSnapshot = do
165166
BlockAlonzo blk ->
166167
newExceptT $
167168
insertBlockUniversal' $
168-
Generic.fromAlonzoBlock (ioPlutusExtra iopts) (getPrices applyResult) blk
169+
Generic.fromAlonzoBlock (ioPlutus iopts) (getPrices applyResult) blk
169170
BlockBabbage blk ->
170171
newExceptT $
171172
insertBlockUniversal' $
172-
Generic.fromBabbageBlock (ioPlutusExtra iopts) (getPrices applyResult) blk
173+
Generic.fromBabbageBlock (ioPlutus iopts) (getPrices applyResult) blk
173174
BlockConway blk ->
174175
newExceptT $
175176
insertBlockUniversal' $
176-
Generic.fromConwayBlock (ioPlutusExtra iopts) (getPrices applyResult) blk
177+
Generic.fromConwayBlock (ioPlutus iopts) (getPrices applyResult) blk
177178
-- update the epoch
178179
updateEpoch details isNewEpochEvent
179180
whenPruneTxOut syncEnv $

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Cardano.DbSync.Era (
99
import Cardano.DbSync.Api.Types (SyncEnv)
1010
import Cardano.DbSync.Config
1111
import qualified Cardano.DbSync.Era.Byron.Genesis as Byron
12-
import qualified Cardano.DbSync.Era.Shelley.Genesis as Shelley
12+
import qualified Cardano.DbSync.Era.Universal.Genesis as Shelley
1313
import Cardano.DbSync.Error
1414
import Cardano.Prelude
1515

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Block (
2525

2626
import qualified Cardano.Crypto.Hash as Crypto
2727
import qualified Cardano.Crypto.KES.Class as KES
28+
import Cardano.DbSync.Config.Types (PlutusConfig)
2829
import Cardano.DbSync.Era.Shelley.Generic.Tx
2930
import Cardano.DbSync.Types
3031
import Cardano.DbSync.Util.Bech32 (serialiseVerKeyVrfToBech32)
@@ -120,8 +121,8 @@ fromMaryBlock blk =
120121
, blkTxs = map fromMaryTx (getTxs blk)
121122
}
122123

123-
fromAlonzoBlock :: Bool -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
124-
fromAlonzoBlock iope mprices blk =
124+
fromAlonzoBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock TPraosStandard StandardAlonzo -> Block
125+
fromAlonzoBlock plutusConfig mprices blk =
125126
Block
126127
{ blkEra = Alonzo
127128
, blkHash = blockHash blk
@@ -134,11 +135,11 @@ fromAlonzoBlock iope mprices blk =
134135
, blkVrfKey = blockVrfKeyView $ blockVrfVkTPraos blk
135136
, blkOpCert = blockOpCertKeyTPraos blk
136137
, blkOpCertCounter = blockOpCertCounterTPraos blk
137-
, blkTxs = map (fromAlonzoTx iope mprices) (getTxs blk)
138+
, blkTxs = map (fromAlonzoTx plutusConfig mprices) (getTxs blk)
138139
}
139140

140-
fromBabbageBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
141-
fromBabbageBlock iope mprices blk =
141+
fromBabbageBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock PraosStandard StandardBabbage -> Block
142+
fromBabbageBlock plutusConfig mprices blk =
142143
Block
143144
{ blkEra = Babbage
144145
, blkHash = blockHash blk
@@ -151,11 +152,11 @@ fromBabbageBlock iope mprices blk =
151152
, blkVrfKey = blockVrfKeyView $ blockVrfVkPraos blk
152153
, blkOpCert = blockOpCertKeyPraos blk
153154
, blkOpCertCounter = blockOpCertCounterPraos blk
154-
, blkTxs = map (fromBabbageTx iope mprices) (getTxs blk)
155+
, blkTxs = map (fromBabbageTx plutusConfig mprices) (getTxs blk)
155156
}
156157

157-
fromConwayBlock :: Bool -> Maybe Prices -> ShelleyBlock PraosStandard StandardConway -> Block
158-
fromConwayBlock iope mprices blk =
158+
fromConwayBlock :: PlutusConfig -> Maybe Prices -> ShelleyBlock PraosStandard StandardConway -> Block
159+
fromConwayBlock plutusConfig mprices blk =
159160
Block
160161
{ blkEra = Conway
161162
, blkHash = blockHash blk
@@ -168,7 +169,7 @@ fromConwayBlock iope mprices blk =
168169
, blkVrfKey = blockVrfKeyView $ blockVrfVkPraos blk
169170
, blkOpCert = blockOpCertKeyPraos blk
170171
, blkOpCertCounter = blockOpCertCounterPraos blk
171-
, blkTxs = map (fromConwayTx iope mprices) (getTxs blk)
172+
, blkTxs = map (fromConwayTx plutusConfig mprices) (getTxs blk)
172173
}
173174

174175
-- -------------------------------------------------------------------------------------------------

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Alonzo.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo (
2727

2828
import qualified Cardano.Crypto.Hash as Crypto
2929
import Cardano.Db (ScriptType (..))
30+
import Cardano.DbSync.Config.Types (PlutusConfig, isPlutusEnabled)
3031
import Cardano.DbSync.Era.Shelley.Generic.Metadata
3132
import Cardano.DbSync.Era.Shelley.Generic.Script (fromTimelock)
3233
import Cardano.DbSync.Era.Shelley.Generic.ScriptData (ScriptData (..))
@@ -66,8 +67,8 @@ import qualified Data.Set as Set
6667
import Lens.Micro
6768
import Ouroboros.Consensus.Cardano.Block (EraCrypto, StandardAlonzo, StandardCrypto)
6869

69-
fromAlonzoTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardAlonzo) -> Tx
70-
fromAlonzoTx ioExtraPlutus mprices (blkIndex, tx) =
70+
fromAlonzoTx :: PlutusConfig -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardAlonzo) -> Tx
71+
fromAlonzoTx plutusConfig mprices (blkIndex, tx) =
7172
Tx
7273
{ txHash = txHashId tx
7374
, txBlockIndex = blkIndex
@@ -129,7 +130,7 @@ fromAlonzoTx ioExtraPlutus mprices (blkIndex, tx) =
129130
MaryValue ada (MultiAsset maMap) = txOut ^. Core.valueTxOutL
130131
mDataHash = txOut ^. Alonzo.dataHashTxOutL
131132

132-
(finalMaps, redeemers) = resolveRedeemers ioExtraPlutus mprices tx (Left . toShelleyCert)
133+
(finalMaps, redeemers) = resolveRedeemers plutusConfig mprices tx (Left . toShelleyCert)
133134

134135
-- This is true if second stage contract validation passes or there are no contracts.
135136
isValid2 :: Bool
@@ -178,13 +179,13 @@ resolveRedeemers ::
178179
, Core.EraTx era
179180
, DBScriptPurpose era
180181
) =>
181-
Bool ->
182+
PlutusConfig ->
182183
Maybe Alonzo.Prices ->
183184
Core.Tx era ->
184185
(TxCert era -> Cert) ->
185186
(RedeemerMaps, [(Word64, TxRedeemer)])
186-
resolveRedeemers ioExtraPlutus mprices tx toCert =
187-
if not ioExtraPlutus
187+
resolveRedeemers plutusConfig mprices tx toCert =
188+
if not $ isPlutusEnabled plutusConfig
188189
then (initRedeemersMaps, [])
189190
else
190191
mkRdmrAndUpdateRec (initRedeemersMaps, []) $

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Generic/Tx/Babbage.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
{-# LANGUAGE TypeApplications #-}
77
{-# LANGUAGE TypeOperators #-}
88
{-# LANGUAGE NoImplicitPrelude #-}
9+
{-# OPTIONS_GHC -Wno-unused-matches #-}
910

1011
module Cardano.DbSync.Era.Shelley.Generic.Tx.Babbage (
1112
fromBabbageTx,
1213
fromScript,
1314
fromTxOut,
1415
) where
1516

17+
import Cardano.DbSync.Config.Types (PlutusConfig)
1618
import Cardano.DbSync.Era.Shelley.Generic.Metadata
1719
import Cardano.DbSync.Era.Shelley.Generic.Tx.Allegra (getInterval)
1820
import Cardano.DbSync.Era.Shelley.Generic.Tx.Alonzo
@@ -34,8 +36,8 @@ import qualified Data.Map.Strict as Map
3436
import Lens.Micro
3537
import Ouroboros.Consensus.Shelley.Eras (StandardBabbage, StandardCrypto)
3638

37-
fromBabbageTx :: Bool -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardBabbage) -> Tx
38-
fromBabbageTx ioExtraPlutus mprices (blkIndex, tx) =
39+
fromBabbageTx :: PlutusConfig -> Maybe Alonzo.Prices -> (Word64, Core.Tx StandardBabbage) -> Tx
40+
fromBabbageTx plutusConfig mprices (blkIndex, tx) =
3941
Tx
4042
{ txHash = txHashId tx
4143
, txBlockIndex = blkIndex
@@ -101,7 +103,7 @@ fromBabbageTx ioExtraPlutus mprices (blkIndex, tx) =
101103
case Alonzo.isValid tx of
102104
Alonzo.IsValid x -> x
103105

104-
(finalMaps, redeemers) = resolveRedeemers ioExtraPlutus mprices tx (Left . toShelleyCert)
106+
(finalMaps, redeemers) = resolveRedeemers plutusConfig mprices tx (Left . toShelleyCert)
105107
(invalidBef, invalidAfter) = getInterval txBody
106108

107109
collInputs = mkCollTxIn txBody

0 commit comments

Comments
 (0)