bech codexTree

This commit is contained in:
munna0908 2025-03-21 12:24:16 +05:30
parent 94ce22ba06
commit d6876227d1
No known key found for this signature in database
GPG Key ID: 2FFCD637E937D3E6
2 changed files with 16 additions and 3 deletions

View File

@ -201,6 +201,10 @@ proc benchmarkGetCidAndProof(
discard (waitFor store.getCidAndProof(treeCid, i)).tryGet()
i += 1
proc benchmarkCodexTree(cids: seq[Cid], benchmarkLoops: int) =
benchmark "codex_tree", benchmarkLoops:
discard CodexTree.init(cids).tryGet()
template profileFunc(fn: untyped) =
enableProfiling()
`fn`
@ -217,11 +221,13 @@ proc benchmarkRepoStore(store: RepoStore) =
var
blcks = newSeq[bt.Block]()
cids = newSeq[Cid]()
proofs = newSeq[CodexProof]()
for i in 0 ..< benchmarkLoops:
var blk = createTestBlock(testDataLen.int)
blcks.add(blk)
cids.add(blk.cid)
let (manifest, tree) = makeManifestAndTree(blcks).tryGet()
let treeCid = tree.rootCid.tryGet()
@ -245,6 +251,8 @@ proc benchmarkRepoStore(store: RepoStore) =
benchmarkPut(store, blcks, benchmarkLoops)
benchmarkDel(store, blcks, benchmarkLoops)
benchmarkCodexTree(cids, benchmarkLoops)
proc benchStore(store: RepoStore, node: CodexNodeRef, file: File) =
benchmark "store", 1:
let

View File

@ -15,6 +15,7 @@ import std/sequtils
import pkg/questionable
import pkg/questionable/results
import pkg/libp2p/[cid, multicodec, multihash]
import pkg/constantine/hashes
import ../../utils
import ../../rng
@ -132,9 +133,13 @@ func compress*(x, y: openArray[byte], key: ByteTreeKey, mhash: MHash): ?!ByteHas
## Compress two hashes
##
var digest = newSeq[byte](mhash.size)
mhash.coder(@x & @y & @[key.byte], digest)
success digest
# var digest = newSeq[byte](mhash.size)
# #mhash.coder(@x & @y & @[key.byte], digest)
let input = @x & @y & @[key.byte]
var digest = hashes.sha256.hash(input)
success @digest
func init*(
_: type CodexTree, mcodec: MultiCodec = Sha256HashCodec, leaves: openArray[ByteHash]