import std/sequtils import std/math import std/importutils import std/sugar import pkg/chronos import pkg/questionable/results import pkg/codex/blocktype as bt import pkg/codex/rng import pkg/codex/stores import pkg/codex/chunker import pkg/codex/merkletree import pkg/codex/manifest {.all.} import pkg/codex/utils import pkg/codex/utils/digest import pkg/datastore import pkg/poseidon2 import pkg/poseidon2/io import constantine/math/io/io_fields import ../../asynctest import ../helpers import ../examples import ../merkletree/helpers import pkg/codex/indexingstrategy {.all.} import pkg/codex/slots {.all.} privateAccess(SlotsBuilder) # enable access to private fields privateAccess(Manifest) # enable access to private fields suite "Slot builder": let blockSize = NBytes 1024 cellSize = NBytes 64 ecK = 3 ecM = 2 numSlots = ecK + ecM numDatasetBlocks = 100 numBlockCells = (blockSize div cellSize).int numTotalBlocks = calcEcBlocksCount(numDatasetBlocks, ecK, ecM) # total number of blocks in the dataset after # EC (should will match number of slots) originalDatasetSize = numDatasetBlocks * blockSize.int # size of the dataset before EC totalDatasetSize = numTotalBlocks * blockSize.int # size of the dataset after EC numTotalSlotBlocks = nextPowerOfTwo(numTotalBlocks div numSlots) blockPadBytes = newSeq[byte](numBlockCells.nextPowerOfTwoPad * cellSize.int) # power of two padding for blocks slotsPadLeafs = newSeqWith((numTotalBlocks div numSlots).nextPowerOfTwoPad, Poseidon2Zero) # power of two padding for block roots rootsPadLeafs = newSeqWith(numSlots.nextPowerOfTwoPad, Poseidon2Zero) var datasetBlocks: seq[bt.Block] localStore: BlockStore manifest: Manifest protectedManifest: Manifest expectedEmptyCid: Cid slotBuilder: SlotsBuilder chunker: Chunker proc createBlocks(): Future[void] {.async.} = while true: let chunk = await chunker.getBytes() if chunk.len <= 0: break let blk = bt.Block.new(chunk).tryGet() datasetBlocks.add(blk) discard await localStore.putBlock(blk) proc createProtectedManifest(): Future[void] {.async.} = let cids = datasetBlocks.mapIt(it.cid) datasetTree = CodexTree.init(cids[0..