Skip to content

Commit b566f56

Browse files
committed
Replaces verification hash placeholder with CID
1 parent 9a5e0b4 commit b566f56

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

codex/manifest/coders.nim

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ proc encode*(_: DagPBCoder, manifest: Manifest): ?!seq[byte] =
7272

7373
if manifest.verifiable:
7474
var verificationInfo = initProtoBuffer()
75-
verificationInfo.write(1, manifest.verificationRoot.encode())
75+
verificationInfo.write(1, manifest.verificationRoot.data.buffer)
7676
for slotRoot in manifest.slotRoots:
77-
verificationInfo.write(2, slotRoot.encode())
77+
verificationInfo.write(2, slotRoot.data.buffer)
7878
erasureInfo.write(5, verificationInfo)
7979

8080
erasureInfo.finish()
@@ -100,8 +100,8 @@ proc decode*(_: DagPBCoder, data: openArray[byte]): ?!Manifest =
100100
blockSize: uint32
101101
originalDatasetSize: uint32
102102
ecK, ecM: uint32
103-
verificationRoot: string
104-
slotRoots: seq[string]
103+
verificationRoot: seq[byte]
104+
slotRoots: seq[seq[byte]]
105105

106106
# Decode `Header` message
107107
if pbNode.getField(1, pbHeader).isErr:
@@ -176,10 +176,14 @@ proc decode*(_: DagPBCoder, data: openArray[byte]): ?!Manifest =
176176
? self.verify()
177177

178178
if verifiable:
179+
let
180+
verificationRootCid = ? Cid.init(verificationRoot).mapFailure
181+
slotRootCids = slotRoots.mapIt(? Cid.init(it).mapFailure)
182+
179183
return Manifest.new(
180184
manifest = self,
181-
verificationRoot = VerificationHash.decode(verificationRoot),
182-
slotRoots = slotRoots.mapIt(VerificationHash.decode(it))
185+
verificationRoot = verificationRootCid,
186+
slotRoots = slotRootCids
183187
)
184188

185189
self.success

codex/manifest/manifest.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type
4444
originalDatasetSize: NBytes
4545
case verifiable {.serialize.}: bool # Verifiable datasets can be used to generate storage proofs
4646
of true:
47-
verificationRoot: VerificationHash
48-
slotRoots: seq[VerificationHash]
47+
verificationRoot: Cid
48+
slotRoots: seq[Cid]
4949
else:
5050
discard
5151
else:
@@ -97,10 +97,10 @@ proc blocksCount*(self: Manifest): int =
9797
proc verifiable*(self: Manifest): bool =
9898
self.verifiable
9999

100-
proc verificationRoot*(self: Manifest): VerificationHash =
100+
proc verificationRoot*(self: Manifest): Cid =
101101
self.verificationRoot
102102

103-
proc slotRoots*(self: Manifest): seq[VerificationHash] =
103+
proc slotRoots*(self: Manifest): seq[Cid] =
104104
self.slotRoots
105105

106106
############################################################
@@ -290,8 +290,8 @@ proc new*(
290290
proc new*(
291291
T: type Manifest,
292292
manifest: Manifest,
293-
verificationRoot: VerificationHash,
294-
slotRoots: seq[VerificationHash]
293+
verificationRoot: Cid,
294+
slotRoots: seq[Cid]
295295
): ?!Manifest =
296296
## Create a verifiable dataset from an
297297
## protected one

codex/manifest/types.nim

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,8 @@ const
2323
type
2424
ManifestCoderType*[codec: static MultiCodec] = object
2525
DagPBCoder* = ManifestCoderType[multiCodec("dag-pb")]
26-
VerificationHash* = int
27-
# TODO: Replace this with a wrapper type that supports Poseidon2
28-
# and is can be encoded/decoded, AND is JSON-serializable
2926

3027
const
3128
ManifestContainers* = {
3229
$DagPBCodec: DagPBCoder()
3330
}.toTable
34-
35-
proc fromInt*(T: type VerificationHash, value: SomeInteger | SomeUnsignedInt): VerificationHash =
36-
value.int
37-
38-
proc encode*(a: VerificationHash): string =
39-
$a
40-
41-
proc decode*(T: type VerificationHash, str: string): VerificationHash =
42-
try:
43-
parseInt(str)
44-
except ValueError:
45-
0

tests/codex/testmanifest.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ checksuite "Manifest":
2626
)
2727
verifiableManifest = Manifest.new(
2828
manifest = protectedManifest,
29-
verificationRoot = VerificationHash.fromInt(12),
30-
slotRoots = @[VerificationHash.fromInt(23), VerificationHash.fromInt(34)]
29+
verificationRoot = Cid.example,
30+
slotRoots = @[Cid.example, Cid.example]
3131
).tryGet()
3232

3333
proc encodeDecode(manifest: Manifest): Manifest =

0 commit comments

Comments
 (0)