diff --git a/eth/keyfile/keyfile.nim b/eth/keyfile/keyfile.nim index da8a9ac..241e6ff 100644 --- a/eth/keyfile/keyfile.nim +++ b/eth/keyfile/keyfile.nim @@ -93,7 +93,10 @@ type KfResult*[T] = Result[T, KeyFileError] proc mapErrTo[T, E](r: Result[T, E], v: static KeyFileError): KfResult[T] = - r.mapErr(proc (e: E): KeyFileError = v) + if r.isOk: + ok(r.value) + else: + err(v) const SupportedHashes = [ diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 0ad9d74..ffde614 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -211,7 +211,7 @@ proc randomNodes*(d: Protocol, maxAmount: int): seq[Node] = d.routingTable.randomNodes(maxAmount) proc randomNodes*(d: Protocol, maxAmount: int, - pred: proc(x: Node): bool {.gcsafe, noSideEffect.}): seq[Node] = + pred: proc(x: Node): bool {.gcsafe, noSideEffect, raises:[Defect].}): seq[Node] = ## Get a `maxAmount` of random nodes from the local routing table with the ## `pred` predicate function applied as filter on the nodes selected. d.routingTable.randomNodes(maxAmount, pred) diff --git a/eth/p2p/discoveryv5/routing_table.nim b/eth/p2p/discoveryv5/routing_table.nim index 5ffb09c..f837b96 100644 --- a/eth/p2p/discoveryv5/routing_table.nim +++ b/eth/p2p/discoveryv5/routing_table.nim @@ -512,7 +512,7 @@ proc nodeToRevalidate*(r: RoutingTable): Node = return b.nodes[^1] proc randomNodes*(r: RoutingTable, maxAmount: int, - pred: proc(x: Node): bool {.gcsafe, noSideEffect.} = nil): seq[Node] = + pred: proc(x: Node): bool {.gcsafe, noSideEffect, raises:[Defect].} = nil): seq[Node] = ## Get a `maxAmount` of random nodes from the routing table with the `pred` ## predicate function applied as filter on the nodes selected. var maxAmount = maxAmount diff --git a/eth/utp/growable_buffer.nim b/eth/utp/growable_buffer.nim index 093ce5b..a34d479 100644 --- a/eth/utp/growable_buffer.nim +++ b/eth/utp/growable_buffer.nim @@ -21,6 +21,9 @@ type items: seq[Option[A]] mask: uint32 +when not defined(nimHasEffectsOfs): + template effectsOf(f: untyped) {.pragma.} + # provided size will always be adjusted to next power of two proc init*[A](T: type GrowableCircularBuffer[A], size: uint32 = 16): T = let powOfTwoSize = nextPowerOfTwo(int(size)) @@ -44,11 +47,13 @@ proc delete*[A](buff: var GrowableCircularBuffer[A], i: uint32) = proc hasKey*[A](buff: GrowableCircularBuffer[A], i: uint32): bool = buff.get(i).isSome() -proc exists*[A](buff: GrowableCircularBuffer[A], i: uint32, check: proc (x: A): bool): bool = +proc exists*[A](buff: GrowableCircularBuffer[A], i: uint32, + check: proc (x: A): bool): bool {.gcsafe, effectsOf: check.} = let maybeElem = buff.get(i) if (maybeElem.isSome()): let elem = maybeElem.unsafeGet() - check(elem) + {.gcsafe.}: + check(elem) else: false