diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 52b6034707..34073e25d4 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -4,8 +4,7 @@ else: {.push raises: [].} import - std/[options, strutils, os, sequtils], - stew/shims/net as stewNet, + std/[options, strutils, os, sequtils, net], chronicles, chronos, metrics, diff --git a/tests/waku_store_legacy/test_wakunode_store.nim b/tests/waku_store_legacy/test_wakunode_store.nim index 8d7f20d28a..ede1f943dc 100644 --- a/tests/waku_store_legacy/test_wakunode_store.nim +++ b/tests/waku_store_legacy/test_wakunode_store.nim @@ -31,7 +31,7 @@ import ../testlib/wakucore, ../testlib/wakunode -procSuite "WakuNode - Store": +procSuite "WakuNode - Store Legacy": ## Fixtures let timeOrigin = now() let msgListA = diff --git a/tests/wakunode2/test_app.nim b/tests/wakunode2/test_app.nim index 9503169021..fa5099f718 100644 --- a/tests/wakunode2/test_app.nim +++ b/tests/wakunode2/test_app.nim @@ -9,7 +9,11 @@ import libp2p/crypto/secp, libp2p/multiaddress, libp2p/switch -import ../testlib/common, ../testlib/wakucore, ../testlib/wakunode +import + ../testlib/common, + ../testlib/wakucore, + ../testlib/wakunode, + ../../waku/node/waku_metrics include ../../waku/factory/waku diff --git a/waku/common/confutils/envvar/std/net.nim b/waku/common/confutils/envvar/std/net.nim index 8309c69c63..4f46fa9e1e 100644 --- a/waku/common/confutils/envvar/std/net.nim +++ b/waku/common/confutils/envvar/std/net.nim @@ -3,7 +3,7 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import std/strutils, stew/shims/net +import std/[strutils, net] import ../../../envvar_serialization export net, envvar_serialization diff --git a/waku/common/databases/db_postgres/dbconn.nim b/waku/common/databases/db_postgres/dbconn.nim index b7b07e4e18..3811ec8506 100644 --- a/waku/common/databases/db_postgres/dbconn.nim +++ b/waku/common/databases/db_postgres/dbconn.nim @@ -1,4 +1,4 @@ -import std/[times, strutils, strformat], stew/results, chronos +import std/[times, strutils], stew/results, chronos include db_postgres diff --git a/waku/common/databases/dburl.nim b/waku/common/databases/dburl.nim index 9b033dc0f4..a6614ab3d1 100644 --- a/waku/common/databases/dburl.nim +++ b/waku/common/databases/dburl.nim @@ -3,7 +3,7 @@ import std/strutils, regex, stew/results proc validateDbUrl*(dbUrl: string): Result[string, string] = ## dbUrl mimics SQLAlchemy Database URL schema ## See: https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls - let regex = re"^\w+:\/\/.+:.+@[\w*-.]+:[0-9]+\/[\w*-.]+$" + let regex = re2"^\w+:\/\/.+:.+@[\w*-.]+:[0-9]+\/[\w*-.]+$" let dbUrl = dbUrl.strip() if "sqlite" in dbUrl or dbUrl == "" or dbUrl == "none" or dbUrl.match(regex): return ok(dbUrl) diff --git a/waku/common/enr/builder.nim b/waku/common/enr/builder.nim index 93220819c4..84b89ca025 100644 --- a/waku/common/enr/builder.nim +++ b/waku/common/enr/builder.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/options, + std/[options, net], stew/results, - stew/shims/net, eth/keys as eth_keys, eth/p2p/discoveryv5/enr, libp2p/crypto/crypto as libp2p_crypto diff --git a/waku/common/logging.nim b/waku/common/logging.nim index 6cd407bd1d..7b242ba9c2 100644 --- a/waku/common/logging.nim +++ b/waku/common/logging.nim @@ -1,10 +1,6 @@ ## This code has been copied and addapted from `status-im/nimbu-eth2` project. ## Link: https://github.com/status-im/nimbus-eth2/blob/c585b0a5b1ae4d55af38ad7f4715ad455e791552/beacon_chain/nimbus_binary_common.nim -import - std/[strutils, typetraits], - chronicles, - chronicles/log_output, - chronicles/topics_registry +import std/typetraits, chronicles, chronicles/log_output, chronicles/topics_registry export chronicles.LogLevel diff --git a/waku/common/utils/nat.nim b/waku/common/utils/nat.nim index 9c69fce9ed..e05a345e62 100644 --- a/waku/common/utils/nat.nim +++ b/waku/common/utils/nat.nim @@ -3,8 +3,8 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import std/[options, strutils] -import chronicles, eth/net/nat, stew/results, stew/shims/net, nativesockets +import std/[options, strutils, net] +import chronicles, eth/net/nat, stew/results, nativesockets logScope: topics = "nat" diff --git a/waku/common/utils/sequence.nim b/waku/common/utils/sequence.nim index ca61b36e95..7af75c32b1 100644 --- a/waku/common/utils/sequence.nim +++ b/waku/common/utils/sequence.nim @@ -3,8 +3,6 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import std/sequtils - proc flatten*[T](a: seq[seq[T]]): seq[T] = var aFlat = newSeq[T](0) for subseq in a: diff --git a/waku/discovery/waku_discv5.nim b/waku/discovery/waku_discv5.nim index 85f3658294..2b135044d3 100644 --- a/waku/discovery/waku_discv5.nim +++ b/waku/discovery/waku_discv5.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/[sequtils, strutils, options, sets], + std/[sequtils, strutils, options, sets, net], stew/results, - stew/shims/net, chronos, chronicles, metrics, diff --git a/waku/discovery/waku_dnsdisc.nim b/waku/discovery/waku_dnsdisc.nim index b635679a12..9d1b76b6a3 100644 --- a/waku/discovery/waku_dnsdisc.nim +++ b/waku/discovery/waku_dnsdisc.nim @@ -9,8 +9,7 @@ else: ## EIP-1459 is defined in https://eips.ethereum.org/EIPS/eip-1459 import - std/options, - stew/shims/net, + std/[options, net], chronicles, chronos, metrics, diff --git a/waku/factory/builder.nim b/waku/factory/builder.nim index af68501594..3d64f58559 100644 --- a/waku/factory/builder.nim +++ b/waku/factory/builder.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/options, + std/[options, net], stew/results, - stew/shims/net, chronicles, libp2p/crypto/crypto, libp2p/builders, diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index 4dd2f4c500..abcc7a0f7a 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -764,8 +764,6 @@ proc readValue*( except CatchableError: raise newException(SerializationError, getCurrentExceptionMsg()) -{.push warning[ProveInit]: off.} - proc load*(T: type WakuNodeConf, version = ""): ConfResult[T] = try: let conf = WakuNodeConf.load( @@ -789,5 +787,3 @@ proc defaultWakuNodeConf*(): ConfResult[WakuNodeConf] = return ok(conf) except CatchableError: return err("exception in defaultWakuNodeConf: " & getCurrentExceptionMsg()) - -{.pop.} diff --git a/waku/factory/internal_config.nim b/waku/factory/internal_config.nim index 49d0146b66..ca3410daaa 100644 --- a/waku/factory/internal_config.nim +++ b/waku/factory/internal_config.nim @@ -4,9 +4,8 @@ import libp2p/crypto/crypto, libp2p/multiaddress, libp2p/nameresolving/dnsresolver, - std/[options, sequtils], - stew/results, - stew/shims/net + std/[options, sequtils, net], + stew/results import ./external_config, ../common/utils/nat, diff --git a/waku/factory/validator_signed.nim b/waku/factory/validator_signed.nim index f33d362dee..5686ed1f8a 100644 --- a/waku/factory/validator_signed.nim +++ b/waku/factory/validator_signed.nim @@ -4,14 +4,12 @@ else: {.push raises: [].} import - std/math, chronicles, chronos, metrics, stew/byteutils, stew/endians2, libp2p/protocols/pubsub/gossipsub, - libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/errors, nimcrypto/sha2, secp256k1 diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 63186e613b..9b85508868 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -4,7 +4,7 @@ else: {.push raises: [].} import - std/[options, strutils, sequtils], + std/[options, sequtils], stew/results, chronicles, chronos, @@ -21,20 +21,10 @@ import ../../waku/common/logging, ../../waku/waku_core, ../../waku/waku_node, - ../../waku/node/waku_metrics, ../../waku/node/peer_manager, ../../waku/node/health_monitor, ../../waku/waku_api/message_cache, - ../../waku/waku_api/handlers, ../../waku/waku_api/rest/server, - ../../waku/waku_api/rest/debug/handlers as rest_debug_api, - ../../waku/waku_api/rest/relay/handlers as rest_relay_api, - ../../waku/waku_api/rest/filter/handlers as rest_filter_api, - ../../waku/waku_api/rest/lightpush/handlers as rest_lightpush_api, - ../../waku/waku_api/rest/store/handlers as rest_store_api, - ../../waku/waku_api/rest/legacy_store/handlers as rest_legacy_store_api, - ../../waku/waku_api/rest/health/handlers as rest_health_api, - ../../waku/waku_api/rest/admin/handlers as rest_admin_api, ../../waku/waku_archive, ../../waku/discovery/waku_dnsdisc, ../../waku/discovery/waku_discv5, diff --git a/waku/node/config.nim b/waku/node/config.nim index 3e06506222..5902f5b01c 100644 --- a/waku/node/config.nim +++ b/waku/node/config.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/[options, sequtils, strutils], + std/[options, sequtils, strutils, net], stew/results, - stew/shims/net, libp2p/[multiaddress, multicodec] import ../../waku/waku_core/peers import ../waku_enr diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index f43573169b..7221e7d8bd 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -4,13 +4,12 @@ else: {.push raises: [].} import - std/[hashes, options, sugar, tables, strutils, sequtils, os], + std/[hashes, options, sugar, tables, strutils, sequtils, os, net], chronos, chronicles, metrics, stew/results, stew/byteutils, - stew/shims/net as stewNet, eth/keys, nimcrypto, bearssl/rand, @@ -435,7 +434,7 @@ proc mountFilter*( filter_subscriptions.DefaultSubscriptionTimeToLiveSec, maxFilterPeers: uint32 = filter_subscriptions.MaxFilterPeers, maxFilterCriteriaPerPeer: uint32 = filter_subscriptions.MaxFilterCriteriaPerPeer, -) {.async, raises: [Defect, LPError].} = +) {.async: (raises: []).} = ## Mounting filter v2 protocol info "mounting filter protocol" @@ -444,9 +443,15 @@ proc mountFilter*( ) if node.started: - await node.wakuFilter.start() + try: + await node.wakuFilter.start() + except CatchableError: + error "failed to start wakuFilter", error = getCurrentExceptionMsg() - node.switch.mount(node.wakuFilter, protocolMatcher(WakuFilterSubscribeCodec)) + try: + node.switch.mount(node.wakuFilter, protocolMatcher(WakuFilterSubscribeCodec)) + except LPError: + error "failed to mount wakuFilter", error = getCurrentExceptionMsg() proc filterHandleMessage*( node: WakuNode, pubsubTopic: PubsubTopic, message: WakuMessage @@ -457,7 +462,7 @@ proc filterHandleMessage*( await node.wakuFilter.handleMessage(pubsubTopic, message) -proc mountFilterClient*(node: WakuNode) {.async, raises: [Defect, LPError].} = +proc mountFilterClient*(node: WakuNode) {.async: (raises: []).} = ## Mounting both filter ## Giving option for application level to choose btw own push message handling or ## rely on node provided cache. - This only applies for v2 filter client @@ -466,16 +471,22 @@ proc mountFilterClient*(node: WakuNode) {.async, raises: [Defect, LPError].} = node.wakuFilterClient = WakuFilterClient.new(node.peerManager, node.rng) if node.started: - await node.wakuFilterClient.start() + try: + await node.wakuFilterClient.start() + except CatchableError: + error "failed to start wakuFilterClient", error = getCurrentExceptionMsg() - node.switch.mount(node.wakuFilterClient, protocolMatcher(WakuFilterSubscribeCodec)) + try: + node.switch.mount(node.wakuFilterClient, protocolMatcher(WakuFilterSubscribeCodec)) + except LPError: + error "failed to mount wakuFilterClient", error = getCurrentExceptionMsg() proc filterSubscribe*( node: WakuNode, pubsubTopic: Option[PubsubTopic], contentTopics: ContentTopic | seq[ContentTopic], peer: RemotePeerInfo | string, -): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = ## Registers for messages that match a specific filter. Triggers the handler whenever a message is received. if node.wakuFilterClient.isNil(): error "cannot register filter subscription to topic", @@ -528,22 +539,29 @@ proc filterSubscribe*( let content = topics.mapIt($it) node.wakuFilterClient.subscribe(remotePeer, $pubsub, content) - let finished = await allFinished(futures) - var subRes: FilterSubscribeResult = FilterSubscribeResult.ok() - for fut in finished: - let res = fut.read() + try: + let finished = await allFinished(futures) - if res.isErr(): - error "failed filter subscription", error = res.error - waku_node_errors.inc(labelValues = ["subscribe_filter_failure"]) - subRes = FilterSubscribeResult.err(res.error) + for fut in finished: + let res = fut.read() - for pubsub, topics in topicMap.pairs: - info "subscribed to topic", pubsubTopic = pubsub, contentTopics = topics + if res.isErr(): + error "failed filter subscription", error = res.error + waku_node_errors.inc(labelValues = ["subscribe_filter_failure"]) + subRes = FilterSubscribeResult.err(res.error) - # Purpose is to update Waku Metadata - node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: $pubsub)) + for pubsub, topics in topicMap.pairs: + info "subscribed to topic", pubsubTopic = pubsub, contentTopics = topics + + # Purpose is to update Waku Metadata + node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: $pubsub)) + except CatchableError: + let errMsg = "exception in filterSubscribe: " & getCurrentExceptionMsg() + error "exception in filterSubscribe", error = getCurrentExceptionMsg() + waku_node_errors.inc(labelValues = ["subscribe_filter_failure"]) + subRes = + FilterSubscribeResult.err(FilterSubscribeError.serviceUnavailable(errMsg)) # return the last error or ok return subRes @@ -553,7 +571,7 @@ proc filterUnsubscribe*( pubsubTopic: Option[PubsubTopic], contentTopics: ContentTopic | seq[ContentTopic], peer: RemotePeerInfo | string, -): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = ## Unsubscribe from a content filter V2". let remotePeerRes = parsePeerInfo(peer) @@ -600,29 +618,36 @@ proc filterUnsubscribe*( let content = topics.mapIt($it) node.wakuFilterClient.unsubscribe(remotePeer, $pubsub, content) - let finished = await allFinished(futures) - var unsubRes: FilterSubscribeResult = FilterSubscribeResult.ok() - for fut in finished: - let res = fut.read() + try: + let finished = await allFinished(futures) - if res.isErr(): - error "failed filter unsubscription", error = res.error - waku_node_errors.inc(labelValues = ["unsubscribe_filter_failure"]) - unsubRes = FilterSubscribeResult.err(res.error) + for fut in finished: + let res = fut.read() - for pubsub, topics in topicMap.pairs: - info "unsubscribed from topic", pubsubTopic = pubsub, contentTopics = topics + if res.isErr(): + error "failed filter unsubscription", error = res.error + waku_node_errors.inc(labelValues = ["unsubscribe_filter_failure"]) + unsubRes = FilterSubscribeResult.err(res.error) - # Purpose is to update Waku Metadata - node.topicSubscriptionQueue.emit((kind: PubsubUnsub, topic: $pubsub)) + for pubsub, topics in topicMap.pairs: + info "unsubscribed from topic", pubsubTopic = pubsub, contentTopics = topics + + # Purpose is to update Waku Metadata + node.topicSubscriptionQueue.emit((kind: PubsubUnsub, topic: $pubsub)) + except CatchableError: + let errMsg = "exception in filterUnsubscribe: " & getCurrentExceptionMsg() + error "exception in filterUnsubscribe", error = getCurrentExceptionMsg() + waku_node_errors.inc(labelValues = ["unsubscribe_filter_failure"]) + unsubRes = + FilterSubscribeResult.err(FilterSubscribeError.serviceUnavailable(errMsg)) # return the last error or ok return unsubRes proc filterUnsubscribeAll*( node: WakuNode, peer: RemotePeerInfo | string -): Future[FilterSubscribeResult] {.async, gcsafe, raises: [Defect, ValueError].} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = ## Unsubscribe from a content filter V2". let remotePeerRes = parsePeerInfo(peer) @@ -1055,15 +1080,21 @@ proc mountRlnRelay*( ## Waku peer-exchange -proc mountPeerExchange*(node: WakuNode) {.async, raises: [Defect, LPError].} = +proc mountPeerExchange*(node: WakuNode) {.async: (raises: []).} = info "mounting waku peer exchange" node.wakuPeerExchange = WakuPeerExchange.new(node.peerManager) if node.started: - await node.wakuPeerExchange.start() + try: + await node.wakuPeerExchange.start() + except CatchableError: + error "failed to start wakuPeerExchange", error = getCurrentExceptionMsg() - node.switch.mount(node.wakuPeerExchange, protocolMatcher(WakuPeerExchangeCodec)) + try: + node.switch.mount(node.wakuPeerExchange, protocolMatcher(WakuPeerExchangeCodec)) + except LPError: + error "failed to mount wakuPeerExchange", error = getCurrentExceptionMsg() proc fetchPeerExchangePeers*( node: Wakunode, amount: uint64 @@ -1110,21 +1141,25 @@ proc setPeerExchangePeer*( ## Other protocols -proc mountLibp2pPing*(node: WakuNode) {.async, raises: [Defect, LPError].} = +proc mountLibp2pPing*(node: WakuNode) {.async: (raises: []).} = info "mounting libp2p ping protocol" try: node.libp2pPing = Ping.new(rng = node.rng) except Exception as e: - # This is necessary as `Ping.new*` does not have explicit `raises` requirement - # @TODO: remove exception handling once explicit `raises` in ping module - raise newException(LPError, "Failed to initialize ping protocol") + error "failed to create ping", error = getCurrentExceptionMsg() if node.started: # Node has started already. Let's start ping too. - await node.libp2pPing.start() + try: + await node.libp2pPing.start() + except CatchableError: + error "failed to start libp2pPing", error = getCurrentExceptionMsg() - node.switch.mount(node.libp2pPing) + try: + node.switch.mount(node.libp2pPing) + except LPError: + error "failed to mount libp2pPing", error = getCurrentExceptionMsg() # TODO: Move this logic to PeerManager proc keepaliveLoop(node: WakuNode, keepalive: chronos.Duration) {.async.} = @@ -1153,15 +1188,21 @@ proc startKeepalive*(node: WakuNode) = asyncSpawn node.keepaliveLoop(defaultKeepalive) -proc mountRendezvous*(node: WakuNode) {.async, raises: [Defect, LPError].} = +proc mountRendezvous*(node: WakuNode) {.async: (raises: []).} = info "mounting rendezvous discovery protocol" node.rendezvous = RendezVous.new(node.switch) if node.started: - await node.rendezvous.start() + try: + await node.rendezvous.start() + except CatchableError: + error "failed to start rendezvous", error = getCurrentExceptionMsg() - node.switch.mount(node.rendezvous) + try: + node.switch.mount(node.rendezvous) + except LPError: + error "failed to mount rendezvous", error = getCurrentExceptionMsg() proc isBindIpWithZeroPort(inputMultiAdd: MultiAddress): bool = let inputStr = $inputMultiAdd diff --git a/waku/node/waku_switch.nim b/waku/node/waku_switch.nim index 9e33c56b22..d062911051 100644 --- a/waku/node/waku_switch.nim +++ b/waku/node/waku_switch.nim @@ -5,7 +5,7 @@ else: {.push raises: [].} import - std/[options, math], + std/options, chronos, chronicles, eth/keys, diff --git a/waku/utils/collector.nim b/waku/utils/collector.nim index c85aee0524..32ade16c55 100644 --- a/waku/utils/collector.nim +++ b/waku/utils/collector.nim @@ -5,9 +5,7 @@ else: import metrics -proc parseCollectorIntoF64( - collector: SimpleCollector -): float64 {.gcsafe, raises: [Defect].} = +proc parseCollectorIntoF64(collector: SimpleCollector): float64 {.gcsafe, raises: [].} = {.gcsafe.}: var total = 0.float64 for metrics in collector.metrics: diff --git a/waku/utils/tableutils.nim b/waku/utils/tableutils.nim index a490534be0..dacea7debe 100644 --- a/waku/utils/tableutils.nim +++ b/waku/utils/tableutils.nim @@ -1,4 +1,4 @@ -import std/tables, stew/objects, stew/templateutils +import std/tables, stew/templateutils template keepItIf*[A, B](tableParam: var Table[A, B], itPredicate: untyped) = bind evalTemplateParamOnce diff --git a/waku/waku_api/handlers.nim b/waku/waku_api/handlers.nim index 26338f8cf3..0b99021fbd 100644 --- a/waku/waku_api/handlers.nim +++ b/waku/waku_api/handlers.nim @@ -3,7 +3,7 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import chronos, chronicles, std/[options, sequtils], stew/results +import chronos, std/[options, sequtils], stew/results import ../discovery/waku_discv5, ../waku_relay, ../waku_core, ./message_cache ### Discovery diff --git a/waku/waku_api/rest/admin/handlers.nim b/waku/waku_api/rest/admin/handlers.nim index b0dc762b6f..70c0630dbf 100644 --- a/waku/waku_api/rest/admin/handlers.nim +++ b/waku/waku_api/rest/admin/handlers.nim @@ -5,7 +5,6 @@ else: import std/[strformat, sequtils, tables], - stew/byteutils, chronicles, json_serialization, presto/route, diff --git a/waku/waku_api/rest/builder.nim b/waku/waku_api/rest/builder.nim index 3b139fd9a0..eda835b6db 100644 --- a/waku/waku_api/rest/builder.nim +++ b/waku/waku_api/rest/builder.nim @@ -6,7 +6,6 @@ else: import net, tables import presto import - ../../waku/common/utils/nat, ../../waku/waku_node, ../../waku/discovery/waku_discv5, ../../waku/factory/external_config, diff --git a/waku/waku_api/rest/filter/handlers.nim b/waku/waku_api/rest/filter/handlers.nim index e30efa6ec5..a5308b8538 100644 --- a/waku/waku_api/rest/filter/handlers.nim +++ b/waku/waku_api/rest/filter/handlers.nim @@ -62,7 +62,9 @@ func decodeRequestBody[T]( return ok(requestResult.get()) -proc getStatusDesc(protocolClientRes: filter_protocol_type.FilterSubscribeResult): string = +proc getStatusDesc( + protocolClientRes: filter_protocol_type.FilterSubscribeResult +): string = ## Retrieve proper error cause of FilterSubscribeError - due stringify make some parts of text double if protocolClientRes.isOk: return "OK" @@ -84,8 +86,7 @@ proc convertResponse( ): T = ## Properly convert filter protocol's response to rest response return FilterSubscriptionResponse( - requestId: requestId, - statusDesc: getStatusDesc(protocolClientRes), + requestId: requestId, statusDesc: getStatusDesc(protocolClientRes) ) proc convertResponse( @@ -94,10 +95,8 @@ proc convertResponse( protocolClientRes: filter_protocol_type.FilterSubscribeError, ): T = ## Properly convert filter protocol's response to rest response in case of error - return FilterSubscriptionResponse( - requestId: requestId, - statusDesc: $protocolClientRes, - ) + return + FilterSubscriptionResponse(requestId: requestId, statusDesc: $protocolClientRes) proc convertErrorKindToHttpStatus( kind: filter_protocol_type.FilterSubscribeErrorKind @@ -117,8 +116,6 @@ proc convertErrorKindToHttpStatus( return Http404 of filter_protocol_type.FilterSubscribeErrorKind.SERVICE_UNAVAILABLE: return Http503 - else: - return Http500 proc makeRestResponse( requestId: string, protocolClientRes: filter_protocol_type.FilterSubscribeResult diff --git a/waku/waku_api/rest/health/types.nim b/waku/waku_api/rest/health/types.nim index 937bc64adc..a4f966467c 100644 --- a/waku/waku_api/rest/health/types.nim +++ b/waku/waku_api/rest/health/types.nim @@ -3,12 +3,7 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import - chronicles, - json_serialization, - json_serialization/std/options, - std/tables, - std/sequtils +import chronicles, json_serialization, json_serialization/std/options import ../../../waku_node, ../serdes #### Serialization and deserialization diff --git a/waku/waku_api/rest/lightpush/handlers.nim b/waku/waku_api/rest/lightpush/handlers.nim index 9a0611c8b2..83b15c098f 100644 --- a/waku/waku_api/rest/lightpush/handlers.nim +++ b/waku/waku_api/rest/lightpush/handlers.nim @@ -16,7 +16,6 @@ import ../../waku/node/peer_manager, ../../../waku_node, ../../waku/waku_lightpush/common, - ../../waku/waku_lightpush/self_req_handler, ../../handlers, ../serdes, ../responses, diff --git a/waku/waku_api/rest/lightpush/types.nim b/waku/waku_api/rest/lightpush/types.nim index 44ddbef25a..e25a41c598 100644 --- a/waku/waku_api/rest/lightpush/types.nim +++ b/waku/waku_api/rest/lightpush/types.nim @@ -8,10 +8,9 @@ import chronicles, json_serialization, json_serialization/std/options, - presto/[route, client, common] + presto/[route, client] -import - ../../../common/base64, ../../../waku_core, ../relay/types as relay_types, ../serdes +import ../../../waku_core, ../relay/types as relay_types, ../serdes export relay_types diff --git a/waku/waku_api/rest/origin_handler.nim b/waku/waku_api/rest/origin_handler.nim index 3468f60c0c..1825b030d2 100644 --- a/waku/waku_api/rest/origin_handler.nim +++ b/waku/waku_api/rest/origin_handler.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/[options, strutils, re], + std/[options, strutils, re, net], stew/results, - stew/shims/net, chronicles, chronos, chronos/apps/http/httpserver diff --git a/waku/waku_api/rest/server.nim b/waku/waku_api/rest/server.nim index b76b7c203d..7e27c0cd50 100644 --- a/waku/waku_api/rest/server.nim +++ b/waku/waku_api/rest/server.nim @@ -3,9 +3,9 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} +import std/net import stew/results, - stew/shims/net, chronicles, chronos, chronos/apps/http/httpserver, diff --git a/waku/waku_archive/driver/postgres_driver/migrations.nim b/waku/waku_archive/driver/postgres_driver/migrations.nim index a3e376e0ae..254decd98e 100644 --- a/waku/waku_archive/driver/postgres_driver/migrations.nim +++ b/waku/waku_archive/driver/postgres_driver/migrations.nim @@ -1,6 +1,6 @@ {.push raises: [].} -import std/[tables, strutils, os], stew/results, chronicles, chronos +import std/strutils, stew/results, chronicles, chronos import ../../../common/databases/common, ../../../../migrations/message_store_postgres/pg_migration_manager, diff --git a/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim b/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim index 28eac59aac..cb918f7fdc 100644 --- a/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim +++ b/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim @@ -4,8 +4,7 @@ else: {.push raises: [].} import chronos, stew/results -import - ../../driver, ../../../common/databases/db_postgres, ../../../common/error_handling +import ../../../common/databases/db_postgres, ../../../common/error_handling ## Simple query to validate that the postgres is working and attending requests const HealthCheckQuery = "SELECT version();" diff --git a/waku/waku_archive/retention_policy/builder.nim b/waku/waku_archive/retention_policy/builder.nim index f4e130b3e0..98d9cf1a5e 100644 --- a/waku/waku_archive/retention_policy/builder.nim +++ b/waku/waku_archive/retention_policy/builder.nim @@ -19,7 +19,7 @@ proc new*( if retPolicy == "" or retPolicy == "none": return ok(none(RetentionPolicy)) - const StoreMessageRetentionPolicyRegex = re"^\w+:\d*\.?\d+((g|m)b)?$" + const StoreMessageRetentionPolicyRegex = re2"^\w+:\d*\.?\d+((g|m)b)?$" if not retPolicy.match(StoreMessageRetentionPolicyRegex): return err("invalid 'store message retention policy' format: " & retPolicy) diff --git a/waku/waku_core/peers.nim b/waku/waku_core/peers.nim index a40c1c7569..d44e89cd9f 100644 --- a/waku/waku_core/peers.nim +++ b/waku/waku_core/peers.nim @@ -4,12 +4,12 @@ else: {.push raises: [].} import - std/[options, sequtils, strutils, uri], + std/[options, sequtils, strutils, uri, net], stew/results, - stew/shims/net, chronos, eth/keys, eth/p2p/discoveryv5/enr, + eth/net/utils, libp2p/crypto/crypto, libp2p/crypto/secp, libp2p/errors, diff --git a/waku/waku_enr/capabilities.nim b/waku/waku_enr/capabilities.nim index 115285e05c..171bce18f1 100644 --- a/waku/waku_enr/capabilities.nim +++ b/waku/waku_enr/capabilities.nim @@ -4,11 +4,7 @@ else: {.push raises: [].} import - std/[options, bitops, sequtils], - stew/results, - stew/shims/net, - eth/keys, - libp2p/crypto/crypto + std/[options, bitops, sequtils, net], stew/results, eth/keys, libp2p/crypto/crypto import ../common/enr const CapabilitiesEnrField* = "waku2" diff --git a/waku/waku_enr/multiaddr.nim b/waku/waku_enr/multiaddr.nim index caf7a819e2..a779faf53e 100644 --- a/waku/waku_enr/multiaddr.nim +++ b/waku/waku_enr/multiaddr.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/[options, sequtils], + std/[options, sequtils, net], stew/[endians2, results], - stew/shims/net, eth/keys, libp2p/[multiaddress, multicodec], libp2p/crypto/crypto diff --git a/waku/waku_enr/sharding.nim b/waku/waku_enr/sharding.nim index 97b3d0d96e..dc73e6b1c3 100644 --- a/waku/waku_enr/sharding.nim +++ b/waku/waku_enr/sharding.nim @@ -4,9 +4,8 @@ else: {.push raises: [].} import - std/[options, bitops, sequtils], + std/[options, bitops, sequtils, net], stew/[endians2, results], - stew/shims/net, chronicles, eth/keys, libp2p/[multiaddress, multicodec], diff --git a/waku/waku_filter_v2/client.nim b/waku/waku_filter_v2/client.nim index 5a772b1306..e20aeaef37 100644 --- a/waku/waku_filter_v2/client.nim +++ b/waku/waku_filter_v2/client.nim @@ -26,22 +26,44 @@ proc sendSubscribeRequest( wfc: WakuFilterClient, servicePeer: RemotePeerInfo, filterSubscribeRequest: FilterSubscribeRequest, -): Future[FilterSubscribeResult] {.async.} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = trace "Sending filter subscribe request", peerId = servicePeer.peerId, filterSubscribeRequest - let connOpt = await wfc.peerManager.dialPeer(servicePeer, WakuFilterSubscribeCodec) - if connOpt.isNone(): - trace "Failed to dial filter service peer", servicePeer - waku_filter_errors.inc(labelValues = [dialFailure]) - return err(FilterSubscribeError.peerDialFailure($servicePeer)) + var connOpt: Option[Connection] + try: + connOpt = await wfc.peerManager.dialPeer(servicePeer, WakuFilterSubscribeCodec) + if connOpt.isNone(): + trace "Failed to dial filter service peer", servicePeer + waku_filter_errors.inc(labelValues = [dialFailure]) + return err(FilterSubscribeError.peerDialFailure($servicePeer)) + except CatchableError: + let errMsg = "failed to dialPeer: " & getCurrentExceptionMsg() + trace "failed to dialPeer", error = getCurrentExceptionMsg() + waku_filter_errors.inc(labelValues = [errMsg]) + return err(FilterSubscribeError.badResponse(errMsg)) let connection = connOpt.get() - # TODO: this can raise an exception - await connection.writeLP(filterSubscribeRequest.encode().buffer) + try: + await connection.writeLP(filterSubscribeRequest.encode().buffer) + except CatchableError: + let errMsg = + "exception in waku_filter_v2 client writeLP: " & getCurrentExceptionMsg() + trace "exception in waku_filter_v2 client writeLP", error = getCurrentExceptionMsg() + waku_filter_errors.inc(labelValues = [errMsg]) + return err(FilterSubscribeError.badResponse(errMsg)) + + var respBuf: seq[byte] + try: + respBuf = await connection.readLp(DefaultMaxSubscribeResponseSize) + except CatchableError: + let errMsg = + "exception in waku_filter_v2 client readLp: " & getCurrentExceptionMsg() + trace "exception in waku_filter_v2 client readLp", error = getCurrentExceptionMsg() + waku_filter_errors.inc(labelValues = [errMsg]) + return err(FilterSubscribeError.badResponse(errMsg)) - let respBuf = await connection.readLp(DefaultMaxSubscribeResponseSize) let respDecodeRes = FilterSubscribeResponse.decode(respBuf) if respDecodeRes.isErr(): trace "Failed to decode filter subscribe response", servicePeer @@ -80,7 +102,7 @@ proc subscribe*( servicePeer: RemotePeerInfo, pubsubTopic: PubsubTopic, contentTopics: ContentTopic | seq[ContentTopic], -): Future[FilterSubscribeResult] {.async.} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = var contentTopicSeq: seq[ContentTopic] when contentTopics is seq[ContentTopic]: contentTopicSeq = contentTopics @@ -99,7 +121,7 @@ proc unsubscribe*( servicePeer: RemotePeerInfo, pubsubTopic: PubsubTopic, contentTopics: ContentTopic | seq[ContentTopic], -): Future[FilterSubscribeResult] {.async.} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = var contentTopicSeq: seq[ContentTopic] when contentTopics is seq[ContentTopic]: contentTopicSeq = contentTopics @@ -115,7 +137,7 @@ proc unsubscribe*( proc unsubscribeAll*( wfc: WakuFilterClient, servicePeer: RemotePeerInfo -): Future[FilterSubscribeResult] {.async.} = +): Future[FilterSubscribeResult] {.async: (raises: []).} = let requestId = generateRequestId(wfc.rng) let filterSubscribeRequest = FilterSubscribeRequest.unsubscribeAll(requestId = requestId) diff --git a/waku/waku_filter_v2/protocol.nim b/waku/waku_filter_v2/protocol.nim index af1d90b13e..100791fa80 100644 --- a/waku/waku_filter_v2/protocol.nim +++ b/waku/waku_filter_v2/protocol.nim @@ -216,8 +216,7 @@ proc handleMessage*( ) {.async.} = let msgHash = computeMessageHash(pubsubTopic, message).to0xHex() - debug "handling message", - pubsubTopic = pubsubTopic, msg_hash = msgHash + debug "handling message", pubsubTopic = pubsubTopic, msg_hash = msgHash let handleMessageStartTime = Moment.now() @@ -312,13 +311,13 @@ proc startMaintainingSubscriptions(wf: WakuFilter, interval: Duration) = wf.maintenanceTask = setTimer(Moment.fromNow(interval), maintainSubs) -method start*(wf: WakuFilter) {.async.} = +method start*(wf: WakuFilter) {.async, base.} = debug "starting filter protocol" wf.startMaintainingSubscriptions(MaintainSubscriptionsInterval) await procCall LPProtocol(wf).start() -method stop*(wf: WakuFilter) {.async.} = +method stop*(wf: WakuFilter) {.async, base.} = debug "stopping filter protocol" if not wf.maintenanceTask.isNil(): wf.maintenanceTask.clearTimer() diff --git a/waku/waku_lightpush/self_req_handler.nim b/waku/waku_lightpush/self_req_handler.nim index b08a87035d..b3094f23c7 100644 --- a/waku/waku_lightpush/self_req_handler.nim +++ b/waku/waku_lightpush/self_req_handler.nim @@ -12,7 +12,7 @@ else: ## which spawn a full service Waku node ## that could be used also as a lightpush client, helping testing and development. -import stew/results, chronos, chronicles, std/options, metrics +import stew/results, chronos, std/options, metrics import ../waku_core, ./protocol, diff --git a/waku/waku_relay/protocol.nim b/waku/waku_relay/protocol.nim index 171b1deeb5..f5772f5c4f 100644 --- a/waku/waku_relay/protocol.nim +++ b/waku/waku_relay/protocol.nim @@ -180,11 +180,11 @@ proc addValidator*( ) {.gcsafe.} = w.wakuValidators.add((handler, errorMessage)) -method start*(w: WakuRelay) {.async.} = +method start*(w: WakuRelay) {.async, base.} = debug "start" await procCall GossipSub(w).start() -method stop*(w: WakuRelay) {.async.} = +method stop*(w: WakuRelay) {.async, base.} = debug "stop" await procCall GossipSub(w).stop() diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index 85f0fd871f..f6ecdea2e3 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -163,7 +163,7 @@ when defined(rln_v2): start: MembershipIndex, rateCommitments = newSeq[RateCommitment](), toRemoveIndices = newSeq[MembershipIndex](), - ): Future[void] {.async: (raises: [Exception]).} = + ): Future[void] {.async: (raises: [Exception]), base.} = initializedGuard(g) # convert the rateCommitment struct to a leaf value @@ -197,7 +197,7 @@ else: start: MembershipIndex, idCommitments = newSeq[IDCommitment](), toRemoveIndices = newSeq[MembershipIndex](), - ): Future[void] {.async: (raises: [Exception]).} = + ): Future[void] {.async: (raises: [Exception]), base.} = initializedGuard(g) waku_rln_membership_insertion_duration_seconds.nanosecondTime: diff --git a/waku/waku_rln_relay/group_manager/static/group_manager.nim b/waku/waku_rln_relay/group_manager/static/group_manager.nim index c577512fac..084aba1af7 100644 --- a/waku/waku_rln_relay/group_manager/static/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/static/group_manager.nim @@ -1,4 +1,4 @@ -import ../group_manager_base, ../../constants, ../../rln, std/sequtils +import ../group_manager_base, ../../rln, std/sequtils, ../../constants export group_manager_base diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index fc2491ca44..c255505cd3 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -4,11 +4,10 @@ else: {.push raises: [].} import - std/[algorithm, sequtils, strutils, tables, times, os, deques], + std/[sequtils, tables, times, deques], chronicles, options, chronos, - chronos/ratelimit, stint, web3, json, @@ -33,8 +32,7 @@ import ../common/error_handling, ../waku_relay, # for WakuRelayHandler ../waku_core, - ../waku_keystore, - ../utils/collector + ../waku_keystore logScope: topics = "waku rln_relay" diff --git a/waku/waku_store/rpc_codec.nim b/waku/waku_store/rpc_codec.nim index 13d7440edb..5f3f65dfff 100644 --- a/waku/waku_store/rpc_codec.nim +++ b/waku/waku_store/rpc_codec.nim @@ -3,7 +3,7 @@ when (NimMajor, NimMinor) < (1, 4): else: {.push raises: [].} -import std/options, stew/arrayops, nimcrypto/hash +import std/options, stew/arrayops import ../common/[protobuf, paging], ../waku_core, ./common const DefaultMaxRpcSize* = -1 diff --git a/waku/waku_store_legacy/self_req_handler.nim b/waku/waku_store_legacy/self_req_handler.nim index 183de1223c..060e073ab7 100644 --- a/waku/waku_store_legacy/self_req_handler.nim +++ b/waku/waku_store_legacy/self_req_handler.nim @@ -13,7 +13,7 @@ ## stored by that local store node. ## -import stew/results, chronos, chronicles +import stew/results, chronos import ./protocol, ./common proc handleSelfStoreRequest*(