Commit Graph

167 Commits

Author SHA1 Message Date
Mark Spanbroek afb89c9233 [Storage] Remove Storage
Rationale: it was already a very thin wrapper
around Marketplace, and now that its remaining
functionality has been moved to Proofs and
Marketplace, we no longer need it.
2023-01-10 12:15:22 +01:00
Mark Spanbroek 6ea2b77a8f [Storage] Move markProofAsMissing() to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek 31d109f0d3 [Storage] Move isProofRequired() et al to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek c9cf47f327 [Storage] Move missingProofs() to Proofs 2023-01-10 12:15:22 +01:00
Mark Spanbroek 154cc00277 [Proofs] remove unused imports 2023-01-10 12:15:22 +01:00
Mark Spanbroek d5d99515fc [Proofs] Remove ProofId and EndId, use SlotId and RequestId
Rationale: in practice, a ProofId was always a slot id, and
an EndId was always a request id. Now that the definitons
of SlotId and RequestId are separated from the Marketplace,
we can import and use them.
2023-01-10 12:15:22 +01:00
Mark Spanbroek ac98689892 [Storage] Remove getSlot()
Rationale: Slot is struct that is used by the contract
to keep track of the state of a slot, it doesn't need
to be exposed on the API
2023-01-10 12:15:22 +01:00
Mark Spanbroek 9b8bcc0bc7 [Storage] Move getRequest() and getHost() to Marketplace 2023-01-10 12:15:22 +01:00
Mark Spanbroek 71656f6a95 [collateral] Remove AccountLocks
AccountLocks is replaced by the isWithDrawAllowed()
implementation in Marketplace.
2022-12-22 10:29:06 +01:00
Mark Spanbroek dbc5e3738e [marketplace] Add tests for collateral locking
The collateral locking check was moved from Collateral
and AccountLocks to Marketplace. This tests the new
locking mechanism.
2022-12-22 10:29:06 +01:00
Mark Spanbroek d5d4dba442 [marketplace] Add missing tests for freeSlot()
Removes unnecessary double removal from slotsPerHost.
2022-12-22 10:29:06 +01:00
Mark Spanbroek 4f75159e02 [marketplace] Slots of failed request remain in mySlots()
Until hosts calls freeSlot()
2022-12-22 10:29:06 +01:00
Mark Spanbroek a7be363f04 [marketplace] Unlock collateral when list of slots is empty 2022-12-22 10:29:06 +01:00
Mark Spanbroek c46c268880 [marketplace] freeSlot() can be called by host
Handles payout, slashing and removal from mySlots
2022-12-22 10:29:06 +01:00
Mark Spanbroek 6e0dfdf7db [marketplace] Rename _freeSlot() -> _forciblyFreeSlot() 2022-12-22 10:29:06 +01:00
Mark Spanbroek a96333ce5f [marketplace] mySlots() returns slots of cancelled request
Reasoning: the node will want to call payoutSlot() for
cancelled requests, at which point it will be removed
from the list.
2022-12-22 10:29:06 +01:00
Mark Spanbroek a19e3f4198 [marketplace] Remove SetMap
No longer needed
2022-12-22 10:29:06 +01:00
Mark Spanbroek 0f6eb306ea [marketplace] Remove resize()
No longer needed
2022-12-22 10:29:06 +01:00
Mark Spanbroek c832dfbb7c [marketplace] Simplify myRequests() 2022-12-22 10:29:06 +01:00
Mark Spanbroek c0a1e11b87 [marketplace] replace mySlots(requestId) by mySlots()
Allows a host to get all slots that it participates in
in a single call.
2022-12-22 10:29:06 +01:00
Eric Mastro 7f59e545b2 Add more tests
- Marketplace tests for requestsForHost, and additional tests for myRequests and mySlots
- Added Utils lib with tests
- Added additional Bytes32AddressSetMap.keys expectations
2022-12-22 10:29:06 +01:00
Eric Mastro 429b9034d8 Add SetMap tests 2022-12-22 10:29:06 +01:00
Eric Mastro a99827ed39 Reinstate mapping index, add ActiveSlotId
Reinstate the index mapping for `activeSlots`, however with a modified data structure. The main difference comes from a change in `mySlots`: it now requires a `RequestId` as a parameter (which can be obtained using `myRequests`. This allowed for the `activeSlots` mapping to be keyed on `RequestId`, which gives a mapping of `ActiveSlotId => EnumerableSet.Bytes32`. `ActiveSlotId` is a keccak hash of `address + activeSlotIdx`, which not only allows retrieval of all active slot ids per request, but also allows clearing of all active slot ids for a request by incrementing the `activeSlotIdx`.
```
requestId => [ keccak(address + activeSlotIdx) => EnumerableSet.Bytes32 ]
```
2022-12-22 10:29:06 +01:00
Eric Mastro 5f056b055a Revert mapping index for clearing active slots
Instead, iterate all active slots and remove them individually, only if they are part of a specific request. This is only for the case of request failure.
2022-12-22 10:29:06 +01:00
Eric Mastro 48eba1fe27 Clear active slots by host
Allow for clearing of active slots by host, by incrementing an mapping index. The new index points to a fresh instance of EnumerableSet, effectively wiping it clean.
2022-12-22 10:29:06 +01:00
Eric Mastro 47bf5d37cf remove slot from waitUntilStarted signature 2022-12-22 10:29:06 +01:00
Eric Mastro b2de745d9a add tests for active slots 2022-12-22 10:29:06 +01:00
Eric Mastro 61b8f5fc35
[test] Remove lastSlot return from waitUntilStarted
This is a remnant from a staggered ending of slots. All slots will end at the request end time now, and thus this is no longer needed.
2022-10-26 13:37:30 +11:00
Eric Mastro 4a470c7dc7
[marketplace] improve requestEnd to check all states
There may be cases where the the request end is not accurate as the state of the request hasn’t yet been updated. For example, when a request is cancelled, the request end would not have been updated to be in the past, and would still be set for the end of the request (which could be in the future).
2022-10-26 13:36:32 +11:00
Mark Spanbroek 9a6a321d5b [marketplace] Add method to get request end time 2022-10-25 14:49:37 +02:00
Eric Mastro 51a02c09ba
[marketplace] remove request from list of active requests 2022-10-25 13:06:52 +11:00
Eric Mastro 29dcfb52b4
[marketplace] formatting
reformatting using prettier
2022-10-25 13:04:16 +11:00
Eric Mastro b2f9e07c56
[marketplace] add list of active requests 2022-10-25 13:00:48 +11:00
Eric Mastro bac2675bb2 set proof end when storage requested
1. set proof end to now + duration when storage is requested
2. set proof end to past when contract is failed
3. add back proof end mappings
2022-10-25 12:38:19 +11:00
Eric Mastro fd74268a8a Remove proof extension, test clean up
1. Remove proof extension as it is not needed. Host are required to provide proofs from the moment they fill a slot, for the duration specified by the contract. This means that the ending of their requirements will be staggered at the end, as they were at the start, but this is more predicable for determining the cost of a request.
2. The proof end time was modified so that if the request state is not accepting proofs, it takes the min of the slot proof end time, the request end time, or block.timestamp - 1, which ensures that it returns a time in the past. If the slot is accepting proofs, it returns the slot end time.
3. Modify marketplace tests so that `waitUntilFinished` advances time to the proof ending of the last slot filled.
2022-10-25 12:38:19 +11:00
Eric Mastro 321132b6fa clean up tests
1. Replace all instances of `now()` with `await currentTime()` to get a more accurate representation of time from the block timestamp. Update examples.js to be async.
2. Move `RequestState` to `marketplace.js`
3. Delete `TestStorage` as `slashAmount` function no longer needed.
2022-10-25 12:38:19 +11:00
Eric Mastro ad040cfee6 [marketplace] extend proof ending
Allow proof ending to be extending once a contract is started, so that all filled slots share an ending time that is equal to the contract end time. Added tests.

Add a mapping for proof id to endId so that proof expectations can be extended for all proofs that share a given endId.

Add function modifiers that require the request state to allow proofs, with accompanying tests.

General clean up of each function’s request state context, with accompanying tests.

General clean up of all tests, including state change “wait” functions and normalising the time advancement functions.
2022-10-25 12:38:19 +11:00
Eric Mastro 1fff2f7295 [marketplace] add isFinished
Add function `isFinished` that checks whethere the state has been set to `RequestState.Finished` (which is not being set yet) or if the contract was started (`RequestState.Started`) and the contract duration has lapsed.

To facilitate `isFinished`, the contract start time (`startedAt`) was added to calculate the contract end time.
2022-10-25 12:38:19 +11:00
Eric Mastro 2170d6bd19 [marketplace] tests for Failed state 2022-10-25 12:38:19 +11:00
Eric Mastro 08e73d9348 [marketplace] Add tests for freeing a slot 2022-10-25 12:38:19 +11:00
Eric Mastro 087c13a7fc update fillSlot and freeSlot state requirements
`fillSlot` and `freeSlot` must both be in a state of New or Started and not Cancelled (Finished to be added later).

Update tests to support the above.
2022-09-21 20:52:44 +10:00
Eric Mastro 1b216f6655 slash first then check collateral threshold
Once a proof is marked as missing, if that missing proof is enough to slash a host, first slash the host, then check the hosts balance. If the balance has dropped below the minimum allowable collateral threshold, then remove them from the slot.
2022-09-21 20:52:44 +10:00
Eric Mastro 9050a0d52d [marketplace] address PR comments
- reordered some tests
- add RequestState export
- change test descriptions to start with “it”
2022-09-21 20:52:44 +10:00
Eric Mastro 7726db2a8d modify collateral threshold test to remove TestStorage dep 2022-09-21 20:52:44 +10:00
Eric Mastro 2b8c8fc42a [marketplace] tests for Failed state 2022-09-21 20:52:44 +10:00
Eric Mastro 980647876f [marketplace] update contract state to failed
Update contract state to failed when too many slots have been freed.
2022-09-21 20:52:44 +10:00
Eric Mastro 9f8affdcaa [marketplace] Add tests for freeing a slot 2022-09-21 20:52:44 +10:00
Eric Mastro 716b864f02 [marketplace] update state getter
Update `Marketplace.state` getter to to take `isCancelled` into account. This state can then be used internally and externally.

Add checks to `proofEnd`, `isProofRequired`, `willProofBeRequired`, and `getChallenge` that understands if the request is in a state to accept proofs. If not, return other values.

Add `slotMustAcceptProofs` modifier, originally introduced in a later PR, which requires the request to be in state of the request accepting proofs.

Add tests for all the above.
2022-09-20 15:59:03 +10:00
Eric Mastro 8be756808c [marketplace] address various PR comments
- Remove `FundsWithdrawn` event
- do not copy request to memory
- todo for changing withdraw amount to not include proof payments
- test lock expiry border
- in tests, move `RequestState` to exported const in marketplace.js
- move test for state checks on `fillSlot` to the “filling a slot” section.
2022-09-20 15:59:03 +10:00
Eric Mastro b580ffd8a3 [refactor] do not expose cancelled logic externally 2022-09-20 15:59:03 +10:00