Skip to content

Commit

Permalink
chore: update dependencies, especially nim-ethers to chronos v4 compa…
Browse files Browse the repository at this point in the history
…tible 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
  • Loading branch information
emizzle authored Oct 30, 2024
1 parent 942f940 commit 2b5a405
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 64 deletions.
10 changes: 5 additions & 5 deletions codex/contracts/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
discard await token.increaseAllowance(market.contract.address(), amount).confirm(0)

method getZkeyHash*(market: OnChainMarket): Future[?string] {.async.} =
let config = await market.contract.config()
let config = await market.contract.configuration()
return some config.proofs.zkeyHash

method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
Expand All @@ -65,18 +65,18 @@ method getSigner*(market: OnChainMarket): Future[Address] {.async.} =

method periodicity*(market: OnChainMarket): Future[Periodicity] {.async.} =
convertEthersError:
let config = await market.contract.config()
let config = await market.contract.configuration()
let period = config.proofs.period
return Periodicity(seconds: period)

method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} =
convertEthersError:
let config = await market.contract.config()
let config = await market.contract.configuration()
return config.proofs.timeout

method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} =
convertEthersError:
let config = await market.contract.config()
let config = await market.contract.configuration()
return config.proofs.downtime

method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} =
Expand Down Expand Up @@ -176,7 +176,7 @@ method fillSlot(market: OnChainMarket,

method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} =
convertEthersError:
var freeSlot: Future[?TransactionResponse]
var freeSlot: Future[Confirmable]
if rewardRecipient =? market.rewardRecipient:
# If --reward-recipient specified, use it as the reward recipient, and use
# the SP's address as the collateral recipient
Expand Down
20 changes: 10 additions & 10 deletions codex/contracts/marketplace.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ export requests
type
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 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): ?TransactionResponse {.contract.}
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof): ?TransactionResponse {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId): ?TransactionResponse {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId, withdrawAddress: Address): ?TransactionResponse {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId): ?TransactionResponse {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId, rewardRecipient: Address, collateralRecipient: Address): ?TransactionResponse {.contract.}
proc requestStorage*(marketplace: Marketplace, request: StorageRequest): Confirmable {.contract.}
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof): Confirmable {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId): Confirmable {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId, withdrawAddress: Address): Confirmable {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId): Confirmable {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId, rewardRecipient: Address, collateralRecipient: Address): Confirmable {.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.}
Expand All @@ -49,8 +49,8 @@ proc willProofBeRequired*(marketplace: Marketplace, id: SlotId): bool {.contract
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: Groth16Proof): ?TransactionResponse {.contract.}
proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): ?TransactionResponse {.contract.}
proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): Confirmable {.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.}
6 changes: 3 additions & 3 deletions codex/node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,15 @@ proc stop*(self: CodexNodeRef) {.async.} =
if not self.discovery.isNil:
await self.discovery.stop()

if not self.clock.isNil:
await self.clock.stop()

if clientContracts =? self.contracts.client:
await clientContracts.stop()

if hostContracts =? self.contracts.host:
await hostContracts.stop()

if not self.clock.isNil:
await self.clock.stop()

if validatorContracts =? self.contracts.validator:
await validatorContracts.stop()

Expand Down
54 changes: 26 additions & 28 deletions codex/utils/asyncstatemachine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,28 @@ proc onError(machine: Machine, error: ref CatchableError): Event =
state.onError(error)

proc run(machine: Machine, state: State) {.async.} =
try:
if next =? await state.run(machine):
machine.schedule(Event.transition(state, next))
except CancelledError:
discard
if next =? await state.run(machine):
machine.schedule(Event.transition(state, next))

proc scheduler(machine: Machine) {.async.} =
var running: Future[void]
try:
while machine.started:
let event = await machine.scheduled.get().track(machine)
if next =? event(machine.state):
if not running.isNil and not running.finished:
await running.cancelAndWait()
let fromState = if machine.state.isNil: "<none>" else: $machine.state
machine.state = next
debug "enter state", state = fromState & " => " & $machine.state
running = machine.run(machine.state)
running
.track(machine)
.catch((err: ref CatchableError) =>
machine.schedule(machine.onError(err))
)
except CancelledError:
discard
while machine.started:
let event = await machine.scheduled.get().track(machine)
if next =? event(machine.state):
if not running.isNil and not running.finished:
trace "cancelling current state", state = $machine.state
await running.cancelAndWait()
let fromState = if machine.state.isNil: "<none>" else: $machine.state
machine.state = next
debug "enter state", state = fromState & " => " & $machine.state
running = machine.run(machine.state)
running
.track(machine)
.cancelled(proc() = trace "state.run cancelled, swallowing", state = $machine.state)
.catch(proc(err: ref CatchableError) =
trace "error caught in state.run, calling state.onError", state = $machine.state
machine.schedule(machine.onError(err))
)

proc start*(machine: Machine, initialState: State) =
if machine.started:
Expand All @@ -93,12 +90,13 @@ proc start*(machine: Machine, initialState: State) =
machine.scheduled = newAsyncQueue[Event]()

machine.started = true
machine.scheduler()
.track(machine)
.catch((err: ref CatchableError) =>
error("Error in scheduler", error = err.msg)
)
machine.schedule(Event.transition(machine.state, initialState))
try:
discard machine.scheduler().track(machine)
machine.schedule(Event.transition(machine.state, initialState))
except CancelledError as e:
discard
except CatchableError as e:
error("Error in scheduler", error = e.msg)

proc stop*(machine: Machine) {.async.} =
if not machine.started:
Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/testContracts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ethersuite "Marketplace contracts":
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())

let config = await marketplace.config()
let config = await marketplace.configuration()
periodicity = Periodicity(seconds: config.proofs.period)

request = StorageRequest.example
Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/testDeployment.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ../checktest
type MockProvider = ref object of Provider
chainId*: UInt256

method getChainId*(provider: MockProvider): Future[UInt256] {.async.} =
method getChainId*(provider: MockProvider): Future[UInt256] {.async: (raises:[ProviderError]).} =
return provider.chainId

proc configFactory(): CodexConf =
Expand Down
6 changes: 3 additions & 3 deletions tests/contracts/testMarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ethersuite "On-Chain Market":
setup:
let address = Marketplace.address(dummyVerifier = true)
marketplace = Marketplace.new(address, ethProvider.getSigner())
let config = await marketplace.config()
let config = await marketplace.configuration()
hostRewardRecipient = accounts[2]

market = OnChainMarket.new(marketplace)
Expand Down Expand Up @@ -76,13 +76,13 @@ ethersuite "On-Chain Market":

test "can retrieve proof periodicity":
let periodicity = await market.periodicity()
let config = await marketplace.config()
let config = await marketplace.configuration()
let periodLength = config.proofs.period
check periodicity.seconds == periodLength

test "can retrieve proof timeout":
let proofTimeout = await market.proofTimeout()
let config = await marketplace.config()
let config = await marketplace.configuration()
check proofTimeout == config.proofs.timeout

test "supports marketplace requests":
Expand Down
1 change: 1 addition & 0 deletions tests/contracts/time.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pkg/ethers
import pkg/serde/json

proc currentTime*(provider: Provider): Future[UInt256] {.async.} =
return (!await provider.getBlock(BlockTag.pending)).timestamp
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/marketplacesuite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ template marketplacesuite*(name: string, body: untyped) =
marketplace = Marketplace.new(Marketplace.address, ethProvider.getSigner())
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
let config = await mp.config(marketplace)
let config = await marketplace.configuration()
period = config.proofs.period.truncate(uint64)
periodicity = Periodicity(seconds: period.u256)

Expand Down
11 changes: 6 additions & 5 deletions tests/tools/cirdl/testcirdl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import std/os
import std/osproc
import std/options
import pkg/chronos
import codex/contracts
import ../../integration/marketplacesuite
import pkg/codex/contracts
import ../../asynctest
import ../../contracts/deployment

marketplacesuite "tools/cirdl":
suite "tools/cirdl":
const
cirdl = "build" / "cirdl"
workdir = "."
Expand All @@ -14,11 +15,11 @@ marketplacesuite "tools/cirdl":
let
circuitPath = "testcircuitpath"
rpcEndpoint = "ws://localhost:8545"
marketplaceAddress = $marketplace.address
marketplaceAddress = Marketplace.address

discard existsOrCreateDir(circuitPath)

let args = [circuitPath, rpcEndpoint, marketplaceAddress]
let args = [circuitPath, rpcEndpoint, $marketplaceAddress]

let process = osproc.startProcess(
cirdl,
Expand Down
2 changes: 1 addition & 1 deletion tools/cirdl/cirdl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc getCircuitHash(rpcEndpoint: string, marketplaceAddress: string): Future[?!s
return failure("Invalid address: " & marketplaceAddress)

let marketplace = Marketplace.new(address, provider)
let config = await marketplace.config()
let config = await marketplace.configuration()
return success config.proofs.zkeyHash

proc formatUrl(hash: string): string =
Expand Down
2 changes: 1 addition & 1 deletion vendor/codex-contracts-eth
2 changes: 1 addition & 1 deletion vendor/nim-ethers
2 changes: 1 addition & 1 deletion vendor/nim-json-rpc
Submodule nim-json-rpc updated 47 files
+34 −10 .github/workflows/ci.yml
+83 −65 README.md
+9 −0 config.nims
+24 −15 json_rpc.nimble
+233 −160 json_rpc/client.nim
+122 −55 json_rpc/clients/httpclient.nim
+87 −20 json_rpc/clients/socketclient.nim
+16 −116 json_rpc/clients/websocketclient.nim
+155 −0 json_rpc/clients/websocketclientimpl.nim
+29 −2 json_rpc/errors.nim
+23 −280 json_rpc/jsonmarshal.nim
+163 −0 json_rpc/private/client_handler_wrapper.nim
+321 −0 json_rpc/private/jrpc_sys.nim
+319 −0 json_rpc/private/server_handler_wrapper.nim
+70 −0 json_rpc/private/shared_wrapper.nim
+199 −119 json_rpc/router.nim
+9 −0 json_rpc/rpcclient.nim
+22 −7 json_rpc/rpcproxy.nim
+0 −3 json_rpc/rpcsecureserver.nim
+9 −0 json_rpc/rpcserver.nim
+61 −8 json_rpc/server.nim
+81 −31 json_rpc/servers/httpserver.nim
+41 −22 json_rpc/servers/socketserver.nim
+61 −25 json_rpc/servers/websocketserver.nim
+9 −0 nim.cfg
+16 −1 tests/all.nim
+0 −12 tests/helpers.nim
+3 −12 tests/private/ethcallsigs.nim
+44 −27 tests/private/ethhexstrings.nim
+27 −9 tests/private/ethprocs.nim
+1 −1 tests/private/ethtypes.nim
+11 −0 tests/private/file_callsigs.nim
+19 −0 tests/private/helpers.nim
+44 −0 tests/private/stintjson.nim
+0 −32 tests/stintjson.nim
+145 −0 tests/test_batch_call.nim
+154 −0 tests/test_callsigs.nim
+302 −0 tests/test_client_hook.nim
+255 −0 tests/test_jrpc_sys.nim
+146 −0 tests/test_router_rpc.nim
+42 −14 tests/testethcalls.nim
+24 −13 tests/testhook.nim
+44 −16 tests/testhttp.nim
+27 −17 tests/testhttps.nim
+19 −11 tests/testproxy.nim
+106 −35 tests/testrpcmacro.nim
+40 −13 tests/testserverclient.nim
2 changes: 1 addition & 1 deletion vendor/nim-json-serialization

0 comments on commit 2b5a405

Please sign in to comment.