From 3fce267352b1bee91dac4c0a3512ef9325c90d55 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sun, 18 Feb 2024 20:10:16 -0600 Subject: [PATCH] Block and manifest as objects (#708) * make block and manifest objects * use unsafeAddr since block is an object type now * make object var --- codex/blocktype.nim | 13 ++++++------- codex/manifest/manifest.nim | 4 ++-- codex/streams/storestream.nim | 2 +- tests/codex/slots/testslotbuilder.nim | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/codex/blocktype.nim b/codex/blocktype.nim index f74295a3..dd3b70e0 100644 --- a/codex/blocktype.nim +++ b/codex/blocktype.nim @@ -31,7 +31,7 @@ import ./codextypes export errors, logutils, units, codextypes type - Block* = ref object of RootObj + Block* = object of RootObj cid*: Cid data*: seq[byte] @@ -86,12 +86,11 @@ proc `$`*(b: Block): string = result &= "\ndata: " & string.fromBytes(b.data) func new*( - T: type Block, - data: openArray[byte] = [], - version = CIDv1, - mcodec = Sha256HashCodec, - codec = BlockCodec -): ?!Block = + T: type Block, + data: openArray[byte] = [], + version = CIDv1, + mcodec = Sha256HashCodec, + codec = BlockCodec): ?!Block = ## creates a new block for both storage and network IO ## diff --git a/codex/manifest/manifest.nim b/codex/manifest/manifest.nim index 922a1062..486a8fc3 100644 --- a/codex/manifest/manifest.nim +++ b/codex/manifest/manifest.nim @@ -29,7 +29,7 @@ import ../logutils # TODO: Manifest should be reworked to more concrete types, # perhaps using inheritance type - Manifest* = ref object of RootObj + Manifest* = object of RootObj treeCid {.serialize.}: Cid # Root of the merkle tree datasetSize {.serialize.}: NBytes # Total size of all blocks blockSize {.serialize.}: NBytes # Size of each contained block (might not be needed if blocks are len-prefixed) @@ -148,7 +148,7 @@ func rounded*(self: Manifest): int = func steps*(self: Manifest): int = ## Number of EC groups in *protected* manifest - divUp(self.originalBlocksCount, self.ecK) + divUp(self.rounded, self.ecK) func verify*(self: Manifest): ?!void = ## Check manifest correctness diff --git a/codex/streams/storestream.nim b/codex/streams/storestream.nim index d3b8c036..a20921dd 100644 --- a/codex/streams/storestream.nim +++ b/codex/streams/storestream.nim @@ -110,7 +110,7 @@ method readOnce*( if blk.isEmpty: zeroMem(pbytes.offset(read), readBytes) else: - copyMem(pbytes.offset(read), blk.data[blockOffset].addr, readBytes) + copyMem(pbytes.offset(read), blk.data[blockOffset].unsafeAddr, readBytes) # Update current positions in the stream and outbuf self.offset += readBytes diff --git a/tests/codex/slots/testslotbuilder.nim b/tests/codex/slots/testslotbuilder.nim index 5f4e65d4..08bb7f24 100644 --- a/tests/codex/slots/testslotbuilder.nim +++ b/tests/codex/slots/testslotbuilder.nim @@ -331,8 +331,8 @@ suite "Slot builder": protectedManifest, cellSize = cellSize).tryGet() + var verifyManifest = (await builder.buildManifest()).tryGet() - offset = verifyManifest.verifyRoot.data.buffer.len div 2 rng.shuffle( Rng.instance,