diff --git a/.gitmodules b/.gitmodules index 5f058d57..19d3c088 100644 --- a/.gitmodules +++ b/.gitmodules @@ -169,10 +169,11 @@ path = vendor/nim-codex-dht url = https://github.com/codex-storage/nim-codex-dht.git ignore = untracked - branch = master + branch = feat/chronos-v4 [submodule "vendor/nim-datastore"] path = vendor/nim-datastore url = https://github.com/status-im/nim-datastore.git + branch = master [submodule "vendor/nim-sqlite3-abi"] path = vendor/nim-sqlite3-abi url = https://github.com/arnetheduck/nim-sqlite3-abi.git diff --git a/codex.nimble b/codex.nimble index 2156919f..5f989a95 100644 --- a/codex.nimble +++ b/codex.nimble @@ -7,10 +7,10 @@ srcDir = "." installFiles = @["build.nims"] requires "nim >= 1.2.0" -requires "asynctest >= 0.3.2 & < 0.4.0" +requires "asynctest >= 0.4.3 & < 0.5.0" requires "bearssl >= 0.1.4" requires "chronicles >= 0.7.2" -requires "chronos >= 2.5.2" +requires "chronos#head" requires "confutils" requires "ethers >= 0.7.1 & < 0.8.0" requires "libbacktrace" diff --git a/codex/blockexchange/engine/engine.nim b/codex/blockexchange/engine/engine.nim index ec7b7f64..dacc7aa9 100644 --- a/codex/blockexchange/engine/engine.nim +++ b/codex/blockexchange/engine/engine.nim @@ -83,7 +83,7 @@ type proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} = b.taskQueue.pushOrUpdateNoWait(task).isOk() -proc blockexcTaskRunner(b: BlockExcEngine): Future[void] {.gcsafe.} +proc blockexcTaskRunner(b: BlockExcEngine): Future[void] {.gcsafe, raises: [].} proc start*(b: BlockExcEngine) {.async.} = ## Start the blockexc task diff --git a/codex/blockexchange/network/network.nim b/codex/blockexchange/network/network.nim index 1a39364b..e829993d 100644 --- a/codex/blockexchange/network/network.nim +++ b/codex/blockexchange/network/network.nim @@ -34,11 +34,11 @@ const MaxInflight* = 100 type - WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe.} - BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe.} - BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe.} - AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe.} - PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe.} + WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, raises: [].} + BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].} + BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].} + AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} + PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} WantListSender* = proc( id: PeerId, addresses: seq[BlockAddress], @@ -46,7 +46,7 @@ type cancel: bool = false, wantType: WantType = WantType.WantHave, full: bool = false, - sendDontHave: bool = false): Future[void] {.gcsafe.} + sendDontHave: bool = false): Future[void] {.gcsafe, raises: [].} BlockExcHandlers* = object onWantList*: WantListHandler @@ -55,10 +55,10 @@ type onAccount*: AccountHandler onPayment*: PaymentHandler - BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe.} - PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe.} - AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe.} - PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe.} + BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].} + PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].} + AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} + PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} BlockExcRequest* = object sendWantList*: WantListSender diff --git a/codex/blockexchange/network/networkpeer.nim b/codex/blockexchange/network/networkpeer.nim index 69a19386..a13ba92a 100644 --- a/codex/blockexchange/network/networkpeer.nim +++ b/codex/blockexchange/network/networkpeer.nim @@ -22,9 +22,9 @@ logScope: topics = "codex blockexcnetworkpeer" type - ConnProvider* = proc(): Future[Connection] {.gcsafe, closure.} + ConnProvider* = proc (): Future[Connection] {.gcsafe, closure, raises: [].} - RPCHandler* = proc(peer: NetworkPeer, msg: Message): Future[void] {.gcsafe.} + RPCHandler* = proc (peer: NetworkPeer, msg: Message): Future[void] {.gcsafe, raises: [].} NetworkPeer* = ref object of RootObj id*: PeerId diff --git a/codex/contracts/clock.nim b/codex/contracts/clock.nim index 9102e5c2..88f627a2 100644 --- a/codex/contracts/clock.nim +++ b/codex/contracts/clock.nim @@ -2,6 +2,7 @@ import std/times import pkg/ethers import pkg/chronos import pkg/stint +import pkg/upraises import ../clock import ../conf @@ -46,7 +47,7 @@ method stop*(clock: OnChainClock) {.async.} = await clock.subscription.unsubscribe() clock.started = false -method now*(clock: OnChainClock): SecondsSince1970 = +method now*(clock: OnChainClock): SecondsSince1970 {.raises: [].}= when codex_use_hardhat: # hardhat's latest block.timestamp is usually 1s behind the block timestamp # in the newHeads event. When testing, always return the latest block. diff --git a/codex/discovery.nim b/codex/discovery.nim index ce0b4032..477a4bae 100644 --- a/codex/discovery.nim +++ b/codex/discovery.nim @@ -129,7 +129,7 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} = method removeProvider*( d: Discovery, - peerId: PeerId): Future[void] {.base.} = + peerId: PeerId): Future[void] {.base, raises: [].} = ## Remove provider from providers table ## diff --git a/codex/stores/cachestore.nim b/codex/stores/cachestore.nim index e670a093..0602fc6e 100644 --- a/codex/stores/cachestore.nim +++ b/codex/stores/cachestore.nim @@ -118,7 +118,7 @@ method hasBlock*(self: CacheStore, treeCid: Cid, index: Natural): Future[?!bool] await self.hasBlock(cidAndProof[0]) -func cids(self: CacheStore): (iterator: Cid {.gcsafe.}) = +func cids(self: CacheStore): (iterator: Cid {.gcsafe, raises: [].}) = return iterator(): Cid = for cid in self.cache.keys: yield cid diff --git a/codex/utils/exceptions.nim b/codex/utils/exceptions.nim index 4aa2af95..1c51120a 100644 --- a/codex/utils/exceptions.nim +++ b/codex/utils/exceptions.nim @@ -4,4 +4,18 @@ proc msgDetail*(e: ref CatchableError): string = var msg = e.msg if e.parent != nil: msg = fmt"{msg} Inner exception: {e.parent.msg}" - return msg \ No newline at end of file + return msg + +template launderBare*(body: untyped): untyped = + ## Launders bare Exceptions into CatchableError. This is typically used to + ## "fix" code that throws bare exceptions and won't compile with Chronos V4, + ## and which cannot be fixed otherise, e.g. in system APIs like json.parseJson + ## in Nim 1.6.x. It should only be used as a last resort. + try: + body + except Defect as ex: + raise ex + except CatchableError as ex: + raise ex + except Exception as ex: + raise newException(Defect, ex.msg, ex) diff --git a/codex/utils/json.nim b/codex/utils/json.nim index 080d4e89..9ff3addd 100644 --- a/codex/utils/json.nim +++ b/codex/utils/json.nim @@ -14,6 +14,7 @@ import pkg/stew/byteutils import pkg/stint import pkg/questionable/results import ../errors +import exceptions export json except `%`, `%*` @@ -27,12 +28,12 @@ proc newUnexpectedKindError( expectedType: type, expectedKinds: string, json: JsonNode -): ref UnexpectedKindError = +): ref UnexpectedKindError {.raises: [].} = let kind = if json.isNil: "nil" else: $json.kind newException(UnexpectedKindError, - &"deserialization to {$expectedType} failed: expected {expectedKinds} " & - &"but got {kind}") + "deserialization to " & $expectedType & " failed: expected " & + expectedKinds & " but got " & kind) proc newUnexpectedKindError( expectedType: type, @@ -218,14 +219,16 @@ proc fromJson*[T: object]( _: type T, bytes: seq[byte] ): ?!T = - let json = ?catch parseJson(string.fromBytes(bytes)) + # FIXME remove launderBare when we upgrade to nim 2.0.0 + let json = ?catch launderBare parseJson(string.fromBytes(bytes)) T.fromJson(json) proc fromJson*[T: ref object]( _: type T, bytes: seq[byte] ): ?!T = - let json = ?catch parseJson(string.fromBytes(bytes)) + # FIXME remove launderBare when we upgrade to nim 2.0.0 + let json = ?catch launderBare parseJson(string.fromBytes(bytes)) T.fromJson(json) func `%`*(s: string): JsonNode = newJString(s) diff --git a/codex/utils/timer.nim b/codex/utils/timer.nim index 9361d07b..92f92451 100644 --- a/codex/utils/timer.nim +++ b/codex/utils/timer.nim @@ -35,12 +35,12 @@ proc timerLoop(timer: Timer) {.async.} = while true: await timer.callback() await sleepAsync(timer.interval) - except CancelledError: - raise + except CancelledError as exc: + raise exc except CatchableError as exc: error "Timer caught unhandled exception: ", name=timer.name, msg=exc.msg -method start*(timer: Timer, callback: TimerCallback, interval: Duration) {.base.} = +method start*(timer: Timer, callback: TimerCallback, interval: Duration) {.base, raises: [].} = if timer.loopFuture != nil: return trace "Timer starting: ", name=timer.name diff --git a/codex/validation.nim b/codex/validation.nim index b549997e..b29fa45f 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -75,8 +75,8 @@ proc markProofAsMissing(validation: Validation, else: let inDowntime {.used.} = await validation.market.inDowntime(slotId) trace "Proof not missing", checkedPeriod = period, inDowntime - except CancelledError: - raise + except CancelledError as e: + raise e except CatchableError as e: error "Marking proof as missing failed", msg = e.msg diff --git a/config.nims b/config.nims index dba6d9fe..a00ce831 100644 --- a/config.nims +++ b/config.nims @@ -67,7 +67,6 @@ else: --threads:on --opt:speed --excessiveStackTrace:on ---experimental:strictEffects # enable metric collection --define:metrics # for heap-usage-by-instance-type metrics and object base-type strings diff --git a/vendor/nim-chronos b/vendor/nim-chronos index c41599a6..e15dc3b4 160000 --- a/vendor/nim-chronos +++ b/vendor/nim-chronos @@ -1 +1 @@ -Subproject commit c41599a6d6d8b11c729032bf8913e06f4171e0fb +Subproject commit e15dc3b41fea95348b58f32244962c1c6df310a7 diff --git a/vendor/nim-codex-dht b/vendor/nim-codex-dht index a7f14bc9..71cc9298 160000 --- a/vendor/nim-codex-dht +++ b/vendor/nim-codex-dht @@ -1 +1 @@ -Subproject commit a7f14bc9b783f1b9e2d02cc85a338b1411058095 +Subproject commit 71cc92988968add33ddf0f517dff68f140feb68a