Change cid format from string to bytes for the marketplace

This commit is contained in:
Arnaud 2025-01-16 10:36:35 +01:00 committed by Eric
parent 6e73338425
commit c05c008286
No known key found for this signature in database
9 changed files with 15 additions and 16 deletions

View File

@ -29,7 +29,7 @@ type
maxSlotLoss* {.serialize.}: uint64
StorageContent* = object
cid* {.serialize.}: string
cid*: seq[byte]
merkleRoot*: array[32, byte]
Slot* = object

View File

@ -502,7 +502,7 @@ proc setupRequest(
maxSlotLoss: tolerance,
),
content: StorageContent(
cid: $manifestBlk.cid, # TODO: why string?
cid: manifestBlk.cid.data.buffer,
merkleRoot: verifyRoot,
),
expiry: expiry,
@ -689,7 +689,7 @@ proc onProve(
failure "Prover not enabled"
proc onExpiryUpdate(
self: CodexNodeRef, rootCid: string, expiry: SecondsSince1970
self: CodexNodeRef, rootCid: seq[byte], expiry: SecondsSince1970
): Future[?!void] {.async.} =
without cid =? Cid.init(rootCid):
trace "Unable to parse Cid", cid
@ -719,7 +719,7 @@ proc start*(self: CodexNodeRef) {.async.} =
self.onStore(request, slot, onBatch)
hostContracts.sales.onExpiryUpdate = proc(
rootCid: string, expiry: SecondsSince1970
rootCid: seq[byte], expiry: SecondsSince1970
): Future[?!void] =
self.onExpiryUpdate(rootCid, expiry)

View File

@ -30,7 +30,7 @@ type
OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[?!Groth16Proof] {.
gcsafe, upraises: []
.}
OnExpiryUpdate* = proc(rootCid: string, expiry: SecondsSince1970): Future[?!void] {.
OnExpiryUpdate* = proc(rootCid: seq[byte], expiry: SecondsSince1970): Future[?!void] {.
gcsafe, upraises: []
.}
OnClear* = proc(request: StorageRequest, slotIndex: UInt256) {.gcsafe, upraises: [].}

View File

@ -78,7 +78,6 @@ asyncchecksuite "Test Node - Host contracts":
erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider, Taskpool.new)
manifestCid = manifestBlock.cid
manifestCidStr = $(manifestCid)
(await localStore.putBlock(manifestBlock)).tryGet()
@ -99,7 +98,7 @@ asyncchecksuite "Test Node - Host contracts":
expectedExpiry: SecondsSince1970 = clock.now + DefaultBlockTtl.seconds + 11123
expiryUpdateCallback = !sales.onExpiryUpdate
(await expiryUpdateCallback(manifestCidStr, expectedExpiry)).tryGet()
(await expiryUpdateCallback(manifestCid.data.buffer, expectedExpiry)).tryGet()
for index in 0 ..< manifest.blocksCount:
let
@ -116,7 +115,7 @@ asyncchecksuite "Test Node - Host contracts":
test "onStore callback":
let onStore = !sales.onStore
var request = StorageRequest.example
request.content.cid = $verifiableBlock.cid
request.content.cid = verifiableBlock.cid.data.buffer
request.expiry = (getTime() + DefaultBlockTtl.toTimesDuration + 1.hours).toUnix.u256
var fetchedBytes: uint = 0

View File

@ -167,7 +167,7 @@ asyncchecksuite "Test Node - Basic":
check:
(await verifiableBlock.cid in localStore) == true
request.content.cid == $verifiableBlock.cid
request.content.cid == verifiableBlock.cid.data.buffer
request.content.merkleRoot == builder.verifyRoot.get.toBytes
test "Should delete a single block":

View File

@ -36,7 +36,7 @@ checksuite "sales state 'filled'":
market.requestEnds[request.id] = 321
onExpiryUpdatePassedExpiry = -1
let onExpiryUpdate = proc(
rootCid: string, expiry: SecondsSince1970
rootCid: seq[byte], expiry: SecondsSince1970
): Future[?!void] {.async.} =
onExpiryUpdatePassedExpiry = expiry
return success()

View File

@ -46,7 +46,7 @@ asyncchecksuite "Sales - start":
pricePerBytePerSecond: 1.u256,
collateralPerByte: 1.u256,
),
content: StorageContent(cid: "some cid"),
content: StorageContent(cid: "some cid".toBytes),
expiry: (getTime() + initDuration(hours = 1)).toUnix.u256,
)
@ -64,7 +64,7 @@ asyncchecksuite "Sales - start":
return success()
sales.onExpiryUpdate = proc(
rootCid: string, expiry: SecondsSince1970
rootCid: seq[byte], expiry: SecondsSince1970
): Future[?!void] {.async.} =
return success()
@ -158,7 +158,7 @@ asyncchecksuite "Sales":
pricePerBytePerSecond: minPricePerBytePerSecond,
collateralPerByte: 1.u256,
),
content: StorageContent(cid: "some cid"),
content: StorageContent(cid: "some cid".toBytes),
expiry: (getTime() + initDuration(hours = 1)).toUnix.u256,
)
@ -181,7 +181,7 @@ asyncchecksuite "Sales":
return success()
sales.onExpiryUpdate = proc(
rootCid: string, expiry: SecondsSince1970
rootCid: seq[byte], expiry: SecondsSince1970
): Future[?!void] {.async.} =
return success()

View File

@ -57,7 +57,7 @@ proc example*(_: type StorageRequest): StorageRequest =
maxSlotLoss: 2, # 2 slots can be freed without data considered to be lost
),
content: StorageContent(
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob".toBytes,
merkleRoot: array[32, byte].example,
),
expiry: (60 * 60).u256, # 1 hour ,

@ -1 +1 @@
Subproject commit e74d3397a133eaf1eb95d9ce59f56747a7c8c30b
Subproject commit f1e674f91c9f104bb4d7e15d4a940f755c51d818