Skip to content

Commit 5bb86ac

Browse files
committed
fix resolveScriptHash in shelley whitelist error
1 parent cc66f77 commit 5bb86ac

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module Cardano.DbSync.Config.Types (
4545
hasLedger,
4646
shouldUseLedger,
4747
isShelleyModeActive,
48+
isShelleyWhitelistModeActive,
4849
isMultiAssetModeActive,
4950
isMetadataModeActive,
5051
isPlutusModeActive,
@@ -330,6 +331,10 @@ isShelleyModeActive ShelleyDisable = False
330331
isShelleyModeActive ShelleyEnable = True
331332
isShelleyModeActive (ShelleyStakeAddrs _) = True
332333

334+
isShelleyWhitelistModeActive :: ShelleyInsertConfig -> Bool
335+
isShelleyWhitelistModeActive (ShelleyStakeAddrs _) = True
336+
isShelleyWhitelistModeActive _other = False
337+
333338
isMultiAssetModeActive :: MultiAssetConfig -> Bool
334339
isMultiAssetModeActive MultiAssetDisable = False
335340
isMultiAssetModeActive MultiAssetEnable = True

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ insertVotingProcedures ::
288288
(Voter StandardCrypto, [(GovActionId StandardCrypto, VotingProcedure StandardConway)]) ->
289289
ExceptT SyncNodeError (ReaderT SqlBackend m) ()
290290
insertVotingProcedures syncEnv txId proposalPs (voter, actions) =
291+
-- TODO: cmdv will actions & proposalPs always be the same length?
291292
mapM_ (insertVotingProcedure syncEnv txId voter) (zip3 [0 ..] actions proposalPs)
292293

293294
insertVotingProcedure ::

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ data ExtendedTxOut = ExtendedTxOut
6262
{ etoTxHash :: !ByteString
6363
, etoTxOut :: !DB.TxOut
6464
}
65+
deriving (Show)
6566

6667
data ExtendedTxIn = ExtendedTxIn
6768
{ etiTxIn :: !DB.TxIn
@@ -144,12 +145,15 @@ insertReverseIndex blockId minIds =
144145
-- This happens the input consumes an output introduced in the same block.
145146
resolveTxInputs ::
146147
MonadIO m =>
148+
SyncEnv ->
149+
-- | Has the output been consumed?
147150
Bool ->
151+
-- | Does the output need a value?
148152
Bool ->
149153
[ExtendedTxOut] ->
150154
Generic.TxIn ->
151155
ExceptT SyncNodeError (ReaderT SqlBackend m) (Generic.TxIn, DB.TxId, Either Generic.TxIn DB.TxOutId, Maybe DbLovelace)
152-
resolveTxInputs hasConsumed needsValue groupedOutputs txIn =
156+
resolveTxInputs _syncEnv hasConsumed needsValue groupedOutputs txIn =
153157
liftLookupFail ("resolveTxInputs " <> textShow txIn <> " ") $ do
154158
qres <-
155159
case (hasConsumed, needsValue) of

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ module Cardano.DbSync.Era.Universal.Insert.Other (
2020
where
2121

2222
import qualified Cardano.Db as DB
23-
import Cardano.DbSync.Api.Types (SyncEnv)
23+
import Cardano.DbSync.Api.Types (InsertOptions (..), SyncEnv (..), SyncOptions (..))
2424
import Cardano.DbSync.Cache (insertDatumAndCache, queryDatum, queryMAWithCache, queryOrInsertRewardAccount, queryOrInsertStakeAddress)
2525
import Cardano.DbSync.Cache.Types (Cache (..), CacheNew (..))
26+
import Cardano.DbSync.Config.Types (isShelleyWhitelistModeActive)
2627
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
2728
import Cardano.DbSync.Era.Shelley.Query (queryStakeRefPtr)
2829
import Cardano.DbSync.Era.Universal.Insert.Grouped
@@ -74,11 +75,14 @@ insertRedeemer syncEnv disInOut groupedOutputs txId (rix, redeemer) = do
7475
(MonadBaseControl IO m, MonadIO m) =>
7576
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe ByteString)
7677
findScriptHash =
77-
case (disInOut, Generic.txRedeemerScriptHash redeemer) of
78-
(True, _) -> pure Nothing
79-
(_, Nothing) -> pure Nothing
80-
(_, Just (Right bs)) -> pure $ Just bs
81-
(_, Just (Left txIn)) -> resolveScriptHash groupedOutputs txIn
78+
-- If we are in shelley whitelist mode, we don't need to resolve the script hash
79+
if isShelleyWhitelistModeActive $ ioShelley $ soptInsertOptions $ envOptions syncEnv
80+
then pure Nothing
81+
else case (disInOut, Generic.txRedeemerScriptHash redeemer) of
82+
(True, _) -> pure Nothing
83+
(_, Nothing) -> pure Nothing
84+
(_, Just (Right bs)) -> pure $ Just bs
85+
(_, Just (Left txIn)) -> resolveScriptHash groupedOutputs txIn
8286

8387
insertRedeemerData ::
8488
(MonadBaseControl IO m, MonadIO m) =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
8686
(resolvedInputs, fees', deposits) <- case (disInOut, mdeposits, unCoin <$> Generic.txFees tx) of
8787
(True, _, _) -> pure ([], 0, unCoin <$> mdeposits)
8888
(_, Just deposits, Just fees) -> do
89-
(resolvedInputs, _) <- splitLast <$> mapM (resolveTxInputs hasConsumed False (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
89+
(resolvedInputs, _) <- splitLast <$> mapM (resolveTxInputs syncEnv hasConsumed False (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
9090
pure (resolvedInputs, fees, Just (unCoin deposits))
9191
(_, Nothing, Just fees) -> do
92-
(resolvedInputs, amounts) <- splitLast <$> mapM (resolveTxInputs hasConsumed False (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
92+
(resolvedInputs, amounts) <- splitLast <$> mapM (resolveTxInputs syncEnv hasConsumed False (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
9393
if any isNothing amounts
9494
then pure (resolvedInputs, fees, Nothing)
9595
else
9696
let !inSum = sum $ map unDbLovelace $ catMaybes amounts
9797
in pure (resolvedInputs, fees, Just $ fromIntegral (inSum + withdrawalSum) - fromIntegral outSum - fromIntegral fees)
9898
(_, _, Nothing) -> do
9999
-- Nothing in fees means a phase 2 failure
100-
(resolvedInsFull, amounts) <- splitLast <$> mapM (resolveTxInputs hasConsumed True (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
100+
(resolvedInsFull, amounts) <- splitLast <$> mapM (resolveTxInputs syncEnv hasConsumed True (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
101101
let !inSum = sum $ map unDbLovelace $ catMaybes amounts
102102
!diffSum = if inSum >= outSum then inSum - outSum else 0
103103
!fees = maybe diffSum (fromIntegral . unCoin) (Generic.txFees tx)

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ share
153153
inlineDatumId DatumId Maybe noreference
154154
referenceScriptId ScriptId Maybe noreference
155155
UniqueTxout txId index -- The (tx_id, index) pair must be unique.
156+
deriving Eq Show
156157

157158
CollateralTxOut
158159
txId TxId noreference -- This type is the primary key for the 'tx' table.

0 commit comments

Comments
 (0)