minimal changes to compile codex with Chronos V4

This commit is contained in:
gmega 2024-01-09 09:09:43 -03:00
parent cbc2ad83be
commit 6754112a25
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
15 changed files with 51 additions and 33 deletions

3
.gitmodules vendored
View File

@ -169,10 +169,11 @@
path = vendor/nim-codex-dht path = vendor/nim-codex-dht
url = https://github.com/codex-storage/nim-codex-dht.git url = https://github.com/codex-storage/nim-codex-dht.git
ignore = untracked ignore = untracked
branch = master branch = feat/chronos-v4
[submodule "vendor/nim-datastore"] [submodule "vendor/nim-datastore"]
path = vendor/nim-datastore path = vendor/nim-datastore
url = https://github.com/status-im/nim-datastore.git url = https://github.com/status-im/nim-datastore.git
branch = master
[submodule "vendor/nim-sqlite3-abi"] [submodule "vendor/nim-sqlite3-abi"]
path = vendor/nim-sqlite3-abi path = vendor/nim-sqlite3-abi
url = https://github.com/arnetheduck/nim-sqlite3-abi.git url = https://github.com/arnetheduck/nim-sqlite3-abi.git

View File

@ -7,10 +7,10 @@ srcDir = "."
installFiles = @["build.nims"] installFiles = @["build.nims"]
requires "nim >= 1.2.0" 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 "bearssl >= 0.1.4"
requires "chronicles >= 0.7.2" requires "chronicles >= 0.7.2"
requires "chronos >= 2.5.2" requires "chronos#head"
requires "confutils" requires "confutils"
requires "ethers >= 0.7.1 & < 0.8.0" requires "ethers >= 0.7.1 & < 0.8.0"
requires "libbacktrace" requires "libbacktrace"

View File

@ -83,7 +83,7 @@ type
proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} = proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} =
b.taskQueue.pushOrUpdateNoWait(task).isOk() 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.} = proc start*(b: BlockExcEngine) {.async.} =
## Start the blockexc task ## Start the blockexc task

View File

@ -34,11 +34,11 @@ const
MaxInflight* = 100 MaxInflight* = 100
type type
WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe.} WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, raises: [].}
BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe.} BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].}
BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe.} BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].}
AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe.} AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].}
PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe.} PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].}
WantListSender* = proc( WantListSender* = proc(
id: PeerId, id: PeerId,
addresses: seq[BlockAddress], addresses: seq[BlockAddress],
@ -46,7 +46,7 @@ type
cancel: bool = false, cancel: bool = false,
wantType: WantType = WantType.WantHave, wantType: WantType = WantType.WantHave,
full: bool = false, full: bool = false,
sendDontHave: bool = false): Future[void] {.gcsafe.} sendDontHave: bool = false): Future[void] {.gcsafe, raises: [].}
BlockExcHandlers* = object BlockExcHandlers* = object
onWantList*: WantListHandler onWantList*: WantListHandler
@ -55,10 +55,10 @@ type
onAccount*: AccountHandler onAccount*: AccountHandler
onPayment*: PaymentHandler onPayment*: PaymentHandler
BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe.} BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].}
PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe.} PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].}
AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe.} AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].}
PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe.} PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].}
BlockExcRequest* = object BlockExcRequest* = object
sendWantList*: WantListSender sendWantList*: WantListSender

View File

@ -22,9 +22,9 @@ logScope:
topics = "codex blockexcnetworkpeer" topics = "codex blockexcnetworkpeer"
type 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 NetworkPeer* = ref object of RootObj
id*: PeerId id*: PeerId

View File

@ -2,6 +2,7 @@ import std/times
import pkg/ethers import pkg/ethers
import pkg/chronos import pkg/chronos
import pkg/stint import pkg/stint
import pkg/upraises
import ../clock import ../clock
import ../conf import ../conf
@ -46,7 +47,7 @@ method stop*(clock: OnChainClock) {.async.} =
await clock.subscription.unsubscribe() await clock.subscription.unsubscribe()
clock.started = false clock.started = false
method now*(clock: OnChainClock): SecondsSince1970 = method now*(clock: OnChainClock): SecondsSince1970 {.raises: [].}=
when codex_use_hardhat: when codex_use_hardhat:
# hardhat's latest block.timestamp is usually 1s behind the block timestamp # hardhat's latest block.timestamp is usually 1s behind the block timestamp
# in the newHeads event. When testing, always return the latest block. # in the newHeads event. When testing, always return the latest block.

View File

@ -129,7 +129,7 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} =
method removeProvider*( method removeProvider*(
d: Discovery, d: Discovery,
peerId: PeerId): Future[void] {.base.} = peerId: PeerId): Future[void] {.base, raises: [].} =
## Remove provider from providers table ## Remove provider from providers table
## ##

View File

@ -118,7 +118,7 @@ method hasBlock*(self: CacheStore, treeCid: Cid, index: Natural): Future[?!bool]
await self.hasBlock(cidAndProof[0]) await self.hasBlock(cidAndProof[0])
func cids(self: CacheStore): (iterator: Cid {.gcsafe.}) = func cids(self: CacheStore): (iterator: Cid {.gcsafe, raises: [].}) =
return iterator(): Cid = return iterator(): Cid =
for cid in self.cache.keys: for cid in self.cache.keys:
yield cid yield cid

View File

@ -5,3 +5,17 @@ proc msgDetail*(e: ref CatchableError): string =
if e.parent != nil: if e.parent != nil:
msg = fmt"{msg} Inner exception: {e.parent.msg}" 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)

View File

@ -14,6 +14,7 @@ import pkg/stew/byteutils
import pkg/stint import pkg/stint
import pkg/questionable/results import pkg/questionable/results
import ../errors import ../errors
import exceptions
export json except `%`, `%*` export json except `%`, `%*`
@ -27,12 +28,12 @@ proc newUnexpectedKindError(
expectedType: type, expectedType: type,
expectedKinds: string, expectedKinds: string,
json: JsonNode json: JsonNode
): ref UnexpectedKindError = ): ref UnexpectedKindError {.raises: [].} =
let kind = if json.isNil: "nil" let kind = if json.isNil: "nil"
else: $json.kind else: $json.kind
newException(UnexpectedKindError, newException(UnexpectedKindError,
&"deserialization to {$expectedType} failed: expected {expectedKinds} " & "deserialization to " & $expectedType & " failed: expected " &
&"but got {kind}") expectedKinds & " but got " & kind)
proc newUnexpectedKindError( proc newUnexpectedKindError(
expectedType: type, expectedType: type,
@ -218,14 +219,16 @@ proc fromJson*[T: object](
_: type T, _: type T,
bytes: seq[byte] bytes: seq[byte]
): ?!T = ): ?!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) T.fromJson(json)
proc fromJson*[T: ref object]( proc fromJson*[T: ref object](
_: type T, _: type T,
bytes: seq[byte] bytes: seq[byte]
): ?!T = ): ?!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) T.fromJson(json)
func `%`*(s: string): JsonNode = newJString(s) func `%`*(s: string): JsonNode = newJString(s)

View File

@ -35,12 +35,12 @@ proc timerLoop(timer: Timer) {.async.} =
while true: while true:
await timer.callback() await timer.callback()
await sleepAsync(timer.interval) await sleepAsync(timer.interval)
except CancelledError: except CancelledError as exc:
raise raise exc
except CatchableError as exc: except CatchableError as exc:
error "Timer caught unhandled exception: ", name=timer.name, msg=exc.msg 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: if timer.loopFuture != nil:
return return
trace "Timer starting: ", name=timer.name trace "Timer starting: ", name=timer.name

View File

@ -75,8 +75,8 @@ proc markProofAsMissing(validation: Validation,
else: else:
let inDowntime {.used.} = await validation.market.inDowntime(slotId) let inDowntime {.used.} = await validation.market.inDowntime(slotId)
trace "Proof not missing", checkedPeriod = period, inDowntime trace "Proof not missing", checkedPeriod = period, inDowntime
except CancelledError: except CancelledError as e:
raise raise e
except CatchableError as e: except CatchableError as e:
error "Marking proof as missing failed", msg = e.msg error "Marking proof as missing failed", msg = e.msg

View File

@ -67,7 +67,6 @@ else:
--threads:on --threads:on
--opt:speed --opt:speed
--excessiveStackTrace:on --excessiveStackTrace:on
--experimental:strictEffects
# enable metric collection # enable metric collection
--define:metrics --define:metrics
# for heap-usage-by-instance-type metrics and object base-type strings # for heap-usage-by-instance-type metrics and object base-type strings

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit c41599a6d6d8b11c729032bf8913e06f4171e0fb Subproject commit e15dc3b41fea95348b58f32244962c1c6df310a7

@ -1 +1 @@
Subproject commit a7f14bc9b783f1b9e2d02cc85a338b1411058095 Subproject commit 71cc92988968add33ddf0f517dff68f140feb68a