Skip to content

Commit 8836de7

Browse files
committed
changes to plutus whitelist
1 parent 78b028e commit 8836de7

File tree

10 files changed

+145
-136
lines changed

10 files changed

+145
-136
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ module Cardano.DbSync.Config.Types (
4444
isTxOutEnabled,
4545
hasLedger,
4646
shouldUseLedger,
47-
isShelleyNotDisabled,
48-
isMultiAssetEnabled,
49-
isMetadataEnabled,
50-
isPlutusEnabled,
47+
isShelleyModeActive,
48+
isMultiAssetModeActive,
49+
isMetadataModeActive,
50+
isPlutusModeActive,
5151
isTxOutBootstrap,
5252
isTxOutConsumed,
5353
isTxOutPrune,
@@ -325,25 +325,25 @@ shouldUseLedger LedgerDisable = False
325325
shouldUseLedger LedgerEnable = True
326326
shouldUseLedger LedgerIgnore = False
327327

328-
isShelleyNotDisabled :: ShelleyInsertConfig -> Bool
329-
isShelleyNotDisabled ShelleyDisable = False
330-
isShelleyNotDisabled ShelleyEnable = True
331-
isShelleyNotDisabled (ShelleyStakeAddrs _) = True
328+
isShelleyModeActive :: ShelleyInsertConfig -> Bool
329+
isShelleyModeActive ShelleyDisable = False
330+
isShelleyModeActive ShelleyEnable = True
331+
isShelleyModeActive (ShelleyStakeAddrs _) = True
332332

333-
isMultiAssetEnabled :: MultiAssetConfig -> Bool
334-
isMultiAssetEnabled MultiAssetDisable = False
335-
isMultiAssetEnabled MultiAssetEnable = True
336-
isMultiAssetEnabled (MultiAssetPolicies _) = True
333+
isMultiAssetModeActive :: MultiAssetConfig -> Bool
334+
isMultiAssetModeActive MultiAssetDisable = False
335+
isMultiAssetModeActive MultiAssetEnable = True
336+
isMultiAssetModeActive (MultiAssetPolicies _) = True
337337

338-
isMetadataEnabled :: MetadataConfig -> Bool
339-
isMetadataEnabled MetadataDisable = False
340-
isMetadataEnabled MetadataEnable = True
341-
isMetadataEnabled (MetadataKeys _) = True
338+
isMetadataModeActive :: MetadataConfig -> Bool
339+
isMetadataModeActive MetadataDisable = False
340+
isMetadataModeActive MetadataEnable = True
341+
isMetadataModeActive (MetadataKeys _) = True
342342

343-
isPlutusEnabled :: PlutusConfig -> Bool
344-
isPlutusEnabled PlutusDisable = False
345-
isPlutusEnabled PlutusEnable = True
346-
isPlutusEnabled (PlutusScripts _) = True
343+
isPlutusModeActive :: PlutusConfig -> Bool
344+
isPlutusModeActive PlutusDisable = False
345+
isPlutusModeActive PlutusEnable = True
346+
isPlutusModeActive (PlutusScripts _) = True
347347

348348
-- -------------------------------------------------------------------------------------------------
349349

@@ -463,7 +463,7 @@ instance FromJSON LedgerInsertConfig where
463463
instance ToJSON ShelleyInsertConfig where
464464
toJSON cfg =
465465
Aeson.object
466-
[ "enable" .= isShelleyNotDisabled cfg
466+
[ "enable" .= isShelleyModeActive cfg
467467
, "stake_addresses" .= stakeAddrs cfg
468468
]
469469
where
@@ -485,7 +485,7 @@ instance FromJSON ShelleyInsertConfig where
485485
instance ToJSON MultiAssetConfig where
486486
toJSON cfg =
487487
Aeson.object
488-
[ "enable" .= isMultiAssetEnabled cfg
488+
[ "enable" .= isMultiAssetModeActive cfg
489489
, "policies" .= policies cfg
490490
]
491491
where
@@ -507,7 +507,7 @@ instance FromJSON MultiAssetConfig where
507507
instance ToJSON MetadataConfig where
508508
toJSON cfg =
509509
Aeson.object
510-
[ "enable" .= isMetadataEnabled cfg
510+
[ "enable" .= isMetadataModeActive cfg
511511
, "keys" .= keys cfg
512512
]
513513
where
@@ -528,7 +528,7 @@ instance FromJSON MetadataConfig where
528528
instance ToJSON PlutusConfig where
529529
toJSON cfg =
530530
Aeson.object
531-
[ "enable" .= isPlutusEnabled cfg
531+
[ "enable" .= isPlutusModeActive cfg
532532
, "script_hashes" .= scriptHashes cfg
533533
]
534534
where

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +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)
30+
import Cardano.DbSync.Config.Types (PlutusConfig, isPlutusModeActive)
3131
import Cardano.DbSync.Era.Shelley.Generic.Metadata
3232
import Cardano.DbSync.Era.Shelley.Generic.Script (fromTimelock)
3333
import Cardano.DbSync.Era.Shelley.Generic.ScriptData (ScriptData (..))
@@ -185,7 +185,7 @@ resolveRedeemers ::
185185
(TxCert era -> Cert) ->
186186
(RedeemerMaps, [(Word64, TxRedeemer)])
187187
resolveRedeemers plutusConfig mprices tx toCert =
188-
if not $ isPlutusEnabled plutusConfig
188+
if not $ isPlutusModeActive plutusConfig
189189
then (initRedeemersMaps, [])
190190
else
191191
mkRdmrAndUpdateRec (initRedeemersMaps, []) $

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Cardano.DbSync.Api.Types (InsertOptions (..), SyncEnv (..), SyncOptions (
1818
import Cardano.DbSync.Cache (insertBlockAndCache, queryPoolKeyWithCache, queryPrevBlockWithCache)
1919
import Cardano.DbSync.Cache.Epoch (writeEpochBlockDiffToCache)
2020
import Cardano.DbSync.Cache.Types (Cache (..), CacheNew (..), EpochBlockDiff (..))
21-
import Cardano.DbSync.Config.Types (isShelleyNotDisabled)
21+
import Cardano.DbSync.Config.Types (isShelleyModeActive)
2222
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
2323
import Cardano.DbSync.Era.Universal.Epoch
2424
import Cardano.DbSync.Era.Universal.Insert.Grouped
@@ -66,7 +66,7 @@ insertBlockUniversal syncEnv shouldLog withinTwoMins withinHalfHour blk details
6666
mPhid <- lift $ queryPoolKeyWithCache syncEnv CacheNew $ coerceKeyRole $ Generic.blkSlotLeader blk
6767
let epochNo = sdEpochNo details
6868

69-
slid <- lift . DB.insertSlotLeader $ Generic.mkSlotLeader (isShelleyNotDisabled $ ioShelley iopts) (Generic.unKeyHashRaw $ Generic.blkSlotLeader blk) (eitherToMaybe mPhid)
69+
slid <- lift . DB.insertSlotLeader $ Generic.mkSlotLeader (isShelleyModeActive $ ioShelley iopts) (Generic.unKeyHashRaw $ Generic.blkSlotLeader blk) (eitherToMaybe mPhid)
7070
blkId <-
7171
lift . insertBlockAndCache cache $
7272
DB.Block

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Cardano.DbSync.Api
2727
import Cardano.DbSync.Api.Types (InsertOptions (..), SyncEnv (..))
2828
import Cardano.DbSync.Cache (queryOrInsertStakeAddress, queryPoolKeyOrInsert)
2929
import Cardano.DbSync.Cache.Types (Cache, CacheNew (..))
30-
import Cardano.DbSync.Config.Types (isShelleyNotDisabled)
30+
import Cardano.DbSync.Config.Types (isShelleyModeActive)
3131
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
3232
import Cardano.DbSync.Era.Universal.Insert.Certificate (insertPots)
3333
import Cardano.DbSync.Era.Universal.Insert.GovAction (insertCostModel, insertDrepDistr, updateEnacted)
@@ -225,7 +225,7 @@ insertEpochStake syncEnv nw epochNo stakeChunk = do
225225
then
226226
( do
227227
saId <- lift $ queryOrInsertStakeAddress syncEnv cache CacheNew nw saddr
228-
poolId <- lift $ queryPoolKeyOrInsert "insertEpochStake" syncEnv cache CacheNew (isShelleyNotDisabled $ ioShelley iopts) pool
228+
poolId <- lift $ queryPoolKeyOrInsert "insertEpochStake" syncEnv cache CacheNew (isShelleyModeActive $ ioShelley iopts) pool
229229
pure $
230230
Just $
231231
DB.EpochStake
@@ -289,7 +289,7 @@ insertRewards syncEnv nw earnedEpoch spendableEpoch cache rewardsChunk = do
289289
PoolKeyHash ->
290290
ExceptT SyncNodeError (ReaderT SqlBackend m) DB.PoolHashId
291291
queryPool poolHash =
292-
lift (queryPoolKeyOrInsert "insertRewards" syncEnv cache CacheNew (isShelleyNotDisabled $ ioShelley iopts) poolHash)
292+
lift (queryPoolKeyOrInsert "insertRewards" syncEnv cache CacheNew (isShelleyModeActive $ ioShelley iopts) poolHash)
293293

294294
iopts = getInsertOptions syncEnv
295295

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Cardano.DbSync.Cache (
3434
queryPoolKeyOrInsert,
3535
)
3636
import Cardano.DbSync.Cache.Types (Cache, CacheNew (..))
37-
import Cardano.DbSync.Config.Types (isShelleyNotDisabled)
37+
import Cardano.DbSync.Config.Types (isShelleyModeActive)
3838
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
3939
import Cardano.DbSync.Era.Universal.Insert.GovAction (
4040
insertCommitteeHash,
@@ -84,20 +84,20 @@ insertCertificate ::
8484
insertCertificate syncEnv isMember blkId txId epochNo slotNo redeemers (Generic.TxCertificate ridx idx cert) =
8585
case cert of
8686
Left (ShelleyTxCertDelegCert deleg) ->
87-
when (isShelleyNotDisabled $ ioShelley iopts) $ insertDelegCert syncEnv network txId idx mRedeemerId epochNo slotNo deleg
87+
when (isShelleyModeActive $ ioShelley iopts) $ insertDelegCert syncEnv network txId idx mRedeemerId epochNo slotNo deleg
8888
Left (ShelleyTxCertPool pool) ->
89-
when (isShelleyNotDisabled $ ioShelley iopts) $ insertPoolCert syncEnv cache isMember network epochNo blkId txId idx pool
89+
when (isShelleyModeActive $ ioShelley iopts) $ insertPoolCert syncEnv cache isMember network epochNo blkId txId idx pool
9090
Left (ShelleyTxCertMir mir) ->
91-
when (isShelleyNotDisabled $ ioShelley iopts) $ insertMirCert syncEnv network txId idx mir
91+
when (isShelleyModeActive $ ioShelley iopts) $ insertMirCert syncEnv network txId idx mir
9292
Left (ShelleyTxCertGenesisDeleg _gen) ->
93-
when (isShelleyNotDisabled $ ioShelley iopts) $
93+
when (isShelleyModeActive $ ioShelley iopts) $
9494
liftIO $
9595
logWarning tracer "insertCertificate: Unhandled DCertGenesis certificate"
9696
Right (ConwayTxCertDeleg deleg) ->
97-
when (isShelleyNotDisabled $ ioShelley iopts) $
97+
when (isShelleyModeActive $ ioShelley iopts) $
9898
insertConwayDelegCert syncEnv txId idx mRedeemerId epochNo slotNo deleg
9999
Right (ConwayTxCertPool pool) ->
100-
when (isShelleyNotDisabled $ ioShelley iopts) $ insertPoolCert syncEnv cache isMember network epochNo blkId txId idx pool
100+
when (isShelleyModeActive $ ioShelley iopts) $ insertPoolCert syncEnv cache isMember network epochNo blkId txId idx pool
101101
Right (ConwayTxCertGov c) ->
102102
when (ioGov iopts) $ case c of
103103
ConwayRegDRep cred coin anchor ->
@@ -147,28 +147,28 @@ insertConwayDelegCert ::
147147
insertConwayDelegCert syncEnv txId idx mRedeemerId epochNo slotNo dCert =
148148
case dCert of
149149
ConwayRegCert cred _dep ->
150-
when (isShelleyNotDisabled $ ioShelley iopts) $
150+
when (isShelleyModeActive $ ioShelley iopts) $
151151
insertStakeRegistration syncEnv epochNo txId idx $
152152
Generic.annotateStakingCred network cred
153153
ConwayUnRegCert cred _dep ->
154-
when (isShelleyNotDisabled $ ioShelley iopts) $
154+
when (isShelleyModeActive $ ioShelley iopts) $
155155
insertStakeDeregistration syncEnv network epochNo txId idx mRedeemerId cred
156156
ConwayDelegCert cred delegatee -> insertDeleg cred delegatee
157157
ConwayRegDelegCert cred delegatee _dep -> do
158-
when (isShelleyNotDisabled $ ioShelley iopts) $
158+
when (isShelleyModeActive $ ioShelley iopts) $
159159
insertStakeRegistration syncEnv epochNo txId idx $
160160
Generic.annotateStakingCred network cred
161161
insertDeleg cred delegatee
162162
where
163163
insertDeleg cred = \case
164164
DelegStake poolkh ->
165-
when (isShelleyNotDisabled $ ioShelley iopts) $
165+
when (isShelleyModeActive $ ioShelley iopts) $
166166
insertDelegation syncEnv cache network epochNo slotNo txId idx mRedeemerId cred poolkh
167167
DelegVote drep ->
168168
when (ioGov iopts) $
169169
insertDelegationVote syncEnv network txId idx cred drep
170170
DelegStakeVote poolkh drep -> do
171-
when (isShelleyNotDisabled $ ioShelley iopts) $
171+
when (isShelleyModeActive $ ioShelley iopts) $
172172
insertDelegation syncEnv cache network epochNo slotNo txId idx mRedeemerId cred poolkh
173173
when (ioGov iopts) $
174174
insertDelegationVote syncEnv network txId idx cred drep

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

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import qualified Data.Text.Encoding as Text
6565
import Database.Persist.Sql (SqlBackend)
6666
import Lens.Micro ((^.))
6767
import Ouroboros.Consensus.Cardano.Block (StandardConway, StandardCrypto)
68+
import Prelude (zip3)
6869

6970
insertGovActionProposal ::
7071
forall m.
@@ -280,48 +281,51 @@ insertVotingProcedures ::
280281
(MonadIO m, MonadBaseControl IO m) =>
281282
SyncEnv ->
282283
DB.TxId ->
284+
[ProposalProcedure StandardConway] ->
283285
(Voter StandardCrypto, [(GovActionId StandardCrypto, VotingProcedure StandardConway)]) ->
284286
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
285-
insertVotingProcedures syncEnv txId (voter, actions) =
286-
mapM_ (insertVotingProcedure syncEnv txId voter) (zip [0 ..] actions)
287+
insertVotingProcedures syncEnv txId proposalPs (voter, actions) =
288+
mapM_ (insertVotingProcedure syncEnv txId voter) (zip3 [0 ..] actions proposalPs)
287289

288290
insertVotingProcedure ::
289291
(MonadIO m, MonadBaseControl IO m) =>
290292
SyncEnv ->
291293
DB.TxId ->
292294
Voter StandardCrypto ->
293-
(Word16, (GovActionId StandardCrypto, VotingProcedure StandardConway)) ->
295+
(Word16, (GovActionId StandardCrypto, VotingProcedure StandardConway), ProposalProcedure StandardConway) ->
294296
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
295-
insertVotingProcedure syncEnv txId voter (index, (gaId, vp)) = do
296-
maybeGovActionId <- resolveGovActionProposal syncEnv gaId
297-
case maybeGovActionId of
298-
Nothing -> pure ()
299-
Just govActionId -> do
300-
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor txId DB.OtherAnchor
301-
(mCommitteeVoterId, mDRepVoter, mStakePoolVoter) <- case voter of
302-
CommitteeVoter cred -> do
303-
khId <- lift $ insertCommitteeHash cred
304-
pure (Just khId, Nothing, Nothing)
305-
DRepVoter cred -> do
306-
drep <- lift $ insertCredDrepHash cred
307-
pure (Nothing, Just drep, Nothing)
308-
StakePoolVoter poolkh -> do
309-
poolHashId <- lift $ queryPoolKeyOrInsert "insertVotingProcedure" syncEnv (envCache syncEnv) CacheNew False poolkh
310-
pure (Nothing, Nothing, Just poolHashId)
311-
void
312-
. lift
313-
. DB.insertVotingProcedure
314-
$ DB.VotingProcedure
315-
{ DB.votingProcedureTxId = txId
316-
, DB.votingProcedureIndex = index
317-
, DB.votingProcedureGovActionProposalId = govActionId
318-
, DB.votingProcedureCommitteeVoter = mCommitteeVoterId
319-
, DB.votingProcedureDrepVoter = mDRepVoter
320-
, DB.votingProcedurePoolVoter = mStakePoolVoter
321-
, DB.votingProcedureVoterRole = Generic.toVoterRole voter
322-
, DB.votingProcedureVote = Generic.toVote $ vProcVote vp
323-
, DB.votingProcedureVotingAnchorId = votingAnchorId
324-
}
297+
insertVotingProcedure syncEnv txId voter (index, (gaId, vp), proposalP) = do
298+
-- check if shelley stake address is in the whitelist
299+
when (shelleyStakeAddrWhitelistCheck syncEnv $ pProcReturnAddr proposalP) $ do
300+
maybeGovActionId <- resolveGovActionProposal syncEnv gaId
301+
case maybeGovActionId of
302+
Nothing -> pure ()
303+
Just govActionId -> do
304+
votingAnchorId <- whenMaybe (strictMaybeToMaybe $ vProcAnchor vp) $ lift . insertVotingAnchor txId DB.OtherAnchor
305+
(mCommitteeVoterId, mDRepVoter, mStakePoolVoter) <- case voter of
306+
CommitteeVoter cred -> do
307+
khId <- lift $ insertCommitteeHash cred
308+
pure (Just khId, Nothing, Nothing)
309+
DRepVoter cred -> do
310+
drep <- lift $ insertCredDrepHash cred
311+
pure (Nothing, Just drep, Nothing)
312+
StakePoolVoter poolkh -> do
313+
poolHashId <- lift $ queryPoolKeyOrInsert "insertVotingProcedure" syncEnv (envCache syncEnv) CacheNew False poolkh
314+
pure (Nothing, Nothing, Just poolHashId)
315+
void
316+
. lift
317+
. DB.insertVotingProcedure
318+
$ DB.VotingProcedure
319+
{ DB.votingProcedureTxId = txId
320+
, DB.votingProcedureIndex = index
321+
, DB.votingProcedureGovActionProposalId = govActionId
322+
, DB.votingProcedureCommitteeVoter = mCommitteeVoterId
323+
, DB.votingProcedureDrepVoter = mDRepVoter
324+
, DB.votingProcedurePoolVoter = mStakePoolVoter
325+
, DB.votingProcedureVoterRole = Generic.toVoterRole voter
326+
, DB.votingProcedureVote = Generic.toVote $ vProcVote vp
327+
, DB.votingProcedureVotingAnchorId = votingAnchorId
328+
}
325329

326330
insertVotingAnchor :: (MonadIO m, MonadBaseControl IO m) => DB.TxId -> DB.AnchorType -> Anchor StandardCrypto -> ReaderT SqlBackend m DB.VotingAnchorId
327331
insertVotingAnchor txId anchorType anchor =

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Cardano.DbSync.Era.Universal.Insert.Grouped
2929
import Cardano.DbSync.Era.Util (safeDecodeToJson)
3030
import Cardano.DbSync.Error
3131
import Cardano.DbSync.Util
32-
import Cardano.DbSync.Util.Whitelist (shelleyStakeAddrWhitelistCheck)
32+
import Cardano.DbSync.Util.Whitelist (isSimplePlutusScriptHashInWhitelist, shelleyStakeAddrWhitelistCheck)
3333
import qualified Cardano.Ledger.Address as Ledger
3434
import qualified Cardano.Ledger.BaseTypes as Ledger
3535
import Cardano.Ledger.Coin (Coin (..))
@@ -205,22 +205,27 @@ insertScript ::
205205
SyncEnv ->
206206
DB.TxId ->
207207
Generic.TxScript ->
208-
ReaderT SqlBackend m DB.ScriptId
209-
insertScript syncEnv txId script = do
210-
mScriptId <- DB.queryScript $ Generic.txScriptHash script
211-
case mScriptId of
212-
Just scriptId -> pure scriptId
213-
Nothing -> do
214-
json <- scriptConvert script
215-
DB.insertScript $
216-
DB.Script
217-
{ DB.scriptTxId = txId
218-
, DB.scriptHash = Generic.txScriptHash script
219-
, DB.scriptType = Generic.txScriptType script
220-
, DB.scriptSerialisedSize = Generic.txScriptPlutusSize script
221-
, DB.scriptJson = json
222-
, DB.scriptBytes = Generic.txScriptCBOR script
223-
}
208+
ReaderT SqlBackend m (Maybe DB.ScriptId)
209+
insertScript syncEnv txId script =
210+
if isSimplePlutusScriptHashInWhitelist syncEnv $ Generic.txScriptHash script
211+
then do
212+
mScriptId <- DB.queryScript $ Generic.txScriptHash script
213+
case mScriptId of
214+
Just scriptId -> pure $ Just scriptId
215+
Nothing -> do
216+
json <- scriptConvert script
217+
mInScript <-
218+
DB.insertScript $
219+
DB.Script
220+
{ DB.scriptTxId = txId
221+
, DB.scriptHash = Generic.txScriptHash script
222+
, DB.scriptType = Generic.txScriptType script
223+
, DB.scriptSerialisedSize = Generic.txScriptPlutusSize script
224+
, DB.scriptJson = json
225+
, DB.scriptBytes = Generic.txScriptCBOR script
226+
}
227+
pure $ Just mInScript
228+
else pure Nothing
224229
where
225230
scriptConvert :: (MonadIO m) => Generic.TxScript -> m (Maybe Text)
226231
scriptConvert s =

0 commit comments

Comments
 (0)