Skip to content

chore: replace Option with Opt#4035

Merged
fcecin merged 4 commits into
masterfrom
chore/migrate-opt
Jul 16, 2026
Merged

chore: replace Option with Opt#4035
fcecin merged 4 commits into
masterfrom
chore/migrate-opt

Conversation

@fcecin

@fcecin fcecin commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

This PR refactors the code to use Opt in place of Option.

Some tricky bits in the port that you'll notice when reviewing this PR:

  • readValue overload for Opt[T] in tools/confutils/cli_args.nim (TOML; must live in the module that expands confutils' load);
  • StoreServiceConf loses {.requiresInit.}: Nim can't default-construct a requiresInit object holding a case-object field, and Opt[T] is one;
  • optionals now render ok(x) / none() instead of some(x) / none(T) in logs and --help (four sites where the new rendering was wrong, with e.g. an error printing as ok(…), are fixed at the source line as well);
  • The broker codec for Opt in persistency/backend_comm.nim needs three procs: broker Opt codec: marshal, unmarshal, and also size;
  • Syntax Opt.some() and Opt.none() was chosen; but ok() and err() can be used instead (but they look like error-handling code). Can't use naked some() and none() for multiple reasons (std/options collision is one of them). Canonical use in the ecosystem is Opt.some() and Opt.none() already;
  • Macros in presto and confutils literally use and thus require "Option," so I just kept those. Changing this requires fixing macros and makes this PR not only longer but more complex; we can do that in a follow-up issue/PR if that's actually necessary, so this PR remains large in line count but trivial to review;
  • This PR also rolls in a few, small compilation fixes for examples/ and apps/ that weren't compiling, since the Opt migration touched apps and examples. Harder for validation to split then fix separately than just include, so I fixed both issues here.

Changes

  • change all usage of std.options.Option[T] to results.Opt[T]
  • fix broken apps and examples (to validate refactor)
  • removed all std/options code added for libp2p v2 migration
  • add broker Opt codec to persistency/backend_comm.nim
  • add a readValue overload for Opt[T] in tools/confutils/cli_args.nim
  • keep Option where required (Presto, confutils' config_file.nim)

Issue

closes #3955

* change all usage of std.options.Option[T] to results.Opt[T]
* fix broken apps and examples (to validate refactor)
* removed all std/options code added for libp2p v2 migration
* add broker Opt codec to persistency/backend_comm.nim
* add a readValue overload for Opt[T] in tools/confutils/cli_args.nim
* keep Option where required (Presto, confutils' config_file.nim)
@github-actions

Copy link
Copy Markdown

This PR may contain changes to configuration options of one of the apps.

If you are introducing a breaking change (i.e. the set of options in latest release would no longer be applicable) make sure the original option is preserved with a deprecation note for 2 following releases before it is actually removed.

Please also make sure the label release-notes is added to make sure any changes to the user interface are properly announced in changelog and release notes.

@github-actions

Copy link
Copy Markdown

This PR may contain changes to database schema of one of the drivers.

If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues.

Please make sure the label release-notes is added to make sure upgrade instructions properly highlight this change.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:4035

Built from 1092b96

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@Ivansete-status Ivansete-status left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for it! 💯
It sounds interesting to submit a separate PR to adjust the REST/presto part.
Cheers.

Comment thread apps/chat2/chat2.nim Outdated
waitFor c.node.rln.generateRLNProof(message.toRLNSignal(), float64(time))
try:
waitFor c.node.rln.generateRLNProof(message.toRLNSignal(), float64(time))
except CatchableError:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could instead handle the possible exception inside generateRLNProof so that we have better granularity of where it occurred. And therefore we can annotate that proc with .async: (raises: []).

if args.ethRpcEndpoint == "":
# Create a basic configuration for the Waku node
# No RLN as we don't have an ETH RPC Endpoint
conf.mode = Core

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seems aside from PR's purpose.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I explained above, the examples don't compile.

Comment thread examples/publisher.nim
const discv5Port = 9000

proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
proc setupAndPublish(rng: crypto.Rng) {.async.} =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that but seems unrelated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the examples are broken. I'm fixing them here.

Comment thread library/liblogosdelivery.nim Outdated
import logos_delivery/waku/compat/option_valueor
import std/[atomics, options, macros]
import chronicles, chronos, chronos/threadsync, ffi
import std/[atomics, macros], chronicles, chronos, chronos/threadsync, ffi

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, even though we not always do, we traditionally separated imports in three categories:

  1. std
  2. explicit nimbledeps (former vendor deps.)
  3. internal modules
Suggested change
import std/[atomics, macros], chronicles, chronos, chronos/threadsync, ffi
import std/[atomics, macros]
import chronicles, chronos, chronos/threadsync, ffi

Comment on lines +1 to +10
import
std/sets,
chronos,
web3,
stew/byteutils,
stint,
results,
chronicles,
logos_delivery/waku/incentivization/rpc,
tests/waku_rln_relay/utils_onchain

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import
std/sets,
chronos,
web3,
stew/byteutils,
stint,
results,
chronicles,
logos_delivery/waku/incentivization/rpc,
tests/waku_rln_relay/utils_onchain
import
std/sets,
chronos,
web3,
stew/byteutils,
stint,
results
import
chronicles
import
logos_delivery/waku/incentivization/rpc,
tests/waku_rln_relay/utils_onchain

mixin mtMarshalSizeValue
result = sizeof(uint8)
if value.isSome():
result += mtMarshalSizeValue(value.get())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid the use of implicit result value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, classic Claude.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the point, but I still want resurrect the Styler project sometime in the future. We've been using GenAI for a few months now, and I guess now I have better ideas about how to automate these recurrent style checks.

Comment on lines +4 to +10
std/options,
std/[strformat, sugar],
results,
chronicles,
uri,
json_serialization,
presto/route

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std/options,
std/[strformat, sugar],
results,
chronicles,
uri,
json_serialization,
presto/route
std/options,
std/[strformat, sugar],
results
import
chronicles,
uri,
json_serialization,
presto/route

chronicles,
chronos,
chronos/apps/http/httpserver
std/[strutils, net], regex, results, chronicles, chronos, chronos/apps/http/httpserver

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std/[strutils, net], regex, results, chronicles, chronos, chronos/apps/http/httpserver
std/[strutils, net], regex, results
import chronicles, chronos, chronos/apps/http/httpserver

Comment on lines +1 to +10
import
chronicles,
eth/keys,
stew/[arrayops, endians2],
stint,
results,
./rln_interface,
../conversion_utils,
../protocol_types,
../protocol_metrics

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import
chronicles,
eth/keys,
stew/[arrayops, endians2],
stint,
results,
./rln_interface,
../conversion_utils,
../protocol_types,
../protocol_metrics
import stew/[arrayops, endians2],
stint,
results
import
chronicles,
eth/keys
import
./rln_interface,
../conversion_utils,
../protocol_types,
../protocol_metrics

Comment on lines +1 to +9
import
results,
chronicles,
chronos,
metrics,
./common,
./rpc,
./rpc_codec,
../node/peer_manager

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import
results,
chronicles,
chronos,
metrics,
./common,
./rpc,
./rpc_codec,
../node/peer_manager
import
results
import
chronicles,
chronos,
metrics
import
./common,
./rpc,
./rpc_codec,
../node/peer_manager

@NagyZoltanPeter NagyZoltanPeter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My claude review found no serious issues with it. IMHO its better to get into master asap due to the wide blast of change radius.
Thanks for it.

@fcecin
fcecin merged commit ce918b0 into master Jul 16, 2026
14 checks passed
@fcecin
fcecin deleted the chore/migrate-opt branch July 16, 2026 17:02
NagyZoltanPeter added a commit that referenced this pull request Jul 16, 2026
Follow-up to the rebase onto master's repo-wide Option[T] -> Opt[T] change
(#4035). Converts the code this branch adds to the new convention:

- messaging/rest_api/types.nim: MessagingJsonEnvelope fields to Opt[T],
  Opt.some/Opt.none, and json_serialization/pkg/results instead of
  json_serialization/std/options.
- tests: WakuNodeConf.clusterId is now Opt[uint16]; DTO fields are Opt.

`Option[ContentBody]` in the handlers is presto's own API and stays as-is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
NagyZoltanPeter added a commit that referenced this pull request Jul 17, 2026
…bility (#4014)

* WIP logosdeliverynode app initial commit

* WIP - extra cli option

* WIP: messaging client REST endpoints

* Add event poll for messaging rest with cache mechanism

* Messaging rest tests

* test: assert 404 via raw string client in messaging REST test

presto's typed REST client raises RestDecodingError when it cannot decode
a non-2xx text error body into the response type. Add a RestResponse[string]
stub (messagingGetSendEventsByIdRawV1) and point the "already-polled id ->
404" assertion at it, matching the relay REST test pattern.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* remove customized cli args as confutils has no support for it

* Introduce --entry-layer and re-introduce --mode flags into cli args, applied new driver into LogosDelivery + tests

* Add messaging REST client test

* Add docker image build of logosdeliverynode for CI builds

* Fix tests

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Refactor Messaging REST API to better match Messaging Send and Receive APIs

* chore: migrate messaging REST API to Opt[T]

Follow-up to the rebase onto master's repo-wide Option[T] -> Opt[T] change
(#4035). Converts the code this branch adds to the new convention:

- messaging/rest_api/types.nim: MessagingJsonEnvelope fields to Opt[T],
  Opt.some/Opt.none, and json_serialization/pkg/results instead of
  json_serialization/std/options.
- tests: WakuNodeConf.clusterId is now Opt[uint16]; DTO fields are Opt.

`Option[ContentBody]` in the handlers is presto's own API and stays as-is.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor replace all Option (std/options) with Opt (results)

4 participants