chore: update dependencies, especially nim-ethers to chronos v4 compatible version (#968)

* chore: bump dependencies, including nim-ethers with chronos v4 support

Bumps the following dependencies:
- nim-ethers to commit 507ac6a4cc71cec9be7693fa393db4a49b52baf9 which contains a pinned nim-eth version. This is to be replaced by a versioned library, so it will be pinned to a particular version. There is a crucial fix in this version of ethers that fixes nonce management which is causing issues in the Codex testnet.
- nim-json-rpc to v0.4.4
- nim-json-serialization to v0.2.8
- nim-serde to v1.2.2
- nim-serialization to v0.2.4

Currently, one of the integration tests is failing.

* fix integration test

- When a state's run was cancelled, it was being caught as an error due to catching all CatchableErrors. This caused a state transition to SaleErrored, however cancellation of run was not actually an error. Handling this correctly fixed the issue.
- Stopping of the clock was moved to after `HostInteractions` (sales) which avoided an assertion around getting time when the clock was not started.

* bump ethers to include nonce fix and filter not found fix

* bump ethers: fixes missing symbol not exported in ethers

* Fix cirdl test imports/exports

* Debugging in ci

* Handle CancelledErrors for state.run in one place only

* Rename `config` to `configuration`

There was a symbol clash preventing compilation and it was easiest to rename `config` to `configuration` in the contracts. Not even remotely ideal, but it was the only way.

* bump ethers to latest

Prevents an issue were `JsonNode.items` symbol could not be found

* More changes to support `config` > `configuration`

* cleanup

* testing to see if this fixes failure in ci

* bumps contracts

- ensures slot is free before allowing reservation
- renames config to configuration to avoid symbol clash
This commit is contained in:
Eric 2024-10-30 21:40:17 +11:00 committed by GitHub
parent 942f940c92
commit 2b5a40559e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 64 additions and 64 deletions

View File

@ -56,7 +56,7 @@ proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
discard await token.increaseAllowance(market.contract.address(), amount).confirm(0) discard await token.increaseAllowance(market.contract.address(), amount).confirm(0)
method getZkeyHash*(market: OnChainMarket): Future[?string] {.async.} = method getZkeyHash*(market: OnChainMarket): Future[?string] {.async.} =
let config = await market.contract.config() let config = await market.contract.configuration()
return some config.proofs.zkeyHash return some config.proofs.zkeyHash
method getSigner*(market: OnChainMarket): Future[Address] {.async.} = method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
@ -65,18 +65,18 @@ method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
method periodicity*(market: OnChainMarket): Future[Periodicity] {.async.} = method periodicity*(market: OnChainMarket): Future[Periodicity] {.async.} =
convertEthersError: convertEthersError:
let config = await market.contract.config() let config = await market.contract.configuration()
let period = config.proofs.period let period = config.proofs.period
return Periodicity(seconds: period) return Periodicity(seconds: period)
method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} = method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} =
convertEthersError: convertEthersError:
let config = await market.contract.config() let config = await market.contract.configuration()
return config.proofs.timeout return config.proofs.timeout
method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} = method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} =
convertEthersError: convertEthersError:
let config = await market.contract.config() let config = await market.contract.configuration()
return config.proofs.downtime return config.proofs.downtime
method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} = method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} =
@ -176,7 +176,7 @@ method fillSlot(market: OnChainMarket,
method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} = method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} =
convertEthersError: convertEthersError:
var freeSlot: Future[?TransactionResponse] var freeSlot: Future[Confirmable]
if rewardRecipient =? market.rewardRecipient: if rewardRecipient =? market.rewardRecipient:
# If --reward-recipient specified, use it as the reward recipient, and use # If --reward-recipient specified, use it as the reward recipient, and use
# the SP's address as the collateral recipient # the SP's address as the collateral recipient

View File

@ -17,18 +17,18 @@ export requests
type type
Marketplace* = ref object of Contract Marketplace* = ref object of Contract
proc config*(marketplace: Marketplace): MarketplaceConfig {.contract, view.} proc configuration*(marketplace: Marketplace): MarketplaceConfig {.contract, view.}
proc token*(marketplace: Marketplace): Address {.contract, view.} proc token*(marketplace: Marketplace): Address {.contract, view.}
proc slashMisses*(marketplace: Marketplace): UInt256 {.contract, view.} proc slashMisses*(marketplace: Marketplace): UInt256 {.contract, view.}
proc slashPercentage*(marketplace: Marketplace): UInt256 {.contract, view.} proc slashPercentage*(marketplace: Marketplace): UInt256 {.contract, view.}
proc minCollateralThreshold*(marketplace: Marketplace): UInt256 {.contract, view.} proc minCollateralThreshold*(marketplace: Marketplace): UInt256 {.contract, view.}
proc requestStorage*(marketplace: Marketplace, request: StorageRequest): ?TransactionResponse {.contract.} proc requestStorage*(marketplace: Marketplace, request: StorageRequest): Confirmable {.contract.}
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof): ?TransactionResponse {.contract.} proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof): Confirmable {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId): ?TransactionResponse {.contract.} proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId): Confirmable {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId, withdrawAddress: Address): ?TransactionResponse {.contract.} proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId, withdrawAddress: Address): Confirmable {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId): ?TransactionResponse {.contract.} proc freeSlot*(marketplace: Marketplace, id: SlotId): Confirmable {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId, rewardRecipient: Address, collateralRecipient: Address): ?TransactionResponse {.contract.} proc freeSlot*(marketplace: Marketplace, id: SlotId, rewardRecipient: Address, collateralRecipient: Address): Confirmable {.contract.}
proc getRequest*(marketplace: Marketplace, id: RequestId): StorageRequest {.contract, view.} proc getRequest*(marketplace: Marketplace, id: RequestId): StorageRequest {.contract, view.}
proc getHost*(marketplace: Marketplace, id: SlotId): Address {.contract, view.} proc getHost*(marketplace: Marketplace, id: SlotId): Address {.contract, view.}
proc getActiveSlot*(marketplace: Marketplace, id: SlotId): Slot {.contract, view.} proc getActiveSlot*(marketplace: Marketplace, id: SlotId): Slot {.contract, view.}
@ -49,8 +49,8 @@ proc willProofBeRequired*(marketplace: Marketplace, id: SlotId): bool {.contract
proc getChallenge*(marketplace: Marketplace, id: SlotId): array[32, byte] {.contract, view.} proc getChallenge*(marketplace: Marketplace, id: SlotId): array[32, byte] {.contract, view.}
proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.} proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.}
proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): ?TransactionResponse {.contract.} proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): Confirmable {.contract.}
proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): ?TransactionResponse {.contract.} proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): Confirmable {.contract.}
proc reserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): ?TransactionResponse {.contract.} proc reserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): Confirmable {.contract.}
proc canReserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): bool {.contract, view.} proc canReserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): bool {.contract, view.}

View File

@ -757,15 +757,15 @@ proc stop*(self: CodexNodeRef) {.async.} =
if not self.discovery.isNil: if not self.discovery.isNil:
await self.discovery.stop() await self.discovery.stop()
if not self.clock.isNil:
await self.clock.stop()
if clientContracts =? self.contracts.client: if clientContracts =? self.contracts.client:
await clientContracts.stop() await clientContracts.stop()
if hostContracts =? self.contracts.host: if hostContracts =? self.contracts.host:
await hostContracts.stop() await hostContracts.stop()
if not self.clock.isNil:
await self.clock.stop()
if validatorContracts =? self.contracts.validator: if validatorContracts =? self.contracts.validator:
await validatorContracts.stop() await validatorContracts.stop()

View File

@ -59,31 +59,28 @@ proc onError(machine: Machine, error: ref CatchableError): Event =
state.onError(error) state.onError(error)
proc run(machine: Machine, state: State) {.async.} = proc run(machine: Machine, state: State) {.async.} =
try: if next =? await state.run(machine):
if next =? await state.run(machine): machine.schedule(Event.transition(state, next))
machine.schedule(Event.transition(state, next))
except CancelledError:
discard
proc scheduler(machine: Machine) {.async.} = proc scheduler(machine: Machine) {.async.} =
var running: Future[void] var running: Future[void]
try: while machine.started:
while machine.started: let event = await machine.scheduled.get().track(machine)
let event = await machine.scheduled.get().track(machine) if next =? event(machine.state):
if next =? event(machine.state): if not running.isNil and not running.finished:
if not running.isNil and not running.finished: trace "cancelling current state", state = $machine.state
await running.cancelAndWait() await running.cancelAndWait()
let fromState = if machine.state.isNil: "<none>" else: $machine.state let fromState = if machine.state.isNil: "<none>" else: $machine.state
machine.state = next machine.state = next
debug "enter state", state = fromState & " => " & $machine.state debug "enter state", state = fromState & " => " & $machine.state
running = machine.run(machine.state) running = machine.run(machine.state)
running running
.track(machine) .track(machine)
.catch((err: ref CatchableError) => .cancelled(proc() = trace "state.run cancelled, swallowing", state = $machine.state)
machine.schedule(machine.onError(err)) .catch(proc(err: ref CatchableError) =
) trace "error caught in state.run, calling state.onError", state = $machine.state
except CancelledError: machine.schedule(machine.onError(err))
discard )
proc start*(machine: Machine, initialState: State) = proc start*(machine: Machine, initialState: State) =
if machine.started: if machine.started:
@ -93,12 +90,13 @@ proc start*(machine: Machine, initialState: State) =
machine.scheduled = newAsyncQueue[Event]() machine.scheduled = newAsyncQueue[Event]()
machine.started = true machine.started = true
machine.scheduler() try:
.track(machine) discard machine.scheduler().track(machine)
.catch((err: ref CatchableError) => machine.schedule(Event.transition(machine.state, initialState))
error("Error in scheduler", error = err.msg) except CancelledError as e:
) discard
machine.schedule(Event.transition(machine.state, initialState)) except CatchableError as e:
error("Error in scheduler", error = e.msg)
proc stop*(machine: Machine) {.async.} = proc stop*(machine: Machine) {.async.} =
if not machine.started: if not machine.started:

View File

@ -38,7 +38,7 @@ ethersuite "Marketplace contracts":
let tokenAddress = await marketplace.token() let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
let config = await marketplace.config() let config = await marketplace.configuration()
periodicity = Periodicity(seconds: config.proofs.period) periodicity = Periodicity(seconds: config.proofs.period)
request = StorageRequest.example request = StorageRequest.example

View File

@ -9,7 +9,7 @@ import ../checktest
type MockProvider = ref object of Provider type MockProvider = ref object of Provider
chainId*: UInt256 chainId*: UInt256
method getChainId*(provider: MockProvider): Future[UInt256] {.async.} = method getChainId*(provider: MockProvider): Future[UInt256] {.async: (raises:[ProviderError]).} =
return provider.chainId return provider.chainId
proc configFactory(): CodexConf = proc configFactory(): CodexConf =

View File

@ -34,7 +34,7 @@ ethersuite "On-Chain Market":
setup: setup:
let address = Marketplace.address(dummyVerifier = true) let address = Marketplace.address(dummyVerifier = true)
marketplace = Marketplace.new(address, ethProvider.getSigner()) marketplace = Marketplace.new(address, ethProvider.getSigner())
let config = await marketplace.config() let config = await marketplace.configuration()
hostRewardRecipient = accounts[2] hostRewardRecipient = accounts[2]
market = OnChainMarket.new(marketplace) market = OnChainMarket.new(marketplace)
@ -76,13 +76,13 @@ ethersuite "On-Chain Market":
test "can retrieve proof periodicity": test "can retrieve proof periodicity":
let periodicity = await market.periodicity() let periodicity = await market.periodicity()
let config = await marketplace.config() let config = await marketplace.configuration()
let periodLength = config.proofs.period let periodLength = config.proofs.period
check periodicity.seconds == periodLength check periodicity.seconds == periodLength
test "can retrieve proof timeout": test "can retrieve proof timeout":
let proofTimeout = await market.proofTimeout() let proofTimeout = await market.proofTimeout()
let config = await marketplace.config() let config = await marketplace.configuration()
check proofTimeout == config.proofs.timeout check proofTimeout == config.proofs.timeout
test "supports marketplace requests": test "supports marketplace requests":

View File

@ -1,4 +1,5 @@
import pkg/ethers import pkg/ethers
import pkg/serde/json
proc currentTime*(provider: Provider): Future[UInt256] {.async.} = proc currentTime*(provider: Provider): Future[UInt256] {.async.} =
return (!await provider.getBlock(BlockTag.pending)).timestamp return (!await provider.getBlock(BlockTag.pending)).timestamp

View File

@ -85,7 +85,7 @@ template marketplacesuite*(name: string, body: untyped) =
marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner()) marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner())
let tokenAddress = await marketplace.token() let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner()) token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
let config = await mp.config(marketplace) let config = await marketplace.configuration()
period = config.proofs.period.truncate(uint64) period = config.proofs.period.truncate(uint64)
periodicity = Periodicity(seconds: period.u256) periodicity = Periodicity(seconds: period.u256)

View File

@ -2,10 +2,11 @@ import std/os
import std/osproc import std/osproc
import std/options import std/options
import pkg/chronos import pkg/chronos
import codex/contracts import pkg/codex/contracts
import ../../integration/marketplacesuite import ../../asynctest
import ../../contracts/deployment
marketplacesuite "tools/cirdl": suite "tools/cirdl":
const const
cirdl = "build" / "cirdl" cirdl = "build" / "cirdl"
workdir = "." workdir = "."
@ -14,11 +15,11 @@ marketplacesuite "tools/cirdl":
let let
circuitPath = "testcircuitpath" circuitPath = "testcircuitpath"
rpcEndpoint = "ws://localhost:8545" rpcEndpoint = "ws://localhost:8545"
marketplaceAddress = $marketplace.address marketplaceAddress = Marketplace.address
discard existsOrCreateDir(circuitPath) discard existsOrCreateDir(circuitPath)
let args = [circuitPath, rpcEndpoint, marketplaceAddress] let args = [circuitPath, rpcEndpoint, $marketplaceAddress]
let process = osproc.startProcess( let process = osproc.startProcess(
cirdl, cirdl,

View File

@ -34,7 +34,7 @@ proc getCircuitHash(rpcEndpoint: string, marketplaceAddress: string): Future[?!s
return failure("Invalid address: " & marketplaceAddress) return failure("Invalid address: " & marketplaceAddress)
let marketplace = Marketplace.new(address, provider) let marketplace = Marketplace.new(address, provider)
let config = await marketplace.config() let config = await marketplace.configuration()
return success config.proofs.zkeyHash return success config.proofs.zkeyHash
proc formatUrl(hash: string): string = proc formatUrl(hash: string): string =

@ -1 +1 @@
Subproject commit 997696a20e0976011cdbc2f0ff3a844672056ba2 Subproject commit 1ce3d10fa2ed325f4f4d1608434e5c6bd666ce24

2
vendor/nim-ethers vendored

@ -1 +1 @@
Subproject commit 5b170adcb1ffb1dbb273d1b7679bf3d9a08adb76 Subproject commit 6523e70eafecc3b9728a491058818e685bd384fb

2
vendor/nim-json-rpc vendored

@ -1 +1 @@
Subproject commit 0bf2bcbe74a18a3c7a709d57108bb7b51e748a92 Subproject commit 0408795be95c00d75e96eaef6eae8a9c734014f5

@ -1 +1 @@
Subproject commit bb53d49caf2a6c6cf1df365ba84af93cdcfa7aa3 Subproject commit 5127b26ee58076e9369e7c126c196793c2b12e73

2
vendor/nim-serde vendored

@ -1 +1 @@
Subproject commit b1e5e5d39a99ea56b750f6d9272dd319f4ad4291 Subproject commit 83e4a2ccf621d3040c6e7e0267393ca2d205988e

@ -1 +1 @@
Subproject commit 384eb2561ee755446cff512a8e057325848b86a7 Subproject commit f709bd9e16b1b6870fe3e4401196479e014a2ef6