From 549834203dfb1412baac38c71f37c8d072175706 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Tue, 2 Jun 2026 15:42:58 -0300 Subject: [PATCH 01/10] Bump to nim-libp2p 2.0.0 * bump libp2p pin to release/v2.0.0 (c43199378) * pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt * add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix * migrate rng to libp2p Rng type (prod, channels, noise, tests) * noise: take Rng, extract bearSslDrbg internally * waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery) * tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng() * drop libp2p/utils/semaphore (use chronos AsyncSemaphore) * add waku/compat/option_valueor shim where needed * add std/options where transitive re-export dropped --- apps/chat2/chat2.nim | 6 +- apps/chat2bridge/chat2bridge.nim | 2 +- apps/chat2mix/chat2mix.nim | 6 +- apps/networkmonitor/networkmonitor.nim | 2 +- apps/wakucanary/wakucanary.nim | 4 +- channels/reliable_channel.nim | 3 +- .../lightpush_mix/lightpush_publisher_mix.nim | 4 +- library/kernel_api/discovery_api.nim | 1 + library/kernel_api/node_lifecycle_api.nim | 1 + library/kernel_api/peer_manager_api.nim | 1 + library/kernel_api/protocols/filter_api.nim | 1 + .../kernel_api/protocols/lightpush_api.nim | 1 + library/kernel_api/protocols/relay_api.nim | 1 + library/kernel_api/protocols/store_api.nim | 1 + library/libwaku.nim | 1 + nimble.lock | 92 +++++++-- tests/common/test_ratelimit_setting.nim | 7 +- tests/common/test_requestratelimiter.nim | 7 +- tests/node/test_wakunode_filter.nim | 7 +- tests/node/test_wakunode_relay_rln.nim | 8 +- tests/test_helpers.nim | 11 +- tests/test_peer_manager.nim | 18 +- tests/test_waku_dnsdisc.nim | 3 +- tests/test_waku_keepalive.nim | 2 +- tests/test_waku_keystore.nim | 40 ++-- tests/test_waku_keystore_keyfile.nim | 20 +- tests/test_waku_netconfig.nim | 1 + tests/test_waku_noise.nim | 178 +++++++++--------- tests/test_waku_noise_sessions.nim | 38 ++-- tests/test_wakunode.nim | 2 +- tests/testlib/common.nim | 6 +- tests/testlib/wakucore.nim | 21 ++- tests/testlib/wakunode.nim | 3 +- tests/waku_discv5/test_waku_discv5.nim | 11 +- tests/waku_filter_v2/waku_filter_utils.nim | 2 +- tests/waku_lightpush/lightpush_utils.nim | 4 +- .../waku_lightpush_legacy/lightpush_utils.nim | 4 +- tests/waku_relay/test_wakunode_relay.nim | 2 +- tests/waku_relay/utils.nim | 2 +- .../rln/waku_rln_relay_utils.nim | 1 + tests/waku_rln_relay/utils_offchain.nim | 2 +- tests/waku_rln_relay/utils_onchain.nim | 5 +- tests/waku_store/store_utils.nim | 4 +- tests/waku_store/test_wakunode_store.nim | 2 +- tests/wakunode2/test_app.nim | 1 + tests/wakunode2/test_validators.nim | 2 +- tests/wakunode_rest/test_rest_cors.nim | 3 +- tests/wakunode_rest/test_rest_debug.nim | 2 +- .../wakunode_rest/test_rest_debug_serdes.nim | 1 + tests/wakunode_rest/test_rest_filter.nim | 1 + tests/wakunode_rest/test_rest_health.nim | 4 +- tests/wakunode_rest/test_rest_lightpush.nim | 1 + .../test_rest_lightpush_legacy.nim | 1 + tests/wakunode_rest/test_rest_relay.nim | 2 +- .../wakunode_rest/test_rest_relay_serdes.nim | 1 + waku.nimble | 3 +- waku/api/api.nim | 1 + waku/api/api_conf.nim | 1 + waku/api/types.nim | 4 +- waku/common/databases/db_postgres/dbconn.nim | 1 + .../databases/db_postgres/pgasyncpool.nim | 1 + waku/common/databases/db_sqlite.nim | 1 + waku/common/enr/typed_record.nim | 1 + waku/common/rate_limit/request_limiter.nim | 1 + waku/common/utils/parse_size_units.nim | 1 + waku/compat/option_valueor.nim | 35 ++++ waku/discovery/autonat_service.nim | 3 +- waku/discovery/waku_discv5.nim | 11 +- waku/discovery/waku_dnsdisc.nim | 1 + waku/discovery/waku_kademlia.nim | 26 +-- waku/factory/builder.nim | 11 +- .../kademlia_discovery_conf_builder.nim | 1 + .../factory/conf_builder/mix_conf_builder.nim | 3 +- .../conf_builder/rate_limit_conf_builder.nim | 1 + .../store_service_conf_builder.nim | 1 + .../conf_builder/waku_conf_builder.nim | 7 +- waku/factory/internal_config.nim | 1 + waku/factory/node_factory.nim | 5 +- waku/factory/waku.nim | 5 +- waku/incentivization/eligibility_manager.nim | 1 + .../recv_service/recv_service.nim | 1 + .../send_service/delivery_task.nim | 1 + .../send_service/lightpush_processor.nim | 1 + .../send_service/relay_processor.nim | 1 + .../send_service/send_service.nim | 1 + .../delivery_service/subscription_manager.nim | 1 + .../health_monitor/node_health_monitor.nim | 1 + waku/node/kernel_api/filter.nim | 1 + waku/node/kernel_api/lightpush.nim | 3 +- waku/node/kernel_api/peer_exchange.nim | 1 + waku/node/kernel_api/ping.nim | 1 + waku/node/kernel_api/relay.nim | 1 + waku/node/kernel_api/store.nim | 1 + waku/node/peer_manager/peer_manager.nim | 2 + .../peer_store/waku_peer_storage.nim | 1 + waku/node/peer_manager/waku_peer_store.nim | 4 +- waku/node/waku_metrics.nim | 1 + waku/node/waku_node.nim | 9 +- waku/node/waku_switch.nim | 13 +- waku/persistency/persistency.nim | 1 + waku/rest_api/endpoint/admin/handlers.nim | 1 + waku/rest_api/endpoint/builder.nim | 1 + waku/rest_api/endpoint/debug/handlers.nim | 1 + waku/rest_api/endpoint/filter/handlers.nim | 1 + waku/rest_api/endpoint/health/handlers.nim | 1 + waku/rest_api/endpoint/health/types.nim | 1 + .../endpoint/legacy_lightpush/handlers.nim | 1 + waku/rest_api/endpoint/lightpush/handlers.nim | 1 + waku/rest_api/endpoint/origin_handler.nim | 1 + waku/rest_api/endpoint/relay/handlers.nim | 1 + waku/rest_api/endpoint/rest_serdes.nim | 1 + waku/rest_api/endpoint/store/handlers.nim | 1 + waku/rest_api/endpoint/store/types.nim | 1 + waku/rest_api/handlers.nim | 1 + waku/utils/noise.nim | 1 + waku/utils/requests.nim | 6 +- waku/waku_archive/archive.nim | 1 + waku/waku_archive/driver/builder.nim | 1 + .../driver/postgres_driver/migrations.nim | 1 + .../postgres_driver/postgres_driver.nim | 1 + .../driver/queue_driver/queue_driver.nim | 1 + .../driver/sqlite_driver/sqlite_driver.nim | 1 + .../waku_archive/retention_policy/builder.nim | 1 + .../retention_policy_capacity.nim | 1 + waku/waku_core/peers.nim | 1 + waku/waku_core/topics/content_topic.nim | 1 + waku/waku_core/topics/sharding.nim | 1 + waku/waku_enr/capabilities.nim | 3 +- waku/waku_enr/multiaddr.nim | 1 + waku/waku_enr/sharding.nim | 1 + waku/waku_filter_v2/client.nim | 10 +- waku/waku_filter_v2/protocol.nim | 1 + waku/waku_filter_v2/subscriptions.nim | 1 + waku/waku_keystore/keystore.nim | 1 + waku/waku_lightpush/callbacks.nim | 1 + waku/waku_lightpush/client.nim | 6 +- waku/waku_lightpush/protocol.nim | 6 +- waku/waku_lightpush_legacy/client.nim | 6 +- waku/waku_lightpush_legacy/protocol.nim | 5 +- waku/waku_metadata/protocol.nim | 1 + waku/waku_mix/protocol.nim | 16 +- waku/waku_noise/noise.nim | 6 +- .../waku_noise/noise_handshake_processing.nim | 5 +- waku/waku_noise/noise_utils.nim | 21 ++- waku/waku_peer_exchange/client.nim | 1 + waku/waku_peer_exchange/protocol.nim | 1 + waku/waku_relay/protocol.nim | 2 + waku/waku_rendezvous/client.nim | 14 +- waku/waku_rendezvous/common.nim | 1 + waku/waku_rendezvous/protocol.nim | 16 +- .../group_manager/on_chain/group_manager.nim | 1 + waku/waku_rln_relay/rln/rln_interface.nim | 1 + waku/waku_rln_relay/rln/wrappers.nim | 1 + waku/waku_rln_relay/rln_relay.nim | 1 + waku/waku_store/client.nim | 6 +- waku/waku_store/protocol.nim | 5 +- waku/waku_store/resume.nim | 1 + waku/waku_store/self_req_handler.nim | 1 + waku/waku_store_sync/reconciliation.nim | 1 + waku/waku_store_sync/transfer.nim | 1 + 160 files changed, 583 insertions(+), 324 deletions(-) create mode 100644 waku/compat/option_valueor.nim diff --git a/apps/chat2/chat2.nim b/apps/chat2/chat2.nim index 282e17bfd5..60ef3beaf4 100644 --- a/apps/chat2/chat2.nim +++ b/apps/chat2/chat2.nim @@ -302,7 +302,7 @@ proc readInput(wfd: AsyncFD) {.thread, raises: [Defect, CatchableError].} = {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError -proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = +proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} = let transp = fromPipe(rfd) conf = Chat2Conf.load() @@ -310,7 +310,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = if conf.nodekey.isSome(): conf.nodekey.get() else: - PrivateKey.random(Secp256k1, rng[]).tryGet() + PrivateKey.random(Secp256k1, rng).tryGet() # set log level if conf.logLevel != LogLevel.NONE: @@ -565,7 +565,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = runForever() -proc main(rng: ref HmacDrbgContext) {.async.} = +proc main(rng: crypto.Rng) {.async.} = let (rfd, wfd) = createAsyncPipe() if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe: raise newException(ValueError, "Could not initialize pipe!") diff --git a/apps/chat2bridge/chat2bridge.nim b/apps/chat2bridge/chat2bridge.nim index eeeea328b9..084004b026 100644 --- a/apps/chat2bridge/chat2bridge.nim +++ b/apps/chat2bridge/chat2bridge.nim @@ -271,7 +271,7 @@ when isMainModule: if conf.nodekey.isSome(): conf.nodekey.get() else: - crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + crypto.PrivateKey.random(Secp256k1, rng).tryGet() let bridge = Chat2Matterbridge.new( mbHostUri = "http://" & $initTAddress(conf.mbHostAddress, Port(conf.mbHostPort)), diff --git a/apps/chat2mix/chat2mix.nim b/apps/chat2mix/chat2mix.nim index 8b786d7b6d..8a4baf11fd 100644 --- a/apps/chat2mix/chat2mix.nim +++ b/apps/chat2mix/chat2mix.nim @@ -388,7 +388,7 @@ proc maintainSubscription( {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError -proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = +proc processInput(rfd: AsyncFD, rng: crypto.Rng) {.async.} = let transp = fromPipe(rfd) conf = Chat2Conf.load() @@ -396,7 +396,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = if conf.nodekey.isSome(): conf.nodekey.get() else: - PrivateKey.random(Secp256k1, rng[]).tryGet() + PrivateKey.random(Secp256k1, rng).tryGet() # set log level if conf.logLevel != LogLevel.NONE: @@ -660,7 +660,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = runForever() -proc main(rng: ref HmacDrbgContext) {.async.} = +proc main(rng: crypto.Rng) {.async.} = let (rfd, wfd) = createAsyncPipe() if rfd == asyncInvalidPipe or wfd == asyncInvalidPipe: raise newException(ValueError, "Could not initialize pipe!") diff --git a/apps/networkmonitor/networkmonitor.nim b/apps/networkmonitor/networkmonitor.nim index 23607b1184..5b37e80f45 100644 --- a/apps/networkmonitor/networkmonitor.nim +++ b/apps/networkmonitor/networkmonitor.nim @@ -423,7 +423,7 @@ proc initAndStartApp( let # some hardcoded parameters rng = keys.newRng() - key = crypto.PrivateKey.random(Secp256k1, rng[])[] + key = crypto.PrivateKey.random(Secp256k1, rng)[] nodeTcpPort = Port(60000) nodeUdpPort = Port(9000) flags = CapabilitiesBitfield.init( diff --git a/apps/wakucanary/wakucanary.nim b/apps/wakucanary/wakucanary.nim index e7b1ff9aa5..a3f0bd91cb 100644 --- a/apps/wakucanary/wakucanary.nim +++ b/apps/wakucanary/wakucanary.nim @@ -159,7 +159,7 @@ proc pingNode( error "Failed to ping the peer", peer = peerInfo, err = msg return false -proc main(rng: ref HmacDrbgContext): Future[int] {.async.} = +proc main(rng: Rng): Future[int] {.async.} = let conf: WakuCanaryConf = WakuCanaryConf.load() # create dns resolver @@ -190,7 +190,7 @@ proc main(rng: ref HmacDrbgContext): Future[int] {.async.} = quit(QuitFailure) let - nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[] + nodeKey = crypto.PrivateKey.random(Secp256k1, rng)[] bindIp = parseIpAddress("0.0.0.0") wsBindPort = Port(conf.nodePort + WebSocketPortOffset) nodeTcpPort = Port(conf.nodePort) diff --git a/channels/reliable_channel.nim b/channels/reliable_channel.nim index e32b57e363..4a5ad7a801 100644 --- a/channels/reliable_channel.nim +++ b/channels/reliable_channel.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Reliable Channel type. ## ## A `ReliableChannel` orchestrates segmentation, SDS (end-to-end @@ -93,7 +94,7 @@ type channelId: ChannelId contentTopic: ContentTopic senderId: SdsParticipantID - rng: ref HmacDrbgContext + rng: libp2p_crypto.Rng segmentation: SegmentationHandler sdsHandler: SdsHandler rateLimit: RateLimitManager diff --git a/examples/lightpush_mix/lightpush_publisher_mix.nim b/examples/lightpush_mix/lightpush_publisher_mix.nim index 104de8552f..893b153687 100644 --- a/examples/lightpush_mix/lightpush_publisher_mix.nim +++ b/examples/lightpush_mix/lightpush_publisher_mix.nim @@ -7,8 +7,8 @@ import confutils, libp2p/crypto/crypto, libp2p/crypto/curve25519, - libp2p/protocols/mix, - libp2p/protocols/mix/curve25519, + libp2p_mix, + libp2p_mix/curve25519, libp2p/multiaddress, eth/keys, eth/p2p/discoveryv5/enr, diff --git a/library/kernel_api/discovery_api.nim b/library/kernel_api/discovery_api.nim index f61b7bad10..589cad1812 100644 --- a/library/kernel_api/discovery_api.nim +++ b/library/kernel_api/discovery_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/json import chronos, chronicles, results, strutils, libp2p/multiaddress, ffi import diff --git a/library/kernel_api/node_lifecycle_api.nim b/library/kernel_api/node_lifecycle_api.nim index 8f3e99b244..6c3f88f5a6 100644 --- a/library/kernel_api/node_lifecycle_api.nim +++ b/library/kernel_api/node_lifecycle_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, json, strutils, net] import chronos, chronicles, results, confutils, confutils/std/net, ffi diff --git a/library/kernel_api/peer_manager_api.nim b/library/kernel_api/peer_manager_api.nim index f0ae37f003..84d806ebc1 100644 --- a/library/kernel_api/peer_manager_api.nim +++ b/library/kernel_api/peer_manager_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[sequtils, strutils, tables] import chronicles, chronos, results, options, json, ffi import waku/factory/waku, waku/node/waku_node, waku/node/peer_manager, ../declare_lib diff --git a/library/kernel_api/protocols/filter_api.nim b/library/kernel_api/protocols/filter_api.nim index c4f99510aa..177d52b682 100644 --- a/library/kernel_api/protocols/filter_api.nim +++ b/library/kernel_api/protocols/filter_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import options, std/[strutils, sequtils] import chronicles, chronos, results, ffi import diff --git a/library/kernel_api/protocols/lightpush_api.nim b/library/kernel_api/protocols/lightpush_api.nim index e9251a3f34..4c87292b61 100644 --- a/library/kernel_api/protocols/lightpush_api.nim +++ b/library/kernel_api/protocols/lightpush_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import options, std/[json, strformat] import chronicles, chronos, results, ffi import diff --git a/library/kernel_api/protocols/relay_api.nim b/library/kernel_api/protocols/relay_api.nim index b184d6011c..a834188865 100644 --- a/library/kernel_api/protocols/relay_api.nim +++ b/library/kernel_api/protocols/relay_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[net, sequtils, strutils, json], strformat import chronicles, chronos, stew/byteutils, results, ffi import diff --git a/library/kernel_api/protocols/store_api.nim b/library/kernel_api/protocols/store_api.nim index 0df4d9b1f8..e9da7da67e 100644 --- a/library/kernel_api/protocols/store_api.nim +++ b/library/kernel_api/protocols/store_api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[json, sugar, strutils, options] import chronos, chronicles, results, stew/byteutils, ffi import diff --git a/library/libwaku.nim b/library/libwaku.nim index dd1ee9fd9f..2576d1713a 100644 --- a/library/libwaku.nim +++ b/library/libwaku.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[atomics, options, atomics, macros] import chronicles, chronos, chronos/threadsync, ffi import diff --git a/nimble.lock b/nimble.lock index cd533001e1..d246ebe840 100644 --- a/nimble.lock +++ b/nimble.lock @@ -50,8 +50,8 @@ } }, "jwt": { - "version": "#18f8378de52b241f321c1f9ea905456e89b95c6f", - "vcsRevision": "18f8378de52b241f321c1f9ea905456e89b95c6f", + "version": "#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2", + "vcsRevision": "057ec95eb5af0eea9c49bfe9025b3312c95dc5f2", "url": "https://github.com/vacp2p/nim-jwt.git", "downloadMethod": "git", "dependencies": [ @@ -60,7 +60,7 @@ "bearssl_pkey_decoder" ], "checksums": { - "sha1": "bcfd6fc9c5e10a52b87117219b7ab5c98136bc8e" + "sha1": "3cd368666fd2bc7f99f253452289e827abcac13c" } }, "testutils": { @@ -434,8 +434,8 @@ } }, "websock": { - "version": "0.3.0", - "vcsRevision": "c105d98e6522e0e2cbe3dfa11b07a273e9fd0e7b", + "version": "0.4.0", + "vcsRevision": "387a8eb7e961e8fdd3b1a717d36bc53b55e4dc5d", "url": "https://github.com/status-im/nim-websock", "downloadMethod": "git", "dependencies": [ @@ -450,7 +450,7 @@ "zlib" ], "checksums": { - "sha1": "1294a66520fa4541e261dec8a6a84f774fb8c0ac" + "sha1": "fd17a854686d9a19af40aba51f05d06b82fc30ec" } }, "json_rpc": { @@ -476,8 +476,8 @@ } }, "lsquic": { - "version": "0.0.1", - "vcsRevision": "4fb03ee7bfb39aecb3316889fdcb60bec3d0936f", + "version": "0.4.1", + "vcsRevision": "00e4b7dfaa197cd120267aa897b33b0914166b45", "url": "https://github.com/vacp2p/nim-lsquic", "downloadMethod": "git", "dependencies": [ @@ -487,10 +487,11 @@ "chronos", "nimcrypto", "unittest2", - "chronicles" + "chronicles", + "boringssl" ], "checksums": { - "sha1": "f465fa994346490d0924d162f53d9b5aec62f948" + "sha1": "5e36783661eab239bd4d8566ff3195c8d14f1923" } }, "secp256k1": { @@ -582,8 +583,8 @@ } }, "libp2p": { - "version": "#ff8d51857b4b79a68468e7bcc27b2026cca02996", - "vcsRevision": "ff8d51857b4b79a68468e7bcc27b2026cca02996", + "version": "#c43199378f46d0aaf61be1cad1ee1d63e8f665d6", + "vcsRevision": "c43199378f46d0aaf61be1cad1ee1d63e8f665d6", "url": "https://github.com/vacp2p/nim-libp2p.git", "downloadMethod": "git", "dependencies": [ @@ -591,20 +592,22 @@ "nimcrypto", "dnsclient", "bearssl", + "boringssl", "chronicles", "chronos", "metrics", "secp256k1", "stew", - "websock", "unittest2", "results", "serialization", "lsquic", + "protobuf_serialization", + "websock", "jwt" ], "checksums": { - "sha1": "fa2a7552c6ec860717b77ce34cf0b7afe4570234" + "sha1": "327dc7a0cb7e9d0be3d6083841bd496c4cbc48dc" } }, "taskpools": { @@ -653,6 +656,67 @@ "checksums": { "sha1": "6f9d49375ea1dc71add55c72ac80a808f238e5b0" } + }, + "boringssl": { + "version": "0.0.4", + "vcsRevision": "1c91a4a2579123597df43bbdea70cc575957bdea", + "url": "https://github.com/vacp2p/nim-boringssl", + "downloadMethod": "git", + "dependencies": [ + "nim" + ], + "checksums": { + "sha1": "3655faa30099538293cb7d60e726783dff9d979a" + } + }, + "protobuf_serialization": { + "version": "0.4.0", + "vcsRevision": "38d24eb3bd93e605fb88199da71d36b1ec0ad60d", + "url": "https://github.com/status-im/nim-protobuf-serialization", + "downloadMethod": "git", + "dependencies": [ + "nim", + "stew", + "faststreams", + "serialization", + "npeg", + "unittest2" + ], + "checksums": { + "sha1": "5a7a80fb8cca29e41899ce9540b74e49c874f8fd" + } + }, + "npeg": { + "version": "1.3.0", + "vcsRevision": "409f6796d0e880b3f0222c964d1da7de6e450811", + "url": "https://github.com/zevv/npeg", + "downloadMethod": "git", + "dependencies": [ + "nim" + ], + "checksums": { + "sha1": "64f15c85a059c889cb11c5fe72372677c50da621" + } + }, + "libp2p_mix": { + "version": "0.1.0", + "vcsRevision": "7cb7556d9a228573fc5622af7ffb2dd11741e043", + "url": "https://github.com/logos-co/nim-libp2p-mix", + "downloadMethod": "git", + "dependencies": [ + "nim", + "libp2p", + "chronicles", + "chronos", + "metrics", + "nimcrypto", + "stew", + "results", + "unittest2" + ], + "checksums": { + "sha1": "8287dda862a4398966cd66a5b3d7d66834c9a9a6" + } } }, "tasks": {} diff --git a/tests/common/test_ratelimit_setting.nim b/tests/common/test_ratelimit_setting.nim index 2bc95fbfb7..c9385ea574 100644 --- a/tests/common/test_ratelimit_setting.nim +++ b/tests/common/test_ratelimit_setting.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/crypto # Chronos Test Suite # (c) Copyright 2022-Present # Status Research & Development GmbH @@ -17,9 +18,9 @@ import ../../waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" -let conn1 = Connection(peerId: PeerId.random().tryGet()) -let conn2 = Connection(peerId: PeerId.random().tryGet()) -let conn3 = Connection(peerId: PeerId.random().tryGet()) +let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet()) suite "RateLimitSetting": test "Parse rate limit setting - ok": diff --git a/tests/common/test_requestratelimiter.nim b/tests/common/test_requestratelimiter.nim index be910b38e1..e3801f8534 100644 --- a/tests/common/test_requestratelimiter.nim +++ b/tests/common/test_requestratelimiter.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/crypto # Chronos Test Suite # (c) Copyright 2022-Present # Status Research & Development GmbH @@ -17,9 +18,9 @@ import ../../waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" -let conn1 = Connection(peerId: PeerId.random().tryGet()) -let conn2 = Connection(peerId: PeerId.random().tryGet()) -let conn3 = Connection(peerId: PeerId.random().tryGet()) +let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet()) suite "RequestRateLimiter": test "RequestRateLimiter Allow up to main bucket": diff --git a/tests/node/test_wakunode_filter.nim b/tests/node/test_wakunode_filter.nim index 2777b01241..c94c8fe94e 100644 --- a/tests/node/test_wakunode_filter.nim +++ b/tests/node/test_wakunode_filter.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/crypto {.used.} import @@ -21,9 +22,9 @@ import ../testlib/[common, wakucore, wakunode, testasync, futures, testutils], ../waku_filter_v2/waku_filter_utils -proc generateRequestId(rng: ref HmacDrbgContext): string = +proc generateRequestId(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return toHex(bytes) proc createRequest( @@ -31,7 +32,7 @@ proc createRequest( pubsubTopic = none(PubsubTopic), contentTopics = newSeq[ContentTopic](), ): FilterSubscribeRequest = - let requestId = generateRequestId(rng) + let requestId = generateRequestId(common.rng()) return FilterSubscribeRequest( requestId: requestId, diff --git a/tests/node/test_wakunode_relay_rln.nim b/tests/node/test_wakunode_relay_rln.nim index 3a2a8a67c9..9e1520aab5 100644 --- a/tests/node/test_wakunode_relay_rln.nim +++ b/tests/node/test_wakunode_relay_rln.nim @@ -35,10 +35,10 @@ from ../../waku/waku_noise/noise_utils import randomSeqByte proc buildRandomIdentityCredentials(): IdentityCredential = # We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) IdentityCredential( idTrapdoor: idTrapdoor, diff --git a/tests/test_helpers.nim b/tests/test_helpers.nim index bd1d837b6a..a4bb69fbc2 100644 --- a/tests/test_helpers.nim +++ b/tests/test_helpers.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/rng import chronos, bearssl/rand, eth/[keys, p2p] import libp2p/crypto/crypto @@ -9,10 +10,10 @@ proc localAddress*(port: int): Address = result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1")) proc setupTestNode*( - rng: ref HmacDrbgContext, capabilities: varargs[ProtocolInfo, `protocolInfo`] + rng: crypto.Rng, capabilities: varargs[ProtocolInfo, `protocolInfo`] ): EthereumNode = let - keys1 = keys.KeyPair.random(rng[]) + keys1 = keys.KeyPair.random(keys.newRng()[]) address = localAddress(nextPort) result = newEthereumNode( keys1, @@ -29,11 +30,11 @@ proc setupTestNode*( # Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28 type RngWrap = object - rng: ref rand.HmacDrbgContext + rng: crypto.Rng var rngVar: RngWrap -proc getRng(): ref rand.HmacDrbgContext = +proc getRng(): crypto.Rng = # TODO if `rngVar` is a threadvar like it should be, there are random and # spurious compile failures on mac - this is not gcsafe but for the # purpose of the tests, it's ok as long as we only use a single thread @@ -42,5 +43,5 @@ proc getRng(): ref rand.HmacDrbgContext = rngVar.rng = crypto.newRng() rngVar.rng -template rng*(): ref rand.HmacDrbgContext = +template rng*(): crypto.Rng = getRng() diff --git a/tests/test_peer_manager.nim b/tests/test_peer_manager.nim index 608889d324..e60ab3c8d5 100644 --- a/tests/test_peer_manager.nim +++ b/tests/test_peer_manager.nim @@ -1,7 +1,7 @@ {.used.} import - std/[sequtils, times, sugar, net], + std/[sequtils, times, sugar, net, options], testutils/unittests, chronos, json_rpc/rpcserver, @@ -955,7 +955,7 @@ procSuite "Peer Manager": # Create peer manager let pm = PeerManager.new( - switch = SwitchBuilder.new().withRng(rng).withMplex().withNoise().build(), + switch = SwitchBuilder.new().withRng(crypto.newRng()).withMplex().withNoise().build(), storage = nil, ) @@ -1013,7 +1013,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(peerStoreSize) @@ -1027,7 +1027,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(25) @@ -1040,7 +1040,7 @@ procSuite "Peer Manager": # Create 30 peers and add them to the peerstore let peers = toSeq(1 .. 30) - .mapIt(parsePeerInfo("/ip4/0.0.0.0/tcp/0/p2p/" & $PeerId.random().get())) + .mapIt(parsePeerInfo("/ip4/0.0.0.0/tcp/0/p2p/" & $PeerId.random(crypto.newRng()).get())) .filterIt(it.isOk()) .mapIt(it.value) for p in peers: @@ -1091,7 +1091,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(25) @@ -1148,7 +1148,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(25) @@ -1164,7 +1164,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(25) @@ -1178,7 +1178,7 @@ procSuite "Peer Manager": let pm = PeerManager.new( switch = SwitchBuilder .new() - .withRng(rng) + .withRng(crypto.newRng()) .withMplex() .withNoise() .withPeerStore(25) diff --git a/tests/test_waku_dnsdisc.nim b/tests/test_waku_dnsdisc.nim index 758bdb3ca7..43e00da80f 100644 --- a/tests/test_waku_dnsdisc.nim +++ b/tests/test_waku_dnsdisc.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/rng {.used.} import @@ -52,7 +53,7 @@ suite "Waku DNS Discovery": ) .get() # No link entries - let treeKeys = keys.KeyPair.random(rng[]) + let treeKeys = keys.KeyPair.random(keys.newRng()[]) # Sign tree check: diff --git a/tests/test_waku_keepalive.nim b/tests/test_waku_keepalive.nim index 5d8402268d..7b7586db1e 100644 --- a/tests/test_waku_keepalive.nim +++ b/tests/test_waku_keepalive.nim @@ -38,7 +38,7 @@ suite "Waku Keepalive": (await node2.mountRelay()).isOkOr: assert false, "Failed to mount relay" - let pingProto = Ping.new(handler = pingHandler) + let pingProto = Ping.new(handler = pingHandler, rng = crypto.newRng()) await pingProto.start() node2.switch.mount(pingProto) diff --git a/tests/test_waku_keystore.nim b/tests/test_waku_keystore.nim index 8fd8ad2974..83536b062d 100644 --- a/tests/test_waku_keystore.nim +++ b/tests/test_waku_keystore.nim @@ -46,10 +46,10 @@ procSuite "Credentials test suite": # We generate a random identity credential (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) var - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) var idCredential = IdentityCredential( idTrapdoor: idTrapdoor, @@ -85,10 +85,10 @@ procSuite "Credentials test suite": # We generate two random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) var - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -141,10 +141,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -193,10 +193,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, @@ -254,10 +254,10 @@ procSuite "Credentials test suite": # We generate random identity credentials (inter-value constrains are not enforced, otherwise we need to load e.g. zerokit RLN keygen) let - idTrapdoor = randomSeqByte(rng[], 32) - idNullifier = randomSeqByte(rng[], 32) - idSecretHash = randomSeqByte(rng[], 32) - idCommitment = randomSeqByte(rng[], 32) + idTrapdoor = randomSeqByte(rng, 32) + idNullifier = randomSeqByte(rng, 32) + idSecretHash = randomSeqByte(rng, 32) + idCommitment = randomSeqByte(rng, 32) idCredential = IdentityCredential( idTrapdoor: idTrapdoor, idNullifier: idNullifier, diff --git a/tests/test_waku_keystore_keyfile.nim b/tests/test_waku_keystore_keyfile.nim index afdb7e44b9..cd187baf6d 100644 --- a/tests/test_waku_keystore_keyfile.nim +++ b/tests/test_waku_keystore_keyfile.nim @@ -16,7 +16,7 @@ suite "KeyFile test suite": removeFile(filepath) # The secret - var secret = randomSeqByte(rng[], 300) + var secret = randomSeqByte(rng, 300) # We create a keyfile encrypting the secret with password let keyfile = createKeyFileJson(secret, password) @@ -42,9 +42,9 @@ suite "KeyFile test suite": test "Create/Save/Load multiple keyfiles in same file": # We set different passwords for different keyfiles that will be stored in same file - let password1 = string.fromBytes(randomSeqByte(rng[], 20)) + let password1 = string.fromBytes(randomSeqByte(rng, 20)) let password2 = "" - let password3 = string.fromBytes(randomSeqByte(rng[], 20)) + let password3 = string.fromBytes(randomSeqByte(rng, 20)) var keyfile: KfResult[JsonNode] let filepath = "./test.keyfile" @@ -53,40 +53,40 @@ suite "KeyFile test suite": # We generate 6 different secrets and we encrypt them using 3 different passwords, and we store the obtained keystore - let secret1 = randomSeqByte(rng[], 300) + let secret1 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret1, password1) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() - let secret2 = randomSeqByte(rng[], 300) + let secret2 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret2, password2) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() - let secret3 = randomSeqByte(rng[], 300) + let secret3 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret3, password3) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret4 with password3 - let secret4 = randomSeqByte(rng[], 300) + let secret4 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret4, password3) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret5 with password1 - let secret5 = randomSeqByte(rng[], 300) + let secret5 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret5, password1) check: keyfile.isOk() saveKeyFile(filepath, keyfile.get()).isOk() # We encrypt secret6 with password1 - let secret6 = randomSeqByte(rng[], 300) + let secret6 = randomSeqByte(rng, 300) keyfile = createKeyFileJson(secret6, password1) check: keyfile.isOk() @@ -343,7 +343,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)": test "Scrypt keyfiles": let - expectedSecret = randomSeqByte(rng[], 300) + expectedSecret = randomSeqByte(rng, 300) password = "miawmiawcat" # By default, keyfiles' encryption key is derived from password using PBKDF2. diff --git a/tests/test_waku_netconfig.nim b/tests/test_waku_netconfig.nim index 0aff641216..d637f8b2b7 100644 --- a/tests/test_waku_netconfig.nim +++ b/tests/test_waku_netconfig.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import chronos, confutils/toml/std/net, libp2p/multiaddress, testutils/unittests diff --git a/tests/test_waku_noise.nim b/tests/test_waku_noise.nim index 6566f9eed0..6dbb3a2f91 100644 --- a/tests/test_waku_noise.nim +++ b/tests/test_waku_noise.nim @@ -27,7 +27,7 @@ procSuite "Waku Noise": let maxMessageLength = 3 * NoisePaddingBlockSize for messageLen in 0 .. maxMessageLength: let - message = randomSeqByte(rng[], messageLen) + message = randomSeqByte(rng, messageLen) padded = pkcs7_pad(message, NoisePaddingBlockSize) unpadded = pkcs7_unpad(padded, NoisePaddingBlockSize) @@ -37,11 +37,11 @@ procSuite "Waku Noise": message == unpadded test "ChaChaPoly Encryption/Decryption: random byte sequences": - let cipherState = randomChaChaPolyCipherState(rng[]) + let cipherState = randomChaChaPolyCipherState(rng) # We encrypt/decrypt random byte sequences let - plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) + plaintext: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext) decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext) @@ -49,7 +49,7 @@ procSuite "Waku Noise": plaintext == decryptedCiphertext test "ChaChaPoly Encryption/Decryption: random strings": - let cipherState = randomChaChaPolyCipherState(rng[]) + let cipherState = randomChaChaPolyCipherState(rng) # We encrypt/decrypt random strings var plaintext: string @@ -64,10 +64,10 @@ procSuite "Waku Noise": plaintext.toBytes() == decryptedCiphertext test "Noise public keys: encrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) @@ -75,20 +75,20 @@ procSuite "Waku Noise": noisePublicKey == decryptedPk test "Noise public keys: decrypt an unencrypted public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, noisePublicKey) check: noisePublicKey == decryptedPk test "Noise public keys: encrypt an encrypted public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) encryptedPk2: NoisePublicKey = encryptNoisePublicKey(cs, encryptedPk) @@ -96,10 +96,10 @@ procSuite "Waku Noise": encryptedPk == encryptedPk2 test "Noise public keys: encrypt, decrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) decryptedPk2: NoisePublicKey = decryptNoisePublicKey(cs, decryptedPk) @@ -109,7 +109,7 @@ procSuite "Waku Noise": test "Noise public keys: serialize and deserialize an unencrypted public key": let - noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(noisePublicKey) deserializedNoisePublicKey: NoisePublicKey = intoNoisePublicKey(serializedNoisePublicKey) @@ -118,10 +118,10 @@ procSuite "Waku Noise": noisePublicKey == deserializedNoisePublicKey test "Noise public keys: encrypt, serialize, deserialize and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) + let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng) let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) + cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng) encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(encryptedPk) deserializedNoisePublicKey: NoisePublicKey = @@ -134,7 +134,7 @@ procSuite "Waku Noise": test "PayloadV2: serialize/deserialize PayloadV2 to byte sequence": let - payload2: PayloadV2 = randomPayloadV2(rng[]) + payload2: PayloadV2 = randomPayloadV2(rng) serializedPayload = serializePayloadV2(payload2) check: @@ -149,7 +149,7 @@ procSuite "Waku Noise": test "PayloadV2: Encode/Decode a Waku Message (version 2) to a PayloadV2": # We encode to a WakuMessage a random PayloadV2 let - payload2 = randomPayloadV2(rng[]) + payload2 = randomPayloadV2(rng) msg = encodePayloadV2(payload2) check: @@ -173,8 +173,8 @@ procSuite "Waku Noise": test "Noise State Machine: Diffie-Hellman operation": #We generate random keypairs let - aliceKey = genKeyPair(rng[]) - bobKey = genKeyPair(rng[]) + aliceKey = genKeyPair(rng) + bobKey = genKeyPair(rng) # A Diffie-Hellman operation between Alice's private key and Bob's public key must be equal to # a Diffie-hellman operation between Alice's public key and Bob's private key @@ -188,10 +188,10 @@ procSuite "Waku Noise": test "Noise State Machine: Cipher State primitives": # We generate a random Cipher State, associated data ad and plaintext var - cipherState: CipherState = randomCipherState(rng[]) + cipherState: CipherState = randomCipherState(rng) nonce: uint64 = uint64(rand(0 .. int.high)) - ad: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) - plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) + ad: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) + plaintext: seq[byte] = randomSeqByte(rng, rand(1 .. 128)) # We set the random nonce generated in the cipher state setNonce(cipherState, nonce) @@ -218,7 +218,7 @@ procSuite "Waku Noise": setCipherStateKey(cipherState, EmptyKey) nonce = getNonce(cipherState) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) ciphertext = encryptWithAd(cipherState, ad, plaintext) check: @@ -230,7 +230,7 @@ procSuite "Waku Noise": nonce = getNonce(cipherState) # Note that we set ciphertext minimum length to 16 to not trigger checks on authentication tag length - ciphertext = randomSeqByte(rng[], rand(16 .. 128)) + ciphertext = randomSeqByte(rng, rand(16 .. 128)) plaintext = decryptWithAd(cipherState, ad, ciphertext) check: @@ -241,9 +241,9 @@ procSuite "Waku Noise": # Note that NonceMax is uint64.high - 1 = 2^64-1-1 and that nonce is increased after each encryption and decryption operation # We generate a test Cipher State with nonce set to MaxNonce - cipherState = randomCipherState(rng[]) + cipherState = randomCipherState(rng) setNonce(cipherState, NonceMax) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) # We test if encryption fails with a NoiseNonceMaxError error. Any subsequent encryption call over the Cipher State should fail similarly and leave the nonce unchanged for _ in [1 .. 5]: @@ -257,9 +257,9 @@ procSuite "Waku Noise": # Since nonce is increased after decryption as well, we need to generate a proper ciphertext in order to test MaxNonceError error handling # We cannot call encryptWithAd to encrypt a plaintext using a nonce equal MaxNonce, since this will trigger a MaxNonceError. # To perform such test, we then need to encrypt a test plaintext using directly ChaChaPoly primitive - cipherState = randomCipherState(rng[]) + cipherState = randomCipherState(rng) setNonce(cipherState, NonceMax) - plaintext = randomSeqByte(rng[], rand(1 .. 128)) + plaintext = randomSeqByte(rng, rand(1 .. 128)) # We perform encryption using the Cipher State key, NonceMax and ad # By Noise specification the nonce is 8 bytes long out of the 12 bytes supported by ChaChaPoly, thus we copy the Little endian conversion of the nonce to a ChaChaPolyNonce @@ -308,7 +308,7 @@ procSuite "Waku Noise": ######################################## # We generate a random byte sequence and execute a mixHash over it - mixHash(symmetricState, randomSeqByte(rng[], rand(1 .. 128))) + mixHash(symmetricState, randomSeqByte(rng, rand(1 .. 128))) # mixHash changes only the handshake hash value of the Symmetric state check: @@ -324,7 +324,7 @@ procSuite "Waku Noise": ######################################## # We generate random input key material and we execute mixKey - var inputKeyMaterial = randomSeqByte(rng[], rand(1 .. 128)) + var inputKeyMaterial = randomSeqByte(rng, rand(1 .. 128)) mixKey(symmetricState, inputKeyMaterial) # mixKey changes the Symmetric State's chaining key and encryption key of the embedded Cipher State @@ -345,7 +345,7 @@ procSuite "Waku Noise": ######################################## # We generate random input key material and we execute mixKeyAndHash - inputKeyMaterial = randomSeqByte(rng[], rand(1 .. 128)) + inputKeyMaterial = randomSeqByte(rng, rand(1 .. 128)) mixKeyAndHash(symmetricState, inputKeyMaterial) # mixKeyAndHash executes a mixKey and a mixHash using the input key material @@ -368,7 +368,7 @@ procSuite "Waku Noise": var initialSymmetricState = symmetricState # We generate random plaintext and we execute encryptAndHash - var plaintext = randomChaChaPolyKey(rng[]) + var plaintext = randomChaChaPolyKey(rng) var nonce = getNonce(getCipherState(symmetricState)) var ciphertext = encryptAndHash(symmetricState, plaintext) @@ -421,11 +421,11 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XX"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) var aliceHS = initialize(hsPattern = hsPattern, staticKey = aliceStaticKey, initiator = true) - let bobStaticKey = genKeyPair(rng[]) + let bobStaticKey = genKeyPair(rng) var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey) var @@ -440,15 +440,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -458,13 +458,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -474,14 +474,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -494,13 +494,13 @@ procSuite "Waku Noise": let prevBobHS = bobHS let bobStep1 = - stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() let aliceStep1 = - stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep1.payload2).get() + stepHandshake(rng, aliceHS, readPayloadV2 = bobStep1.payload2).get() let aliceStep2 = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() let bobStep2 = - stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep2.payload2).get() + stepHandshake(rng, bobHS, readPayloadV2 = aliceStep2.payload2).get() check: aliceStep1 == default(HandshakeStepResult) @@ -529,7 +529,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -538,7 +538,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -550,15 +550,15 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XXpsk0"] # We generate a random psk - let psk = randomSeqByte(rng[], 32) + let psk = randomSeqByte(rng, 32) # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) var aliceHS = initialize( hsPattern = hsPattern, staticKey = aliceStaticKey, psk = psk, initiator = true ) - let bobStaticKey = genKeyPair(rng[]) + let bobStaticKey = genKeyPair(rng) var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey, psk = psk) var @@ -573,15 +573,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -591,13 +591,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -607,14 +607,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -640,7 +640,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -649,7 +649,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -661,8 +661,8 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["K1K1"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) + let bobStaticKey = genKeyPair(rng) # This handshake has the following pre-message pattern: # -> s @@ -696,15 +696,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -714,13 +714,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -730,14 +730,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake_message and the (encrypted) transportMessage aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -763,7 +763,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -772,7 +772,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() @@ -784,8 +784,8 @@ procSuite "Waku Noise": let hsPattern = NoiseHandshakePatterns["XK1"] # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) + let aliceStaticKey = genKeyPair(rng) + let bobStaticKey = genKeyPair(rng) # This handshake has the following pre-message pattern: # <- s @@ -816,15 +816,15 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message # and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -834,13 +834,13 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() + bobStep = stepHandshake(rng, bobHS, transportMessage = sentTransportMessage).get() # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() + aliceStep = stepHandshake(rng, aliceHS, readPayloadV2 = bobStep.payload2).get() check: aliceStep.transportMessage == sentTransportMessage @@ -850,14 +850,14 @@ procSuite "Waku Noise": ############### # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) + sentTransportMessage = randomSeqByte(rng, 32) # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() + stepHandshake(rng, aliceHS, transportMessage = sentTransportMessage).get() # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() + bobStep = stepHandshake(rng, bobHS, readPayloadV2 = aliceStep.payload2).get() check: bobStep.transportMessage == sentTransportMessage @@ -883,7 +883,7 @@ procSuite "Waku Noise": for _ in 0 .. 10: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() @@ -892,7 +892,7 @@ procSuite "Waku Noise": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) readMessage = readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() diff --git a/tests/test_waku_noise_sessions.nim b/tests/test_waku_noise_sessions.nim index 543653982e..61eaa00386 100644 --- a/tests/test_waku_noise_sessions.nim +++ b/tests/test_waku_noise_sessions.nim @@ -25,22 +25,22 @@ procSuite "Waku Noise Sessions": let hsPattern = NoiseHandshakePatterns["WakuPairing"] # Alice static/ephemeral key initialization and commitment - let aliceStaticKey = genKeyPair(rng[]) - let aliceEphemeralKey = genKeyPair(rng[]) - let s = randomSeqByte(rng[], 32) + let aliceStaticKey = genKeyPair(rng) + let aliceEphemeralKey = genKeyPair(rng) + let s = randomSeqByte(rng, 32) let aliceCommittedStaticKey = commitPublicKey(getPublicKey(aliceStaticKey), s) # Bob static/ephemeral key initialization and commitment - let bobStaticKey = genKeyPair(rng[]) - let bobEphemeralKey = genKeyPair(rng[]) - let r = randomSeqByte(rng[], 32) + let bobStaticKey = genKeyPair(rng) + let bobEphemeralKey = genKeyPair(rng) + let r = randomSeqByte(rng, 32) let bobCommittedStaticKey = commitPublicKey(getPublicKey(bobStaticKey), r) # Content Topic information let applicationName = "waku-noise-sessions" let applicationVersion = "0.1" let shardId = "10" - let qrMessageNametag = randomSeqByte(rng[], MessageNametagLength) + let qrMessageNametag = randomSeqByte(rng, MessageNametagLength) # Out-of-band Communication @@ -133,7 +133,7 @@ procSuite "Waku Noise Sessions": # and the (encrypted) transport message # The message is sent with a messageNametag equal to the one received through the QR code aliceStep = stepHandshake( - rng[], + rng, aliceHS, transportMessage = sentTransportMessage, messageNametag = qrMessageNametag, @@ -168,7 +168,7 @@ procSuite "Waku Noise Sessions": # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him # Note that Bob verifies if the received payloadv2 has the expected messageNametag set bobStep = stepHandshake( - rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag + rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = qrMessageNametag ) .get() @@ -199,7 +199,7 @@ procSuite "Waku Noise Sessions": # At this step, Bob writes and returns a payload bobStep = stepHandshake( - rng[], + rng, bobHS, transportMessage = sentTransportMessage, messageNametag = bobMessageNametag, @@ -233,7 +233,7 @@ procSuite "Waku Noise Sessions": # While Alice reads and returns the (decrypted) transport message aliceStep = stepHandshake( - rng[], + rng, aliceHS, readPayloadV2 = readPayloadV2, messageNametag = aliceMessageNametag, @@ -265,7 +265,7 @@ procSuite "Waku Noise Sessions": # Similarly as in first step, Alice writes a Waku2 payload containing the handshake message and the (encrypted) transport message aliceStep = stepHandshake( - rng[], + rng, aliceHS, transportMessage = sentTransportMessage, messageNametag = aliceMessageNametag, @@ -299,7 +299,7 @@ procSuite "Waku Noise Sessions": # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him bobStep = stepHandshake( - rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag + rng, bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag ) .get() @@ -333,7 +333,7 @@ procSuite "Waku Noise Sessions": # Note that we exchange more than the number of messages contained in the nametag buffer to test if they are filled correctly as the communication proceeds for i in 0 .. 10 * MessageNametagBufferSize: # Alice writes to Bob - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, @@ -350,7 +350,7 @@ procSuite "Waku Noise Sessions": message == readMessage # Bob writes to Alice - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( bobHSResult, message, @@ -368,13 +368,13 @@ procSuite "Waku Noise Sessions": # We test how nametag buffers help in detecting lost messages # Alice writes two messages to Bob, but only the second is received - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, ) - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, @@ -390,7 +390,7 @@ procSuite "Waku Noise Sessions": # We adjust bob nametag buffer for next test (i.e. the missed message is correctly recovered) delete(bobHSResult.nametagsInbound, 2) - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( bobHSResult, message, outboundMessageNametagBuffer = bobHSResult.nametagsOutbound ) @@ -405,7 +405,7 @@ procSuite "Waku Noise Sessions": message == readMessage # We test if a missing nametag is correctly detected - message = randomSeqByte(rng[], 32) + message = randomSeqByte(rng, 32) payload2 = writeMessage( aliceHSResult, message, diff --git a/tests/test_wakunode.nim b/tests/test_wakunode.nim index a7f1084fb0..081ad02e1d 100644 --- a/tests/test_wakunode.nim +++ b/tests/test_wakunode.nim @@ -1,7 +1,7 @@ {.used.} import - std/[sequtils, strutils, net], + std/[sequtils, strutils, net, options], stew/byteutils, testutils/unittests, chronicles, diff --git a/tests/testlib/common.nim b/tests/testlib/common.nim index 2163206925..d3692e137b 100644 --- a/tests/testlib/common.nim +++ b/tests/testlib/common.nim @@ -12,13 +12,13 @@ proc randomize*() = # Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28 type Rng = object - rng: ref HmacDrbgContext + rng: crypto.Rng # Typically having a module variable is considered bad design. This case should # be considered as an exception and it should be used only in the tests. var rngVar: Rng -proc getRng(): ref HmacDrbgContext = +proc getRng(): crypto.Rng = # TODO: if `rngVar` is a threadvar like it should be, there are random and # spurious compile failures on mac - this is not gcsafe but for the # purpose of the tests, it's ok as long as we only use a single thread @@ -28,5 +28,5 @@ proc getRng(): ref HmacDrbgContext = rngVar.rng -template rng*(): ref HmacDrbgContext = +template rng*(): crypto.Rng = getRng() diff --git a/tests/testlib/wakucore.nim b/tests/testlib/wakucore.nim index 0c5b5199db..c0d59b0fc8 100644 --- a/tests/testlib/wakucore.nim +++ b/tests/testlib/wakucore.nim @@ -22,17 +22,32 @@ proc ts*(offset = 0, origin = now()): Timestamp = # Switch proc generateEcdsaKey*(): libp2p_keys.PrivateKey = - libp2p_keys.PrivateKey.random(ECDSA, rng[]).get() + libp2p_keys.PrivateKey.random(ECDSA, common.rng()).get() proc generateEcdsaKeyPair*(): libp2p_keys.KeyPair = - libp2p_keys.KeyPair.random(ECDSA, rng[]).get() + libp2p_keys.KeyPair.random(ECDSA, common.rng()).get() proc generateSecp256k1Key*(): libp2p_keys.PrivateKey = - libp2p_keys.PrivateKey.random(Secp256k1, rng[]).get() + libp2p_keys.PrivateKey.random(Secp256k1, common.rng()).get() proc ethSecp256k1Key*(hex: string): eth_keys.PrivateKey = eth_keys.PrivateKey.fromHex(hex).get() +proc newStandardSwitch*( + privKey = Opt.none(libp2p_keys.PrivateKey), + addrs: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").get(), +): Switch = + var b = SwitchBuilder + .new() + .withRng(common.rng()) + .withAddress(addrs) + .withTcpTransport() + .withMplex() + .withNoise() + if privKey.isSome(): + b = b.withPrivateKey(privKey.get()) + b.build() + proc newTestSwitch*( key = none(libp2p_keys.PrivateKey), address = none(MultiAddress) ): Switch = diff --git a/tests/testlib/wakunode.nim b/tests/testlib/wakunode.nim index 77c017d966..54f0b1ed8e 100644 --- a/tests/testlib/wakunode.nim +++ b/tests/testlib/wakunode.nim @@ -11,6 +11,7 @@ import waku/[ waku_node, waku_core/topics, + node/waku_switch, node/peer_manager, waku_enr, discovery/waku_discv5, @@ -55,7 +56,7 @@ proc newTestWakuNode*( extPort = none(Port), extMultiAddrs = newSeq[MultiAddress](), peerStorage: PeerStorage = nil, - maxConnections = builders.MaxConnections, + maxConnections = MaxConnections, wsBindPort: Port = (Port) 8000, wsEnabled: bool = false, wssEnabled: bool = false, diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 936c018265..640d60e7dc 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/rng {.used.} import @@ -38,8 +39,8 @@ suite "Waku Discovery v5": let rng = eth_keys.newRng() - pk1 = eth_keys.PrivateKey.random(rng[]) - pk2 = eth_keys.PrivateKey.random(rng[]) + pk1 = eth_keys.PrivateKey.random(eth_keys.newRng()[]) + pk2 = eth_keys.PrivateKey.random(eth_keys.newRng()[]) suite "shardingPredicate": var @@ -423,7 +424,7 @@ suite "Waku Discovery v5": let myRng = libp2p_keys.newRng() var confBuilder = defaultTestWakuConfBuilder() - confBuilder.withNodeKey(libp2p_keys.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(libp2p_keys.PrivateKey.random(Secp256k1, myRng)[]) confBuilder.discv5Conf.withEnabled(true) confBuilder.discv5Conf.withUdpPort(9000.Port) let conf = confBuilder.build().valueOr: @@ -434,7 +435,7 @@ suite "Waku Discovery v5": (waitFor startWaku(addr waku0)).isOkOr: raiseAssert error - confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng)[]) confBuilder.discv5Conf.withBootstrapNodes(@[waku0.node.enr.toURI()]) confBuilder.discv5Conf.withEnabled(true) confBuilder.discv5Conf.withUdpPort(9001.Port) @@ -454,7 +455,7 @@ suite "Waku Discovery v5": confBuilder.discv5Conf.withBootstrapNodes(@[waku1.node.enr.toURI()]) confBuilder.withP2pTcpPort(60003.Port) confBuilder.discv5Conf.withUdpPort(9003.Port) - confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng[])[]) + confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng)[]) let conf2 = confBuilder.build().valueOr: raiseAssert error diff --git a/tests/waku_filter_v2/waku_filter_utils.nim b/tests/waku_filter_v2/waku_filter_utils.nim index 2f04ceb366..2390997654 100644 --- a/tests/waku_filter_v2/waku_filter_utils.nim +++ b/tests/waku_filter_v2/waku_filter_utils.nim @@ -36,7 +36,7 @@ proc newTestWakuFilter*( proc newTestWakuFilterClient*(switch: Switch): Future[WakuFilterClient] {.async.} = let peerManager = PeerManager.new(switch) - proto = WakuFilterClient.new(peerManager, rng) + proto = WakuFilterClient.new(peerManager, common.rng()) await proto.start() switch.mount(proto) diff --git a/tests/waku_lightpush/lightpush_utils.nim b/tests/waku_lightpush/lightpush_utils.nim index 7bd44a311e..074dc87543 100644 --- a/tests/waku_lightpush/lightpush_utils.nim +++ b/tests/waku_lightpush/lightpush_utils.nim @@ -20,7 +20,7 @@ proc newTestWakuLightpushNode*( peerManager = PeerManager.new(switch) wakuAutoSharding = Sharding(clusterId: 1, shardCountGenZero: 8) proto = WakuLightPush.new( - peerManager, rng, handler, some(wakuAutoSharding), rateLimitSetting + peerManager, crypto.newRng(), handler, some(wakuAutoSharding), rateLimitSetting ) await proto.start() @@ -30,4 +30,4 @@ proc newTestWakuLightpushNode*( proc newTestWakuLightpushClient*(switch: Switch): WakuLightPushClient = let peerManager = PeerManager.new(switch) - WakuLightPushClient.new(peerManager, rng) + WakuLightPushClient.new(peerManager, crypto.newRng()) diff --git a/tests/waku_lightpush_legacy/lightpush_utils.nim b/tests/waku_lightpush_legacy/lightpush_utils.nim index d5602173ab..5636afbeee 100644 --- a/tests/waku_lightpush_legacy/lightpush_utils.nim +++ b/tests/waku_lightpush_legacy/lightpush_utils.nim @@ -19,7 +19,7 @@ proc newTestWakuLegacyLightpushNode*( ): Future[WakuLegacyLightPush] {.async.} = let peerManager = PeerManager.new(switch) - proto = WakuLegacyLightPush.new(peerManager, rng, handler, rateLimitSetting) + proto = WakuLegacyLightPush.new(peerManager, crypto.newRng(), handler, rateLimitSetting) await proto.start() switch.mount(proto) @@ -28,4 +28,4 @@ proc newTestWakuLegacyLightpushNode*( proc newTestWakuLegacyLightpushClient*(switch: Switch): WakuLegacyLightPushClient = let peerManager = PeerManager.new(switch) - WakuLegacyLightPushClient.new(peerManager, rng) + WakuLegacyLightPushClient.new(peerManager, crypto.newRng()) diff --git a/tests/waku_relay/test_wakunode_relay.nim b/tests/waku_relay/test_wakunode_relay.nim index a687119bda..dabc0e119d 100644 --- a/tests/waku_relay/test_wakunode_relay.nim +++ b/tests/waku_relay/test_wakunode_relay.nim @@ -1,7 +1,7 @@ {.used.} import - std/[os, strutils, sequtils, sysrand, math], + std/[os, strutils, sequtils, sysrand, math, options], stew/byteutils, testutils/unittests, chronos, diff --git a/tests/waku_relay/utils.nim b/tests/waku_relay/utils.nim index 069600106b..0bc7a31431 100644 --- a/tests/waku_relay/utils.nim +++ b/tests/waku_relay/utils.nim @@ -1,7 +1,7 @@ {.used.} import - std/[strutils, sequtils, tempfiles], + std/[strutils, sequtils, tempfiles, options], stew/byteutils, chronos, chronicles, diff --git a/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim b/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim index 4bdcbbdc31..5737f95eaa 100644 --- a/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim +++ b/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim @@ -1,3 +1,4 @@ +import std/options import std/tempfiles import diff --git a/tests/waku_rln_relay/utils_offchain.nim b/tests/waku_rln_relay/utils_offchain.nim index e0e1bd1f79..e550989b28 100644 --- a/tests/waku_rln_relay/utils_offchain.nim +++ b/tests/waku_rln_relay/utils_offchain.nim @@ -1,7 +1,7 @@ {.used.} import - std/[sequtils, tempfiles], + std/[sequtils, tempfiles, options], stew/byteutils, chronos, chronicles, diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index db07d3cd66..41f616157a 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/rng {.used.} {.push raises: [].} @@ -446,7 +447,7 @@ proc createEthAccount*( let gasPrice = Quantity(await web3.provider.eth_gasPrice()) web3.defaultAccount = accounts[0] - let pk = keys.PrivateKey.random(rng[]) + let pk = keys.PrivateKey.random(keys.newRng()[]) let acc = Address(toCanonicalAddress(pk.toPublicKey())) var tx: TransactionArgs @@ -464,7 +465,7 @@ proc createEthAccount*( return (pk, acc) proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) = - let pk = keys.PrivateKey.random(rng[]) + let pk = keys.PrivateKey.random(keys.newRng()[]) let acc = Address(toCanonicalAddress(pk.toPublicKey())) return (pk, acc) diff --git a/tests/waku_store/store_utils.nim b/tests/waku_store/store_utils.nim index 4586a06312..bbcb2f7c29 100644 --- a/tests/waku_store/store_utils.nim +++ b/tests/waku_store/store_utils.nim @@ -10,7 +10,7 @@ proc newTestWakuStore*( ): Future[WakuStore] {.async.} = let peerManager = PeerManager.new(switch) - proto = WakuStore.new(peerManager, rng, handler) + proto = WakuStore.new(peerManager, common.rng(), handler) await proto.start() switch.mount(proto) @@ -19,4 +19,4 @@ proc newTestWakuStore*( proc newTestWakuStoreClient*(switch: Switch): WakuStoreClient {.gcsafe.} = let peerManager = PeerManager.new(switch) - WakuStoreClient.new(peerManager, rng) + WakuStoreClient.new(peerManager, common.rng()) diff --git a/tests/waku_store/test_wakunode_store.nim b/tests/waku_store/test_wakunode_store.nim index fa73cd16d0..cce3e3b02d 100644 --- a/tests/waku_store/test_wakunode_store.nim +++ b/tests/waku_store/test_wakunode_store.nim @@ -1,7 +1,7 @@ {.used.} import - std/sequtils, + std/[sequtils, options], testutils/unittests, chronicles, chronos, diff --git a/tests/wakunode2/test_app.nim b/tests/wakunode2/test_app.nim index 7621ab1e75..6cd7712c7e 100644 --- a/tests/wakunode2/test_app.nim +++ b/tests/wakunode2/test_app.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.used.} import diff --git a/tests/wakunode2/test_validators.nim b/tests/wakunode2/test_validators.nim index 83928e4dfa..dfc3b847d1 100644 --- a/tests/wakunode2/test_validators.nim +++ b/tests/wakunode2/test_validators.nim @@ -1,7 +1,7 @@ {.used.} import - std/[sequtils, sysrand, math], + std/[sequtils, sysrand, math, options], testutils/unittests, chronos, libp2p/crypto/crypto, diff --git a/tests/wakunode_rest/test_rest_cors.nim b/tests/wakunode_rest/test_rest_cors.nim index 0393b0d727..1880cee9e7 100644 --- a/tests/wakunode_rest/test_rest_cors.nim +++ b/tests/wakunode_rest/test_rest_cors.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import @@ -22,7 +23,7 @@ type TestResponseTuple = tuple[status: int, data: string, headers: HttpTable] proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/tests/wakunode_rest/test_rest_debug.nim b/tests/wakunode_rest/test_rest_debug.nim index 1171f5878d..df3804114b 100644 --- a/tests/wakunode_rest/test_rest_debug.nim +++ b/tests/wakunode_rest/test_rest_debug.nim @@ -25,7 +25,7 @@ import proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/tests/wakunode_rest/test_rest_debug_serdes.nim b/tests/wakunode_rest/test_rest_debug_serdes.nim index d3232e5714..b654665e1f 100644 --- a/tests/wakunode_rest/test_rest_debug_serdes.nim +++ b/tests/wakunode_rest/test_rest_debug_serdes.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import results, stew/byteutils, testutils/unittests, json_serialization diff --git a/tests/wakunode_rest/test_rest_filter.nim b/tests/wakunode_rest/test_rest_filter.nim index 1a4731d6ae..75d06b73eb 100644 --- a/tests/wakunode_rest/test_rest_filter.nim +++ b/tests/wakunode_rest/test_rest_filter.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import diff --git a/tests/wakunode_rest/test_rest_health.nim b/tests/wakunode_rest/test_rest_health.nim index 0bdb931234..e3250127ea 100644 --- a/tests/wakunode_rest/test_rest_health.nim +++ b/tests/wakunode_rest/test_rest_health.nim @@ -1,7 +1,7 @@ {.used.} import - std/[tempfiles, osproc], + std/[tempfiles, osproc, options], testutils/unittests, presto, presto/client as presto_client, @@ -29,7 +29,7 @@ import proc testWakuNode(): WakuNode = let - privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet() + privkey = crypto.PrivateKey.random(Secp256k1, rng).tryGet() bindIp = parseIpAddress("0.0.0.0") extIp = parseIpAddress("127.0.0.1") port = Port(0) diff --git a/tests/wakunode_rest/test_rest_lightpush.nim b/tests/wakunode_rest/test_rest_lightpush.nim index deba7de22e..9afb0eb6fd 100644 --- a/tests/wakunode_rest/test_rest_lightpush.nim +++ b/tests/wakunode_rest/test_rest_lightpush.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import diff --git a/tests/wakunode_rest/test_rest_lightpush_legacy.nim b/tests/wakunode_rest/test_rest_lightpush_legacy.nim index 4043eeed9e..339638038b 100644 --- a/tests/wakunode_rest/test_rest_lightpush_legacy.nim +++ b/tests/wakunode_rest/test_rest_lightpush_legacy.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import diff --git a/tests/wakunode_rest/test_rest_relay.nim b/tests/wakunode_rest/test_rest_relay.nim index a98b755204..135ff90d99 100644 --- a/tests/wakunode_rest/test_rest_relay.nim +++ b/tests/wakunode_rest/test_rest_relay.nim @@ -1,7 +1,7 @@ {.used.} import - std/[sequtils, strformat, tempfiles, osproc], + std/[sequtils, strformat, tempfiles, osproc, options], stew/byteutils, testutils/unittests, presto, diff --git a/tests/wakunode_rest/test_rest_relay_serdes.nim b/tests/wakunode_rest/test_rest_relay_serdes.nim index 21d21e281c..87ff37c324 100644 --- a/tests/wakunode_rest/test_rest_relay_serdes.nim +++ b/tests/wakunode_rest/test_rest_relay_serdes.nim @@ -1,3 +1,4 @@ +import std/options {.used.} import results, stew/byteutils, unittest2, json_serialization diff --git a/waku.nimble b/waku.nimble index da5b87eb62..3c50ce54cb 100644 --- a/waku.nimble +++ b/waku.nimble @@ -27,7 +27,7 @@ requires "nim >= 2.2.4", "toml_serialization", "faststreams", # Networking & P2P - "https://github.com/vacp2p/nim-libp2p.git#ff8d51857b4b79a68468e7bcc27b2026cca02996", + "https://github.com/vacp2p/nim-libp2p.git#c43199378f46d0aaf61be1cad1ee1d63e8f665d6", "eth", "nat_traversal", "dnsdisc", @@ -75,6 +75,7 @@ requires "https://github.com/NagyZoltanPeter/nim-brokers.git#v2.0.1" requires "https://github.com/vacp2p/nim-lsquic" requires "https://github.com/vacp2p/nim-jwt.git#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2" +requires "https://github.com/logos-co/nim-libp2p-mix#7cb7556d9a228573fc5622af7ffb2dd11741e043" proc getMyCPU(): string = ## Need to set cpu more explicit manner to avoid arch issues between dependencies diff --git a/waku/api/api.nim b/waku/api/api.nim index 1eee982fd8..3ee3acadc6 100644 --- a/waku/api/api.nim +++ b/waku/api/api.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, chronos, results import waku/factory/waku diff --git a/waku/api/api_conf.nim b/waku/api/api_conf.nim index 3606be5965..74ed1dabf9 100644 --- a/waku/api/api_conf.nim +++ b/waku/api/api_conf.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[net, options] import results diff --git a/waku/api/types.nim b/waku/api/types.nim index 2b7edd616e..2dcba3f244 100644 --- a/waku/api/types.nim +++ b/waku/api/types.nim @@ -1,3 +1,5 @@ +import waku/compat/option_valueor +import libp2p/crypto/crypto {.push raises: [].} import bearssl/rand, std/times, chronos @@ -23,7 +25,7 @@ type PartiallyConnected Connected -proc new*(T: typedesc[RequestId], rng: ref HmacDrbgContext): T = +proc new*(T: typedesc[RequestId], rng: crypto.Rng): T = ## Generate a new RequestId using the provided RNG. RequestId(request_utils.generateRequestId(rng)) diff --git a/waku/common/databases/db_postgres/dbconn.nim b/waku/common/databases/db_postgres/dbconn.nim index f24f3d4dd5..a5975a0bfd 100644 --- a/waku/common/databases/db_postgres/dbconn.nim +++ b/waku/common/databases/db_postgres/dbconn.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[times, strutils, os, sets, strformat, tables], results, diff --git a/waku/common/databases/db_postgres/pgasyncpool.nim b/waku/common/databases/db_postgres/pgasyncpool.nim index 0b298084ea..1e151080fb 100644 --- a/waku/common/databases/db_postgres/pgasyncpool.nim +++ b/waku/common/databases/db_postgres/pgasyncpool.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor # Simple async pool driver for postgress. # Inspired by: https://github.com/treeform/pg/ {.push raises: [].} diff --git a/waku/common/databases/db_sqlite.nim b/waku/common/databases/db_sqlite.nim index e398ea5acd..60d45f54cf 100644 --- a/waku/common/databases/db_sqlite.nim +++ b/waku/common/databases/db_sqlite.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} # The code in this file is an adaptation of the Sqlite KV Store found in nim-eth. # https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim diff --git a/waku/common/enr/typed_record.nim b/waku/common/enr/typed_record.nim index 1db3576211..475f301acc 100644 --- a/waku/common/enr/typed_record.nim +++ b/waku/common/enr/typed_record.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/options, results, eth/keys as eth_keys, libp2p/crypto/crypto as libp2p_crypto diff --git a/waku/common/rate_limit/request_limiter.nim b/waku/common/rate_limit/request_limiter.nim index bc318e1514..7d6d432e82 100644 --- a/waku/common/rate_limit/request_limiter.nim +++ b/waku/common/rate_limit/request_limiter.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## RequestRateLimiter ## ## RequestRateLimiter is a general service protection mechanism. diff --git a/waku/common/utils/parse_size_units.nim b/waku/common/utils/parse_size_units.nim index 14f41a9334..58fc6279fd 100644 --- a/waku/common/utils/parse_size_units.nim +++ b/waku/common/utils/parse_size_units.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[strutils, math], results, regex proc parseMsgSize*(input: string): Result[uint64, string] = diff --git a/waku/compat/option_valueor.nim b/waku/compat/option_valueor.nim new file mode 100644 index 0000000000..12c2cb2719 --- /dev/null +++ b/waku/compat/option_valueor.nim @@ -0,0 +1,35 @@ +## Polyfill: `valueOr` / `withValue` templates for `std/options.Option[T]`. +## +## Previously provided transitively by `libp2p/utility`, removed in +## nim-libp2p PR #2162 (commit 8a9943145). logos-delivery uses these +## templates pervasively on `Option[T]`. The shim restores them here while +## we adapt to upstream churn; collocated under `waku/compat/` so the +## category is explicit (compatibility with upstream API drift), not a +## generic dumping ground. + +{.push raises: [].} + +import std/[macros, options] + +template valueOr*[T](self: Option[T], body: untyped): untyped = + let temp = (self) + if temp.isSome: + temp.get() + else: + body + +template withValue*[T](self: Option[T], value, body: untyped): untyped = + let temp = (self) + if temp.isSome: + let `value` {.inject.} = temp.get() + body + +macro withValue*[T](self: Option[T], value, body, elseStmt: untyped): untyped = + let elseBody = elseStmt[0] + quote: + let temp = (`self`) + if temp.isSome: + let `value` {.inject.} = temp.get() + `body` + else: + `elseBody` diff --git a/waku/discovery/autonat_service.nim b/waku/discovery/autonat_service.nim index fb1f7dbc3f..9f6ecaafda 100644 --- a/waku/discovery/autonat_service.nim +++ b/waku/discovery/autonat_service.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/crypto import chronos, chronicles, @@ -7,7 +8,7 @@ import const AutonatCheckInterval = Opt.some(chronos.seconds(30)) -proc getAutonatService*(rng: ref HmacDrbgContext): AutonatService = +proc getAutonatService*(rng: crypto.Rng): AutonatService = ## AutonatService request other peers to dial us back ## flagging us as Reachable or NotReachable. ## minConfidence is used as threshold to determine the state. diff --git a/waku/discovery/waku_discv5.nim b/waku/discovery/waku_discv5.nim index c1b253c8cd..631f4a60b1 100644 --- a/waku/discovery/waku_discv5.nim +++ b/waku/discovery/waku_discv5.nim @@ -1,3 +1,6 @@ +import libp2p/crypto/crypto +import libp2p/crypto/rng +import waku/compat/option_valueor {.push raises: [].} import @@ -80,7 +83,7 @@ proc shardingPredicate*( proc new*( T: type WakuDiscoveryV5, - rng: ref HmacDrbgContext, + rng: crypto.Rng, conf: WakuDiscoveryV5Config, record: Option[waku_enr.Record], peerManager: Option[PeerManager] = none(PeerManager), @@ -88,7 +91,7 @@ proc new*( newAsyncEventQueue[SubscriptionEvent](30), ): T = let protocol = newProtocol( - rng = rng, + rng = rng.bearSslDrbgRef, config = conf.discv5Config.get(protocol.defaultDiscoveryConfig), bindPort = conf.port, bindIp = conf.address, @@ -405,7 +408,7 @@ proc setupDiscoveryV5*( nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent], conf: Discv5Conf, dynamicBootstrapNodes: seq[RemotePeerInfo], - rng: ref HmacDrbgContext, + rng: crypto.Rng, key: crypto.PrivateKey, p2pListenAddress: IpAddress, portsShift: uint16, @@ -461,7 +464,7 @@ proc setupAndStartDiscv5*( nodeTopicSubscriptionQueue: AsyncEventQueue[SubscriptionEvent], conf: Discv5Conf, dynamicBootstrapNodes: seq[RemotePeerInfo], - rng: ref HmacDrbgContext, + rng: crypto.Rng, key: crypto.PrivateKey, p2pListenAddress: IpAddress, portsShift: uint16, diff --git a/waku/discovery/waku_dnsdisc.nim b/waku/discovery/waku_dnsdisc.nim index 0d0a829483..4754dcce02 100644 --- a/waku/discovery/waku_dnsdisc.nim +++ b/waku/discovery/waku_dnsdisc.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} ## A set of utilities to integrate EIP-1459 DNS-based discovery diff --git a/waku/discovery/waku_kademlia.nim b/waku/discovery/waku_kademlia.nim index 94b63a3215..22fe4d7b8a 100644 --- a/waku/discovery/waku_kademlia.nim +++ b/waku/discovery/waku_kademlia.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/[options, sequtils] @@ -9,9 +10,9 @@ import libp2p/[peerid, multiaddress, switch], libp2p/extended_peer_record, libp2p/crypto/curve25519, - libp2p/protocols/[kademlia, kad_disco], - libp2p/protocols/kademlia_discovery/types as kad_types, - libp2p/protocols/mix/mix_protocol + libp2p/protocols/[kademlia, service_discovery], + libp2p/protocols/service_discovery/types as svdisc_types, + libp2p_mix/mix_protocol import waku/waku_core, waku/node/peer_manager @@ -32,7 +33,7 @@ type advertiseMix*: bool = false WakuKademlia* = ref object - protocol*: KademliaDiscovery + protocol*: ServiceDiscovery peerManager: PeerManager discoveryLoop: Future[void] running*: bool @@ -50,13 +51,14 @@ proc new*( if params.bootstrapNodes.len == 0: info "creating kademlia discovery as seed node (no bootstrap nodes)" - let kademlia = KademliaDiscovery.new( + let kademlia = ServiceDiscovery.new( switch, bootstrapNodes = params.bootstrapNodes, config = KadDHTConfig.new( - validator = kad_types.ExtEntryValidator(), selector = kad_types.ExtEntrySelector() + validator = svdisc_types.ExtEntryValidator(), selector = svdisc_types.ExtEntrySelector() ), - codec = ExtendedKademliaDiscoveryCodec, + rng = switch.rng, + codec = ExtendedServiceDiscoveryCodec, ) try: @@ -68,11 +70,9 @@ proc new*( # initial self-signed peer record published to the DHT if params.advertiseMix: if params.mixPubKey.isSome(): - let alreadyAdvertising = kademlia.startAdvertising( + kademlia.startAdvertising( ServiceInfo(id: MixProtocolID, data: @(params.mixPubKey.get())) ) - if alreadyAdvertising: - warn "mix service was already being advertised" debug "extended kademlia advertising mix service", keyHex = byteutils.toHex(params.mixPubKey.get()), bootstrapNodes = params.bootstrapNodes.len @@ -164,7 +164,9 @@ proc lookupMixPeers*( let mixService = ServiceInfo(id: MixProtocolID, data: @[]) var records: seq[ExtendedPeerRecord] try: - records = await wk.protocol.lookup(mixService) + let advertisements = (await wk.protocol.lookup(mixService)).valueOr: + return err("mix peer lookup failed: " & $error) + records = advertisements.mapIt(it.data) except CatchableError: return err("mix peer lookup failed: " & getCurrentExceptionMsg()) @@ -202,7 +204,7 @@ proc runDiscoveryLoop( var records: seq[ExtendedPeerRecord] try: - records = await wk.protocol.randomRecords() + records = await wk.protocol.lookupRandom() except CatchableError as e: warn "extended kademlia discovery failed", error = e.msg await sleepAsync(interval) diff --git a/waku/factory/builder.nim b/waku/factory/builder.nim index 4212cb92df..184937ab53 100644 --- a/waku/factory/builder.nim +++ b/waku/factory/builder.nim @@ -15,13 +15,14 @@ import ../waku_enr, ../discovery/waku_discv5, ../waku_node, + ../node/waku_switch, ../node/peer_manager, ../common/rate_limit/setting, ../common/utils/parse_size_units type WakuNodeBuilder* = object # General - nodeRng: Option[ref crypto.HmacDrbgContext] + nodeRng: Option[crypto.Rng] nodeKey: Option[crypto.PrivateKey] netConfig: Option[NetConfig] record: Option[enr.Record] @@ -57,7 +58,7 @@ proc init*(T: type WakuNodeBuilder): WakuNodeBuilder = ## General -proc withRng*(builder: var WakuNodeBuilder, rng: ref crypto.HmacDrbgContext) = +proc withRng*(builder: var WakuNodeBuilder, rng: crypto.Rng) = builder.nodeRng = some(rng) proc withNodeKey*(builder: var WakuNodeBuilder, nodeKey: crypto.PrivateKey) = @@ -157,7 +158,7 @@ proc withSwitchConfiguration*( ## Build proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] = - var rng: ref crypto.HmacDrbgContext + var rng: crypto.Rng if builder.nodeRng.isNone(): rng = crypto.newRng() else: @@ -190,7 +191,7 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] = wsAddress = builder.netConfig.get().wsHostAddress, transportFlags = {ServerFlags.ReuseAddr, ServerFlags.TcpNoDelay}, rng = rng, - maxConnections = builder.switchMaxConnections.get(builders.MaxConnections), + maxConnections = builder.switchMaxConnections.get(MaxConnections), wssEnabled = builder.netConfig.get().wssEnabled, secureKeyPath = builder.switchSslSecureKey.get(""), secureCertPath = builder.switchSslSecureCert.get(""), @@ -210,7 +211,7 @@ proc build*(builder: WakuNodeBuilder): Result[WakuNode, string] = maxServicePeers = some(builder.maxServicePeers), colocationLimit = builder.colocationLimit, shardedPeerManagement = builder.shardAware, - maxConnections = builder.switchMaxConnections.get(builders.MaxConnections), + maxConnections = builder.switchMaxConnections.get(MaxConnections), ) var node: WakuNode diff --git a/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim b/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim index 916d71be1c..9d60ed6216 100644 --- a/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim +++ b/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, std/options, results import libp2p/[peerid, multiaddress, peerinfo] import waku/factory/waku_conf diff --git a/waku/factory/conf_builder/mix_conf_builder.nim b/waku/factory/conf_builder/mix_conf_builder.nim index 145ccb76e9..956a9b52bb 100644 --- a/waku/factory/conf_builder/mix_conf_builder.nim +++ b/waku/factory/conf_builder/mix_conf_builder.nim @@ -1,5 +1,6 @@ +import waku/compat/option_valueor import chronicles, std/options, results -import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p/protocols/mix/curve25519 +import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p_mix/curve25519 import ../waku_conf, waku/waku_mix logScope: diff --git a/waku/factory/conf_builder/rate_limit_conf_builder.nim b/waku/factory/conf_builder/rate_limit_conf_builder.nim index b2edbef03e..78e069ccf7 100644 --- a/waku/factory/conf_builder/rate_limit_conf_builder.nim +++ b/waku/factory/conf_builder/rate_limit_conf_builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, std/[net, options], results import waku/common/rate_limit/setting diff --git a/waku/factory/conf_builder/store_service_conf_builder.nim b/waku/factory/conf_builder/store_service_conf_builder.nim index f1b0b1402d..0a0e4af825 100644 --- a/waku/factory/conf_builder/store_service_conf_builder.nim +++ b/waku/factory/conf_builder/store_service_conf_builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, strutils, sequtils] import chronicles, results, chronos import ../waku_conf, ./store_sync_conf_builder diff --git a/waku/factory/conf_builder/waku_conf_builder.nim b/waku/factory/conf_builder/waku_conf_builder.nim index 96e34eeedb..83cfd9086c 100644 --- a/waku/factory/conf_builder/waku_conf_builder.nim +++ b/waku/factory/conf_builder/waku_conf_builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import libp2p/crypto/crypto, libp2p/multiaddress, @@ -293,13 +294,13 @@ proc withStaticNodes*(builder: var WakuConfBuilder, staticNodes: seq[string]) = ## Building proc nodeKey( - builder: WakuConfBuilder, rng: ref HmacDrbgContext + builder: WakuConfBuilder, rng: crypto.Rng ): Result[crypto.PrivateKey, string] = if builder.nodeKey.isSome(): return ok(builder.nodeKey.get()) else: warn "missing node key, generating new set" - let nodeKey = crypto.PrivateKey.random(Secp256k1, rng[]).valueOr: + let nodeKey = crypto.PrivateKey.random(Secp256k1, rng).valueOr: error "Failed to generate key", error = error return err("Failed to generate key: " & $error) return ok(nodeKey) @@ -443,7 +444,7 @@ proc applyNetworkConf(builder: var WakuConfBuilder) = warn "Failed to process entry nodes from network conf", error = processed.error() proc build*( - builder: var WakuConfBuilder, rng: ref HmacDrbgContext = crypto.newRng() + builder: var WakuConfBuilder, rng: crypto.Rng = crypto.newRng() ): Result[WakuConf, string] = ## Return a WakuConf that contains all mandatory parameters ## Applies some sane defaults that are applicable across any usage diff --git a/waku/factory/internal_config.nim b/waku/factory/internal_config.nim index fa36aff576..c2928103f4 100644 --- a/waku/factory/internal_config.nim +++ b/waku/factory/internal_config.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, chronos, diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 52b719b8fd..5a4a2d2fd9 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, sequtils], chronicles, @@ -54,7 +55,7 @@ proc setupPeerStorage(): Result[Option[WakuPeerStorage], string] = proc initNode( conf: WakuConf, netConfig: NetConfig, - rng: ref HmacDrbgContext, + rng: crypto.Rng, record: enr.Record, peerStore: Option[WakuPeerStorage], relay: Relay, @@ -458,7 +459,7 @@ proc startNode*( return ok() proc setupNode*( - wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay + wakuConf: WakuConf, rng: crypto.Rng = crypto.newRng(), relay: Relay ): Future[Result[WakuNode, string]] {.async.} = let netConfig = ( await networkConfiguration( diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 6a5567f8cc..62c33b12a6 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -60,7 +61,7 @@ const git_version* {.strdefine.} = "n/a" type Waku* = ref object stateInfo*: WakuStateInfo conf*: WakuConf - rng*: ref HmacDrbgContext + rng*: crypto.Rng key: crypto.PrivateKey @@ -82,7 +83,7 @@ type Waku* = ref object brokerCtx*: BrokerContext proc setupSwitchServices( - waku: Waku, conf: WakuConf, circuitRelay: Relay, rng: ref HmacDrbgContext + waku: Waku, conf: WakuConf, circuitRelay: Relay, rng: crypto.Rng ) = proc onReservation(addresses: seq[MultiAddress]) {.gcsafe, raises: [].} = info "circuit relay handler new reserve event", diff --git a/waku/incentivization/eligibility_manager.nim b/waku/incentivization/eligibility_manager.nim index cbbf4774c9..cd0b093034 100644 --- a/waku/incentivization/eligibility_manager.nim +++ b/waku/incentivization/eligibility_manager.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, sets], chronos, web3, stew/byteutils, stint, results, chronicles import waku/incentivization/rpc, tests/waku_rln_relay/utils_onchain diff --git a/waku/node/delivery_service/recv_service/recv_service.nim b/waku/node/delivery_service/recv_service/recv_service.nim index 899f80f71b..43c6ae70c7 100644 --- a/waku/node/delivery_service/recv_service/recv_service.nim +++ b/waku/node/delivery_service/recv_service/recv_service.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## This module is in charge of taking care of the messages that this node is expecting to ## receive and is backed by store-v3 requests to get an additional degree of certainty ## diff --git a/waku/node/delivery_service/send_service/delivery_task.nim b/waku/node/delivery_service/send_service/delivery_task.nim index aa1dc17d73..a8b55138cf 100644 --- a/waku/node/delivery_service/send_service/delivery_task.nim +++ b/waku/node/delivery_service/send_service/delivery_task.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, times], chronos import brokers/broker_context import waku/waku_core, waku/api/types, waku/requests/node_requests diff --git a/waku/node/delivery_service/send_service/lightpush_processor.nim b/waku/node/delivery_service/send_service/lightpush_processor.nim index 7a9f65c719..bbed1a2a14 100644 --- a/waku/node/delivery_service/send_service/lightpush_processor.nim +++ b/waku/node/delivery_service/send_service/lightpush_processor.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, chronos, results import std/options import brokers/broker_context diff --git a/waku/node/delivery_service/send_service/relay_processor.nim b/waku/node/delivery_service/send_service/relay_processor.nim index e06b664fbb..4fe428921a 100644 --- a/waku/node/delivery_service/send_service/relay_processor.nim +++ b/waku/node/delivery_service/send_service/relay_processor.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/options import chronos, chronicles import brokers/broker_context diff --git a/waku/node/delivery_service/send_service/send_service.nim b/waku/node/delivery_service/send_service/send_service.nim index 88ec802cfb..209f4f958f 100644 --- a/waku/node/delivery_service/send_service/send_service.nim +++ b/waku/node/delivery_service/send_service/send_service.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## This module reinforces the publish operation with regular store-v3 requests. ## diff --git a/waku/node/delivery_service/subscription_manager.nim b/waku/node/delivery_service/subscription_manager.nim index 393a61eaea..6a731b621f 100644 --- a/waku/node/delivery_service/subscription_manager.nim +++ b/waku/node/delivery_service/subscription_manager.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[sequtils, sets, tables, options, strutils], chronos, chronicles, results import libp2p/[peerid, peerinfo] import brokers/broker_context diff --git a/waku/node/health_monitor/node_health_monitor.nim b/waku/node/health_monitor/node_health_monitor.nim index c652f7cea7..c1bdc65726 100644 --- a/waku/node/health_monitor/node_health_monitor.nim +++ b/waku/node/health_monitor/node_health_monitor.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/kernel_api/filter.nim b/waku/node/kernel_api/filter.nim index 948035f14b..fdc1efba7c 100644 --- a/waku/node/kernel_api/filter.nim +++ b/waku/node/kernel_api/filter.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/kernel_api/lightpush.nim b/waku/node/kernel_api/lightpush.nim index ffe2afdac4..edc579301a 100644 --- a/waku/node/kernel_api/lightpush.nim +++ b/waku/node/kernel_api/lightpush.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -17,7 +18,7 @@ import libp2p/transports/tcptransport, libp2p/transports/wstransport, libp2p/utility, - libp2p/protocols/mix + libp2p_mix import ../waku_node, diff --git a/waku/node/kernel_api/peer_exchange.nim b/waku/node/kernel_api/peer_exchange.nim index a4bec727b3..f52818378c 100644 --- a/waku/node/kernel_api/peer_exchange.nim +++ b/waku/node/kernel_api/peer_exchange.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/kernel_api/ping.nim b/waku/node/kernel_api/ping.nim index 9dc649fd84..eddd69530e 100644 --- a/waku/node/kernel_api/ping.nim +++ b/waku/node/kernel_api/ping.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/kernel_api/relay.nim b/waku/node/kernel_api/relay.nim index f1b80cf197..8fc6bda1fc 100644 --- a/waku/node/kernel_api/relay.nim +++ b/waku/node/kernel_api/relay.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/kernel_api/store.nim b/waku/node/kernel_api/store.nim index fcf0dfc895..1da9477e39 100644 --- a/waku/node/kernel_api/store.nim +++ b/waku/node/kernel_api/store.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/peer_manager/peer_manager.nim b/waku/node/peer_manager/peer_manager.nim index 6602c049b5..81a030da58 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/waku/node/peer_manager/peer_manager.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -25,6 +26,7 @@ import common/callbacks, common/utils/parse_size_units, node/health_monitor/online_monitor, + node/waku_switch, ], ./peer_store/peer_storage, ./waku_peer_store diff --git a/waku/node/peer_manager/peer_store/waku_peer_storage.nim b/waku/node/peer_manager/peer_store/waku_peer_storage.nim index dc14526181..c112744315 100644 --- a/waku/node/peer_manager/peer_store/waku_peer_storage.nim +++ b/waku/node/peer_manager/peer_store/waku_peer_storage.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/node/peer_manager/waku_peer_store.nim b/waku/node/peer_manager/waku_peer_store.nim index 93ac9ad2e9..b4a668ccf4 100644 --- a/waku/node/peer_manager/waku_peer_store.nim +++ b/waku/node/peer_manager/waku_peer_store.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -7,7 +8,8 @@ import eth/p2p/discoveryv5/enr, libp2p/builders, libp2p/peerstore, - libp2p/crypto/curve25519 + libp2p/crypto/curve25519, + libp2p_mix/pool import ../../waku_core, diff --git a/waku/node/waku_metrics.nim b/waku/node/waku_metrics.nim index af74b15327..3fc8bc5851 100644 --- a/waku/node/waku_metrics.nim +++ b/waku/node/waku_metrics.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import chronicles, chronos, metrics, metrics/chronos_httpserver diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 26a2b5a570..c10f7e0f3b 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -23,8 +24,8 @@ import libp2p/transports/wstransport, libp2p/utility, libp2p/utils/offsettedseq, - libp2p/protocols/mix, - libp2p/protocols/mix/mix_protocol, + libp2p_mix, + libp2p_mix/mix_protocol, brokers/broker_context, brokers/request_broker @@ -126,7 +127,7 @@ type wakuAutoSharding*: Option[Sharding] enr*: enr.Record libp2pPing*: Ping - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng brokerCtx*: BrokerContext wakuRendezvous*: WakuRendezVous wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient @@ -207,7 +208,7 @@ proc new*( peerManager: PeerManager, rateLimitSettings: ProtocolRateLimitSettings = DefaultProtocolRateLimit, # TODO: make this argument required after tests are updated - rng: ref HmacDrbgContext = crypto.newRng(), + rng: crypto.Rng = crypto.newRng(), ): T {.raises: [Defect, LPError, IOError, TLSStreamProtocolError].} = ## Creates a Waku Node instance. diff --git a/waku/node/waku_switch.nim b/waku/node/waku_switch.nim index d1af776621..6e02b8b8bd 100644 --- a/waku/node/waku_switch.nim +++ b/waku/node/waku_switch.nim @@ -18,10 +18,12 @@ import # override nim-libp2p default value (which is also 1) const MaxConnectionsPerPeer* = 1 +const MaxConnections* = 50 + proc withWsTransport*(b: SwitchBuilder): SwitchBuilder = b.withTransport( - proc(upgr: Upgrade, privateKey: crypto.PrivateKey): Transport = - WsTransport.new(upgr) + proc(config: TransportConfig): Transport = + WsTransport.new(config.upgr, rng = config.rng) ) proc getSecureKey(path: string): TLSPrivateKey {.raises: [Defect, IOError].} = @@ -59,7 +61,7 @@ proc newWakuSwitch*( wsAddress = none(MultiAddress), secureManagers: openarray[SecureProtocol] = [SecureProtocol.Noise], transportFlags: set[ServerFlags] = {}, - rng: ref HmacDrbgContext, + rng: crypto.Rng, inTimeout: Duration = 5.minutes, outTimeout: Duration = 5.minutes, maxConnections = MaxConnections, @@ -80,8 +82,7 @@ proc newWakuSwitch*( .new() .withRng(rng) .withMaxConnections(maxConnections) - .withMaxIn(maxIn) - .withMaxOut(maxOut) + .withMaxInOut(maxIn, maxOut) .withMaxConnsPerPeer(maxConnsPerPeer) .withYamux() .withMplex(inTimeout, outTimeout) @@ -112,6 +113,6 @@ proc newWakuSwitch*( b = b.withAddress(address) if not rendezvous.isNil(): - b = b.withRendezVous(rendezvous) + b = b.withRendezVous() b.build() diff --git a/waku/persistency/persistency.nim b/waku/persistency/persistency.nim index 916f3ac8be..ef00bd6f6a 100644 --- a/waku/persistency/persistency.nim +++ b/waku/persistency/persistency.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Public facade and main driver types for the persistency library. ## ## ``Persistency`` is the per-root coordinator; one instance owns one diff --git a/waku/rest_api/endpoint/admin/handlers.nim b/waku/rest_api/endpoint/admin/handlers.nim index 304fdabf89..371d75df81 100644 --- a/waku/rest_api/endpoint/admin/handlers.nim +++ b/waku/rest_api/endpoint/admin/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/builder.nim b/waku/rest_api/endpoint/builder.nim index 9b4ecf6620..56876db3ae 100644 --- a/waku/rest_api/endpoint/builder.nim +++ b/waku/rest_api/endpoint/builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import net, tables diff --git a/waku/rest_api/endpoint/debug/handlers.nim b/waku/rest_api/endpoint/debug/handlers.nim index 43b6fbbf17..d033b905d8 100644 --- a/waku/rest_api/endpoint/debug/handlers.nim +++ b/waku/rest_api/endpoint/debug/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import chronicles, json_serialization, presto/route diff --git a/waku/rest_api/endpoint/filter/handlers.nim b/waku/rest_api/endpoint/filter/handlers.nim index 61d7eb96fc..c5c2639a6d 100644 --- a/waku/rest_api/endpoint/filter/handlers.nim +++ b/waku/rest_api/endpoint/filter/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/health/handlers.nim b/waku/rest_api/endpoint/health/handlers.nim index 8651332454..a7456a7b3b 100644 --- a/waku/rest_api/endpoint/health/handlers.nim +++ b/waku/rest_api/endpoint/health/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import chronicles, json_serialization, presto/route diff --git a/waku/rest_api/endpoint/health/types.nim b/waku/rest_api/endpoint/health/types.nim index 88fa736a81..c7f9ec60f0 100644 --- a/waku/rest_api/endpoint/health/types.nim +++ b/waku/rest_api/endpoint/health/types.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import results diff --git a/waku/rest_api/endpoint/legacy_lightpush/handlers.nim b/waku/rest_api/endpoint/legacy_lightpush/handlers.nim index 7a3c5b1ed1..cb953ff494 100644 --- a/waku/rest_api/endpoint/legacy_lightpush/handlers.nim +++ b/waku/rest_api/endpoint/legacy_lightpush/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/lightpush/handlers.nim b/waku/rest_api/endpoint/lightpush/handlers.nim index 342053e72b..e5b657f722 100644 --- a/waku/rest_api/endpoint/lightpush/handlers.nim +++ b/waku/rest_api/endpoint/lightpush/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/origin_handler.nim b/waku/rest_api/endpoint/origin_handler.nim index 9752bfb569..0edf7ec9a4 100644 --- a/waku/rest_api/endpoint/origin_handler.nim +++ b/waku/rest_api/endpoint/origin_handler.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/relay/handlers.nim b/waku/rest_api/endpoint/relay/handlers.nim index 4a1415361d..a65373a757 100644 --- a/waku/rest_api/endpoint/relay/handlers.nim +++ b/waku/rest_api/endpoint/relay/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/rest_serdes.nim b/waku/rest_api/endpoint/rest_serdes.nim index 8dcb7c8f11..be7de9df0f 100644 --- a/waku/rest_api/endpoint/rest_serdes.nim +++ b/waku/rest_api/endpoint/rest_serdes.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/store/handlers.nim b/waku/rest_api/endpoint/store/handlers.nim index 7d37191fb0..183dd24933 100644 --- a/waku/rest_api/endpoint/store/handlers.nim +++ b/waku/rest_api/endpoint/store/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/endpoint/store/types.nim b/waku/rest_api/endpoint/store/types.nim index 99818b5ff4..e097ff2df6 100644 --- a/waku/rest_api/endpoint/store/types.nim +++ b/waku/rest_api/endpoint/store/types.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/rest_api/handlers.nim b/waku/rest_api/handlers.nim index 4fc922f361..ed4018a322 100644 --- a/waku/rest_api/handlers.nim +++ b/waku/rest_api/handlers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import chronos, std/[options, sequtils], results diff --git a/waku/utils/noise.nim b/waku/utils/noise.nim index c225ad9bfe..e04fc8dba8 100644 --- a/waku/utils/noise.nim +++ b/waku/utils/noise.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import results diff --git a/waku/utils/requests.nim b/waku/utils/requests.nim index d9afd2887a..a7fd9a2a95 100644 --- a/waku/utils/requests.nim +++ b/waku/utils/requests.nim @@ -2,9 +2,9 @@ {.push raises: [].} -import bearssl/rand, stew/byteutils +import libp2p/crypto/crypto, stew/byteutils -proc generateRequestId*(rng: ref HmacDrbgContext): string = +proc generateRequestId*(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return byteutils.toHex(bytes) diff --git a/waku/waku_archive/archive.nim b/waku/waku_archive/archive.nim index 976d7d035d..e29913b04d 100644 --- a/waku/waku_archive/archive.nim +++ b/waku/waku_archive/archive.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_archive/driver/builder.nim b/waku/waku_archive/driver/builder.nim index 811b169995..b2bb410a09 100644 --- a/waku/waku_archive/driver/builder.nim +++ b/waku/waku_archive/driver/builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import results, chronicles, chronos diff --git a/waku/waku_archive/driver/postgres_driver/migrations.nim b/waku/waku_archive/driver/postgres_driver/migrations.nim index 700f2a1622..2e0f3519b7 100644 --- a/waku/waku_archive/driver/postgres_driver/migrations.nim +++ b/waku/waku_archive/driver/postgres_driver/migrations.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/strutils, results, chronicles, chronos diff --git a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim index 82c8ec2aef..6d2e471a17 100644 --- a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim +++ b/waku/waku_archive/driver/postgres_driver/postgres_driver.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_archive/driver/queue_driver/queue_driver.nim b/waku/waku_archive/driver/queue_driver/queue_driver.nim index 2ffc9ab006..6ab5ff104d 100644 --- a/waku/waku_archive/driver/queue_driver/queue_driver.nim +++ b/waku/waku_archive/driver/queue_driver/queue_driver.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/options, results, stew/sorted_set, chronicles, chronos diff --git a/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim b/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim index ff7b0e7d36..8a1d775ffa 100644 --- a/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim +++ b/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor # The code in this file is an adaptation of the Sqlite KV Store found in nim-eth. # https://github.com/status-im/nim-eth/blob/master/eth/db/kvstore_sqlite3.nim {.push raises: [].} diff --git a/waku/waku_archive/retention_policy/builder.nim b/waku/waku_archive/retention_policy/builder.nim index 7e777f4a06..d274e01d95 100644 --- a/waku/waku_archive/retention_policy/builder.nim +++ b/waku/waku_archive/retention_policy/builder.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/[strutils, options], regex, results diff --git a/waku/waku_archive/retention_policy/retention_policy_capacity.nim b/waku/waku_archive/retention_policy/retention_policy_capacity.nim index ff4da6861c..94502014e4 100644 --- a/waku/waku_archive/retention_policy/retention_policy_capacity.nim +++ b/waku/waku_archive/retention_policy/retention_policy_capacity.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import results, chronicles, chronos diff --git a/waku/waku_core/peers.nim b/waku/waku_core/peers.nim index c4b8b593ea..d2db1b6c49 100644 --- a/waku/waku_core/peers.nim +++ b/waku/waku_core/peers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_core/topics/content_topic.nim b/waku/waku_core/topics/content_topic.nim index 3eeb357711..7e1942f250 100644 --- a/waku/waku_core/topics/content_topic.nim +++ b/waku/waku_core/topics/content_topic.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Waku content topics definition and namespacing utils ## ## See 23/WAKU2-TOPICS RFC: https://rfc.vac.dev/spec/23/ diff --git a/waku/waku_core/topics/sharding.nim b/waku/waku_core/topics/sharding.nim index 1cb5b37b3c..a34e56fbf8 100644 --- a/waku/waku_core/topics/sharding.nim +++ b/waku/waku_core/topics/sharding.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Waku autosharding utils ## ## See 51/WAKU2-RELAY-SHARDING RFC: https://rfc.vac.dev/spec/51/#automatic-sharding diff --git a/waku/waku_enr/capabilities.nim b/waku/waku_enr/capabilities.nim index 26899fbb41..901b4d8f3a 100644 --- a/waku/waku_enr/capabilities.nim +++ b/waku/waku_enr/capabilities.nim @@ -1,9 +1,10 @@ +import waku/compat/option_valueor {.push raises: [].} import std/[options, bitops, sequtils, net, tables], results, eth/keys, libp2p/crypto/crypto import ../common/enr, ../waku_core/codecs -import libp2p/protocols/mix +import libp2p_mix const CapabilitiesEnrField* = "waku2" diff --git a/waku/waku_enr/multiaddr.nim b/waku/waku_enr/multiaddr.nim index 4d6e9baa78..0e1e8e390b 100644 --- a/waku/waku_enr/multiaddr.nim +++ b/waku/waku_enr/multiaddr.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_enr/sharding.nim b/waku/waku_enr/sharding.nim index 2aeb96a9da..a48571cc47 100644 --- a/waku/waku_enr/sharding.nim +++ b/waku/waku_enr/sharding.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_filter_v2/client.nim b/waku/waku_filter_v2/client.nim index 7798f41b7e..b4c873d263 100644 --- a/waku/waku_filter_v2/client.nim +++ b/waku/waku_filter_v2/client.nim @@ -1,3 +1,5 @@ +import waku/compat/option_valueor +import libp2p/crypto/crypto ## Waku Filter client for subscribing and receiving filtered messages {.push raises: [].} @@ -23,13 +25,13 @@ logScope: type WakuFilterClient* = ref object of LPProtocol brokerCtx: BrokerContext - rng: ref HmacDrbgContext + rng: crypto.Rng peerManager: PeerManager pushHandlers: seq[FilterPushHandler] -func generateRequestId(rng: ref HmacDrbgContext): string = +func generateRequestId(rng: crypto.Rng): string = var bytes: array[10, byte] - hmacDrbgGenerate(rng[], bytes) + rng.generate(bytes) return byteutils.toHex(bytes) proc sendSubscribeRequest( @@ -211,7 +213,7 @@ proc initProtocolHandler(wfc: WakuFilterClient) = wfc.codec = WakuFilterPushCodec proc new*( - T: type WakuFilterClient, peerManager: PeerManager, rng: ref HmacDrbgContext + T: type WakuFilterClient, peerManager: PeerManager, rng: crypto.Rng ): T = let brokerCtx = globalBrokerContext() let wfc = WakuFilterClient( diff --git a/waku/waku_filter_v2/protocol.nim b/waku/waku_filter_v2/protocol.nim index 35620b6cda..b24e9e0c7e 100644 --- a/waku/waku_filter_v2/protocol.nim +++ b/waku/waku_filter_v2/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Waku Filter protocol for subscribing and filtering messages {.push raises: [].} diff --git a/waku/waku_filter_v2/subscriptions.nim b/waku/waku_filter_v2/subscriptions.nim index 0e66899d01..687756572e 100644 --- a/waku/waku_filter_v2/subscriptions.nim +++ b/waku/waku_filter_v2/subscriptions.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_keystore/keystore.nim b/waku/waku_keystore/keystore.nim index 158f1a98ea..e33ac78ed0 100644 --- a/waku/waku_keystore/keystore.nim +++ b/waku/waku_keystore/keystore.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import options, json, strutils, sequtils, std/[tables, os] diff --git a/waku/waku_lightpush/callbacks.nim b/waku/waku_lightpush/callbacks.nim index ac2e562b61..fe3c8378fb 100644 --- a/waku/waku_lightpush/callbacks.nim +++ b/waku/waku_lightpush/callbacks.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import results diff --git a/waku/waku_lightpush/client.nim b/waku/waku_lightpush/client.nim index fd12c49d20..a3e25cb9d4 100644 --- a/waku/waku_lightpush/client.nim +++ b/waku/waku_lightpush/client.nim @@ -1,3 +1,5 @@ +import libp2p/crypto/crypto +import waku/compat/option_valueor {.push raises: [].} import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils @@ -16,11 +18,11 @@ logScope: topics = "waku lightpush client" type WakuLightPushClient* = ref object - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng peerManager*: PeerManager proc new*( - T: type WakuLightPushClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext + T: type WakuLightPushClient, peerManager: PeerManager, rng: crypto.Rng ): T = WakuLightPushClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_lightpush/protocol.nim b/waku/waku_lightpush/protocol.nim index 8336f4dfc2..dd4970fdc6 100644 --- a/waku/waku_lightpush/protocol.nim +++ b/waku/waku_lightpush/protocol.nim @@ -1,3 +1,5 @@ +import libp2p/crypto/crypto +import waku/compat/option_valueor {.push raises: [].} import @@ -22,7 +24,7 @@ logScope: topics = "waku lightpush" type WakuLightPush* = ref object of LPProtocol - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng peerManager*: PeerManager pushHandler*: PushMessageHandler requestRateLimiter*: RequestRateLimiter @@ -156,7 +158,7 @@ proc initProtocolHandler(wl: WakuLightPush) = proc new*( T: type WakuLightPush, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, pushHandler: PushMessageHandler, autoSharding: Option[Sharding], rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), diff --git a/waku/waku_lightpush_legacy/client.nim b/waku/waku_lightpush_legacy/client.nim index ab489bec90..a566ac87cc 100644 --- a/waku/waku_lightpush_legacy/client.nim +++ b/waku/waku_lightpush_legacy/client.nim @@ -1,3 +1,5 @@ +import libp2p/crypto/crypto +import waku/compat/option_valueor {.push raises: [].} import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils @@ -17,12 +19,12 @@ logScope: type WakuLegacyLightPushClient* = ref object peerManager*: PeerManager - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng proc new*( T: type WakuLegacyLightPushClient, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, ): T = WakuLegacyLightPushClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_lightpush_legacy/protocol.nim b/waku/waku_lightpush_legacy/protocol.nim index f5ed601349..b3d728f9c6 100644 --- a/waku/waku_lightpush_legacy/protocol.nim +++ b/waku/waku_lightpush_legacy/protocol.nim @@ -1,3 +1,4 @@ +import libp2p/crypto/crypto {.push raises: [].} import std/options, results, stew/byteutils, chronicles, chronos, metrics, bearssl/rand @@ -14,7 +15,7 @@ logScope: topics = "waku lightpush legacy" type WakuLegacyLightPush* = ref object of LPProtocol - rng*: ref rand.HmacDrbgContext + rng*: crypto.Rng peerManager*: PeerManager pushHandler*: PushMessageHandler requestRateLimiter*: RequestRateLimiter @@ -116,7 +117,7 @@ proc initProtocolHandler(wl: WakuLegacyLightPush) = proc new*( T: type WakuLegacyLightPush, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, pushHandler: PushMessageHandler, rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), ): T = diff --git a/waku/waku_metadata/protocol.nim b/waku/waku_metadata/protocol.nim index 7c72a69347..30f77bd736 100644 --- a/waku/waku_metadata/protocol.nim +++ b/waku/waku_metadata/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_mix/protocol.nim b/waku/waku_mix/protocol.nim index ac8b69eaf1..b458a5ecfc 100644 --- a/waku/waku_mix/protocol.nim +++ b/waku/waku_mix/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import chronicles, std/options, chronos, results, metrics @@ -5,11 +6,11 @@ import chronicles, std/options, chronos, results, metrics import libp2p/crypto/curve25519, libp2p/crypto/crypto, - libp2p/protocols/mix, - libp2p/protocols/mix/mix_node, - libp2p/protocols/mix/mix_protocol, - libp2p/protocols/mix/mix_metrics, - libp2p/protocols/mix/delay_strategy, + libp2p_mix, + libp2p_mix/mix_node, + libp2p_mix/mix_protocol, + libp2p_mix/mix_metrics, + libp2p_mix/delay_strategy, libp2p/[multiaddress, peerid], eth/common/keys @@ -91,8 +92,9 @@ proc new*( procCall MixProtocol(m).init( localMixNodeInfo, peermgr.switch, - delayStrategy = - ExponentialDelayStrategy.new(meanDelayMs = 50, rng = crypto.newRng()), + delayStrategy = Opt.some( + DelayStrategy(ExponentialDelayStrategy.new(meanDelay = 50'u16, rng = crypto.newRng())) + ), ) processBootNodes(bootnodes, peermgr, m) diff --git a/waku/waku_noise/noise.nim b/waku/waku_noise/noise.nim index 9c5dd76e73..23c3de2a33 100644 --- a/waku/waku_noise/noise.nim +++ b/waku/waku_noise/noise.nim @@ -8,6 +8,8 @@ {.push raises: [].} +import libp2p/crypto/rng +import libp2p/crypto/crypto import std/[options, strutils] import stew/byteutils import chronos @@ -168,9 +170,9 @@ proc setCipherStateKey*(cs: var CipherState, key: ChaChaPolyKey) = cs.k = key # Generates a random Symmetric Cipher State for test purposes -proc randomCipherState*(rng: var HmacDrbgContext, nonce: uint64 = 0): CipherState = +proc randomCipherState*(rng: Rng, nonce: uint64 = 0): CipherState = var randomCipherState: CipherState - hmacDrbgGenerate(rng, randomCipherState.k) + hmacDrbgGenerate(rng.bearSslDrbg, randomCipherState.k) setNonce(randomCipherState, nonce) return randomCipherState diff --git a/waku/waku_noise/noise_handshake_processing.nim b/waku/waku_noise/noise_handshake_processing.nim index 8b84bf9588..e366668ad1 100644 --- a/waku/waku_noise/noise_handshake_processing.nim +++ b/waku/waku_noise/noise_handshake_processing.nim @@ -4,6 +4,7 @@ {.push raises: [].} +import libp2p/crypto/rng import std/[options, strutils, tables] import chronos import chronicles @@ -237,7 +238,7 @@ proc processMessagePatternPayload( # We process an input handshake message according to current handshake state and we return the next handshake step's handshake message proc processMessagePatternTokens( - rng: var rand.HmacDrbgContext, + rng: Rng, hs: var HandshakeState, inputHandshakeMessage: seq[NoisePublicKey] = @[], ): Result[seq[NoisePublicKey], cstring] {. @@ -480,7 +481,7 @@ proc initialize*( # If the user is writing the handshake message, the transport message (if not empty) and eventually a non-empty message nametag has to be passed to transportMessage and messageNametag and readPayloadV2 can be left to its default value # It the user is reading the handshake message, the read payload v2 has to be passed to readPayloadV2 and the transportMessage can be left to its default values. Decryption is skipped if the payloadv2 read doesn't have a message nametag equal to messageNametag (empty input nametags are converted to all-0 MessageNametagLength bytes arrays) proc stepHandshake*( - rng: var rand.HmacDrbgContext, + rng: Rng, hs: var HandshakeState, readPayloadV2: PayloadV2 = default(PayloadV2), transportMessage: seq[byte] = @[], diff --git a/waku/waku_noise/noise_utils.nim b/waku/waku_noise/noise_utils.nim index 177dc6557a..ea4cdb7c18 100644 --- a/waku/waku_noise/noise_utils.nim +++ b/waku/waku_noise/noise_utils.nim @@ -5,6 +5,7 @@ {.push raises: [].} +import libp2p/crypto/rng import std/[algorithm, base64, oids, options, strutils, tables, sequtils] import chronos import chronicles @@ -28,9 +29,9 @@ logScope: ################################# # Generates random byte sequences of given size -proc randomSeqByte*(rng: var HmacDrbgContext, size: int): seq[byte] = +proc randomSeqByte*(rng: Rng, size: int): seq[byte] = var output = newSeq[byte](size.uint32) - hmacDrbgGenerate(rng, output) + hmacDrbgGenerate(rng.bearSslDrbg, output) return output # Pads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3 @@ -149,7 +150,7 @@ proc isDefault*[T](value: T): bool = ################################# # Generate random (public, private) Elliptic Curve key pairs -proc genKeyPair*(rng: var HmacDrbgContext): KeyPair = +proc genKeyPair*(rng: Rng): KeyPair = var keyPair: KeyPair keyPair.privateKey = EllipticCurveKey.random(rng) keyPair.publicKey = keyPair.privateKey.public() @@ -319,18 +320,18 @@ proc dh*(private: EllipticCurveKey, public: EllipticCurveKey): EllipticCurveKey ################################# # Generates a random ChaChaPolyKey for testing encryption/decryption -proc randomChaChaPolyKey*(rng: var HmacDrbgContext): ChaChaPolyKey = +proc randomChaChaPolyKey*(rng: Rng): ChaChaPolyKey = var key: ChaChaPolyKey - hmacDrbgGenerate(rng, key) + hmacDrbgGenerate(rng.bearSslDrbg, key) return key # Generates a random ChaChaPoly Cipher State for testing encryption/decryption -proc randomChaChaPolyCipherState*(rng: var HmacDrbgContext): ChaChaPolyCipherState = +proc randomChaChaPolyCipherState*(rng: Rng): ChaChaPolyCipherState = var randomCipherState: ChaChaPolyCipherState randomCipherState.k = randomChaChaPolyKey(rng) - hmacDrbgGenerate(rng, randomCipherState.nonce) + hmacDrbgGenerate(rng.bearSslDrbg, randomCipherState.nonce) randomCipherState.ad = newSeq[byte](32) - hmacDrbgGenerate(rng, randomCipherState.ad) + hmacDrbgGenerate(rng.bearSslDrbg, randomCipherState.ad) return randomCipherState ################################################################# @@ -351,7 +352,7 @@ proc toNoisePublicKey*(publicKey: EllipticCurveKey): NoisePublicKey = return noisePublicKey # Generates a random Noise public key -proc genNoisePublicKey*(rng: var HmacDrbgContext): NoisePublicKey = +proc genNoisePublicKey*(rng: Rng): NoisePublicKey = var noisePublicKey: NoisePublicKey # We generate a random key pair let keyPair: KeyPair = genKeyPair(rng) @@ -446,7 +447,7 @@ proc `==`*(p1, p2: PayloadV2): bool = (p1.transportMessage == p2.transportMessage) # Generates a random PayloadV2 -proc randomPayloadV2*(rng: var HmacDrbgContext): PayloadV2 = +proc randomPayloadV2*(rng: Rng): PayloadV2 = var payload2: PayloadV2 # We set a random messageNametag let randMessageNametag = randomSeqByte(rng, MessageNametagLength) diff --git a/waku/waku_peer_exchange/client.nim b/waku/waku_peer_exchange/client.nim index 15426c4646..b1940b424b 100644 --- a/waku/waku_peer_exchange/client.nim +++ b/waku/waku_peer_exchange/client.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/options, results, chronicles, chronos, metrics import ./common, ./rpc, ./rpc_codec, ../node/peer_manager diff --git a/waku/waku_peer_exchange/protocol.nim b/waku/waku_peer_exchange/protocol.nim index b99f5eabf1..fd7896e83f 100644 --- a/waku/waku_peer_exchange/protocol.nim +++ b/waku/waku_peer_exchange/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import std/[options, sequtils, random], results, diff --git a/waku/waku_relay/protocol.nim b/waku/waku_relay/protocol.nim index d0b1ddb48b..8c59bf2502 100644 --- a/waku/waku_relay/protocol.nim +++ b/waku/waku_relay/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Waku Relay module. Thin layer on top of GossipSub. ## ## See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-relay.md @@ -366,6 +367,7 @@ proc new*( triggerSelf = true, msgIdProvider = defaultMessageIdProvider, maxMessageSize = maxMessageSize, + rng = switch.rng, parameters = GossipsubParameters, ) w.brokerCtx = globalBrokerContext() diff --git a/waku/waku_rendezvous/client.nim b/waku/waku_rendezvous/client.nim index 09e7897741..15561c944c 100644 --- a/waku/waku_rendezvous/client.nim +++ b/waku/waku_rendezvous/client.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -7,8 +8,7 @@ import chronicles, libp2p/protocols/rendezvous, libp2p/crypto/curve25519, - libp2p/switch, - libp2p/utils/semaphore + libp2p/switch import metrics except collect @@ -107,10 +107,12 @@ proc new*( switch: switch, rng: rng, sema: newAsyncSemaphore(MaxSimultanesousAdvertisements), - minDuration: rendezvous.MinimumAcceptedDuration, - maxDuration: rendezvous.MaximumDuration, - minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, - maxTTL: rendezvous.MaximumDuration.seconds.uint64, + config: RendezVousConfig( + minDuration: rendezvous.MinimumAcceptedDuration, + maxDuration: rendezvous.MaximumDuration, + minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, + maxTTL: rendezvous.MaximumDuration.seconds.uint64, + ), peers: @[], # Will be populated from selectPeer calls cookiesSaved: initTable[PeerId, Table[string, seq[byte]]](), peerRecordValidator: checkWakuPeerRecord, diff --git a/waku/waku_rendezvous/common.nim b/waku/waku_rendezvous/common.nim index 18c633efb0..e78efc0251 100644 --- a/waku/waku_rendezvous/common.nim +++ b/waku/waku_rendezvous/common.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import std/options, chronos diff --git a/waku/waku_rendezvous/protocol.nim b/waku/waku_rendezvous/protocol.nim index 89433f533b..b848ab1673 100644 --- a/waku/waku_rendezvous/protocol.nim +++ b/waku/waku_rendezvous/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import @@ -8,7 +9,6 @@ import stew/byteutils, libp2p/protocols/rendezvous, libp2p/protocols/rendezvous/protobuf, - libp2p/utils/semaphore, libp2p/utils/offsettedseq, libp2p/crypto/curve25519, libp2p/switch, @@ -51,7 +51,7 @@ proc advertise*( self: WakuRendezVous, namespace: string, peers: seq[PeerId], - ttl: timer.Duration = self.minDuration, + ttl: timer.Duration = self.config.minDuration, ): Future[Result[void, string]] {.async: (raises: []).} = trace "advertising via waku rendezvous", namespace = namespace, ttl = ttl, peers = $peers, peerRecord = $self.getPeerRecord() @@ -154,14 +154,16 @@ proc new*( let rng = newRng() let wrv = T( rng: rng, - salt: string.fromBytes(generateBytes(rng[], 8)), + salt: string.fromBytes(generateBytes(rng, 8)), registered: initOffsettedSeq[RegisteredData](), expiredDT: Moment.now() - 1.days, sema: newAsyncSemaphore(SemaphoreDefaultSize), - minDuration: rendezvous.MinimumAcceptedDuration, - maxDuration: rendezvous.MaximumDuration, - minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, - maxTTL: rendezvous.MaximumDuration.seconds.uint64, + config: RendezVousConfig( + minDuration: rendezvous.MinimumAcceptedDuration, + maxDuration: rendezvous.MaximumDuration, + minTTL: rendezvous.MinimumAcceptedDuration.seconds.uint64, + maxTTL: rendezvous.MaximumDuration.seconds.uint64, + ), peerRecordValidator: checkWakuPeerRecord, ) 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 02317a056f..e9a9db519b 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 @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_rln_relay/rln/rln_interface.nim b/waku/waku_rln_relay/rln/rln_interface.nim index 612d1a2cc5..e735ab0f3f 100644 --- a/waku/waku_rln_relay/rln/rln_interface.nim +++ b/waku/waku_rln_relay/rln/rln_interface.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Nim wrappers for librln (zerokit v2.0.2, safer-ffi typed handles). ## ## Built against the `stateless` zerokit feature: tree-mutation FFI is not diff --git a/waku/waku_rln_relay/rln/wrappers.nim b/waku/waku_rln_relay/rln/wrappers.nim index 4fc8c15425..42f10d53e8 100644 --- a/waku/waku_rln_relay/rln/wrappers.nim +++ b/waku/waku_rln_relay/rln/wrappers.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor import chronicles, eth/keys, stew/[arrayops, endians2], stint, results import ./rln_interface, ../conversion_utils, ../protocol_types, ../protocol_metrics diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index 7c36300b2c..48be77521d 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_store/client.nim b/waku/waku_store/client.nim index b496628114..22c5212350 100644 --- a/waku/waku_store/client.nim +++ b/waku/waku_store/client.nim @@ -1,3 +1,5 @@ +import libp2p/crypto/crypto +import waku/compat/option_valueor {.push raises: [].} import @@ -20,11 +22,11 @@ const MaxQueryRetries = 5 # Maximum number of store peers to try before giving u type WakuStoreClient* = ref object peerManager: PeerManager - rng: ref rand.HmacDrbgContext + rng: crypto.Rng storeMsgMetricsPerShard*: Table[string, float64] proc new*( - T: type WakuStoreClient, peerManager: PeerManager, rng: ref rand.HmacDrbgContext + T: type WakuStoreClient, peerManager: PeerManager, rng: crypto.Rng ): T {.gcsafe.} = WakuStoreClient(peerManager: peerManager, rng: rng) diff --git a/waku/waku_store/protocol.nim b/waku/waku_store/protocol.nim index 17b7fb2143..535a5fe9c2 100644 --- a/waku/waku_store/protocol.nim +++ b/waku/waku_store/protocol.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## Waku Store protocol for historical messaging support. ## See spec for more details: ## https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-store.md @@ -30,7 +31,7 @@ type StoreQueryRequestHandler* = type WakuStore* = ref object of LPProtocol peerManager: PeerManager - rng: ref rand.HmacDrbgContext + rng: crypto.Rng requestHandler*: StoreQueryRequestHandler requestRateLimiter*: RequestRateLimiter @@ -156,7 +157,7 @@ proc initProtocolHandler(self: WakuStore) = proc new*( T: type WakuStore, peerManager: PeerManager, - rng: ref rand.HmacDrbgContext, + rng: crypto.Rng, requestHandler: StoreQueryRequestHandler, rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](), ): T = diff --git a/waku/waku_store/resume.nim b/waku/waku_store/resume.nim index b7864da94a..cddd9a7fb9 100644 --- a/waku/waku_store/resume.nim +++ b/waku/waku_store/resume.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_store/self_req_handler.nim b/waku/waku_store/self_req_handler.nim index 315961307d..c4358f3225 100644 --- a/waku/waku_store/self_req_handler.nim +++ b/waku/waku_store/self_req_handler.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor ## ## This file is aimed to attend the requests that come directly ## from the 'self' node. It is expected to attend the store requests that diff --git a/waku/waku_store_sync/reconciliation.nim b/waku/waku_store_sync/reconciliation.nim index b18251fff8..bcf93f0582 100644 --- a/waku/waku_store_sync/reconciliation.nim +++ b/waku/waku_store_sync/reconciliation.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import diff --git a/waku/waku_store_sync/transfer.nim b/waku/waku_store_sync/transfer.nim index 5d20afb186..3f819bd09a 100644 --- a/waku/waku_store_sync/transfer.nim +++ b/waku/waku_store_sync/transfer.nim @@ -1,3 +1,4 @@ +import waku/compat/option_valueor {.push raises: [].} import From 3dfc86262b24f614ae0f979aac7f9529abdb6e03 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 3 Jun 2026 12:55:40 -0300 Subject: [PATCH 02/10] Get nim-libp2p 2.0.0 bump to E2E working state (WIP) * deps: json_rpc + web3 via websock-relaxed forks (WIP: revert on upstream fix) * fix: setup() post-build switch services (autonat nil segfault) * fix: unified 2.0.0 connection limits * test: 2.0.0 defaults (identify-push, agent string) * test: drop reboot/reconnect (unsupported Switch restart) --- nimble.lock | 14 ++-- tests/node/test_wakunode_peer_manager.nim | 13 +++- tests/test_wakunode.nim | 4 +- tests/waku_relay/test_protocol.nim | 95 ----------------------- waku.nimble | 8 +- waku/factory/waku.nim | 11 +++ waku/node/waku_switch.nim | 11 ++- 7 files changed, 44 insertions(+), 112 deletions(-) diff --git a/nimble.lock b/nimble.lock index d246ebe840..fe702cc651 100644 --- a/nimble.lock +++ b/nimble.lock @@ -454,9 +454,9 @@ } }, "json_rpc": { - "version": "#43bbf499143eb45046c83ac9794c9e3280a2b8e7", - "vcsRevision": "43bbf499143eb45046c83ac9794c9e3280a2b8e7", - "url": "https://github.com/status-im/nim-json-rpc.git", + "version": "0.6.1", + "vcsRevision": "8ce09c2ccc08b23f433a054b2b1ccb022d9547dc", + "url": "https://github.com/fcecin/nim-json-rpc-websock040", "downloadMethod": "git", "dependencies": [ "nim", @@ -472,7 +472,7 @@ "unittest2" ], "checksums": { - "sha1": "30ff6ead115b88c79862c5c7e37b1c9852eea59f" + "sha1": "596db0aafcb3c83f5dba6d42993f2276e0d00eb5" } }, "lsquic": { @@ -538,8 +538,8 @@ }, "web3": { "version": "0.8.0", - "vcsRevision": "cdfe5601d2812a58e54faf53ee634452d01e5918", - "url": "https://github.com/status-im/nim-web3", + "vcsRevision": "96f39ea1b633277c1d93eafd62759db1d498e359", + "url": "https://github.com/fcecin/nim-web3-websock040", "downloadMethod": "git", "dependencies": [ "nim", @@ -557,7 +557,7 @@ "results" ], "checksums": { - "sha1": "26a112af032ef1536f97da2ca7364af618a11b80" + "sha1": "b5972104bc9223a34ae3758293225264822af893" } }, "dnsdisc": { diff --git a/tests/node/test_wakunode_peer_manager.nim b/tests/node/test_wakunode_peer_manager.nim index ed58db7fe6..6710c0fc9a 100644 --- a/tests/node/test_wakunode_peer_manager.nim +++ b/tests/node/test_wakunode_peer_manager.nim @@ -28,8 +28,13 @@ import ../waku_discv5/utils, ./peer_manager/peer_store/utils +# nim-libp2p 2.0.0 enables the IdentifyPush protocol by default, so every node +# now also advertises "/ipfs/id/push/1.0.0" (prepended to the identify list). const DEFAULT_PROTOCOLS: seq[string] = - @["/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", "/libp2p/circuit/relay/0.2.0/hop"] + @[ + "/ipfs/id/push/1.0.0", "/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", + "/libp2p/circuit/relay/0.2.0/hop", + ] let listenIp = parseIpAddress("0.0.0.0") @@ -376,7 +381,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned serverRemotePeerInfo.agent, - "nim-libp2p/0.0.1", + "nim-libp2p", ) chainedComparison( clientPeerStore[ProtoVersionBook][serverPeerId], # FIXME: Not assigned @@ -442,7 +447,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned serverRemotePeerInfo.agent, - "nim-libp2p/0.0.1", + "nim-libp2p", ) chainedComparison( clientPeerStore[ProtoVersionBook][serverPeerId], # FIXME: Not assigned @@ -493,7 +498,7 @@ suite "Peer Manager": chainedComparison( clientPeerStore[AgentBook][server2PeerId], # FIXME: Not assigned server2RemotePeerInfo.agent, - "nim-libp2p/0.0.1", + "nim-libp2p", ) chainedComparison( clientPeerStore[ProtoVersionBook][server2PeerId], # FIXME: Not assigned diff --git a/tests/test_wakunode.nim b/tests/test_wakunode.nim index 081ad02e1d..2fea352054 100644 --- a/tests/test_wakunode.nim +++ b/tests/test_wakunode.nim @@ -292,8 +292,8 @@ suite "WakuNode": # custom agent string expectedAgentString1 = "node1-agent-string" - # bump when updating nim-libp2p - expectedAgentString2 = "nim-libp2p/0.0.1" + # bump when updating nim-libp2p (2.0.0 default AgentVersion is "nim-libp2p") + expectedAgentString2 = "nim-libp2p" let # node with custom agent string nodeKey1 = generateSecp256k1Key() diff --git a/tests/waku_relay/test_protocol.nim b/tests/waku_relay/test_protocol.nim index 46032b6938..09104e100d 100644 --- a/tests/waku_relay/test_protocol.nim +++ b/tests/waku_relay/test_protocol.nim @@ -1214,101 +1214,6 @@ suite "Waku Relay": await allFutures(otherSwitch.stop(), otherNode.stop()) suite "Security and Privacy": - asyncTest "Relay can receive messages after reboot and reconnect": - # Given a second node connected to the first one - let - otherSwitch = newTestSwitch() - otherPeerManager = PeerManager.new(otherSwitch) - otherNode = await newTestWakuRelay(otherSwitch) - - await otherSwitch.start() - let - otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo() - otherPeerId = otherRemotePeerInfo.peerId - - check await peerManager.connectPeer(otherRemotePeerInfo) - - # Given both are subscribed to the same pubsub topic - var otherHandlerFuture = newPushHandlerFuture() - proc otherSimpleFutureHandler( - topic: PubsubTopic, message: WakuMessage - ) {.async, gcsafe.} = - otherHandlerFuture.complete((topic, message)) - - otherNode.subscribe(pubsubTopic, otherSimpleFutureHandler) - node.subscribe(pubsubTopic, simpleFutureHandler) - check: - node.subscribedTopics == pubsubTopicSeq - otherNode.subscribedTopics == pubsubTopicSeq - await sleepAsync(500.millis) - - # Given other node is stopped and restarted - await otherSwitch.stop() - await otherSwitch.start() - - check await peerManager.connectPeer(otherRemotePeerInfo) - - # FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connectPeer, as below - # check await otherPeerManager.connectPeer(otherRemotePeerInfo) - - # When sending a message from node - let msg1 = fakeWakuMessage(testMessage, pubsubTopic) - discard await node.publish(pubsubTopic, msg1) - - # Then the message is received in both nodes - check: - await handlerFuture.withTimeout(FUTURE_TIMEOUT) - await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT) - (pubsubTopic, msg1) == handlerFuture.read() - (pubsubTopic, msg1) == otherHandlerFuture.read() - - # When sending a message from other node - handlerFuture = newPushHandlerFuture() - otherHandlerFuture = newPushHandlerFuture() - let msg2 = fakeWakuMessage(testMessage, pubsubTopic) - discard await otherNode.publish(pubsubTopic, msg2) - - # Then the message is received in both nodes - check: - await handlerFuture.withTimeout(FUTURE_TIMEOUT) - await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT) - (pubsubTopic, msg2) == handlerFuture.read() - (pubsubTopic, msg2) == otherHandlerFuture.read() - - # Given node is stopped and restarted - await switch.stop() - await switch.start() - check await peerManager.connectPeer(otherRemotePeerInfo) - - # When sending a message from node - handlerFuture = newPushHandlerFuture() - otherHandlerFuture = newPushHandlerFuture() - let msg3 = fakeWakuMessage(testMessage, pubsubTopic) - discard await node.publish(pubsubTopic, msg3) - - # Then the message is received in both nodes - check: - await handlerFuture.withTimeout(FUTURE_TIMEOUT) - await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT) - (pubsubTopic, msg3) == handlerFuture.read() - (pubsubTopic, msg3) == otherHandlerFuture.read() - - # When sending a message from other node - handlerFuture = newPushHandlerFuture() - otherHandlerFuture = newPushHandlerFuture() - let msg4 = fakeWakuMessage(testMessage, pubsubTopic) - discard await otherNode.publish(pubsubTopic, msg4) - - # Then the message is received in both nodes - check: - await handlerFuture.withTimeout(FUTURE_TIMEOUT) - await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT) - (pubsubTopic, msg4) == handlerFuture.read() - (pubsubTopic, msg4) == otherHandlerFuture.read() - - # Finally stop the other node - await allFutures(otherSwitch.stop(), otherNode.stop()) - asyncTest "Relay can't receive messages after subscribing and stopping without unsubscribing": # Given a second node connected to the first one let diff --git a/waku.nimble b/waku.nimble index 3c50ce54cb..949c079795 100644 --- a/waku.nimble +++ b/waku.nimble @@ -39,9 +39,13 @@ requires "nim >= 2.2.4", "secp256k1", "bearssl", # RPC & APIs - "https://github.com/status-im/nim-json-rpc.git#43bbf499143eb45046c83ac9794c9e3280a2b8e7", + # DRAFT: json_rpc + web3 repointed to fcecin forks for the libp2p 2.0.0 bump. + # json_rpc fork relaxes the websock cap (<0.4.0 -> <0.5.0); web3 fork repoints + # its own json_rpc require to the same fork so the SAT graph unifies. Revert to + # status-im json_rpc + bare "web3" once the cap fix lands upstream. + "https://github.com/fcecin/nim-json-rpc-websock040#8ce09c2ccc08b23f433a054b2b1ccb022d9547dc", "presto", - "web3", + "https://github.com/fcecin/nim-web3-websock040#96f39ea1b633277c1d93eafd62759db1d498e359", # Database "db_connector", "sqlite3_abi", diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 62c33b12a6..effb2cd124 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -111,6 +111,17 @@ proc setupSwitchServices( else: waku.node.switch.services = @[Service(autonatService)] + # libp2p 2.0.0 split Service.setup out of Service.start: the switch runs setup + # only at build time (SwitchBuilder.setupServices), while switch.start calls + # just start. These services are created and attached post-build, so setup must + # be invoked explicitly here -- otherwise AutonatService.addressMapper stays nil + # and the peerInfo.update() inside start dereferences it (SIGSEGV). + for service in waku.node.switch.services: + try: + service.setup(waku.node.switch) + except CatchableError as e: + error "failed to set up libp2p switch service", error = e.msg + ## Initialisation proc newCircuitRelay(isRelayClient: bool): Relay = diff --git a/waku/node/waku_switch.nim b/waku/node/waku_switch.nim index 6e02b8b8bd..31177591e0 100644 --- a/waku/node/waku_switch.nim +++ b/waku/node/waku_switch.nim @@ -81,8 +81,6 @@ proc newWakuSwitch*( var b = SwitchBuilder .new() .withRng(rng) - .withMaxConnections(maxConnections) - .withMaxInOut(maxIn, maxOut) .withMaxConnsPerPeer(maxConnsPerPeer) .withYamux() .withMplex(inTimeout, outTimeout) @@ -93,6 +91,15 @@ proc newWakuSwitch*( .withCircuitRelay(circuitRelay) .withAutonat() + # libp2p 2.0.0 folded withMaxConnections and withMaxInOut into a single + # `limits` field: they are mutually exclusive (last one wins), and + # ConnectionLimits.maxInOut asserts maxIn/maxOut > 0. So apply explicit in/out + # limits only when both are provided (>0); otherwise use the shared total cap. + if maxIn > 0 and maxOut > 0: + b = b.withMaxInOut(maxIn, maxOut) + else: + b = b.withMaxConnections(maxConnections) + if peerStoreCapacity.isSome(): b = b.withPeerStore(peerStoreCapacity.get()) else: From d9592dcbdc0bc1ba4a416d2158da6632d01095a4 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 3 Jun 2026 13:41:45 -0300 Subject: [PATCH 03/10] Bump fixes * add yamux to our newStandardSwitch to match prod behavior * test: rng instantiation cleanup --- tests/common/test_ratelimit_setting.nim | 7 ++++--- tests/common/test_requestratelimiter.nim | 7 ++++--- tests/testlib/wakucore.nim | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/common/test_ratelimit_setting.nim b/tests/common/test_ratelimit_setting.nim index c9385ea574..f41a66b8d9 100644 --- a/tests/common/test_ratelimit_setting.nim +++ b/tests/common/test_ratelimit_setting.nim @@ -18,9 +18,10 @@ import ../../waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" -let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet()) -let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet()) -let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let rng = newRng() +let conn1 = Connection(peerId: PeerId.random(rng).tryGet()) +let conn2 = Connection(peerId: PeerId.random(rng).tryGet()) +let conn3 = Connection(peerId: PeerId.random(rng).tryGet()) suite "RateLimitSetting": test "Parse rate limit setting - ok": diff --git a/tests/common/test_requestratelimiter.nim b/tests/common/test_requestratelimiter.nim index e3801f8534..68e1d36df6 100644 --- a/tests/common/test_requestratelimiter.nim +++ b/tests/common/test_requestratelimiter.nim @@ -18,9 +18,10 @@ import ../../waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" -let conn1 = Connection(peerId: PeerId.random(newRng()).tryGet()) -let conn2 = Connection(peerId: PeerId.random(newRng()).tryGet()) -let conn3 = Connection(peerId: PeerId.random(newRng()).tryGet()) +let rng = newRng() +let conn1 = Connection(peerId: PeerId.random(rng).tryGet()) +let conn2 = Connection(peerId: PeerId.random(rng).tryGet()) +let conn3 = Connection(peerId: PeerId.random(rng).tryGet()) suite "RequestRateLimiter": test "RequestRateLimiter Allow up to main bucket": diff --git a/tests/testlib/wakucore.nim b/tests/testlib/wakucore.nim index c0d59b0fc8..d6a0e4e634 100644 --- a/tests/testlib/wakucore.nim +++ b/tests/testlib/wakucore.nim @@ -37,11 +37,23 @@ proc newStandardSwitch*( privKey = Opt.none(libp2p_keys.PrivateKey), addrs: MultiAddress = MultiAddress.init("/ip4/127.0.0.1/tcp/0").get(), ): Switch = + ## Bare libp2p switch for tests. Replaces nim-libp2p's `newStandardSwitch`, + ## removed in 2.0.0. Mirrors the *substrate* of the production switch + ## (`newWakuSwitch`, waku/node/waku_switch.nim): same transport (TCP only — no + ## QUIC yet, like prod), security (Noise), and muxers (yamux first so it is the + ## one negotiated, then mplex). Tests therefore run on the same kernel peers + ## actually use in prod. NB: the removed libp2p `newStandardSwitch` was + ## mplex-only; mounting yamux here is intentional (match prod's muxer) — do not + ## "restore" it to mplex-only. Deliberately omits the prod services (autonat, circuit + ## relay, name resolver, NAT, signed peer record, connection limits): they add + ## port grief, network delays, and nondeterminism with no value to unit tests. + ## For a full-stack node, use newTestWakuNode / newWakuSwitch instead. var b = SwitchBuilder .new() .withRng(common.rng()) .withAddress(addrs) .withTcpTransport() + .withYamux() .withMplex() .withNoise() if privKey.isSome(): From 5eed0f25ff14fb9c325f7a375de379664ee0fa56 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Thu, 4 Jun 2026 15:24:25 -0300 Subject: [PATCH 04/10] Add -d:libp2p_quic_support to Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index ea1bf66f07..2be21b681f 100644 --- a/Makefile +++ b/Makefile @@ -140,6 +140,9 @@ NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace # enable experimental exit is dest feature in libp2p mix NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest +# enable libp2p's QUIC transport +NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_quic_support + ifeq ($(POSTGRES), 1) NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen endif From b76556e38b5ad3e34d26158fdc5e3520919246f3 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Thu, 4 Jun 2026 17:12:48 -0300 Subject: [PATCH 05/10] Fix CatchableError -> ServiceSetupError (copied from #3931) --- waku/factory/waku.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index effb2cd124..44e685c455 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -119,7 +119,7 @@ proc setupSwitchServices( for service in waku.node.switch.services: try: service.setup(waku.node.switch) - except CatchableError as e: + except ServiceSetupError as e: error "failed to set up libp2p switch service", error = e.msg ## Initialisation From 93d4b3c65fbb8c6d866d679dc8b047c9c148db01 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 10 Jun 2026 09:40:51 -0300 Subject: [PATCH 06/10] remove dep forks --- nimble.lock | 14 +++++++------- waku.nimble | 10 ++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/nimble.lock b/nimble.lock index fe702cc651..b29c76eba0 100644 --- a/nimble.lock +++ b/nimble.lock @@ -454,9 +454,9 @@ } }, "json_rpc": { - "version": "0.6.1", - "vcsRevision": "8ce09c2ccc08b23f433a054b2b1ccb022d9547dc", - "url": "https://github.com/fcecin/nim-json-rpc-websock040", + "version": "0.6.0", + "vcsRevision": "f62ed04d7c630ddd834e296b7e7db2e1aa72a315", + "url": "https://github.com/status-im/nim-json-rpc.git", "downloadMethod": "git", "dependencies": [ "nim", @@ -472,7 +472,7 @@ "unittest2" ], "checksums": { - "sha1": "596db0aafcb3c83f5dba6d42993f2276e0d00eb5" + "sha1": "4221c98dbc09ba56d68ca0a36b5c2ad90e39a43b" } }, "lsquic": { @@ -538,8 +538,8 @@ }, "web3": { "version": "0.8.0", - "vcsRevision": "96f39ea1b633277c1d93eafd62759db1d498e359", - "url": "https://github.com/fcecin/nim-web3-websock040", + "vcsRevision": "cdfe5601d2812a58e54faf53ee634452d01e5918", + "url": "https://github.com/status-im/nim-web3", "downloadMethod": "git", "dependencies": [ "nim", @@ -557,7 +557,7 @@ "results" ], "checksums": { - "sha1": "b5972104bc9223a34ae3758293225264822af893" + "sha1": "26a112af032ef1536f97da2ca7364af618a11b80" } }, "dnsdisc": { diff --git a/waku.nimble b/waku.nimble index 949c079795..552d38a9be 100644 --- a/waku.nimble +++ b/waku.nimble @@ -39,13 +39,11 @@ requires "nim >= 2.2.4", "secp256k1", "bearssl", # RPC & APIs - # DRAFT: json_rpc + web3 repointed to fcecin forks for the libp2p 2.0.0 bump. - # json_rpc fork relaxes the websock cap (<0.4.0 -> <0.5.0); web3 fork repoints - # its own json_rpc require to the same fork so the SAT graph unifies. Revert to - # status-im json_rpc + bare "web3" once the cap fix lands upstream. - "https://github.com/fcecin/nim-json-rpc-websock040#8ce09c2ccc08b23f433a054b2b1ccb022d9547dc", + # json_rpc pinned to the master commit that relaxes the nim-websock cap to allow + # v0.4.0 (PR #277, landed after the v0.6.0 tag) — needed by the libp2p 2.0.0 bump. + "https://github.com/status-im/nim-json-rpc.git#f62ed04d7c630ddd834e296b7e7db2e1aa72a315", "presto", - "https://github.com/fcecin/nim-web3-websock040#96f39ea1b633277c1d93eafd62759db1d498e359", + "web3", # Database "db_connector", "sqlite3_abi", From 1f5f4c2816ae434656a3bfab59184dfc34e68425 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 10 Jun 2026 11:52:49 -0300 Subject: [PATCH 07/10] Fixes * Fix libp2p bump to v2.0.0 tag * Fix libp2p_mix bump to commit that references libp2p v2.0.0 * Fix lint --- logos_delivery.nimble | 4 ++-- logos_delivery/waku/discovery/waku_kademlia.nim | 3 ++- logos_delivery/waku/waku_filter_v2/client.nim | 4 +--- logos_delivery/waku/waku_lightpush/client.nim | 4 +--- logos_delivery/waku/waku_lightpush_legacy/client.nim | 4 +--- logos_delivery/waku/waku_mix/protocol.nim | 4 +++- nimble.lock | 6 +++--- tests/node/test_wakunode_peer_manager.nim | 9 ++++----- tests/test_peer_manager.nim | 7 +++++-- tests/waku_lightpush_legacy/lightpush_utils.nim | 3 ++- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/logos_delivery.nimble b/logos_delivery.nimble index b80ba7cf38..0f29fa6fdd 100644 --- a/logos_delivery.nimble +++ b/logos_delivery.nimble @@ -28,7 +28,7 @@ requires "nim >= 2.2.4", "toml_serialization", "faststreams", # Networking & P2P - "https://github.com/vacp2p/nim-libp2p.git#c43199378f46d0aaf61be1cad1ee1d63e8f665d6", + "https://github.com/vacp2p/nim-libp2p.git#v2.0.0", "eth", "nat_traversal", "dnsdisc", @@ -71,7 +71,7 @@ requires "https://github.com/NagyZoltanPeter/nim-brokers.git#v3.1.1" requires "https://github.com/vacp2p/nim-lsquic" requires "https://github.com/vacp2p/nim-jwt.git#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2" -requires "https://github.com/logos-co/nim-libp2p-mix#7cb7556d9a228573fc5622af7ffb2dd11741e043" +requires "https://github.com/logos-co/nim-libp2p-mix#380513117d556bf8f70066f5e72a7fd74fe36ba6" proc getMyCPU(): string = ## Need to set cpu more explicit manner to avoid arch issues between dependencies diff --git a/logos_delivery/waku/discovery/waku_kademlia.nim b/logos_delivery/waku/discovery/waku_kademlia.nim index acedadbff4..92ff4d94ac 100644 --- a/logos_delivery/waku/discovery/waku_kademlia.nim +++ b/logos_delivery/waku/discovery/waku_kademlia.nim @@ -55,7 +55,8 @@ proc new*( switch, bootstrapNodes = params.bootstrapNodes, config = KadDHTConfig.new( - validator = svdisc_types.ExtEntryValidator(), selector = svdisc_types.ExtEntrySelector() + validator = svdisc_types.ExtEntryValidator(), + selector = svdisc_types.ExtEntrySelector(), ), rng = switch.rng, codec = ExtendedServiceDiscoveryCodec, diff --git a/logos_delivery/waku/waku_filter_v2/client.nim b/logos_delivery/waku/waku_filter_v2/client.nim index b3e0cd28fe..ddae363a3a 100644 --- a/logos_delivery/waku/waku_filter_v2/client.nim +++ b/logos_delivery/waku/waku_filter_v2/client.nim @@ -212,9 +212,7 @@ proc initProtocolHandler(wfc: WakuFilterClient) = wfc.handler = handler wfc.codec = WakuFilterPushCodec -proc new*( - T: type WakuFilterClient, peerManager: PeerManager, rng: crypto.Rng -): T = +proc new*(T: type WakuFilterClient, peerManager: PeerManager, rng: crypto.Rng): T = let brokerCtx = globalBrokerContext() let wfc = WakuFilterClient( brokerCtx: brokerCtx, rng: rng, peerManager: peerManager, pushHandlers: @[] diff --git a/logos_delivery/waku/waku_lightpush/client.nim b/logos_delivery/waku/waku_lightpush/client.nim index afd4fa539a..680970a512 100644 --- a/logos_delivery/waku/waku_lightpush/client.nim +++ b/logos_delivery/waku/waku_lightpush/client.nim @@ -21,9 +21,7 @@ type WakuLightPushClient* = ref object rng*: crypto.Rng peerManager*: PeerManager -proc new*( - T: type WakuLightPushClient, peerManager: PeerManager, rng: crypto.Rng -): T = +proc new*(T: type WakuLightPushClient, peerManager: PeerManager, rng: crypto.Rng): T = WakuLightPushClient(peerManager: peerManager, rng: rng) proc ensureTimestampSet(message: var WakuMessage) = diff --git a/logos_delivery/waku/waku_lightpush_legacy/client.nim b/logos_delivery/waku/waku_lightpush_legacy/client.nim index cb65ee5973..511c3f543b 100644 --- a/logos_delivery/waku/waku_lightpush_legacy/client.nim +++ b/logos_delivery/waku/waku_lightpush_legacy/client.nim @@ -22,9 +22,7 @@ type WakuLegacyLightPushClient* = ref object rng*: crypto.Rng proc new*( - T: type WakuLegacyLightPushClient, - peerManager: PeerManager, - rng: crypto.Rng, + T: type WakuLegacyLightPushClient, peerManager: PeerManager, rng: crypto.Rng ): T = WakuLegacyLightPushClient(peerManager: peerManager, rng: rng) diff --git a/logos_delivery/waku/waku_mix/protocol.nim b/logos_delivery/waku/waku_mix/protocol.nim index e648040f17..613b6e3c7f 100644 --- a/logos_delivery/waku/waku_mix/protocol.nim +++ b/logos_delivery/waku/waku_mix/protocol.nim @@ -93,7 +93,9 @@ proc new*( localMixNodeInfo, peermgr.switch, delayStrategy = Opt.some( - DelayStrategy(ExponentialDelayStrategy.new(meanDelay = 50'u16, rng = crypto.newRng())) + DelayStrategy( + ExponentialDelayStrategy.new(meanDelay = 50'u16, rng = crypto.newRng()) + ) ), ) diff --git a/nimble.lock b/nimble.lock index b482a2f25e..53a911ad2f 100644 --- a/nimble.lock +++ b/nimble.lock @@ -583,7 +583,7 @@ } }, "libp2p": { - "version": "#c43199378f46d0aaf61be1cad1ee1d63e8f665d6", + "version": "2.0.0", "vcsRevision": "c43199378f46d0aaf61be1cad1ee1d63e8f665d6", "url": "https://github.com/vacp2p/nim-libp2p.git", "downloadMethod": "git", @@ -700,7 +700,7 @@ }, "libp2p_mix": { "version": "0.1.0", - "vcsRevision": "7cb7556d9a228573fc5622af7ffb2dd11741e043", + "vcsRevision": "380513117d556bf8f70066f5e72a7fd74fe36ba6", "url": "https://github.com/logos-co/nim-libp2p-mix", "downloadMethod": "git", "dependencies": [ @@ -715,7 +715,7 @@ "unittest2" ], "checksums": { - "sha1": "8287dda862a4398966cd66a5b3d7d66834c9a9a6" + "sha1": "ccfb0f0160ac15ac970471964c730d57edacad91" } } }, diff --git a/tests/node/test_wakunode_peer_manager.nim b/tests/node/test_wakunode_peer_manager.nim index 3aba26e221..a43f76d973 100644 --- a/tests/node/test_wakunode_peer_manager.nim +++ b/tests/node/test_wakunode_peer_manager.nim @@ -29,11 +29,10 @@ import # nim-libp2p 2.0.0 enables the IdentifyPush protocol by default, so every node # now also advertises "/ipfs/id/push/1.0.0" (prepended to the identify list). -const DEFAULT_PROTOCOLS: seq[string] = - @[ - "/ipfs/id/push/1.0.0", "/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", - "/libp2p/circuit/relay/0.2.0/hop", - ] +const DEFAULT_PROTOCOLS: seq[string] = @[ + "/ipfs/id/push/1.0.0", "/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", + "/libp2p/circuit/relay/0.2.0/hop", +] let listenIp = parseIpAddress("0.0.0.0") diff --git a/tests/test_peer_manager.nim b/tests/test_peer_manager.nim index 7b5cf3624a..1505a686fc 100644 --- a/tests/test_peer_manager.nim +++ b/tests/test_peer_manager.nim @@ -955,7 +955,8 @@ procSuite "Peer Manager": # Create peer manager let pm = PeerManager.new( - switch = SwitchBuilder.new().withRng(crypto.newRng()).withMplex().withNoise().build(), + switch = + SwitchBuilder.new().withRng(crypto.newRng()).withMplex().withNoise().build(), storage = nil, ) @@ -1040,7 +1041,9 @@ procSuite "Peer Manager": # Create 30 peers and add them to the peerstore let peers = toSeq(1 .. 30) - .mapIt(parsePeerInfo("/ip4/0.0.0.0/tcp/0/p2p/" & $PeerId.random(crypto.newRng()).get())) + .mapIt( + parsePeerInfo("/ip4/0.0.0.0/tcp/0/p2p/" & $PeerId.random(crypto.newRng()).get()) + ) .filterIt(it.isOk()) .mapIt(it.value) for p in peers: diff --git a/tests/waku_lightpush_legacy/lightpush_utils.nim b/tests/waku_lightpush_legacy/lightpush_utils.nim index 5d1a6e7e52..e64f5d69fe 100644 --- a/tests/waku_lightpush_legacy/lightpush_utils.nim +++ b/tests/waku_lightpush_legacy/lightpush_utils.nim @@ -19,7 +19,8 @@ proc newTestWakuLegacyLightpushNode*( ): Future[WakuLegacyLightPush] {.async.} = let peerManager = PeerManager.new(switch) - proto = WakuLegacyLightPush.new(peerManager, crypto.newRng(), handler, rateLimitSetting) + proto = + WakuLegacyLightPush.new(peerManager, crypto.newRng(), handler, rateLimitSetting) await proto.start() switch.mount(proto) From 5aebe3de3e6fa1e72f25d60b98cf27361b049a73 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 10 Jun 2026 12:13:43 -0300 Subject: [PATCH 08/10] Fix nix/deps.nix --- nix/deps.nix | 56 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/nix/deps.nix b/nix/deps.nix index 8e4453675b..f69864fc83 100644 --- a/nix/deps.nix +++ b/nix/deps.nix @@ -26,8 +26,8 @@ jwt = pkgs.fetchgit { url = "https://github.com/vacp2p/nim-jwt.git"; - rev = "18f8378de52b241f321c1f9ea905456e89b95c6f"; - sha256 = "1986czmszdxj6g9yr7xn1fx8y2y9mwpb3f1bn9nc6973qawsdm0p"; + rev = "057ec95eb5af0eea9c49bfe9025b3312c95dc5f2"; + sha256 = "1hnxsl5762fdn80hl4xxfdqrcgmxrrfck66js1iqaqfxc4m0fv63"; fetchSubmodules = true; }; @@ -159,8 +159,8 @@ brokers = pkgs.fetchgit { url = "https://github.com/NagyZoltanPeter/nim-brokers.git"; - rev = "2093ca4d50e581adda73fee7fd16231f990f4cbe"; - sha256 = "0a4ix2q6riqfrd0hfnajisy159qdmk5imwzymppj23rwc8n7d2dx"; + rev = "a7316a35f1b62e3497ae8ee0fc1aace74df0beb2"; + sha256 = "1990270n88jm0i48g07zr4vq2nn79g7gymf28f3g5ak42g33l7rm"; fetchSubmodules = true; }; @@ -215,22 +215,22 @@ websock = pkgs.fetchgit { url = "https://github.com/status-im/nim-websock"; - rev = "c105d98e6522e0e2cbe3dfa11b07a273e9fd0e7b"; - sha256 = "1zrigw27nwcmg7mw9867581ipcp3ckrqq3cwl2snabcjhkp5dm2c"; + rev = "387a8eb7e961e8fdd3b1a717d36bc53b55e4dc5d"; + sha256 = "1v0m3x96fbp9jdzsys6mbxxc2xw3k3dqiv7wksfla89gc6z8w377"; fetchSubmodules = true; }; json_rpc = pkgs.fetchgit { url = "https://github.com/status-im/nim-json-rpc.git"; - rev = "43bbf499143eb45046c83ac9794c9e3280a2b8e7"; - sha256 = "1c1msxg958jm2ggvs875b6wh6n829d3lh7x4ch6dcxawda16qf95"; + rev = "f62ed04d7c630ddd834e296b7e7db2e1aa72a315"; + sha256 = "0rq39yjnmdjbg4vrfqn12c3i7r5fxlfj4mpdffahagz13dxscmh6"; fetchSubmodules = true; }; lsquic = pkgs.fetchgit { url = "https://github.com/vacp2p/nim-lsquic"; - rev = "4fb03ee7bfb39aecb3316889fdcb60bec3d0936f"; - sha256 = "0qdhcd4hyp185szc9sv3jvwdwc9zp3j0syy7glxv13k9bchfmkfg"; + rev = "00e4b7dfaa197cd120267aa897b33b0914166b45"; + sha256 = "0kfkcscafiz82amj7skn5hspqhs6ixdz09hy64cfhsxyd6mi48nq"; fetchSubmodules = true; }; @@ -264,8 +264,8 @@ libp2p = pkgs.fetchgit { url = "https://github.com/vacp2p/nim-libp2p.git"; - rev = "ff8d51857b4b79a68468e7bcc27b2026cca02996"; - sha256 = "08y4s0zhqzsd780bwaixfqbi79km0mcq5g8nyw7awfvcbjqsa53l"; + rev = "c43199378f46d0aaf61be1cad1ee1d63e8f665d6"; + sha256 = "0q1hkwwz08zfdwwz7cfql1hqil0iyv3dn8jypdwqmg7497l1bmxk"; fetchSubmodules = true; }; @@ -278,8 +278,8 @@ sds = pkgs.fetchgit { url = "https://github.com/logos-messaging/nim-sds.git"; - rev = "2e9a7683f0e180bf112135fae3a3803eed8490d4"; - sha256 = "1dbpvp3zhvdlfxdyggz5waga1vg3b6ndd3acfzhnx8k1wdr01c6f"; + rev = "abdd40cc645f1b024c3ee99cced7e287c4e4c441"; + sha256 = "01k49sljxnzjy82jljcffwqkaqvhpj1aiz605gv429sbzgyfr8mm"; fetchSubmodules = true; }; @@ -290,4 +290,32 @@ fetchSubmodules = true; }; + boringssl = pkgs.fetchgit { + url = "https://github.com/vacp2p/nim-boringssl"; + rev = "1c91a4a2579123597df43bbdea70cc575957bdea"; + sha256 = "0vh26cdski46jaaqfxqz8pfzjxxnkr3znvyqdgn5m6q4xkbb1jqz"; + fetchSubmodules = true; + }; + + protobuf_serialization = pkgs.fetchgit { + url = "https://github.com/status-im/nim-protobuf-serialization"; + rev = "38d24eb3bd93e605fb88199da71d36b1ec0ad60d"; + sha256 = "0jr0a41b4r444si6xfa7bclw8mjsk6id10lrdvbxzp99750zspb9"; + fetchSubmodules = true; + }; + + npeg = pkgs.fetchgit { + url = "https://github.com/zevv/npeg"; + rev = "409f6796d0e880b3f0222c964d1da7de6e450811"; + sha256 = "1h2f5znbpa3svk7wsw2axn8f7f59d23xq85z148kiv6fqh0ffwbm"; + fetchSubmodules = true; + }; + + libp2p_mix = pkgs.fetchgit { + url = "https://github.com/logos-co/nim-libp2p-mix"; + rev = "380513117d556bf8f70066f5e72a7fd74fe36ba6"; + sha256 = "05zjf98nl2hxx62m9blk4yip2f31y44r5x4n98lmm5hghb7wbcpk"; + fetchSubmodules = true; + }; + } From 4038769c737bf4c6d9b12a361f7a3ae36aa6aee3 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 10 Jun 2026 15:10:55 -0300 Subject: [PATCH 09/10] pin json_rpc, lsquic, boringssl to release tags * json_rpc: to v0.6.1 tag (latest) * lsquic: v0.5.1 (latest; QUIC connection-handling fixes) * boringssl: v0.0.8 (latest) --- logos_delivery.nimble | 6 ++---- nimble.lock | 18 +++++++++--------- nix/deps.nix | 12 ++++++------ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/logos_delivery.nimble b/logos_delivery.nimble index 0f29fa6fdd..59f6f9e559 100644 --- a/logos_delivery.nimble +++ b/logos_delivery.nimble @@ -40,9 +40,7 @@ requires "nim >= 2.2.4", "secp256k1", "bearssl", # RPC & APIs - # json_rpc pinned to the master commit that relaxes the nim-websock cap to allow - # v0.4.0 (PR #277, landed after the v0.6.0 tag) — needed by the libp2p 2.0.0 bump. - "https://github.com/status-im/nim-json-rpc.git#f62ed04d7c630ddd834e296b7e7db2e1aa72a315", + "https://github.com/status-im/nim-json-rpc.git#v0.6.1", "presto", "web3", # Database @@ -69,7 +67,7 @@ requires "https://github.com/logos-messaging/nim-sds.git#abdd40cc645f1b024c3ee99 requires "https://github.com/NagyZoltanPeter/nim-brokers.git#v3.1.1" -requires "https://github.com/vacp2p/nim-lsquic" +requires "https://github.com/vacp2p/nim-lsquic.git#v0.5.1" requires "https://github.com/vacp2p/nim-jwt.git#057ec95eb5af0eea9c49bfe9025b3312c95dc5f2" requires "https://github.com/logos-co/nim-libp2p-mix#380513117d556bf8f70066f5e72a7fd74fe36ba6" diff --git a/nimble.lock b/nimble.lock index 53a911ad2f..67e4296ff3 100644 --- a/nimble.lock +++ b/nimble.lock @@ -454,8 +454,8 @@ } }, "json_rpc": { - "version": "0.6.0", - "vcsRevision": "f62ed04d7c630ddd834e296b7e7db2e1aa72a315", + "version": "0.6.1", + "vcsRevision": "6f1fff8ba685c9192fab153a9d66484ad9066e78", "url": "https://github.com/status-im/nim-json-rpc.git", "downloadMethod": "git", "dependencies": [ @@ -472,12 +472,12 @@ "unittest2" ], "checksums": { - "sha1": "4221c98dbc09ba56d68ca0a36b5c2ad90e39a43b" + "sha1": "596db0aafcb3c83f5dba6d42993f2276e0d00eb5" } }, "lsquic": { - "version": "0.4.1", - "vcsRevision": "00e4b7dfaa197cd120267aa897b33b0914166b45", + "version": "0.5.1", + "vcsRevision": "2f01046bf1d513de8b5f8296c3d8bec819ab0cb9", "url": "https://github.com/vacp2p/nim-lsquic", "downloadMethod": "git", "dependencies": [ @@ -491,7 +491,7 @@ "boringssl" ], "checksums": { - "sha1": "5e36783661eab239bd4d8566ff3195c8d14f1923" + "sha1": "959df1a9ac2a574d6fe30a4faf37c37b443e1cfb" } }, "secp256k1": { @@ -658,15 +658,15 @@ } }, "boringssl": { - "version": "0.0.4", - "vcsRevision": "1c91a4a2579123597df43bbdea70cc575957bdea", + "version": "0.0.8", + "vcsRevision": "e77caabae78fbc9aa5b78a0a521181b077c82571", "url": "https://github.com/vacp2p/nim-boringssl", "downloadMethod": "git", "dependencies": [ "nim" ], "checksums": { - "sha1": "3655faa30099538293cb7d60e726783dff9d979a" + "sha1": "2f603bb6d70683393bbb091bf6bd325d9c52be9f" } }, "protobuf_serialization": { diff --git a/nix/deps.nix b/nix/deps.nix index f69864fc83..1f2735457a 100644 --- a/nix/deps.nix +++ b/nix/deps.nix @@ -222,15 +222,15 @@ json_rpc = pkgs.fetchgit { url = "https://github.com/status-im/nim-json-rpc.git"; - rev = "f62ed04d7c630ddd834e296b7e7db2e1aa72a315"; - sha256 = "0rq39yjnmdjbg4vrfqn12c3i7r5fxlfj4mpdffahagz13dxscmh6"; + rev = "6f1fff8ba685c9192fab153a9d66484ad9066e78"; + sha256 = "1r4xlis5fxcmp1cdqskb25nzmxckfkl8lndshvl76kcqrb0hl88d"; fetchSubmodules = true; }; lsquic = pkgs.fetchgit { url = "https://github.com/vacp2p/nim-lsquic"; - rev = "00e4b7dfaa197cd120267aa897b33b0914166b45"; - sha256 = "0kfkcscafiz82amj7skn5hspqhs6ixdz09hy64cfhsxyd6mi48nq"; + rev = "2f01046bf1d513de8b5f8296c3d8bec819ab0cb9"; + sha256 = "16xj0hx13nc95x7scck8lyir0kzx4wqnd6d4h79aai8j9hlcmbsl"; fetchSubmodules = true; }; @@ -292,8 +292,8 @@ boringssl = pkgs.fetchgit { url = "https://github.com/vacp2p/nim-boringssl"; - rev = "1c91a4a2579123597df43bbdea70cc575957bdea"; - sha256 = "0vh26cdski46jaaqfxqz8pfzjxxnkr3znvyqdgn5m6q4xkbb1jqz"; + rev = "e77caabae78fbc9aa5b78a0a521181b077c82571"; + sha256 = "15k4dqh1hlcpq9zm30lpr728h7apdmgm22xzqhdm3clq9kia6fr8"; fetchSubmodules = true; }; From 0f6e4796c44208cdf5f85b5b53f201e871459591 Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Thu, 11 Jun 2026 17:20:50 -0300 Subject: [PATCH 10/10] Fix test problems exposed by MacOS CI runners --- tests/node/test_wakunode_legacy_lightpush.nim | 5 +++- tests/node/test_wakunode_lightpush.nim | 5 +++- tests/waku_relay/test_protocol.nim | 24 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/node/test_wakunode_legacy_lightpush.nim b/tests/node/test_wakunode_legacy_lightpush.nim index ec61c2cdf3..4dfe21e9cc 100644 --- a/tests/node/test_wakunode_legacy_lightpush.nim +++ b/tests/node/test_wakunode_legacy_lightpush.nim @@ -118,7 +118,10 @@ suite "RLN Proofs as a Lightpush Service": manager = waitFor setupOnchainGroupManager(deployContracts = false) # mount rln-relay - let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1)) + # match prod epoch window to reduce test flake + let wakuRlnConfig = getWakuRlnConfig( + manager = manager, index = MembershipIndex(1), epochSizeSec = 600 + ) await allFutures(server.start(), client.start()) await server.start() diff --git a/tests/node/test_wakunode_lightpush.nim b/tests/node/test_wakunode_lightpush.nim index be36b8d984..df6c7f8e0a 100644 --- a/tests/node/test_wakunode_lightpush.nim +++ b/tests/node/test_wakunode_lightpush.nim @@ -116,7 +116,10 @@ suite "RLN Proofs as a Lightpush Service": manager = waitFor setupOnchainGroupManager(deployContracts = false) # mount rln-relay - let wakuRlnConfig = getWakuRlnConfig(manager = manager, index = MembershipIndex(1)) + # match prod epoch window to reduce test flake + let wakuRlnConfig = getWakuRlnConfig( + manager = manager, index = MembershipIndex(1), epochSizeSec = 600 + ) await allFutures(server.start(), client.start()) await server.start() diff --git a/tests/waku_relay/test_protocol.nim b/tests/waku_relay/test_protocol.nim index 16a1767b65..a2042627e6 100644 --- a/tests/waku_relay/test_protocol.nim +++ b/tests/waku_relay/test_protocol.nim @@ -1,7 +1,7 @@ {.used.} import - std/[options, strformat], + std/[options, strformat, sets, tables], testutils/unittests, chronos, libp2p/protocols/pubsub/[pubsub, gossipsub], @@ -21,6 +21,23 @@ import ./utils, ../resources/payloads +proc hasMeshPeer(relay: WakuRelay, topic: PubsubTopic, peer: PeerId): bool = + for p in relay.mesh.getOrDefault(topic): + if p.peerId == peer: + return true + false + +proc waitForMeshPeer( + relay: WakuRelay, topic: PubsubTopic, peer: PeerId, timeout = 10.seconds +): Future[bool] {.async.} = + ## Wait until `relay`'s gossipsub mesh for `topic` has GRAFTed `peer`. + let deadline = Moment.now() + timeout + while Moment.now() < deadline: + if relay.hasMeshPeer(topic, peer): + return true + await sleepAsync(50.milliseconds) + false + suite "Waku Relay": var messageSeq {.threadvar.}: seq[(PubsubTopic, WakuMessage)] var handlerFuture {.threadvar.}: Future[(PubsubTopic, WakuMessage)] @@ -677,6 +694,11 @@ suite "Waku Relay": anotherPeerManager.switch.isConnected(otherPeerId) otherPeerManager.switch.isConnected(anotherPeerId) + # Wait for the mesh to re-form before publishing (else it races the 1s FUTURE_TIMEOUT). + check: + await otherNode.waitForMeshPeer(pubsubTopicC, anotherPeerId) + await anotherNode.waitForMeshPeer(pubsubTopicC, otherPeerId) + # When publishing a message in anotherNode for each of the pubsub topics handlerFuture = newPushHandlerFuture() handlerFuture2 = newPushHandlerFuture()