Fix missing CancelledError on discv5 waitMessage + results imports (#704)

Fixes a missing CancelledError async raising on discv5 waitMessage
which would cause "Error set on a non-raising future".

Also moves some more results import away from stew.
This commit is contained in:
Kim De Mey 2024-06-13 12:11:25 +02:00 committed by GitHub
parent 7c952cf40e
commit f169068df6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 23 additions and 16 deletions

View File

@ -1,5 +1,5 @@
# Nim Ethereum Keys # Nim Ethereum Keys
# Copyright (c) 2020-2023 Status Research & Development GmbH # Copyright (c) 2020-2024 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# - Apache License, version 2.0, (LICENSE-APACHEv2) # - Apache License, version 2.0, (LICENSE-APACHEv2)
# - MIT license (LICENSE-MIT) # - MIT license (LICENSE-MIT)
@ -17,7 +17,8 @@
import import
std/strformat, std/strformat,
secp256k1, bearssl/hash as bhash, bearssl/rand, secp256k1, bearssl/hash as bhash, bearssl/rand,
stew/[byteutils, objects, results, ptrops], stew/[byteutils, objects, ptrops],
results,
./common/eth_hash ./common/eth_hash
from nimcrypto/utils import burnMem from nimcrypto/utils import burnMem

View File

@ -16,7 +16,8 @@
import import
std/[tables, options, hashes, net], std/[tables, options, hashes, net],
nimcrypto/[bcmode, rijndael, sha2], stint, chronicles, nimcrypto/[bcmode, rijndael, sha2], stint, chronicles,
stew/[results, byteutils, endians2], metrics, stew/[byteutils, endians2], metrics,
results,
".."/../[rlp, keys], ".."/../[rlp, keys],
"."/[messages_encoding, node, enr, hkdf, sessions] "."/[messages_encoding, node, enr, hkdf, sessions]

View File

@ -13,7 +13,8 @@
import import
std/[strutils, macros, algorithm, options, net], std/[strutils, macros, algorithm, options, net],
nimcrypto/[keccak, utils], nimcrypto/[keccak, utils],
stew/[base64, results], stew/base64,
results,
chronicles, chronicles,
".."/../[rlp, keys], ".."/../[rlp, keys],
../../net/utils ../../net/utils

View File

@ -11,7 +11,8 @@
import import
std/net, std/net,
stew/[arrayops, results], stew/arrayops,
results,
../../rlp, ../../rlp,
"."/[messages, enr] "."/[messages, enr]

View File

@ -504,15 +504,15 @@ proc registerRequest(d: Protocol, n: Node, message: seq[byte],
d.pendingRequests.del(nonce) d.pendingRequests.del(nonce)
proc waitMessage(d: Protocol, fromNode: Node, reqId: RequestId): proc waitMessage(d: Protocol, fromNode: Node, reqId: RequestId):
Future[Option[Message]] {.async: (raw: true, raises: []).} = Future[Option[Message]] {.async: (raw: true, raises: [CancelledError]).} =
result = newFuture[Option[Message]]("waitMessage") let retFuture = Future[Option[Message]].Raising([CancelledError]).init("discv5.waitMessage")
let res = result
let key = (fromNode.id, reqId) let key = (fromNode.id, reqId)
sleepAsync(d.responseTimeout).addCallback() do(data: pointer): sleepAsync(d.responseTimeout).addCallback() do(data: pointer):
d.awaitedMessages.del(key) d.awaitedMessages.del(key)
if not res.finished: if not retFuture.finished:
res.complete(none(Message)) retFuture.complete(none(Message))
d.awaitedMessages[key] = result d.awaitedMessages[key] = retFuture
retFuture
proc waitNodes(d: Protocol, fromNode: Node, reqId: RequestId): proc waitNodes(d: Protocol, fromNode: Node, reqId: RequestId):
Future[DiscResult[seq[Record]]] {.async: (raises: [CancelledError]).} = Future[DiscResult[seq[Record]]] {.async: (raises: [CancelledError]).} =

View File

@ -4,7 +4,8 @@
import import
std/[strutils, options], std/[strutils, options],
stew/[byteutils, shims/macros, results], stew/[byteutils, shims/macros],
results,
./rlp/[writer, object_serialization], ./rlp/[writer, object_serialization],
./rlp/priv/defs ./rlp/priv/defs

View File

@ -1,4 +1,4 @@
# Copyright (c) 2020-2023 Status Research & Development GmbH # Copyright (c) 2020-2024 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -12,7 +12,8 @@
import import
faststreams, faststreams,
chronos, chronos,
stew/[endians2, results, objects], stew/[endians2, objects],
results,
../p2p/discoveryv5/random2 ../p2p/discoveryv5/random2
export results, random2 export results, random2

View File

@ -9,7 +9,8 @@
import import
std/[sugar, deques], std/[sugar, deques],
chronos, chronicles, metrics, chronos, chronicles, metrics,
stew/[results, bitops2], stew/bitops2,
results,
./growable_buffer, ./growable_buffer,
./packets, ./packets,
./ledbat_congestion_control, ./ledbat_congestion_control,
@ -18,7 +19,7 @@ import
./clock_drift_calculator ./clock_drift_calculator
export export
chronicles chronicles, results
logScope: logScope:
topics = "eth utp utp_socket" topics = "eth utp utp_socket"