[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:
parent
1039e27524
commit
5cb74b6638
|
@ -59,7 +59,7 @@ method fillSlot(market: OnChainMarket,
|
||||||
await market.contract.fillSlot(requestId, slotIndex, proof)
|
await market.contract.fillSlot(requestId, slotIndex, proof)
|
||||||
|
|
||||||
method withdrawFunds(market: OnChainMarket,
|
method withdrawFunds(market: OnChainMarket,
|
||||||
requestId: array[32, byte]) {.async.} =
|
requestId: RequestId) {.async.} =
|
||||||
await market.contract.withdrawFunds(requestId)
|
await market.contract.withdrawFunds(requestId)
|
||||||
|
|
||||||
method subscribeRequests(market: OnChainMarket,
|
method subscribeRequests(market: OnChainMarket,
|
||||||
|
@ -92,7 +92,7 @@ method subscribeFulfillment(market: OnChainMarket,
|
||||||
return OnChainMarketSubscription(eventSubscription: subscription)
|
return OnChainMarketSubscription(eventSubscription: subscription)
|
||||||
|
|
||||||
method subscribeRequestCancelled*(market: OnChainMarket,
|
method subscribeRequestCancelled*(market: OnChainMarket,
|
||||||
requestId: array[32, byte],
|
requestId: RequestId,
|
||||||
callback: OnRequestCancelled):
|
callback: OnRequestCancelled):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestCancelled) {.upraises:[].} =
|
proc onEvent(event: RequestCancelled) {.upraises:[].} =
|
||||||
|
|
|
@ -23,11 +23,11 @@ method periodicity*(proofs: OnChainProofs): Future[Periodicity] {.async.} =
|
||||||
return Periodicity(seconds: period)
|
return Periodicity(seconds: period)
|
||||||
|
|
||||||
method isSlotCancelled*(proofs: OnChainProofs,
|
method isSlotCancelled*(proofs: OnChainProofs,
|
||||||
id: ContractId): Future[bool] {.async.} =
|
id: SlotId): Future[bool] {.async.} =
|
||||||
return await proofs.storage.isSlotCancelled(id)
|
return await proofs.storage.isSlotCancelled(id)
|
||||||
|
|
||||||
method isCancelled*(proofs: OnChainProofs,
|
method isCancelled*(proofs: OnChainProofs,
|
||||||
id: array[32, byte]): Future[bool] {.async.} =
|
id: RequestId): Future[bool] {.async.} =
|
||||||
return await proofs.storage.isCancelled(id)
|
return await proofs.storage.isCancelled(id)
|
||||||
|
|
||||||
method isProofRequired*(proofs: OnChainProofs,
|
method isProofRequired*(proofs: OnChainProofs,
|
||||||
|
|
|
@ -19,7 +19,7 @@ type
|
||||||
RequestFulfilled* = object of Event
|
RequestFulfilled* = object of Event
|
||||||
requestId* {.indexed.}: RequestId
|
requestId* {.indexed.}: RequestId
|
||||||
RequestCancelled* = object of Event
|
RequestCancelled* = object of Event
|
||||||
requestId* {.indexed.}: Id
|
requestId* {.indexed.}: RequestId
|
||||||
ProofSubmitted* = object of Event
|
ProofSubmitted* = object of Event
|
||||||
id*: SlotId
|
id*: SlotId
|
||||||
proof*: seq[byte]
|
proof*: seq[byte]
|
||||||
|
@ -35,7 +35,7 @@ proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
|
||||||
|
|
||||||
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
|
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
|
||||||
proc fillSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256, proof: seq[byte]) {.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 payoutSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256) {.contract.}
|
||||||
proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.}
|
proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.}
|
||||||
proc getHost*(storage: Storage, id: SlotId): Address {.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 proofEnd*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
|
||||||
proc missingProofs*(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 isCancelled*(storage: Storage, id: RequestId): bool {.contract, view.}
|
||||||
proc isSlotCancelled*(storage: Storage, id: Id): bool {.contract, view.}
|
proc isSlotCancelled*(storage: Storage, id: SlotId): bool {.contract, view.}
|
||||||
proc isProofRequired*(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 willProofBeRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
|
||||||
proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.}
|
proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.}
|
||||||
|
|
|
@ -10,10 +10,10 @@ export requests
|
||||||
type
|
type
|
||||||
Market* = ref object of RootObj
|
Market* = ref object of RootObj
|
||||||
Subscription* = ref object of RootObj
|
Subscription* = ref object of RootObj
|
||||||
OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.gcsafe, upraises:[].}
|
OnRequest* = proc(id: RequestId, ask: StorageAsk) {.gcsafe, upraises:[].}
|
||||||
OnFulfillment* = proc(requestId: array[32, byte]) {.gcsafe, upraises: [].}
|
OnFulfillment* = proc(requestId: RequestId) {.gcsafe, upraises: [].}
|
||||||
OnSlotFilled* = proc(requestId: array[32, byte], slotIndex: UInt256) {.gcsafe, upraises:[].}
|
OnSlotFilled* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises:[].}
|
||||||
OnRequestCancelled* = proc(requestId: array[32, byte]) {.gcsafe, upraises:[].}
|
OnRequestCancelled* = proc(requestId: RequestId) {.gcsafe, upraises:[].}
|
||||||
|
|
||||||
method getSigner*(market: Market): Future[Address] {.base, async.} =
|
method getSigner*(market: Market): Future[Address] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
@ -40,7 +40,7 @@ method fillSlot*(market: Market,
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method withdrawFunds*(market: Market,
|
method withdrawFunds*(market: Market,
|
||||||
requestId: array[32, byte]) {.base, async.} =
|
requestId: RequestId) {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method subscribeRequests*(market: Market,
|
method subscribeRequests*(market: Market,
|
||||||
|
@ -62,7 +62,7 @@ method subscribeSlotFilled*(market: Market,
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method subscribeRequestCancelled*(market: Market,
|
method subscribeRequestCancelled*(market: Market,
|
||||||
requestId: array[32, byte],
|
requestId: RequestId,
|
||||||
callback: OnRequestCancelled):
|
callback: OnRequestCancelled):
|
||||||
Future[Subscription] {.base, async.} =
|
Future[Subscription] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
|
@ -43,11 +43,11 @@ proc removeEndedContracts(proving: Proving) {.async.} =
|
||||||
proving.slots.excl(ended)
|
proving.slots.excl(ended)
|
||||||
|
|
||||||
proc removeCancelledContracts(proving: Proving) {.async.} =
|
proc removeCancelledContracts(proving: Proving) {.async.} =
|
||||||
var cancelled: HashSet[ContractId]
|
var cancelled: HashSet[SlotId]
|
||||||
for id in proving.contracts:
|
for id in proving.slots:
|
||||||
if (await proving.proofs.isSlotCancelled(id)):
|
if (await proving.proofs.isSlotCancelled(id)):
|
||||||
cancelled.incl(id)
|
cancelled.incl(id)
|
||||||
proving.contracts.excl(cancelled)
|
proving.slots.excl(cancelled)
|
||||||
|
|
||||||
proc run(proving: Proving) {.async.} =
|
proc run(proving: Proving) {.async.} =
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -19,11 +19,11 @@ method periodicity*(proofs: Proofs):
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method isSlotCancelled*(proofs: Proofs,
|
method isSlotCancelled*(proofs: Proofs,
|
||||||
id: ContractId): Future[bool] {.base, async.} =
|
id: SlotId): Future[bool] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method isCancelled*(proofs: Proofs,
|
method isCancelled*(proofs: Proofs,
|
||||||
id: array[32, byte]): Future[bool] {.base, async.} =
|
id: RequestId): Future[bool] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method isProofRequired*(proofs: Proofs,
|
method isProofRequired*(proofs: Proofs,
|
||||||
|
|
|
@ -38,7 +38,7 @@ type
|
||||||
callback: OnSlotFilled
|
callback: OnSlotFilled
|
||||||
RequestCancelledSubscription* = ref object of Subscription
|
RequestCancelledSubscription* = ref object of Subscription
|
||||||
market: MockMarket
|
market: MockMarket
|
||||||
requestId: array[32, byte]
|
requestId: RequestId
|
||||||
callback: OnRequestCancelled
|
callback: OnRequestCancelled
|
||||||
|
|
||||||
proc new*(_: type MockMarket): MockMarket =
|
proc new*(_: type MockMarket): MockMarket =
|
||||||
|
@ -81,7 +81,7 @@ proc emitSlotFilled*(market: MockMarket,
|
||||||
subscription.callback(requestId, slotIndex)
|
subscription.callback(requestId, slotIndex)
|
||||||
|
|
||||||
proc emitRequestCancelled*(market: MockMarket,
|
proc emitRequestCancelled*(market: MockMarket,
|
||||||
requestId: array[32, byte]) =
|
requestId: RequestId) =
|
||||||
var subscriptions = market.subscriptions.onRequestCancelled
|
var subscriptions = market.subscriptions.onRequestCancelled
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
if subscription.requestId == requestId:
|
if subscription.requestId == requestId:
|
||||||
|
@ -114,7 +114,7 @@ method fillSlot*(market: MockMarket,
|
||||||
market.fillSlot(requestId, slotIndex, proof, market.signer)
|
market.fillSlot(requestId, slotIndex, proof, market.signer)
|
||||||
|
|
||||||
method withdrawFunds*(market: MockMarket,
|
method withdrawFunds*(market: MockMarket,
|
||||||
requestId: array[32, byte]) {.async.} =
|
requestId: RequestId) {.async.} =
|
||||||
market.emitRequestCancelled(requestId)
|
market.emitRequestCancelled(requestId)
|
||||||
|
|
||||||
method subscribeRequests*(market: MockMarket,
|
method subscribeRequests*(market: MockMarket,
|
||||||
|
@ -154,7 +154,7 @@ method subscribeSlotFilled*(market: MockMarket,
|
||||||
return subscription
|
return subscription
|
||||||
|
|
||||||
method subscribeRequestCancelled*(market: MockMarket,
|
method subscribeRequestCancelled*(market: MockMarket,
|
||||||
requestId: array[32, byte],
|
requestId: RequestId,
|
||||||
callback: OnRequestCancelled):
|
callback: OnRequestCancelled):
|
||||||
Future[Subscription] {.async.} =
|
Future[Subscription] {.async.} =
|
||||||
let subscription = RequestCancelledSubscription(
|
let subscription = RequestCancelledSubscription(
|
||||||
|
|
|
@ -7,7 +7,7 @@ import pkg/codex/storageproofs
|
||||||
type
|
type
|
||||||
MockProofs* = ref object of Proofs
|
MockProofs* = ref object of Proofs
|
||||||
periodicity: Periodicity
|
periodicity: Periodicity
|
||||||
cancelledRequests: HashSet[ContractId]
|
cancelledRequests: HashSet[SlotId]
|
||||||
proofsRequired: HashSet[SlotId]
|
proofsRequired: HashSet[SlotId]
|
||||||
proofsToBeRequired: HashSet[SlotId]
|
proofsToBeRequired: HashSet[SlotId]
|
||||||
proofEnds: Table[SlotId, UInt256]
|
proofEnds: Table[SlotId, UInt256]
|
||||||
|
@ -33,18 +33,18 @@ proc setProofRequired*(mock: MockProofs, id: SlotId, required: bool) =
|
||||||
else:
|
else:
|
||||||
mock.proofsRequired.excl(id)
|
mock.proofsRequired.excl(id)
|
||||||
|
|
||||||
proc setCancelled*(mock: MockProofs, id: ContractId, required: bool) =
|
proc setCancelled*(mock: MockProofs, id: SlotId, required: bool) =
|
||||||
if required:
|
if required:
|
||||||
mock.cancelledRequests.incl(id)
|
mock.cancelledRequests.incl(id)
|
||||||
else:
|
else:
|
||||||
mock.cancelledRequests.excl(id)
|
mock.cancelledRequests.excl(id)
|
||||||
|
|
||||||
method isCancelled*(mock: MockProofs,
|
method isCancelled*(mock: MockProofs,
|
||||||
id: array[32, byte]): Future[bool] {.async.} =
|
id: RequestId): Future[bool] {.async.} =
|
||||||
return mock.cancelledRequests.contains(id)
|
return mock.cancelledRequests.contains(id)
|
||||||
|
|
||||||
method isSlotCancelled*(mock: MockProofs,
|
method isSlotCancelled*(mock: MockProofs,
|
||||||
id: ContractId): Future[bool] {.async.} =
|
id: SlotId): Future[bool] {.async.} =
|
||||||
return mock.cancelledRequests.contains(id)
|
return mock.cancelledRequests.contains(id)
|
||||||
|
|
||||||
method isProofRequired*(mock: MockProofs,
|
method isProofRequired*(mock: MockProofs,
|
||||||
|
|
|
@ -93,17 +93,17 @@ suite "Proving":
|
||||||
check not called
|
check not called
|
||||||
|
|
||||||
test "stops watching when contract is cancelled":
|
test "stops watching when contract is cancelled":
|
||||||
let id = ContractId.example
|
let id = SlotId.example
|
||||||
proving.add(id)
|
proving.add(id)
|
||||||
var called: bool
|
var called: bool
|
||||||
proc onProofRequired(id: ContractId) =
|
proc onProofRequired(id: SlotId) =
|
||||||
called = true
|
called = true
|
||||||
proofs.setProofRequired(id, true)
|
proofs.setProofRequired(id, true)
|
||||||
await proofs.advanceToNextPeriod()
|
await proofs.advanceToNextPeriod()
|
||||||
proving.onProofRequired = onProofRequired
|
proving.onProofRequired = onProofRequired
|
||||||
proofs.setCancelled(id, true)
|
proofs.setCancelled(id, true)
|
||||||
await proofs.advanceToNextPeriod()
|
await proofs.advanceToNextPeriod()
|
||||||
check not proving.contracts.contains(id)
|
check not proving.slots.contains(id)
|
||||||
check not called
|
check not called
|
||||||
|
|
||||||
test "submits proofs":
|
test "submits proofs":
|
||||||
|
|
|
@ -92,9 +92,9 @@ suite "Purchasing":
|
||||||
test "supports request cancelled subscription when request times out":
|
test "supports request cancelled subscription when request times out":
|
||||||
let purchase = purchasing.purchase(request)
|
let purchase = purchasing.purchase(request)
|
||||||
let request = market.requested[0]
|
let request = market.requested[0]
|
||||||
var receivedIds: seq[array[32, byte]]
|
var receivedIds: seq[RequestId]
|
||||||
clock.set(request.expiry.truncate(int64))
|
clock.set(request.expiry.truncate(int64))
|
||||||
proc onRequestCancelled(id: array[32, byte]) {.gcsafe, upraises:[].} =
|
proc onRequestCancelled(id: RequestId) {.gcsafe, upraises:[].} =
|
||||||
receivedIds.add(id)
|
receivedIds.add(id)
|
||||||
let subscription = await market.subscribeRequestCancelled(
|
let subscription = await market.subscribeRequestCancelled(
|
||||||
request.id,
|
request.id,
|
||||||
|
|
|
@ -205,8 +205,8 @@ suite "Sales":
|
||||||
request: StorageRequest,
|
request: StorageRequest,
|
||||||
slotIndex: UInt256) =
|
slotIndex: UInt256) =
|
||||||
soldSlotIndex = slotIndex
|
soldSlotIndex = slotIndex
|
||||||
check proving.contracts.len == 0
|
check proving.slots.len == 0
|
||||||
sales.add(availability)
|
sales.add(availability)
|
||||||
discard await market.requestStorage(request)
|
discard await market.requestStorage(request)
|
||||||
check proving.contracts.len == 1
|
check proving.slots.len == 1
|
||||||
check proving.contracts.contains(request.slotId(soldSlotIndex))
|
check proving.slots.contains(request.slotId(soldSlotIndex))
|
||||||
|
|
|
@ -82,9 +82,9 @@ ethersuite "Storage contracts":
|
||||||
check await storage.isCancelled(request.id)
|
check await storage.isCancelled(request.id)
|
||||||
|
|
||||||
test "a slot is cancelled after expiry":
|
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)
|
await provider.advanceTimeTo(request.expiry + 1)
|
||||||
check await storage.isSlotCancelled(id)
|
check await storage.isSlotCancelled(slotId)
|
||||||
|
|
||||||
test "cannot mark proofs missing for cancelled request":
|
test "cannot mark proofs missing for cancelled request":
|
||||||
await provider.advanceTimeTo(request.expiry + 1)
|
await provider.advanceTimeTo(request.expiry + 1)
|
||||||
|
@ -92,4 +92,4 @@ ethersuite "Storage contracts":
|
||||||
let missingPeriod = periodicity.periodOf(await provider.currentTime())
|
let missingPeriod = periodicity.periodOf(await provider.currentTime())
|
||||||
await provider.advanceTime(periodicity.seconds)
|
await provider.advanceTime(periodicity.seconds)
|
||||||
revertsWith "Request was cancelled":
|
revertsWith "Request was cancelled":
|
||||||
await storage.markProofAsMissing(id, missingPeriod)
|
await storage.markProofAsMissing(slotId, missingPeriod)
|
||||||
|
|
Loading…
Reference in New Issue