[chore] additional clean up of `array[32, byte]` types

- rename `ContractId` to `SlotId`
- rename `Proving.contracts` to `Proving.slots`
- change signatures of `isSlotCancelled` and `isCancelled` to use `SlotId` and `RequestId` types, respectively.
- change all references to `RequestId`, `SlotId`
This commit is contained in:
Eric Mastro 2022-08-17 14:18:30 +10:00 committed by Eric Mastro
parent 1039e27524
commit 5cb74b6638
12 changed files with 38 additions and 38 deletions

View File

@ -59,7 +59,7 @@ method fillSlot(market: OnChainMarket,
await market.contract.fillSlot(requestId, slotIndex, proof)
method withdrawFunds(market: OnChainMarket,
requestId: array[32, byte]) {.async.} =
requestId: RequestId) {.async.} =
await market.contract.withdrawFunds(requestId)
method subscribeRequests(market: OnChainMarket,
@ -92,7 +92,7 @@ method subscribeFulfillment(market: OnChainMarket,
return OnChainMarketSubscription(eventSubscription: subscription)
method subscribeRequestCancelled*(market: OnChainMarket,
requestId: array[32, byte],
requestId: RequestId,
callback: OnRequestCancelled):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestCancelled) {.upraises:[].} =

View File

@ -23,11 +23,11 @@ method periodicity*(proofs: OnChainProofs): Future[Periodicity] {.async.} =
return Periodicity(seconds: period)
method isSlotCancelled*(proofs: OnChainProofs,
id: ContractId): Future[bool] {.async.} =
id: SlotId): Future[bool] {.async.} =
return await proofs.storage.isSlotCancelled(id)
method isCancelled*(proofs: OnChainProofs,
id: array[32, byte]): Future[bool] {.async.} =
id: RequestId): Future[bool] {.async.} =
return await proofs.storage.isCancelled(id)
method isProofRequired*(proofs: OnChainProofs,

View File

@ -19,7 +19,7 @@ type
RequestFulfilled* = object of Event
requestId* {.indexed.}: RequestId
RequestCancelled* = object of Event
requestId* {.indexed.}: Id
requestId* {.indexed.}: RequestId
ProofSubmitted* = object of Event
id*: SlotId
proof*: seq[byte]
@ -35,7 +35,7 @@ proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
proc fillSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256, proof: seq[byte]) {.contract.}
proc withdrawFunds*(storage: Storage, requestId: Id) {.contract.}
proc withdrawFunds*(storage: Storage, requestId: RequestId) {.contract.}
proc payoutSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256) {.contract.}
proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.}
proc getHost*(storage: Storage, id: SlotId): Address {.contract, view.}
@ -45,8 +45,8 @@ proc proofTimeout*(storage: Storage): UInt256 {.contract, view.}
proc proofEnd*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
proc missingProofs*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
proc isCancelled*(storage: Storage, id: Id): bool {.contract, view.}
proc isSlotCancelled*(storage: Storage, id: Id): bool {.contract, view.}
proc isCancelled*(storage: Storage, id: RequestId): bool {.contract, view.}
proc isSlotCancelled*(storage: Storage, id: SlotId): bool {.contract, view.}
proc isProofRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
proc willProofBeRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.}

View File

@ -10,10 +10,10 @@ export requests
type
Market* = ref object of RootObj
Subscription* = ref object of RootObj
OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.gcsafe, upraises:[].}
OnFulfillment* = proc(requestId: array[32, byte]) {.gcsafe, upraises: [].}
OnSlotFilled* = proc(requestId: array[32, byte], slotIndex: UInt256) {.gcsafe, upraises:[].}
OnRequestCancelled* = proc(requestId: array[32, byte]) {.gcsafe, upraises:[].}
OnRequest* = proc(id: RequestId, ask: StorageAsk) {.gcsafe, upraises:[].}
OnFulfillment* = proc(requestId: RequestId) {.gcsafe, upraises: [].}
OnSlotFilled* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises:[].}
OnRequestCancelled* = proc(requestId: RequestId) {.gcsafe, upraises:[].}
method getSigner*(market: Market): Future[Address] {.base, async.} =
raiseAssert("not implemented")
@ -40,7 +40,7 @@ method fillSlot*(market: Market,
raiseAssert("not implemented")
method withdrawFunds*(market: Market,
requestId: array[32, byte]) {.base, async.} =
requestId: RequestId) {.base, async.} =
raiseAssert("not implemented")
method subscribeRequests*(market: Market,
@ -62,7 +62,7 @@ method subscribeSlotFilled*(market: Market,
raiseAssert("not implemented")
method subscribeRequestCancelled*(market: Market,
requestId: array[32, byte],
requestId: RequestId,
callback: OnRequestCancelled):
Future[Subscription] {.base, async.} =
raiseAssert("not implemented")

View File

@ -43,11 +43,11 @@ proc removeEndedContracts(proving: Proving) {.async.} =
proving.slots.excl(ended)
proc removeCancelledContracts(proving: Proving) {.async.} =
var cancelled: HashSet[ContractId]
for id in proving.contracts:
var cancelled: HashSet[SlotId]
for id in proving.slots:
if (await proving.proofs.isSlotCancelled(id)):
cancelled.incl(id)
proving.contracts.excl(cancelled)
proving.slots.excl(cancelled)
proc run(proving: Proving) {.async.} =
try:

View File

@ -19,11 +19,11 @@ method periodicity*(proofs: Proofs):
raiseAssert("not implemented")
method isSlotCancelled*(proofs: Proofs,
id: ContractId): Future[bool] {.base, async.} =
id: SlotId): Future[bool] {.base, async.} =
raiseAssert("not implemented")
method isCancelled*(proofs: Proofs,
id: array[32, byte]): Future[bool] {.base, async.} =
id: RequestId): Future[bool] {.base, async.} =
raiseAssert("not implemented")
method isProofRequired*(proofs: Proofs,

View File

@ -38,7 +38,7 @@ type
callback: OnSlotFilled
RequestCancelledSubscription* = ref object of Subscription
market: MockMarket
requestId: array[32, byte]
requestId: RequestId
callback: OnRequestCancelled
proc new*(_: type MockMarket): MockMarket =
@ -81,7 +81,7 @@ proc emitSlotFilled*(market: MockMarket,
subscription.callback(requestId, slotIndex)
proc emitRequestCancelled*(market: MockMarket,
requestId: array[32, byte]) =
requestId: RequestId) =
var subscriptions = market.subscriptions.onRequestCancelled
for subscription in subscriptions:
if subscription.requestId == requestId:
@ -114,7 +114,7 @@ method fillSlot*(market: MockMarket,
market.fillSlot(requestId, slotIndex, proof, market.signer)
method withdrawFunds*(market: MockMarket,
requestId: array[32, byte]) {.async.} =
requestId: RequestId) {.async.} =
market.emitRequestCancelled(requestId)
method subscribeRequests*(market: MockMarket,
@ -154,7 +154,7 @@ method subscribeSlotFilled*(market: MockMarket,
return subscription
method subscribeRequestCancelled*(market: MockMarket,
requestId: array[32, byte],
requestId: RequestId,
callback: OnRequestCancelled):
Future[Subscription] {.async.} =
let subscription = RequestCancelledSubscription(

View File

@ -7,7 +7,7 @@ import pkg/codex/storageproofs
type
MockProofs* = ref object of Proofs
periodicity: Periodicity
cancelledRequests: HashSet[ContractId]
cancelledRequests: HashSet[SlotId]
proofsRequired: HashSet[SlotId]
proofsToBeRequired: HashSet[SlotId]
proofEnds: Table[SlotId, UInt256]
@ -33,18 +33,18 @@ proc setProofRequired*(mock: MockProofs, id: SlotId, required: bool) =
else:
mock.proofsRequired.excl(id)
proc setCancelled*(mock: MockProofs, id: ContractId, required: bool) =
proc setCancelled*(mock: MockProofs, id: SlotId, required: bool) =
if required:
mock.cancelledRequests.incl(id)
else:
mock.cancelledRequests.excl(id)
method isCancelled*(mock: MockProofs,
id: array[32, byte]): Future[bool] {.async.} =
id: RequestId): Future[bool] {.async.} =
return mock.cancelledRequests.contains(id)
method isSlotCancelled*(mock: MockProofs,
id: ContractId): Future[bool] {.async.} =
id: SlotId): Future[bool] {.async.} =
return mock.cancelledRequests.contains(id)
method isProofRequired*(mock: MockProofs,

View File

@ -93,17 +93,17 @@ suite "Proving":
check not called
test "stops watching when contract is cancelled":
let id = ContractId.example
let id = SlotId.example
proving.add(id)
var called: bool
proc onProofRequired(id: ContractId) =
proc onProofRequired(id: SlotId) =
called = true
proofs.setProofRequired(id, true)
await proofs.advanceToNextPeriod()
proving.onProofRequired = onProofRequired
proofs.setCancelled(id, true)
await proofs.advanceToNextPeriod()
check not proving.contracts.contains(id)
check not proving.slots.contains(id)
check not called
test "submits proofs":

View File

@ -92,9 +92,9 @@ suite "Purchasing":
test "supports request cancelled subscription when request times out":
let purchase = purchasing.purchase(request)
let request = market.requested[0]
var receivedIds: seq[array[32, byte]]
var receivedIds: seq[RequestId]
clock.set(request.expiry.truncate(int64))
proc onRequestCancelled(id: array[32, byte]) {.gcsafe, upraises:[].} =
proc onRequestCancelled(id: RequestId) {.gcsafe, upraises:[].} =
receivedIds.add(id)
let subscription = await market.subscribeRequestCancelled(
request.id,

View File

@ -205,8 +205,8 @@ suite "Sales":
request: StorageRequest,
slotIndex: UInt256) =
soldSlotIndex = slotIndex
check proving.contracts.len == 0
check proving.slots.len == 0
sales.add(availability)
discard await market.requestStorage(request)
check proving.contracts.len == 1
check proving.contracts.contains(request.slotId(soldSlotIndex))
check proving.slots.len == 1
check proving.slots.contains(request.slotId(soldSlotIndex))

View File

@ -82,9 +82,9 @@ ethersuite "Storage contracts":
check await storage.isCancelled(request.id)
test "a slot is cancelled after expiry":
check not await storage.isSlotCancelled(id)
check not await storage.isSlotCancelled(slotId)
await provider.advanceTimeTo(request.expiry + 1)
check await storage.isSlotCancelled(id)
check await storage.isSlotCancelled(slotId)
test "cannot mark proofs missing for cancelled request":
await provider.advanceTimeTo(request.expiry + 1)
@ -92,4 +92,4 @@ ethersuite "Storage contracts":
let missingPeriod = periodicity.periodOf(await provider.currentTime())
await provider.advanceTime(periodicity.seconds)
revertsWith "Request was cancelled":
await storage.markProofAsMissing(id, missingPeriod)
await storage.markProofAsMissing(slotId, missingPeriod)