Skip to content

Commit c752e61

Browse files
committed
handle whitelist resolvetxinput
1 parent 5bb86ac commit c752e61

File tree

2 files changed

+12
-25
lines changed
  • cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway
  • cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert

2 files changed

+12
-25
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Whitelist.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ fullTxStakeAddressWhitelist ioManager metadata = do
259259
assertEqBackoff dbSync MockQ.queryStakeDeRegCount 2 [] "Expected 1 stake deregistration"
260260
assertEqBackoff dbSync MockQ.queryStakeRegCount 2 [] "Expected 1 stake registration"
261261
assertEqBackoff dbSync MockQ.countTxOutNonNullStakeAddrIds 2 [] "Expected 1 non-null stake address id"
262-
-- TODO: Cmdv: Missing tables that are currently blank:
263-
-- delegation, epoch_stake, pool_owner, stake_deregistration
264-
-- One's that are needed for sanchonet:
262+
-- TODO: Cmdv: Missing tables checks that are currently blank in tests:
265263
-- delegation_vote, gov_action_proposal, instant_reward, reserve,
266264
-- treasury, treasury_withdrawl.
267265

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Cardano.DbSync.Api
2020
import Cardano.DbSync.Api.Types (InsertOptions (..), SyncEnv (..))
2121
import Cardano.DbSync.Cache.Types (Cache (..))
2222

23-
import Cardano.DbSync.Config.Types (MetadataConfig (..), MultiAssetConfig (..), PlutusConfig (..), ShelleyInsertConfig (..), isPlutusModeActive, isShelleyModeActive)
23+
import Cardano.DbSync.Config.Types (MetadataConfig (..), MultiAssetConfig (..), PlutusConfig (..), isPlutusModeActive, isShelleyModeActive)
2424
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
2525
import Cardano.DbSync.Era.Shelley.Generic.Metadata (TxMetadataValue (..), metadataValueToJsonNoSchema)
2626
import Cardano.DbSync.Era.Universal.Insert.Certificate (insertCertificate)
@@ -83,7 +83,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
8383
disInOut <- liftIO $ getDisableInOutState syncEnv
8484
-- In some txs and with specific configuration we may be able to find necessary data within the tx body.
8585
-- In these cases we can avoid expensive queries.
86-
(resolvedInputs, fees', deposits) <- case (disInOut, mdeposits, unCoin <$> Generic.txFees tx) of
86+
(resolvedInputs, resolvedFees', resolvedDeposits) <- case (disInOut, mdeposits, unCoin <$> Generic.txFees tx) of
8787
(True, _, _) -> pure ([], 0, unCoin <$> mdeposits)
8888
(_, Just deposits, Just fees) -> do
8989
(resolvedInputs, _) <- splitLast <$> mapM (resolveTxInputs syncEnv hasConsumed False (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
@@ -95,14 +95,14 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
9595
else
9696
let !inSum = sum $ map unDbLovelace $ catMaybes amounts
9797
in pure (resolvedInputs, fees, Just $ fromIntegral (inSum + withdrawalSum) - fromIntegral outSum - fromIntegral fees)
98+
-- Nothing in fees means a phase 2 failure
9899
(_, _, Nothing) -> do
99-
-- Nothing in fees means a phase 2 failure
100100
(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)
104104
pure (resolvedInsFull, fromIntegral fees, Just 0)
105-
let fees = fromIntegral fees'
105+
let resolvedFees = fromIntegral resolvedFees'
106106
-- Insert transaction and get txId from the DB.
107107
!txId <-
108108
lift
@@ -112,8 +112,8 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
112112
, DB.txBlockId = blkId
113113
, DB.txBlockIndex = blockIndex
114114
, DB.txOutSum = DB.DbLovelace outSum
115-
, DB.txFee = DB.DbLovelace fees
116-
, DB.txDeposit = fromIntegral <$> deposits
115+
, DB.txFee = DB.DbLovelace resolvedFees
116+
, DB.txDeposit = fromIntegral <$> resolvedDeposits
117117
, DB.txSize = Generic.txSize tx
118118
, DB.txInvalidBefore = DbWord64 . unSlotNo <$> Generic.txInvalidBefore tx
119119
, DB.txInvalidHereafter = DbWord64 . unSlotNo <$> Generic.txInvalidHereafter tx
@@ -132,7 +132,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
132132
let !txIns = map (prepareTxIn txId Map.empty) resolvedInputs
133133
-- There is a custom semigroup instance for BlockGroupedData which uses addition for the values `fees` and `outSum`.
134134
-- Same happens bellow on last line of this function.
135-
pure (grouped <> BlockGroupedData txIns txOutsGrouped [] [] fees outSum)
135+
pure (grouped <> BlockGroupedData txIns txOutsGrouped [] [] resolvedFees outSum)
136136
else do
137137
-- The following operations only happen if the script passes stage 2 validation (or the tx has
138138
-- no script).
@@ -168,7 +168,6 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
168168

169169
when (isShelleyModeActive $ ioShelley iopts) $ do
170170
mapM_ (insertWithdrawals syncEnv cache txId redeemers) $ Generic.txWithdrawals tx
171-
-- TODO: cmdv SHELLEY
172171
mapM_ (lift . insertParamProposal blkId txId) $ Generic.txParamProposal tx
173172

174173
maTxMint <-
@@ -179,11 +178,10 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
179178

180179
when (ioGov iopts) $ do
181180
mapM_ (insertGovActionProposal syncEnv blkId txId (getGovExpiresAt applyResult epochNo) (apCommittee applyResult)) $ zip [0 ..] (Generic.txProposalProcedure tx)
182-
-- TODO: cmdv SHELLEY
183181
mapM_ (insertVotingProcedures syncEnv txId (Generic.txProposalProcedure tx)) (Generic.txVotingProcedure tx)
184182

185183
let !txIns = map (prepareTxIn txId redeemers) resolvedInputs
186-
pure (grouped <> BlockGroupedData txIns txOutsGrouped txMetadata maTxMint fees outSum)
184+
pure (grouped <> BlockGroupedData txIns txOutsGrouped txMetadata maTxMint resolvedFees outSum)
187185
where
188186
tracer = getTrace syncEnv
189187
cache = envCache syncEnv
@@ -202,18 +200,10 @@ insertTxOut ::
202200
Generic.TxOut ->
203201
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe (ExtendedTxOut, [MissingMaTxOut]))
204202
insertTxOut syncEnv cache iopts (txId, txHash) (Generic.TxOut index addr value maMap mScript dt) =
205-
case ioShelley iopts of
206-
ShelleyStakeAddrs _ ->
207-
if shelleyStkAddrWhitelistCheckWithAddr syncEnv addr
208-
then plutusCheck
209-
else pure Nothing
210-
_other -> plutusCheck
203+
case ioPlutus iopts of
204+
PlutusDisable -> buildExtendedTxOutPart2 Nothing Nothing
205+
_other -> buildExtendedTxOutPart1
211206
where
212-
plutusCheck =
213-
case ioPlutus iopts of
214-
PlutusDisable -> buildExtendedTxOutPart2 Nothing Nothing
215-
_other -> buildExtendedTxOutPart1
216-
217207
buildExtendedTxOutPart1 ::
218208
(MonadBaseControl IO m, MonadIO m) =>
219209
ExceptT SyncNodeError (ReaderT SqlBackend m) (Maybe (ExtendedTxOut, [MissingMaTxOut]))
@@ -420,7 +410,6 @@ insertCollateralTxOut syncEnv cache (txId, _txHash) txout@(Generic.TxOut index a
420410
, DB.collateralTxOutReferenceScriptId = mScriptId
421411
}
422412
pure ()
423-
-- TODO: Is there any reason to add new tables for collateral multi-assets/multi-asset-outputs
424413
hasScript :: Bool
425414
hasScript = maybe False Generic.hasCredScript (Generic.getPaymentCred addr)
426415

0 commit comments

Comments
 (0)