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 18:04:33 -03:00 committed by GitHub
parent fbce240e3d
commit 4f56f2af26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 33 additions and 25 deletions

View File

@ -105,8 +105,7 @@ proc advertiseQueueLoop(b: DiscoveryEngine) {.async.} =
trace "Begin iterating blocks..." trace "Begin iterating blocks..."
for c in cids: for c in cids:
if cid =? await c: if cid =? await c:
b.advertiseBlock(cid) await b.advertiseBlock(cid)
await sleepAsync(100.millis)
trace "Iterating blocks finished." trace "Iterating blocks finished."
await sleepAsync(b.advertiseLoopSleep) await sleepAsync(b.advertiseLoopSleep)

View File

@ -31,7 +31,7 @@ import ./codextypes
export errors, logutils, units, codextypes export errors, logutils, units, codextypes
type type
Block* = object of RootObj Block* = ref object of RootObj
cid*: Cid cid*: Cid
data*: seq[byte] data*: seq[byte]

View File

@ -29,7 +29,7 @@ import ../logutils
# TODO: Manifest should be reworked to more concrete types, # TODO: Manifest should be reworked to more concrete types,
# perhaps using inheritance # perhaps using inheritance
type type
Manifest* = object of RootObj Manifest* = ref object of RootObj
treeCid {.serialize.}: Cid # Root of the merkle tree treeCid {.serialize.}: Cid # Root of the merkle tree
datasetSize {.serialize.}: NBytes # Total size of all blocks 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) blockSize {.serialize.}: NBytes # Size of each contained block (might not be needed if blocks are len-prefixed)

View File

@ -121,6 +121,9 @@ switch("define", "ctt_asm=false")
# Allow the use of old-style case objects for nim config compatibility # Allow the use of old-style case objects for nim config compatibility
switch("define", "nimOldCaseObjects") switch("define", "nimOldCaseObjects")
# Enable compat mode for Chronos V4
switch("define", "chronosHandleException")
# begin Nimble config (version 1) # begin Nimble config (version 1)
when system.fileExists("nimble.paths"): when system.fileExists("nimble.paths"):
include "nimble.paths" include "nimble.paths"

View File

@ -323,8 +323,7 @@ asyncchecksuite "Sales":
slot: UInt256, slot: UInt256,
onBatch: BatchProc): Future[?!void] {.async.} = onBatch: BatchProc): Future[?!void] {.async.} =
let blk = bt.Block.new( @[1.byte] ).get let blk = bt.Block.new( @[1.byte] ).get
onBatch( blk.repeat(request.ask.slotSize.truncate(int)) ) await onBatch( blk.repeat(request.ask.slotSize.truncate(int)) )
return success()
createAvailability() createAvailability()
await market.requestStorage(request) await market.requestStorage(request)
@ -337,8 +336,8 @@ asyncchecksuite "Sales":
onBatch: BatchProc): Future[?!void] {.async.} = onBatch: BatchProc): Future[?!void] {.async.} =
slotIndex = slot slotIndex = slot
let blk = bt.Block.new( @[1.byte] ).get let blk = bt.Block.new( @[1.byte] ).get
onBatch(@[ blk ]) await onBatch(@[ blk ])
return success()
let sold = newFuture[void]() let sold = newFuture[void]()
sales.onSale = proc(request: StorageRequest, slotIndex: UInt256) = sales.onSale = proc(request: StorageRequest, slotIndex: UInt256) =
sold.complete() sold.complete()

View File

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

View File

@ -256,7 +256,7 @@ ethersuite "On-Chain Market":
receivedIds.add(requestId) receivedIds.add(requestId)
let subscription = await market.subscribeRequestCancelled(request.id, onRequestCancelled) 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) await market.withdrawFunds(otherRequest.id)
check receivedIds.len == 0 check receivedIds.len == 0
await market.withdrawFunds(request.id) await market.withdrawFunds(request.id)

View File

@ -25,5 +25,5 @@ template ethersuite*(name, body) =
body body
export unittest export asynctest
export ethers except `%` export ethers except `%`

View File

@ -2,8 +2,9 @@ import pkg/chronos
# Allow multiple setups and teardowns in a test suite # Allow multiple setups and teardowns in a test suite
template asyncmultisetup* = template asyncmultisetup* =
var setups: seq[proc: Future[void] {.gcsafe.}] var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
var teardowns: seq[proc: Future[void] {.gcsafe.}] var teardowns: seq[
proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
setup: setup:
for setup in setups: for setup in setups:
@ -14,10 +15,12 @@ template asyncmultisetup* =
await teardown() await teardown()
template setup(setupBody) {.inject, used.} = template setup(setupBody) {.inject, used.} =
setups.add(proc {.async.} = setupBody) setups.add(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = setupBody)
template teardown(teardownBody) {.inject, used.} = template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc {.async.} = teardownBody) teardowns.insert(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = teardownBody)
template multisetup* = template multisetup* =
var setups: seq[proc() {.gcsafe.}] var setups: seq[proc() {.gcsafe.}]
@ -32,7 +35,8 @@ template multisetup* =
teardown() teardown()
template setup(setupBody) {.inject, used.} = template setup(setupBody) {.inject, used.} =
setups.add(proc = setupBody) let setupProc = proc = setupBody
setups.add(setupProc)
template teardown(teardownBody) {.inject, used.} = template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc = teardownBody) teardowns.insert(proc = teardownBody)

View File

@ -2,6 +2,7 @@ import pkg/questionable
import pkg/questionable/results import pkg/questionable/results
import pkg/confutils import pkg/confutils
import pkg/chronicles import pkg/chronicles
import pkg/chronos/asyncproc
import pkg/ethers import pkg/ethers
import pkg/libp2p import pkg/libp2p
import std/os import std/os

View File

@ -3,6 +3,7 @@ import pkg/questionable/results
import pkg/confutils import pkg/confutils
import pkg/chronicles import pkg/chronicles
import pkg/chronos import pkg/chronos
import pkg/chronos/asyncproc
import pkg/stew/io2 import pkg/stew/io2
import std/os import std/os
import std/sets import std/sets

View File

@ -2,6 +2,7 @@ import pkg/questionable
import pkg/questionable/results import pkg/questionable/results
import pkg/confutils import pkg/confutils
import pkg/chronicles import pkg/chronicles
import pkg/chronos/asyncproc
import pkg/libp2p import pkg/libp2p
import std/os import std/os
import std/strutils import std/strutils

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 0277b65be2c7a365ac13df002fba6e172be55537 Subproject commit 035ae11ba92369e7722e649db597e79134fd06b9

@ -1 +1 @@
Subproject commit a7f14bc9b783f1b9e2d02cc85a338b1411058095 Subproject commit 63822e83561ea1c6396d0f3eca583b038f5d44c6

@ -1 +1 @@
Subproject commit 3b491a40c60aad9e8d3407443f46f62511e63b18 Subproject commit be57dbc902d36f37540897e98c69aa80f868cb45

@ -1 +1 @@
Subproject commit fe9bc3f3759ae1add6bf8c899db2e75327f03782 Subproject commit b2e1fb022f1ee800b439648953e92cc993c1264c