diff --git a/eth/common/eth_types.nim b/eth/common/eth_types.nim index 21d17ce..63c436c 100644 --- a/eth/common/eth_types.nim +++ b/eth/common/eth_types.nim @@ -268,8 +268,8 @@ func destination*(tx: Transaction): EthAddress = if tx.to.isSome: return tx.to.get -func init*(T: type BlockHashOrNumber, str: string): T - {.raises: [ValueError, Defect].} = +func init*( + T: type BlockHashOrNumber, str: string): T {.raises: [ValueError].} = if str.startsWith "0x": if str.len != sizeof(default(T).hash.data) * 2 + 2: raise newException(ValueError, "Block hash has incorrect length") diff --git a/eth/common/eth_types_json_serialization.nim b/eth/common/eth_types_json_serialization.nim index 4ecfb13..46ad9a2 100644 --- a/eth/common/eth_types_json_serialization.nim +++ b/eth/common/eth_types_json_serialization.nim @@ -1,3 +1,9 @@ +# Copyright (c) 2022-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import std/[times, net], json_serialization, nimcrypto/[hash, utils], @@ -6,7 +12,7 @@ import export json_serialization -{.push raises: [SerializationError, IOError, Defect].} +{.push raises: [SerializationError, IOError].} proc writeValue*(w: var JsonWriter, a: MDigest) = w.writeValue a.data.toHex(true) diff --git a/eth/db/kvstore_sqlite3.nim b/eth/db/kvstore_sqlite3.nim index f240777..b5f9d9a 100644 --- a/eth/db/kvstore_sqlite3.nim +++ b/eth/db/kvstore_sqlite3.nim @@ -1,6 +1,6 @@ ## Implementation of KvStore based on sqlite3 -{.push raises: [Defect].} +{.push raises: [].} {.pragma: callback, gcsafe, raises: [].} import diff --git a/eth/keyfile/keyfile.nim b/eth/keyfile/keyfile.nim index 3e2b451..5071613 100644 --- a/eth/keyfile/keyfile.nim +++ b/eth/keyfile/keyfile.nim @@ -7,7 +7,7 @@ # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) -{.push raises: [Defect].} +{.push raises: [].} import std/[strutils, json], @@ -480,7 +480,8 @@ proc loadKeyFile*(pathname: string, data = json.parseFile(pathname) except JsonParsingError: return err(JsonError) - except Exception: # json raises Exception + except Exception: + # json parseFile also raises IOError, ValueError and raw Exception return err(OsError) decodeKeyFileJson(data, password) diff --git a/eth/keyfile/uuid.nim b/eth/keyfile/uuid.nim index b549b9e..b9112cc 100644 --- a/eth/keyfile/uuid.nim +++ b/eth/keyfile/uuid.nim @@ -16,7 +16,7 @@ ## - ``FreeBSD``, ``OpenBSD``, ``NetBSD``, ## ``DragonflyBSD`` - using `uuid_create()`. -{.push raises: [Defect].} +{.push raises: [].} import stew/[byteutils, endians2, results] diff --git a/eth/keys.nim b/eth/keys.nim index 441d74c..ed5a005 100644 --- a/eth/keys.nim +++ b/eth/keys.nim @@ -1,5 +1,5 @@ -# Nim Ethereum Keys (nim-eth-keys) -# Copyright (c) 2020 Status Research & Development GmbH +# Nim Ethereum Keys +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed under either of # - Apache License, version 2.0, (LICENSE-APACHEv2) # - MIT license (LICENSE-MIT) @@ -12,7 +12,7 @@ # * Shared secrets are serialized in raw format without the initial byte # * distinct types are used to avoid confusion with the "standard" secp types -{.push raises: [Defect].} +{.push raises: [].} import std/strformat, diff --git a/eth/net/nat.nim b/eth/net/nat.nim index 0ffe4a4..4d4e71d 100644 --- a/eth/net/nat.nim +++ b/eth/net/nat.nim @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2021 Status Research & Development GmbH +# Copyright (c) 2019-2023 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -6,7 +6,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[options, os, strutils, times], @@ -204,7 +204,7 @@ var natThread: Thread[PortMappingArgs] natCloseChan: Channel[bool] -proc repeatPortMapping(args: PortMappingArgs) {.thread, raises: [Defect, ValueError].} = +proc repeatPortMapping(args: PortMappingArgs) {.thread, raises: [ValueError].} = ignoreSignalsInThread() let (tcpPort, udpPort, description) = args @@ -323,7 +323,7 @@ type of true: extIp*: ValidIpAddress of false: nat*: NatStrategy -func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [Defect, ConfigurationError].} = +func parseCmdArg*(T: type NatConfig, p: string): T {.raises: [ConfigurationError].} = case p.toLowerAscii: of "any": NatConfig(hasExtIp: false, nat: NatAny) diff --git a/eth/net/utils.nim b/eth/net/utils.nim index 6957e89..88000ca 100644 --- a/eth/net/utils.nim +++ b/eth/net/utils.nim @@ -1,11 +1,11 @@ # nim-eth -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, hashes], diff --git a/eth/p2p.nim b/eth/p2p.nim index ede02ea..2396acf 100644 --- a/eth/p2p.nim +++ b/eth/p2p.nim @@ -1,11 +1,11 @@ # nim-eth -# Copyright (c) 2018-2022 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, algorithm, random, typetraits, strutils, net], @@ -134,7 +134,7 @@ proc processIncoming(server: StreamServer, proc listeningAddress*(node: EthereumNode): ENode = node.toENode() -proc startListening*(node: EthereumNode) {.raises: [CatchableError, Defect].} = +proc startListening*(node: EthereumNode) {.raises: [CatchableError].} = # TODO: allow binding to both IPv4 & IPv6 let ta = initTAddress(node.bindIp, node.bindPort) if node.listeningServer == nil: @@ -165,7 +165,7 @@ proc connectToNetwork*( trace "Waiting for more peers", peers = node.peerPool.connectedNodes.len await sleepAsync(500.milliseconds) -proc stopListening*(node: EthereumNode) {.raises: [CatchableError, Defect].} = +proc stopListening*(node: EthereumNode) {.raises: [CatchableError].} = node.listeningServer.stop() iterator peers*(node: EthereumNode): Peer = diff --git a/eth/p2p/auth.nim b/eth/p2p/auth.nim index 7c5a887..25a7790 100644 --- a/eth/p2p/auth.nim +++ b/eth/p2p/auth.nim @@ -1,6 +1,6 @@ # # Ethereum P2P -# (c) Copyright 2018-2022 +# (c) Copyright 2018-2023 # Status Research & Development GmbH # # Licensed under either of @@ -10,7 +10,7 @@ ## This module implements Ethereum RLPx authentication -{.push raises: [Defect].} +{.push raises: [].} import nimcrypto/[rijndael, keccak, utils], diff --git a/eth/p2p/discovery.nim b/eth/p2p/discovery.nim index 2f05e73..ea42c7b 100644 --- a/eth/p2p/discovery.nim +++ b/eth/p2p/discovery.nim @@ -1,11 +1,11 @@ # nim-eth -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[times, net], @@ -86,7 +86,7 @@ proc recoverMsgPublicKey(msg: openArray[byte]): DiscResult[PublicKey] = recover(sig, msg.toOpenArray(HEAD_SIZE, msg.high)) proc unpack(msg: openArray[byte]): tuple[cmdId: CommandId, payload: seq[byte]] - {.raises: [DiscProtocolError, Defect].} = + {.raises: [DiscProtocolError].} = # Check against possible RangeError if msg[HEAD_SIZE].int < CommandId.low.ord or msg[HEAD_SIZE].int > CommandId.high.ord: @@ -99,14 +99,14 @@ proc expiration(): uint32 = # Wire protocol -proc send(d: DiscoveryProtocol, n: Node, data: seq[byte]) {.raises: [Defect].} = +proc send(d: DiscoveryProtocol, n: Node, data: seq[byte]) = let ta = initTAddress(n.node.address.ip, n.node.address.udpPort) let f = d.transp.sendTo(ta, data) f.callback = proc(data: pointer) {.gcsafe.} = if f.failed: debug "Discovery send failed", msg = f.readError.msg -proc sendPing*(d: DiscoveryProtocol, n: Node): seq[byte] {.raises: [Defect].} = +proc sendPing*(d: DiscoveryProtocol, n: Node): seq[byte] = let payload = rlp.encode((PROTO_VERSION, d.address, n.node.address, expiration())) let msg = pack(cmdPing, payload, d.privKey) @@ -172,17 +172,17 @@ proc newDiscoveryProtocol*( discovery proc recvPing(d: DiscoveryProtocol, node: Node, msgHash: MDigest[256]) - {.raises: [ValueError, Defect].} = + {.raises: [ValueError].} = d.kademlia.recvPing(node, msgHash) proc recvPong(d: DiscoveryProtocol, node: Node, payload: seq[byte]) - {.raises: [RlpError, Defect].} = + {.raises: [RlpError].} = let rlp = rlpFromBytes(payload) let tok = rlp.listElem(1).toBytes() d.kademlia.recvPong(node, tok) proc recvNeighbours(d: DiscoveryProtocol, node: Node, payload: seq[byte]) - {.raises: [RlpError, Defect].} = + {.raises: [RlpError].} = let rlp = rlpFromBytes(payload) let neighboursList = rlp.listElem(0) let sz = neighboursList.listLen() @@ -214,7 +214,7 @@ proc recvNeighbours(d: DiscoveryProtocol, node: Node, payload: seq[byte]) d.kademlia.recvNeighbours(node, neighbours) proc recvFindNode(d: DiscoveryProtocol, node: Node, payload: openArray[byte]) - {.raises: [RlpError, ValueError, Defect].} = + {.raises: [RlpError, ValueError].} = let rlp = rlpFromBytes(payload) trace "<<< find_node from ", node let rng = rlp.listElem(0).toBytes @@ -242,7 +242,7 @@ proc expirationValid(cmdId: CommandId, rlpEncodedPayload: openArray[byte]): raise newException(DiscProtocolError, "Invalid RLP list for this packet id") proc receive*(d: DiscoveryProtocol, a: Address, msg: openArray[byte]) - {.raises: [DiscProtocolError, RlpError, ValueError, Defect].} = + {.raises: [DiscProtocolError, RlpError, ValueError].} = # Note: export only needed for testing let msgHash = validateMsgHash(msg) if msgHash.isOk(): @@ -272,7 +272,7 @@ proc receive*(d: DiscoveryProtocol, a: Address, msg: openArray[byte]) notice "Wrong msg mac from ", a proc processClient(transp: DatagramTransport, raddr: TransportAddress): - Future[void] {.async, raises: [Defect].} = + Future[void] {.async.} = var proto = getUserData[DiscoveryProtocol](transp) let buf = try: transp.getMessage() except TransportOsError as e: @@ -289,7 +289,7 @@ proc processClient(transp: DatagramTransport, raddr: TransportAddress): except ValueError as e: debug "Receive failed", exc = e.name, err = e.msg -proc open*(d: DiscoveryProtocol) {.raises: [Defect, CatchableError].} = +proc open*(d: DiscoveryProtocol) {.raises: [CatchableError].} = # TODO: allow binding to both IPv4 and IPv6 let ta = initTAddress(d.bindIp, d.bindPort) d.transp = newDatagramTransport(processClient, udata = d, local = ta) diff --git a/eth/p2p/discoveryv5/encoding.nim b/eth/p2p/discoveryv5/encoding.nim index 9e553b5..5ae2cd7 100644 --- a/eth/p2p/discoveryv5/encoding.nim +++ b/eth/p2p/discoveryv5/encoding.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -11,7 +11,7 @@ ## https://github.com/ethereum/devp2p/blob/master/discv5/discv5-theory.md#sessions ## -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, options, hashes, net], diff --git a/eth/p2p/discoveryv5/enr.nim b/eth/p2p/discoveryv5/enr.nim index be60d59..de90f8f 100644 --- a/eth/p2p/discoveryv5/enr.nim +++ b/eth/p2p/discoveryv5/enr.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -8,7 +8,7 @@ ## ENR implementation according to specification in EIP-778: ## https://github.com/ethereum/EIPs/blob/master/EIPS/eip-778.md -{.push raises: [Defect].} +{.push raises: [].} import std/[strutils, macros, algorithm, options], @@ -394,7 +394,7 @@ func verifySignatureV4( else: false -func verifySignature(r: Record): bool {.raises: [RlpError, Defect].} = +func verifySignature(r: Record): bool {.raises: [RlpError].} = var rlp = rlpFromBytes(r.raw) let sz = rlp.listLen if not rlp.enterList: @@ -420,7 +420,7 @@ func verifySignature(r: Record): bool {.raises: [RlpError, Defect].} = # No Identity Scheme provided false -func fromBytesAux(r: var Record): bool {.raises: [RlpError, Defect].} = +func fromBytesAux(r: var Record): bool {.raises: [RlpError].} = if r.raw.len > maxEnrSize: return false @@ -546,7 +546,7 @@ func `==`*(a, b: Record): bool = a.raw == b.raw func read*( rlp: var Rlp, T: type Record): - T {.raises: [RlpError, ValueError, Defect].} = + T {.raises: [RlpError, ValueError].} = var res: T if not rlp.hasData() or not res.fromBytes(rlp.rawData): # TODO: This could also just be an invalid signature, would be cleaner to diff --git a/eth/p2p/discoveryv5/hkdf.nim b/eth/p2p/discoveryv5/hkdf.nim index 6332694..04152b9 100644 --- a/eth/p2p/discoveryv5/hkdf.nim +++ b/eth/p2p/discoveryv5/hkdf.nim @@ -1,9 +1,20 @@ +# nim-eth +# Copyright (c) 2020-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. +# + +{.push raises: [].} + import nimcrypto/[hmac, hash] export hmac, hash -proc hkdf*(HashType: typedesc, ikm, salt, info: openArray[byte], +proc hkdf*( + HashType: typedesc, ikm, salt, info: openArray[byte], output: var openArray[byte]) = var ctx: HMAC[HashType] ctx.init(salt) diff --git a/eth/p2p/discoveryv5/ip_vote.nim b/eth/p2p/discoveryv5/ip_vote.nim index 2392e8b..32d6fa1 100644 --- a/eth/p2p/discoveryv5/ip_vote.nim +++ b/eth/p2p/discoveryv5/ip_vote.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -15,7 +15,7 @@ ## To select the right address, a majority count is done. This is done over a ## sort of moving window as votes expire after `IpVoteTimeout`. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, options], diff --git a/eth/p2p/discoveryv5/lru.nim b/eth/p2p/discoveryv5/lru.nim index 160c2d6..e55c772 100644 --- a/eth/p2p/discoveryv5/lru.nim +++ b/eth/p2p/discoveryv5/lru.nim @@ -1,6 +1,14 @@ -import std/[tables, lists, options] +# nim-eth +# Copyright (c) 2020-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. +# -{.push raises: [Defect].} +{.push raises: [].} + +import std/[tables, lists, options] type LRUCache*[K, V] = object of RootObj diff --git a/eth/p2p/discoveryv5/messages.nim b/eth/p2p/discoveryv5/messages.nim index cbec3c0..4c819be 100644 --- a/eth/p2p/discoveryv5/messages.nim +++ b/eth/p2p/discoveryv5/messages.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -9,7 +9,7 @@ ## https://github.com/ethereum/devp2p/blob/master/discv5/discv5-wire.md#protocol-messages ## -{.push raises: [Defect].} +{.push raises: [].} import std/[hashes, net], diff --git a/eth/p2p/discoveryv5/messages_encoding.nim b/eth/p2p/discoveryv5/messages_encoding.nim index d07ddb7..3fa1c67 100644 --- a/eth/p2p/discoveryv5/messages_encoding.nim +++ b/eth/p2p/discoveryv5/messages_encoding.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2022 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -7,7 +7,7 @@ # ## Discovery v5 Protocol Messages RLP Encoding -{.push raises: [Defect].} +{.push raises: [].} import std/net, @@ -20,7 +20,7 @@ from stew/objects import checkedEnumAssign export messages, rlp, results func read*(rlp: var Rlp, T: type RequestId): T - {.raises: [ValueError, RlpError, Defect].} = + {.raises: [ValueError, RlpError].} = mixin read var reqId: RequestId reqId.id = rlp.toBytes() @@ -34,7 +34,7 @@ func append*(writer: var RlpWriter, value: RequestId) = writer.append(value.id) func read*(rlp: var Rlp, T: type IpAddress): T - {.raises: [RlpError, Defect].} = + {.raises: [RlpError].} = let ipBytes = rlp.toBytes() rlp.skipElem() @@ -93,7 +93,7 @@ func decodeMessage*(body: openArray[byte]): Result[Message, cstring] = return err("Invalid request-id") func decode[T](rlp: var Rlp, v: var T) - {.nimcall, raises:[RlpError, ValueError, Defect].} = + {.nimcall, raises: [RlpError, ValueError].} = for k, v in v.fieldPairs: v = rlp.read(typeof(v)) diff --git a/eth/p2p/discoveryv5/node.nim b/eth/p2p/discoveryv5/node.nim index 391ba95..2160053 100644 --- a/eth/p2p/discoveryv5/node.nim +++ b/eth/p2p/discoveryv5/node.nim @@ -1,11 +1,11 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/hashes, diff --git a/eth/p2p/discoveryv5/nodes_verification.nim b/eth/p2p/discoveryv5/nodes_verification.nim index 6512cd1..2b9314d 100644 --- a/eth/p2p/discoveryv5/nodes_verification.nim +++ b/eth/p2p/discoveryv5/nodes_verification.nim @@ -6,7 +6,7 @@ # This file may not be copied, modified, or distributed except according to # those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[sets, options], diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index bb6aa59..24a1bb5 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2022 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -78,7 +78,7 @@ ## When distance 0 is provided in the requested list of distances, only the own ## ENR will be returned. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, sets, options, math, sequtils, algorithm], @@ -158,7 +158,7 @@ type TalkProtocolHandler* = proc( p: TalkProtocol, request: seq[byte], fromId: NodeId, fromUdpAddress: Address): seq[byte] - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} TalkProtocol* = ref object of RootObj protocolHandler*: TalkProtocolHandler @@ -1016,7 +1016,7 @@ proc newProtocol*( template listeningAddress*(p: Protocol): Address = p.bindAddress -proc open*(d: Protocol) {.raises: [Defect, CatchableError].} = +proc open*(d: Protocol) {.raises: [CatchableError].} = info "Starting discovery node", node = d.localNode, bindAddress = d.bindAddress diff --git a/eth/p2p/discoveryv5/random2.nim b/eth/p2p/discoveryv5/random2.nim index 02d69e4..265e0a1 100644 --- a/eth/p2p/discoveryv5/random2.nim +++ b/eth/p2p/discoveryv5/random2.nim @@ -1,3 +1,13 @@ +# nim-eth +# Copyright (c) 2020-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. +# + +{.push raises: [].} + import bearssl/rand diff --git a/eth/p2p/discoveryv5/routing_table.nim b/eth/p2p/discoveryv5/routing_table.nim index 74f836f..d8db595 100644 --- a/eth/p2p/discoveryv5/routing_table.nim +++ b/eth/p2p/discoveryv5/routing_table.nim @@ -1,11 +1,11 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[algorithm, times, sequtils, bitops, sets, options], @@ -20,9 +20,12 @@ declarePublicGauge routing_table_nodes, "Discovery routing table nodes", labels = ["state"] type - DistanceProc* = proc(a, b: NodeId): NodeId {.raises: [Defect], gcsafe, noSideEffect.} - LogDistanceProc* = proc(a, b: NodeId): uint16 {.raises: [Defect], gcsafe, noSideEffect.} - IdAtDistanceProc* = proc (id: NodeId, dist: uint16): NodeId {.raises: [Defect], gcsafe, noSideEffect.} + DistanceProc* = + proc(a, b: NodeId): NodeId {.raises: [], gcsafe, noSideEffect.} + LogDistanceProc* = + proc(a, b: NodeId): uint16 {.raises: [], gcsafe, noSideEffect.} + IdAtDistanceProc* = + proc (id: NodeId, dist: uint16): NodeId {.raises: [], gcsafe, noSideEffect.} DistanceCalculator* = object calculateDistance*: DistanceProc diff --git a/eth/p2p/discoveryv5/sessions.nim b/eth/p2p/discoveryv5/sessions.nim index 5b52d17..2a4755f 100644 --- a/eth/p2p/discoveryv5/sessions.nim +++ b/eth/p2p/discoveryv5/sessions.nim @@ -1,5 +1,5 @@ # nim-eth - Node Discovery Protocol v5 -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -9,7 +9,7 @@ ## https://github.com/ethereum/devp2p/blob/master/discv5/discv5-theory.md#session-cache ## -{.push raises: [Defect].} +{.push raises: [].} import std/options, diff --git a/eth/p2p/ecies.nim b/eth/p2p/ecies.nim index 62943d2..dd99885 100644 --- a/eth/p2p/ecies.nim +++ b/eth/p2p/ecies.nim @@ -1,6 +1,6 @@ # # Ethereum P2P -# (c) Copyright 2018-2022 +# (c) Copyright 2018-2023 # Status Research & Development GmbH # # Licensed under either of @@ -10,7 +10,7 @@ ## This module implements ECIES method encryption/decryption. -{.push raises: [Defect].} +{.push raises: [].} import stew/[results, endians2], diff --git a/eth/p2p/enode.nim b/eth/p2p/enode.nim index 67df0e1..5d8d6df 100644 --- a/eth/p2p/enode.nim +++ b/eth/p2p/enode.nim @@ -1,6 +1,6 @@ # # Ethereum P2P -# (c) Copyright 2018-2020 +# (c) Copyright 2018-2023 # Status Research & Development GmbH # # Licensed under either of @@ -8,7 +8,7 @@ # MIT license (LICENSE-MIT) # -{.push raises: [Defect].} +{.push raises: [].} import std/[uri, strutils, net], diff --git a/eth/p2p/kademlia.nim b/eth/p2p/kademlia.nim index af173a3..e4a9741 100644 --- a/eth/p2p/kademlia.nim +++ b/eth/p2p/kademlia.nim @@ -1,11 +1,11 @@ # nim-eth -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, hashes, times, algorithm, sets, sequtils], @@ -31,7 +31,7 @@ type routing: RoutingTable pongFutures: Table[seq[byte], Future[bool]] pingFutures: Table[Node, Future[bool]] - neighboursCallbacks: Table[Node, proc(n: seq[Node]) {.gcsafe, raises: [Defect].}] + neighboursCallbacks: Table[Node, proc(n: seq[Node]) {.gcsafe, raises: [].}] rng: ref HmacDrbgContext pingPongTime: OrderedTable[TimeKey, int64] # int64 -> unix time @@ -253,7 +253,7 @@ proc isFull(k: KBucket): bool = k.len == BUCKET_SIZE proc contains(k: KBucket, n: Node): bool = n in k.nodes proc binaryGetBucketForNode(buckets: openArray[KBucket], n: Node): - KBucket {.raises: [ValueError, Defect].} = + KBucket {.raises: [ValueError].} = ## Given a list of ordered buckets, returns the bucket for a given node. let bucketPos = lowerBound(buckets, n.id) do(a: KBucket, b: NodeId) -> int: cmp(a.iend, b) @@ -293,14 +293,14 @@ proc splitBucket(r: var RoutingTable, index: int) = r.buckets.insert(b, index + 1) proc bucketForNode(r: RoutingTable, n: Node): KBucket - {.raises: [ValueError, Defect].} = + {.raises: [ValueError].} = binaryGetBucketForNode(r.buckets, n) -proc removeNode(r: var RoutingTable, n: Node) {.raises: [ValueError, Defect].} = +proc removeNode(r: var RoutingTable, n: Node) {.raises: [ValueError].} = r.bucketForNode(n).removeNode(n) proc addNode(r: var RoutingTable, n: Node): Node - {.raises: [ValueError, Defect].} = + {.raises: [ValueError].} = if n == r.thisNode: warn "Trying to add ourselves to the routing table", node = n return @@ -318,7 +318,7 @@ proc addNode(r: var RoutingTable, n: Node): Node # Nothing added, ping evictionCandidate return evictionCandidate -proc contains(r: RoutingTable, n: Node): bool {.raises: [ValueError, Defect].} = +proc contains(r: RoutingTable, n: Node): bool {.raises: [ValueError].} = n in r.bucketForNode(n) proc bucketsByDistanceTo(r: RoutingTable, id: NodeId): seq[KBucket] = @@ -357,7 +357,7 @@ proc bond(k: KademliaProtocol, n: Node): Future[bool] {.async.} proc bondDiscard(k: KademliaProtocol, n: Node) {.async.} proc updateRoutingTable(k: KademliaProtocol, n: Node) - {.raises: [ValueError, Defect], gcsafe.} = + {.raises: [ValueError], gcsafe.} = ## Update the routing table entry for the given node. let evictionCandidate = k.routing.addNode(n) if not evictionCandidate.isNil: @@ -367,7 +367,7 @@ proc updateRoutingTable(k: KademliaProtocol, n: Node) # replacement cache. asyncSpawn k.bondDiscard(evictionCandidate) -proc doSleep(p: proc() {.gcsafe, raises: [Defect].}) {.async.} = +proc doSleep(p: proc() {.gcsafe, raises: [].}) {.async.} = await sleepAsync(REQUEST_TIMEOUT) p() @@ -402,13 +402,12 @@ proc waitPing(k: KademliaProtocol, n: Node): Future[bool] = k.pingFutures.del(n) fut.complete(false) -proc waitNeighbours(k: KademliaProtocol, remote: Node): - Future[seq[Node]] {.raises: [Defect].} = +proc waitNeighbours(k: KademliaProtocol, remote: Node): Future[seq[Node]] = doAssert(remote notin k.neighboursCallbacks) result = newFuture[seq[Node]]("waitNeighbours") let fut = result var neighbours = newSeqOfCap[Node](BUCKET_SIZE) - k.neighboursCallbacks[remote] = proc(n: seq[Node]) {.gcsafe, raises: [Defect].} = + k.neighboursCallbacks[remote] = proc(n: seq[Node]) {.gcsafe, raises: [].} = # This callback is expected to be called multiple times because nodes usually # split the neighbours replies into multiple packets, so we only complete the # future event.set() we've received enough neighbours. @@ -607,7 +606,7 @@ proc recvPong*(k: KademliaProtocol, n: Node, token: seq[byte]) = k.updateLastPongReceived(n, getTime()) proc recvPing*(k: KademliaProtocol, n: Node, msgHash: auto) - {.raises: [ValueError, Defect].} = + {.raises: [ValueError].} = trace "<<< ping from ", n k.wire.sendPong(n, msgHash) @@ -654,7 +653,7 @@ proc recvNeighbours*(k: KademliaProtocol, remote: Node, neighbours: seq[Node]) = trace "Unexpected neighbours, probably came too late", remote proc recvFindNode*(k: KademliaProtocol, remote: Node, nodeId: NodeId) - {.raises: [ValueError, Defect].} = + {.raises: [ValueError].} = if remote notin k.routing: # FIXME: This is not correct; a node we've bonded before may have become unavailable # and thus removed from self.routing, but once it's back online we should accept diff --git a/eth/p2p/p2p_backends_helpers.nim b/eth/p2p/p2p_backends_helpers.nim index 75f4750..e54b37c 100644 --- a/eth/p2p/p2p_backends_helpers.nim +++ b/eth/p2p/p2p_backends_helpers.nim @@ -29,11 +29,11 @@ template networkState*(connection: Peer, Protocol: type): untyped = protocolState(connection.network, Protocol) proc initProtocolState*[T](state: T, x: Peer|EthereumNode) - {.gcsafe, raises: [Defect].} = + {.gcsafe, raises: [].} = discard proc initProtocolStates(peer: Peer, protocols: openArray[ProtocolInfo]) - {.raises: [Defect].} = + {.raises: [].} = # Initialize all the active protocol states newSeq(peer.protocolStates, allProtocols.len) for protocol in protocols: diff --git a/eth/p2p/p2p_protocol_dsl.nim b/eth/p2p/p2p_protocol_dsl.nim index 8d4f8c8..8f53f81 100644 --- a/eth/p2p/p2p_protocol_dsl.nim +++ b/eth/p2p/p2p_protocol_dsl.nim @@ -1,4 +1,4 @@ -{.push raises: [Defect].} +{.push raises: [].} import std/[options, sequtils], diff --git a/eth/p2p/peer_pool.nim b/eth/p2p/peer_pool.nim index 93570d4..62d49c3 100644 --- a/eth/p2p/peer_pool.nim +++ b/eth/p2p/peer_pool.nim @@ -1,5 +1,5 @@ # nim-eth -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -8,7 +8,7 @@ # PeerPool attempts to keep connections to at least min_peers # on the given network. -{.push raises: [Defect].} +{.push raises: [].} import std/[os, tables, times, random, sequtils, options], diff --git a/eth/p2p/private/p2p_types.nim b/eth/p2p/private/p2p_types.nim index a84068f..005bf77 100644 --- a/eth/p2p/private/p2p_types.nim +++ b/eth/p2p/private/p2p_types.nim @@ -1,10 +1,12 @@ # nim-eth -# Copyright (c) 2018-2022 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. +{.push raises: [].} + import std/[deques, tables], chronos, @@ -74,8 +76,8 @@ type observers*: Table[int, PeerObserver] PeerObserver* = object - onPeerConnected*: proc(p: Peer) {.gcsafe, raises: [Defect].} - onPeerDisconnected*: proc(p: Peer) {.gcsafe, raises: [Defect].} + onPeerConnected*: proc(p: Peer) {.gcsafe, raises: [].} + onPeerDisconnected*: proc(p: Peer) {.gcsafe, raises: [].} protocol*: ProtocolInfo Capability* = object @@ -152,19 +154,19 @@ type # Private types: MessageHandlerDecorator* = proc(msgId: int, n: NimNode): NimNode ThunkProc* = proc(x: Peer, msgId: int, data: Rlp): Future[void] - {.gcsafe, raises: [RlpError, Defect].} + {.gcsafe, raises: [RlpError].} MessageContentPrinter* = proc(msg: pointer): string - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} RequestResolver* = proc(msg: pointer, future: FutureBase) - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} NextMsgResolver* = proc(msgData: Rlp, future: FutureBase) - {.gcsafe, raises: [RlpError, Defect].} - PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [RlpError].} + PeerStateInitializer* = proc(peer: Peer): RootRef {.gcsafe, raises: [].} NetworkStateInitializer* = proc(network: EthereumNode): RootRef - {.gcsafe, raises: [Defect].} - HandshakeStep* = proc(peer: Peer): Future[void] {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} + HandshakeStep* = proc(peer: Peer): Future[void] {.gcsafe, raises: [].} DisconnectionHandler* = proc(peer: Peer, reason: DisconnectionReason): - Future[void] {.gcsafe, raises: [Defect].} + Future[void] {.gcsafe, raises: [].} ConnectionState* = enum None, diff --git a/eth/p2p/rlpx.nim b/eth/p2p/rlpx.nim index d00a330..a0f1ced 100644 --- a/eth/p2p/rlpx.nim +++ b/eth/p2p/rlpx.nim @@ -1,11 +1,11 @@ # nim-eth -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, algorithm, deques, hashes, options, typetraits, os], @@ -71,7 +71,7 @@ type value: DisconnectionReason proc read(rlp: var Rlp; T: type DisconnectionReasonList): T - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = ## Rlp mixin: `DisconnectionReasonList` parser if rlp.isList: @@ -321,7 +321,7 @@ proc cmp*(lhs, rhs: ProtocolInfo): int = return cmp(lhs.name, rhs.name) proc nextMsgResolver[MsgType](msgData: Rlp, future: FutureBase) - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = var reader = msgData Future[MsgType](future).complete reader.readRecordType(MsgType, MsgType.rlpFieldsCount > 1) @@ -374,7 +374,7 @@ template perPeerMsgId(peer: Peer, MsgType: type): int = perPeerMsgIdImpl(peer, MsgType.msgProtocol.protocolInfo, MsgType.msgId) proc invokeThunk*(peer: Peer, msgId: int, msgData: var Rlp): Future[void] - {.raises: [UnsupportedMessageError, RlpError, Defect].} = + {.raises: [UnsupportedMessageError, RlpError].} = template invalidIdError: untyped = raise newException(UnsupportedMessageError, "RLPx message with an invalid id " & $msgId & @@ -698,7 +698,7 @@ proc recvMsg*(peer: Peer): Future[tuple[msgId: int, msgData: Rlp]] {.async.} = proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): - auto {.raises: [RlpError, Defect].} = + auto {.raises: [RlpError].} = when defined(release): return r.read(MsgType) else: @@ -962,7 +962,7 @@ proc p2pProtocolBackendImpl*(protocol: P2PProtocol): Backend = proc `thunkName`(`peerVar`: `Peer`, _: int, data: Rlp) # Fun error if you just use `RlpError` instead of `rlp.RlpError`: # "Error: type expected, but got symbol 'RlpError' of kind 'EnumField'" - {.async, gcsafe, raises: [rlp.RlpError, Defect].} = + {.async, gcsafe, raises: [rlp.RlpError].} = var `receivedRlp` = data var `receivedMsg` {.noinit.}: `msgRecName` `readParamsPrelude` @@ -1130,13 +1130,13 @@ func validatePubKeyInHello(msg: DevP2P.hello, pubKey: PublicKey): bool = let pk = PublicKey.fromRaw(msg.nodeId) pk.isOk and pk[] == pubKey -func checkUselessPeer(peer: Peer) {.raises: [UselessPeerError, Defect].} = +func checkUselessPeer(peer: Peer) {.raises: [UselessPeerError].} = if peer.dispatcher.numProtocols == 0: # XXX: Send disconnect + UselessPeer raise newException(UselessPeerError, "Useless peer") proc initPeerState*(peer: Peer, capabilities: openArray[Capability]) - {.raises: [UselessPeerError, Defect].} = + {.raises: [UselessPeerError].} = peer.dispatcher = getDispatcher(peer.network, capabilities) checkUselessPeer(peer) diff --git a/eth/p2p/rlpxcrypt.nim b/eth/p2p/rlpxcrypt.nim index abfaa80..6affb45 100644 --- a/eth/p2p/rlpxcrypt.nim +++ b/eth/p2p/rlpxcrypt.nim @@ -1,6 +1,6 @@ # # Ethereum P2P -# (c) Copyright 2018 +# (c) Copyright 2018-2023 # Status Research & Development GmbH # # Licensed under either of @@ -10,7 +10,7 @@ ## This module implements RLPx cryptography -{.push raises: [Defect].} +{.push raises: [].} import nimcrypto/[bcmode, keccak, rijndael, utils], stew/results diff --git a/eth/trie/db.nim b/eth/trie/db.nim index 361be60..ed6b1b5 100644 --- a/eth/trie/db.nim +++ b/eth/trie/db.nim @@ -1,4 +1,12 @@ -{.push raises: [Defect].} +# nim-eth +# Copyright (c) 2018-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + + +{.push raises: [].} import std/[options, tables, hashes, sets], @@ -15,17 +23,17 @@ type # XXX: poor's man vtref types PutProc = proc (db: RootRef, key, val: openArray[byte]) {. - gcsafe, raises: [Defect].} + gcsafe, raises: [].} GetProc = proc (db: RootRef, key: openArray[byte]): seq[byte] {. - gcsafe, raises: [Defect].} + gcsafe, raises: [].} ## The result will be empty seq if not found DelProc = proc (db: RootRef, key: openArray[byte]): bool {. - gcsafe, raises: [Defect].} + gcsafe, raises: [].} ContainsProc = proc (db: RootRef, key: openArray[byte]): bool {. - gcsafe, raises: [Defect].} + gcsafe, raises: [].} TrieDatabaseRef* = ref object obj: RootRef diff --git a/eth/trie/hexary.nim b/eth/trie/hexary.nim index dcda646..9699eb7 100644 --- a/eth/trie/hexary.nim +++ b/eth/trie/hexary.nim @@ -1,3 +1,10 @@ +# nim-eth +# Copyright (c) 2018-2023 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + import std/[options, tables], nimcrypto/[keccak, hash], @@ -37,14 +44,14 @@ type MissingNodeError* = ref object of AssertionDefect nodeHashBytes*: seq[byte] proc dbGet(db: DB, data: openArray[byte]): seq[byte] - {.gcsafe, raises: [Defect].} = + {.gcsafe, raises: [].} = db.get(data) proc dbGet(db: DB, key: Rlp): seq[byte] = dbGet(db, key.expectHash) proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey - {.gcsafe, raises: [Defect].} + {.gcsafe, raises: [].} # For stateless mode, it's possible for nodes to be missing from the DB, # and we need the higher-level code to be able to find out the *path* to @@ -52,7 +59,7 @@ proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey # node is missing we'll raise an exception to get that information up to # where it's needed. proc getPossiblyMissingNode(db: DB, data: openArray[byte], fullPath: NibblesSeq, pathIndex: int, errorIfMissing: bool): seq[byte] - {.gcsafe, raises: [Defect].} = + {.gcsafe, raises: [].} = let nodeBytes = db.get(data) # need to call this before the call to contains, otherwise CaptureDB complains if nodeBytes.len > 0 or not errorIfMissing: nodeBytes @@ -76,7 +83,7 @@ template initSecureHexaryTrie*(db: DB, rootHash: KeccakHash, isPruning = true, s SecureHexaryTrie initHexaryTrie(db, rootHash, isPruning, shouldMissingNodesBeErrors) proc initHexaryTrie*(db: DB, isPruning = true, shouldMissingNodesBeErrors = false): HexaryTrie - {.raises: [Defect].} = + {.raises: [].} = result.db = db result.root = result.db.dbPut(emptyRlp) result.isPruning = isPruning @@ -115,7 +122,7 @@ proc getLookup(db: DB, elem: Rlp, fullPath: NibblesSeq, pathIndex: int, errorIfM else: rlpFromBytes(getPossiblyMissingNode(db, elem.expectHash, fullPath, pathIndex, errorIfMissing)) proc getAux(db: DB, nodeRlp: Rlp, fullPath: NibblesSeq, pathIndex: int, errorIfMissing: bool): seq[byte] - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = if not nodeRlp.hasData or nodeRlp.isEmpty: return @@ -377,7 +384,7 @@ proc dbDel(t: var HexaryTrie, data: openArray[byte]) = if data.len >= 32: t.prune(data.keccakHash.data) proc dbPut(db: DB, data: openArray[byte]): TrieNodeKey - {.raises: [Defect].} = + {.raises: [].} = result.hash = data.keccakHash result.usedBytes = 32 put(db, result.asDbKey, data) @@ -439,7 +446,7 @@ proc deleteAt(self: var HexaryTrie; origRlp: Rlp, fullPath: NibblesSeq, pathIndex: int): seq[byte] - {.gcsafe, raises: [RlpError, Defect].} + {.gcsafe, raises: [RlpError].} proc deleteAux(self: var HexaryTrie; rlpWriter: var RlpWriter; @@ -498,7 +505,7 @@ proc mergeAndGraft(self: var HexaryTrie; # If the key is present, returns the RLP bytes for a node that # omits this key. Returns an empty seq if the key is absent. proc deleteAt(self: var HexaryTrie; origRlp: Rlp, fullPath: NibblesSeq, pathIndex: int): seq[byte] - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = if origRlp.isEmpty: # It's empty RLP, so the key is absent, so no change necessary. return @@ -592,7 +599,7 @@ proc del*(self: var HexaryTrie; key: openArray[byte]) = proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash, fullPath: NibblesSeq, pathIndex: int, value: openArray[byte], isInline = false): seq[byte] - {.gcsafe, raises: [RlpError, Defect].} + {.gcsafe, raises: [RlpError].} proc mergeAt(self: var HexaryTrie, rlp: Rlp, fullPath: NibblesSeq, pathIndex: int, value: openArray[byte], @@ -613,7 +620,7 @@ proc mergeAtAux(self: var HexaryTrie, output: var RlpWriter, orig: Rlp, proc mergeAt(self: var HexaryTrie, orig: Rlp, origHash: KeccakHash, fullPath: NibblesSeq, pathIndex: int, value: openArray[byte], isInline = false): seq[byte] - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = let path = fullPath.slice(pathIndex) template origWithNewValue: auto = self.prune(origHash.data) @@ -771,7 +778,7 @@ proc maybeGetLookup(db: DB, elem: Rlp): Option[Rlp] = some(rlpFromBytes(bytes)) proc maybeGetAux(db: DB, nodeRlp: Rlp, fullPath: NibblesSeq, pathIndex: int): Option[seq[byte]] - {.gcsafe, raises: [RlpError, Defect].} = + {.gcsafe, raises: [RlpError].} = # FIXME-Adam: do I need to distinguish between these two cases? if not nodeRlp.hasData: let zero: seq[byte] = @[] diff --git a/eth/trie/hexary_proof_verification.nim b/eth/trie/hexary_proof_verification.nim index f94c8e2..6c20314 100644 --- a/eth/trie/hexary_proof_verification.nim +++ b/eth/trie/hexary_proof_verification.nim @@ -1,11 +1,11 @@ # proof verification -# Copyright (c) 2022 Status Research & Development GmbH +# Copyright (c) 2022-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, options, sequtils], diff --git a/eth/utp/clock_drift_calculator.nim b/eth/utp/clock_drift_calculator.nim index 6a718e4..6d2d0a1 100644 --- a/eth/utp/clock_drift_calculator.nim +++ b/eth/utp/clock_drift_calculator.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import chronos diff --git a/eth/utp/delay_histogram.nim b/eth/utp/delay_histogram.nim index e606f19..39185b9 100644 --- a/eth/utp/delay_histogram.nim +++ b/eth/utp/delay_histogram.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import chronos, diff --git a/eth/utp/growable_buffer.nim b/eth/utp/growable_buffer.nim index 660b5fb..310d321 100644 --- a/eth/utp/growable_buffer.nim +++ b/eth/utp/growable_buffer.nim @@ -1,21 +1,23 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. +{.push raises: [].} + import std/[options, math] export options -# Buffer implementation similar to the one in in reference implementation. -# Main rationale for it, is to refer to items in buffer by their sequence number, -# and support out of order packets. -# Therefore it is super specific data structure, and it mostly usefully for -# utp implementation. -# Another alternative would be to use standard deque from deques module, and calculate -# item indexes from their sequence numbers. +# Buffer implementation similar to the one in the reference implementation. +# Main rationale for it is to refer to items in buffer by their sequence number +# and to support out of order packets. +# Therefore it is a super specific data structure, and it mostly usefully for +# the uTP implementation. +# An alternative could be to use standard deque from deques module, and +# calculate item indexes from their sequence numbers. type GrowableCircularBuffer*[A] = object items: seq[Option[A]] @@ -44,7 +46,9 @@ 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 {.gcsafe, raises: [].}): bool = let maybeElem = buff.get(i) if (maybeElem.isSome()): let elem = maybeElem.unsafeGet() @@ -53,8 +57,8 @@ proc exists*[A](buff: GrowableCircularBuffer[A], i: uint32, check: proc (x: A): false proc `[]`*[A](buff: var GrowableCircularBuffer[A], i: uint32): var A = - ## Returns contents of the `var GrowableCircularBuffer`. If it is not set, then an exception - ## is thrown. + ## Returns contents of the `var GrowableCircularBuffer`. If it is not set, + ## then an exception is thrown. buff.items[i and buff.mask].get() proc len*[A](buff: GrowableCircularBuffer[A]): int = @@ -74,7 +78,8 @@ proc calculateNextMask(currentMask: uint32, index:uint32): uint32 = # Item contains the element we want to make space for # index is the index in the list. -proc ensureSize*[A](buff: var GrowableCircularBuffer[A], item: uint32, index: uint32) = +proc ensureSize*[A]( + buff: var GrowableCircularBuffer[A], item: uint32, index: uint32) = if (index > buff.mask): let newMask = calculateNextMask(buff.mask, index) var newSeq = newSeq[Option[A]](int(newMask) + 1) diff --git a/eth/utp/ledbat_congestion_control.nim b/eth/utp/ledbat_congestion_control.nim index edf58e3..8248079 100644 --- a/eth/utp/ledbat_congestion_control.nim +++ b/eth/utp/ledbat_congestion_control.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import chronos, diff --git a/eth/utp/packets.nim b/eth/utp/packets.nim index da3f740..92f072f 100644 --- a/eth/utp/packets.nim +++ b/eth/utp/packets.nim @@ -7,7 +7,7 @@ # uTP packet format as specified in: # https://www.bittorrent.org/beps/bep_0029.html -{.push raises: [Defect].} +{.push raises: [].} import faststreams, diff --git a/eth/utp/utp.nim b/eth/utp/utp.nim index 23a911e..58406b8 100644 --- a/eth/utp/utp.nim +++ b/eth/utp/utp.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import chronos, stew/[results, byteutils], @@ -12,8 +12,9 @@ import ./utp_socket, ./utp_protocol -# Exemple application to interact with reference implementation server to help with implementation -# To run lib utp server: +# Example application to interact with the reference implementation server +# to be able to test against the reference implementation. +# To run libutp server: # 1. git clone https://github.com/bittorrent/libutp.git # 2. cd libutp # 3. make @@ -21,7 +22,9 @@ import when isMainModule: proc echoIncomingSocketCallBack(): AcceptConnectionCallback[TransportAddress] = return ( - proc (server: UtpRouter[TransportAddress], client: UtpSocket[TransportAddress]): Future[void] {.gcsafe, raises: [Defect].} = + proc (server: UtpRouter[TransportAddress], + client: UtpSocket[TransportAddress]): + Future[void] {.gcsafe, raises: [].} = echo "received incoming connection" let fakeFuture = newFuture[void]() fakeFuture.complete() diff --git a/eth/utp/utp_discv5_protocol.nim b/eth/utp/utp_discv5_protocol.nim index 57126b3..06a91e5 100644 --- a/eth/utp/utp_discv5_protocol.nim +++ b/eth/utp/utp_discv5_protocol.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021-2022 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[hashes, sugar], diff --git a/eth/utp/utp_protocol.nim b/eth/utp/utp_protocol.nim index 2fc4df6..8bcae22 100644 --- a/eth/utp/utp_protocol.nim +++ b/eth/utp/utp_protocol.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, options, hashes, math], @@ -23,7 +23,9 @@ type transport: DatagramTransport utpRouter: UtpRouter[TransportAddress] - SendCallbackBuilder* = proc (d: DatagramTransport): SendCallback[TransportAddress] {.gcsafe, raises: [Defect].} + SendCallbackBuilder* = + proc (d: DatagramTransport): + SendCallback[TransportAddress] {.gcsafe, raises: [].} # This should probably be defined in TransportAddress module, as hash function should # be consistent with equality function @@ -82,7 +84,7 @@ proc new*( socketConfig: SocketConfig = SocketConfig.init(), allowConnectionCb: AllowConnectionCallback[TransportAddress] = nil, sendCallbackBuilder: SendCallbackBuilder = nil, - rng = newRng()): UtpProtocol {.raises: [Defect, CatchableError].} = + rng = newRng()): UtpProtocol {.raises: [CatchableError].} = doAssert(not(isNil(acceptConnectionCb))) @@ -111,7 +113,7 @@ proc new*( socketConfig: SocketConfig = SocketConfig.init(), allowConnectionCb: AllowConnectionCallback[TransportAddress] = nil, sendCallbackBuilder: SendCallbackBuilder = nil, - rng = newRng()): UtpProtocol {.raises: [Defect, CatchableError].} = + rng = newRng()): UtpProtocol {.raises: [CatchableError].} = GC_ref(udata) UtpProtocol.new( acceptConnectionCb, diff --git a/eth/utp/utp_router.nim b/eth/utp/utp_router.nim index f7154d6..e4391e6 100644 --- a/eth/utp/utp_router.nim +++ b/eth/utp/utp_router.nim @@ -4,7 +4,7 @@ # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[tables, options, sugar], @@ -38,12 +38,12 @@ type # ``server`` - UtpProtocol object. # ``client`` - accepted client utp socket. AcceptConnectionCallback*[A] = proc(server: UtpRouter[A], - client: UtpSocket[A]): Future[void] {.gcsafe, raises: [Defect].} + client: UtpSocket[A]): Future[void] {.gcsafe, raises: [].} # Callback to act as firewall for incoming peers. Should return true if peer # is allowed to connect. AllowConnectionCallback*[A] = proc(r: UtpRouter[A], remoteAddress: A, - connectionId: uint16): bool {.gcsafe, raises: [Defect], noSideEffect.} + connectionId: uint16): bool {.gcsafe, raises: [], noSideEffect.} # Object responsible for creating and maintaining table of utp sockets. # Caller should use `processIncomingBytes` proc to feed it with incoming byte diff --git a/eth/utp/utp_socket.nim b/eth/utp/utp_socket.nim index 3e5fa47..3c81ab9 100644 --- a/eth/utp/utp_socket.nim +++ b/eth/utp/utp_socket.nim @@ -4,7 +4,7 @@ # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import std/[sugar, deques], @@ -49,7 +49,7 @@ type # Socket callback to send data to remote peer SendCallback*[A] = - proc (to: A, data: seq[byte]): Future[void] {.gcsafe, raises: [Defect]} + proc (to: A, data: seq[byte]): Future[void] {.gcsafe, raises: []} SocketConfig* = object # This is configurable (in contrast to reference impl), as with standard 2 @@ -297,7 +297,7 @@ type # User driven call back to be called whenever socket is permanently closed i.e # reaches destroy state - SocketCloseCallback* = proc (): void {.gcsafe, raises: [Defect].} + SocketCloseCallback* = proc (): void {.gcsafe, raises: [].} ConnectionError* = object of CatchableError diff --git a/eth/utp/utp_utils.nim b/eth/utp/utp_utils.nim index c83da1b..58e9c7d 100644 --- a/eth/utp/utp_utils.nim +++ b/eth/utp/utp_utils.nim @@ -1,10 +1,10 @@ -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # at your option. This file may not be copied, modified, or distributed except according to those terms. -{.push raises: [Defect].} +{.push raises: [].} import chronos diff --git a/tests/p2p/test_discoveryv5.nim b/tests/p2p/test_discoveryv5.nim index cce700a..5df2d0d 100644 --- a/tests/p2p/test_discoveryv5.nim +++ b/tests/p2p/test_discoveryv5.nim @@ -793,7 +793,7 @@ suite "Discovery v5 Tests": proc handler( protocol: TalkProtocol, request: seq[byte], fromId: NodeId, fromUdpAddress: Address): - seq[byte] {.gcsafe, raises: [Defect].} = + seq[byte] {.gcsafe, raises: [].} = request let echoProtocol = TalkProtocol(protocolHandler: handler) @@ -820,7 +820,7 @@ suite "Discovery v5 Tests": proc handler( protocol: TalkProtocol, request: seq[byte], fromId: NodeId, fromUdpAddress: Address): - seq[byte] {.gcsafe, raises: [Defect].} = + seq[byte] {.gcsafe, raises: [].} = request let echoProtocol = TalkProtocol(protocolHandler: handler) @@ -844,7 +844,7 @@ suite "Discovery v5 Tests": proc handler( protocol: TalkProtocol, request: seq[byte], fromId: NodeId, fromUdpAddress: Address): - seq[byte] {.gcsafe, raises: [Defect].} = + seq[byte] {.gcsafe, raises: [].} = request let echoProtocol = TalkProtocol(protocolHandler: handler) @@ -883,7 +883,7 @@ suite "Discovery v5 Tests": proc handler( protocol: TalkProtocol, request: seq[byte], fromId: NodeId, fromUdpAddress: Address): - seq[byte] {.gcsafe, raises: [Defect].} = + seq[byte] {.gcsafe, raises: [].} = # Return the request + same protocol id + 2 bytes, to make it 1 byte # bigger than the request request & "echo12".toBytes() diff --git a/tests/trie/test_branches_utils.nim b/tests/trie/test_branches_utils.nim index 0773e81..ad31ba2 100644 --- a/tests/trie/test_branches_utils.nim +++ b/tests/trie/test_branches_utils.nim @@ -58,7 +58,7 @@ suite "branches utils": discard getBranch(db, trie.getRootHash(), key) except InvalidKeyError: check(true) - except: + except CatchableError: check(false) const trieNodesData = [ diff --git a/tests/trie/test_hexary_proof.nim b/tests/trie/test_hexary_proof.nim index 091590e..74ad000 100644 --- a/tests/trie/test_hexary_proof.nim +++ b/tests/trie/test_hexary_proof.nim @@ -1,5 +1,5 @@ # proof verification -# Copyright (c) 2022 Status Research & Development GmbH +# Copyright (c) 2022-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -7,7 +7,7 @@ {.used.} -{.push raises: [Defect].} +{.push raises: [].} import unittest2, diff --git a/tests/utp/test_buffer.nim b/tests/utp/test_buffer.nim index 8b1cbdb..3a14160 100644 --- a/tests/utp/test_buffer.nim +++ b/tests/utp/test_buffer.nim @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2021 Status Research & Development GmbH +# Copyright (c) 2020-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -67,17 +67,17 @@ suite "Utp ring buffer": let textIdx = 11'u32 check: - not buff.exists(textIdx, x => x.foo == text) + not buff.exists(textIdx, x {.gcsafe, raises: [].} => x.foo == text) buff.put(textIdx, TestObj(foo: "old")) check: - not buff.exists(textIdx, x => x.foo == text) + not buff.exists(textIdx, x {.gcsafe, raises: [].} => x.foo == text) buff[textIdx].foo = text check: - buff.exists(textIdx, x => x.foo == text) + buff.exists(textIdx, x {.gcsafe, raises: [].} => x.foo == text) test "Deleting elements from buffer": var buff = GrowableCircularBuffer[int].init(size = 4) @@ -144,7 +144,7 @@ suite "Utp ring buffer": buff.ensureSize(0, 1) buff.put(0, 0) - # index 2 will not fit in buffer of size 2 so it will need to be expanded to 4 + # index 2 will not fit in buffer of size 2 so it needs to be expanded to 4 buff.ensureSize(1, 2) buff.put(1, 1) diff --git a/tests/utp/test_utils.nim b/tests/utp/test_utils.nim index c94b71a..9307581 100644 --- a/tests/utp/test_utils.nim +++ b/tests/utp/test_utils.nim @@ -4,7 +4,7 @@ import ../../eth/utp/packets, ../../eth/keys -type AssertionCallback = proc(): bool {.gcsafe, raises: [Defect].} +type AssertionCallback = proc(): bool {.gcsafe, raises: [].} let testBufferSize* = 1024'u32 let defaultRcvOutgoingId = 314'u16