Use correct blocks count in builder (#709)
This commit is contained in:
parent
3fce267352
commit
0497114e44
|
@ -531,11 +531,14 @@ proc onStore(
|
|||
return success()
|
||||
|
||||
without indexer =? manifest.protectedStrategy.init(
|
||||
0, manifest.blocksCount() - 1, manifest.numSlots).catch and
|
||||
blksIter =? indexer.getIndicies(slotIdx).catch, err:
|
||||
0, manifest.numSlotBlocks() - 1, manifest.numSlots).catch, err:
|
||||
trace "Unable to create indexing strategy from protected manifest", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
without blksIter =? indexer.getIndicies(slotIdx).catch, err:
|
||||
trace "Unable to get indicies from strategy", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
if err =? (await self.fetchBatched(
|
||||
manifest.treeCid,
|
||||
blksIter,
|
||||
|
|
|
@ -331,26 +331,36 @@ proc new*[T, H](
|
|||
return failure("Block size must be divisable by cell size.")
|
||||
|
||||
let
|
||||
numSlotBlocks = manifest.numSlotBlocks
|
||||
numBlockCells = (manifest.blockSize div cellSize).int # number of cells per block
|
||||
numSlotCells = manifest.numSlotBlocks * numBlockCells # number of uncorrected slot cells
|
||||
pow2SlotCells = nextPowerOfTwo(numSlotCells) # pow2 cells per slot
|
||||
numPadSlotBlocks = pow2SlotCells div numBlockCells # pow2 blocks per slot
|
||||
numPadBlocksTotal = numPadSlotBlocks * manifest.numSlots # total number of pad blocks
|
||||
numPadSlotBlocks = (pow2SlotCells div numBlockCells) - numSlotBlocks # pow2 blocks per slot
|
||||
|
||||
numSlotBlocksTotal = # pad blocks per slot
|
||||
if numPadSlotBlocks > 0:
|
||||
numPadSlotBlocks + numSlotBlocks
|
||||
else:
|
||||
numSlotBlocks
|
||||
|
||||
numBlocksTotal = numSlotBlocksTotal * manifest.numSlots # number of blocks per slot
|
||||
|
||||
emptyBlock = newSeq[byte](manifest.blockSize.int)
|
||||
emptyDigestTree = ? T.digestTree(emptyBlock, cellSize.int)
|
||||
|
||||
strategy = ? strategy.init(
|
||||
0,
|
||||
numPadBlocksTotal - 1,
|
||||
numBlocksTotal - 1,
|
||||
manifest.numSlots).catch
|
||||
|
||||
logScope:
|
||||
numSlotBlocks = numSlotBlocks
|
||||
numBlockCells = numBlockCells
|
||||
numSlotCells = numSlotCells
|
||||
pow2SlotCells = pow2SlotCells
|
||||
numPadSlotBlocks = numPadSlotBlocks
|
||||
numPadBlocksTotal = numPadBlocksTotal
|
||||
numBlocksTotal = numBlocksTotal
|
||||
numSlotBlocksTotal = numSlotBlocksTotal
|
||||
strategy = strategy.strategyType
|
||||
|
||||
trace "Creating slots builder"
|
||||
|
@ -362,7 +372,7 @@ proc new*[T, H](
|
|||
strategy: strategy,
|
||||
cellSize: cellSize,
|
||||
emptyBlock: emptyBlock,
|
||||
numSlotBlocks: numPadSlotBlocks,
|
||||
numSlotBlocks: numSlotBlocksTotal,
|
||||
emptyDigestTree: emptyDigestTree)
|
||||
|
||||
if manifest.verifiable:
|
||||
|
|
|
@ -128,10 +128,10 @@ asyncchecksuite "Test Node - Host contracts":
|
|||
return success()
|
||||
|
||||
(await onStore(request, 1.u256, onBlocks)).tryGet()
|
||||
check fetchedBytes == 851968
|
||||
check fetchedBytes == 262144
|
||||
|
||||
let indexer = verifiable.protectedStrategy.init(
|
||||
0, verifiable.blocksCount - 1, verifiable.numSlots)
|
||||
0, verifiable.numSlotBlocks() - 1, verifiable.numSlots)
|
||||
|
||||
for index in indexer.getIndicies(1):
|
||||
let
|
||||
|
|
|
@ -43,18 +43,25 @@ suite "Slot builder":
|
|||
ecM = 2
|
||||
|
||||
numSlots = ecK + ecM
|
||||
numDatasetBlocks = 50
|
||||
numDatasetBlocks = 8
|
||||
numTotalBlocks = calcEcBlocksCount(numDatasetBlocks, ecK, ecM) # total number of blocks in the dataset after
|
||||
# EC (should will match number of slots)
|
||||
originalDatasetSize = numDatasetBlocks * blockSize.int
|
||||
totalDatasetSize = numTotalBlocks * blockSize.int
|
||||
|
||||
numSlotBlocks = numTotalBlocks div numSlots
|
||||
numBlockCells = (blockSize div cellSize).int # number of cells per block
|
||||
numSlotBlocks = numTotalBlocks div numSlots # number of blocks per slot
|
||||
numSlotCells = numSlotBlocks * numBlockCells # number of uncorrected slot cells
|
||||
pow2SlotCells = nextPowerOfTwo(numSlotCells) # pow2 cells per slot
|
||||
numPadSlotBlocks = pow2SlotCells div numBlockCells # pow2 blocks per slot
|
||||
numPadBlocksTotal = numPadSlotBlocks * numSlots # total number of pad blocks
|
||||
numPadSlotBlocks = (pow2SlotCells div numBlockCells) - numSlotBlocks # pow2 blocks per slot
|
||||
|
||||
numSlotBlocksTotal = # pad blocks per slot
|
||||
if numPadSlotBlocks > 0:
|
||||
numPadSlotBlocks + numSlotBlocks
|
||||
else:
|
||||
numSlotBlocks
|
||||
|
||||
numBlocksTotal = numSlotBlocksTotal * numSlots
|
||||
|
||||
# empty digest
|
||||
emptyDigest = SpongeMerkle.digest(newSeq[byte](blockSize.int), cellSize.int)
|
||||
|
@ -157,30 +164,30 @@ suite "Slot builder":
|
|||
builder.cellSize == cellSize
|
||||
builder.numSlots == numSlots
|
||||
builder.numBlockCells == numBlockCells
|
||||
builder.numSlotBlocks == numPadSlotBlocks
|
||||
builder.numSlotBlocks == numSlotBlocksTotal
|
||||
builder.numSlotCells == pow2SlotCells
|
||||
builder.numBlocks == numPadBlocksTotal
|
||||
builder.numBlocks == numBlocksTotal
|
||||
|
||||
test "Should build slot hashes for all slots":
|
||||
let
|
||||
steppedStrategy = Strategy.init(
|
||||
0, numPadBlocksTotal - 1, numSlots)
|
||||
0, numBlocksTotal - 1, numSlots)
|
||||
|
||||
builder = Poseidon2Builder.new(
|
||||
localStore,
|
||||
protectedManifest,
|
||||
cellSize = cellSize).tryGet()
|
||||
|
||||
# for i in 0..<numSlots:
|
||||
for i in 0..<numSlots:
|
||||
let
|
||||
expectedHashes = collect(newSeq):
|
||||
for j, idx in steppedStrategy.getIndicies(0):
|
||||
for j, idx in steppedStrategy.getIndicies(i):
|
||||
if j > (protectedManifest.numSlotBlocks - 1):
|
||||
emptyDigest
|
||||
else:
|
||||
SpongeMerkle.digest(datasetBlocks[idx].data, cellSize.int)
|
||||
|
||||
cellHashes = (await builder.getCellHashes(0)).tryGet()
|
||||
cellHashes = (await builder.getCellHashes(i)).tryGet()
|
||||
|
||||
check:
|
||||
cellHashes.len == expectedHashes.len
|
||||
|
@ -189,7 +196,7 @@ suite "Slot builder":
|
|||
test "Should build slot trees for all slots":
|
||||
let
|
||||
steppedStrategy = Strategy.init(
|
||||
0, numPadBlocksTotal - 1, numSlots)
|
||||
0, numBlocksTotal - 1, numSlots)
|
||||
|
||||
builder = Poseidon2Builder.new(
|
||||
localStore,
|
||||
|
@ -237,7 +244,7 @@ suite "Slot builder":
|
|||
|
||||
test "Should build correct verification root":
|
||||
let
|
||||
steppedStrategy = Strategy.init(0, numPadBlocksTotal - 1, numSlots)
|
||||
steppedStrategy = Strategy.init(0, numBlocksTotal - 1, numSlots)
|
||||
builder = Poseidon2Builder.new(
|
||||
localStore,
|
||||
protectedManifest,
|
||||
|
@ -265,7 +272,7 @@ suite "Slot builder":
|
|||
|
||||
test "Should build correct verification root manifest":
|
||||
let
|
||||
steppedStrategy = Strategy.init(0, numPadBlocksTotal - 1, numSlots)
|
||||
steppedStrategy = Strategy.init(0, numBlocksTotal - 1, numSlots)
|
||||
builder = Poseidon2Builder.new(
|
||||
localStore,
|
||||
protectedManifest,
|
||||
|
|
Loading…
Reference in New Issue