Skip to content

Commit

Permalink
Chronos v4 Update (v3 Compat Mode) (#814)
Browse files Browse the repository at this point in the history
* add changes to use chronos v4 in compat mode

* switch chronos to compat fix branch

* use nimbus-build-system with configurable Nim repo

* add missing imports

* add missing await

* bump compat

* pin nim version in Makefile

* add await instead of asyncSpawn to advertisement queue loop

* bump DHT to v0.5.0

* allow error state of `onBatch` to propagate upwards in test code

* pin Nim compiler commit to avoid fetching stale branch

* make CI build against branch head instead of merge

* fix handling of return values in testslotqueue
  • Loading branch information
gmega authored Jul 18, 2024
1 parent fbce240 commit 4f56f2a
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 25 deletions.
3 changes: 1 addition & 2 deletions codex/blockexchange/engine/discovery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ proc advertiseQueueLoop(b: DiscoveryEngine) {.async.} =
trace "Begin iterating blocks..."
for c in cids:
if cid =? await c:
b.advertiseBlock(cid)
await sleepAsync(100.millis)
await b.advertiseBlock(cid)
trace "Iterating blocks finished."

await sleepAsync(b.advertiseLoopSleep)
Expand Down
2 changes: 1 addition & 1 deletion codex/blocktype.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ./codextypes
export errors, logutils, units, codextypes

type
Block* = object of RootObj
Block* = ref object of RootObj
cid*: Cid
data*: seq[byte]

Expand Down
2 changes: 1 addition & 1 deletion codex/manifest/manifest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import ../logutils
# TODO: Manifest should be reworked to more concrete types,
# perhaps using inheritance
type
Manifest* = object of RootObj
Manifest* = ref object of RootObj
treeCid {.serialize.}: Cid # Root of the merkle tree
datasetSize {.serialize.}: NBytes # Total size of all blocks
blockSize {.serialize.}: NBytes # Size of each contained block (might not be needed if blocks are len-prefixed)
Expand Down
3 changes: 3 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ switch("define", "ctt_asm=false")
# Allow the use of old-style case objects for nim config compatibility
switch("define", "nimOldCaseObjects")

# Enable compat mode for Chronos V4
switch("define", "chronosHandleException")

# begin Nimble config (version 1)
when system.fileExists("nimble.paths"):
include "nimble.paths"
Expand Down
7 changes: 3 additions & 4 deletions tests/codex/sales/testsales.nim
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ asyncchecksuite "Sales":
slot: UInt256,
onBatch: BatchProc): Future[?!void] {.async.} =
let blk = bt.Block.new( @[1.byte] ).get
onBatch( blk.repeat(request.ask.slotSize.truncate(int)) )
return success()
await onBatch( blk.repeat(request.ask.slotSize.truncate(int)) )

createAvailability()
await market.requestStorage(request)
Expand All @@ -337,8 +336,8 @@ asyncchecksuite "Sales":
onBatch: BatchProc): Future[?!void] {.async.} =
slotIndex = slot
let blk = bt.Block.new( @[1.byte] ).get
onBatch(@[ blk ])
return success()
await onBatch(@[ blk ])

let sold = newFuture[void]()
sales.onSale = proc(request: StorageRequest, slotIndex: UInt256) =
sold.complete()
Expand Down
12 changes: 6 additions & 6 deletions tests/codex/sales/testslotqueue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ suite "Slot queue":
request.ask,
request.expiry,
seen = true)
queue.push(item)
check queue.push(item).isOk
check eventually queue.paused
check onProcessSlotCalledWith.len == 0

Expand All @@ -534,7 +534,7 @@ suite "Slot queue":

let request = StorageRequest.example
var items = SlotQueueItem.init(request)
queue.push(items)
check queue.push(items).isOk
# check all items processed
check eventually queue.len == 0

Expand All @@ -546,7 +546,7 @@ suite "Slot queue":
request.expiry,
seen = true)
check queue.paused
queue.push(item0)
check queue.push(item0).isOk
check queue.paused

test "paused queue waits for unpause before continuing processing":
Expand All @@ -558,7 +558,7 @@ suite "Slot queue":
seen = false)
check queue.paused
# push causes unpause
queue.push(item)
check queue.push(item).isOk
# check all items processed
check eventually onProcessSlotCalledWith == @[
(item.requestId, item.slotIndex),
Expand All @@ -576,8 +576,8 @@ suite "Slot queue":
request.ask,
request.expiry,
seen = true)
queue.push(item0)
queue.push(item1)
check queue.push(item0).isOk
check queue.push(item1).isOk
check queue[0].seen
check queue[1].seen

Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/testMarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ ethersuite "On-Chain Market":
receivedIds.add(requestId)

let subscription = await market.subscribeRequestCancelled(request.id, onRequestCancelled)
advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
await advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
await market.withdrawFunds(otherRequest.id)
check receivedIds.len == 0
await market.withdrawFunds(request.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/ethertest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ template ethersuite*(name, body) =

body

export unittest
export asynctest
export ethers except `%`
14 changes: 9 additions & 5 deletions tests/helpers/multisetup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import pkg/chronos

# Allow multiple setups and teardowns in a test suite
template asyncmultisetup* =
var setups: seq[proc: Future[void] {.gcsafe.}]
var teardowns: seq[proc: Future[void] {.gcsafe.}]
var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
var teardowns: seq[
proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]

setup:
for setup in setups:
Expand All @@ -14,10 +15,12 @@ template asyncmultisetup* =
await teardown()

template setup(setupBody) {.inject, used.} =
setups.add(proc {.async.} = setupBody)
setups.add(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = setupBody)

template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc {.async.} = teardownBody)
teardowns.insert(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = teardownBody)

template multisetup* =
var setups: seq[proc() {.gcsafe.}]
Expand All @@ -32,7 +35,8 @@ template multisetup* =
teardown()

template setup(setupBody) {.inject, used.} =
setups.add(proc = setupBody)
let setupProc = proc = setupBody
setups.add(setupProc)

template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc = teardownBody)
1 change: 1 addition & 0 deletions tests/integration/codexprocess.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import pkg/questionable
import pkg/questionable/results
import pkg/confutils
import pkg/chronicles
import pkg/chronos/asyncproc
import pkg/ethers
import pkg/libp2p
import std/os
Expand Down
1 change: 1 addition & 0 deletions tests/integration/hardhatprocess.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import pkg/questionable/results
import pkg/confutils
import pkg/chronicles
import pkg/chronos
import pkg/chronos/asyncproc
import pkg/stew/io2
import std/os
import std/sets
Expand Down
1 change: 1 addition & 0 deletions tests/integration/nodeprocess.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import pkg/questionable
import pkg/questionable/results
import pkg/confutils
import pkg/chronicles
import pkg/chronos/asyncproc
import pkg/libp2p
import std/os
import std/strutils
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-chronos
Submodule nim-chronos updated 94 files
+0 −40 .appveyor.yml
+9 −2 .github/workflows/ci.yml
+28 −32 .github/workflows/doc.yml
+0 −27 .travis.yml
+29 −307 README.md
+7 −3 chronos.nim
+51 −16 chronos.nimble
+3 −0 chronos/apps/http/httpagent.nim
+12 −10 chronos/apps/http/httpbodyrw.nim
+344 −169 chronos/apps/http/httpclient.nim
+135 −39 chronos/apps/http/httpcommon.nim
+13 −3 chronos/apps/http/httpdebug.nim
+709 −625 chronos/apps/http/httpserver.nim
+4 −0 chronos/apps/http/httptable.nim
+95 −101 chronos/apps/http/multipart.nim
+87 −37 chronos/apps/http/shttpserver.nim
+0 −983 chronos/asyncfutures2.nim
+3 −1,632 chronos/asyncloop.nim
+0 −336 chronos/asyncmacro2.nim
+145 −36 chronos/asyncproc.nim
+87 −298 chronos/asyncsync.nim
+140 −0 chronos/bipbuffer.nim
+133 −52 chronos/config.nim
+71 −27 chronos/futures.nim
+121 −57 chronos/handles.nim
+1,277 −0 chronos/internal/asyncengine.nim
+1,874 −0 chronos/internal/asyncfutures.nim
+596 −0 chronos/internal/asyncmacro.nim
+9 −0 chronos/internal/errors.nim
+248 −0 chronos/internal/raisesfutures.nim
+5 −5 chronos/ioselects/ioselectors_epoll.nim
+4 −4 chronos/ioselects/ioselectors_kqueue.nim
+11 −8 chronos/ioselects/ioselectors_poll.nim
+101 −39 chronos/osdefs.nim
+1 −0 chronos/oserrno.nim
+6 −2 chronos/osutils.nim
+2 −2 chronos/ratelimit.nim
+13 −32 chronos/selectors2.nim
+5 −1 chronos/sendfile.nim
+230 −274 chronos/streams/asyncstream.nim
+25 −13 chronos/streams/boundstream.nim
+23 −12 chronos/streams/chunkstream.nim
+107 −94 chronos/streams/tlsstream.nim
+9 −5 chronos/threadsync.nim
+127 −28 chronos/transports/common.nim
+532 −223 chronos/transports/datagram.nim
+2 −2 chronos/transports/osnet.nim
+802 −471 chronos/transports/stream.nim
+5 −4 chronos/unittest2/asynctests.nim
+1 −0 docs/.gitignore
+20 −0 docs/book.toml
+21 −0 docs/examples/cancellation.nim
+28 −0 docs/examples/discards.nim
+15 −0 docs/examples/httpget.nim
+130 −0 docs/examples/middleware.nim
+1 −0 docs/examples/nim.cfg
+38 −0 docs/examples/signalling.nim
+25 −0 docs/examples/timeoutcomposed.nim
+20 −0 docs/examples/timeoutsimple.nim
+24 −0 docs/examples/twogets.nim
+7 −0 docs/open-in.css
+16 −0 docs/src/SUMMARY.md
+123 −0 docs/src/async_procs.md
+214 −0 docs/src/concepts.md
+149 −0 docs/src/error_handling.md
+23 −0 docs/src/examples.md
+19 −0 docs/src/getting_started.md
+102 −0 docs/src/http_server_middleware.md
+50 −0 docs/src/introduction.md
+59 −0 docs/src/porting.md
+18 −0 docs/src/threads.md
+34 −0 docs/src/tips.md
+1 −0 nim.cfg
+18 −6 tests/testall.nim
+63 −0 tests/testasyncstream.c
+488 −483 tests/testasyncstream.nim
+27 −11 tests/testbugs.nim
+748 −235 tests/testdatagram.nim
+1,192 −29 tests/testfut.nim
+496 −182 tests/testhttpclient.nim
+498 −142 tests/testhttpserver.nim
+393 −0 tests/testmacro.nim
+7 −1 tests/testproc.bat
+83 −29 tests/testproc.nim
+9 −1 tests/testproc.sh
+12 −7 tests/testratelimit.nim
+86 −62 tests/testserver.nim
+19 −14 tests/testshttpserver.nim
+74 −66 tests/testsoon.nim
+824 −294 tests/teststream.nim
+2 −2 tests/testsync.nim
+20 −5 tests/testthreadsync.nim
+17 −7 tests/testtime.nim
+1 −6 tests/testutils.nim
2 changes: 1 addition & 1 deletion vendor/nim-http-utils
2 changes: 1 addition & 1 deletion vendor/nimbus-build-system

0 comments on commit 4f56f2a

Please sign in to comment.