Test fixed, all working
This commit is contained in:
parent
2ad9b77899
commit
fb55e79649
|
@ -412,19 +412,6 @@ proc decode*(
|
||||||
finally:
|
finally:
|
||||||
decoder.release()
|
decoder.release()
|
||||||
|
|
||||||
without encodedTree =? MerkleTree.init(cids[]), err:
|
|
||||||
return failure(err)
|
|
||||||
|
|
||||||
without encodedTreeCid =? encodedTree.rootCid, err:
|
|
||||||
return failure(err)
|
|
||||||
|
|
||||||
if encodedTreeCid != encoded.treeCid:
|
|
||||||
return failure("Encoded tree root differs from the tree root computed out of recovered data")
|
|
||||||
|
|
||||||
let idxIter = Iter.fromItems(recoveredIndices)
|
|
||||||
if err =? (await self.store.putSomeProofs(encodedTree, idxIter)).errorOption:
|
|
||||||
return failure(err)
|
|
||||||
|
|
||||||
without tree =? MerkleTree.init(cids[0..<encoded.originalBlocksCount]), err:
|
without tree =? MerkleTree.init(cids[0..<encoded.originalBlocksCount]), err:
|
||||||
return failure(err)
|
return failure(err)
|
||||||
|
|
||||||
|
@ -434,7 +421,11 @@ proc decode*(
|
||||||
if treeCid != encoded.originalTreeCid:
|
if treeCid != encoded.originalTreeCid:
|
||||||
return failure("Original tree root differs from the tree root computed out of recovered data")
|
return failure("Original tree root differs from the tree root computed out of recovered data")
|
||||||
|
|
||||||
if err =? (await self.store.putSomeProofs(tree, idxIter.filter((i: int) => i < tree.leavesCount))).errorOption:
|
let idxIter = Iter
|
||||||
|
.fromItems(recoveredIndices)
|
||||||
|
.filter((i: int) => i < tree.leavesCount)
|
||||||
|
|
||||||
|
if err =? (await self.store.putSomeProofs(tree, idxIter)).errorOption:
|
||||||
return failure(err)
|
return failure(err)
|
||||||
|
|
||||||
let decoded = Manifest.new(encoded)
|
let decoded = Manifest.new(encoded)
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
import std/math
|
import std/math
|
||||||
import std/bitops
|
import std/bitops
|
||||||
import std/sequtils
|
import std/sequtils
|
||||||
|
import std/options
|
||||||
import std/sugar
|
import std/sugar
|
||||||
import std/algorithm
|
import std/algorithm
|
||||||
|
|
||||||
import pkg/chronicles
|
import pkg/chronicles
|
||||||
|
import pkg/questionable
|
||||||
import pkg/questionable/results
|
import pkg/questionable/results
|
||||||
import pkg/nimcrypto/sha2
|
import pkg/nimcrypto/sha2
|
||||||
import pkg/libp2p/[cid, multicodec, multihash, vbuffer]
|
import pkg/libp2p/[cid, multicodec, multihash, vbuffer]
|
||||||
|
@ -289,18 +291,6 @@ proc init*(
|
||||||
else:
|
else:
|
||||||
failure("Expected nodesBuffer len to be " & $(totalNodes * digestSize) & " but was " & $nodesBuffer.len)
|
failure("Expected nodesBuffer len to be " & $(totalNodes * digestSize) & " but was " & $nodesBuffer.len)
|
||||||
|
|
||||||
proc init*(
|
|
||||||
T: type MerkleTree,
|
|
||||||
cids: openArray[Cid]
|
|
||||||
): ?!MerkleTree =
|
|
||||||
let leaves = collect:
|
|
||||||
for cid in cids:
|
|
||||||
without mhash =? cid.mhash.mapFailure, errx:
|
|
||||||
return failure(errx)
|
|
||||||
mhash
|
|
||||||
|
|
||||||
MerkleTree.init(leaves)
|
|
||||||
|
|
||||||
proc init*(
|
proc init*(
|
||||||
T: type MerkleTree,
|
T: type MerkleTree,
|
||||||
leaves: openArray[MultiHash]
|
leaves: openArray[MultiHash]
|
||||||
|
@ -316,6 +306,18 @@ proc init*(
|
||||||
|
|
||||||
builder.build()
|
builder.build()
|
||||||
|
|
||||||
|
proc init*(
|
||||||
|
T: type MerkleTree,
|
||||||
|
cids: openArray[Cid]
|
||||||
|
): ?!MerkleTree =
|
||||||
|
let leaves = collect:
|
||||||
|
for idx, cid in cids:
|
||||||
|
without mhash =? cid.mhash.mapFailure, errx:
|
||||||
|
return failure(errx)
|
||||||
|
mhash
|
||||||
|
|
||||||
|
MerkleTree.init(leaves)
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
# MerkleProof
|
# MerkleProof
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
|
@ -21,7 +21,6 @@ import pkg/questionable
|
||||||
import pkg/questionable/results
|
import pkg/questionable/results
|
||||||
|
|
||||||
import ./blockstore
|
import ./blockstore
|
||||||
import ./treereader
|
|
||||||
import ../units
|
import ../units
|
||||||
import ../chunker
|
import ../chunker
|
||||||
import ../errors
|
import ../errors
|
||||||
|
@ -274,9 +273,6 @@ proc new*(
|
||||||
currentSize: currentSize,
|
currentSize: currentSize,
|
||||||
size: cacheSize)
|
size: cacheSize)
|
||||||
|
|
||||||
# proc getBlockFromStore(cid: Cid): Future[?!Block] = store.getBlock(cid)
|
|
||||||
# store.treeReader = TreeReader.new(getBlockFromStore)
|
|
||||||
|
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
discard store.putBlockSync(blk)
|
discard store.putBlockSync(blk)
|
||||||
|
|
||||||
|
|
|
@ -95,22 +95,23 @@ proc map*[T, U](iter: Iter[T], fn: Function[T, U]): Iter[U] =
|
||||||
)
|
)
|
||||||
|
|
||||||
proc filter*[T](iter: Iter[T], predicate: Function[T, bool]): Iter[T] =
|
proc filter*[T](iter: Iter[T], predicate: Function[T, bool]): Iter[T] =
|
||||||
var nextItem: T
|
var nextT: Option[T]
|
||||||
|
|
||||||
proc tryFetch(): void =
|
proc tryFetch(): void =
|
||||||
|
nextT = T.none
|
||||||
while not iter.finished:
|
while not iter.finished:
|
||||||
let item = iter.next()
|
let t = iter.next()
|
||||||
if predicate(item):
|
if predicate(t):
|
||||||
nextItem = item
|
nextT = some(t)
|
||||||
break
|
break
|
||||||
|
|
||||||
proc genNext(): T =
|
proc genNext(): T =
|
||||||
let t = nextItem
|
let t = nextT.unsafeGet
|
||||||
tryFetch()
|
tryFetch()
|
||||||
return t
|
return t
|
||||||
|
|
||||||
proc isFinished(): bool =
|
proc isFinished(): bool =
|
||||||
iter.finished
|
nextT.isNone
|
||||||
|
|
||||||
tryFetch()
|
tryFetch()
|
||||||
Iter.new(genNext, isFinished)
|
Iter.new(genNext, isFinished)
|
||||||
|
|
|
@ -58,20 +58,19 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
for _ in 0..<encoded.ecM:
|
for _ in 0..<encoded.ecM:
|
||||||
dropped.add(column)
|
dropped.add(column)
|
||||||
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, column)).tryGet()
|
||||||
column.inc(encoded.steps - 1)
|
column.inc(encoded.steps - 1)
|
||||||
|
|
||||||
echo $dropped
|
|
||||||
|
|
||||||
var
|
var
|
||||||
decoded = (await erasure.decode(encoded)).tryGet()
|
decoded = (await erasure.decode(encoded)).tryGet()
|
||||||
|
|
||||||
check:
|
check:
|
||||||
decoded.cid.tryGet() == manifest.cid.tryGet()
|
decoded.treeCid == manifest.treeCid
|
||||||
decoded.cid.tryGet() == encoded.originalCid
|
decoded.treeCid == encoded.originalCid
|
||||||
decoded.blocksCount == encoded.originalBlocksCount
|
decoded.blocksCount == encoded.originalBlocksCount
|
||||||
|
|
||||||
for d in dropped:
|
for d in dropped:
|
||||||
let present = await store.hasBlock(encoded.treeCid, d)
|
let present = await store.hasBlock(manifest.treeCid, d)
|
||||||
check present.tryGet()
|
check present.tryGet()
|
||||||
|
|
||||||
test "Should not tolerate losing more than M data blocks in a single random column":
|
test "Should not tolerate losing more than M data blocks in a single random column":
|
||||||
|
@ -88,6 +87,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
for _ in 0..<encoded.ecM + 1:
|
for _ in 0..<encoded.ecM + 1:
|
||||||
dropped.add(column)
|
dropped.add(column)
|
||||||
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, column)).tryGet()
|
||||||
column.inc(encoded.steps)
|
column.inc(encoded.steps)
|
||||||
|
|
||||||
var
|
var
|
||||||
|
@ -97,7 +97,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
decoded = (await erasure.decode(encoded)).tryGet()
|
decoded = (await erasure.decode(encoded)).tryGet()
|
||||||
|
|
||||||
for d in dropped:
|
for d in dropped:
|
||||||
let present = await store.hasBlock(encoded.treeCid, d)
|
let present = await store.hasBlock(manifest.treeCid, d)
|
||||||
check not present.tryGet()
|
check not present.tryGet()
|
||||||
|
|
||||||
test "Should tolerate losing M data blocks in M random columns":
|
test "Should tolerate losing M data blocks in M random columns":
|
||||||
|
@ -121,6 +121,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
|
|
||||||
for idx in blocks:
|
for idx in blocks:
|
||||||
(await store.delBlock(encoded.treeCid, idx)).tryGet()
|
(await store.delBlock(encoded.treeCid, idx)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, idx)).tryGet()
|
||||||
discard
|
discard
|
||||||
|
|
||||||
discard (await erasure.decode(encoded)).tryGet()
|
discard (await erasure.decode(encoded)).tryGet()
|
||||||
|
@ -157,6 +158,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
|
|
||||||
for idx in blocks:
|
for idx in blocks:
|
||||||
(await store.delBlock(encoded.treeCid, idx)).tryGet()
|
(await store.delBlock(encoded.treeCid, idx)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, idx)).tryGet()
|
||||||
discard
|
discard
|
||||||
|
|
||||||
var
|
var
|
||||||
|
@ -174,6 +176,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
|
|
||||||
for b in 0..<encoded.steps * encoded.ecM:
|
for b in 0..<encoded.steps * encoded.ecM:
|
||||||
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, b)).tryGet()
|
||||||
|
|
||||||
discard (await erasure.decode(encoded)).tryGet()
|
discard (await erasure.decode(encoded)).tryGet()
|
||||||
|
|
||||||
|
@ -190,6 +193,7 @@ asyncchecksuite "Erasure encode/decode":
|
||||||
|
|
||||||
for b in (encoded.blocksCount - encoded.steps * encoded.ecM)..<encoded.blocksCount:
|
for b in (encoded.blocksCount - encoded.steps * encoded.ecM)..<encoded.blocksCount:
|
||||||
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
||||||
|
(await store.delBlock(manifest.treeCid, b)).tryGet()
|
||||||
|
|
||||||
discard (await erasure.decode(encoded)).tryGet()
|
discard (await erasure.decode(encoded)).tryGet()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue