Prevent further underflow when deleting blocks

This commit is contained in:
E M 2026-02-25 20:13:54 +11:00
parent 4c3cfabe6c
commit 8e337478f2
No known key found for this signature in database
2 changed files with 3 additions and 2 deletions

View File

@ -157,7 +157,7 @@ proc updateBlockMetadata*(
BlockMetadata(
size: currBlockMd.size,
expiry: max(currBlockMd.expiry, minExpiry),
refCount: currBlockMd.refCount + plusRefCount - minusRefCount,
refCount: max(0, currBlockMd.refCount + plusRefCount - minusRefCount),
).some
else:
raise newException(

View File

@ -272,7 +272,8 @@ method delBlock*(
error "Failed to delete leaf metadata, block will remain on disk.", err = err.msg
return failure(err)
if err =?
if leafMd.blkCid.mcodec == BlockCodec and
err =?
(await self.updateBlockMetadata(leafMd.blkCid, minusRefCount = 1)).errorOption:
if not (err of BlockNotFoundError):
return failure(err)