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
This commit is contained in:
Giuliano Mega
2024-07-18 21:04:33 +00:00
committed by GitHub
parent fbce240e3d
commit 4f56f2af26
16 changed files with 33 additions and 25 deletions
+1 -2
View File
@@ -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)
+1 -1
View File
@@ -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]
+1 -1
View File
@@ -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)
+3
View File
@@ -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"
+3 -4
View File
@@ -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)
@@ -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()
+6 -6
View File
@@ -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
@@ -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
@@ -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":
@@ -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),
@@ -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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -25,5 +25,5 @@ template ethersuite*(name, body) =
body
export unittest
export asynctest
export ethers except `%`
+9 -5
View File
@@ -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:
@@ -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.}]
@@ -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
View File
@@ -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
+1
View File
@@ -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
+1
View File
@@ -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