File tree Expand file tree Collapse file tree
cardano-db/src/Cardano/Db/Statement Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -857,17 +857,41 @@ deleteBlocksSlotNo ::
857857 Bool ->
858858 DbM Bool
859859deleteBlocksSlotNo trce txOutVariantType (SlotNo slotNo) isConsumedTxOut = do
860- blockEpochE <- queryNearestBlockSlotNo slotNo
861- case blockEpochE of
862- Nothing -> pure False
863- (Just (blockId, epochN)) -> do
864- -- Delete the block and return whether it was successful
865- deleteCount <- deleteBlocksBlockId trce txOutVariantType blockId epochN isConsumedTxOut
866- if deleteCount > 0
867- then pure True
868- else do
869- liftIO $ logWarning trce $ " deleteBlocksSlotNo: No blocks found for slot: " <> Text. pack (show slotNo)
860+ mBlock <- queryNearestBlockSlotNo slotNo
861+ case mBlock of
862+ Nothing -> do
863+ liftIO $ logWarning trce $ " deleteBlocksSlotNo: No block found at or after slot: " <> textShow slotNo
864+ pure False
865+ Just (blockId, blockNo) -> do
866+ -- Get the correct epoch number (same approach as rollbackFromBlockNo)
867+ mBlockAndEpoch <- queryBlockNoAndEpoch blockNo
868+ case mBlockAndEpoch of
869+ Nothing -> do
870+ liftIO $ logWarning trce $ " deleteBlocksSlotNo: Block not found for block_no: " <> textShow blockNo
870871 pure False
872+ Just (_, epochNo) -> do
873+ nBlocks <- queryBlockCountAfterBlockNo blockNo True
874+ liftIO $
875+ logInfo trce $
876+ " Rollback: Deleting "
877+ <> textShow nBlocks
878+ <> " blocks with block_no >= "
879+ <> textShow blockNo
880+ <> " (slot >= "
881+ <> textShow slotNo
882+ <> " , epoch "
883+ <> textShow epochNo
884+ <> " )"
885+
886+ deleteCount <- deleteBlocksBlockId trce txOutVariantType blockId epochNo isConsumedTxOut
887+
888+ if deleteCount > 0
889+ then do
890+ liftIO $ logInfo trce $ " Rollback: Successfully deleted " <> textShow deleteCount <> " blocks"
891+ pure True
892+ else do
893+ liftIO $ logWarning trce $ " deleteBlocksSlotNo: No blocks were deleted for slot: " <> textShow slotNo
894+ pure False
871895
872896--------------------------------------------------------------------------------
873897deleteBlocksSlotNoNoTrace :: TxOutVariantType -> SlotNo -> DbM Bool
You can’t perform that action at this time.
0 commit comments