Skip to content

Commit de26071

Browse files
committed
Extendend whitelist options
1 parent 77cd794 commit de26071

File tree

20 files changed

+343
-599
lines changed

20 files changed

+343
-599
lines changed

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

+4-3
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
@@ -140,6 +140,7 @@ library
140140
Cardano.DbSync.Util.Bech32
141141
Cardano.DbSync.Util.Cbor
142142
Cardano.DbSync.Util.Constraint
143+
Cardano.DbSync.Util.Whitelist
143144

144145
Paths_cardano_db_sync
145146

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

+35-45
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

+9-10
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

+8-4
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

+4-3
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

+1-1
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/Conway/GovAction.hs renamed to cardano-db-sync/src/Cardano/DbSync/Era/Conway/Insert/GovAction.hs

+8-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{-# LANGUAGE TypeFamilies #-}
99
{-# LANGUAGE NoImplicitPrelude #-}
1010

11-
module Cardano.DbSync.Era.Conway.GovAction (
11+
module Cardano.DbSync.Era.Conway.Insert.GovAction (
1212
insertConstitution,
1313
insertCostModel,
1414
insertCredDrepHash,
@@ -47,10 +47,12 @@ import Cardano.Ledger.Conway.Governance
4747
import qualified Cardano.Ledger.Credential as Ledger
4848
import Cardano.Ledger.DRep (DRepState (..))
4949
import Cardano.Ledger.Keys (KeyRole (..))
50-
import qualified Cardano.Ledger.Plutus.CostModels as Ledger
50+
import Cardano.Ledger.Plutus.CostModels (CostModel)
5151
import Cardano.Ledger.Plutus.Language (Language)
5252
import Cardano.Ledger.Shelley.API (Coin (..))
5353
import Cardano.Prelude
54+
55+
import Cardano.Ledger.Plutus (mkCostModels)
5456
import Control.Monad.Extra (whenJust)
5557
import Control.Monad.Trans.Control (MonadBaseControl)
5658
import qualified Data.Aeson as Aeson
@@ -72,7 +74,7 @@ insertGovActionProposal ::
7274
insertGovActionProposal cache blkId txId govExpiresAt (index, pp) = do
7375
addrId <-
7476
lift $ queryOrInsertRewardAccount cache CacheNew $ pProcReturnAddr pp
75-
votingAnchorId <- lift $ insertAnchor txId $ pProcAnchor pp
77+
votingAnchorId <- lift $ insertVotingAnchor txId $ pProcAnchor pp
7678
mParamProposalId <- lift $
7779
case pProcGovAction pp of
7880
ParameterChange _ pparams _ ->
@@ -286,15 +288,6 @@ insertVotingAnchor txId anchor =
286288
, DB.votingAnchorDataHash = Generic.safeHashToByteString $ anchorDataHash anchor
287289
}
288290

289-
insertAnchor :: (MonadIO m, MonadBaseControl IO m) => DB.TxId -> Anchor StandardCrypto -> ReaderT SqlBackend m DB.VotingAnchorId
290-
insertAnchor txId anchor =
291-
DB.insertAnchor $
292-
DB.VotingAnchor
293-
{ DB.votingAnchorTxId = txId
294-
, DB.votingAnchorUrl = DB.VoteUrl $ Ledger.urlToText $ anchorUrl anchor -- TODO: Conway check unicode and size of URL
295-
, DB.votingAnchorDataHash = Generic.safeHashToByteString $ anchorDataHash anchor
296-
}
297-
298291
--------------------------------------------------------------------------------------
299292
-- DREP
300293
--------------------------------------------------------------------------------------
@@ -340,21 +333,19 @@ insertDrepDistr e pSnapshot = do
340333
insertCostModel ::
341334
(MonadBaseControl IO m, MonadIO m) =>
342335
DB.BlockId ->
343-
Map Language Ledger.CostModel ->
336+
Map Language CostModel ->
344337
ReaderT SqlBackend m DB.CostModelId
345338
insertCostModel _blkId cms =
346339
DB.insertCostModel $
347340
DB.CostModel
348-
{ DB.costModelHash = Crypto.abstractHashToBytes $ Crypto.serializeCborHash $ Ledger.mkCostModels cms
341+
{ DB.costModelHash = Crypto.abstractHashToBytes $ Crypto.serializeCborHash $ mkCostModels cms
349342
, DB.costModelCosts = Text.decodeUtf8 $ LBS.toStrict $ Aeson.encode cms
350343
}
351344

352345
updateEnacted :: forall m. (MonadBaseControl IO m, MonadIO m) => Bool -> EpochNo -> EnactState StandardConway -> ExceptT SyncNodeError (ReaderT SqlBackend m) ()
353346
updateEnacted isEnacted epochNo enactedState = do
354347
whenJust (strictMaybeToMaybe (enactedState ^. ensPrevPParamUpdateL)) $ \prevId -> do
355-
gaId <- resolveGovActionProposal $ getPrevId prevId
348+
gaId <- resolveGovActionProposal $ unGovPurposeId prevId
356349
if isEnacted
357350
then lift $ DB.updateGovActionEnacted gaId (unEpochNo epochNo)
358351
else lift $ DB.updateGovActionRatified gaId (unEpochNo epochNo)
359-
where
360-
getPrevId = unGovPurposeId

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

+10-9
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
-- -------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)