diff --git a/codex/slotbuilder/slotbuilder.nim b/codex/slotbuilder/slotbuilder.nim index cc912b1b..12be8267 100644 --- a/codex/slotbuilder/slotbuilder.nim +++ b/codex/slotbuilder/slotbuilder.nim @@ -30,7 +30,10 @@ proc new*( return failure("Can only create SlotBuilder using protected manifests.") if (manifest.blocksCount mod manifest.ecK) != 0: - return failure("Number of blocks must be devisable by number of slots.") + return failure("Number of blocks must be divisable by number of slots.") + + if (manifest.blockSize.int mod CellSize) != 0: + return failure("Block size must be divisable by cell size.") let numberOfSlotBlocks = manifest.blocksCount div manifest.ecK success(SlotBuilder( diff --git a/tests/codex/slotbuilder/testslotbuilder.nim b/tests/codex/slotbuilder/testslotbuilder.nim index 45018a84..8319517f 100644 --- a/tests/codex/slotbuilder/testslotbuilder.nim +++ b/tests/codex/slotbuilder/testslotbuilder.nim @@ -96,6 +96,21 @@ asyncchecksuite "Slot builder": check: SlotBuilder.new(localStore, mismatchManifest).isErr + test "Block size must be divisable by cell size": + let mismatchManifest = Manifest.new( + manifest = Manifest.new( + treeCid = Cid.example, + blockSize = (blockSize - 1).NBytes, + datasetSize = (datasetSize - numberOfDatasetBlocks).NBytes), + treeCid = Cid.example, + datasetSize = (datasetSize - numberOfDatasetBlocks).NBytes, + ecK = numberOfSlots, + ecM = 0 + ) + + check: + SlotBuilder.new(localStore, mismatchManifest).isErr + proc getNextPowerOfTwo(i: int): int = if i < 1: return 1 @@ -178,5 +193,3 @@ asyncchecksuite "Slot builder": # 1 pad block slotTree.getLeafCid(numberOfSlotBlocks).tryget() == expectedEmptyCid - -