From bbebc8554192cc655dd510a64f0234c1eccce3f0 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Wed, 2 Aug 2023 12:44:32 -0700 Subject: [PATCH] fixing blocktypes --- codex/blocktype.nim | 41 +++++++++++++++---------------------- codex/manifest/manifest.nim | 2 +- config.nims | 5 ++++- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/codex/blocktype.nim b/codex/blocktype.nim index a32db2da..b19a5b2f 100644 --- a/codex/blocktype.nim +++ b/codex/blocktype.nim @@ -63,31 +63,21 @@ proc emptyCid*(version: CidVersion, codex: MultiCodec): ?!Cid = var EmptyDigests {.threadvar.}: array[CIDv0..CIDv1, Table[MultiCodec, MultiHash]] -proc emptyDigest*(version: CidVersion, codex: MultiCodec): ?!MultiHash = +proc emptyDigest*(version: CidVersion, codec: MultiCodec): ?!MultiHash = + once: + let cid0 = emptyCid(CIDv0, multiCodec("sha2-256")).get() + let cid1 = emptyCid(CIDv1, multiCodec("sha2-256")).get() + let mhash0 = cid0.mhash.get + let mhash1 = cid1.mhash.get + EmptyDigests = [ - CIDv0: { - multiCodec("sha2-256"): EmptyCid[CIDv0] - .catch - .get()[multiCodec("sha2-256")] - .catch - .get() - .mhash - .get() - }.toTable, - CIDv1: { - multiCodec("sha2-256"): EmptyCid[CIDv1] - .catch - .get()[multiCodec("sha2-256")] - .catch - .get() - .mhash - .get() - }.toTable, + CIDv0: { multiCodec("sha2-256"): mhash0 }.toTable, + CIDv1: { multiCodec("sha2-256"): mhash1 }.toTable, ] try: - success EmptyDigests[version][codex] + success EmptyDigests[version][codec] except CatchableError as exc: err(exc) @@ -96,13 +86,14 @@ var proc emptyBlock*(version: CidVersion, codex: MultiCodec): ?!Block = once: - let cid = ? EmptyCid[CIDv0].catch - let sha2 = ? cid[multiCodec("sha2-256")].catch - let blk = Block(cid: sha2) + let cid0 = ? emptyCid(CIDv0, multiCodec("sha2-256")) + let cid1 = ? emptyCid(CIDv1, multiCodec("sha2-256")) + let blk0 = Block(cid: cid0) + let blk1 = Block(cid: cid1) EmptyBlock = [ - CIDv0: { multiCodec("sha2-256"): blk }.toTable, - CIDv1: { multiCodec("sha2-256"): blk }.toTable, + CIDv0: { multiCodec("sha2-256"): blk0 }.toTable, + CIDv1: { multiCodec("sha2-256"): blk1 }.toTable, ] try: diff --git a/codex/manifest/manifest.nim b/codex/manifest/manifest.nim index c7616102..56b55215 100644 --- a/codex/manifest/manifest.nim +++ b/codex/manifest/manifest.nim @@ -190,7 +190,7 @@ proc makeRoot*(self: Manifest): ?!void = stack.add(mh) if stack.len == 1: - let digest = ? emptyDigest(self.version, self.hcodec) + let digest = emptyDigest(self.version, self.hcodec).expect("empty manifest") let cid = ? Cid.init(self.version, self.codec, digest).mapFailure self.rootHash = cid.some diff --git a/config.nims b/config.nims index e9239546..f94f5d70 100644 --- a/config.nims +++ b/config.nims @@ -63,7 +63,10 @@ else: # ("-fno-asynchronous-unwind-tables" breaks Nim's exception raising, sometimes) switch("passC", "-mno-avx512vl") -# --gc:orc +when getEnv("CODEX_USE_ORC", "") in ["true", "1"]: + --mm:orc + --deepcopy:on + --tlsEmulation:off --threads:on --opt:speed