Skip to content

Commit 4f56f2a

Browse files
authored
Chronos v4 Update (v3 Compat Mode) (#814)
* 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
1 parent fbce240 commit 4f56f2a

File tree

16 files changed

+33
-25
lines changed

16 files changed

+33
-25
lines changed

codex/blockexchange/engine/discovery.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ proc advertiseQueueLoop(b: DiscoveryEngine) {.async.} =
105105
trace "Begin iterating blocks..."
106106
for c in cids:
107107
if cid =? await c:
108-
b.advertiseBlock(cid)
109-
await sleepAsync(100.millis)
108+
await b.advertiseBlock(cid)
110109
trace "Iterating blocks finished."
111110

112111
await sleepAsync(b.advertiseLoopSleep)

codex/blocktype.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import ./codextypes
3131
export errors, logutils, units, codextypes
3232

3333
type
34-
Block* = object of RootObj
34+
Block* = ref object of RootObj
3535
cid*: Cid
3636
data*: seq[byte]
3737

codex/manifest/manifest.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import ../logutils
2929
# TODO: Manifest should be reworked to more concrete types,
3030
# perhaps using inheritance
3131
type
32-
Manifest* = object of RootObj
32+
Manifest* = ref object of RootObj
3333
treeCid {.serialize.}: Cid # Root of the merkle tree
3434
datasetSize {.serialize.}: NBytes # Total size of all blocks
3535
blockSize {.serialize.}: NBytes # Size of each contained block (might not be needed if blocks are len-prefixed)

config.nims

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ switch("define", "ctt_asm=false")
121121
# Allow the use of old-style case objects for nim config compatibility
122122
switch("define", "nimOldCaseObjects")
123123

124+
# Enable compat mode for Chronos V4
125+
switch("define", "chronosHandleException")
126+
124127
# begin Nimble config (version 1)
125128
when system.fileExists("nimble.paths"):
126129
include "nimble.paths"

tests/codex/sales/testsales.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ asyncchecksuite "Sales":
323323
slot: UInt256,
324324
onBatch: BatchProc): Future[?!void] {.async.} =
325325
let blk = bt.Block.new( @[1.byte] ).get
326-
onBatch( blk.repeat(request.ask.slotSize.truncate(int)) )
327-
return success()
326+
await onBatch( blk.repeat(request.ask.slotSize.truncate(int)) )
328327

329328
createAvailability()
330329
await market.requestStorage(request)
@@ -337,8 +336,8 @@ asyncchecksuite "Sales":
337336
onBatch: BatchProc): Future[?!void] {.async.} =
338337
slotIndex = slot
339338
let blk = bt.Block.new( @[1.byte] ).get
340-
onBatch(@[ blk ])
341-
return success()
339+
await onBatch(@[ blk ])
340+
342341
let sold = newFuture[void]()
343342
sales.onSale = proc(request: StorageRequest, slotIndex: UInt256) =
344343
sold.complete()

tests/codex/sales/testslotqueue.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ suite "Slot queue":
524524
request.ask,
525525
request.expiry,
526526
seen = true)
527-
queue.push(item)
527+
check queue.push(item).isOk
528528
check eventually queue.paused
529529
check onProcessSlotCalledWith.len == 0
530530

@@ -534,7 +534,7 @@ suite "Slot queue":
534534

535535
let request = StorageRequest.example
536536
var items = SlotQueueItem.init(request)
537-
queue.push(items)
537+
check queue.push(items).isOk
538538
# check all items processed
539539
check eventually queue.len == 0
540540

@@ -546,7 +546,7 @@ suite "Slot queue":
546546
request.expiry,
547547
seen = true)
548548
check queue.paused
549-
queue.push(item0)
549+
check queue.push(item0).isOk
550550
check queue.paused
551551

552552
test "paused queue waits for unpause before continuing processing":
@@ -558,7 +558,7 @@ suite "Slot queue":
558558
seen = false)
559559
check queue.paused
560560
# push causes unpause
561-
queue.push(item)
561+
check queue.push(item).isOk
562562
# check all items processed
563563
check eventually onProcessSlotCalledWith == @[
564564
(item.requestId, item.slotIndex),
@@ -576,8 +576,8 @@ suite "Slot queue":
576576
request.ask,
577577
request.expiry,
578578
seen = true)
579-
queue.push(item0)
580-
queue.push(item1)
579+
check queue.push(item0).isOk
580+
check queue.push(item1).isOk
581581
check queue[0].seen
582582
check queue[1].seen
583583

tests/contracts/testMarket.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ ethersuite "On-Chain Market":
256256
receivedIds.add(requestId)
257257

258258
let subscription = await market.subscribeRequestCancelled(request.id, onRequestCancelled)
259-
advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
259+
await advanceToCancelledRequest(otherRequest) # shares expiry with otherRequest
260260
await market.withdrawFunds(otherRequest.id)
261261
check receivedIds.len == 0
262262
await market.withdrawFunds(request.id)

tests/ethertest.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ template ethersuite*(name, body) =
2525

2626
body
2727

28-
export unittest
28+
export asynctest
2929
export ethers except `%`

tests/helpers/multisetup.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import pkg/chronos
22

33
# Allow multiple setups and teardowns in a test suite
44
template asyncmultisetup* =
5-
var setups: seq[proc: Future[void] {.gcsafe.}]
6-
var teardowns: seq[proc: Future[void] {.gcsafe.}]
5+
var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
6+
var teardowns: seq[
7+
proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
78

89
setup:
910
for setup in setups:
@@ -14,10 +15,12 @@ template asyncmultisetup* =
1415
await teardown()
1516

1617
template setup(setupBody) {.inject, used.} =
17-
setups.add(proc {.async.} = setupBody)
18+
setups.add(proc {.async: (
19+
handleException: true, raises: [AsyncExceptionError]).} = setupBody)
1820

1921
template teardown(teardownBody) {.inject, used.} =
20-
teardowns.insert(proc {.async.} = teardownBody)
22+
teardowns.insert(proc {.async: (
23+
handleException: true, raises: [AsyncExceptionError]).} = teardownBody)
2124

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

3437
template setup(setupBody) {.inject, used.} =
35-
setups.add(proc = setupBody)
38+
let setupProc = proc = setupBody
39+
setups.add(setupProc)
3640

3741
template teardown(teardownBody) {.inject, used.} =
3842
teardowns.insert(proc = teardownBody)

tests/integration/codexprocess.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import pkg/questionable
22
import pkg/questionable/results
33
import pkg/confutils
44
import pkg/chronicles
5+
import pkg/chronos/asyncproc
56
import pkg/ethers
67
import pkg/libp2p
78
import std/os

tests/integration/hardhatprocess.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import pkg/questionable/results
33
import pkg/confutils
44
import pkg/chronicles
55
import pkg/chronos
6+
import pkg/chronos/asyncproc
67
import pkg/stew/io2
78
import std/os
89
import std/sets

tests/integration/nodeprocess.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import pkg/questionable
22
import pkg/questionable/results
33
import pkg/confutils
44
import pkg/chronicles
5+
import pkg/chronos/asyncproc
56
import pkg/libp2p
67
import std/os
78
import std/strutils

vendor/nim-chronos

Submodule nim-chronos updated 94 files

0 commit comments

Comments
 (0)