fix(mix): add nil guard in setupSpamProtectionCallbacks

Defensive nil check for mixRlnSpamProtection when spam protection
is disabled, preventing potential crash if the guard in start()
is ever bypassed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Prem Chaitanya Prathi 2026-04-10 10:39:11 +05:30
parent 5090fedb00
commit acab10008e
No known key found for this signature in database
32 changed files with 42 additions and 11 deletions

View File

@ -99,9 +99,6 @@ if not defined(macosx) and not defined(android):
nimStackTraceOverride
switch("import", "libbacktrace")
# Compatibility shims for std/options after results library update
switch("import", "waku/common/option_shims")
--define:
nimOldCaseObjects
# https://github.com/status-im/nim-confutils/issues/9

View File

@ -157,3 +157,9 @@ Key metrics to look for:
- `mix_cover_emitted_total` — cover messages generated per node (should increase each epoch)
- `mix_cover_received_total` — cover messages received back at origin after 3-hop mix path
- `mix_slots_exhausted_total` — expected when slots per epoch are low
### Note on Rate Limit and Expected Errors
The default `mix-user-message-limit=2` (R=2) with path length L=3 yields a fractional cover target of `R/(1+L) = 0.5` packets per epoch. Because this is not an integer, epoch boundary jitter can cause two cover emissions in one epoch, exhausting all slots and leaving none for forwarding. This produces `SLOT_EXHAUSTED` and `SPAM_PROOF_GEN_FAILED` errors at intermediate hops — these are expected with the default config.
For a clean setup, R should be a multiple of `(1+L) = 4`. Setting `mix-user-message-limit=4` gives exactly 1 cover packet per epoch with 3 slots remaining for forwarding, eliminating these errors.

View File

@ -21,7 +21,7 @@ import
const
KeystorePassword = "mix-rln-password" # Must match protocol.nim
DefaultUserMessageLimit = 2'u64 # ~12 msgs/min with 10s epochs
SpammerUserMessageLimit = 3'u64 # Lower limit for spammer testing
SpammerUserMessageLimit = 3'u64 # Higher limit for spammer testing
# Peer IDs derived from nodekeys in config files
# config.toml: nodekey = "f98e3fba96c32e8d1967d460f1b79457380e1a895f7971cecc8528abe733781a"

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[sequtils, strutils, net],
std/[options, sequtils, strutils, net],
stew/byteutils,
testutils/unittests,
chronicles,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[os, strutils, sequtils, sysrand, math],
std/[options, os, strutils, sequtils, sysrand, math],
stew/byteutils,
testutils/unittests,
chronos,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/sequtils,
std/[options, sequtils],
testutils/unittests,
chronicles,
chronos,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/net,
std/[net, options],
testutils/unittests,
chronos,
libp2p/crypto/crypto,

View File

@ -24,6 +24,7 @@ import
import std/times except TimeInterval, Duration, seconds, minutes
import ../option_shims
import ./[single_token_limiter, service_metrics, timed_map]
export token_bucket, setting, service_metrics

View File

@ -10,7 +10,7 @@ import
eth/keys as eth_keys,
eth/p2p/discoveryv5/node,
eth/p2p/discoveryv5/protocol
import ../node/peer_manager/peer_manager, ../waku_core, ../waku_enr
import ../common/option_shims, ../node/peer_manager/peer_manager, ../waku_core, ../waku_enr
export protocol, waku_enr

View File

@ -2,6 +2,7 @@ import chronicles, chronos, results
import std/options
import
waku/common/option_shims,
waku/node/peer_manager,
waku/waku_core,
waku/waku_lightpush/[common, client, rpc],

View File

@ -28,6 +28,7 @@ import
../../waku_lightpush/client as lightpush_client,
../../waku_lightpush as lightpush_protocol,
../peer_manager,
../../common/option_shims,
../../common/rate_limit/setting,
../../waku_rln_relay

View File

@ -11,7 +11,7 @@ import
libp2p/transports/tcptransport,
libp2p/utility
import ../waku_node, ../peer_manager
import ../../common/option_shims, ../waku_node, ../peer_manager
logScope:
topics = "waku node ping api"

View File

@ -31,6 +31,7 @@ import
waku_mix,
node/waku_node,
node/peer_manager,
common/option_shims,
common/broker/broker_context,
events/message_events,
]

View File

@ -19,6 +19,7 @@ import
events/peer_events,
common/nimchronos,
common/enr,
common/option_shims,
common/callbacks,
common/utils/parse_size_units,
common/broker/broker_context,

View File

@ -10,6 +10,7 @@ import
libp2p/crypto/curve25519
import
../../common/option_shims,
../../waku_core,
../../waku_enr/sharding,
../../waku_enr/capabilities,

View File

@ -57,6 +57,7 @@ import
waku_rln_relay,
common/rate_limit/setting,
common/callbacks,
common/option_shims,
common/nimchronos,
common/broker/broker_context,
common/broker/request_broker,

View File

@ -10,6 +10,7 @@ import
presto/route,
presto/common
import
../../../common/option_shims,
../../../waku_core,
../../../waku_node,
../../../node/peer_manager,

View File

@ -10,6 +10,7 @@ import
presto/common
import
waku/common/option_shims,
waku/node/peer_manager,
waku/waku_lightpush_legacy/common,
../../../waku_node,

View File

@ -3,6 +3,7 @@
import
std/[strformat, sugar], results, chronicles, uri, json_serialization, presto/route
import
../../../common/option_shims,
../../../waku_core,
../../../waku_store_legacy/common,
../../../waku_store_legacy/self_req_handler,

View File

@ -10,6 +10,7 @@ import
presto/common
import
waku/common/option_shims,
waku/node/peer_manager,
waku/waku_lightpush/common,
../../../waku_node,

View File

@ -3,6 +3,7 @@
import
std/[strformat, sugar], results, chronicles, uri, json_serialization, presto/route
import
../../../common/option_shims,
../../../waku_core,
../../../waku_store/common,
../../../waku_store/self_req_handler,

View File

@ -8,7 +8,7 @@ import
eth/keys,
libp2p/[multiaddress, multicodec],
libp2p/crypto/crypto
import ../common/enr, ../waku_core/topics/pubsub_topic
import ../common/enr, ../common/option_shims, ../waku_core/topics/pubsub_topic
logScope:
topics = "waku enr sharding"

View File

@ -3,6 +3,7 @@
import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils
import libp2p/peerid, libp2p/stream/connection
import
../common/option_shims,
../waku_core/peers,
../node/peer_manager,
../utils/requests,

View File

@ -9,6 +9,7 @@ import
metrics,
bearssl/rand
import
../common/option_shims,
../node/peer_manager/peer_manager,
../waku_core,
../waku_core/topics/sharding,

View File

@ -3,6 +3,7 @@
import std/options, results, chronicles, chronos, metrics, bearssl/rand, stew/byteutils
import libp2p/peerid
import
../common/option_shims,
../waku_core/peers,
../node/peer_manager,
../utils/requests,

View File

@ -122,11 +122,16 @@ proc new*(
else:
info "mix spam protection disabled"
var mixRlnSpam: MixRlnSpamProtection
if spamProtectionOpt.isSome():
mixRlnSpam = MixRlnSpamProtection(spamProtectionOpt.get())
var m = WakuMix(
peerManager: peermgr,
clusterId: clusterId,
pubKey: mixPubKey,
publishMessage: publishMessage,
mixRlnSpamProtection: mixRlnSpam,
)
procCall MixProtocol(m).init(
localMixNodeInfo,
@ -151,6 +156,8 @@ proc setupSpamProtectionCallbacks(mix: WakuMix) =
## Set up the publish callback for spam protection coordination.
## This enables the plugin to broadcast membership updates and proof metadata
## via Waku relay.
if mix.mixRlnSpamProtection.isNil():
return
if mix.publishMessage.isNil():
warn "PublishMessage callback not available, spam protection coordination disabled"
return

View File

@ -13,6 +13,7 @@ import
import metrics except collect
import
waku/common/option_shims,
waku/node/peer_manager,
waku/waku_core/peers,
waku/waku_core/codecs,

View File

@ -19,6 +19,7 @@ import metrics except collect
import
../node/peer_manager,
../common/callbacks,
../common/option_shims,
../waku_enr/capabilities,
../waku_core/peers,
../waku_core/codecs,

View File

@ -8,6 +8,7 @@ import
metrics,
bearssl/rand
import
../common/option_shims,
../node/peer_manager, ../utils/requests, ./protocol_metrics, ./common, ./rpc_codec
logScope:

View File

@ -13,6 +13,7 @@ import
import
../common/databases/db_sqlite,
../common/option_shims,
../waku_core,
../waku_archive,
../common/nimchronos,

View File

@ -14,6 +14,7 @@ import
eth/p2p/discoveryv5/enr
import
../common/nimchronos,
../common/option_shims,
../common/protobuf,
../common/paging,
../waku_enr,

View File

@ -13,6 +13,7 @@ import
eth/p2p/discoveryv5/enr
import
../common/nimchronos,
../common/option_shims,
../common/protobuf,
../waku_enr,
../waku_core/codecs,