mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-10 22:55:47 +00:00
d56eb6aee1
* [contracts] Add SlotFreed event * [integration] allow test node to be stopped twice * [cli] add --validator option * [contracts] remove dead code * [contracts] instantiate OnChainMarket and OnChainClock only once * [contracts] add Validation * [sales] remove duplicate import * [market] add missing import * [market] subscribe to all SlotFilled events * [market] add freeSlot() * [sales] fix warnings * [market] subscribe to SlotFreed events * [contracts] fix warning * [validator] keep track of filled slots * [validation] remove slots that have ended * [proving] absorb Proofs into Market Both Proofs and Market are abstractions around the Marketplace contract, having them separately is more trouble than it's worth at the moment. * [market] add markProofAsMissing() * [clock] speed up waiting for clock in tests * [validator] mark proofs as missing * [timer] fix error on node shutdown * [cli] handle --persistence and --validator separately * [market] allow retrieval of proof timeout value * [validator] do not subscribe to SlotFreed events Freed slots are already handled in removeSlotsThatHaveEnded(), and onSlotsFreed() interfered with its iterator. * [validator] Start validation at the start of a new period To decrease the likelihood that we hit the validation timeout. * [validator] do not mark proofs as missing after timeout * [market] check whether proof can be marked as missing * [validator] simplify validation Simulate a transaction to mark proof as missing, instead of trying to keep track of all the conditions that may lead to a proof being marked as missing. * [build] use nim-ethers PR #40 Uses "pending" blocktag instead of "latest" blocktag for better simulation of transactions before sending them. https://github.com/status-im/nim-ethers/pull/40 * [integration] integration test for validator * [validator] monitor a maximum number of slots Adds cli parameter --validator-max-slots. * [market] fix missing collateral argument After rebasing, add the new argument to fillSlot calls. * [build] update to nim-ethers 0.2.5 * [validator] use Set instead of Table to keep track of slots * [validator] add logging * [validator] add test for slot failure * [market] use "pending" blocktag to use more up to date block time * [contracts] remove unused import * [validator] fix: wait until after period ends The smart contract checks that 'end < block.timestamp', so we need to wait until the block timestamp is greater than the period end.
70 lines
3.0 KiB
Nim
70 lines
3.0 KiB
Nim
import pkg/ethers
|
|
import pkg/ethers/erc20
|
|
import pkg/json_rpc/rpcclient
|
|
import pkg/stint
|
|
import pkg/chronos
|
|
import ../clock
|
|
import ./requests
|
|
import ./config
|
|
|
|
export stint
|
|
export ethers
|
|
export erc20
|
|
export config
|
|
export requests
|
|
|
|
type
|
|
Marketplace* = ref object of Contract
|
|
StorageRequested* = object of Event
|
|
requestId*: RequestId
|
|
ask*: StorageAsk
|
|
SlotFilled* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
slotIndex* {.indexed.}: UInt256
|
|
slotId*: SlotId
|
|
SlotFreed* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
slotId*: SlotId
|
|
RequestFulfilled* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
RequestCancelled* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
RequestFailed* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
ProofSubmitted* = object of Event
|
|
id*: SlotId
|
|
proof*: seq[byte]
|
|
|
|
|
|
proc config*(marketplace: Marketplace): MarketplaceConfig {.contract, view.}
|
|
proc token*(marketplace: Marketplace): Address {.contract, view.}
|
|
proc slashMisses*(marketplace: Marketplace): UInt256 {.contract, view.}
|
|
proc slashPercentage*(marketplace: Marketplace): UInt256 {.contract, view.}
|
|
proc minCollateralThreshold*(marketplace: Marketplace): UInt256 {.contract, view.}
|
|
|
|
proc requestStorage*(marketplace: Marketplace, request: StorageRequest) {.contract.}
|
|
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: seq[byte]) {.contract.}
|
|
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId) {.contract.}
|
|
proc freeSlot*(marketplace: Marketplace, id: SlotId) {.contract.}
|
|
proc getRequest*(marketplace: Marketplace, id: RequestId): StorageRequest {.contract, view.}
|
|
proc getHost*(marketplace: Marketplace, id: SlotId): Address {.contract, view.}
|
|
proc getActiveSlot*(marketplace: Marketplace, id: SlotId): Slot {.contract, view.}
|
|
|
|
proc myRequests*(marketplace: Marketplace): seq[RequestId] {.contract, view.}
|
|
proc mySlots*(marketplace: Marketplace): seq[SlotId] {.contract, view.}
|
|
proc requestState*(marketplace: Marketplace, requestId: RequestId): RequestState {.contract, view.}
|
|
proc slotState*(marketplace: Marketplace, slotId: SlotId): SlotState {.contract, view.}
|
|
proc requestEnd*(marketplace: Marketplace, requestId: RequestId): SecondsSince1970 {.contract, view.}
|
|
|
|
proc proofTimeout*(marketplace: Marketplace): UInt256 {.contract, view.}
|
|
|
|
proc proofEnd*(marketplace: Marketplace, id: SlotId): UInt256 {.contract, view.}
|
|
proc missingProofs*(marketplace: Marketplace, id: SlotId): UInt256 {.contract, view.}
|
|
proc isProofRequired*(marketplace: Marketplace, id: SlotId): bool {.contract, view.}
|
|
proc willProofBeRequired*(marketplace: Marketplace, id: SlotId): bool {.contract, view.}
|
|
proc getChallenge*(marketplace: Marketplace, id: SlotId): array[32, byte] {.contract, view.}
|
|
proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.}
|
|
|
|
proc submitProof*(marketplace: Marketplace, id: SlotId, proof: seq[byte]) {.contract.}
|
|
proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256) {.contract.}
|