From 088e3108c86085c2d3c072c29964ae96f285c6d2 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Sat, 22 Nov 2025 08:11:05 +0530 Subject: [PATCH] use exit==dest approach for mix (#3642) --- Makefile | 3 +++ apps/chat2mix/chat2mix.nim | 7 +++++-- examples/lightpush_mix/lightpush_publisher_mix.nim | 5 ++++- simulations/mixnet/config.toml | 4 ++-- .../mixnet/{run_lp_service_node.sh => run_mix_node.sh} | 0 waku/node/kernel_api/lightpush.nim | 2 +- waku/waku_mix/protocol.nim | 10 +++++----- waku/waku_rendezvous/protocol.nim | 3 +++ 8 files changed, 23 insertions(+), 11 deletions(-) rename simulations/mixnet/{run_lp_service_node.sh => run_mix_node.sh} (100%) diff --git a/Makefile b/Makefile index 029313c99..f65daff71 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,9 @@ ifeq ($(USE_LIBBACKTRACE), 0) NIM_PARAMS := $(NIM_PARAMS) -d:disable_libbacktrace endif +# enable experimental exit is dest feature in libp2p mix +NIM_PARAMS := $(NIM_PARAMS) -d:libp2p_mix_experimental_exit_is_dest + libbacktrace: + $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0 diff --git a/apps/chat2mix/chat2mix.nim b/apps/chat2mix/chat2mix.nim index 3fdd7bc9c..45fd1fa2d 100644 --- a/apps/chat2mix/chat2mix.nim +++ b/apps/chat2mix/chat2mix.nim @@ -82,6 +82,8 @@ type PrivateKey* = crypto.PrivateKey Topic* = waku_core.PubsubTopic +const MinMixNodePoolSize = 4 + ##################### ## chat2 protobufs ## ##################### @@ -592,6 +594,7 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = node.peerManager.addServicePeer(servicePeerInfo, WakuLightpushCodec) node.peerManager.addServicePeer(servicePeerInfo, WakuPeerExchangeCodec) + #node.peerManager.addServicePeer(servicePeerInfo, WakuRendezVousCodec) # Start maintaining subscription asyncSpawn maintainSubscription( @@ -599,12 +602,12 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} = ) echo "waiting for mix nodes to be discovered..." while true: - if node.getMixNodePoolSize() >= 3: + if node.getMixNodePoolSize() >= MinMixNodePoolSize: break discard await node.fetchPeerExchangePeers() await sleepAsync(1000) - while node.getMixNodePoolSize() < 3: + while node.getMixNodePoolSize() < MinMixNodePoolSize: info "waiting for mix nodes to be discovered", currentpoolSize = node.getMixNodePoolSize() await sleepAsync(1000) diff --git a/examples/lightpush_mix/lightpush_publisher_mix.nim b/examples/lightpush_mix/lightpush_publisher_mix.nim index bb4bb4c4e..4219cd665 100644 --- a/examples/lightpush_mix/lightpush_publisher_mix.nim +++ b/examples/lightpush_mix/lightpush_publisher_mix.nim @@ -144,7 +144,7 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.} conn = connOpt.get() else: conn = node.wakuMix.toConnection( - MixDestination.init(dPeerId, pxPeerInfo.addrs[0]), # destination lightpush peer + MixDestination.exitNode(dPeerId), # destination lightpush peer WakuLightPushCodec, # protocol codec which will be used over the mix connection MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))), # mix parameters indicating we expect a single reply @@ -163,6 +163,9 @@ proc setupAndPublish(rng: ref HmacDrbgContext, conf: LightPushMixConf) {.async.} ephemeral: true, # tell store nodes to not store it timestamp: getNowInNanosecondTime(), ) # current timestamp + let res = await node.wakuLightpushClient.publishWithConn( + LightpushPubsubTopic, message, conn, dPeerId + ) let startTime = getNowInNanosecondTime() diff --git a/simulations/mixnet/config.toml b/simulations/mixnet/config.toml index 17e9242d3..3719d8177 100644 --- a/simulations/mixnet/config.toml +++ b/simulations/mixnet/config.toml @@ -1,6 +1,6 @@ log-level = "INFO" relay = true -#mix = true +mix = true filter = true store = false lightpush = true @@ -18,7 +18,7 @@ num-shards-in-network = 1 shard = [0] agent-string = "nwaku-mix" nodekey = "f98e3fba96c32e8d1967d460f1b79457380e1a895f7971cecc8528abe733781a" -#mixkey = "a87db88246ec0eedda347b9b643864bee3d6933eb15ba41e6d58cb678d813258" +mixkey = "a87db88246ec0eedda347b9b643864bee3d6933eb15ba41e6d58cb678d813258" rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" diff --git a/simulations/mixnet/run_lp_service_node.sh b/simulations/mixnet/run_mix_node.sh similarity index 100% rename from simulations/mixnet/run_lp_service_node.sh rename to simulations/mixnet/run_mix_node.sh diff --git a/waku/node/kernel_api/lightpush.nim b/waku/node/kernel_api/lightpush.nim index f42cb146e..8df6291b1 100644 --- a/waku/node/kernel_api/lightpush.nim +++ b/waku/node/kernel_api/lightpush.nim @@ -199,7 +199,7 @@ proc lightpushPublishHandler( if mixify: #indicates we want to use mix to send the message #TODO: How to handle multiple addresses? let conn = node.wakuMix.toConnection( - MixDestination.init(peer.peerId, peer.addrs[0]), + MixDestination.exitNode(peer.peerId), WakuLightPushCodec, MixParameters(expectReply: Opt.some(true), numSurbs: Opt.some(byte(1))), # indicating we only want a single path to be used for reply hence numSurbs = 1 diff --git a/waku/waku_mix/protocol.nim b/waku/waku_mix/protocol.nim index d3d765df8..366d5da91 100644 --- a/waku/waku_mix/protocol.nim +++ b/waku/waku_mix/protocol.nim @@ -21,7 +21,7 @@ import logScope: topics = "waku mix" -const mixMixPoolSize = 3 +const minMixPoolSize = 4 type WakuMix* = ref object of MixProtocol @@ -181,12 +181,12 @@ proc new*( peermgr.switch.peerInfo.peerId, nodeMultiAddr, mixPubKey, mixPrivKey, peermgr.switch.peerInfo.publicKey.skkey, peermgr.switch.peerInfo.privateKey.skkey, ) - if bootnodes.len < mixMixPoolSize: - warn "publishing with mix won't work until there are 3 mix nodes in node pool" + if bootnodes.len < minMixPoolSize: + warn "publishing with mix won't work until atleast 3 mix nodes in node pool" let initTable = processBootNodes(bootnodes, peermgr) - if len(initTable) < mixMixPoolSize: - warn "publishing with mix won't work until there are 3 mix nodes in node pool" + if len(initTable) < minMixPoolSize: + warn "publishing with mix won't work until atleast 3 mix nodes in node pool" var m = WakuMix(peerManager: peermgr, clusterId: clusterId, pubKey: mixPubKey) procCall MixProtocol(m).init(localMixNodeInfo, initTable, peermgr.switch) return ok(m) diff --git a/waku/waku_rendezvous/protocol.nim b/waku/waku_rendezvous/protocol.nim index ed414fa42..7b97375ff 100644 --- a/waku/waku_rendezvous/protocol.nim +++ b/waku/waku_rendezvous/protocol.nim @@ -234,4 +234,7 @@ proc stopWait*(self: WakuRendezVous) {.async: (raises: []).} = # Stop the parent GenericRendezVous (stops the register deletion loop) await GenericRendezVous[WakuPeerRecord](self).stop() + # Stop the parent GenericRendezVous (stops the register deletion loop) + await GenericRendezVous[WakuPeerRecord](self).stop() + info "waku rendezvous discovery stopped"