Skip to content

Commit 8aceaef

Browse files
committed
Don't try to set null consumed when it's disabled
Fixes #1902
1 parent f772b0d commit 8aceaef

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rollbackFromBlockNo syncEnv blkNo = do
4848
, textShow blkNo
4949
]
5050
lift $ do
51-
deletedBlockCount <- DB.deleteBlocksBlockId trce txOutTableType blockId epochNo (Just (DB.pcmConsumedTxOut $ getPruneConsume syncEnv))
51+
deletedBlockCount <- DB.deleteBlocksBlockId trce txOutTableType blockId epochNo (DB.pcmConsumedTxOut $ getPruneConsume syncEnv)
5252
when (deletedBlockCount > 0) $ do
5353
-- We use custom constraints to improve input speeds when syncing.
5454
-- If they don't already exists we add them here as once a rollback has happened
@@ -111,4 +111,4 @@ prepareRollback syncEnv point serverTip =
111111
unsafeRollback :: Trace IO Text -> DB.TxOutTableType -> DB.PGConfig -> SlotNo -> IO (Either SyncNodeError ())
112112
unsafeRollback trce txOutTableType config slotNo = do
113113
logWarning trce $ "Starting a forced rollback to slot: " <> textShow (unSlotNo slotNo)
114-
Right <$> DB.runDbNoLogging (DB.PGPassCached config) (void $ DB.deleteBlocksSlotNo trce txOutTableType slotNo Nothing)
114+
Right <$> DB.runDbNoLogging (DB.PGPassCached config) (void $ DB.deleteBlocksSlotNo trce txOutTableType slotNo True)

cardano-db/src/Cardano/Db/Operations/Delete.hs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
{-# LANGUAGE TypeOperators #-}
1010

1111
module Cardano.Db.Operations.Delete (
12-
deleteBlocksSlotNo,
13-
deleteBlocksSlotNoNoTrace,
1412
deleteDelistedPool,
1513
deleteBlocksBlockId,
14+
queryDelete,
15+
deleteBlocksSlotNo,
16+
deleteBlocksSlotNoNoTrace,
1617
deleteBlocksForTests,
1718
deleteBlock,
18-
queryDelete,
1919
) where
2020

2121
import Cardano.BM.Trace (Trace, logInfo, logWarning, nullTracer)
@@ -54,32 +54,25 @@ import Database.Persist (
5454
)
5555
import Database.Persist.Sql (Filter, SqlBackend, delete, deleteWhere, deleteWhereCount, selectKeysList)
5656

57-
deleteBlocksSlotNoNoTrace :: MonadIO m => TxOutTableType -> SlotNo -> ReaderT SqlBackend m Bool
58-
deleteBlocksSlotNoNoTrace txOutTableType slotNo = deleteBlocksSlotNo nullTracer txOutTableType slotNo Nothing
59-
6057
-- | Delete a block if it exists. Returns 'True' if it did exist and has been
6158
-- deleted and 'False' if it did not exist.
6259
deleteBlocksSlotNo ::
6360
MonadIO m =>
6461
Trace IO Text ->
6562
TxOutTableType ->
6663
SlotNo ->
67-
Maybe Bool ->
64+
Bool ->
6865
ReaderT SqlBackend m Bool
69-
deleteBlocksSlotNo trce txOutTableType (SlotNo slotNo) mIsConsumedTxOut = do
66+
deleteBlocksSlotNo trce txOutTableType (SlotNo slotNo) isConsumedTxOut = do
7067
mBlockId <- queryNearestBlockSlotNo slotNo
7168
case mBlockId of
7269
Nothing -> do
7370
liftIO $ logWarning trce $ "deleteBlocksSlotNo: No block contains the the slot: " <> pack (show slotNo)
7471
pure False
7572
Just (blockId, epochN) -> do
76-
void $ deleteBlocksBlockId trce txOutTableType blockId epochN mIsConsumedTxOut
73+
void $ deleteBlocksBlockId trce txOutTableType blockId epochN isConsumedTxOut
7774
pure True
7875

79-
deleteBlocksForTests :: MonadIO m => TxOutTableType -> BlockId -> Word64 -> ReaderT SqlBackend m ()
80-
deleteBlocksForTests txOutTableType blockId epochN = do
81-
void $ deleteBlocksBlockId nullTracer txOutTableType blockId epochN Nothing
82-
8376
-- | Delete starting from a 'BlockId'.
8477
deleteBlocksBlockId ::
8578
MonadIO m =>
@@ -89,20 +82,19 @@ deleteBlocksBlockId ::
8982
-- | The 'EpochNo' of the block to delete.
9083
Word64 ->
9184
-- | Is ConsumeTxout
92-
Maybe Bool ->
85+
Bool ->
9386
ReaderT SqlBackend m Int64
94-
deleteBlocksBlockId trce txOutTableType blockId epochN mIsConsumedTxOut = do
87+
deleteBlocksBlockId trce txOutTableType blockId epochN isConsumedTxOut = do
9588
mMinIds <- fmap (textToMinIds txOutTableType =<<) <$> queryReverseIndexBlockId blockId
9689
(cminIds, completed) <- findMinIdsRec mMinIds mempty
9790
mTxId <- queryMinRefId TxBlockId blockId
9891
minIds <- if completed then pure cminIds else completeMinId mTxId cminIds
9992
deleteEpochLogs <- deleteUsingEpochNo epochN
10093
(deleteBlockCount, blockDeleteLogs) <- deleteTablesAfterBlockId txOutTableType blockId mTxId minIds
10194
setNullLogs <-
102-
maybe
103-
(pure ("ConsumedTxOut is not active so no Nulls set", 0))
104-
(\_ -> querySetNullTxOut txOutTableType mTxId)
105-
mIsConsumedTxOut
95+
if isConsumedTxOut
96+
then querySetNullTxOut txOutTableType mTxId
97+
else pure ("ConsumedTxOut is not active so no Nulls set", 0)
10698
-- log all the deleted rows in the rollback
10799
liftIO $ logInfo trce $ mkRollbackSummary (deleteEpochLogs <> blockDeleteLogs) setNullLogs
108100
pure deleteBlockCount
@@ -357,17 +349,6 @@ deleteDelistedPool poolHash = do
357349
mapM_ delete keys
358350
pure $ not (null keys)
359351

360-
-- | Delete a block if it exists. Returns 'True' if it did exist and has been
361-
-- deleted and 'False' if it did not exist.
362-
deleteBlock :: MonadIO m => TxOutTableType -> Block -> ReaderT SqlBackend m Bool
363-
deleteBlock txOutTableType block = do
364-
mBlockId <- queryBlockHash block
365-
case mBlockId of
366-
Nothing -> pure False
367-
Just (blockId, epochN) -> do
368-
void $ deleteBlocksBlockId nullTracer txOutTableType blockId epochN Nothing
369-
pure True
370-
371352
mkRollbackSummary :: [(Text, Int64)] -> (Text, Int64) -> Text
372353
mkRollbackSummary logs setNullLogs =
373354
"\n----------------------- Rollback Summary: ----------------------- \n"
@@ -392,3 +373,25 @@ mkRollbackSummary logs setNullLogs =
392373
<> if nullCount == 0
393374
then nullMessage
394375
else "\n\nSet Null: " <> nullMessage <> " - Count: " <> pack (show nullCount)
376+
377+
-- Tools
378+
379+
deleteBlocksSlotNoNoTrace :: MonadIO m => TxOutTableType -> SlotNo -> ReaderT SqlBackend m Bool
380+
deleteBlocksSlotNoNoTrace txOutTableType slotNo = deleteBlocksSlotNo nullTracer txOutTableType slotNo True
381+
382+
-- Tests
383+
384+
deleteBlocksForTests :: MonadIO m => TxOutTableType -> BlockId -> Word64 -> ReaderT SqlBackend m ()
385+
deleteBlocksForTests txOutTableType blockId epochN = do
386+
void $ deleteBlocksBlockId nullTracer txOutTableType blockId epochN False
387+
388+
-- | Delete a block if it exists. Returns 'True' if it did exist and has been
389+
-- deleted and 'False' if it did not exist.
390+
deleteBlock :: MonadIO m => TxOutTableType -> Block -> ReaderT SqlBackend m Bool
391+
deleteBlock txOutTableType block = do
392+
mBlockId <- queryBlockHash block
393+
case mBlockId of
394+
Nothing -> pure False
395+
Just (blockId, epochN) -> do
396+
void $ deleteBlocksBlockId nullTracer txOutTableType blockId epochN False
397+
pure True

0 commit comments

Comments
 (0)