logos-messaging-nim/waku/common/option_shims.nim
Prem Chaitanya Prathi 2033358df2
feat(mix): add cover traffic, disable-spam-protection flag, and fix option_shims crash
- Add cover traffic support with constant rate as per spec
- Add mix-user-message-limit and mix-disable-spam-protection CLI flags
- Fix option_shims.nim double-evaluation bug causing UnpackDefect crash
  in ping (template expanded await expression twice, racing two calls)
- Reduce default rate limit to 2 msgs/epoch for simulation testing
- Add check_cover_traffic.sh metrics monitoring script

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 23:09:26 +05:30

29 lines
663 B
Nim

# Compatibility shims for std/options
# The results library removed valueOr/withValue support for Option[T].
# These templates restore that functionality.
{.push raises: [].}
import std/options
template valueOr*[T](self: Option[T], def: untyped): T =
let tmp = self
if tmp.isSome():
tmp.get()
else:
def
template withValue*[T](self: Option[T], value, body: untyped): untyped =
let tmp = self
if tmp.isSome():
let value {.inject.} = tmp.get()
body
template withValue*[T](self: Option[T], value, body, elseBody: untyped): untyped =
let tmp = self
if tmp.isSome():
let value {.inject.} = tmp.get()
body
else:
elseBody