mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-09 18:36:29 +00:00
92a0eda79a
* adds a new overload of queryPastEvents allowing to query past events based on timestamp in the past * adds state restoration to validator * refactors a bit to get the tests back to work * replaces deprecated generic methods from Market with methods for specific event types * Refactors binary search * adds market tests for querying past SlotFilled events and binary search * Takes into account that <<earliest>> block available is not necessarily the genesis block * Adds more logging and makes testing earliest block boundary more reliable * adds validation tests for historical state restoration * adds mockprovider to simplify and improve testing of the edge conditions * adds slot reservation to the new tests after rebasing * adds validation groups and group index in logs of validator * adds integration test with two validators * adds comment on how to enable logging in integration test executable itself * testIntegration: makes list is running nodes injected and available in the body of the test * validation: adds integration test for historical state * adds more logging to validator * integration test: validator only looks 30 days back for historical state * adds logging of the slotState when removing slots during validation * review and refactor validator integration tests * adds validation to the set of integration tests * Fixes mistyped name of the mock provider module in testMarket * Fixes a typo in the name of the validation suite in integration tests * Makes validation unit test a bit easier to follow * better use of logScopes to reduce duplication * improves timing and clarifies the test conditions * uses http as default RPC provider for nodes running in integration tests as a workaround for dropped subscriptions * simplifies the validation integration tests by waiting for failed request instead of tracking slots * adds config option allowing selectively to set different provider url * Brings back the default settings for RPC provider in integration tests * use http RPC provider for clients in validation integration tests * fine-tune the tests * Makes validator integration test more robust - adds extra tracking * brings tracking of marketplace event back to validator integration test * refactors integration tests * deletes tmp file * adds <<return>> after forcing integration test to fail preliminarily * re-enables all integration tests and matrix * stops debug output in CI * allows to choose a different RPC provider for a given integration test suite * fixes signature of <<getBlock>> method in mockProvider * adds missing import which seem to be braking integration tests on windows * makes sure that clients, SPs, and validators use the same provider url * makes validator integration tests using http at 127.0.0.1:8545 * testvalidator: stop resubscribing as we are now using http polling as rpc provider * applying review comments * groups queryPastStorage overrides together (review comment) * groups the historical validation tests into a sub suite * removes the temporary extensions in marketplacesuite and multinodesuite allowing to specify provider url * simplifies validation integration tests * Removes debug logs when waiting for request to fail * Renaming waitForRequestFailed => waitForRequestToFail * renames blockNumberForBlocksAgo to pastBlockTag and makes it private * removes redundant debugging logs * refines logging in validation * removes dev logging from mockmarket * improves exception handling in provider helper procs and prepares for extraction to a separate module * Uses chronos instead of std/times for Duration * extracts provider and binary search helpers to a separate module * removes redundant log entry params from validator * unifies the notation to consistently use method call syntax * reuses ProviderError from nim-ethers in the provider extension * clarifies the comment in multinodesuite * uses == operator to check the predefined tags and raises exception when `BlockTag.pending` is requested. * when waiting for request to fail, we break on any request state that is not Started * removes tests that were moved to testProvider from testMarket * extracts tests that use MockProvider to a separate async suite * improves performance of the historical state restoration * removing redundant log messages in validator (groupIndex and groups) * adds testProvider to testContracts group * removes unused import in testMarket
273 lines
9.5 KiB
Nim
273 lines
9.5 KiB
Nim
import pkg/chronos
|
|
import pkg/upraises
|
|
import pkg/questionable
|
|
import pkg/ethers/erc20
|
|
import ./contracts/requests
|
|
import ./contracts/proofs
|
|
import ./clock
|
|
import ./errors
|
|
import ./periods
|
|
|
|
export chronos
|
|
export questionable
|
|
export requests
|
|
export proofs
|
|
export SecondsSince1970
|
|
export periods
|
|
|
|
type
|
|
Market* = ref object of RootObj
|
|
MarketError* = object of CodexError
|
|
Subscription* = ref object of RootObj
|
|
OnRequest* = proc(id: RequestId,
|
|
ask: StorageAsk,
|
|
expiry: UInt256) {.gcsafe, upraises:[].}
|
|
OnFulfillment* = proc(requestId: RequestId) {.gcsafe, upraises: [].}
|
|
OnSlotFilled* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises:[].}
|
|
OnSlotFreed* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises: [].}
|
|
OnSlotReservationsFull* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises: [].}
|
|
OnRequestCancelled* = proc(requestId: RequestId) {.gcsafe, upraises:[].}
|
|
OnRequestFailed* = proc(requestId: RequestId) {.gcsafe, upraises:[].}
|
|
OnProofSubmitted* = proc(id: SlotId) {.gcsafe, upraises:[].}
|
|
ProofChallenge* = array[32, byte]
|
|
|
|
# Marketplace events -- located here due to the Market abstraction
|
|
MarketplaceEvent* = Event
|
|
StorageRequested* = object of MarketplaceEvent
|
|
requestId*: RequestId
|
|
ask*: StorageAsk
|
|
expiry*: UInt256
|
|
SlotFilled* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
slotIndex*: UInt256
|
|
SlotFreed* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
slotIndex*: UInt256
|
|
SlotReservationsFull* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
slotIndex*: UInt256
|
|
RequestFulfilled* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
RequestCancelled* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
RequestFailed* = object of MarketplaceEvent
|
|
requestId* {.indexed.}: RequestId
|
|
ProofSubmitted* = object of MarketplaceEvent
|
|
id*: SlotId
|
|
|
|
method getZkeyHash*(market: Market): Future[?string] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getSigner*(market: Market): Future[Address] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method periodicity*(market: Market): Future[Periodicity] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method proofTimeout*(market: Market): Future[UInt256] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method repairRewardPercentage*(market: Market): Future[uint8] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method proofDowntime*(market: Market): Future[uint8] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getPointer*(market: Market, slotId: SlotId): Future[uint8] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
proc inDowntime*(market: Market, slotId: SlotId): Future[bool] {.async.} =
|
|
let downtime = await market.proofDowntime
|
|
let pntr = await market.getPointer(slotId)
|
|
return pntr < downtime
|
|
|
|
method requestStorage*(market: Market,
|
|
request: StorageRequest) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method mySlots*(market: Market): Future[seq[SlotId]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getRequest*(market: Market,
|
|
id: RequestId):
|
|
Future[?StorageRequest] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method requestState*(market: Market,
|
|
requestId: RequestId): Future[?RequestState] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method slotState*(market: Market,
|
|
slotId: SlotId): Future[SlotState] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getRequestEnd*(market: Market,
|
|
id: RequestId): Future[SecondsSince1970] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method requestExpiresAt*(market: Market,
|
|
id: RequestId): Future[SecondsSince1970] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getHost*(market: Market,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256): Future[?Address] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getActiveSlot*(
|
|
market: Market,
|
|
slotId: SlotId): Future[?Slot] {.base, async.} =
|
|
|
|
raiseAssert("not implemented")
|
|
|
|
method fillSlot*(market: Market,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256,
|
|
proof: Groth16Proof,
|
|
collateral: UInt256) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method freeSlot*(market: Market, slotId: SlotId) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method withdrawFunds*(market: Market,
|
|
requestId: RequestId) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeRequests*(market: Market,
|
|
callback: OnRequest):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method isProofRequired*(market: Market,
|
|
id: SlotId): Future[bool] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method willProofBeRequired*(market: Market,
|
|
id: SlotId): Future[bool] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method getChallenge*(market: Market, id: SlotId): Future[ProofChallenge] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method submitProof*(market: Market,
|
|
id: SlotId,
|
|
proof: Groth16Proof) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method markProofAsMissing*(market: Market,
|
|
id: SlotId,
|
|
period: Period) {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method canProofBeMarkedAsMissing*(market: Market,
|
|
id: SlotId,
|
|
period: Period): Future[bool] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method reserveSlot*(
|
|
market: Market,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256) {.base, async.} =
|
|
|
|
raiseAssert("not implemented")
|
|
|
|
method canReserveSlot*(
|
|
market: Market,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256): Future[bool] {.base, async.} =
|
|
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeFulfillment*(market: Market,
|
|
callback: OnFulfillment):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeFulfillment*(market: Market,
|
|
requestId: RequestId,
|
|
callback: OnFulfillment):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeSlotFilled*(market: Market,
|
|
callback: OnSlotFilled):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeSlotFilled*(market: Market,
|
|
requestId: RequestId,
|
|
slotIndex: UInt256,
|
|
callback: OnSlotFilled):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeSlotFreed*(market: Market,
|
|
callback: OnSlotFreed):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeSlotReservationsFull*(
|
|
market: Market,
|
|
callback: OnSlotReservationsFull): Future[Subscription] {.base, async.} =
|
|
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeRequestCancelled*(market: Market,
|
|
callback: OnRequestCancelled):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeRequestCancelled*(market: Market,
|
|
requestId: RequestId,
|
|
callback: OnRequestCancelled):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeRequestFailed*(market: Market,
|
|
callback: OnRequestFailed):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeRequestFailed*(market: Market,
|
|
requestId: RequestId,
|
|
callback: OnRequestFailed):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method subscribeProofSubmission*(market: Market,
|
|
callback: OnProofSubmitted):
|
|
Future[Subscription] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method unsubscribe*(subscription: Subscription) {.base, async, upraises:[].} =
|
|
raiseAssert("not implemented")
|
|
|
|
method queryPastSlotFilledEvents*(
|
|
market: Market,
|
|
fromBlock: BlockTag): Future[seq[SlotFilled]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method queryPastSlotFilledEvents*(
|
|
market: Market,
|
|
blocksAgo: int): Future[seq[SlotFilled]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method queryPastSlotFilledEvents*(
|
|
market: Market,
|
|
fromTime: SecondsSince1970): Future[seq[SlotFilled]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method queryPastStorageRequestedEvents*(
|
|
market: Market,
|
|
fromBlock: BlockTag): Future[seq[StorageRequested]] {.base, async.} =
|
|
raiseAssert("not implemented")
|
|
|
|
method queryPastStorageRequestedEvents*(
|
|
market: Market,
|
|
blocksAgo: int): Future[seq[StorageRequested]] {.base, async.} =
|
|
raiseAssert("not implemented")
|