Skip to content

Commit

Permalink
Fix an issue with hardcoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
kderme committed May 30, 2023
1 parent 9738a34 commit de170fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 0 additions & 1 deletion cardano-db-sync/src/Cardano/DbSync/Default.hs
Expand Up @@ -82,7 +82,6 @@ applyAndInsertBlockMaybe syncEnv cblk = do
, ". Time to restore consistency."
]
rollbackFromBlockNo syncEnv (blockNo cblk)
liftIO $ putStrLn ("block" :: Text)
insertBlock syncEnv cblk applyRes True tookSnapshot
liftIO $ setConsistentLevel syncEnv Consistent
Right blockId | Just (adaPots, slotNo, epochNo) <- getAdaPots applyRes -> do
Expand Down
18 changes: 11 additions & 7 deletions cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Insert.hs
Expand Up @@ -114,7 +114,7 @@ insertShelleyBlock syncEnv shouldLog withinTwoMins withinHalfHour blk details is
}

let zippedTx = zip [0 ..] (Generic.blkTxs blk)
let txInserter = insertTx tracer cache (getInsertOptions syncEnv) (getNetwork syncEnv) isMember blkId (sdEpochNo details) (Generic.blkSlotNo blk)
let txInserter = insertTx syncEnv isMember blkId (sdEpochNo details) (Generic.blkSlotNo blk)
grouped <- foldM (\grouped (idx, tx) -> txInserter idx tx grouped) mempty zippedTx
minIds <- insertBlockGroupedData syncEnv grouped
when withinHalfHour $
Expand Down Expand Up @@ -211,10 +211,7 @@ insertOnNewEpoch tracer blkId slotNo epochNo newEpoch = do

insertTx ::
(MonadBaseControl IO m, MonadIO m) =>
Trace IO Text ->
Cache ->
InsertOptions ->
Ledger.Network ->
SyncEnv ->
IsPoolMember ->
DB.BlockId ->
EpochNo ->
Expand All @@ -223,10 +220,11 @@ insertTx ::
Generic.Tx ->
BlockGroupedData ->
ExceptT SyncNodeError (ReaderT SqlBackend m) BlockGroupedData
insertTx tracer cache iopts network isMember blkId epochNo slotNo blockIndex tx grouped = do
insertTx syncEnv isMember blkId epochNo slotNo blockIndex tx grouped = do
hasConsumed <- liftIO $ getHasConsumed syncEnv
let !outSum = fromIntegral $ unCoin $ Generic.txOutSum tx
!withdrawalSum = fromIntegral $ unCoin $ Generic.txWithdrawalSum tx
!resolvedInputs <- mapM (resolveTxInputs (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
!resolvedInputs <- mapM (resolveTxInputs hasConsumed (fst <$> groupedTxOut grouped)) (Generic.txInputs tx)
let !inSum = sum $ map (unDbLovelace . forth4) resolvedInputs
let diffSum = if inSum >= outSum then inSum - outSum else 0
let !fees = maybe diffSum (fromIntegral . unCoin) (Generic.txFees tx)
Expand Down Expand Up @@ -295,6 +293,12 @@ insertTx tracer cache iopts network isMember blkId epochNo slotNo blockIndex tx

let !txIns = map (prepareTxIn txId redeemers) resolvedInputs
pure $ grouped <> BlockGroupedData txIns txOutsGrouped txMetadata maTxMint
where
tracer = getTrace syncEnv
cache = envCache syncEnv
iopts = getInsertOptions syncEnv
network = getNetwork syncEnv


prepareTxOut ::
(MonadBaseControl IO m, MonadIO m) =>
Expand Down
Expand Up @@ -136,13 +136,14 @@ insertReverseIndex blockId minIds =
-- In this case we also cannot find yet the 'TxOutId', so we return 'Nothing' for now
resolveTxInputs ::
MonadIO m =>
Bool ->
[ExtendedTxOut] ->
Generic.TxIn ->
ExceptT SyncNodeError (ReaderT SqlBackend m) (Generic.TxIn, DB.TxId, Either Generic.TxIn DB.TxOutId, DbLovelace)
resolveTxInputs groupedOutputs txIn =
resolveTxInputs hasConsumed groupedOutputs txIn =
liftLookupFail ("resolveTxInputs " <> textShow txIn <> " ") $ do
qres <-
if True
if not hasConsumed
then fmap convertnotFound <$> queryResolveInput txIn
else fmap convertFound <$> queryResolveInput2 txIn
case qres of
Expand Down

0 comments on commit de170fc

Please sign in to comment.