mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-02 18:33:10 +00:00
formatting
This commit is contained in:
parent
e3937c69a9
commit
026c26a2fb
@ -853,7 +853,8 @@ proc localLookup(
|
||||
)
|
||||
else:
|
||||
(await self.localStore.getBlock(address)).map(
|
||||
(blk: Block) => BlockDelivery(address: address, blk: blk, proof: StorageMerkleProof.none)
|
||||
(blk: Block) =>
|
||||
BlockDelivery(address: address, blk: blk, proof: StorageMerkleProof.none)
|
||||
)
|
||||
|
||||
iterator splitBatches[T](sequence: seq[T], batchSize: int): seq[T] =
|
||||
|
||||
@ -201,7 +201,8 @@ proc decode*(_: type BlockDelivery, pb: ProtoBuffer): ProtoResult[BlockDelivery]
|
||||
if value.address.leaf:
|
||||
var proofBuf = newSeq[byte]()
|
||||
if ?pb.getField(4, proofBuf):
|
||||
let proof = ?StorageMerkleProof.decode(proofBuf).mapErr(x => ProtoError.IncorrectBlob)
|
||||
let proof =
|
||||
?StorageMerkleProof.decode(proofBuf).mapErr(x => ProtoError.IncorrectBlob)
|
||||
value.proof = proof.some
|
||||
else:
|
||||
value.proof = StorageMerkleProof.none
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import ./merkletree/merkletree
|
||||
import ./merkletree/coders
|
||||
|
||||
export merkletree, coders
|
||||
export merkletree, coders
|
||||
|
||||
@ -26,7 +26,6 @@ import ../codextypes
|
||||
|
||||
from ../utils/digest import digestBytes
|
||||
|
||||
|
||||
export merkletree
|
||||
|
||||
logScope:
|
||||
@ -75,7 +74,9 @@ func verify*(self: StorageMerkleProof, leaf: MultiHash, root: MultiHash): ?!bool
|
||||
func verify*(self: StorageMerkleProof, leaf: Cid, root: Cid): ?!bool =
|
||||
self.verify(?leaf.mhash.mapFailure, ?leaf.mhash.mapFailure)
|
||||
|
||||
proc rootCid*(self: StorageMerkleTree, version = CIDv1, dataCodec = DatasetRootCodec): ?!Cid =
|
||||
proc rootCid*(
|
||||
self: StorageMerkleTree, version = CIDv1, dataCodec = DatasetRootCodec
|
||||
): ?!Cid =
|
||||
if (?self.root).len == 0:
|
||||
return failure "Empty root"
|
||||
|
||||
@ -101,12 +102,13 @@ proc `$`*(self: StorageMerkleTree): string =
|
||||
byteutils.toHex(self.root.get)
|
||||
else:
|
||||
"none"
|
||||
"StorageMerkleTree(" & " root: " & root & ", leavesCount: " & $self.leavesCount & ", levels: " &
|
||||
$self.levels & ", mcodec: " & $self.mcodec & " )"
|
||||
"StorageMerkleTree(" & " root: " & root & ", leavesCount: " & $self.leavesCount &
|
||||
", levels: " & $self.levels & ", mcodec: " & $self.mcodec & " )"
|
||||
|
||||
proc `$`*(self: StorageMerkleProof): string =
|
||||
"StorageMerkleProof(" & " nleaves: " & $self.nleaves & ", index: " & $self.index & ", path: " &
|
||||
$self.path.mapIt(byteutils.toHex(it)) & ", mcodec: " & $self.mcodec & " )"
|
||||
"StorageMerkleProof(" & " nleaves: " & $self.nleaves & ", index: " & $self.index &
|
||||
", path: " & $self.path.mapIt(byteutils.toHex(it)) & ", mcodec: " & $self.mcodec &
|
||||
" )"
|
||||
|
||||
func compress*(x, y: openArray[byte], key: ByteTreeKey, codec: MultiCodec): ?!ByteHash =
|
||||
## Compress two hashes
|
||||
@ -133,7 +135,9 @@ func initTree(mcodec: MultiCodec, leaves: openArray[ByteHash]): ?!StorageMerkleT
|
||||
success self
|
||||
|
||||
func init*(
|
||||
_: type StorageMerkleTree, mcodec: MultiCodec = Sha256HashCodec, leaves: openArray[ByteHash]
|
||||
_: type StorageMerkleTree,
|
||||
mcodec: MultiCodec = Sha256HashCodec,
|
||||
leaves: openArray[ByteHash],
|
||||
): ?!StorageMerkleTree =
|
||||
let tree = ?initTree(mcodec, leaves)
|
||||
?tree.compute()
|
||||
@ -149,7 +153,9 @@ proc init*(
|
||||
?await tree.compute(tp)
|
||||
success tree
|
||||
|
||||
func init*(_: type StorageMerkleTree, leaves: openArray[MultiHash]): ?!StorageMerkleTree =
|
||||
func init*(
|
||||
_: type StorageMerkleTree, leaves: openArray[MultiHash]
|
||||
): ?!StorageMerkleTree =
|
||||
if leaves.len == 0:
|
||||
return failure "Empty leaves"
|
||||
|
||||
|
||||
@ -80,7 +80,9 @@ method getBlocks*(
|
||||
|
||||
method getBlockAndProof*(
|
||||
self: BlockStore, treeCid: Cid, index: Natural
|
||||
): Future[?!(Block, StorageMerkleProof)] {.base, async: (raises: [CancelledError]), gcsafe.} =
|
||||
): Future[?!(Block, StorageMerkleProof)] {.
|
||||
base, async: (raises: [CancelledError]), gcsafe
|
||||
.} =
|
||||
## Get a block and associated inclusion proof by Cid of a merkle tree and an index of a leaf in a tree
|
||||
##
|
||||
|
||||
@ -95,7 +97,11 @@ method putBlock*(
|
||||
raiseAssert("putBlock not implemented!")
|
||||
|
||||
method putCidAndProof*(
|
||||
self: BlockStore, treeCid: Cid, index: Natural, blockCid: Cid, proof: StorageMerkleProof
|
||||
self: BlockStore,
|
||||
treeCid: Cid,
|
||||
index: Natural,
|
||||
blockCid: Cid,
|
||||
proof: StorageMerkleProof,
|
||||
): Future[?!void] {.base, async: (raises: [CancelledError]), gcsafe.} =
|
||||
## Put a block proof to the blockstore
|
||||
##
|
||||
@ -104,7 +110,9 @@ method putCidAndProof*(
|
||||
|
||||
method getCidAndProof*(
|
||||
self: BlockStore, treeCid: Cid, index: Natural
|
||||
): Future[?!(Cid, StorageMerkleProof)] {.base, async: (raises: [CancelledError]), gcsafe.} =
|
||||
): Future[?!(Cid, StorageMerkleProof)] {.
|
||||
base, async: (raises: [CancelledError]), gcsafe
|
||||
.} =
|
||||
## Get a block proof from the blockstore
|
||||
##
|
||||
|
||||
|
||||
@ -226,7 +226,11 @@ method putBlock*(
|
||||
return success()
|
||||
|
||||
method putCidAndProof*(
|
||||
self: CacheStore, treeCid: Cid, index: Natural, blockCid: Cid, proof: StorageMerkleProof
|
||||
self: CacheStore,
|
||||
treeCid: Cid,
|
||||
index: Natural,
|
||||
blockCid: Cid,
|
||||
proof: StorageMerkleProof,
|
||||
): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
self.cidAndProofCache[(treeCid, index)] = (blockCid, proof)
|
||||
success()
|
||||
|
||||
@ -104,7 +104,11 @@ method putBlock*(
|
||||
return success()
|
||||
|
||||
method putCidAndProof*(
|
||||
self: NetworkStore, treeCid: Cid, index: Natural, blockCid: Cid, proof: StorageMerkleProof
|
||||
self: NetworkStore,
|
||||
treeCid: Cid,
|
||||
index: Natural,
|
||||
blockCid: Cid,
|
||||
proof: StorageMerkleProof,
|
||||
): Future[?!void] {.async: (raw: true, raises: [CancelledError]).} =
|
||||
self.localStore.putCidAndProof(treeCid, index, blockCid, proof)
|
||||
|
||||
|
||||
@ -33,7 +33,11 @@ declareGauge(codex_repostore_bytes_used, "codex repostore bytes used")
|
||||
declareGauge(codex_repostore_bytes_reserved, "codex repostore bytes reserved")
|
||||
|
||||
proc putLeafMetadata*(
|
||||
self: RepoStore, treeCid: Cid, index: Natural, blkCid: Cid, proof: StorageMerkleProof
|
||||
self: RepoStore,
|
||||
treeCid: Cid,
|
||||
index: Natural,
|
||||
blkCid: Cid,
|
||||
proof: StorageMerkleProof,
|
||||
): Future[?!StoreResultKind] {.async: (raises: [CancelledError]).} =
|
||||
without key =? createBlockCidAndProofMetadataKey(treeCid, index), err:
|
||||
return failure(err)
|
||||
|
||||
@ -136,7 +136,11 @@ method ensureExpiry*(
|
||||
await self.ensureExpiry(leafMd.blkCid, expiry)
|
||||
|
||||
method putCidAndProof*(
|
||||
self: RepoStore, treeCid: Cid, index: Natural, blkCid: Cid, proof: StorageMerkleProof
|
||||
self: RepoStore,
|
||||
treeCid: Cid,
|
||||
index: Natural,
|
||||
blkCid: Cid,
|
||||
proof: StorageMerkleProof,
|
||||
): Future[?!void] {.async: (raises: [CancelledError]).} =
|
||||
## Put a block to the blockstore
|
||||
##
|
||||
|
||||
@ -8,7 +8,8 @@ import pkg/codex/rng
|
||||
|
||||
import ./randomchunker
|
||||
|
||||
type TestDataset* = tuple[blocks: seq[Block], tree: StorageMerkleTree, manifest: Manifest]
|
||||
type TestDataset* =
|
||||
tuple[blocks: seq[Block], tree: StorageMerkleTree, manifest: Manifest]
|
||||
|
||||
proc makeRandomBlock*(size: NBytes): Block =
|
||||
let bytes = newSeqWith(size.int, rand(uint8))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user