mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-10 19:06:28 +00:00
52c5578c46
* rework merkle tree support * deps * rename merkletree -> codexmerkletree * treed and proof encoding/decoding * small change to invoke proof verification * rename merkletree to codexmerkletree * style * adding codex merkle and coders tests * fixup imports * remove new codecs for now * bump deps * adding trace statement * properly serde of manifest block codecs * use default hash codec * add more trace logging to aid debugging * misc * remove double import * revert un-needded change * proof size changed * bump poseidon2 * add from nodes test * shorte file names * remove upraises * wip poseidon tree * adjust file names * misc * shorten file names * fix bad `elements` iter * don't do asserts * add fromNodes and converters * root and getProof now return result * add poseidon2 tree tests * root now returns result * misc * had to make merkletree a ref, because nim blows up otherwise * root returns a result * root returns a result * import poseidon tests * bump * merkle poseidon2 digest * misc * add merkle digest tests * bump * don't use checksuite * Update tests/codex/merkletree/generictreetests.nim Co-authored-by: markspanbroek <mark@spanbroek.net> Signed-off-by: Dmitriy Ryajov <dryajov@gmail.com> * Update codex/merkletree/merkletree.nim Co-authored-by: markspanbroek <mark@spanbroek.net> Signed-off-by: Dmitriy Ryajov <dryajov@gmail.com> * Update codex/merkletree/merkletree.nim Co-authored-by: markspanbroek <mark@spanbroek.net> Signed-off-by: Dmitriy Ryajov <dryajov@gmail.com> * Update tests/codex/merkletree/generictreetests.nim Co-authored-by: markspanbroek <mark@spanbroek.net> Signed-off-by: Dmitriy Ryajov <dryajov@gmail.com> * missing return * make toBool private (it's still needed otherwise comparison won't work) * added `digestTree` that returns a tree and `digest` for root * test against both poseidon trees - codex and poseidon2 * shorten merkle tree names * don't compare trees - it's going to be too slow * move comparison to mekrle helper * remove merkle utils --------- Signed-off-by: Dmitriy Ryajov <dryajov@gmail.com> Co-authored-by: markspanbroek <mark@spanbroek.net>
50 lines
1.6 KiB
Nim
50 lines
1.6 KiB
Nim
## Nim-Codex
|
|
## Copyright (c) 2022 Status Research & Development GmbH
|
|
## Licensed under either of
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
## at your option.
|
|
## This file may not be copied, modified, or distributed except according to
|
|
## those terms.
|
|
|
|
import pkg/upraises
|
|
push: {.upraises: [].}
|
|
|
|
import std/sugar
|
|
import pkg/questionable/results
|
|
import pkg/datastore
|
|
import pkg/libp2p
|
|
import ../namespaces
|
|
import ../manifest
|
|
|
|
const
|
|
CodexMetaKey* = Key.init(CodexMetaNamespace).tryGet
|
|
CodexRepoKey* = Key.init(CodexRepoNamespace).tryGet
|
|
CodexBlocksKey* = Key.init(CodexBlocksNamespace).tryGet
|
|
CodexTotalBlocksKey* = Key.init(CodexBlockTotalNamespace).tryGet
|
|
CodexManifestKey* = Key.init(CodexManifestNamespace).tryGet
|
|
BlocksTtlKey* = Key.init(CodexBlocksTtlNamespace).tryGet
|
|
BlockProofKey* = Key.init(CodexBlockProofNamespace).tryGet
|
|
QuotaKey* = Key.init(CodexQuotaNamespace).tryGet
|
|
QuotaUsedKey* = (QuotaKey / "used").tryGet
|
|
QuotaReservedKey* = (QuotaKey / "reserved").tryGet
|
|
|
|
func makePrefixKey*(postFixLen: int, cid: Cid): ?!Key =
|
|
let
|
|
cidKey = ? Key.init(($cid)[^postFixLen..^1] & "/" & $cid)
|
|
|
|
if ? cid.isManifest:
|
|
success CodexManifestKey / cidKey
|
|
else:
|
|
success CodexBlocksKey / cidKey
|
|
|
|
proc createBlockExpirationMetadataKey*(cid: Cid): ?!Key =
|
|
BlocksTtlKey / $cid
|
|
|
|
proc createBlockExpirationMetadataQueryKey*(): ?!Key =
|
|
let queryString = ? (BlocksTtlKey / "*")
|
|
Key.init(queryString)
|
|
|
|
proc createBlockCidAndProofMetadataKey*(treeCid: Cid, index: Natural): ?!Key =
|
|
(BlockProofKey / $treeCid).flatMap((k: Key) => k / $index)
|