-
Notifications
You must be signed in to change notification settings - Fork 31
fix(sales): fix marketplace block expiry #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import codex/clock | ||
|
|
||
| import ../examples | ||
| import ./mockclock | ||
|
|
||
| export market | ||
| export tables | ||
|
|
@@ -51,7 +52,7 @@ | |
| errorOnFillSlot*: ?(ref MarketError) | ||
| errorOnFreeSlot*: ?(ref MarketError) | ||
| errorOnGetHost*: ?(ref MarketError) | ||
| clock: ?Clock | ||
| clock: Clock | ||
|
|
||
| Fulfillment* = object | ||
| requestId*: RequestId | ||
|
|
@@ -63,7 +64,7 @@ | |
| host*: Address | ||
| slotIndex*: uint64 | ||
| proof*: Groth16Proof | ||
| timestamp: ?SecondsSince1970 | ||
| timestamp: SecondsSince1970 | ||
| collateral*: UInt256 | ||
|
|
||
| Subscriptions = object | ||
|
|
@@ -119,7 +120,7 @@ | |
| proc hash*(requestId: RequestId): Hash = | ||
| hash(requestId.toArray) | ||
|
|
||
| proc new*(_: type MockMarket, clock: ?Clock = Clock.none): MockMarket = | ||
| proc new*(_: type MockMarket, clock: Clock = MockClock.new()): MockMarket = | ||
| ## Create a new mocked Market instance | ||
| ## | ||
| let config = MarketplaceConfig( | ||
|
|
@@ -181,10 +182,15 @@ | |
| method requestStorage*( | ||
| market: MockMarket, request: StorageRequest | ||
| ) {.async: (raises: [CancelledError, MarketError]).} = | ||
| let now = market.clock.now() | ||
| let requestExpiresAt = now + request.expiry.toSecondsSince1970 | ||
| let requestEndsAt = now + request.ask.duration.toSecondsSince1970 | ||
| market.requested.add(request) | ||
| market.requestExpiry[request.id] = requestExpiresAt | ||
| market.requestEnds[request.id] = requestEndsAt | ||
| var subscriptions = market.subscriptions.onRequest | ||
| for subscription in subscriptions: | ||
| subscription.callback(request.id, request.ask, request.expiry) | ||
| subscription.callback(request.id, request.ask, requestExpiresAt.uint64) | ||
|
|
||
| method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} = | ||
| return market.activeRequests[market.signer] | ||
|
|
@@ -308,7 +314,7 @@ | |
| slotIndex: slotIndex, | ||
| proof: proof, | ||
| host: host, | ||
| timestamp: market.clock .? now, | ||
| timestamp: market.clock.now, | ||
| collateral: collateral, | ||
| ) | ||
| market.filled.add(slot) | ||
|
|
@@ -541,15 +547,23 @@ | |
| ): Future[seq[StorageRequested]] {.async.} = | ||
| return market.requested.map( | ||
| request => | ||
| StorageRequested(requestId: request.id, ask: request.ask, expiry: request.expiry) | ||
| StorageRequested( | ||
| requestId: request.id, | ||
| ask: request.ask, | ||
| expiry: market.requestExpiry[request.id].uint64, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here the expiry should be the duration no ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no sorry, it is ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's really confusing keeping these two uint64 values apart, so that's why in #1196 I created different types for durations and timestamps. But I didn't want to extract all of that into this PR. |
||
| ) | ||
| ) | ||
|
|
||
| method queryPastStorageRequestedEvents*( | ||
| market: MockMarket, blocksAgo: int | ||
| ): Future[seq[StorageRequested]] {.async.} = | ||
| return market.requested.map( | ||
| request => | ||
| StorageRequested(requestId: request.id, ask: request.ask, expiry: request.expiry) | ||
| StorageRequested( | ||
| requestId: request.id, | ||
| ask: request.ask, | ||
| expiry: market.requestExpiry[request.id].uint64, | ||
| ) | ||
| ) | ||
|
|
||
| method queryPastSlotFilledEvents*( | ||
|
|
@@ -571,10 +585,7 @@ | |
| ): Future[seq[SlotFilled]] {.async.} = | ||
| let filtered = market.filled.filter( | ||
| proc(slot: MockSlot): bool = | ||
| if timestamp =? slot.timestamp: | ||
| return timestamp >= fromTime | ||
| else: | ||
| true | ||
| return slot.timestamp >= fromTime | ||
| ) | ||
| return filtered.map( | ||
| slot => SlotFilled(requestId: slot.requestId, slotIndex: slot.slotIndex) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon the
filledstate, this will get "re-updated" to the same value, but I guess it is not a problem except a bit of wasted CPU cycles.