mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-15 07:25:21 +00:00
fffb674bba
* rework merkle tree support * rename merkletree -> codexmerkletree * treed and proof encoding/decoding * style * adding codex merkle and coders tests * use default hash codec * proof size changed * add from nodes test * shorte file names * wip poseidon tree * shorten file names * root returns a result * import poseidon tests * fix merge issues and cleanup a few warnings * setting up slot builder * Getting cids in slot * ensures blocks are devisable by number of slots * wip * Implements indexing strategies * Swaps in indexing strategy into erasure. * wires slot and indexing tests up * Fixes issue where indexing strategy stepped gives wrong values for smallest of ranges * debugs indexing strategies * Can select slot blocks * finding number of pad cells * Implements building slot tree * finishes implementing slot builder * Adds check that block size is a multiple of cell size * Cleanup slotbuilder * Review comments by Tomasz * Fixes issue where ecK was used as numberOfSlots. * rework merkle tree support * deps * rename merkletree -> codexmerkletree * treed and proof encoding/decoding * style * adding codex merkle and coders tests * remove new codecs for now * proof size changed * add from nodes test * shorte file names * wip poseidon tree * shorten file names * fix bad `elements` iter * bump * bump * wip * reworking slotbuilder * move out of manifest * expose getCidAndProof * import index strat... * remove getMHash * remove unused artifacts * alias zero * add digest for multihash * merge issues * remove unused hashes * add option to result converter * misc * fix tests * add helper to derive EC block count * rename method * misc * bump * extract slot root building into own proc * revert to manifest to accessor --------- Co-authored-by: benbierens <thatbenbierens@gmail.com>
168 lines
4.5 KiB
Nim
168 lines
4.5 KiB
Nim
## Nim-Codex
|
|
## Copyright (c) 2021 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 pkg/chronos
|
|
import pkg/libp2p
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
import ../clock
|
|
import ../blocktype
|
|
import ../merkletree
|
|
import ../utils
|
|
|
|
export blocktype
|
|
|
|
type
|
|
BlockNotFoundError* = object of CodexError
|
|
|
|
BlockType* {.pure.} = enum
|
|
Manifest, Block, Both
|
|
|
|
BlockStore* = ref object of RootObj
|
|
|
|
method getBlock*(self: BlockStore, cid: Cid): Future[?!Block] {.base.} =
|
|
## Get a block from the blockstore
|
|
##
|
|
|
|
raiseAssert("getBlock by cid not implemented!")
|
|
|
|
method getBlock*(self: BlockStore, treeCid: Cid, index: Natural): Future[?!Block] {.base.} =
|
|
## Get a block from the blockstore
|
|
##
|
|
|
|
raiseAssert("getBlock by treecid not implemented!")
|
|
|
|
method getCid*(self: BlockStore, treeCid: Cid, index: Natural): Future[?!Cid] {.base.} =
|
|
## Get a cid given a tree and index
|
|
##
|
|
raiseAssert("getCid by treecid not implemented!")
|
|
|
|
method getBlock*(self: BlockStore, address: BlockAddress): Future[?!Block] {.base.} =
|
|
## Get a block from the blockstore
|
|
##
|
|
|
|
raiseAssert("getBlock by addr not implemented!")
|
|
|
|
method getBlockAndProof*(self: BlockStore, treeCid: Cid, index: Natural): Future[?!(Block, CodexProof)] {.base.} =
|
|
## Get a block and associated inclusion proof by Cid of a merkle tree and an index of a leaf in a tree
|
|
##
|
|
|
|
raiseAssert("getBlockAndProof not implemented!")
|
|
|
|
method putBlock*(
|
|
self: BlockStore,
|
|
blk: Block,
|
|
ttl = Duration.none
|
|
): Future[?!void] {.base.} =
|
|
## Put a block to the blockstore
|
|
##
|
|
|
|
raiseAssert("putBlock not implemented!")
|
|
|
|
method putCidAndProof*(
|
|
self: BlockStore,
|
|
treeCid: Cid,
|
|
index: Natural,
|
|
blockCid: Cid,
|
|
proof: CodexProof
|
|
): Future[?!void] {.base.} =
|
|
## Put a block proof to the blockstore
|
|
##
|
|
|
|
raiseAssert("putCidAndProof not implemented!")
|
|
|
|
method getCidAndProof*(
|
|
self: BlockStore,
|
|
treeCid: Cid,
|
|
index: Natural): Future[?!(Cid, CodexProof)] {.base.} =
|
|
## Get a block proof from the blockstore
|
|
##
|
|
|
|
raiseAssert("putCidAndProof not implemented!")
|
|
|
|
method ensureExpiry*(
|
|
self: BlockStore,
|
|
cid: Cid,
|
|
expiry: SecondsSince1970
|
|
): Future[?!void] {.base.} =
|
|
## Ensure that block's assosicated expiry is at least given timestamp
|
|
## If the current expiry is lower then it is updated to the given one, otherwise it is left intact
|
|
##
|
|
|
|
raiseAssert("Not implemented!")
|
|
|
|
method ensureExpiry*(
|
|
self: BlockStore,
|
|
treeCid: Cid,
|
|
index: Natural,
|
|
expiry: SecondsSince1970
|
|
): Future[?!void] {.base.} =
|
|
## Ensure that block's associated expiry is at least given timestamp
|
|
## If the current expiry is lower then it is updated to the given one, otherwise it is left intact
|
|
##
|
|
|
|
raiseAssert("Not implemented!")
|
|
|
|
method delBlock*(self: BlockStore, cid: Cid): Future[?!void] {.base.} =
|
|
## Delete a block from the blockstore
|
|
##
|
|
|
|
raiseAssert("delBlock not implemented!")
|
|
|
|
method delBlock*(self: BlockStore, treeCid: Cid, index: Natural): Future[?!void] {.base.} =
|
|
## Delete a block from the blockstore
|
|
##
|
|
|
|
raiseAssert("delBlock not implemented!")
|
|
|
|
method hasBlock*(self: BlockStore, cid: Cid): Future[?!bool] {.base.} =
|
|
## Check if the block exists in the blockstore
|
|
##
|
|
|
|
raiseAssert("hasBlock not implemented!")
|
|
|
|
method hasBlock*(self: BlockStore, tree: Cid, index: Natural): Future[?!bool] {.base.} =
|
|
## Check if the block exists in the blockstore
|
|
##
|
|
|
|
raiseAssert("hasBlock not implemented!")
|
|
|
|
method listBlocks*(
|
|
self: BlockStore,
|
|
blockType = BlockType.Manifest): Future[?!AsyncIter[?Cid]] {.base.} =
|
|
## Get the list of blocks in the BlockStore. This is an intensive operation
|
|
##
|
|
|
|
raiseAssert("listBlocks not implemented!")
|
|
|
|
method close*(self: BlockStore): Future[void] {.base.} =
|
|
## Close the blockstore, cleaning up resources managed by it.
|
|
## For some implementations this may be a no-op
|
|
##
|
|
|
|
raiseAssert("close not implemented!")
|
|
|
|
proc contains*(self: BlockStore, blk: Cid): Future[bool] {.async.} =
|
|
## Check if the block exists in the blockstore.
|
|
## Return false if error encountered
|
|
##
|
|
|
|
return (await self.hasBlock(blk)) |? false
|
|
|
|
proc contains*(self: BlockStore, address: BlockAddress): Future[bool] {.async.} =
|
|
return if address.leaf:
|
|
(await self.hasBlock(address.treeCid, address.index)) |? false
|
|
else:
|
|
(await self.hasBlock(address.cid)) |? false
|