minimal changes to compile codex with Chronos V4
This commit is contained in:
parent
cbc2ad83be
commit
6754112a25
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
##
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c41599a6d6d8b11c729032bf8913e06f4171e0fb
|
||||
Subproject commit e15dc3b41fea95348b58f32244962c1c6df310a7
|
|
@ -1 +1 @@
|
|||
Subproject commit a7f14bc9b783f1b9e2d02cc85a338b1411058095
|
||||
Subproject commit 71cc92988968add33ddf0f517dff68f140feb68a
|
Loading…
Reference in New Issue