From b593d16d11c3f61205743dfbf79b8859beac66b9 Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:25:21 +0200 Subject: [PATCH 01/13] tools: add sync-nimble-lock.sh to cross-check waku.nimble pins into nimble.lock (#3924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a portable (macOS bash 3.2 / Linux) helper that detects git-URL pinned `requires` in waku.nimble which changed vs a git base ref (default HEAD) and updates ONLY those nimble.lock entries — version, vcsRevision and the sha1 checksum — leaving every other entry byte-for-byte untouched. It does not run `nimble lock` (which rewrites the whole file). The sha1 is computed directly, reproducing nimble's algorithm from src/nimblepkg/checksums.nim (git ls-files -> sort -> SHA1 over path + symlink-target/file-bytes). Resolves tags to commits via git rev-parse and guards against invalid commit hashes (e.g. a stray leading character). Dry-run by default (exit 1 on drift); --apply writes; --base REF to compare against another ref. Requires git + python3; nimble not required. Co-authored-by: Claude Opus 4.8 --- tools/sync-nimble-lock.sh | 322 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 322 insertions(+) create mode 100755 tools/sync-nimble-lock.sh diff --git a/tools/sync-nimble-lock.sh b/tools/sync-nimble-lock.sh new file mode 100755 index 000000000..b55826327 --- /dev/null +++ b/tools/sync-nimble-lock.sh @@ -0,0 +1,322 @@ +#!/usr/bin/env bash +# +# sync-nimble-lock.sh +# +# Cross-check git-URL pinned `requires` in waku.nimble against nimble.lock and +# sync the lock entry for any pin that CHANGED relative to a git base ref +# (default: HEAD) -- and ONLY those entries. No other package is touched. +# +# It does NOT run `nimble lock` (which rewrites the whole file and churns +# unrelated packages). Instead it computes the package sha1 checksum itself, +# reproducing nimble's algorithm exactly (src/nimblepkg/checksums.nim): +# +# files = `git ls-files` in the package's git checkout at the pinned rev +# files.sort() # lexicographic +# sha1 = SHA1 over, for each existing regular file (in sorted order): +# update(relative_path_string) +# if symlink: update(symlink_target_string) +# else: update(file_bytes) # 8192-byte chunks +# +# For each changed pin it updates exactly three fields of the matching lock +# entry, preserving all formatting and every other entry byte-for-byte: +# version = "#" + (commit or tag) +# vcsRevision = git rev-parse of the ref (resolves tags) +# checksums.sha1 = the self-computed checksum +# +# The `dependencies` array is intentionally left untouched (see NOTE below). +# +# Usage: +# tools/sync-nimble-lock.sh # dry-run; exit 1 if drift +# tools/sync-nimble-lock.sh --apply # update nimble.lock +# tools/sync-nimble-lock.sh --base origin/master # compare against a ref +# +# Exit codes: 0 = in sync / applied, 1 = drift (dry-run), 2 = usage/tooling error +# +# Portable across macOS (bash 3.2, BSD tools) and Linux: all logic is in +# python3; bash only parses args and checks tools. Requires: git, python3. +# +# NOTE on `dependencies`: a version bump can in principle change a package's +# direct dependency set. Reproducing nimble's dependency-name normalization +# without running nimble is fragile, and the user-requested scope is +# version/vcsRevision/sha1. If a bumped dependency added/removed a `requires`, +# update its lock `dependencies` array by hand. The script warns when the +# bumped package's own .nimble `requires` count differs from the lock entry. + +set -euo pipefail + +APPLY=0 +BASE="HEAD" + +usage() { sed -n '2,55p' "$0" | sed 's/^#\{0,1\} \{0,1\}//'; } + +while [ $# -gt 0 ]; do + case "$1" in + --apply) APPLY=1 ;; + --base) shift; [ $# -gt 0 ] || { echo "error: --base needs a ref" >&2; exit 2; }; BASE="$1" ;; + --base=*) BASE="${1#*=}" ;; + -h|--help) usage; exit 0 ;; + *) echo "error: unknown argument: $1" >&2; exit 2 ;; + esac + shift +done + +command -v python3 >/dev/null 2>&1 || { echo "error: python3 is required" >&2; exit 2; } +command -v git >/dev/null 2>&1 || { echo "error: git is required" >&2; exit 2; } + +ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "error: not in a git repo" >&2; exit 2; } + +export SYNC_ROOT="$ROOT" SYNC_APPLY="$APPLY" SYNC_BASE="$BASE" SYNC_PKGCACHE="${HOME}/.nimble/pkgcache" + +exec python3 - <<'PYEOF' +import hashlib +import json +import os +import re +import shutil +import subprocess +import sys +import tempfile + +ROOT = os.environ["SYNC_ROOT"] +APPLY = os.environ["SYNC_APPLY"] == "1" +BASE = os.environ["SYNC_BASE"] +PKGCACHE = os.environ["SYNC_PKGCACHE"] + +NIMBLE_FILE = os.path.join(ROOT, "waku.nimble") +LOCK_FILE = os.path.join(ROOT, "nimble.lock") + +REQ_RE = re.compile(r'requires\s+"(https?://[^"#]+)#([^"]+)"') +COMMIT_RE = re.compile(r"^[0-9a-f]{40}$") +NEAR_HASH_RE = re.compile(r"^[0-9a-fx]{38,42}$") # catches the leading-`x` typo + + +def fail(msg): + sys.stderr.write("error: %s\n" % msg) + sys.exit(2) + + +def warn(msg): + sys.stderr.write("warning: %s\n" % msg) + + +def norm_url(url): + u = url.rstrip("/") + return u[:-4] if u.endswith(".git") else u + + +def git(args, cwd=None, check=True): + r = subprocess.run(["git"] + args, cwd=cwd, capture_output=True, text=True) + if check and r.returncode != 0: + fail("git %s failed: %s" % (" ".join(args), (r.stderr or r.stdout).strip())) + return r + + +# --------------------------------------------------------------------------- +# nimble checksum reproduction (verified byte-for-byte against nimble v0.22.3) +# --------------------------------------------------------------------------- +def compute_checksum(checkout_dir): + out = git(["-C", checkout_dir, "ls-files"]).stdout + files = out.strip().splitlines() + files.sort() + h = hashlib.sha1() + for rel in files: + path = os.path.join(checkout_dir, rel) + if not os.path.isfile(path): + # Skips directories / gitlinks / broken symlinks, matching nimble's + # `fileExists` guard (regular file or symlink-to-file only). + continue + h.update(rel.encode("utf-8")) + if os.path.islink(path): + h.update(os.readlink(path).encode("utf-8")) + else: + with open(path, "rb") as fh: + while True: + chunk = fh.read(8192) + if not chunk: + break + h.update(chunk) + return h.hexdigest() + + +def get_checkout(url, rev, tmpdir): + """Return (checkout_dir, cleanup_fn). Reuses ~/.nimble/pkgcache when the + exact commit is already cloned; otherwise clones from the URL.""" + # pkgcache dirs are suffixed with the commit sha (commit pins only). + if os.path.isdir(PKGCACHE): + for name in os.listdir(PKGCACHE): + if name.endswith("_" + rev) and os.path.isdir(os.path.join(PKGCACHE, name, ".git")): + cache = os.path.join(PKGCACHE, name) + git(["-C", cache, "checkout", "-q", rev]) + return cache, (lambda: None) + # Fall back to a fresh clone (network). Full clone, then checkout the ref. + dest = os.path.join(tmpdir, "clone") + print(" cloning %s ..." % url) + git(["clone", "--quiet", url, dest]) + r = git(["-C", dest, "checkout", "-q", rev], check=False) + if r.returncode != 0: + # commit may live on a ref not fetched by default; try fetching it + git(["-C", dest, "fetch", "--quiet", "origin", rev], check=False) + git(["-C", dest, "checkout", "-q", rev]) + return dest, (lambda: shutil.rmtree(dest, ignore_errors=True)) + + +def dep_requires_count(checkout_dir): + """Best-effort count of git/registry `requires` in the dep's .nimble file, + for a heads-up if the lock `dependencies` array may be stale.""" + nimbles = [f for f in os.listdir(checkout_dir) if f.endswith(".nimble")] + if not nimbles: + return None + try: + txt = open(os.path.join(checkout_dir, nimbles[0])).read() + except OSError: + return None + n = 0 + for m in re.finditer(r'requires\s+"([^"]+)"', txt): + n += len([p for p in m.group(1).split(",") if p.strip()]) + return n or None + + +# --------------------------------------------------------------------------- +# detect changes +# --------------------------------------------------------------------------- +def parse_changed(base): + r = git(["-C", ROOT, "diff", base, "--", "waku.nimble"], check=False) + if r.returncode != 0: + fail("git diff against %r failed: %s" % (base, r.stderr.strip())) + changed, seen = [], set() + for line in r.stdout.splitlines(): + if not line.startswith("+") or line.startswith("+++"): + continue + m = REQ_RE.search(line[1:]) + if not m: + continue + url, rev = m.group(1), m.group(2) + key = norm_url(url) + if key in seen: + continue + seen.add(key) + if not COMMIT_RE.match(rev) and NEAR_HASH_RE.match(rev): + fail("invalid commit hash for %s: %r is not a valid 40-char hex SHA " + "(stray character / typo?)" % (url, rev)) + changed.append((url, rev)) + return changed + + +# --------------------------------------------------------------------------- +# surgical lock patch (text-level: preserves formatting & all other entries) +# --------------------------------------------------------------------------- +PKG_OPEN_RE = re.compile(r'^\s{4}"[^"]+":\s*\{\s*$') +PKG_CLOSE_RE = re.compile(r'^\s{4}\},?\s*$') + + +def set_value(line, key, val): + return re.sub(r'(^\s*"' + re.escape(key) + r'":\s*")[^"]*(")', + lambda m: m.group(1) + val + m.group(2), line, count=1) + + +def patch_lock_text(text, url, version, vcs_rev, sha1): + lines = text.splitlines(keepends=True) + url_re = re.compile(r'^\s*"url":\s*"' + re.escape(url) + r'"\s*,?\s*$') + ui = next((i for i, l in enumerate(lines) if url_re.match(l)), None) + if ui is None: + return None + # block bounds + start = next(i for i in range(ui, -1, -1) if PKG_OPEN_RE.match(lines[i])) + end = next(i for i in range(ui, len(lines)) if PKG_CLOSE_RE.match(lines[i])) + done = set() + for i in range(start, end + 1): + if "version" not in done and re.match(r'^\s*"version":', lines[i]): + lines[i] = set_value(lines[i], "version", version); done.add("version") + elif "vcsRevision" not in done and re.match(r'^\s*"vcsRevision":', lines[i]): + lines[i] = set_value(lines[i], "vcsRevision", vcs_rev); done.add("vcsRevision") + elif "sha1" not in done and re.match(r'^\s*"sha1":', lines[i]): + lines[i] = set_value(lines[i], "sha1", sha1); done.add("sha1") + missing = {"version", "vcsRevision", "sha1"} - done + if missing: + fail("could not locate field(s) %s in lock block for %s" % (sorted(missing), url)) + return "".join(lines) + + +# --------------------------------------------------------------------------- +def main(): + for p in (NIMBLE_FILE, LOCK_FILE): + if not os.path.isfile(p): + fail("%s not found" % p) + + changed = parse_changed(BASE) + if not changed: + print("No changed git-URL `requires` in waku.nimble vs %s — nothing to sync." % BASE) + return 0 + + lock = json.load(open(LOCK_FILE)) + by_url = {} + for name, e in lock.get("packages", {}).items(): + if e.get("url"): + by_url[norm_url(e["url"])] = (name, e) + + drift = [] # (url, rev, name_or_None, cur_version_or_None) + for url, rev in changed: + hit = by_url.get(norm_url(url)) + want = "#" + rev + if hit is None: + drift.append((url, rev, None, None)) + elif hit[1].get("version") != want: + drift.append((url, rev, hit[0], hit[1].get("version"))) + + if not drift: + print("nimble.lock already in sync with waku.nimble (%d changed pin(s) checked)." % len(changed)) + return 0 + + print("Dependency drift (waku.nimble vs nimble.lock):") + for url, rev, name, cur in drift: + tag = name or "(missing)" + print(" ~ %s [%s]\n waku.nimble: #%s\n nimble.lock: %s" % (url, tag, rev, cur)) + + if not APPLY: + print("\nRun with --apply to update nimble.lock (computes checksum itself; no `nimble lock`).") + return 1 + + print("\nApplying (computing checksums; not running `nimble lock`)...") + text = open(LOCK_FILE).read() + updated = [] + tmproot = tempfile.mkdtemp(prefix="sync-nimble-lock.") + try: + for url, rev, name, _cur in drift: + if name is None: + fail("%s has no entry in nimble.lock; this script updates existing " + "entries only (add new deps with a normal nimble install first)." % url) + sub = os.path.join(tmproot, re.sub(r"\W+", "_", norm_url(url))) + os.makedirs(sub, exist_ok=True) + checkout, cleanup = get_checkout(url, rev, sub) + try: + vcs_rev = git(["-C", checkout, "rev-parse", "HEAD"]).stdout.strip() + sha1 = compute_checksum(checkout) + # dependency-drift heads-up + cnt = dep_requires_count(checkout) + lock_deps = len(by_url[norm_url(url)][1].get("dependencies", [])) + if cnt is not None and lock_deps and cnt != lock_deps: + warn("%s: .nimble has %d `requires` but lock lists %d dependencies; " + "review the `dependencies` array manually." % (name, cnt, lock_deps)) + finally: + cleanup() + new_text = patch_lock_text(text, url, "#" + rev, vcs_rev, sha1) + if new_text is None: + fail("could not find lock block for url %s" % url) + text = new_text + updated.append((name, "#" + rev, vcs_rev, sha1)) + finally: + shutil.rmtree(tmproot, ignore_errors=True) + + with open(LOCK_FILE, "w") as f: + f.write(text) + + print("\nUpdated nimble.lock (only these entries; all others untouched):") + for name, ver, vcs, sha1 in updated: + print(" %-16s version=%s" % (name, ver)) + print(" %-16s vcsRevision=%s" % ("", vcs)) + print(" %-16s sha1=%s" % ("", sha1)) + return 0 + + +sys.exit(main()) +PYEOF From 64a0ed7d967454d9c3b345023719e6ca5d73f129 Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:25:51 +0200 Subject: [PATCH 02/13] Add helper nimble task to ease nph formatting on branch/pr's changed nim files -> nimble nphchanges (#3926) --- waku.nimble | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/waku.nimble b/waku.nimble index da5b87eb6..99f649758 100644 --- a/waku.nimble +++ b/waku.nimble @@ -528,3 +528,67 @@ task liblogosdeliveryStaticLinux, "Generate bindings": task liblogosdeliveryStaticMac, "Generate bindings": buildLibStaticMac("liblogosdelivery", "liblogosdelivery") + +### Formatting tasks + +task nphchanges, "Run nph on .nim/.nims/.nimble files changed on this branch/PR": + ## Formats every Nim source file that differs from the base branch. + ## The set covers committed changes on the branch, working-tree edits + ## (staged or not) and untracked files. The base branch is auto-detected + ## (origin's default branch, else local main/master); override it with + ## the NPH_BASE_BRANCH env var. + let nph = + if findExe("nph").len > 0: findExe("nph") + else: getHomeDir() / ".nimble" / "bin" / "nph" + if not fileExists(nph): + quit "nph not found. Run `make build-nph` first.", 1 + + proc detectBaseBranch(): string = + # Explicit override wins. + if existsEnv("NPH_BASE_BRANCH"): + return getEnv("NPH_BASE_BRANCH") + # origin's default branch, e.g. "origin/main" -> "main". + let (head, hCode) = + gorgeEx("git symbolic-ref --short refs/remotes/origin/HEAD") + if hCode == 0 and head.strip().len > 0: + let parts = head.strip().split('/') + return parts[^1] + # Fall back to whichever local branch exists. + for candidate in ["main", "master"]: + let (_, vCode) = + gorgeEx("git rev-parse --verify --quiet " & candidate) + if vCode == 0: + return candidate + return "master" + + let baseBranch = detectBaseBranch() + + # Diff against the merge-base so we only touch what this branch introduced. + var diffRef = baseBranch + let (mergeBase, mbCode) = gorgeEx("git merge-base HEAD " & baseBranch) + if mbCode == 0 and mergeBase.strip().len > 0: + diffRef = mergeBase.strip() + + let (changed, dCode) = gorgeEx("git diff --name-only --diff-filter=ACMR " & diffRef) + if dCode != 0: + quit "git diff failed: " & changed, 1 + let (untracked, _) = gorgeEx("git ls-files --others --exclude-standard") + + var files: seq[string] + for line in (changed & "\n" & untracked).splitLines(): + let f = line.strip() + if f.len == 0: + continue + if not (f.endsWith(".nim") or f.endsWith(".nims") or f.endsWith(".nimble")): + continue + if fileExists(f) and f notin files: + files.add(f) + + if files.len == 0: + echo "nphchanges: no changed .nim/.nims/.nimble files to format" + return + + echo "nphchanges: formatting " & $files.len & " file(s) (base: " & baseBranch & ")" + for f in files: + echo "Formatting " & f + exec nph & " \"" & f & "\"" From 4099ff26382480ae2946f27087b430323330799e Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Wed, 3 Jun 2026 19:30:51 +0200 Subject: [PATCH 03/13] Pin nim-ffi to v0.1.3 in waku.nimble (#3928) --- waku.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku.nimble b/waku.nimble index 99f649758..2b3c6ef7b 100644 --- a/waku.nimble +++ b/waku.nimble @@ -59,7 +59,7 @@ requires "nim >= 2.2.4", "unittest2" # Packages not on nimble (use git URLs) -requires "https://github.com/logos-messaging/nim-ffi" +requires "https://github.com/logos-messaging/nim-ffi#v0.1.3" requires "https://github.com/logos-messaging/nim-sds.git#2e9a7683f0e180bf112135fae3a3803eed8490d4" From deb6929670385371ec67a1dadba9856138795881 Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Thu, 4 Jun 2026 10:53:02 +0200 Subject: [PATCH 04/13] feat: introduce SDS persistency glue (#3913) * persistency: follow nim-sds 0.3.0 snapshot persistence contract nim-sds 0.3.0 replaced the ~14 fine-grained per-row Persistence callbacks with a 5-proc snapshot model (saveChannelMeta / updateHistory / loadChannel / dropChannel / setRetrievalHint), all returning Future[Result[...]]. Rewrite waku/persistency/sds_persistency.nim accordingly: - ChannelMeta is stored as one blob per channel; the message log as append/evict rows. Categories collapse from 7 to 2 (sds.meta, sds.log). - Blob transform uses nim-sds' own codecs: snapshot_codec (schema-versioned protobuf) for ChannelMeta, the SDS wire codec for SdsMessage log rows. The generic payload_codec/BlobCodec path is retired (removed payload_codec.nim and test_blob_codec.nim). - setRetrievalHint is a deliberate no-op: persisted hints are never read back (loadChannel/ChannelMeta carry none; hints are supplied live via the onRetrievalHint provider). The closure stays because the field is required. - Fix the module import spelling (srcDir="sds" => bare module paths), which the previous adapter got wrong and never compiled against the locked deps. Add tests/persistency/test_sds_persistency.nim (round-trip, empty-load, evict, drop) replacing test_blob_codec in test_all. Full persistency suite passes 74/74 under both refc and ORC. * Bump to latest nim-sds and nim-brokers 3.1.1 * Update with latest nim-sds changes - removal of setRetrievalHints - not needed --- nimble.lock | 12 +- tests/persistency/test_all.nim | 1 + tests/persistency/test_sds_persistency.nim | 155 ++++++++++++++++++ waku.nimble | 12 +- waku/persistency/backend_comm.nim | 4 +- waku/persistency/backend_sqlite.nim | 35 +++- waku/persistency/persistency.nim | 12 ++ waku/persistency/sds_persistency.nim | 176 +++++++++++++++++++++ waku/persistency/types.nim | 3 + waku/waku_persistency.nim | 3 + 10 files changed, 395 insertions(+), 18 deletions(-) create mode 100644 tests/persistency/test_sds_persistency.nim create mode 100644 waku/persistency/sds_persistency.nim create mode 100644 waku/waku_persistency.nim diff --git a/nimble.lock b/nimble.lock index cd533001e..4bdb8bb82 100644 --- a/nimble.lock +++ b/nimble.lock @@ -328,8 +328,8 @@ } }, "brokers": { - "version": "#v2.0.1", - "vcsRevision": "2093ca4d50e581adda73fee7fd16231f990f4cbe", + "version": "#v3.1.1", + "vcsRevision": "a7316a35f1b62e3497ae8ee0fc1aace74df0beb2", "url": "https://github.com/NagyZoltanPeter/nim-brokers.git", "downloadMethod": "git", "dependencies": [ @@ -341,7 +341,7 @@ "cbor_serialization" ], "checksums": { - "sha1": "cc74c987af94537e9d44d1b0143aa417299040c5" + "sha1": "4447d7c1f9da14ae439afb23aee45116ce2ecb40" } }, "stint": { @@ -620,8 +620,8 @@ } }, "sds": { - "version": "#2e9a7683f0e180bf112135fae3a3803eed8490d4", - "vcsRevision": "2e9a7683f0e180bf112135fae3a3803eed8490d4", + "version": "#abdd40cc645f1b024c3ee99cced7e287c4e4c441", + "vcsRevision": "abdd40cc645f1b024c3ee99cced7e287c4e4c441", "url": "https://github.com/logos-messaging/nim-sds.git", "downloadMethod": "git", "dependencies": [ @@ -636,7 +636,7 @@ "taskpools" ], "checksums": { - "sha1": "d13f1bf8d1b90b27e9edfc063b043831242cda19" + "sha1": "61c4ae13c6896bfa70e662520e8660a78c7f438c" } }, "ffi": { diff --git a/tests/persistency/test_all.nim b/tests/persistency/test_all.nim index 194977692..5b0cfdbb5 100644 --- a/tests/persistency/test_all.nim +++ b/tests/persistency/test_all.nim @@ -5,5 +5,6 @@ import ./test_backend import ./test_lifecycle import ./test_facade import ./test_encoding +import ./test_sds_persistency import ./test_string_lookup import ./test_singleton diff --git a/tests/persistency/test_sds_persistency.nim b/tests/persistency/test_sds_persistency.nim new file mode 100644 index 000000000..ed14f904b --- /dev/null +++ b/tests/persistency/test_sds_persistency.nim @@ -0,0 +1,155 @@ +{.used.} + +## Behavioural tests for the SDS Persistence adapter (nim-sds 0.3.0 snapshot +## model). Importing `sds_persistency` also compile-checks the real adapter. +## +## Writes go through the fire-and-forget Job path (the Future resolves when +## the op is queued, not applied — Persistency v1), so every read-back polls +## until the row appears/disappears. + +import std/[options, os, times] +import chronos, results +import testutils/unittests +import waku/persistency/persistency +import waku/persistency/keys +import waku/persistency/sds_persistency + +proc tmpRoot(label: string): string = + let p = getTempDir() / ("sds_persistency_test_" & label & "_" & $epochTime().int) + removeDir(p) + p + +proc pollExists( + t: Job, category: string, k: Key, timeoutMs = 1000 +): Future[bool] {.async.} = + let deadline = epochTime() + (timeoutMs.float / 1000.0) + while epochTime() < deadline: + let r = await t.exists(category, k) + if r.isOk and r.get(): + return true + await sleepAsync(chronos.milliseconds(2)) + return false + +proc pollGone( + t: Job, category: string, k: Key, timeoutMs = 1000 +): Future[bool] {.async.} = + let deadline = epochTime() + (timeoutMs.float / 1000.0) + while epochTime() < deadline: + let r = await t.exists(category, k) + if r.isOk and not r.get(): + return true + await sleepAsync(chronos.milliseconds(2)) + return false + +proc mkMsg(channelId: SdsChannelID, msgId: SdsMessageID, lamport: int64): SdsMessage = + SdsMessage.init( + messageId = msgId, + lamportTimestamp = lamport, + causalHistory = @[], + channelId = channelId, + content = @[byte(1), byte(2)], + bloomFilter = @[], + ) + +suite "SDS persistency adapter (0.3.0 snapshot model)": + asyncTest "saveChannelMeta + updateHistory round-trip via loadChannel": + let root = tmpRoot("roundtrip") + defer: + removeDir(root) + let p = Persistency.instance(root).get() + defer: + Persistency.reset() + let job = p.openJob("sds").get() + let persistence = newSdsPersistence(job) + let channelId = "chan-1".SdsChannelID + + var meta = ChannelMeta.init() + meta.lamportTimestamp = 42 + check (await persistence.saveChannelMeta(channelId, meta)).isOk + check (await job.pollExists(CatMeta, toKey(channelId))) + + # append out of (lamport) order on purpose; loadChannel must sort. + var upd = HistoryUpdate.init() + upd.append = @[mkMsg(channelId, "m2", 2), mkMsg(channelId, "m1", 1)] + check (await persistence.updateHistory(channelId, upd)).isOk + check (await job.pollExists(CatLog, key(channelId, "m2"))) + + let data = (await persistence.loadChannel(channelId)).valueOr: + check false + return + check data.meta.lamportTimestamp == 42 + check data.messageHistory.len == 2 + check data.messageHistory[0].messageId == "m1" + check data.messageHistory[1].messageId == "m2" + + asyncTest "loadChannel on a fresh channel returns empty ChannelData": + let root = tmpRoot("empty") + defer: + removeDir(root) + let p = Persistency.instance(root).get() + defer: + Persistency.reset() + let job = p.openJob("sds").get() + let persistence = newSdsPersistence(job) + + let data = (await persistence.loadChannel("nope".SdsChannelID)).valueOr: + check false + return + check data.meta.lamportTimestamp == 0 + check data.messageHistory.len == 0 + + asyncTest "updateHistory evict removes a log row": + let root = tmpRoot("evict") + defer: + removeDir(root) + let p = Persistency.instance(root).get() + defer: + Persistency.reset() + let job = p.openJob("sds").get() + let persistence = newSdsPersistence(job) + let channelId = "c".SdsChannelID + + var upd = HistoryUpdate.init() + upd.append = @[mkMsg(channelId, "a", 1), mkMsg(channelId, "b", 2)] + check (await persistence.updateHistory(channelId, upd)).isOk + check (await job.pollExists(CatLog, key(channelId, "b"))) + + var ev = HistoryUpdate.init() + ev.evict = @["a".SdsMessageID] + check (await persistence.updateHistory(channelId, ev)).isOk + check (await job.pollGone(CatLog, key(channelId, "a"))) + + let data = (await persistence.loadChannel(channelId)).valueOr: + check false + return + check data.messageHistory.len == 1 + check data.messageHistory[0].messageId == "b" + + asyncTest "dropChannel wipes meta and log": + let root = tmpRoot("drop") + defer: + removeDir(root) + let p = Persistency.instance(root).get() + defer: + Persistency.reset() + let job = p.openJob("sds").get() + let persistence = newSdsPersistence(job) + let channelId = "d".SdsChannelID + + var meta = ChannelMeta.init() + meta.lamportTimestamp = 7 + check (await persistence.saveChannelMeta(channelId, meta)).isOk + var upd = HistoryUpdate.init() + upd.append = @[mkMsg(channelId, "x", 1)] + check (await persistence.updateHistory(channelId, upd)).isOk + check (await job.pollExists(CatMeta, toKey(channelId))) + check (await job.pollExists(CatLog, key(channelId, "x"))) + + check (await persistence.dropChannel(channelId)).isOk + check (await job.pollGone(CatMeta, toKey(channelId))) + + let data = (await persistence.loadChannel(channelId)).valueOr: + check false + return + check data.meta.lamportTimestamp == 0 + check data.messageHistory.len == 0 diff --git a/waku.nimble b/waku.nimble index 2b3c6ef7b..4ed98917e 100644 --- a/waku.nimble +++ b/waku.nimble @@ -61,17 +61,9 @@ requires "nim >= 2.2.4", # Packages not on nimble (use git URLs) requires "https://github.com/logos-messaging/nim-ffi#v0.1.3" -requires "https://github.com/logos-messaging/nim-sds.git#2e9a7683f0e180bf112135fae3a3803eed8490d4" +requires "https://github.com/logos-messaging/nim-sds.git#abdd40cc645f1b024c3ee99cced7e287c4e4c441" -# brokers: pinned by URL+commit rather than the bare `brokers >= 2.0.1` -# form because the nim-lang/packages registry entry for `brokers` only -# carries metadata for the original v0.1.0 publication. Until that -# registry entry is refreshed, the local SAT solver enumerates "0.1.0" -# as the only available version and cannot satisfy `>= 2.0.1`. The URL -# pin below bypasses the registry and locks the exact commit of the -# v2.0.1 tag. Revert to the bare form once nim-lang/packages is -# updated. -requires "https://github.com/NagyZoltanPeter/nim-brokers.git#v2.0.1" +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" diff --git a/waku/persistency/backend_comm.nim b/waku/persistency/backend_comm.nim index dd7e71297..193e52825 100644 --- a/waku/persistency/backend_comm.nim +++ b/waku/persistency/backend_comm.nim @@ -68,7 +68,7 @@ proc mtMarshalValue*( of txPut: if not mtMarshalValue(buf, cap, value.payload, pos): return false - of txDelete: + of txDelete, txDeletePrefix: discard return true @@ -93,6 +93,8 @@ proc mtUnmarshalValue*( value = TxOp(category: category, key: key, kind: txPut, payload: payload) of txDelete: value = TxOp(category: category, key: key, kind: txDelete) + of txDeletePrefix: + value = TxOp(category: category, key: key, kind: txDeletePrefix) return true EventBroker(mt): diff --git a/waku/persistency/backend_sqlite.nim b/waku/persistency/backend_sqlite.nim index 6851febc1..95757bc2c 100644 --- a/waku/persistency/backend_sqlite.nim +++ b/waku/persistency/backend_sqlite.nim @@ -7,7 +7,7 @@ import std/options import results, sqlite3_abi import ../common/databases/[common, db_sqlite] -import ./[types, schema] +import ./[types, keys, schema] type KvBackend* = ref object @@ -121,6 +121,37 @@ proc close*(b: KvBackend) = b.db.close() b.db = nil +proc deletePrefix( + b: KvBackend, category: string, prefix: Key +): Result[void, PersistencyError] = + let rng = prefixRange(prefix) + let openEnded = bytes(rng.stop).len == 0 + let sql = + if openEnded: + "DELETE FROM kv WHERE category = ? AND key >= ?;" + else: + "DELETE FROM kv WHERE category = ? AND key >= ? AND key < ?;" + var s: ptr sqlite3_stmt + let rc = sqlite3_prepare_v2(b.db.env, sql.cstring, sql.len.cint, addr s, nil) + if rc != SQLITE_OK: + return err(toErr("deletePrefix prepare: " & $sqlite3_errstr(rc))) + defer: + discard sqlite3_finalize(s) + var bc = bindBlob(s, 1.cint, catBytes(category)) + if bc != SQLITE_OK: + return err(toErr("deletePrefix bind cat: " & $sqlite3_errstr(bc))) + bc = bindBlob(s, 2.cint, keyBytes(rng.start)) + if bc != SQLITE_OK: + return err(toErr("deletePrefix bind start: " & $sqlite3_errstr(bc))) + if not openEnded: + bc = bindBlob(s, 3.cint, keyBytes(rng.stop)) + if bc != SQLITE_OK: + return err(toErr("deletePrefix bind stop: " & $sqlite3_errstr(bc))) + let v = sqlite3_step(s) + if v != SQLITE_DONE: + return err(toErr("deletePrefix step: " & $sqlite3_errstr(v))) + return ok() + proc applyOne(b: KvBackend, op: TxOp): Result[void, PersistencyError] = case op.kind of txPut: @@ -131,6 +162,8 @@ proc applyOne(b: KvBackend, op: TxOp): Result[void, PersistencyError] = let r = b.deleteStmt.exec((catBytes(op.category), keyBytes(op.key))) if r.isErr: return err(toErr("delete failed: " & r.error)) + of txDeletePrefix: + ?b.deletePrefix(op.category, op.key) return ok() proc execSql(b: KvBackend, sql: string): Result[void, PersistencyError] = diff --git a/waku/persistency/persistency.nim b/waku/persistency/persistency.nim index 916f3ac8b..1e070dbb5 100644 --- a/waku/persistency/persistency.nim +++ b/waku/persistency/persistency.nim @@ -284,6 +284,11 @@ proc persistPut*( proc persistDelete*(t: Job, category: string, key: Key): Future[void] {.async.} = await persist(t, TxOp(category: category, key: key, kind: txDelete)) +proc persistDeletePrefix*( + t: Job, category: string, prefix: Key +): Future[void] {.async.} = + await persist(t, TxOp(category: category, key: prefix, kind: txDeletePrefix)) + proc persistEncoded*[T]( t: Job, category: string, key: Key, value: T ): Future[void] {.async.} = @@ -335,6 +340,13 @@ proc persistDelete*( if not j.isNil(): await j.persistDelete(category, key) +proc persistDeletePrefix*( + p: Persistency, jobId: string, category: string, prefix: Key +): Future[void] {.async.} = + let j = p.jobOrWarn(jobId) + if not j.isNil(): + await j.persistDeletePrefix(category, prefix) + proc persistEncoded*[T]( p: Persistency, jobId: string, category: string, key: Key, value: T ): Future[void] {.async.} = diff --git a/waku/persistency/sds_persistency.nim b/waku/persistency/sds_persistency.nim new file mode 100644 index 000000000..3c44f7802 --- /dev/null +++ b/waku/persistency/sds_persistency.nim @@ -0,0 +1,176 @@ +## Adapter that materialises the SDS `Persistence` contract (nim-sds 0.3.0, +## snapshot model) on top of a waku-persistency `Job`. One `Job` (== one +## SQLite file, one worker thread) services all channels for a given SDS +## context; rows are namespaced by category and the channelId is the first +## key component so per-channel prefix scans stay cheap. +## +## ## Snapshot contract (nim-sds 0.3.0) +## +## The fine-grained per-row callbacks of 0.2.4 are gone. SDS now persists via +## five procs, all `Future[Result[void, string]]` (load returns +## `Result[ChannelData, string]`), `{.async: (raises: []), gcsafe.}`: +## +## * **`saveChannelMeta`** — the complete fast-changing per-channel state +## (lamport clock, outgoing/incoming buffers, both SDS-R repair buffers) +## as ONE blob. Idempotent; a missed write self-heals on the next save. +## * **`updateHistory`** — append newly-delivered messages / evict the +## oldest past the cap, applied as one transactional batch. +## * **`loadChannel`** — bootstrap: returns the prior `ChannelData` +## (meta + ordered message history) or an empty one. Surfaces errors. +## * **`dropChannel`** — wipe all state for a channel. Surfaces errors. +## +## Failure policy mirrors the interface docs: save/update/hint are non-fatal +## (we log and still return the error string); load/drop are durability-intent +## and propagate their error to the caller. +## +## ## Codec +## +## The blob transform is owned by nim-sds: `ChannelMeta` round-trips through +## `sds/snapshot_codec` (protobuf, schema-versioned — refuses unknown +## versions), and each persisted `SdsMessage` log row through the SDS wire +## codec in `sds/protobuf`. We do not maintain a second codec for these +## shapes (the previous `payload_codec`/`BlobCodec` path is retired). +## +## ## Retrieval hints +## +## `setRetrievalHint` is intentionally a no-op: persisted hints are never read +## back — `loadChannel` returns `ChannelData` (meta + messageHistory) with no +## hint field, and `ChannelMeta` carries none. Hints are supplied live via the +## `onRetrievalHint` provider, so persisting them would be write-only dead +## data. The closure still exists because the field is required by the +## `Persistence` object (SDS calls it from `getRecentHistoryEntries`). +## +## ## Storage layout +## +## | Category | Key | Value | +## |---------------|--------------------------|----------------------------------------| +## | `sds.meta` | `key(channelId)` | `ChannelMeta` (snapshot_codec protobuf)| +## | `sds.log` | `key(channelId, msgId)` | `SdsMessage` (sds wire protobuf) | +## +## `messageHistory` is reconstructed in memory by sorting on +## `(lamportTimestamp, messageId)` — the same total order SDS uses for +## delivery (see sds/sds_utils.nim). + +{.push raises: [].} + +import std/[algorithm, options] +import chronos, chronicles, results +import libp2p/protobuf/minprotobuf +import ./persistency +import ./keys +import types/persistence +import snapshot_codec +import protobuf + +export persistence, persistency + +logScope: + topics = "sds-persistency" + +const + CatMeta* = "sds.meta" + CatLog* = "sds.log" + +# ── Public factory ────────────────────────────────────────────────────── + +proc newSdsPersistence*(job: Job): Persistence {.gcsafe, raises: [].} = + ## Build an SDS `Persistence` value backed by ``job``. One Job services + ## all channels — channelId is part of every key. + ## + ## The closures capture ``job`` by ref. They must be invoked from a thread + ## that owns a running chronos loop (the SDS context's worker thread + ## satisfies this). + doAssert not job.isNil, "newSdsPersistence: job is nil" + + # Built field-by-field via assignment rather than an object literal: every + # field is an async closure whose body uses `await`/`return` statements, + # which cannot be followed by the `,` field separator a `Persistence(..)` + # literal would require. Assignments have no separator, so bodies stay plain. + var persistence = Persistence() + + persistence.saveChannelMeta = proc( + channelId: SdsChannelID, meta: ChannelMeta + ): Future[Result[void, string]] {.async: (raises: []), gcsafe.} = + try: + await job.persistPut(CatMeta, toKey(channelId), encode(meta).buffer) + return ok() + except CatchableError as e: + warn "sds-persistency: saveChannelMeta failed", channelId, err = e.msg + return err(e.msg) + + persistence.updateHistory = proc( + channelId: SdsChannelID, update: HistoryUpdate + ): Future[Result[void, string]] {.async: (raises: []), gcsafe.} = + if update.isEmpty: + return ok() + # One transactional batch: append rows (txPut) and evictions (txDelete). + var ops = newSeq[TxOp]() + for m in update.append: + ops.add TxOp( + category: CatLog, + key: key(channelId, m.messageId), + kind: txPut, + payload: encode(m).buffer, + ) + for id in update.evict: + ops.add TxOp(category: CatLog, key: key(channelId, id), kind: txDelete) + try: + await job.persist(ops) + return ok() + except CatchableError as e: + warn "sds-persistency: updateHistory failed", + channelId, appended = update.append.len, evicted = update.evict.len, err = e.msg + return err(e.msg) + + persistence.loadChannel = proc( + channelId: SdsChannelID + ): Future[Result[ChannelData, string]] {.async: (raises: []), gcsafe.} = + let chanKey = toKey(channelId) + var data = ChannelData.init() + try: + block meta: + let opt = (await job.get(CatMeta, chanKey)).valueOr: + return err("loadChannel: get meta: " & $error) + if opt.isSome: + # schema-versioned decode; refuses unknown versions loudly. + data.meta = ChannelMeta.decode(opt.get).valueOr: + return err("loadChannel: corrupt or unsupported ChannelMeta blob") + + block history: + let rows = (await job.scanPrefix(CatLog, chanKey)).valueOr: + return err("loadChannel: scan log: " & $error) + var msgs = newSeq[SdsMessage]() + for row in rows: + let m = SdsMessage.decode(row.payload).valueOr: + warn "sds-persistency: skipping undecodable log row", channelId + continue + msgs.add(m) + msgs.sort do(a, b: SdsMessage) -> int: + result = cmp(a.lamportTimestamp, b.lamportTimestamp) + if result == 0: + result = cmp(a.messageId, b.messageId) + data.messageHistory = msgs + + return ok(data) + except CatchableError as e: + return err("loadChannel: " & e.msg) + + persistence.dropChannel = proc( + channelId: SdsChannelID + ): Future[Result[void, string]] {.async: (raises: []), gcsafe.} = + let chanKey = toKey(channelId) + try: + await job.persist( + @[ + TxOp(category: CatLog, key: chanKey, kind: txDeletePrefix), + TxOp(category: CatMeta, key: chanKey, kind: txDelete), + ] + ) + return ok() + except CatchableError as e: + error "sds-persistency: dropChannel failed", channelId, err = e.msg + return err(e.msg) + + return persistence + +{.pop.} diff --git a/waku/persistency/types.nim b/waku/persistency/types.nim index 4c4c2de3f..0fdf12af0 100644 --- a/waku/persistency/types.nim +++ b/waku/persistency/types.nim @@ -19,6 +19,7 @@ type TxOpKind* = enum txPut txDelete + txDeletePrefix TxOp* = object category*: string @@ -28,6 +29,8 @@ type payload*: seq[byte] of txDelete: discard + of txDeletePrefix: + discard PersistencyErrorKind* = enum peBackend diff --git a/waku/waku_persistency.nim b/waku/waku_persistency.nim new file mode 100644 index 000000000..5eb94e3f0 --- /dev/null +++ b/waku/waku_persistency.nim @@ -0,0 +1,3 @@ +import waku/persistency/persistency + +export persistency From 86e424c82ca2a96b93880698e0b8d5dcbdc2581e Mon Sep 17 00:00:00 2001 From: Tanya S <120410716+stubbsta@users.noreply.github.com> Date: Thu, 4 Jun 2026 16:02:25 +0200 Subject: [PATCH 05/13] chore: retrieve cache of merkle roots from RLN contract (#3903) * Only add new roots, not all received * Fix error in removing recent roots not checking AcceptableWindowSize * fix merging * more merging fixes * merge fixes * add test for updated merkle roots window * add pr re-add gauge for proof-generation-duration-seconds * Decrease AcceptableRootWindowSize for testing * debug spam log * linting * start trackRootChanges call loop immediately * Fix 5s delay trackRootChanges * set rpcDelay for root tracking to 10s * add default params to sendEthCallWithParams * improve recents roots retrieval and logs * Use updateRecentRoots to track root changes * simplify updateRecentRoots * set root polling to 15s * set rpc poll delay to 30s * set acceptablerootwindowsize and root poll delay * Improve test 'should fetch history correctly' for root cache * Make root cache handling more efficient * add contract root cache size as constant and function use fix * updateRecentRoots comments update * Update group_manager and tests * fix linting --- .../test_rln_group_manager_onchain.nim | 91 ++++++++++++++-- waku/waku_rln_relay/constants.nim | 3 + .../group_manager/on_chain/group_manager.nim | 102 +++++++++++++++--- .../group_manager/on_chain/rpc_wrapper.nim | 2 +- 4 files changed, 173 insertions(+), 25 deletions(-) diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 6b5b81532..6af5bb0f2 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -97,7 +97,8 @@ suite "Onchain group manager": check: merkleRootBefore != merkleRootAfter - test "trackRootChanges: should fetch history correctly": + test "trackRootChanges: should fetch history correctly: fetch single root()": + # basic check for the soon to be deprecated root contract function, is replaced by getRecentRoots() # TODO: We can't use `trackRootChanges()` directly in this test because its current implementation # relies on a busy loop rather than event-based monitoring. but that busy loop fetch root every 5 seconds # so we can't use it in this test. @@ -107,7 +108,8 @@ suite "Onchain group manager": (waitFor manager.init()).isOkOr: raiseAssert $error - let merkleRootBefore = waitFor manager.fetchMerkleRoot() + let merkleRootBefore = (waitFor manager.fetchMerkleRoot()).valueOr: + raiseAssert "Failed to fetch merkle root before: " & error for i in 0 ..< credentials.len(): info "Registering credential", index = i, credential = credentials[i] @@ -115,12 +117,83 @@ suite "Onchain group manager": assert false, "Failed to register credential " & $i & ": " & error discard waitFor manager.updateRoots() - let merkleRootAfter = waitFor manager.fetchMerkleRoot() + let merkleRootAfter = (waitFor manager.fetchMerkleRoot()).valueOr: + raiseAssert "Failed to fetch merkle root after: " & error check: merkleRootBefore != merkleRootAfter manager.validRoots.len() == credentialCount + test "trackRootChanges: should fetch history correctly: fetch root cache": + # Verify that the group_manager list of valid roots is updated correctly from the recent roots + # cache as new credentials are registered. + # TODO: We can't use `trackRootChanges()` directly in this test because its current implementation + # relies on a busy loop rather than event-based monitoring. but that busy loop fetch root every 5 seconds + # so we can't use it in this test. + + const credentialCount = RlnContractRootCacheSize + let credentials = generateCredentials(credentialCount) + (waitFor manager.init()).isOkOr: + raiseAssert $error + + let merkleRootCacheBefore = (waitFor manager.fetchMerkleRootsCache()).valueOr: + raiseAssert "Failed to fetch merkle root cache before: " & error + + check: + merkleRootCacheBefore.len == RlnContractRootCacheSize * 32 + merkleRootCacheBefore.allIt(it == 0'u8) + manager.validRoots.len() == 0 + + for i in 0 ..< credentials.len(): + info "Registering credential", index = i, credential = credentials[i] + (waitFor manager.register(credentials[i], UserMessageLimit(20))).isOkOr: + assert false, "Failed to register credential " & $i & ": " & error + discard waitFor manager.updateRecentRoots() + + let merkleRootCacheAfter = (waitFor manager.fetchMerkleRootsCache()).valueOr: + raiseAssert "Failed to fetch merkle root cache after: " & error + + check: + merkleRootCacheAfter.len == RlnContractRootCacheSize * 32 + not merkleRootCacheAfter.allIt(it == 0'u8) + manager.validRoots.len() == credentialCount + manager.validRoots.items().toSeq().allIt(it != default(MerkleNode)) + + test "trackRootChanges: oldest roots are evicted once the window is exceeded": + const + initialCount = AcceptableRootWindowSize - RlnContractRootCacheSize + additionalCount = RlnContractRootCacheSize + 1 + # one more than the cache size to ensure eviction occurs + let credentials = generateCredentials(initialCount + additionalCount) + (waitFor manager.init()).isOkOr: + raiseAssert $error + + # Register the first credentials and snapshot the 3 oldest roots. + for i in 0 ..< initialCount: + (waitFor manager.register(credentials[i], UserMessageLimit(20))).isOkOr: + assert false, "Failed to register credential " & $i & ": " & error + discard waitFor manager.updateRecentRoots() + + check manager.validRoots.len() >= 3 + let firstThreeBefore = + @[manager.validRoots[0], manager.validRoots[1], manager.validRoots[2]] + + # Register the remaining credentials, pushing the deque past AcceptableRootWindowSize. + for i in initialCount ..< credentials.len(): + (waitFor manager.register(credentials[i], UserMessageLimit(20))).isOkOr: + assert false, "Failed to register credential " & $i & ": " & error + discard waitFor manager.updateRecentRoots() + + let rootsAfter = manager.validRoots.items().toSeq() + + # AcceptableRootWindowSize + 1 registrations evicts exactly the single oldest root, + # so only the first of the original three is gone; the other two remain. + check: + manager.validRoots.len() == AcceptableRootWindowSize + firstThreeBefore[0] notin rootsAfter + firstThreeBefore[1] in rootsAfter + firstThreeBefore[2] in rootsAfter + test "register: should guard against uninitialized state": let dummyCommitment = default(IDCommitment) @@ -214,7 +287,7 @@ suite "Onchain group manager": waitFor fut - let rootUpdated = waitFor manager.updateRoots() + let rootUpdated = waitFor manager.updateRecentRoots() if rootUpdated: let proofResult = waitFor manager.fetchMerkleProofElements() @@ -296,7 +369,7 @@ suite "Onchain group manager": assert false, "error returned when calling register: " & error waitFor fut - let rootUpdated = waitFor manager.updateRoots() + let rootUpdated = waitFor manager.updateRecentRoots() if rootUpdated: let proofResult = waitFor manager.fetchMerkleProofElements() @@ -333,7 +406,7 @@ suite "Onchain group manager": let messageBytes = "Hello".toBytes() - let rootUpdated = waitFor manager.updateRoots() + let rootUpdated = waitFor manager.updateRecentRoots() manager.merkleProofCache = newSeq[byte](640) for i in 0 ..< 640: @@ -362,7 +435,7 @@ suite "Onchain group manager": verified == false test "root queue should be updated correctly": - const credentialCount = 12 + const credentialCount = 9 let credentials = generateCredentials(credentialCount) (waitFor manager.init()).isOkOr: raiseAssert $error @@ -391,7 +464,7 @@ suite "Onchain group manager": for i in 0 ..< credentials.len(): (waitFor manager.register(credentials[i], UserMessageLimit(20))).isOkOr: assert false, "Failed to register credential " & $i & ": " & error - discard waitFor manager.updateRoots() + discard waitFor manager.updateRecentRoots() waitFor allFutures(futures) @@ -436,7 +509,7 @@ suite "Onchain group manager": (waitFor manager.register(credentials, UserMessageLimit(20))).isOkOr: assert false, "register failed: " & error - discard waitFor manager.updateRoots() + discard waitFor manager.updateRecentRoots() let roots = manager.validRoots.items().toSeq() require: roots.len > 0 diff --git a/waku/waku_rln_relay/constants.nim b/waku/waku_rln_relay/constants.nim index 8532abaaa..757de398f 100644 --- a/waku/waku_rln_relay/constants.nim +++ b/waku/waku_rln_relay/constants.nim @@ -7,6 +7,9 @@ import ../waku_keystore # Acceptable roots for merkle root validation of incoming messages const AcceptableRootWindowSize* = 50 +#Size if RLN contract root cache +const RlnContractRootCacheSize* = 5 + # RLN membership key and index files path const RlnCredentialsFilename* = "rlnCredentials.txt" 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 02317a056..02b463077 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 @@ -62,10 +62,10 @@ proc fetchMerkleProofElements*( let response = await sendEthCallWithParams( ethRpc = g.ethRpc.get(), functionSignature = methodSig, - params = paddedParam, fromAddress = g.ethRpc.get().defaultAccount, toAddress = fromHex(Address, g.ethContractAddress), chainId = g.chainId, + params = paddedParam, ) return response @@ -73,14 +73,32 @@ proc fetchMerkleProofElements*( proc fetchMerkleRoot*( g: OnchainGroupManager ): Future[Result[UInt256, string]] {.async.} = - let merkleRoot = await sendEthCallWithoutParams( - ethRpc = g.ethRpc.get(), - functionSignature = "root()", - fromAddress = g.ethRpc.get().defaultAccount, - toAddress = fromHex(Address, g.ethContractAddress), - chainId = g.chainId, - ) - return merkleRoot + try: + let merkleRoot = await sendEthCallWithoutParams( + ethRpc = g.ethRpc.get(), + functionSignature = "root()", + fromAddress = g.ethRpc.get().defaultAccount, + toAddress = fromHex(Address, g.ethContractAddress), + chainId = g.chainId, + ) + return merkleRoot + except CatchableError: + error "Failed to fetch Merkle root", error = getCurrentExceptionMsg() + return err("Failed to fetch merkle root: " & getCurrentExceptionMsg()) + +proc fetchMerkleRootsCache*( + g: OnchainGroupManager +): Future[Result[seq[byte], string]] {.async.} = + let + # using sendEthCallWithParams to get return type of seq[bytes] for getRecentRoots() function which returns an array of bytes32 + merkleRoots = await sendEthCallWithParams( + ethRpc = g.ethRpc.get(), + functionSignature = "getRecentRoots()", + fromAddress = g.ethRpc.get().defaultAccount, + toAddress = fromHex(Address, g.ethContractAddress), + chainId = g.chainId, + ) + return merkleRoots proc fetchNextFreeIndex*( g: OnchainGroupManager @@ -102,10 +120,10 @@ proc fetchMembershipStatus*( await sendEthCallWithParams( ethRpc = g.ethRpc.get(), functionSignature = "isInMembershipSet(uint256)", - params = params, fromAddress = g.ethRpc.get().defaultAccount, toAddress = fromHex(Address, g.ethContractAddress), chainId = g.chainId, + params = params, ) ).valueOr: return err("Failed to check membership: " & error) @@ -148,14 +166,64 @@ proc updateRoots*(g: OnchainGroupManager): Future[bool] {.async.} = return false +proc updateRecentRoots*(g: OnchainGroupManager): Future[bool] {.async.} = + ## Fetch recent roots from the contract roots cache and update the validRoots deque, ensuring we maintain a window of unique acceptable roots. + ## Contract returns array of uint256 roots, newest first, zero-padded to the cache size (e.g. 5). + let bytes = (await g.fetchMerkleRootsCache()).valueOr: + error "Failed to fetch current Merkle root", error = error + return false + + if (bytes.len mod 32) != 0: + error "Invalid recent roots payload length", length = bytes.len + return false + + let chunkCount = bytes.len div 32 + if chunkCount != RlnContractRootCacheSize: + warn "Unexpected number of recent roots returned; proceeding anyway", + count = chunkCount + + # Parse 32-byte chunks (contract returns newest-first) into MerkleNode values, + # reversing to oldest-first and skipping zero roots. + var newRootsDequeOrder: seq[MerkleNode] = @[] + for startIdx in countdown(bytes.len - 32, 0, 32): + let u = UInt256.fromBytesBE(bytes.toOpenArray(startIdx, startIdx + 31)) + if u.isZero: + continue + newRootsDequeOrder.add(UInt256ToField(u)) + + if newRootsDequeOrder.len == 0: + debug "no non-zero recent roots to add; skipping update" + return false + + # Determine overlap with existing tail so we only append truly new roots + let overlap = min(g.validRoots.len, newRootsDequeOrder.len) + var matchLen = 0 + for startIdx in (g.validRoots.len - overlap) ..< g.validRoots.len: + if g.validRoots[startIdx] == newRootsDequeOrder[0]: + matchLen = g.validRoots.len - startIdx + break + + let toAdd = newRootsDequeOrder[matchLen ..< newRootsDequeOrder.len] + if toAdd.len == 0: + return false + + # Append new roots to the tail; trim happens below if we exceed the window. + for root in toAdd: + g.validRoots.addLast(root) + debug "appended recent roots to list of valid roots", count = toAdd.len, roots = toAdd + + while g.validRoots.len > AcceptableRootWindowSize: + discard g.validRoots.popFirst() + + return true + proc trackRootChanges*(g: OnchainGroupManager): Future[Result[void, string]] {.async.} = ?checkInitialized(g) - const rpcDelay = 5.seconds + const rpcDelay = 10.seconds while true: - await sleepAsync(rpcDelay) - let rootUpdated = await g.updateRoots() + let rootUpdated = await g.updateRecentRoots() if rootUpdated: ## The membership set on-chain has changed (some new members have joined or some members have left) @@ -174,6 +242,7 @@ proc trackRootChanges*(g: OnchainGroupManager): Future[Result[void, string]] {.a let memberCount = cast[int64](nextFreeIndex) waku_rln_number_registered_memberships.set(float64(memberCount)) + await sleepAsync(rpcDelay) method register*( g: OnchainGroupManager, rateCommitment: RateCommitment @@ -393,8 +462,11 @@ method generateProof*( external_nullifier: extNullifier, ) - let output = generateRlnProofWithWitness(g.rlnInstance, witness, epoch, rlnIdentifier).valueOr: - return err("Failed to generate proof: " & error) + waku_rln_proof_generation_duration_seconds.nanosecondTime: + let output = generateRlnProofWithWitness( + g.rlnInstance, witness, epoch, rlnIdentifier + ).valueOr: + return err("Failed to generate proof: " & error) info "Proof generated successfully", proof = output diff --git a/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim b/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim index 2c47b11fa..a82356af8 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim @@ -76,10 +76,10 @@ proc sendEthCallWithoutParams*( proc sendEthCallWithParams*( ethRpc: Web3, functionSignature: string, - params: seq[byte], fromAddress: Address, toAddress: Address, chainId: UInt256, + params: seq[byte] = @[], ): Future[Result[seq[byte], string]] {.async.} = ## Workaround for web3 chainId=null issue with parameterized contract calls let functionHash = From f833ded20945aa27af7cc741e276a1017b2d6fcd Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Thu, 4 Jun 2026 15:53:27 -0300 Subject: [PATCH 06/13] Clean separation between ReliableChannelManager, MessagingClient, and kernel/core (#3918) * Convert DeliveryService into optionally mountable MessagingClient * Move SubscriptionManager to core layer (WakuNode) * Ensure libwaku kernel_api/ still works (deprecated; removal pending) * Create node_types.nim to allow WakuNode to compose subsystems cleanly * Create node_telemetry.nim to centralize Prometheus types * Remove unnecessary "ptr Waku" / "addr waku" indirection * Rename Waku.startWaku -> Waku.start for upcoming Waku rename * Write complete proc surface for SubscriptionManager (all intents expressible) * Rename edgeFilterHealthLoop -> edgeFilterConnectionLoop ("Health" means monitoring) * logosdelivery_start_node calls mountMessagingClient then starts * libwaku and wakunode2 do not mount messagingClient * Improve edge filter peer cleanup on disconnect * misc refactors/moves, improvements, fixes Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> --- .../liteprotocoltester/liteprotocoltester.nim | 2 +- apps/wakunode2/wakunode2.nim | 2 +- channels/events.nim | 2 +- channels/reliable_channel.nim | 37 +- channels/reliable_channel_manager.nim | 83 +- examples/api_example/api_example.nim | 6 +- examples/wakustealthcommitments/node_spec.nim | 2 +- .../logos_delivery_api/node_api.nim | 12 +- library/kernel_api/node_lifecycle_api.nim | 2 +- nix/default.nix | 2 +- tests/api/test_api_health.nim | 8 +- tests/api/test_api_receive.nim | 7 +- tests/api/test_api_send.nim | 24 +- tests/api/test_api_subscription.nim | 71 +- .../test_reliable_channel_send_receive.nim | 52 +- tests/node/test_wakunode_health_monitor.nim | 20 +- tests/node/test_wakunode_peer_exchange.nim | 202 ++--- tests/waku_discv5/test_waku_discv5.nim | 6 +- tests/waku_peer_exchange/test_protocol.nim | 186 ++--- tests/wakunode2/test_app.nim | 6 +- waku/api/api.nim | 33 +- waku/factory/waku.nim | 170 +++-- waku/messaging_client.nim | 63 ++ .../delivery_service/delivery_service.nim | 44 -- .../recv_service/recv_service.nim | 14 +- .../send_service/send_service.nim | 11 +- .../delivery_service/subscription_manager.nim | 596 --------------- .../health_monitor/node_health_monitor.nim | 1 + waku/node/kernel_api/filter.nim | 1 + waku/node/kernel_api/peer_exchange.nim | 1 + waku/node/kernel_api/relay.nim | 114 +-- waku/node/node_telemetry.nim | 27 + waku/node/node_types.nim | 116 +++ waku/node/subscription_manager.nim | 711 ++++++++++++++++++ waku/node/waku_metrics.nim | 1 + waku/node/waku_node.nim | 71 +- waku/requests/health_requests.nim | 4 +- 37 files changed, 1454 insertions(+), 1256 deletions(-) create mode 100644 waku/messaging_client.nim delete mode 100644 waku/node/delivery_service/delivery_service.nim delete mode 100644 waku/node/delivery_service/subscription_manager.nim create mode 100644 waku/node/node_telemetry.nim create mode 100644 waku/node/node_types.nim create mode 100644 waku/node/subscription_manager.nim diff --git a/apps/liteprotocoltester/liteprotocoltester.nim b/apps/liteprotocoltester/liteprotocoltester.nim index 46c85e910..1877b8477 100644 --- a/apps/liteprotocoltester/liteprotocoltester.nim +++ b/apps/liteprotocoltester/liteprotocoltester.nim @@ -123,7 +123,7 @@ when isMainModule: error "Waku initialization failed", error = error quit(QuitFailure) - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: error "Starting waku failed", error = error quit(QuitFailure) diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index 484adf68f..be3a83f57 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -55,7 +55,7 @@ when isMainModule: error "Waku initialization failed", error = error quit(QuitFailure) - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: error "Starting waku failed", error = error quit(QuitFailure) diff --git a/channels/events.nim b/channels/events.nim index 904a34dc6..3e271976e 100644 --- a/channels/events.nim +++ b/channels/events.nim @@ -1,7 +1,7 @@ ## Reliable Channel event types emitted to API consumers. ## ## Lifecycle events for individual segments (sent / propagated / errored) -## are the same as the network-level ones the DeliveryService already +## are the same as the network-level ones the MessagingClient already ## emits — `requestId` is shared across layers — so we just re-export ## `waku/events/message_events` and avoid declaring duplicates. ## diff --git a/channels/reliable_channel.nim b/channels/reliable_channel.nim index e32b57e36..6aa7086e5 100644 --- a/channels/reliable_channel.nim +++ b/channels/reliable_channel.nim @@ -20,8 +20,7 @@ import bearssl/rand import stew/byteutils import libp2p/crypto/crypto as libp2p_crypto -import waku/api/api -import waku/factory/waku as waku_factory +import waku/api/types import waku/node/delivery_service/send_service import waku/waku_core/topics @@ -32,7 +31,7 @@ import ./rate_limit_manager/rate_limit_manager import ./encryption/encryption export - api, waku_factory, events, segmentation, scalable_data_sync, rate_limit_manager, + types, send_service, events, segmentation, scalable_data_sync, rate_limit_manager, encryption const LipWireReliableChannelVersion* = "RELIABLE-CHANNEL-API/1" @@ -47,9 +46,10 @@ type SendHandler* = proc(envelope: MessageEnvelope): Future[Result[RequestId, string]] {. async: (raises: [CatchableError]), gcsafe .} - ## Egress dispatch boundary. Defaults to `waku.send`; tests inject a - ## fake that records calls and returns canned `RequestId`s so the - ## send state machine can be exercised end-to-end without a network. + ## Egress dispatch boundary. Typically wraps `MessagingClient.send`; + ## tests inject a fake that records calls and returns canned + ## `RequestId`s so the send state machine can be exercised end-to-end + ## without a network. MessagePersistence {.pure.} = enum Persistent @@ -264,20 +264,20 @@ proc onReadyToSend( meta: LipWireReliableChannelVersion.toBytes(), ) - ## `waku.send` is not annotated `(raises: [])`, but this listener is. + ## `sendHandler` is not annotated `(raises: [])`, but this listener is. ## Convert any raise to a Result error so the state machine handles ## both failure modes (Result.err and exception) through one path. let sendRes = try: await self.sendHandler(envelope) except CatchableError as e: - Result[RequestId, string].err("waku send raised: " & e.msg) + Result[RequestId, string].err("messaging send raised: " & e.msg) let messagingReqId = sendRes.valueOr: MessageErrorEvent.emit( self.brokerCtx, MessageErrorEvent( - requestId: channelReqId, messageHash: "", error: "waku send failed: " & error + requestId: channelReqId, messageHash: "", error: "messaging send failed: " & error ), ) self.markSegmentFailed(channelReqId) @@ -374,7 +374,7 @@ proc onMessageReceived( proc new*( T: type ReliableChannel, - waku: Waku, + sendHandler: SendHandler, channelId: ChannelId, contentTopic: ContentTopic, senderId: SdsParticipantID, @@ -382,7 +382,6 @@ proc new*( sdsConfig: SdsConfig, rateConfig: RateLimitConfig, brokerCtx: BrokerContext = globalBrokerContext(), - sendHandler: SendHandler = nil, ): T = ## Pipeline handlers (segmentation/SDS/rate-limit) are constructed ## inside the channel rather than handed in by the caller — they are @@ -391,19 +390,11 @@ proc new*( ## `Decrypt` request brokers, so the channel keeps no per-instance ## encryption state either. ## - ## `sendHandler` defaults to `waku.send`; tests pass a fake to drive - ## the send state machine without touching the network. - let resolvedSendHandler = - if sendHandler.isNil(): - proc( - envelope: MessageEnvelope - ): Future[Result[RequestId, string]] {.async: (raises: [CatchableError]), gcsafe.} = - return await waku.send(envelope) - else: - sendHandler - + ## `sendHandler` is the egress dispatch. The owning `ReliableChannelManager` + ## typically constructs it as a closure over `MessagingClient.send`. Tests + ## pass a fake to drive the send state machine without touching the network. let chn = T( - sendHandler: resolvedSendHandler, + sendHandler: sendHandler, channelId: channelId, contentTopic: contentTopic, senderId: senderId, diff --git a/channels/reliable_channel_manager.nim b/channels/reliable_channel_manager.nim index 747f755b4..68ae82388 100644 --- a/channels/reliable_channel_manager.nim +++ b/channels/reliable_channel_manager.nim @@ -10,11 +10,10 @@ import results import chronos import stew/byteutils -import waku/api/api -import waku/api/api_conf +import brokers/broker_context + import waku/events/message_events as waku_message_events -import waku/factory/waku as waku_factory -import waku/node/delivery_service/delivery_service +import waku/messaging_client import waku/waku_core/topics import ./reliable_channel @@ -24,40 +23,43 @@ export reliable_channel type ReliableChannelManager* = ref object channels: Table[ChannelId, ReliableChannel] - waku: Waku - ## Owned by the manager. The channel layer reaches the messaging - ## API through `waku.send(envelope)`; constructing DeliveryTasks - ## directly would breach the layer boundary. + messagingClient: MessagingClient + ## Borrowed from the owning `Waku`. + sendHandler: SendHandler + ## Default egress dispatch for channels created through this manager. + ## Constructed at mount time as a closure over `MessagingClient.send` + ## so the channel layer itself stays callable-only. brokerCtx: BrokerContext proc new*( T: type ReliableChannelManager, - conf: WakuNodeConf, + messagingClient: MessagingClient, + sendHandler: SendHandler, brokerCtx: BrokerContext = globalBrokerContext(), -): Future[Result[T, string]] {.async.} = - ## TODO !! The proper ownership chain is: - ## ReliableChannelManager -> DeliveryService (MessagingClient) -> Waku (Kernel/Protocols) -> WakuNode, - ## and this will be implemented in the future. For now, `createNode` - ## is called here to get a Waku instance, and the WakuNode is immediately discarded. - ## This is a temporary workaround to get the API - - let waku = ?(await createNode(conf)) - - let manager = T( - channels: initTable[ChannelId, ReliableChannel](), waku: waku, brokerCtx: brokerCtx +): Result[T, string] = + if messagingClient.isNil(): + return err("messaging client is required") + if sendHandler.isNil(): + return err("sendHandler is required") + return ok( + T( + channels: initTable[ChannelId, ReliableChannel](), + messagingClient: messagingClient, + sendHandler: sendHandler, + brokerCtx: brokerCtx, + ) ) - return ok(manager) - proc start*(self: ReliableChannelManager): Result[void, string] = - ## Bring the owned DeliveryService up. Separated from `new` so callers - ## can register encryption providers / create channels before traffic - ## starts flowing. - self.waku.deliveryService.startDeliveryService() + ## Placeholder: per-channel listeners are installed in `ReliableChannel.new`, + ## so the manager has nothing to start at this layer. Kept for symmetry + ## with the `Waku` mount/start lifecycle and as a hook for future state. + discard + ok() proc stop*(self: ReliableChannelManager) {.async.} = - if not self.waku.isNil(): - await self.waku.deliveryService.stopDeliveryService() + ## Placeholder mirror of `start`. + discard proc createReliableChannel*( self: ReliableChannelManager, @@ -66,17 +68,17 @@ proc createReliableChannel*( senderId: SdsParticipantID, sendHandler: SendHandler = nil, ): Result[ChannelId, string] = - ## Spec entry point. The `DeliveryService` and `rng` the channel needs - ## are sourced from the owning `ReliableChannelManager` rather than - ## passed per call. Encryption is wired up through the `Encrypt`/ - ## `Decrypt` request brokers — the application installs its own - ## providers (or `setNoopEncryption()`) before traffic flows. + ## Spec entry point. The `sendHandler` and `rng` the channel needs are + ## sourced from the owning `ReliableChannelManager` rather than passed + ## per call. Encryption is wired up through the `Encrypt`/`Decrypt` + ## request brokers — the application installs its own providers + ## (or `setNoopEncryption()`) before traffic flows. ## ## Segmentation, SDS and rate-limit configs will eventually be read ## from the node's `NodeConfig`. Defaults for now. ## - ## `sendHandler` is left `nil` in production so the channel uses the - ## owned `waku.send`; tests pass a fake to bypass the network. + ## `sendHandler` defaults to the manager's default (constructed at mount + ## from `MessagingClient.send`); tests pass a fake to bypass the network. if self.channels.hasKey(channelId): return err("channel already exists: " & channelId) @@ -95,8 +97,14 @@ proc createReliableChannel*( epochPeriodSec: DefaultEpochPeriodSec, messagesPerEpoch: DefaultMessagesPerEpoch ) + let effectiveSendHandler = + if sendHandler.isNil(): + self.sendHandler + else: + sendHandler + let chn = ReliableChannel.new( - waku = self.waku, + sendHandler = effectiveSendHandler, channelId = channelId, contentTopic = contentTopic, senderId = senderId, @@ -104,7 +112,6 @@ proc createReliableChannel*( sdsConfig = sdsConfig, rateConfig = rateConfig, brokerCtx = self.brokerCtx, - sendHandler = sendHandler, ) self.channels[channelId] = chn @@ -137,5 +144,5 @@ proc send*( ## `ReliableChannel` installs its own `MessageReceivedEvent` listener ## in `ReliableChannel.new`, filters by spec marker and `contentTopic`, ## and routes to its private `onMessageReceived`. This keeps the lower -## layer (MessagingAPI/Waku) unaware of the existence of ReliableChannel +## layer (MessagingClient/Waku) unaware of the existence of ReliableChannel ## and keeps the manager out of per-channel event dispatch. diff --git a/examples/api_example/api_example.nim b/examples/api_example/api_example.nim index 2093a81c0..207e83429 100644 --- a/examples/api_example/api_example.nim +++ b/examples/api_example/api_example.nim @@ -82,8 +82,12 @@ when isMainModule: echo("Waku node created successfully!") + node.mountMessagingClient().isOkOr: + echo "Failed to mount messaging: ", error + quit(QuitFailure) + # Start the node - (waitFor startWaku(addr node)).isOkOr: + (waitFor node.start()).isOkOr: echo "Failed to start node: ", error quit(QuitFailure) diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index d85e83a5b..7751878ca 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -48,7 +48,7 @@ proc setup*(): Waku = error "Waku initialization failed", error = error quit(QuitFailure) - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: error "Starting waku failed", error = error quit(QuitFailure) diff --git a/liblogosdelivery/logos_delivery_api/node_api.nim b/liblogosdelivery/logos_delivery_api/node_api.nim index 2e30d1b43..042bdb3a8 100644 --- a/liblogosdelivery/logos_delivery_api/node_api.nim +++ b/liblogosdelivery/logos_delivery_api/node_api.nim @@ -172,7 +172,17 @@ proc logosdelivery_start_node( chronicles.error "ConnectionStatusChange.listen failed", err = $error return err("ConnectionStatusChange.listen failed: " & $error) - (await startWaku(addr ctx.myLib[])).isOkOr: + ctx.myLib[].mountMessagingClient().isOkOr: + let errMsg = $error + chronicles.error "mountMessagingClient failed", error = errMsg + return err("failed to mount messaging: " & errMsg) + + ctx.myLib[].mountReliableChannelManager().isOkOr: + let errMsg = $error + chronicles.error "mountReliableChannelManager failed", err = errMsg + return err("failed to mount reliable channel manager: " & errMsg) + + (await ctx.myLib[].start()).isOkOr: let errMsg = $error chronicles.error "START_NODE failed", err = errMsg return err("failed to start: " & errMsg) diff --git a/library/kernel_api/node_lifecycle_api.nim b/library/kernel_api/node_lifecycle_api.nim index 8f3e99b24..55dd7cd55 100644 --- a/library/kernel_api/node_lifecycle_api.nim +++ b/library/kernel_api/node_lifecycle_api.nim @@ -71,7 +71,7 @@ registerReqFFI(CreateNodeRequest, ctx: ptr FFIContext[Waku]): proc waku_start( ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer ) {.ffi.} = - (await startWaku(ctx[].myLib)).isOkOr: + (await ctx.myLib[].start()).isOkOr: error "START_NODE failed", error = error return err("failed to start: " & $error) return ok("") diff --git a/nix/default.nix b/nix/default.nix index ec9e0542c..dfe537f24 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -30,7 +30,7 @@ let # while others use the repo root. Pass both so the compiler finds either layout. pathArgs = builtins.concatStringsSep " " - (builtins.concatMap (p: [ "--path:${p}" "--path:${p}/src" ]) + (builtins.concatMap (p: [ "--path:${p}" "--path:${p}/src" "--path:${p}/sds" ]) (builtins.attrValues otherDeps)); libExt = diff --git a/tests/api/test_api_health.nim b/tests/api/test_api_health.nim index d949db24f..62fe39b9e 100644 --- a/tests/api/test_api_health.nim +++ b/tests/api/test_api_health.nim @@ -103,7 +103,9 @@ suite "LM API health checking": client = (await createNode(conf)).valueOr: raiseAssert error - (await startWaku(addr client)).isOkOr: + client.mountMessagingClient().isOkOr: + raiseAssert error + (await client.start()).isOkOr: raiseAssert error asyncTeardown: @@ -281,7 +283,9 @@ suite "LM API health checking": edgeWaku = (await createNode(edgeConf)).valueOr: raiseAssert "Failed to create edge node: " & error - (await startWaku(addr edgeWaku)).isOkOr: + edgeWaku.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount edge messaging: " & error + (await edgeWaku.start()).isOkOr: raiseAssert "Failed to start edge waku: " & error let relayReq = await RequestProtocolHealth.request( diff --git a/tests/api/test_api_receive.nim b/tests/api/test_api_receive.nim index d6aa954a4..85e522afc 100644 --- a/tests/api/test_api_receive.nim +++ b/tests/api/test_api_receive.nim @@ -6,6 +6,7 @@ import libp2p/[peerid, peerinfo, crypto/crypto] import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] import ../waku_archive/archive_utils +import waku/messaging_client import waku, @@ -16,7 +17,6 @@ import waku_relay/protocol, waku_archive, waku_archive/common as archive_common, - node/delivery_service/delivery_service, node/delivery_service/recv_service, ] import waku/factory/waku_conf @@ -147,7 +147,8 @@ suite "Messaging API, Receive Service (store recovery)": subscriber = (await createNode(createApiNodeConf(numShards))).expect( "Failed to create subscriber" ) - (await startWaku(addr subscriber)).expect("Failed to start subscriber") + subscriber.mountMessagingClient().expect("Failed to mount messaging") + (await subscriber.start()).expect("Failed to start subscriber") # publish after the subscriber exists but before it connects to the # store; the message reaches the archive but the subscriber doesn't @@ -185,7 +186,7 @@ suite "Messaging API, Receive Service (store recovery)": await eventManager.teardown() # trigger store check, should recover and deliver via MessageReceivedEvent - await subscriber.deliveryService.recvService.checkStore() + await subscriber.messagingClient.recvService.checkStore() let received = await eventManager.waitForEvents(TestTimeout) check received diff --git a/tests/api/test_api_send.nim b/tests/api/test_api_send.nim index 084119041..679d6a419 100644 --- a/tests/api/test_api_send.nim +++ b/tests/api/test_api_send.nim @@ -241,7 +241,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf())).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error # node is not connected ! @@ -263,7 +265,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf())).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error await node.node.connectToNodes( @@ -297,7 +301,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf())).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error await node.node.connectToNodes(@[relayNode1PeerInfo]) @@ -327,7 +333,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf())).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error await node.node.connectToNodes(@[lightpushNodePeerInfo]) @@ -357,7 +365,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf())).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error await node.node.connectToNodes(@[lightpushNodePeerInfo, storeNodePeerInfo]) @@ -411,7 +421,9 @@ suite "Waku API - Send": lockNewGlobalBrokerContext: node = (await createNode(createApiNodeConf(cli_args.WakuMode.Edge))).valueOr: raiseAssert error - (await startWaku(addr node)).isOkOr: + node.mountMessagingClient().isOkOr: + raiseAssert "Failed to mount messaging: " & error + (await node.start()).isOkOr: raiseAssert "Failed to start Waku node: " & error await node.node.connectToNodes(@[fakeLightpushNodePeerInfo]) diff --git a/tests/api/test_api_subscription.nim b/tests/api/test_api_subscription.nim index 32d4e742f..8f587b535 100644 --- a/tests/api/test_api_subscription.nim +++ b/tests/api/test_api_subscription.nim @@ -5,6 +5,7 @@ import chronos, testutils/unittests, stew/byteutils import libp2p/[peerid, peerinfo, multiaddress, crypto/crypto] import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] +import waku/messaging_client import waku, @@ -14,13 +15,14 @@ import events/message_events, waku_relay/protocol, node/kernel_api/filter, - node/delivery_service/subscription_manager, + node/subscription_manager, ] import waku/factory/waku_conf import tools/confutils/cli_args const TestTimeout = chronos.seconds(10) const NegativeTestTimeout = chronos.seconds(2) +const EdgeWaitTimeout = chronos.seconds(60) type ReceiveEventListenerManager = ref object brokerCtx: BrokerContext @@ -85,7 +87,8 @@ proc setupSubscriberNode(conf: WakuNodeConf): Future[Waku] {.async.} = var node: Waku lockNewGlobalBrokerContext: node = (await createNode(conf)).expect("Failed to create subscriber node") - (await startWaku(addr node)).expect("Failed to start subscriber node") + node.mountMessagingClient().expect("Failed to mount messaging") + (await node.start()).expect("Failed to start subscriber node") return node proc setupNetwork( @@ -161,20 +164,39 @@ proc getRelayShard(node: WakuNode, contentTopic: ContentTopic): PubsubTopic = return PubsubTopic($shardObj) proc waitForMesh(node: WakuNode, shard: PubsubTopic) {.async.} = - for _ in 0 ..< 50: + let deadline = Moment.now() + EdgeWaitTimeout + while Moment.now() < deadline: if node.wakuRelay.getNumPeersInMesh(shard).valueOr(0) > 0: return await sleepAsync(100.milliseconds) raise newException(ValueError, "GossipSub Mesh failed to stabilize on " & shard) proc waitForEdgeSubs(w: Waku, shard: PubsubTopic) {.async.} = - let sm = w.deliveryService.subscriptionManager - for _ in 0 ..< 50: - if sm.edgeFilterPeerCount(shard) > 0: + let deadline = Moment.now() + EdgeWaitTimeout + while Moment.now() < deadline: + if w.node.subscriptionManager.edgeFilterPeerCount(shard) > 0: return await sleepAsync(100.milliseconds) raise newException(ValueError, "Edge filter subscription failed on " & shard) +proc edgePeersReached(w: Waku, shard: PubsubTopic, n: int): Future[bool] {.async.} = + let deadline = Moment.now() + EdgeWaitTimeout + while Moment.now() < deadline: + if w.node.subscriptionManager.edgeFilterPeerCount(shard) >= n: + return true + await sleepAsync(100.milliseconds) + return false + +proc edgePeersDroppedBelow( + w: Waku, shard: PubsubTopic, n: int +): Future[bool] {.async.} = + let deadline = Moment.now() + EdgeWaitTimeout + while Moment.now() < deadline: + if w.node.subscriptionManager.edgeFilterPeerCount(shard) < n: + return true + await sleepAsync(100.milliseconds) + return false + proc publishToMesh( net: TestNetwork, contentTopic: ContentTopic, payload: seq[byte] ): Future[Result[int, string]] {.async.} = @@ -621,7 +643,8 @@ suite "Messaging API, SubscriptionManager": var subscriber: Waku lockNewGlobalBrokerContext: subscriber = (await createNode(conf)).expect("Failed to create edge subscriber") - (await startWaku(addr subscriber)).expect("Failed to start edge subscriber") + subscriber.mountMessagingClient().expect("Failed to mount messaging") + (await subscriber.start()).expect("Failed to start edge subscriber") # Connect edge subscriber to both filter servers so selectPeers finds both await subscriber.node.connectToNodes(@[publisherPeerInfo, meshBuddyPeerInfo]) @@ -632,12 +655,7 @@ suite "Messaging API, SubscriptionManager": (await subscriber.subscribe(testTopic)).expect("Failed to subscribe") # Wait for dialing both filter servers (HealthyThreshold = 2) - for _ in 0 ..< 100: - if subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 2: - break - await sleepAsync(100.milliseconds) - - check subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 2 + check await edgePeersReached(subscriber, shard, 2) # Verify message delivery with both servers alive await waitForMesh(publisher, shard) @@ -659,12 +677,8 @@ suite "Messaging API, SubscriptionManager": await subscriber.node.disconnectNode(meshBuddyPeerInfo) # Wait for the dead peer to be pruned - for _ in 0 ..< 50: - if subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) < 2: - break - await sleepAsync(100.milliseconds) - - check subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 1 + check await edgePeersDroppedBelow(subscriber, shard, 2) + check subscriber.node.subscriptionManager.edgeFilterPeerCount(shard) >= 1 # Verify messages still arrive through the surviving filter server (publisher) eventManager = newReceiveEventListenerManager(subscriber.brokerCtx, 1) @@ -758,7 +772,8 @@ suite "Messaging API, SubscriptionManager": var subscriber: Waku lockNewGlobalBrokerContext: subscriber = (await createNode(conf)).expect("Failed to create edge subscriber") - (await startWaku(addr subscriber)).expect("Failed to start edge subscriber") + subscriber.mountMessagingClient().expect("Failed to mount messaging") + (await subscriber.start()).expect("Failed to start edge subscriber") await subscriber.node.connectToNodes( @[publisherPeerInfo, meshBuddyPeerInfo, sparePeerInfo] @@ -770,23 +785,13 @@ suite "Messaging API, SubscriptionManager": (await subscriber.subscribe(testTopic)).expect("Failed to subscribe") # Wait for 2 confirmed peers (HealthyThreshold). The 3rd is available but not dialed. - for _ in 0 ..< 100: - if subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 2: - break - await sleepAsync(100.milliseconds) - - require subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) == - 2 + check await edgePeersReached(subscriber, shard, 2) + require subscriber.node.subscriptionManager.edgeFilterPeerCount(shard) == 2 await subscriber.node.disconnectNode(meshBuddyPeerInfo) # Wait for the sub loop to detect the loss and dial a replacement - for _ in 0 ..< 100: - if subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 2: - break - await sleepAsync(100.milliseconds) - - check subscriber.deliveryService.subscriptionManager.edgeFilterPeerCount(shard) >= 2 + check await edgePeersReached(subscriber, shard, 2) await waitForMesh(publisher, shard) diff --git a/tests/channels/test_reliable_channel_send_receive.nim b/tests/channels/test_reliable_channel_send_receive.nim index 5ea300eb3..dabc4497f 100644 --- a/tests/channels/test_reliable_channel_send_receive.nim +++ b/tests/channels/test_reliable_channel_send_receive.nim @@ -35,7 +35,7 @@ suite "Reliable Channel - ingress": ## Unit test for the receive side of the API: instead of standing ## up two libp2p nodes and a relay mesh, we drive the manager ## directly by emitting a `MessageReceivedEvent` (the exact event - ## the DeliveryService emits when a `WakuMessage` arrives off the + ## the MessagingClient emits when a `WakuMessage` arrives off the ## wire). The manager must: ## - drop traffic missing the Reliable Channel spec marker ## - dispatch the matching channel's `onMessageReceived` @@ -45,13 +45,15 @@ suite "Reliable Channel - ingress": contentTopic = ContentTopic("/reliable-channel/test/proto") let appPayload = "hello reliable channel".toBytes() + var waku: Waku var manager: ReliableChannelManager var brokerCtx: BrokerContext lockNewGlobalBrokerContext: brokerCtx = globalBrokerContext() - manager = (await ReliableChannelManager.new(createApiNodeConf())).expect( - "Failed to create manager" - ) + waku = (await createNode(createApiNodeConf())).expect("createNode") + waku.mountMessagingClient().expect("mountMessagingClient") + waku.mountReliableChannelManager().expect("mountReliableChannelManager") + manager = waku.reliableChannelManager ## Noop encryption providers so the Encrypt/Decrypt brokers have ## something to dispatch to; without this the channel falls back to @@ -95,7 +97,7 @@ suite "Reliable Channel - ingress": if arrived: check received.read() == appPayload - await manager.stop() + (await waku.stop()).expect("stop") asyncTest "manager drops unmarked WakuMessage": ## Mirror of the above: same content topic, but `meta` is empty @@ -105,13 +107,15 @@ suite "Reliable Channel - ingress": contentTopic = ContentTopic("/reliable-channel/test/proto") let appPayload = "foreign payload".toBytes() + var waku: Waku var manager: ReliableChannelManager var brokerCtx: BrokerContext lockNewGlobalBrokerContext: brokerCtx = globalBrokerContext() - manager = (await ReliableChannelManager.new(createApiNodeConf())).expect( - "Failed to create manager" - ) + waku = (await createNode(createApiNodeConf())).expect("createNode") + waku.mountMessagingClient().expect("mountMessagingClient") + waku.mountReliableChannelManager().expect("mountReliableChannelManager") + manager = waku.reliableChannelManager setNoopEncryption() @@ -146,7 +150,7 @@ suite "Reliable Channel - ingress": await sleepAsync(100.milliseconds) check not fired - await manager.stop() + (await waku.stop()).expect("stop") suite "Reliable Channel - send state machine": asyncTest "MessageSentEvent finalises the channelReqId as Sent": @@ -162,13 +166,15 @@ suite "Reliable Channel - send state machine": contentTopic = ContentTopic("/reliable-channel/test/sm-success") fakeMsgReqId = RequestId("fake-msg-req-1") + var waku: Waku var manager: ReliableChannelManager var brokerCtx: BrokerContext lockNewGlobalBrokerContext: brokerCtx = globalBrokerContext() - manager = (await ReliableChannelManager.new(createApiNodeConf())).expect( - "Failed to create manager" - ) + waku = (await createNode(createApiNodeConf())).expect("createNode") + waku.mountMessagingClient().expect("mountMessagingClient") + waku.mountReliableChannelManager().expect("mountReliableChannelManager") + manager = waku.reliableChannelManager setNoopEncryption() @@ -213,7 +219,7 @@ suite "Reliable Channel - send state machine": if finalised: check sentFut.read() == channelReqId - await manager.stop() + (await waku.stop()).expect("stop") asyncTest "two independent channelReqIds are finalised independently": ## Two `send()` calls -> two independent `channelReqId`s, each with @@ -227,13 +233,15 @@ suite "Reliable Channel - send state machine": channelId = ChannelId("sm-multi-channel") contentTopic = ContentTopic("/reliable-channel/test/sm-multi") + var waku: Waku var manager: ReliableChannelManager var brokerCtx: BrokerContext lockNewGlobalBrokerContext: brokerCtx = globalBrokerContext() - manager = (await ReliableChannelManager.new(createApiNodeConf())).expect( - "Failed to create manager" - ) + waku = (await createNode(createApiNodeConf())).expect("createNode") + waku.mountMessagingClient().expect("mountMessagingClient") + waku.mountReliableChannelManager().expect("mountReliableChannelManager") + manager = waku.reliableChannelManager setNoopEncryption() @@ -303,7 +311,7 @@ suite "Reliable Channel - send state machine": if erroredArrived: check erroredFut.read() == channelReqId2 - await manager.stop() + (await waku.stop()).expect("stop") asyncTest "TODO: channelReqId not pruned until ALL its segments are final": ## Placeholder for the multi-sibling prune rule. Today's @@ -326,13 +334,15 @@ suite "Reliable Channel - send state machine": channelId = ChannelId("sm-race-channel") contentTopic = ContentTopic("/reliable-channel/test/sm-race") + var waku: Waku var manager: ReliableChannelManager var brokerCtx: BrokerContext lockNewGlobalBrokerContext: brokerCtx = globalBrokerContext() - manager = (await ReliableChannelManager.new(createApiNodeConf())).expect( - "Failed to create manager" - ) + waku = (await createNode(createApiNodeConf())).expect("createNode") + waku.mountMessagingClient().expect("mountMessagingClient") + waku.mountReliableChannelManager().expect("mountReliableChannelManager") + manager = waku.reliableChannelManager setNoopEncryption() @@ -413,4 +423,4 @@ suite "Reliable Channel - send state machine": check channelReqId1 in finalisedReqIds check channelReqId2 in finalisedReqIds - await manager.stop() + (await waku.stop()).expect("stop") diff --git a/tests/node/test_wakunode_health_monitor.nim b/tests/node/test_wakunode_health_monitor.nim index 08f641a75..a85056d51 100644 --- a/tests/node/test_wakunode_health_monitor.nim +++ b/tests/node/test_wakunode_health_monitor.nim @@ -15,8 +15,7 @@ import node/health_monitor/protocol_health, node/health_monitor/topic_health, node/health_monitor/node_health_monitor, - node/delivery_service/delivery_service, - node/delivery_service/subscription_manager, + messaging_client, node/kernel_api/relay, node/kernel_api/store, node/kernel_api/lightpush, @@ -27,6 +26,7 @@ import ] import ../testlib/[wakunode, wakucore], ../waku_archive/archive_utils +import waku/node/subscription_manager const MockDLow = 4 # Mocked GossipSub DLow value @@ -229,8 +229,8 @@ suite "Health Monitor - events": await nodeA.start() let ds = - DeliveryService.new(false, nodeA).expect("Failed to create DeliveryService") - ds.startDeliveryService().expect("Failed to start DeliveryService") + MessagingClient.new(false, nodeA).expect("Failed to create MessagingClient") + ds.start().expect("Failed to start MessagingClient") let monitorA = NodeHealthMonitor.new(nodeA) @@ -317,7 +317,7 @@ suite "Health Monitor - events": lastStatus == ConnectionStatus.Disconnected await monitorA.stopHealthMonitor() - await ds.stopDeliveryService() + await ds.stop() await nodeA.stop() asyncTest "Edge health driven by confirmed filter subscriptions": @@ -333,9 +333,9 @@ suite "Health Monitor - events": await nodeA.start() let ds = - DeliveryService.new(false, nodeA).expect("Failed to create DeliveryService") - ds.startDeliveryService().expect("Failed to start DeliveryService") - let subMgr = ds.subscriptionManager + MessagingClient.new(false, nodeA).expect("Failed to create MessagingClient") + ds.start().expect("Failed to start MessagingClient") + let subMgr = nodeA.subscriptionManager var nodeB: WakuNode lockNewGlobalBrokerContext: @@ -416,7 +416,7 @@ suite "Health Monitor - events": await EventShardTopicHealthChange.dropListener(nodeA.brokerCtx, shardHealthLis) check shardHealthOk == true - check subMgr.edgeFilterSubStates.len > 0 + check nodeA.subscriptionManager.edgeFilterSubStates.len > 0 healthSignal.clear() deadline = Moment.now() + TestConnectivityTimeLimit @@ -428,7 +428,7 @@ suite "Health Monitor - events": check lastStatus == ConnectionStatus.PartiallyConnected - await ds.stopDeliveryService() + await ds.stop() await monitorA.stopHealthMonitor() await nodeB.stop() await nodeA.stop() diff --git a/tests/node/test_wakunode_peer_exchange.nim b/tests/node/test_wakunode_peer_exchange.nim index e6649c455..82ca25868 100644 --- a/tests/node/test_wakunode_peer_exchange.nim +++ b/tests/node/test_wakunode_peer_exchange.nim @@ -9,7 +9,8 @@ import libp2p/peerId, libp2p/crypto/crypto, eth/keys, - eth/p2p/discoveryv5/enr + eth/p2p/discoveryv5/enr, + brokers/broker_context import waku/[ @@ -184,114 +185,115 @@ suite "Waku Peer Exchange": suite "Waku Peer Exchange with discv5": asyncTest "Node successfully exchanges px peers with real discv5": - ## Given (copied from test_waku_discv5.nim) - let - # todo: px flag - flags = CapabilitiesBitfield.init( - lightpush = false, filter = false, store = false, relay = true - ) - bindIp = parseIpAddress("0.0.0.0") - extIp = parseIpAddress("127.0.0.1") + lockNewGlobalBrokerContext: + ## Given (copied from test_waku_discv5.nim) + let + # todo: px flag + flags = CapabilitiesBitfield.init( + lightpush = false, filter = false, store = false, relay = true + ) + bindIp = parseIpAddress("0.0.0.0") + extIp = parseIpAddress("127.0.0.1") - nodeKey1 = generateSecp256k1Key() - nodeTcpPort1 = Port(64010) - nodeUdpPort1 = Port(9000) - node1 = newTestWakuNode( - nodeKey1, - bindIp, - nodeTcpPort1, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort1), + nodeKey1 = generateSecp256k1Key() + nodeTcpPort1 = Port(64010) + nodeUdpPort1 = Port(9000) + node1 = newTestWakuNode( + nodeKey1, + bindIp, + nodeTcpPort1, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort1), + ) + + nodeKey2 = generateSecp256k1Key() + nodeTcpPort2 = Port(64012) + nodeUdpPort2 = Port(9002) + node2 = newTestWakuNode( + nodeKey2, + bindIp, + nodeTcpPort2, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort2), + ) + + nodeKey3 = generateSecp256k1Key() + nodeTcpPort3 = Port(64014) + nodeUdpPort3 = Port(9004) + node3 = newTestWakuNode( + nodeKey3, + bindIp, + nodeTcpPort3, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort3), + ) + + # discv5 + let conf1 = WakuDiscoveryV5Config( + discv5Config: none(DiscoveryConfig), + address: bindIp, + port: nodeUdpPort1, + privateKey: keys.PrivateKey(nodeKey1.skkey), + bootstrapRecords: @[], + autoupdateRecord: true, ) - nodeKey2 = generateSecp256k1Key() - nodeTcpPort2 = Port(64012) - nodeUdpPort2 = Port(9002) - node2 = newTestWakuNode( - nodeKey2, - bindIp, - nodeTcpPort2, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort2), + let disc1 = + WakuDiscoveryV5.new(node1.rng, conf1, some(node1.enr), some(node1.peerManager)) + + let conf2 = WakuDiscoveryV5Config( + discv5Config: none(DiscoveryConfig), + address: bindIp, + port: nodeUdpPort2, + privateKey: keys.PrivateKey(nodeKey2.skkey), + bootstrapRecords: @[disc1.protocol.getRecord()], + autoupdateRecord: true, ) - nodeKey3 = generateSecp256k1Key() - nodeTcpPort3 = Port(64014) - nodeUdpPort3 = Port(9004) - node3 = newTestWakuNode( - nodeKey3, - bindIp, - nodeTcpPort3, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort3), + let disc2 = + WakuDiscoveryV5.new(node2.rng, conf2, some(node2.enr), some(node2.peerManager)) + + await allFutures(node1.start(), node2.start(), node3.start()) + let resultDisc1StartRes = await disc1.start() + assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error + let resultDisc2StartRes = await disc2.start() + assert resultDisc2StartRes.isOk(), resultDisc2StartRes.error + + ## When + var attempts = 10 + while (disc1.protocol.nodesDiscovered < 1 or disc2.protocol.nodesDiscovered < 1) and + attempts > 0: + await sleepAsync(1.seconds) + attempts -= 1 + + # node2 can be connected, so will be returned by peer exchange + require ( + await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) ) - # discv5 - let conf1 = WakuDiscoveryV5Config( - discv5Config: none(DiscoveryConfig), - address: bindIp, - port: nodeUdpPort1, - privateKey: keys.PrivateKey(nodeKey1.skkey), - bootstrapRecords: @[], - autoupdateRecord: true, - ) + # Mount peer exchange + await node1.mountPeerExchange() + await node3.mountPeerExchange() + await node3.mountPeerExchangeClient() - let disc1 = - WakuDiscoveryV5.new(node1.rng, conf1, some(node1.enr), some(node1.peerManager)) + let dialResponse = + await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo()) - let conf2 = WakuDiscoveryV5Config( - discv5Config: none(DiscoveryConfig), - address: bindIp, - port: nodeUdpPort2, - privateKey: keys.PrivateKey(nodeKey2.skkey), - bootstrapRecords: @[disc1.protocol.getRecord()], - autoupdateRecord: true, - ) + check dialResponse.isOk - let disc2 = - WakuDiscoveryV5.new(node2.rng, conf2, some(node2.enr), some(node2.peerManager)) + let + requestPeers = 1 + currentPeers = node3.peerManager.switch.peerStore.peers.len + let res = await node3.fetchPeerExchangePeers(1) + check res.tryGet() == 1 - await allFutures(node1.start(), node2.start(), node3.start()) - let resultDisc1StartRes = await disc1.start() - assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error - let resultDisc2StartRes = await disc2.start() - assert resultDisc2StartRes.isOk(), resultDisc2StartRes.error + # Then node3 has received 1 peer from node1 + check: + node3.peerManager.switch.peerStore.peers.len == currentPeers + requestPeers - ## When - var attempts = 10 - while (disc1.protocol.nodesDiscovered < 1 or disc2.protocol.nodesDiscovered < 1) and - attempts > 0: - await sleepAsync(1.seconds) - attempts -= 1 - - # node2 can be connected, so will be returned by peer exchange - require ( - await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) - ) - - # Mount peer exchange - await node1.mountPeerExchange() - await node3.mountPeerExchange() - await node3.mountPeerExchangeClient() - - let dialResponse = - await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo()) - - check dialResponse.isOk - - let - requestPeers = 1 - currentPeers = node3.peerManager.switch.peerStore.peers.len - let res = await node3.fetchPeerExchangePeers(1) - check res.tryGet() == 1 - - # Then node3 has received 1 peer from node1 - check: - node3.peerManager.switch.peerStore.peers.len == currentPeers + requestPeers - - await allFutures( - [node1.stop(), node2.stop(), node3.stop(), disc1.stop(), disc2.stop()] - ) + await allFutures( + [node1.stop(), node2.stop(), node3.stop(), disc1.stop(), disc2.stop()] + ) diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 936c01826..36d34058c 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -431,7 +431,7 @@ suite "Waku Discovery v5": let waku0 = (await Waku.new(conf)).valueOr: raiseAssert error - (waitFor startWaku(addr waku0)).isOkOr: + (waitFor waku0.start()).isOkOr: raiseAssert error confBuilder.withNodeKey(crypto.PrivateKey.random(Secp256k1, myRng[])[]) @@ -445,7 +445,7 @@ suite "Waku Discovery v5": let waku1 = (await Waku.new(conf1)).valueOr: raiseAssert error - (waitFor startWaku(addr waku1)).isOkOr: + (waitFor waku1.start()).isOkOr: raiseAssert error await waku1.node.mountPeerExchange() @@ -461,7 +461,7 @@ suite "Waku Discovery v5": let waku2 = (await Waku.new(conf2)).valueOr: raiseAssert error - (waitFor startWaku(addr waku2)).isOkOr: + (waitFor waku2.start()).isOkOr: raiseAssert error # leave some time for discv5 to act diff --git a/tests/waku_peer_exchange/test_protocol.nim b/tests/waku_peer_exchange/test_protocol.nim index 74cdba110..29ec45d1e 100644 --- a/tests/waku_peer_exchange/test_protocol.nim +++ b/tests/waku_peer_exchange/test_protocol.nim @@ -5,7 +5,8 @@ import testutils/unittests, chronos, libp2p/[switch, peerId, crypto/crypto], - eth/[keys, p2p/discoveryv5/enr] + eth/[keys, p2p/discoveryv5/enr], + brokers/broker_context import waku/[ @@ -31,110 +32,113 @@ suite "Waku Peer Exchange": suite "request": asyncTest "Retrieve and provide peer exchange peers from discv5": - ## Given (copied from test_waku_discv5.nim) - let - # todo: px flag - flags = CapabilitiesBitfield.init( - lightpush = false, filter = false, store = false, relay = true - ) - bindIp = parseIpAddress("0.0.0.0") - extIp = parseIpAddress("127.0.0.1") + lockNewGlobalBrokerContext: + ## Given (copied from test_waku_discv5.nim) + let + # todo: px flag + flags = CapabilitiesBitfield.init( + lightpush = false, filter = false, store = false, relay = true + ) + bindIp = parseIpAddress("0.0.0.0") + extIp = parseIpAddress("127.0.0.1") - nodeKey1 = generateSecp256k1Key() - nodeTcpPort1 = Port(64010) - nodeUdpPort1 = Port(9000) - node1 = newTestWakuNode( - nodeKey1, - bindIp, - nodeTcpPort1, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort1), + nodeKey1 = generateSecp256k1Key() + nodeTcpPort1 = Port(64010) + nodeUdpPort1 = Port(9000) + node1 = newTestWakuNode( + nodeKey1, + bindIp, + nodeTcpPort1, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort1), + ) + + nodeKey2 = generateSecp256k1Key() + nodeTcpPort2 = Port(64012) + nodeUdpPort2 = Port(9002) + node2 = newTestWakuNode( + nodeKey2, + bindIp, + nodeTcpPort2, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort2), + ) + + nodeKey3 = generateSecp256k1Key() + nodeTcpPort3 = Port(64014) + nodeUdpPort3 = Port(9004) + node3 = newTestWakuNode( + nodeKey3, + bindIp, + nodeTcpPort3, + some(extIp), + wakuFlags = some(flags), + discv5UdpPort = some(nodeUdpPort3), + ) + + # discv5 + let conf1 = WakuDiscoveryV5Config( + discv5Config: none(DiscoveryConfig), + address: bindIp, + port: nodeUdpPort1, + privateKey: keys.PrivateKey(nodeKey1.skkey), + bootstrapRecords: @[], + autoupdateRecord: true, ) - nodeKey2 = generateSecp256k1Key() - nodeTcpPort2 = Port(64012) - nodeUdpPort2 = Port(9002) - node2 = newTestWakuNode( - nodeKey2, - bindIp, - nodeTcpPort2, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort2), + let disc1 = WakuDiscoveryV5.new( + node1.rng, conf1, some(node1.enr), some(node1.peerManager) ) - nodeKey3 = generateSecp256k1Key() - nodeTcpPort3 = Port(64014) - nodeUdpPort3 = Port(9004) - node3 = newTestWakuNode( - nodeKey3, - bindIp, - nodeTcpPort3, - some(extIp), - wakuFlags = some(flags), - discv5UdpPort = some(nodeUdpPort3), + let conf2 = WakuDiscoveryV5Config( + discv5Config: none(DiscoveryConfig), + address: bindIp, + port: nodeUdpPort2, + privateKey: keys.PrivateKey(nodeKey2.skkey), + bootstrapRecords: @[disc1.protocol.getRecord()], + autoupdateRecord: true, ) - # discv5 - let conf1 = WakuDiscoveryV5Config( - discv5Config: none(DiscoveryConfig), - address: bindIp, - port: nodeUdpPort1, - privateKey: keys.PrivateKey(nodeKey1.skkey), - bootstrapRecords: @[], - autoupdateRecord: true, - ) + let disc2 = WakuDiscoveryV5.new( + node2.rng, conf2, some(node2.enr), some(node2.peerManager) + ) - let disc1 = - WakuDiscoveryV5.new(node1.rng, conf1, some(node1.enr), some(node1.peerManager)) + await allFutures(node1.start(), node2.start(), node3.start()) + let resultDisc1StartRes = await disc1.start() + assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error + let resultDisc2StartRes = await disc2.start() + assert resultDisc2StartRes.isOk(), resultDisc2StartRes.error - let conf2 = WakuDiscoveryV5Config( - discv5Config: none(DiscoveryConfig), - address: bindIp, - port: nodeUdpPort2, - privateKey: keys.PrivateKey(nodeKey2.skkey), - bootstrapRecords: @[disc1.protocol.getRecord()], - autoupdateRecord: true, - ) + ## When + var attempts = 10 + while (disc1.protocol.nodesDiscovered < 1 or disc2.protocol.nodesDiscovered < 1) and + attempts > 0: + await sleepAsync(1.seconds) + attempts -= 1 - let disc2 = - WakuDiscoveryV5.new(node2.rng, conf2, some(node2.enr), some(node2.peerManager)) + # node2 can be connected, so will be returned by peer exchange + require ( + await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) + ) - await allFutures(node1.start(), node2.start(), node3.start()) - let resultDisc1StartRes = await disc1.start() - assert resultDisc1StartRes.isOk(), resultDisc1StartRes.error - let resultDisc2StartRes = await disc2.start() - assert resultDisc2StartRes.isOk(), resultDisc2StartRes.error + # Mount peer exchange + await node1.mountPeerExchange() + await node3.mountPeerExchange() - ## When - var attempts = 10 - while (disc1.protocol.nodesDiscovered < 1 or disc2.protocol.nodesDiscovered < 1) and - attempts > 0: - await sleepAsync(1.seconds) - attempts -= 1 + let dialResponse = + await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo()) + let response = dialResponse.get() - # node2 can be connected, so will be returned by peer exchange - require ( - await node1.peerManager.connectPeer(node2.switch.peerInfo.toRemotePeerInfo()) - ) + ## Then + check: + response.get().peerInfos.len == 1 + response.get().peerInfos[0].enr == disc2.protocol.localNode.record.raw - # Mount peer exchange - await node1.mountPeerExchange() - await node3.mountPeerExchange() - - let dialResponse = - await node3.dialForPeerExchange(node1.switch.peerInfo.toRemotePeerInfo()) - let response = dialResponse.get() - - ## Then - check: - response.get().peerInfos.len == 1 - response.get().peerInfos[0].enr == disc2.protocol.localNode.record.raw - - await allFutures( - [node1.stop(), node2.stop(), node3.stop(), disc1.stop(), disc2.stop()] - ) + await allFutures( + [node1.stop(), node2.stop(), node3.stop(), disc1.stop(), disc2.stop()] + ) asyncTest "Request returns some discovered peers": let diff --git a/tests/wakunode2/test_app.nim b/tests/wakunode2/test_app.nim index 7621ab1e7..8dc9e3582 100644 --- a/tests/wakunode2/test_app.nim +++ b/tests/wakunode2/test_app.nim @@ -46,7 +46,7 @@ suite "Wakunode2 - Waku initialization": var waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: raiseAssert error ## Then @@ -71,7 +71,7 @@ suite "Wakunode2 - Waku initialization": var waku = (waitFor Waku.new(conf)).valueOr: raiseAssert error - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: raiseAssert error ## Then @@ -128,7 +128,7 @@ suite "Wakunode2 - Waku initialization": (waitFor waku.stop()).isOkOr: raiseAssert error - (waitFor startWaku(addr waku)).isOkOr: + (waitFor waku.start()).isOkOr: raiseAssert error let portsJson = waku.stateInfo.getNodeInfoItem(NodeInfoId.MyBoundPorts) diff --git a/waku/api/api.nim b/waku/api/api.nim index 1eee982fd..24049002b 100644 --- a/waku/api/api.nim +++ b/waku/api/api.nim @@ -1,9 +1,10 @@ import chronicles, chronos, results import waku/factory/waku +import waku/messaging_client import waku/[requests/health_requests, waku_core, waku_node] import waku/node/delivery_service/send_service -import waku/node/delivery_service/subscription_manager +import waku/node/subscription_manager import libp2p/peerid import ../../tools/confutils/cli_args import ./[api_conf, types] @@ -38,39 +39,15 @@ proc subscribe*( ): Future[Result[void, string]] {.async.} = ?checkApiAvailability(w) - return w.deliveryService.subscriptionManager.subscribe(contentTopic) + return w.node.subscriptionManager.subscribe(contentTopic) proc unsubscribe*(w: Waku, contentTopic: ContentTopic): Result[void, string] = ?checkApiAvailability(w) - return w.deliveryService.subscriptionManager.unsubscribe(contentTopic) + return w.node.subscriptionManager.unsubscribe(contentTopic) proc send*( w: Waku, envelope: MessageEnvelope ): Future[Result[RequestId, string]] {.async.} = ?checkApiAvailability(w) - - let isSubbed = w.deliveryService.subscriptionManager - .isSubscribed(envelope.contentTopic) - .valueOr(false) - if not isSubbed: - info "Auto-subscribing to topic on send", contentTopic = envelope.contentTopic - w.deliveryService.subscriptionManager.subscribe(envelope.contentTopic).isOkOr: - warn "Failed to auto-subscribe", error = error - return err("Failed to auto-subscribe before sending: " & error) - - let requestId = RequestId.new(w.rng) - - let deliveryTask = DeliveryTask.new(requestId, envelope, w.brokerCtx).valueOr: - return err("API send: Failed to create delivery task: " & error) - - info "API send: scheduling delivery task", - requestId = $requestId, - pubsubTopic = deliveryTask.pubsubTopic, - contentTopic = deliveryTask.msg.contentTopic, - msgHash = deliveryTask.msgHash.to0xHex(), - myPeerId = w.node.peerId() - - asyncSpawn w.deliveryService.sendService.send(deliveryTask) - - return ok(requestId) + return await w.messagingClient.send(envelope) diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index 6a5567f8c..ee70cf713 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -30,12 +30,12 @@ import waku_enr/sharding, waku_enr/multiaddr, api/types, + messaging_client, common/logging, node/peer_manager, node/health_monitor, node/waku_metrics, - node/delivery_service/delivery_service, - node/delivery_service/subscription_manager, + node/subscription_manager, rest_api/message_cache, rest_api/endpoint/server, rest_api/endpoint/builder as rest_server_builder, @@ -48,6 +48,7 @@ import factory/app_callbacks, persistency/persistency, ], + channels/reliable_channel_manager, ./waku_conf, ./waku_state_info @@ -73,7 +74,9 @@ type Waku* = ref object healthMonitor*: NodeHealthMonitor - deliveryService*: DeliveryService + messagingClient*: MessagingClient + + reliableChannelManager*: ReliableChannelManager restServer*: WakuRestServerRef metricsServer*: MetricsHttpServerRef @@ -215,10 +218,6 @@ proc new*( error "Failed setting up app callbacks", error = error return err("Failed setting up app callbacks: " & $error) - ## Delivery Monitor - let deliveryService = DeliveryService.new(wakuConf.p2pReliability, node).valueOr: - return err("could not create delivery service: " & $error) - var waku = Waku( stateInfo: WakuStateInfo.init(node), conf: wakuConf, @@ -226,7 +225,6 @@ proc new*( key: wakuConf.nodeKey, node: node, healthMonitor: healthMonitor, - deliveryService: deliveryService, appCallbacks: appCallbacks, restServer: restServer, brokerCtx: brokerCtx, @@ -254,9 +252,9 @@ proc getPorts( return ok((tcpPort: tcpPort, websocketPort: websocketPort)) -proc getRunningNetConfig(waku: ptr Waku): Future[Result[NetConfig, string]] {.async.} = - let conf = waku[].conf - let (tcpPort, websocketPort) = getPorts(waku[].node.switch.peerInfo.listenAddrs).valueOr: +proc getRunningNetConfig(waku: Waku): Future[Result[NetConfig, string]] {.async.} = + let conf = waku.conf + let (tcpPort, websocketPort) = getPorts(waku.node.switch.peerInfo.listenAddrs).valueOr: return err("Could not retrieve ports: " & error) if tcpPort.isSome(): @@ -276,67 +274,67 @@ proc getRunningNetConfig(waku: ptr Waku): Future[Result[NetConfig, string]] {.as return ok(netConf) -proc updateEnr(waku: ptr Waku): Future[Result[void, string]] {.async.} = +proc updateEnr(waku: Waku): Future[Result[void, string]] {.async.} = let netConf: NetConfig = (await getRunningNetConfig(waku)).valueOr: return err("error calling updateNetConfig: " & $error) - let record = enrConfiguration(waku[].conf, netConf).valueOr: + let record = enrConfiguration(waku.conf, netConf).valueOr: return err("ENR setup failed: " & error) - if isClusterMismatched(record, waku[].conf.clusterId): + if isClusterMismatched(record, waku.conf.clusterId): return err("cluster-id mismatch configured shards") - waku[].node.enr = record + waku.node.enr = record # If TCP/WS was configured with port 0, node.announcedAddresses was built # pre-bind with a port value of 0. In any case, the resync is harmless. - waku[].node.announcedAddresses = netConf.announcedAddresses + waku.node.announcedAddresses = netConf.announcedAddresses return ok() -proc updateAddressInENR(waku: ptr Waku): Result[void, string] = - let addresses: seq[MultiAddress] = waku[].node.announcedAddresses +proc updateAddressInENR(waku: Waku): Result[void, string] = + let addresses: seq[MultiAddress] = waku.node.announcedAddresses let encodedAddrs = multiaddr.encodeMultiaddrs(addresses) ## First update the enr info contained in WakuNode - let keyBytes = waku[].key.getRawBytes().valueOr: + let keyBytes = waku.key.getRawBytes().valueOr: return err("failed to retrieve raw bytes from waku key: " & $error) let parsedPk = keys.PrivateKey.fromHex(keyBytes.toHex()).valueOr: return err("failed to parse the private key: " & $error) let enrFields = @[toFieldPair(MultiaddrEnrField, encodedAddrs)] - waku[].node.enr.update(parsedPk, extraFields = enrFields).isOkOr: + waku.node.enr.update(parsedPk, extraFields = enrFields).isOkOr: return err("failed to update multiaddress in ENR updateAddressInENR: " & $error) info "Waku node ENR updated successfully with new multiaddress", - enr = waku[].node.enr.toUri(), record = $(waku[].node.enr) + enr = waku.node.enr.toUri(), record = $(waku.node.enr) ## Now update the ENR infor in discv5 - if not waku[].wakuDiscv5.isNil(): - waku[].wakuDiscv5.protocol.localNode.record = waku[].node.enr - let enr = waku[].wakuDiscv5.protocol.localNode.record + if not waku.wakuDiscv5.isNil(): + waku.wakuDiscv5.protocol.localNode.record = waku.node.enr + let enr = waku.wakuDiscv5.protocol.localNode.record info "Waku discv5 ENR updated successfully with new multiaddress", enr = enr.toUri(), record = $(enr) return ok() -proc updateWaku(waku: ptr Waku): Future[Result[void, string]] {.async.} = +proc updateWaku(waku: Waku): Future[Result[void, string]] {.async.} = (await updateEnr(waku)).isOkOr: return err("error calling updateEnr: " & $error) - ?updateAnnouncedAddrWithPrimaryIpAddr(waku[].node) + ?updateAnnouncedAddrWithPrimaryIpAddr(waku.node) ?updateAddressInENR(waku) return ok() -proc startDnsDiscoveryRetryLoop(waku: ptr Waku): Future[void] {.async.} = +proc startDnsDiscoveryRetryLoop(waku: Waku): Future[void] {.async.} = while true: await sleepAsync(30.seconds) if waku.conf.dnsDiscoveryConf.isSome(): let dnsDiscoveryConf = waku.conf.dnsDiscoveryConf.get() - waku[].dynamicBootstrapNodes = ( + waku.dynamicBootstrapNodes = ( await waku_dnsdisc.retrieveDynamicBootstrapNodes( dnsDiscoveryConf.enrTreeUrl, dnsDiscoveryConf.nameServers ) @@ -344,35 +342,61 @@ proc startDnsDiscoveryRetryLoop(waku: ptr Waku): Future[void] {.async.} = error "Retrieving dynamic bootstrap nodes failed", error = error continue - if not waku[].wakuDiscv5.isNil(): - let dynamicBootstrapEnrs = waku[].dynamicBootstrapNodes - .filterIt(it.hasUdpPort()) - .mapIt(it.enr.get().toUri()) + if not waku.wakuDiscv5.isNil(): + let dynamicBootstrapEnrs = + waku.dynamicBootstrapNodes.filterIt(it.hasUdpPort()).mapIt(it.enr.get().toUri()) var discv5BootstrapEnrs: seq[enr.Record] # parse enrURIs from the configuration and add the resulting ENRs to the discv5BootstrapEnrs seq for enrUri in dynamicBootstrapEnrs: addBootstrapNode(enrUri, discv5BootstrapEnrs) - waku[].wakuDiscv5.updateBootstrapRecords( - waku[].wakuDiscv5.protocol.bootstrapRecords & discv5BootstrapEnrs + waku.wakuDiscv5.updateBootstrapRecords( + waku.wakuDiscv5.protocol.bootstrapRecords & discv5BootstrapEnrs ) info "Connecting to dynamic bootstrap peers" try: - await connectToNodes( - waku[].node, waku[].dynamicBootstrapNodes, "dynamic bootstrap" - ) + await connectToNodes(waku.node, waku.dynamicBootstrapNodes, "dynamic bootstrap") except CatchableError: error "failed to connect to dynamic bootstrap nodes: " & getCurrentExceptionMsg() return -proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: []).} = - if waku[].node.started: - warn "startWaku: waku node already started" +proc mountMessagingClient*(waku: Waku): Result[void, string] = + if not waku.messagingClient.isNil(): + return err("messaging client already mounted") + if waku.node.started: + return err("cannot mount messaging client on a started node") + waku.messagingClient = MessagingClient.new(waku.conf.p2pReliability, waku.node).valueOr: + return err("could not create messaging client: " & $error) + return ok() + +proc mountReliableChannelManager*(waku: Waku): Result[void, string] = + if not waku.reliableChannelManager.isNil(): + return err("reliable channel manager already mounted") + if waku.messagingClient.isNil(): + return err("reliable channel manager requires a mounted messaging client") + if waku.node.started: + return err("cannot mount reliable channel manager on a started node") + + let messagingClient = waku.messagingClient + let defaultSendHandler: SendHandler = proc( + envelope: MessageEnvelope + ): Future[Result[RequestId, string]] {.async: (raises: [CatchableError]), gcsafe.} = + return await messagingClient.send(envelope) + + waku.reliableChannelManager = ReliableChannelManager.new( + messagingClient, defaultSendHandler, waku.brokerCtx + ).valueOr: + return err("could not create reliable channel manager: " & $error) + return ok() + +proc start*(waku: Waku): Future[Result[void, string]] {.async: (raises: []).} = + if waku.node.started: + warn "start: waku node already started" return ok() info "Retrieve dynamic bootstrap nodes" - let conf = waku[].conf + let conf = waku.conf if conf.dnsDiscoveryConf.isSome(): let dnsDiscoveryConf = waku.conf.dnsDiscoveryConf.get() @@ -390,9 +414,9 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: error "Retrieving dynamic bootstrap nodes failed", error = dynamicBootstrapNodesRes.error # Start Dns Discovery retry loop - waku[].dnsRetryLoopHandle = waku.startDnsDiscoveryRetryLoop() + waku.dnsRetryLoopHandle = waku.startDnsDiscoveryRetryLoop() else: - waku[].dynamicBootstrapNodes = dynamicBootstrapNodesRes.get() + waku.dynamicBootstrapNodes = dynamicBootstrapNodesRes.get() ## Initialize persistency singleton instance - we don't need the instance itself here, ## but this ensures it's initialized before any store job starts. @@ -405,12 +429,12 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: let bound = getPorts(waku.node.switch.peerInfo.listenAddrs).valueOr: return err("failed to read bound ports from switch: " & $error) - waku[].node.ports.tcp = bound.tcpPort.get(Port(0)).uint16 - waku[].node.ports.webSocket = bound.websocketPort.get(Port(0)).uint16 + waku.node.ports.tcp = bound.tcpPort.get(Port(0)).uint16 + waku.node.ports.webSocket = bound.websocketPort.get(Port(0)).uint16 ## Discv5 if conf.discv5Conf.isSome(): - waku[].wakuDiscV5 = ( + waku.wakuDiscV5 = ( await waku_discv5.setupAndStartDiscv5( waku.node.enr, waku.node.peerManager, @@ -425,23 +449,21 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: ).valueOr: return err("failed to start waku discovery v5: " & error) - waku[].node.ports.discv5Udp = waku[].wakuDiscV5.udpPort.uint16 - waku[].conf.discv5Conf.get().udpPort = waku[].wakuDiscV5.udpPort + waku.node.ports.discv5Udp = waku.wakuDiscV5.udpPort.uint16 + waku.conf.discv5Conf.get().udpPort = waku.wakuDiscV5.udpPort ## Update waku data that is set dynamically on node start try: (await updateWaku(waku)).isOkOr: - return err("Error in startWaku: " & $error) + return err("Error in start: " & $error) except CatchableError: - return err("Caught exception in startWaku: " & getCurrentExceptionMsg()) + return err("Caught exception in start: " & getCurrentExceptionMsg()) - ## Reliability - if not waku[].deliveryService.isNil(): - waku[].deliveryService.startDeliveryService().isOkOr: - return err("failed to start delivery service: " & $error) + waku.node.subscriptionManager.subscribeAllAutoshards().isOkOr: + return err("failed to auto-subscribe autosharding shards: " & $error) ## Health Monitor - waku[].healthMonitor.startHealthMonitor().isOkOr: + waku.healthMonitor.startHealthMonitor().isOkOr: return err("failed to start health monitor: " & $error) ## Setup RequestConnectionStatus provider @@ -450,7 +472,7 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: globalBrokerContext(), proc(): Result[RequestConnectionStatus, string] = try: - let healthReport = waku[].healthMonitor.getSyncNodeHealthReport() + let healthReport = waku.healthMonitor.getSyncNodeHealthReport() return ok(RequestConnectionStatus(connectionStatus: healthReport.connectionStatus)) except CatchableError: @@ -467,7 +489,7 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: ): Future[Result[RequestProtocolHealth, string]] {.async.} = try: let protocolHealthStatus = - await waku[].healthMonitor.getProtocolHealthInfo(protocol) + await waku.healthMonitor.getProtocolHealthInfo(protocol) return ok(RequestProtocolHealth(healthStatus: protocolHealthStatus)) except CatchableError: return err("Failed to get protocol health: " & getCurrentExceptionMsg()), @@ -480,7 +502,7 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: globalBrokerContext(), proc(): Future[Result[RequestHealthReport, string]] {.async.} = try: - let report = await waku[].healthMonitor.getNodeHealthReport() + let report = await waku.healthMonitor.getNodeHealthReport() return ok(RequestHealthReport(healthReport: report)) except CatchableError: return err("Failed to get health report: " & getCurrentExceptionMsg()), @@ -489,9 +511,9 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: if conf.restServerConf.isSome(): rest_server_builder.startRestServerProtocolSupport( - waku[].restServer, - waku[].node, - waku[].wakuDiscv5, + waku.restServer, + waku.node, + waku.wakuDiscv5, conf.restServerConf.get(), conf.relay, conf.lightPush, @@ -509,21 +531,27 @@ proc startWaku*(waku: ptr Waku): Future[Result[void, string]] {.async: (raises: ) ).valueOr: return err("Starting monitoring and external interfaces failed: " & error) - waku[].metricsServer = server - waku[].node.ports.metrics = port.uint16 - waku[].conf.metricsServerConf.get().httpPort = port + waku.metricsServer = server + waku.node.ports.metrics = port.uint16 + waku.conf.metricsServerConf.get().httpPort = port except CatchableError: return err( "Caught exception starting monitoring and external interfaces failed: " & getCurrentExceptionMsg() ) - waku[].healthMonitor.setOverallHealth(HealthStatus.READY) + waku.healthMonitor.setOverallHealth(HealthStatus.READY) + + if not waku.messagingClient.isNil(): + waku.messagingClient.start().isOkOr: + return err("failed to start messaging client: " & $error) + + if not waku.reliableChannelManager.isNil(): + waku.reliableChannelManager.start().isOkOr: + return err("failed to start reliable channel manager: " & $error) return ok() proc stop*(waku: Waku): Future[Result[void, string]] {.async: (raises: []).} = - ## Waku shutdown - if not waku.node.started: warn "stop: attempting to stop node that isn't running" @@ -538,9 +566,11 @@ proc stop*(waku: Waku): Future[Result[void, string]] {.async: (raises: []).} = if not waku.wakuDiscv5.isNil(): await waku.wakuDiscv5.stop() - if not waku.deliveryService.isNil(): - await waku.deliveryService.stopDeliveryService() - waku.deliveryService = nil + if not waku.reliableChannelManager.isNil(): + await waku.reliableChannelManager.stop() + + if not waku.messagingClient.isNil(): + await waku.messagingClient.stop() if not waku.node.isNil(): await waku.node.stop() diff --git a/waku/messaging_client.nim b/waku/messaging_client.nim new file mode 100644 index 000000000..1fc4deb3c --- /dev/null +++ b/waku/messaging_client.nim @@ -0,0 +1,63 @@ +import results, chronos +import chronicles +import + ./api/types, + ./node/[ + waku_node, + subscription_manager, + delivery_service/recv_service, + delivery_service/send_service, + delivery_service/send_service/delivery_task, + ] + +type MessagingClient* = ref object + node: WakuNode + sendService*: SendService + recvService*: RecvService + started: bool + +proc new*( + T: type MessagingClient, useP2PReliability: bool, node: WakuNode +): Result[T, string] = + let sendService = ?SendService.new(useP2PReliability, node) + let recvService = RecvService.new(node) + ok(T(node: node, sendService: sendService, recvService: recvService)) + +proc start*(self: MessagingClient): Result[void, string] = + if self.started: + return ok() + self.recvService.startRecvService() + self.sendService.startSendService() + self.started = true + ok() + +proc stop*(self: MessagingClient) {.async.} = + if not self.started: + return + await self.sendService.stopSendService() + await self.recvService.stopRecvService() + self.started = false + +proc send*( + self: MessagingClient, envelope: MessageEnvelope +): Future[Result[RequestId, string]] {.async.} = + ## High-level messaging API send. Auto-subscribes to the content topic + ## (so the local node sees its own gossipsub broadcast), builds a + ## `DeliveryTask`, and hands it to the send service. Returns the request + ## id the caller can correlate with `MessageSentEvent` / `MessageErrorEvent`. + let isSubbed = + self.node.subscriptionManager.isSubscribed(envelope.contentTopic).valueOr(false) + if not isSubbed: + info "Auto-subscribing to topic on send", contentTopic = envelope.contentTopic + self.node.subscriptionManager.subscribe(envelope.contentTopic).isOkOr: + warn "Failed to auto-subscribe", error = error + return err("Failed to auto-subscribe before sending: " & error) + + let requestId = RequestId.new(self.node.rng) + + let deliveryTask = DeliveryTask.new(requestId, envelope, self.node.brokerCtx).valueOr: + return err("MessagingClient.send: Failed to create delivery task: " & error) + + asyncSpawn self.sendService.send(deliveryTask) + + return ok(requestId) diff --git a/waku/node/delivery_service/delivery_service.nim b/waku/node/delivery_service/delivery_service.nim deleted file mode 100644 index f3d78d98e..000000000 --- a/waku/node/delivery_service/delivery_service.nim +++ /dev/null @@ -1,44 +0,0 @@ -## This module helps to ensure the correct transmission and reception of messages - -import results -import chronos, chronicles -import - ./recv_service, - ./send_service, - ./subscription_manager, - waku/[ - waku_core, waku_node, waku_store/client, waku_relay/protocol, waku_lightpush/client - ] - -type DeliveryService* = ref object - sendService*: SendService - recvService*: RecvService - subscriptionManager*: SubscriptionManager - -proc new*( - T: type DeliveryService, useP2PReliability: bool, w: WakuNode -): Result[T, string] = - ## storeClient is needed to give store visitility to DeliveryService - ## wakuRelay and wakuLightpushClient are needed to give a mechanism to SendService to re-publish - let subscriptionManager = SubscriptionManager.new(w) - let sendService = ?SendService.new(useP2PReliability, w, subscriptionManager) - let recvService = RecvService.new(w, subscriptionManager) - - return ok( - DeliveryService( - sendService: sendService, - recvService: recvService, - subscriptionManager: subscriptionManager, - ) - ) - -proc startDeliveryService*(self: DeliveryService): Result[void, string] = - ?self.subscriptionManager.startSubscriptionManager() - self.recvService.startRecvService() - self.sendService.startSendService() - return ok() - -proc stopDeliveryService*(self: DeliveryService) {.async.} = - await self.sendService.stopSendService() - await self.recvService.stopRecvService() - await self.subscriptionManager.stopSubscriptionManager() diff --git a/waku/node/delivery_service/recv_service/recv_service.nim b/waku/node/delivery_service/recv_service/recv_service.nim index 899f80f71..500926cc7 100644 --- a/waku/node/delivery_service/recv_service/recv_service.nim +++ b/waku/node/delivery_service/recv_service/recv_service.nim @@ -4,17 +4,17 @@ import std/[tables, sequtils, options, sets] import chronos, chronicles, libp2p/utility -import ../[subscription_manager] import brokers/broker_context import waku/[ waku_core, + waku_core/topics, waku_store/client, waku_store/common, waku_filter_v2/client, - waku_core/topics, events/message_events, waku_node, + node/subscription_manager, ] const StoreCheckPeriod = chronos.minutes(5) ## How often to perform store queries @@ -38,7 +38,6 @@ type RecvService* = ref object of RootObj brokerCtx: BrokerContext node: WakuNode seenMsgListener: MessageSeenEventListener - subscriptionManager: SubscriptionManager recentReceivedMsgs: seq[RecvMessage] @@ -77,7 +76,9 @@ proc processIncomingMessage( ## or if the message is a duplicate (recently-seen). Otherwise, save it as ## recently-seen, emit a MessageReceivedEvent, and return true. - if not self.subscriptionManager.isSubscribed(pubsubTopic, message.contentTopic): + if not self.node.subscriptionManager.isContentSubscribed( + pubsubTopic, message.contentTopic + ): trace "skipping message as I am not subscribed", shard = pubsubTopic, contentTopic = message.contentTopic return false @@ -101,7 +102,7 @@ proc checkStore*(self: RecvService) {.async.} = self.endTimeToCheck = getNowInNanosecondTime() ## query store and deliver new recovered messages per subscribed topic - for pubsubTopic, contentTopics in self.subscriptionManager.subscribedTopics: + for pubsubTopic, contentTopics in self.node.subscriptionManager.subscribedContentTopics: let storeResp: StoreQueryResponse = ( await self.node.wakuStoreClient.queryToAny( StoreQueryRequest( @@ -146,7 +147,7 @@ proc msgChecker(self: RecvService) {.async.} = await sleepAsync(StoreCheckPeriod) await self.checkStore() -proc new*(T: typedesc[RecvService], node: WakuNode, s: SubscriptionManager): T = +proc new*(T: typedesc[RecvService], node: WakuNode): T = ## The storeClient will help to acquire any possible missed messages let now = getNowInNanosecondTime() @@ -154,7 +155,6 @@ proc new*(T: typedesc[RecvService], node: WakuNode, s: SubscriptionManager): T = node: node, startTimeToCheck: now, brokerCtx: node.brokerCtx, - subscriptionManager: s, recentReceivedMsgs: @[], ) diff --git a/waku/node/delivery_service/send_service/send_service.nim b/waku/node/delivery_service/send_service/send_service.nim index 88ec802cf..e60b26124 100644 --- a/waku/node/delivery_service/send_service/send_service.nim +++ b/waku/node/delivery_service/send_service/send_service.nim @@ -6,10 +6,10 @@ import chronos, chronicles, libp2p/utility import brokers/broker_context import ./[send_processor, relay_processor, lightpush_processor, delivery_task], - ../[subscription_manager], waku/[ waku_core, node/waku_node, + node/subscription_manager, node/peer_manager, waku_store/client, waku_store/common, @@ -58,7 +58,6 @@ type SendService* = ref object of RootObj node: WakuNode checkStoreForMessages: bool - subscriptionManager: SubscriptionManager proc setupSendProcessorChain( peerManager: PeerManager, @@ -96,10 +95,7 @@ proc setupSendProcessorChain( return ok(processors[0]) proc new*( - T: typedesc[SendService], - preferP2PReliability: bool, - w: WakuNode, - s: SubscriptionManager, + T: typedesc[SendService], preferP2PReliability: bool, w: WakuNode ): Result[T, string] = if w.wakuRelay.isNil() and w.wakuLightpushClient.isNil(): return err( @@ -120,7 +116,6 @@ proc new*( sendProcessor: sendProcessorChain, node: w, checkStoreForMessages: checkStoreForMessages, - subscriptionManager: s, ) return ok(sendService) @@ -263,7 +258,7 @@ proc send*(self: SendService, task: DeliveryTask) {.async.} = info "SendService.send: processing delivery task", requestId = task.requestId, msgHash = task.msgHash.to0xHex() - self.subscriptionManager.subscribe(task.msg.contentTopic).isOkOr: + self.node.subscriptionManager.subscribe(task.msg.contentTopic).isOkOr: error "SendService.send: failed to subscribe to content topic", contentTopic = task.msg.contentTopic, error = error diff --git a/waku/node/delivery_service/subscription_manager.nim b/waku/node/delivery_service/subscription_manager.nim deleted file mode 100644 index 393a61eae..000000000 --- a/waku/node/delivery_service/subscription_manager.nim +++ /dev/null @@ -1,596 +0,0 @@ -import std/[sequtils, sets, tables, options, strutils], chronos, chronicles, results -import libp2p/[peerid, peerinfo] -import brokers/broker_context - -import - waku/[ - waku_core, - waku_core/topics, - waku_core/topics/sharding, - waku_node, - waku_relay, - waku_filter_v2/common as filter_common, - waku_filter_v2/client as filter_client, - waku_filter_v2/protocol as filter_protocol, - events/health_events, - events/peer_events, - requests/health_requests, - node/peer_manager, - node/health_monitor/topic_health, - node/health_monitor/connection_status, - ] - -# --------------------------------------------------------------------------- -# Logos Messaging API SubscriptionManager -# -# Maps all topic subscription intent and centralizes all consistency -# maintenance of the pubsub and content topic subscription model across -# the various network drivers that handle topics (Edge/Filter and Core/Relay). -# --------------------------------------------------------------------------- - -type EdgeFilterSubState* = object - peers: seq[RemotePeerInfo] - ## Filter service peers with confirmed subscriptions on this shard. - pending: seq[Future[void]] ## In-flight dial futures for peers not yet confirmed. - pendingPeers: HashSet[PeerId] ## PeerIds of peers currently being dialed. - currentHealth: TopicHealth - ## Cached health derived from peers.len; updated on every peer set change. - -func toTopicHealth*(peersCount: int): TopicHealth = - if peersCount >= HealthyThreshold: - TopicHealth.SUFFICIENTLY_HEALTHY - elif peersCount > 0: - TopicHealth.MINIMALLY_HEALTHY - else: - TopicHealth.UNHEALTHY - -type SubscriptionManager* = ref object of RootObj - node: WakuNode - contentTopicSubs: Table[PubsubTopic, HashSet[ContentTopic]] - ## Map of Shard to ContentTopic needed because e.g. WakuRelay is PubsubTopic only. - ## A present key with an empty HashSet value means pubsubtopic already subscribed - ## (via subscribePubsubTopics()) but there's no specific content topic interest yet. - edgeFilterSubStates*: Table[PubsubTopic, EdgeFilterSubState] - ## Per-shard filter subscription state for edge mode. - edgeFilterWakeup: AsyncEvent - ## Signalled when the edge filter sub loop should re-reconcile. - edgeFilterSubLoopFut: Future[void] - edgeFilterHealthLoopFut: Future[void] - peerEventListener: WakuPeerEventListener - ## Listener for peer connect/disconnect events (edge filter wakeup). - -iterator subscribedTopics*( - self: SubscriptionManager -): (PubsubTopic, HashSet[ContentTopic]) = - ## Iterate over all subscribed content topics, batched per shard. - ## This is guaranteed to return a non-empty `topics` (content topics) list on iteration. - - for pubsub, topics in self.contentTopicSubs.pairs: - # We are iterating over subscribed content topics; if we are subscribed to - # a shard but have no subscription (interest) for any content topic in that - # shard, then avoid triggering an iteration that doesn't advance the intent - # to iterate over content topic subscriptions. - if topics.len == 0: - continue - yield (pubsub, topics) - -proc edgeFilterPeerCount*(sm: SubscriptionManager, shard: PubsubTopic): int = - sm.edgeFilterSubStates.withValue(shard, state): - return state.peers.len - return 0 - -proc new*(T: typedesc[SubscriptionManager], node: WakuNode): T = - SubscriptionManager( - node: node, contentTopicSubs: initTable[PubsubTopic, HashSet[ContentTopic]]() - ) - -proc addContentTopicInterest( - self: SubscriptionManager, shard: PubsubTopic, topic: ContentTopic -): Result[void, string] = - var changed = false - if not self.contentTopicSubs.hasKey(shard): - self.contentTopicSubs[shard] = initHashSet[ContentTopic]() - changed = true - - self.contentTopicSubs.withValue(shard, cTopics): - if not cTopics[].contains(topic): - cTopics[].incl(topic) - changed = true - - if changed and not isNil(self.edgeFilterWakeup): - self.edgeFilterWakeup.fire() - - return ok() - -proc removeContentTopicInterest( - self: SubscriptionManager, shard: PubsubTopic, topic: ContentTopic -): Result[void, string] = - var changed = false - self.contentTopicSubs.withValue(shard, cTopics): - if cTopics[].contains(topic): - cTopics[].excl(topic) - changed = true - - if cTopics[].len == 0 and isNil(self.node.wakuRelay): - self.contentTopicSubs.del(shard) # We're done with cTopics here - - if changed and not isNil(self.edgeFilterWakeup): - self.edgeFilterWakeup.fire() - - return ok() - -proc subscribePubsubTopics( - self: SubscriptionManager, shards: seq[PubsubTopic] -): Result[void, string] = - if isNil(self.node.wakuRelay): - return err("subscribePubsubTopics requires a Relay") - - var errors: seq[string] - - for shard in shards: - if not self.contentTopicSubs.hasKey(shard): - self.node.subscribe((kind: PubsubSub, topic: shard), nil).isOkOr: - errors.add("shard " & shard & ": " & error) - continue - - self.contentTopicSubs[shard] = initHashSet[ContentTopic]() - - if errors.len > 0: - return err("subscribeShard errors: " & errors.join("; ")) - - return ok() - -proc getShardForContentTopic( - self: SubscriptionManager, topic: ContentTopic -): Result[PubsubTopic, string] = - if self.node.wakuAutoSharding.isSome(): - let shardObj = ?self.node.wakuAutoSharding.get().getShard(topic) - return ok($shardObj) - - return err("SubscriptionManager requires AutoSharding") - -proc isSubscribed*( - self: SubscriptionManager, topic: ContentTopic -): Result[bool, string] = - let shard = ?self.getShardForContentTopic(topic) - return ok( - self.contentTopicSubs.hasKey(shard) and self.contentTopicSubs[shard].contains(topic) - ) - -proc isSubscribed*( - self: SubscriptionManager, shard: PubsubTopic, contentTopic: ContentTopic -): bool {.raises: [].} = - self.contentTopicSubs.withValue(shard, cTopics): - return cTopics[].contains(contentTopic) - return false - -proc subscribe*(self: SubscriptionManager, topic: ContentTopic): Result[void, string] = - if isNil(self.node.wakuRelay) and isNil(self.node.wakuFilterClient): - return err("SubscriptionManager requires either Relay or Filter Client.") - - let shard = ?self.getShardForContentTopic(topic) - - if not isNil(self.node.wakuRelay) and not self.contentTopicSubs.hasKey(shard): - ?self.subscribePubsubTopics(@[shard]) - - ?self.addContentTopicInterest(shard, topic) - - return ok() - -proc unsubscribe*( - self: SubscriptionManager, topic: ContentTopic -): Result[void, string] = - if isNil(self.node.wakuRelay) and isNil(self.node.wakuFilterClient): - return err("SubscriptionManager requires either Relay or Filter Client.") - - let shard = ?self.getShardForContentTopic(topic) - - if self.isSubscribed(shard, topic): - ?self.removeContentTopicInterest(shard, topic) - - return ok() - -# --------------------------------------------------------------------------- -# Edge Filter driver for the Logos Messaging API -# -# The SubscriptionManager absorbs natively the responsibility of using the -# Edge Filter protocol to effect subscriptions and message receipt for edge. -# --------------------------------------------------------------------------- - -const EdgeFilterSubscribeTimeout = chronos.seconds(15) - ## Timeout for a single filter subscribe/unsubscribe RPC to a service peer. -const EdgeFilterPingTimeout = chronos.seconds(5) - ## Timeout for a filter ping health check. -const EdgeFilterLoopInterval = chronos.seconds(30) - ## Interval for the edge filter health ping loop. -const EdgeFilterSubLoopDebounce = chronos.seconds(1) - ## Debounce delay to coalesce rapid-fire wakeups into a single reconciliation pass. - -type EdgeDialTask = object - peer: RemotePeerInfo - shard: PubsubTopic - topics: seq[ContentTopic] - -proc updateShardHealth( - self: SubscriptionManager, shard: PubsubTopic, state: var EdgeFilterSubState -) = - ## Recompute and emit health for a shard after its peer set changed. - let newHealth = toTopicHealth(state.peers.len) - if newHealth != state.currentHealth: - state.currentHealth = newHealth - EventShardTopicHealthChange.emit(self.node.brokerCtx, shard, newHealth) - -proc removePeer(self: SubscriptionManager, shard: PubsubTopic, peerId: PeerId) = - ## Remove a peer from edgeFilterSubStates for the given shard, - ## update health, and wake the sub loop to dial a replacement. - ## Best-effort unsubscribe so the service peer stops pushing to us. - self.edgeFilterSubStates.withValue(shard, state): - var peer: RemotePeerInfo - var found = false - for p in state.peers: - if p.peerId == peerId: - peer = p - found = true - break - if not found: - return - - state.peers.keepItIf(it.peerId != peerId) - self.updateShardHealth(shard, state[]) - self.edgeFilterWakeup.fire() - - if not self.node.wakuFilterClient.isNil(): - self.contentTopicSubs.withValue(shard, topics): - let ct = toSeq(topics[]) - if ct.len > 0: - proc doUnsubscribe() {.async.} = - discard await self.node.wakuFilterClient.unsubscribe(peer, shard, ct) - - asyncSpawn doUnsubscribe() - -type SendChunkedFilterRpcKind = enum - FilterSubscribe - FilterUnsubscribe - -proc sendChunkedFilterRpc( - self: SubscriptionManager, - peer: RemotePeerInfo, - shard: PubsubTopic, - topics: seq[ContentTopic], - kind: SendChunkedFilterRpcKind, -): Future[bool] {.async.} = - ## Send a chunked filter subscribe or unsubscribe RPC. Returns true on - ## success. On failure the peer is removed and false is returned. - try: - var i = 0 - while i < topics.len: - let chunk = - topics[i ..< min(i + filter_protocol.MaxContentTopicsPerRequest, topics.len)] - let fut = - case kind - of FilterSubscribe: - self.node.wakuFilterClient.subscribe(peer, shard, chunk) - of FilterUnsubscribe: - self.node.wakuFilterClient.unsubscribe(peer, shard, chunk) - if not (await fut.withTimeout(EdgeFilterSubscribeTimeout)) or fut.read().isErr(): - trace "sendChunkedFilterRpc: chunk failed", - op = kind, shard = shard, peer = peer.peerId - self.removePeer(shard, peer.peerId) - return false - i += filter_protocol.MaxContentTopicsPerRequest - except CatchableError as exc: - debug "sendChunkedFilterRpc: failed", - op = kind, shard = shard, peer = peer.peerId, err = exc.msg - self.removePeer(shard, peer.peerId) - return false - return true - -proc syncFilterDeltas( - self: SubscriptionManager, - peer: RemotePeerInfo, - shard: PubsubTopic, - added: seq[ContentTopic], - removed: seq[ContentTopic], -) {.async.} = - ## Push content topic changes (adds/removes) to an already-tracked peer. - if added.len > 0: - if not await self.sendChunkedFilterRpc(peer, shard, added, FilterSubscribe): - return - - if removed.len > 0: - discard await self.sendChunkedFilterRpc(peer, shard, removed, FilterUnsubscribe) - -proc dialFilterPeer( - self: SubscriptionManager, - peer: RemotePeerInfo, - shard: PubsubTopic, - contentTopics: seq[ContentTopic], -) {.async.} = - ## Subscribe a new peer to all content topics on a shard and start tracking it. - self.edgeFilterSubStates.withValue(shard, state): - state.pendingPeers.incl(peer.peerId) - - try: - if not await self.sendChunkedFilterRpc(peer, shard, contentTopics, FilterSubscribe): - return - - self.edgeFilterSubStates.withValue(shard, state): - if state.peers.anyIt(it.peerId == peer.peerId): - trace "dialFilterPeer: peer already tracked, skipping duplicate", - shard = shard, peer = peer.peerId - return - - state.peers.add(peer) - self.updateShardHealth(shard, state[]) - trace "dialFilterPeer: successfully subscribed to all chunks", - shard = shard, peer = peer.peerId, totalPeers = state.peers.len - do: - trace "dialFilterPeer: shard removed while subscribing, discarding result", - shard = shard, peer = peer.peerId - finally: - self.edgeFilterSubStates.withValue(shard, state): - state.pendingPeers.excl(peer.peerId) - -proc edgeFilterHealthLoop*(self: SubscriptionManager) {.async.} = - ## Periodically pings all connected filter service peers to verify they are - ## still alive at the application layer. Peers that fail the ping are removed. - while true: - await sleepAsync(EdgeFilterLoopInterval) - - if self.node.wakuFilterClient.isNil(): - warn "filter client is nil within edge filter health loop" - continue - - var connected = initTable[PeerId, RemotePeerInfo]() - for state in self.edgeFilterSubStates.values: - for peer in state.peers: - if self.node.peerManager.switch.peerStore.isConnected(peer.peerId): - connected[peer.peerId] = peer - - var alive = initHashSet[PeerId]() - - if connected.len > 0: - var pingTasks: seq[(PeerId, Future[FilterSubscribeResult])] - for peer in connected.values: - pingTasks.add( - (peer.peerId, self.node.wakuFilterClient.ping(peer, EdgeFilterPingTimeout)) - ) - - # extract future tasks from (PeerId, Future) tuples and await them - await allFutures(pingTasks.mapIt(it[1])) - - for (peerId, task) in pingTasks: - if task.read().isOk(): - alive.incl(peerId) - - var changed = false - for shard, state in self.edgeFilterSubStates.mpairs: - let oldLen = state.peers.len - state.peers.keepItIf(it.peerId notin connected or alive.contains(it.peerId)) - - if state.peers.len < oldLen: - changed = true - self.updateShardHealth(shard, state) - trace "Edge Filter health degraded by Ping failure", - shard = shard, new = state.currentHealth - - if changed: - self.edgeFilterWakeup.fire() - -proc selectFilterCandidates( - self: SubscriptionManager, shard: PubsubTopic, exclude: HashSet[PeerId], needed: int -): seq[RemotePeerInfo] = - ## Select filter service peer candidates for a shard. - - # Start with every filter server peer that can serve the shard - var allCandidates = self.node.peerManager.selectPeers( - filter_common.WakuFilterSubscribeCodec, some(shard) - ) - - # Remove all already used in this shard or being dialed for it - allCandidates.keepItIf(it.peerId notin exclude) - - # Collect peer IDs already tracked on other shards - var trackedOnOther = initHashSet[PeerId]() - for otherShard, otherState in self.edgeFilterSubStates.pairs: - if otherShard != shard: - for peer in otherState.peers: - trackedOnOther.incl(peer.peerId) - - # Prefer peers we already have a connection to first, preserving shuffle - var candidates = - allCandidates.filterIt(it.peerId in trackedOnOther) & - allCandidates.filterIt(it.peerId notin trackedOnOther) - - # We need to return 'needed' peers only - if candidates.len > needed: - candidates.setLen(needed) - return candidates - -proc edgeFilterSubLoop*(self: SubscriptionManager) {.async.} = - ## Reconciles filter subscriptions with the desired state from SubscriptionManager. - var lastSynced = initTable[PubsubTopic, HashSet[ContentTopic]]() - - while true: - await self.edgeFilterWakeup.wait() - await sleepAsync(EdgeFilterSubLoopDebounce) - self.edgeFilterWakeup.clear() - trace "edgeFilterSubLoop: woke up" - - if isNil(self.node.wakuFilterClient): - trace "edgeFilterSubLoop: wakuFilterClient is nil, skipping" - continue - - let desired = self.contentTopicSubs - - trace "edgeFilterSubLoop: desired state", numShards = desired.len - - let allShards = toHashSet(toSeq(desired.keys)) + toHashSet(toSeq(lastSynced.keys)) - - # Step 1: read state across all shards at once and - # create a list of peer dial tasks and shard tracking to delete. - - var dialTasks: seq[EdgeDialTask] - var shardsToDelete: seq[PubsubTopic] - - for shard in allShards: - let currTopics = desired.getOrDefault(shard) - let prevTopics = lastSynced.getOrDefault(shard) - - if shard notin self.edgeFilterSubStates: - self.edgeFilterSubStates[shard] = - EdgeFilterSubState(currentHealth: TopicHealth.UNHEALTHY) - - let addedTopics = toSeq(currTopics - prevTopics) - let removedTopics = toSeq(prevTopics - currTopics) - - self.edgeFilterSubStates.withValue(shard, state): - state.peers.keepItIf( - self.node.peerManager.switch.peerStore.isConnected(it.peerId) - ) - state.pending.keepItIf(not it.finished) - - if addedTopics.len > 0 or removedTopics.len > 0: - for peer in state.peers: - asyncSpawn self.syncFilterDeltas(peer, shard, addedTopics, removedTopics) - - if currTopics.len == 0: - shardsToDelete.add(shard) - else: - self.updateShardHealth(shard, state[]) - - let needed = max(0, HealthyThreshold - state.peers.len - state.pending.len) - - if needed > 0: - let tracked = state.peers.mapIt(it.peerId).toHashSet() + state.pendingPeers - let candidates = self.selectFilterCandidates(shard, tracked, needed) - let toDial = min(needed, candidates.len) - - trace "edgeFilterSubLoop: shard reconciliation", - shard = shard, - num_peers = state.peers.len, - num_pending = state.pending.len, - num_needed = needed, - num_available = candidates.len, - toDial = toDial - - for i in 0 ..< toDial: - dialTasks.add( - EdgeDialTask( - peer: candidates[i], shard: shard, topics: toSeq(currTopics) - ) - ) - - # Step 2: execute deferred shard tracking deletion and dial tasks. - - for shard in shardsToDelete: - self.edgeFilterSubStates.withValue(shard, state): - for fut in state.pending: - if not fut.finished: - await fut.cancelAndWait() - self.edgeFilterSubStates.del(shard) - - for task in dialTasks: - let fut = self.dialFilterPeer(task.peer, task.shard, task.topics) - self.edgeFilterSubStates.withValue(task.shard, state): - state.pending.add(fut) - - lastSynced = desired - -proc startEdgeFilterLoops(self: SubscriptionManager): Result[void, string] = - ## Start the edge filter orchestration loops. - ## Caller must ensure this is only called in edge mode (relay nil, filter client present). - self.edgeFilterWakeup = newAsyncEvent() - - self.peerEventListener = WakuPeerEvent.listen( - self.node.brokerCtx, - proc(evt: WakuPeerEvent) {.async: (raises: []), gcsafe.} = - if evt.kind == WakuPeerEventKind.EventDisconnected or - evt.kind == WakuPeerEventKind.EventMetadataUpdated: - self.edgeFilterWakeup.fire() - , - ).valueOr: - return err("Failed to listen to peer events for edge filter: " & error) - - self.edgeFilterSubLoopFut = self.edgeFilterSubLoop() - self.edgeFilterHealthLoopFut = self.edgeFilterHealthLoop() - return ok() - -proc stopEdgeFilterLoops(self: SubscriptionManager) {.async: (raises: []).} = - ## Stop the edge filter orchestration loops and clean up pending futures. - if not isNil(self.edgeFilterSubLoopFut): - await self.edgeFilterSubLoopFut.cancelAndWait() - self.edgeFilterSubLoopFut = nil - - if not isNil(self.edgeFilterHealthLoopFut): - await self.edgeFilterHealthLoopFut.cancelAndWait() - self.edgeFilterHealthLoopFut = nil - - for shard, state in self.edgeFilterSubStates: - for fut in state.pending: - if not fut.finished: - await fut.cancelAndWait() - - await WakuPeerEvent.dropListener(self.node.brokerCtx, self.peerEventListener) - -# --------------------------------------------------------------------------- -# SubscriptionManager Lifecycle (calls Edge behavior above) -# -# startSubscriptionManager and stopSubscriptionManager orchestrate both the -# core (relay) and edge (filter) paths, and register/clear broker providers. -# --------------------------------------------------------------------------- - -proc startSubscriptionManager*(self: SubscriptionManager): Result[void, string] = - # Register edge filter broker providers. The shard/content health providers - # in WakuNode query these via the broker as a fallback when relay health is - # not available. If edge mode is not active, these providers simply return - # NOT_SUBSCRIBED / strength 0, which is harmless. - RequestEdgeShardHealth.setProvider( - self.node.brokerCtx, - proc(shard: PubsubTopic): Result[RequestEdgeShardHealth, string] = - self.edgeFilterSubStates.withValue(shard, state): - return ok(RequestEdgeShardHealth(health: state.currentHealth)) - return ok(RequestEdgeShardHealth(health: TopicHealth.NOT_SUBSCRIBED)), - ).isOkOr: - error "Can't set provider for RequestEdgeShardHealth", error = error - - RequestEdgeFilterPeerCount.setProvider( - self.node.brokerCtx, - proc(): Result[RequestEdgeFilterPeerCount, string] = - var minPeers = high(int) - for state in self.edgeFilterSubStates.values: - minPeers = min(minPeers, state.peers.len) - if minPeers == high(int): - minPeers = 0 - return ok(RequestEdgeFilterPeerCount(peerCount: minPeers)), - ).isOkOr: - error "Can't set provider for RequestEdgeFilterPeerCount", error = error - - if self.node.wakuRelay.isNil(): - return self.startEdgeFilterLoops() - - # Core mode: auto-subscribe relay to all shards in autosharding. - if self.node.wakuAutoSharding.isSome(): - let autoSharding = self.node.wakuAutoSharding.get() - let clusterId = autoSharding.clusterId - let numShards = autoSharding.shardCountGenZero - - if numShards > 0: - var clusterPubsubTopics = newSeqOfCap[PubsubTopic](numShards) - - for i in 0 ..< numShards: - let shardObj = RelayShard(clusterId: clusterId, shardId: uint16(i)) - clusterPubsubTopics.add(PubsubTopic($shardObj)) - - self.subscribePubsubTopics(clusterPubsubTopics).isOkOr: - error "Failed to auto-subscribe Relay to cluster shards: ", error = error - else: - info "SubscriptionManager has no AutoSharding configured; skipping auto-subscribe." - - return ok() - -proc stopSubscriptionManager*(self: SubscriptionManager) {.async: (raises: []).} = - if self.node.wakuRelay.isNil(): - await self.stopEdgeFilterLoops() - RequestEdgeShardHealth.clearProvider(self.node.brokerCtx) - RequestEdgeFilterPeerCount.clearProvider(self.node.brokerCtx) diff --git a/waku/node/health_monitor/node_health_monitor.nim b/waku/node/health_monitor/node_health_monitor.nim index c652f7cea..98c0f6c7a 100644 --- a/waku/node/health_monitor/node_health_monitor.nim +++ b/waku/node/health_monitor/node_health_monitor.nim @@ -14,6 +14,7 @@ import events/health_events, events/peer_events, node/waku_node, + node/node_telemetry, node/peer_manager, node/kernel_api, node/health_monitor/online_monitor, diff --git a/waku/node/kernel_api/filter.nim b/waku/node/kernel_api/filter.nim index 948035f14..0db4875b0 100644 --- a/waku/node/kernel_api/filter.nim +++ b/waku/node/kernel_api/filter.nim @@ -21,6 +21,7 @@ import import ../waku_node, + ../node_telemetry, ../../waku_core, ../../waku_core/topics/sharding, ../../waku_filter_v2, diff --git a/waku/node/kernel_api/peer_exchange.nim b/waku/node/kernel_api/peer_exchange.nim index a4bec727b..1cb6bd3bb 100644 --- a/waku/node/kernel_api/peer_exchange.nim +++ b/waku/node/kernel_api/peer_exchange.nim @@ -19,6 +19,7 @@ import import ../waku_node, + ../node_telemetry, ../../waku_peer_exchange, ../../waku_core, ../peer_manager, diff --git a/waku/node/kernel_api/relay.nim b/waku/node/kernel_api/relay.nim index f1b80cf19..30fc22ec3 100644 --- a/waku/node/kernel_api/relay.nim +++ b/waku/node/kernel_api/relay.nim @@ -29,90 +29,18 @@ import waku_store_sync, waku_rln_relay, node/waku_node, + node/subscription_manager, node/peer_manager, events/message_events, ] export waku_relay.WakuRelayHandler -declarePublicHistogram waku_histogram_message_size, - "message size histogram in kB", - buckets = [ - 0.0, 1.0, 3.0, 5.0, 15.0, 50.0, 75.0, 100.0, 125.0, 150.0, 500.0, 700.0, 1000.0, Inf - ] - logScope: topics = "waku node relay api" ## Waku relay -proc registerRelayHandler( - node: WakuNode, topic: PubsubTopic, appHandler: WakuRelayHandler = nil -): bool = - ## Registers the only handler for the given topic. - ## Notice that this handler internally calls other handlers, such as filter, - ## archive, etc, plus the handler provided by the application. - ## Returns `true` if a mesh subscription was created or `false` if the relay - ## was already subscribed to the topic. - - let alreadySubscribed = node.wakuRelay.isSubscribed(topic) - - if not appHandler.isNil(): - if not alreadySubscribed or not node.legacyAppHandlers.hasKey(topic): - node.legacyAppHandlers[topic] = appHandler - else: - debug "Legacy appHandler already exists for active PubsubTopic, ignoring new handler", - topic = topic - - if alreadySubscribed: - return false - - proc traceHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = - let msgSizeKB = msg.payload.len / 1000 - - waku_node_messages.inc(labelValues = ["relay"]) - waku_histogram_message_size.observe(msgSizeKB) - - proc filterHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = - if node.wakuFilter.isNil(): - return - - await node.wakuFilter.handleMessage(topic, msg) - - proc archiveHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = - if node.wakuArchive.isNil(): - return - - await node.wakuArchive.handleMessage(topic, msg) - - proc syncHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = - if node.wakuStoreReconciliation.isNil(): - return - - node.wakuStoreReconciliation.messageIngress(topic, msg) - - proc internalHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = - MessageSeenEvent.emit(node.brokerCtx, topic, msg) - - let uniqueTopicHandler = proc( - topic: PubsubTopic, msg: WakuMessage - ): Future[void] {.async, gcsafe.} = - await traceHandler(topic, msg) - await filterHandler(topic, msg) - await archiveHandler(topic, msg) - await syncHandler(topic, msg) - await internalHandler(topic, msg) - - # Call the legacy (kernel API) app handler if it exists. - # Normally, hasKey is false and the MessageSeenEvent bus (new API) is used instead. - # But we need to support legacy behavior (kernel API use), hence this. - # NOTE: We can delete `legacyAppHandlers` if instead we refactor WakuRelay to support multiple - # PubsubTopic handlers, since that's actually supported by libp2p PubSub (bigger refactor...) - if node.legacyAppHandlers.hasKey(topic) and not node.legacyAppHandlers[topic].isNil(): - await node.legacyAppHandlers[topic](topic, msg) - - node.wakuRelay.subscribe(topic, uniqueTopicHandler) - proc getTopicOfSubscriptionEvent( node: WakuNode, subscription: SubscriptionEvent ): Result[(PubsubTopic, Option[ContentTopic]), string] = @@ -143,21 +71,15 @@ proc subscribe*( error "Invalid API call to `subscribe`. WakuRelay not mounted." return err("Invalid API call to `subscribe`. WakuRelay not mounted.") - let (pubsubTopic, contentTopicOp) = getTopicOfSubscriptionEvent(node, subscription).valueOr: + let (pubsubTopic, _) = getTopicOfSubscriptionEvent(node, subscription).valueOr: error "Failed to decode subscription event", error = error return err("Failed to decode subscription event: " & error) - if node.registerRelayHandler(pubsubTopic, handler): - info "subscribe", pubsubTopic, contentTopicOp - node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: pubsubTopic)) - else: - if isNil(handler): - warn "No-effect API call to subscribe. Already subscribed to topic", pubsubTopic - else: - info "subscribe (was already subscribed in the mesh; appHandler set)", - pubsubTopic = pubsubTopic - - return ok() + # strict version + #if contentTopicOp.isSome(): + # return + # node.subscriptionManager.subscribe(pubsubTopic, contentTopicOp.get(), handler) + return node.subscriptionManager.subscribeShard(pubsubTopic, handler) proc unsubscribe*( node: WakuNode, subscription: SubscriptionEvent @@ -170,26 +92,14 @@ proc unsubscribe*( error "Invalid API call to `unsubscribe`. WakuRelay not mounted." return err("Invalid API call to `unsubscribe`. WakuRelay not mounted.") - let (pubsubTopic, contentTopicOp) = getTopicOfSubscriptionEvent(node, subscription).valueOr: + let (pubsubTopic, _) = getTopicOfSubscriptionEvent(node, subscription).valueOr: error "Failed to decode unsubscribe event", error = error return err("Failed to decode unsubscribe event: " & error) - let hadHandler = node.legacyAppHandlers.hasKey(pubsubTopic) - if hadHandler: - node.legacyAppHandlers.del(pubsubTopic) - - if node.wakuRelay.isSubscribed(pubsubTopic): - info "unsubscribe", pubsubTopic, contentTopicOp - node.wakuRelay.unsubscribe(pubsubTopic) - node.topicSubscriptionQueue.emit((kind: PubsubUnsub, topic: pubsubTopic)) - else: - if not hadHandler: - warn "No-effect API call to `unsubscribe`. Was not subscribed", pubsubTopic - else: - info "unsubscribe (was not subscribed in the mesh; appHandler removed)", - pubsubTopic = pubsubTopic - - return ok() + # strict version + #if contentTopicOp.isSome(): + # return node.subscriptionManager.unsubscribe(pubsubTopic, contentTopicOp.get()) + return node.subscriptionManager.unsubscribeAll(pubsubTopic) proc isSubscribed*( node: WakuNode, subscription: SubscriptionEvent diff --git a/waku/node/node_telemetry.nim b/waku/node/node_telemetry.nim new file mode 100644 index 000000000..cd214969c --- /dev/null +++ b/waku/node/node_telemetry.nim @@ -0,0 +1,27 @@ +{.push raises: [].} + +import metrics + +declarePublicGauge waku_version, + "Waku version info (in git describe format)", ["version"] + +declarePublicCounter waku_node_errors, "number of wakunode errors", ["type"] + +declarePublicGauge waku_lightpush_peers, "number of lightpush peers" + +declarePublicGauge waku_filter_peers, "number of filter peers" + +declarePublicGauge waku_store_peers, "number of store peers" + +declarePublicGauge waku_px_peers, + "number of peers (in the node's peerManager) supporting the peer exchange protocol" + +declarePublicCounter waku_node_messages, "number of messages received", ["type"] + +declarePublicHistogram waku_histogram_message_size, + "message size histogram in kB", + buckets = [ + 0.0, 1.0, 3.0, 5.0, 15.0, 50.0, 75.0, 100.0, 125.0, 150.0, 500.0, 700.0, 1000.0, Inf + ] + +{.pop.} diff --git a/waku/node/node_types.nim b/waku/node/node_types.nim new file mode 100644 index 000000000..f5c2a56b6 --- /dev/null +++ b/waku/node/node_types.nim @@ -0,0 +1,116 @@ +{.push raises: [].} + +import + std/[options, tables, sets], + chronos, + results, + eth/keys, + bearssl/rand, + eth/p2p/discoveryv5/enr, + libp2p/crypto/crypto, + libp2p/[multiaddress, multicodec], + libp2p/protocols/ping, + libp2p/protocols/mix/mix_protocol, + brokers/broker_context + +import + waku/[ + waku_core, + waku_relay, + waku_archive, + waku_store/protocol as store, + waku_store/client as store_client, + waku_store/resume, + waku_store_sync, + waku_filter_v2, + waku_filter_v2/client as filter_client, + waku_metadata, + waku_rendezvous/protocol, + waku_rendezvous/client as rendezvous_client, + waku_lightpush_legacy/client as legacy_lightpush_client, + waku_lightpush_legacy as legacy_lightpush_protocol, + waku_lightpush/client as lightpush_client, + waku_lightpush as lightpush_protocol, + waku_peer_exchange, + waku_rln_relay, + waku_mix, + common/rate_limit/setting, + discovery/waku_kademlia, + net/bound_ports, + events/peer_events, + ], + ./peer_manager, + ./health_monitor/topic_health + +# key and crypto modules different +type + # TODO: Move to application instance (e.g., `WakuNode2`) + WakuInfo* = object # NOTE One for simplicity, can extend later as needed + listenAddresses*: seq[string] + enrUri*: string #multiaddrStrings*: seq[string] + mixPubKey*: Option[string] + + # NOTE based on Eth2Node in NBC eth2_network.nim + WakuNode* = ref object + peerManager*: PeerManager + switch*: Switch + wakuRelay*: WakuRelay + wakuArchive*: waku_archive.WakuArchive + wakuStore*: store.WakuStore + wakuStoreClient*: store_client.WakuStoreClient + wakuStoreResume*: StoreResume + wakuStoreReconciliation*: SyncReconciliation + wakuStoreTransfer*: SyncTransfer + wakuFilter*: waku_filter_v2.WakuFilter + wakuFilterClient*: filter_client.WakuFilterClient + wakuRlnRelay*: WakuRLNRelay + wakuLegacyLightPush*: WakuLegacyLightPush + wakuLegacyLightpushClient*: WakuLegacyLightPushClient + wakuLightPush*: WakuLightPush + wakuLightpushClient*: WakuLightPushClient + wakuPeerExchange*: WakuPeerExchange + wakuPeerExchangeClient*: WakuPeerExchangeClient + wakuMetadata*: WakuMetadata + wakuAutoSharding*: Option[Sharding] + enr*: enr.Record + libp2pPing*: Ping + rng*: ref rand.HmacDrbgContext + brokerCtx*: BrokerContext + wakuRendezvous*: WakuRendezVous + wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient + announcedAddresses*: seq[MultiAddress] + extMultiAddrsOnly*: bool # When true, skip automatic IP address replacement + started*: bool # Indicates that node has started listening + topicSubscriptionQueue*: AsyncEventQueue[SubscriptionEvent] + rateLimitSettings*: ProtocolRateLimitSettings + legacyAppHandlers*: Table[PubsubTopic, WakuRelayHandler] + ## Kernel API Relay appHandlers (if any) + subscriptionManager*: SubscriptionManager + wakuMix*: WakuMix + kademliaDiscoveryLoop*: Future[void] + wakuKademlia*: WakuKademlia + ports*: BoundPorts + + ShardSubscription* = object + contentTopics*: HashSet[ContentTopic] + directShardSub*: bool + ## shard subscribed directly (PubsubSub), independent of content-topic interest + + EdgeFilterSubState* = object + peers*: seq[RemotePeerInfo] + pending*: seq[Future[void]] + pendingPeers*: HashSet[PeerId] + currentHealth*: TopicHealth + + SubscriptionManager* = ref object of RootObj + node*: WakuNode + shards*: Table[PubsubTopic, ShardSubscription] + edgeFilterSubStates*: Table[PubsubTopic, EdgeFilterSubState] + edgeFilterWakeup*: AsyncEvent + edgeFilterSubLoopFut*: Future[void] + edgeFilterConnectionLoopFut*: Future[void] + peerEventListener*: WakuPeerEventListener + ownsEdgeShardHealthProvider*: bool + ownsEdgeFilterPeerCountProvider*: bool + +{.pop.} diff --git a/waku/node/subscription_manager.nim b/waku/node/subscription_manager.nim new file mode 100644 index 000000000..409fab53f --- /dev/null +++ b/waku/node/subscription_manager.nim @@ -0,0 +1,711 @@ +import std/[sequtils, sets, tables, options], chronos, chronicles, metrics, results +import libp2p/[peerid, peerinfo] +import brokers/broker_context + +import + waku/[ + waku_core, + waku_core/topics/sharding, + node/node_types, + node/node_telemetry, + waku_relay, + waku_archive, + waku_store_sync, + waku_filter_v2/common as filter_common, + waku_filter_v2/client as filter_client, + waku_filter_v2/protocol as filter_protocol, + events/health_events, + events/message_events, + events/peer_events, + requests/health_requests, + node/peer_manager, + node/health_monitor/topic_health, + node/health_monitor/connection_status, + ] + +{.push raises: [].} + +proc registerRelayHandler( + node: WakuNode, shard: PubsubTopic, appHandler: WakuRelayHandler = nil +): bool = + ## Returns true iff we did a new (and only) subscription for this shard in GossipSub. + let alreadySubscribed = node.wakuRelay.isSubscribed(shard) + + if not appHandler.isNil(): + if not alreadySubscribed or not node.legacyAppHandlers.hasKey(shard): + node.legacyAppHandlers[shard] = appHandler + else: + debug "Legacy appHandler already exists for active shard, ignoring new handler", + shard + + if alreadySubscribed: + return false + + proc traceHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = + let msgSizeKB = msg.payload.len / 1000 + + waku_node_messages.inc(labelValues = ["relay"]) + waku_histogram_message_size.observe(msgSizeKB) + + proc filterHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = + if node.wakuFilter.isNil(): + return + + await node.wakuFilter.handleMessage(topic, msg) + + proc archiveHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = + if node.wakuArchive.isNil(): + return + + await node.wakuArchive.handleMessage(topic, msg) + + proc syncHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = + if node.wakuStoreReconciliation.isNil(): + return + + node.wakuStoreReconciliation.messageIngress(topic, msg) + + proc internalHandler(topic: PubsubTopic, msg: WakuMessage) {.async, gcsafe.} = + MessageSeenEvent.emit(node.brokerCtx, topic, msg) + + let uniqueTopicHandler = proc( + topic: PubsubTopic, msg: WakuMessage + ): Future[void] {.async, gcsafe.} = + await traceHandler(topic, msg) + await filterHandler(topic, msg) + await archiveHandler(topic, msg) + await syncHandler(topic, msg) + await internalHandler(topic, msg) + + if node.legacyAppHandlers.hasKey(topic) and not node.legacyAppHandlers[topic].isNil(): + await node.legacyAppHandlers[topic](topic, msg) + + node.wakuRelay.subscribe(shard, uniqueTopicHandler) + return true + +proc unregisterRelayHandler(node: WakuNode, shard: PubsubTopic): bool = + ## Returns true iff we had a subscription for this shard in GossipSub and it was removed. + if node.legacyAppHandlers.hasKey(shard): + node.legacyAppHandlers.del(shard) + + if node.wakuRelay.isSubscribed(shard): + node.wakuRelay.unsubscribe(shard) + return true + return false + +proc doRelaySubscribe( + node: WakuNode, shard: PubsubTopic, appHandler: WakuRelayHandler = nil +): bool = + ## Subscribes the node to a shard. + ## Returns true if we actually subscribed (transitioned from unsubscribed to subscribed). + ## Emit the shard subscription event if we actually subscribed. + let installed = node.registerRelayHandler(shard, appHandler) + if installed: + node.topicSubscriptionQueue.emit((kind: PubsubSub, topic: shard)) + return installed + +proc doRelayUnsubscribe(node: WakuNode, shard: PubsubTopic): bool = + ## Unsubscribes the node from a shard. + ## Returns true if we actually unsubscribed (transitioned from subscribed to unsubscribed). + ## Emit the shard unsubscription event if we actually unsubscribed. + let unsubscribed = node.unregisterRelayHandler(shard) + if unsubscribed: + node.topicSubscriptionQueue.emit((kind: PubsubUnsub, topic: shard)) + return unsubscribed + +proc new*(T: type SubscriptionManager, node: WakuNode): T = + T( + node: node, + shards: initTable[PubsubTopic, ShardSubscription](), + edgeFilterSubStates: initTable[PubsubTopic, EdgeFilterSubState](), + edgeFilterWakeup: newAsyncEvent(), + ) + +func wanted(entry: ShardSubscription): bool = + ## True if the shard has content-topic interest or a direct subscription. + return entry.contentTopics.len > 0 or entry.directShardSub + +proc isContentSubscribed*( + self: SubscriptionManager, shard: PubsubTopic, contentTopic: ContentTopic +): bool = + self.shards.withValue(shard, sub): + return contentTopic in sub.contentTopics + return false + +iterator subscribedContentTopics*( + self: SubscriptionManager +): (PubsubTopic, HashSet[ContentTopic]) = + ## Yields each shard with its non-empty content-topic set. + for shard, sub in self.shards.pairs: + if sub.contentTopics.len > 0: + yield (shard, sub.contentTopics) + +func toTopicHealth*(peersCount: int): TopicHealth = + if peersCount >= HealthyThreshold: + return TopicHealth.SUFFICIENTLY_HEALTHY + elif peersCount > 0: + return TopicHealth.MINIMALLY_HEALTHY + else: + return TopicHealth.UNHEALTHY + +proc edgeFilterPeerCount*(self: SubscriptionManager, shard: PubsubTopic): int = + self.edgeFilterSubStates.withValue(shard, state): + return state.peers.len + return 0 + +proc getShardForContentTopic( + self: SubscriptionManager, topic: ContentTopic +): Result[PubsubTopic, string] = + if self.node.wakuAutoSharding.isSome(): + let shardObj = ?self.node.wakuAutoSharding.get().getShard(topic) + return ok($shardObj) + + return err("autosharding is not configured; pass an explicit shard") + +proc subscribeShard*( + self: SubscriptionManager, shard: PubsubTopic, handler: WakuRelayHandler = nil +): Result[void, string] = + ## Subscribes to the shard directly and joins the relay mesh. + var added = false + self.shards.withValue(shard, entry): + if not entry.directShardSub: + entry.directShardSub = true + added = true + do: + self.shards[shard] = ShardSubscription( + contentTopics: initHashSet[ContentTopic](), directShardSub: true + ) + added = true + if added: + self.edgeFilterWakeup.fire() + if not isNil(self.node.wakuRelay): + discard self.node.doRelaySubscribe(shard, handler) + return ok() + +proc unsubscribeShard*( + self: SubscriptionManager, shard: PubsubTopic +): Result[void, string] = + ## Drops the direct shard subscription; unsubscribes the mesh if no content topic wants it. + var removed = false + var shardEmpty = false + self.shards.withValue(shard, entry): + if entry.directShardSub: + entry.directShardSub = false + removed = true + shardEmpty = not entry[].wanted() + if removed: + self.edgeFilterWakeup.fire() + if shardEmpty: + self.shards.del(shard) + if not isNil(self.node.wakuRelay): + discard self.node.doRelayUnsubscribe(shard) + return ok() + +proc subscribe*( + self: SubscriptionManager, + shard: PubsubTopic, + contentTopic: ContentTopic, + handler: WakuRelayHandler = nil, +): Result[void, string] = + ## Adds content-topic interest on the shard and joins the relay mesh. + var added = false + self.shards.withValue(shard, entry): + if contentTopic notin entry.contentTopics: + entry.contentTopics.incl(contentTopic) + added = true + do: + var entry = ShardSubscription(contentTopics: initHashSet[ContentTopic]()) + entry.contentTopics.incl(contentTopic) + self.shards[shard] = entry + added = true + if added: + self.edgeFilterWakeup.fire() + if not isNil(self.node.wakuRelay): + discard self.node.doRelaySubscribe(shard, handler) + return ok() + +proc unsubscribe*( + self: SubscriptionManager, shard: PubsubTopic, contentTopic: ContentTopic +): Result[void, string] = + ## Drops content-topic interest on the shard; unsubscribes the mesh if nothing else wants it. + var removed = false + var shardEmpty = false + self.shards.withValue(shard, entry): + if contentTopic in entry.contentTopics: + entry.contentTopics.excl(contentTopic) + removed = true + shardEmpty = not entry[].wanted() + if removed: + self.edgeFilterWakeup.fire() + if shardEmpty: + self.shards.del(shard) + if not isNil(self.node.wakuRelay): + discard self.node.doRelayUnsubscribe(shard) + return ok() + +proc subscribe*(self: SubscriptionManager, topic: ContentTopic): Result[void, string] = + ## Subscribes to a content topic, resolving its shard via autosharding. + let shard = ?self.getShardForContentTopic(topic) + return self.subscribe(shard, topic) + +proc unsubscribe*( + self: SubscriptionManager, topic: ContentTopic +): Result[void, string] = + ## Unsubscribes from a content topic, resolving its shard via autosharding. + let shard = ?self.getShardForContentTopic(topic) + return self.unsubscribe(shard, topic) + +proc unsubscribeAll*( + self: SubscriptionManager, shard: PubsubTopic +): Result[void, string] = + ## Drops every content topic on the shard, then the direct subscription. + var snapshot: seq[ContentTopic] + self.shards.withValue(shard, sub): + snapshot = toSeq(sub.contentTopics) + for contentTopic in snapshot: + ?self.unsubscribe(shard, contentTopic) + return self.unsubscribeShard(shard) + +proc isSubscribed*( + self: SubscriptionManager, topic: ContentTopic +): Result[bool, string] = + let shard = ?self.getShardForContentTopic(topic) + return ok(self.isContentSubscribed(shard, topic)) + +proc subscribeAllAutoshards*(self: SubscriptionManager): Result[void, string] = + ## Subscribes the relay to every shard in the configured autosharding cluster. + if self.node.wakuRelay.isNil() or self.node.wakuAutoSharding.isNone(): + return ok() + + let autoSharding = self.node.wakuAutoSharding.get() + let numShards = autoSharding.shardCountGenZero + if numShards == 0: + return ok() + + for i in 0'u32 ..< numShards: + let shardObj = RelayShard(clusterId: autoSharding.clusterId, shardId: uint16(i)) + self.subscribeShard(PubsubTopic($shardObj)).isOkOr: + error "failed to auto-subscribe relay to cluster shard", + shard = $shardObj, error = error + + ok() + +{.pop.} + +const EdgeFilterSubscribeTimeout = chronos.seconds(15) + ## Timeout for a single filter subscribe/unsubscribe RPC to a service peer. +const EdgeFilterPingTimeout = chronos.seconds(5) + ## Timeout for a filter ping health check. +const EdgeFilterLoopInterval = chronos.seconds(30) + ## Interval for the edge filter health ping loop. +const EdgeFilterSubLoopDebounce = chronos.seconds(1) + ## Debounce delay to coalesce rapid-fire wakeups into a single reconciliation pass. + +type EdgeFilterSubscribeTask = object + peer: RemotePeerInfo + shard: PubsubTopic + topics: seq[ContentTopic] + +proc updateShardHealth( + self: SubscriptionManager, shard: PubsubTopic, state: var EdgeFilterSubState +) = + ## Recompute and emit health for a shard after its peer set changed. + let newHealth = toTopicHealth(state.peers.len) + if newHealth != state.currentHealth: + state.currentHealth = newHealth + EventShardTopicHealthChange.emit(self.node.brokerCtx, shard, newHealth) + +proc removePeer(self: SubscriptionManager, shard: PubsubTopic, peerId: PeerId) = + ## Remove a peer from edgeFilterSubStates for the given shard, + ## update health, and wake the sub loop to filter-subscribe a replacement. + ## Best-effort unsubscribe so the service peer stops pushing to us. + self.edgeFilterSubStates.withValue(shard, state): + var idx = -1 + for i, p in state.peers: + if p.peerId == peerId: + idx = i + break + if idx < 0: + return + + let peer = state.peers[idx] + state.peers.del(idx) + self.updateShardHealth(shard, state[]) + self.edgeFilterWakeup.fire() + + if not self.node.wakuFilterClient.isNil(): + self.shards.withValue(shard, sub): + let ct = toSeq(sub.contentTopics) + if ct.len > 0: + proc doUnsubscribe() {.async.} = + discard await self.node.wakuFilterClient.unsubscribe(peer, shard, ct) + + asyncSpawn doUnsubscribe() + +type SendChunkedFilterRpcKind = enum + FilterSubscribe + FilterUnsubscribe + +proc sendChunkedFilterRpc( + self: SubscriptionManager, + peer: RemotePeerInfo, + shard: PubsubTopic, + topics: seq[ContentTopic], + kind: SendChunkedFilterRpcKind, +): Future[bool] {.async.} = + ## Send a chunked filter subscribe or unsubscribe RPC. Returns true on + ## success. On failure the peer is removed and false is returned. + try: + var i = 0 + while i < topics.len: + let chunk = + topics[i ..< min(i + filter_protocol.MaxContentTopicsPerRequest, topics.len)] + let fut = + case kind + of FilterSubscribe: + self.node.wakuFilterClient.subscribe(peer, shard, chunk) + of FilterUnsubscribe: + self.node.wakuFilterClient.unsubscribe(peer, shard, chunk) + if not (await fut.withTimeout(EdgeFilterSubscribeTimeout)) or fut.read().isErr(): + trace "sendChunkedFilterRpc: chunk failed", + op = kind, shard = shard, peer = peer.peerId + self.removePeer(shard, peer.peerId) + return false + i += filter_protocol.MaxContentTopicsPerRequest + except CatchableError as exc: + debug "sendChunkedFilterRpc: failed", + op = kind, shard = shard, peer = peer.peerId, err = exc.msg + self.removePeer(shard, peer.peerId) + return false + return true + +proc syncFilterDeltas( + self: SubscriptionManager, + peer: RemotePeerInfo, + shard: PubsubTopic, + added: seq[ContentTopic], + removed: seq[ContentTopic], +) {.async.} = + ## Push content topic changes (adds/removes) to an already-tracked peer. + if added.len > 0: + if not await self.sendChunkedFilterRpc(peer, shard, added, FilterSubscribe): + return + + if removed.len > 0: + discard await self.sendChunkedFilterRpc(peer, shard, removed, FilterUnsubscribe) + +proc subscribeFilterPeer( + self: SubscriptionManager, + peer: RemotePeerInfo, + shard: PubsubTopic, + contentTopics: seq[ContentTopic], +) {.async.} = + ## Filter-subscribe to a service peer for all content topics on a shard and + ## start tracking it (note that the filter client dials the peer if not connected). + self.edgeFilterSubStates.withValue(shard, state): + state.pendingPeers.incl(peer.peerId) + + try: + if not await self.sendChunkedFilterRpc(peer, shard, contentTopics, FilterSubscribe): + return + + self.edgeFilterSubStates.withValue(shard, state): + if state.peers.anyIt(it.peerId == peer.peerId): + trace "subscribeFilterPeer: peer already tracked, skipping duplicate", + shard = shard, peer = peer.peerId + return + + state.peers.add(peer) + self.updateShardHealth(shard, state[]) + trace "subscribeFilterPeer: successfully subscribed to all chunks", + shard = shard, peer = peer.peerId, totalPeers = state.peers.len + do: + trace "subscribeFilterPeer: shard removed while subscribing, discarding result", + shard = shard, peer = peer.peerId + finally: + self.edgeFilterSubStates.withValue(shard, state): + state.pendingPeers.excl(peer.peerId) + +proc edgeFilterConnectionLoop(self: SubscriptionManager) {.async.} = + ## Periodically pings all tracked filter service peers to verify they are + ## still alive at the application layer. Peers that fail the ping are removed. + while true: + await sleepAsync(EdgeFilterLoopInterval) + + if self.node.wakuFilterClient.isNil(): + warn "filter client is nil within edge filter connection loop" + continue + + var connected = initTable[PeerId, RemotePeerInfo]() + for state in self.edgeFilterSubStates.values: + for peer in state.peers: + if self.node.peerManager.switch.peerStore.isConnected(peer.peerId): + connected[peer.peerId] = peer + + var alive = initHashSet[PeerId]() + + if connected.len > 0: + var pingTasks: seq[(PeerId, Future[FilterSubscribeResult])] + for peer in connected.values: + pingTasks.add( + (peer.peerId, self.node.wakuFilterClient.ping(peer, EdgeFilterPingTimeout)) + ) + + await allFutures(pingTasks.mapIt(it[1])) + + for (peerId, task) in pingTasks: + if task.read().isOk(): + alive.incl(peerId) + + var changed = false + for shard, state in self.edgeFilterSubStates.mpairs: + let oldLen = state.peers.len + state.peers.keepItIf(it.peerId notin connected or alive.contains(it.peerId)) + + if state.peers.len < oldLen: + changed = true + self.updateShardHealth(shard, state) + trace "Edge Filter health degraded by Ping failure", + shard = shard, new = state.currentHealth + + if changed: + self.edgeFilterWakeup.fire() + +proc selectFilterCandidates( + self: SubscriptionManager, shard: PubsubTopic, exclude: HashSet[PeerId], needed: int +): seq[RemotePeerInfo] = + ## Select filter service peer candidates for a shard. + + # Start with every filter server peer that can serve the shard + var allCandidates = self.node.peerManager.selectPeers( + filter_common.WakuFilterSubscribeCodec, some(shard) + ) + + # Remove all already used in this shard or being filter-subscribed for it + allCandidates.keepItIf(it.peerId notin exclude) + + # Collect peer IDs already tracked on other shards + var trackedOnOther = initHashSet[PeerId]() + for otherShard, otherState in self.edgeFilterSubStates.pairs: + if otherShard != shard: + for peer in otherState.peers: + trackedOnOther.incl(peer.peerId) + + # Prefer peers we already have a connection to first, preserving shuffle + var candidates = + allCandidates.filterIt(it.peerId in trackedOnOther) & + allCandidates.filterIt(it.peerId notin trackedOnOther) + + # We need to return 'needed' peers only + if candidates.len > needed: + candidates.setLen(needed) + return candidates + +proc edgeFilterSubLoop(self: SubscriptionManager) {.async.} = + ## Reconciles filter subscriptions with the desired state from SubscriptionManager. + var lastSynced = initTable[PubsubTopic, HashSet[ContentTopic]]() + + while true: + await self.edgeFilterWakeup.wait() + await sleepAsync(EdgeFilterSubLoopDebounce) + self.edgeFilterWakeup.clear() + trace "edgeFilterSubLoop: woke up" + + if isNil(self.node.wakuFilterClient): + trace "edgeFilterSubLoop: wakuFilterClient is nil, skipping" + continue + + var newSynced = initTable[PubsubTopic, HashSet[ContentTopic]]() + var allShards: HashSet[PubsubTopic] + for shard, sub in self.shards.pairs: + if sub.contentTopics.len > 0: + newSynced[shard] = sub.contentTopics + allShards.incl(shard) + for shard in lastSynced.keys: + allShards.incl(shard) + + trace "edgeFilterSubLoop: desired state", numShards = newSynced.len + + # Step 1: read state across all shards at once and + # create a list of peer filter-subscribe tasks and shard tracking to delete. + + var subscribeTasks: seq[EdgeFilterSubscribeTask] + var shardsToDelete: seq[PubsubTopic] + + for shard in allShards: + # Compute added/removed deltas via direct iteration; no HashSet copies. + var addedTopics: seq[ContentTopic] + var removedTopics: seq[ContentTopic] + newSynced.withValue(shard, curr): + lastSynced.withValue(shard, prev): + for t in curr[]: + if t notin prev[]: + addedTopics.add(t) + for t in prev[]: + if t notin curr[]: + removedTopics.add(t) + do: + for t in curr[]: + addedTopics.add(t) + do: + lastSynced.withValue(shard, prev): + for t in prev[]: + removedTopics.add(t) + + discard self.edgeFilterSubStates.mgetOrPut( + shard, EdgeFilterSubState(currentHealth: TopicHealth.UNHEALTHY) + ) + + self.edgeFilterSubStates.withValue(shard, state): + state.peers.keepItIf( + self.node.peerManager.switch.peerStore.isConnected(it.peerId) + ) + state.pending.keepItIf(not it.finished) + + if addedTopics.len > 0 or removedTopics.len > 0: + for peer in state.peers: + asyncSpawn self.syncFilterDeltas(peer, shard, addedTopics, removedTopics) + + if shard notin newSynced: + shardsToDelete.add(shard) + else: + self.updateShardHealth(shard, state[]) + + let needed = max(0, HealthyThreshold - state.peers.len - state.pending.len) + + if needed > 0: + var tracked: HashSet[PeerId] + for p in state.peers: + tracked.incl(p.peerId) + for p in state.pendingPeers: + tracked.incl(p) + let candidates = self.selectFilterCandidates(shard, tracked, needed) + let toSubscribe = min(needed, candidates.len) + + trace "edgeFilterSubLoop: shard reconciliation", + shard = shard, + num_peers = state.peers.len, + num_pending = state.pending.len, + num_needed = needed, + num_available = candidates.len, + toSubscribe = toSubscribe + + var subscribeTopics: seq[ContentTopic] + newSynced.withValue(shard, curr): + subscribeTopics = toSeq(curr[]) + + for i in 0 ..< toSubscribe: + subscribeTasks.add( + EdgeFilterSubscribeTask( + peer: candidates[i], shard: shard, topics: subscribeTopics + ) + ) + + # Step 2: execute deferred shard tracking deletion and filter-subscribe tasks. + + for shard in shardsToDelete: + self.edgeFilterSubStates.withValue(shard, state): + for fut in state.pending: + if not fut.finished: + await fut.cancelAndWait() + self.edgeFilterSubStates.del(shard) + + for task in subscribeTasks: + let fut = self.subscribeFilterPeer(task.peer, task.shard, task.topics) + self.edgeFilterSubStates.withValue(task.shard, state): + state.pending.add(fut) + + lastSynced = newSynced + +proc startEdgeFilterLoops(self: SubscriptionManager): Result[void, string] = + ## Start the edge filter orchestration loops. + ## Caller must ensure this is only called in edge mode (relay nil, filter client present). + self.peerEventListener = WakuPeerEvent.listen( + self.node.brokerCtx, + proc(evt: WakuPeerEvent) {.async: (raises: []), gcsafe.} = + if evt.kind == WakuPeerEventKind.EventDisconnected: + # We know a peer is gone, so if it was a service filter peer for this + # edge node, remove it from the list of service filter peers for each + # shard it served and re-evaluate shard health for the affected shards. + for shard, state in self.edgeFilterSubStates.mpairs: + let oldLen = state.peers.len + state.peers.keepItIf(it.peerId != evt.peerId) + if state.peers.len < oldLen: + self.updateShardHealth(shard, state) + self.edgeFilterWakeup.fire() + elif evt.kind == WakuPeerEventKind.EventMetadataUpdated: + self.edgeFilterWakeup.fire(), + ).valueOr: + return err("Failed to listen to peer events for edge filter: " & error) + + self.edgeFilterSubLoopFut = self.edgeFilterSubLoop() + self.edgeFilterConnectionLoopFut = self.edgeFilterConnectionLoop() + return ok() + +proc stopEdgeFilterLoops(self: SubscriptionManager) {.async: (raises: []).} = + ## Stop the edge filter orchestration loops and clean up pending futures. + if not isNil(self.edgeFilterSubLoopFut): + await self.edgeFilterSubLoopFut.cancelAndWait() + self.edgeFilterSubLoopFut = nil + + if not isNil(self.edgeFilterConnectionLoopFut): + await self.edgeFilterConnectionLoopFut.cancelAndWait() + self.edgeFilterConnectionLoopFut = nil + + for shard, state in self.edgeFilterSubStates: + for fut in state.pending: + if not fut.finished: + await fut.cancelAndWait() + + await WakuPeerEvent.dropListener(self.node.brokerCtx, self.peerEventListener) + +proc start*(self: SubscriptionManager): Result[void, string] = + let edgeShardHealthRes = RequestEdgeShardHealth.setProvider( + self.node.brokerCtx, + proc(shard: PubsubTopic): Result[RequestEdgeShardHealth, string] = + self.edgeFilterSubStates.withValue(shard, state): + return ok(RequestEdgeShardHealth(health: state.currentHealth)) + return ok(RequestEdgeShardHealth(health: TopicHealth.NOT_SUBSCRIBED)), + ) + self.ownsEdgeShardHealthProvider = edgeShardHealthRes.isOk() + if edgeShardHealthRes.isErr(): + error "Can't set provider for RequestEdgeShardHealth", + error = edgeShardHealthRes.error + + let edgeFilterPeerCountRes = RequestEdgeFilterPeerCount.setProvider( + self.node.brokerCtx, + proc(): Result[RequestEdgeFilterPeerCount, string] = + var minPeers = high(int) + for state in self.edgeFilterSubStates.values: + minPeers = min(minPeers, state.peers.len) + if minPeers == high(int): + minPeers = 0 + return ok(RequestEdgeFilterPeerCount(peerCount: minPeers)), + ) + self.ownsEdgeFilterPeerCountProvider = edgeFilterPeerCountRes.isOk() + if edgeFilterPeerCountRes.isErr(): + error "Can't set provider for RequestEdgeFilterPeerCount", + error = edgeFilterPeerCountRes.error + + # Start Edge workers only when we are in Edge mode (relay not mounted) + # AND the filter client is mounted (otherwise the loops have nothing + # to talk to and just spam "filter client is nil" warnings). + if self.node.wakuRelay.isNil() and not self.node.wakuFilterClient.isNil(): + return self.startEdgeFilterLoops() + + return ok() + +proc stop*(self: SubscriptionManager) {.async: (raises: []).} = + # Stop Edge workers if we started them in `start` (Edge mode + filter client). + if self.node.wakuRelay.isNil() and not self.node.wakuFilterClient.isNil(): + await self.stopEdgeFilterLoops() + + # Only clear providers we actually registered: another SubscriptionManager + # sharing this brokerCtx may have won the race, and clearing its provider + # would leave the broker silently provider-less. + if self.ownsEdgeShardHealthProvider: + RequestEdgeShardHealth.clearProvider(self.node.brokerCtx) + self.ownsEdgeShardHealthProvider = false + if self.ownsEdgeFilterPeerCountProvider: + RequestEdgeFilterPeerCount.clearProvider(self.node.brokerCtx) + self.ownsEdgeFilterPeerCountProvider = false diff --git a/waku/node/waku_metrics.nim b/waku/node/waku_metrics.nim index af74b1532..bb4c10fff 100644 --- a/waku/node/waku_metrics.nim +++ b/waku/node/waku_metrics.nim @@ -4,6 +4,7 @@ import chronicles, chronos, metrics, metrics/chronos_httpserver import waku/[net/auto_port, waku_rln_relay/protocol_metrics as rln_metrics, utils/collector], ./peer_manager, + ./node_telemetry, ./waku_node const LogInterval = 10.minutes diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 26a2b5a57..9ac3c5d00 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -60,23 +60,14 @@ import requests/health_requests, events/health_events, events/message_events, + events/peer_events, ], waku/discovery/waku_kademlia, waku/net/[bound_ports, net_config], ./peer_manager, ./health_monitor/health_status, - ./health_monitor/topic_health - -declarePublicCounter waku_node_messages, "number of messages received", ["type"] - -declarePublicGauge waku_version, - "Waku version info (in git describe format)", ["version"] -declarePublicCounter waku_node_errors, "number of wakunode errors", ["type"] -declarePublicGauge waku_lightpush_peers, "number of lightpush peers" -declarePublicGauge waku_filter_peers, "number of filter peers" -declarePublicGauge waku_store_peers, "number of store peers" -declarePublicGauge waku_px_peers, - "number of peers (in the node's peerManager) supporting the peer exchange protocol" + ./health_monitor/topic_health, + ./node_telemetry logScope: topics = "waku node" @@ -94,53 +85,10 @@ const clientId* = "Nimbus Waku v2 node" const WakuNodeVersionString* = "version / git commit hash: " & git_version -# key and crypto modules different -type - # TODO: Move to application instance (e.g., `WakuNode2`) - WakuInfo* = object # NOTE One for simplicity, can extend later as needed - listenAddresses*: seq[string] - enrUri*: string #multiaddrStrings*: seq[string] - mixPubKey*: Option[string] +import ./node_types +export node_types - # NOTE based on Eth2Node in NBC eth2_network.nim - WakuNode* = ref object - peerManager*: PeerManager - switch*: Switch - wakuRelay*: WakuRelay - wakuArchive*: waku_archive.WakuArchive - wakuStore*: store.WakuStore - wakuStoreClient*: store_client.WakuStoreClient - wakuStoreResume*: StoreResume - wakuStoreReconciliation*: SyncReconciliation - wakuStoreTransfer*: SyncTransfer - wakuFilter*: waku_filter_v2.WakuFilter - wakuFilterClient*: filter_client.WakuFilterClient - wakuRlnRelay*: WakuRLNRelay - wakuLegacyLightPush*: WakuLegacyLightPush - wakuLegacyLightpushClient*: WakuLegacyLightPushClient - wakuLightPush*: WakuLightPush - wakuLightpushClient*: WakuLightPushClient - wakuPeerExchange*: WakuPeerExchange - wakuPeerExchangeClient*: WakuPeerExchangeClient - wakuMetadata*: WakuMetadata - wakuAutoSharding*: Option[Sharding] - enr*: enr.Record - libp2pPing*: Ping - rng*: ref rand.HmacDrbgContext - brokerCtx*: BrokerContext - wakuRendezvous*: WakuRendezVous - wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient - announcedAddresses*: seq[MultiAddress] - extMultiAddrsOnly*: bool # When true, skip automatic IP address replacement - started*: bool # Indicates that node has started listening - topicSubscriptionQueue*: AsyncEventQueue[SubscriptionEvent] - rateLimitSettings*: ProtocolRateLimitSettings - legacyAppHandlers*: Table[PubsubTopic, WakuRelayHandler] - ## Kernel API Relay appHandlers (if any) - wakuMix*: WakuMix - kademliaDiscoveryLoop*: Future[void] - wakuKademlia*: WakuKademlia - ports*: BoundPorts +import ./subscription_manager proc deduceRelayShard( node: WakuNode, @@ -230,6 +178,8 @@ proc new*( peerManager.setShardGetter(node.getShardsGetter(@[])) + node.subscriptionManager = SubscriptionManager.new(node) + return node proc peerInfo*(node: WakuNode): PeerInfo = @@ -600,6 +550,9 @@ proc start*(node: WakuNode) {.async.} = node.startProvidersAndListeners() + node.subscriptionManager.start().isOkOr: + error "failed to start subscription manager", error = error + if not zeroPortPresent: updateAnnouncedAddrWithPrimaryIpAddr(node).isOkOr: error "failed update announced addr", error = $error @@ -611,6 +564,8 @@ proc start*(node: WakuNode) {.async.} = proc stop*(node: WakuNode) {.async.} = ## By stopping the switch we are stopping all the underlying mounted protocols + await node.subscriptionManager.stop() + node.stopProvidersAndListeners() ## NOTE: This will dispatch gossipsub stop to the WakuRelay.stop method override diff --git a/waku/requests/health_requests.nim b/waku/requests/health_requests.nim index d48b3278f..ccf08f83d 100644 --- a/waku/requests/health_requests.nim +++ b/waku/requests/health_requests.nim @@ -38,14 +38,14 @@ RequestBroker: proc signature(protocol: WakuProtocol): Future[Result[RequestProtocolHealth, string]] -# Get edge filter health for a single shard (set by DeliveryService when edge mode is active) +# Get edge filter health for a single shard (set when edge mode is active) RequestBroker(sync): type RequestEdgeShardHealth* = object health*: TopicHealth proc signature(shard: PubsubTopic): Result[RequestEdgeShardHealth, string] -# Get edge filter confirmed peer count (set by DeliveryService when edge mode is active) +# Get edge filter confirmed peer count (set when edge mode is active) RequestBroker(sync): type RequestEdgeFilterPeerCount* = object peerCount*: int From 6fd0f9c079b9e8b9b2e28f4d7b1c508686a50dee Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Thu, 4 Jun 2026 21:17:43 +0200 Subject: [PATCH 07/13] ci: fix Windows build hang on re-downloading nimble deps (#3920) --- .github/workflows/ci.yml | 21 +++++++--- .github/workflows/container-image.yml | 4 ++ .github/workflows/windows-build.yml | 33 +++++++++++---- Makefile | 60 +++++++++++++++++---------- waku.nimble | 1 + 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ddf904ef..67a29fa31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,12 +89,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup @@ -142,12 +145,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup @@ -207,12 +213,15 @@ jobs: path: | nimbledeps/ nimble.paths - key: ${{ runner.os }}-nimbledeps-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} + key: ${{ runner.os }}-nimbledeps-v2-nimble${{ env.NIMBLE_VERSION }}-${{ hashFiles('nimble.lock', 'BearSSL.mk', 'Nat.mk') }} - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | - nimble setup --localdeps -y + # nim's source tree checksums differently across platforms, so its + # locked checksum is unreliable. --useSystemNim uses the CI nim and + # skips that check, while still verifying every other locked dep. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps make rebuild-bearssl-nimbledeps touch nimbledeps/.nimble-setup diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml index 0ff427d87..b2066438b 100644 --- a/.github/workflows/container-image.yml +++ b/.github/workflows/container-image.yml @@ -15,6 +15,10 @@ env: NPROC: 2 MAKEFLAGS: "-j${NPROC}" NIMFLAGS: "--parallelBuild:${NPROC}" + # waku.nimble reads compile flags from NIM_PARAMS, not NIMFLAGS. Without + # -d:disableMarchNative here, config.nims applies -march=native and + # secp256k1 fails to compile. + NIM_PARAMS: "-d:disableMarchNative" NIM_VERSION: '2.2.4' NIMBLE_VERSION: '0.22.3' diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 50f1602cd..4d955de23 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -24,6 +24,16 @@ jobs: MSYSTEM: MINGW64 steps: + - name: Configure Git to keep LF line endings + # Windows Git defaults to core.autocrlf=true. The LF→CRLF conversion + # changes the SHA1 of nimble's cloned deps, so they no longer match + # nimble.lock and nimble re-downloads them on every run (hanging the + # job). Disable autocrlf so clones match the Linux-computed checksums. + shell: pwsh + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Checkout code uses: actions/checkout@v4 @@ -52,6 +62,14 @@ jobs: mingw-w64-x86_64-clang mingw-w64-x86_64-nasm + - name: Configure Git in MSYS2 to keep LF line endings + # The step above only configures Git for Windows. nimble clones its deps + # from the MSYS2 shell, whose git reads a separate global config, so the + # same setting must be repeated here. + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Manually install nasm run: | bash scripts/install_nasm_in_windows.sh @@ -80,19 +98,16 @@ jobs: cd /tmp && nimble install "nimble@${{ env.NIMBLE_VERSION }}" -y echo "$HOME/.nimble/bin" >> $GITHUB_PATH - - name: Patch nimble.lock for Windows nim checksum - # nimble.exe uses Windows Git (core.autocrlf=true by default), which converts LF→CRLF - # on checkout. This changes the SHA1 of the nim package source tree relative to the - # Linux-computed checksum stored in nimble.lock. Patch the lock file with the - # Windows-computed checksum before nimble reads it. - run: | - sed -i 's/68bb85cbfb1832ce4db43943911b046c3af3caab/a092a045d3a427d127a5334a6e59c76faff54686/g' nimble.lock - - name: Install nimble deps if: steps.cache-nimbledeps.outputs.cache-hit != 'true' run: | export PATH="$GITHUB_WORKSPACE/.nim_runtime/bin:$HOME/.nimble/bin:$PATH" - nimble setup --localdeps -y + # nim's source tree checks out differently per platform (its own + # .gitattributes forces line endings), so its locked checksum never + # matches on Windows — even with autocrlf disabled. --useSystemNim + # uses the CI-installed nim and skips that check, while still + # verifying every other locked dependency. + nimble setup --localdeps -y --useSystemNim make rebuild-nat-libs-nimbledeps CC=gcc make rebuild-bearssl-nimbledeps CC=gcc touch nimbledeps/.nimble-setup diff --git a/Makefile b/Makefile index ea1bf66f0..344743c86 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,9 @@ export PATH := $(HOME)/.nimble/bin:$(PATH) # NIM binary location NIM_BINARY := $(shell which nim 2>/dev/null) NPH := $(HOME)/.nimble/bin/nph -NIMBLE := $(HOME)/.nimble/bin/nimble +# Resolve nimble via PATH (Windows has no $(HOME)/.nimble/bin); --useSystemNim +# reuses the nim on PATH so nimble never re-clones the locked nim. +NIMBLE := nimble --useSystemNim NIMBLEDEPS_STAMP := nimbledeps/.nimble-setup # Compilation parameters @@ -204,7 +206,7 @@ clean: | clean-librln testcommon: | build-deps build echo -e $(BUILD_MSG) "build/$@" && \ - nimble testcommon + $(NIMBLE) testcommon ########## ## Waku ## @@ -213,47 +215,54 @@ testcommon: | build-deps build testwaku: | build-deps build rln-deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble test + $(NIMBLE) test +# Windows: build with nim directly — `nimble ` re-clones git deps every +# build and they intermittently hang on the MSYS2 runner. Flags mirror waku.nimble. wakunode2: | build-deps build deps librln +ifeq ($(detected_OS),Windows) echo -e $(BUILD_MSG) "build/$@" && \ - nimble wakunode2 + nim c --out:build/wakunode2 --mm:refc --cpu:amd64 $(NIM_PARAMS) -d:chronicles_log_level=TRACE apps/wakunode2/wakunode2.nim +else + echo -e $(BUILD_MSG) "build/$@" && \ + $(NIMBLE) wakunode2 +endif benchmarks: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble benchmarks + $(NIMBLE) benchmarks testwakunode2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble testwakunode2 + $(NIMBLE) testwakunode2 example2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble example2 + $(NIMBLE) example2 chat2: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2 + $(NIMBLE) chat2 chat2mix: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2mix + $(NIMBLE) chat2mix rln-db-inspector: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble rln_db_inspector + $(NIMBLE) rln_db_inspector chat2bridge: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble chat2bridge + $(NIMBLE) chat2bridge liteprotocoltester: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble liteprotocoltester + $(NIMBLE) liteprotocoltester lightpushwithmix: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble lightpushwithmix + $(NIMBLE) lightpushwithmix api_example: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ @@ -261,12 +270,12 @@ api_example: | build-deps build deps librln build/%: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$*" && \ - nimble buildone $* + $(NIMBLE) buildone $* compile-test: | build-deps build deps librln echo -e $(BUILD_MSG) "$(TEST_FILE)" "\"$(TEST_NAME)\"" && \ - nimble buildTest $(TEST_FILE) && \ - nimble execTest $(TEST_FILE) "\"$(TEST_NAME)\"" + $(NIMBLE) buildTest $(TEST_FILE) && \ + $(NIMBLE) execTest $(TEST_FILE) "\"$(TEST_NAME)\"" ################ ## Waku tools ## @@ -277,11 +286,11 @@ tools: networkmonitor wakucanary wakucanary: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble wakucanary + $(NIMBLE) wakucanary networkmonitor: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - nimble networkmonitor + $(NIMBLE) networkmonitor ############ ## Format ## @@ -327,7 +336,7 @@ clean: docs: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - nimble doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims + $(NIMBLE) doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims coverage: echo -e $(BUILD_MSG) "build/$@" && \ @@ -423,11 +432,16 @@ else ifeq ($(detected_OS),Linux) BUILD_COMMAND := $(BUILD_COMMAND)Linux endif +# Windows: build with nim directly (see wakunode2). Flags mirror waku.nimble. libwaku: | build-deps librln - nimble --verbose libwaku$(BUILD_COMMAND) waku.nimble +ifeq ($(detected_OS),Windows) + nim c --out:build/libwaku.dll --threads:on --app:lib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:off -d:discv5_protocol_id=d5waku --cpu:amd64 $(NIM_PARAMS) library/libwaku.nim +else + $(NIMBLE) --verbose libwaku$(BUILD_COMMAND) waku.nimble +endif liblogosdelivery: | build-deps librln - nimble --verbose liblogosdelivery$(BUILD_COMMAND) waku.nimble + $(NIMBLE) --verbose liblogosdelivery$(BUILD_COMMAND) waku.nimble logosdelivery_example: | build liblogosdelivery @echo -e $(BUILD_MSG) "build/$@" @@ -502,7 +516,7 @@ endif build-libwaku-for-android-arch: ifneq ($(findstring /nix/store,$(LIBRLN_FILE)),) mkdir -p $(CURDIR)/build/android/$(ABIDIR)/ - CPU=$(CPU) ABIDIR=$(ABIDIR) ANDROID_ARCH=$(ANDROID_ARCH) ANDROID_COMPILER=$(ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) nimble libWakuAndroid + CPU=$(CPU) ABIDIR=$(ABIDIR) ANDROID_ARCH=$(ANDROID_ARCH) ANDROID_COMPILER=$(ANDROID_COMPILER) ANDROID_TOOLCHAIN_DIR=$(ANDROID_TOOLCHAIN_DIR) $(NIMBLE) libWakuAndroid else ./scripts/build_rln_android.sh $(CURDIR)/build $(LIBRLN_BUILDDIR) $(LIBRLN_VERSION) $(CROSS_TARGET) $(ABIDIR) endif @@ -559,7 +573,7 @@ else endif build-libwaku-for-ios-arch: - IOS_SDK=$(IOS_SDK) IOS_ARCH=$(IOS_ARCH) IOS_SDK_PATH=$(IOS_SDK_PATH) nimble libWakuIOS + IOS_SDK=$(IOS_SDK) IOS_ARCH=$(IOS_ARCH) IOS_SDK_PATH=$(IOS_SDK_PATH) $(NIMBLE) libWakuIOS libwaku-ios-device: IOS_ARCH=arm64 libwaku-ios-device: IOS_SDK=iphoneos diff --git a/waku.nimble b/waku.nimble index 4ed98917e..38548b5dc 100644 --- a/waku.nimble +++ b/waku.nimble @@ -59,6 +59,7 @@ requires "nim >= 2.2.4", "unittest2" # Packages not on nimble (use git URLs) + requires "https://github.com/logos-messaging/nim-ffi#v0.1.3" requires "https://github.com/logos-messaging/nim-sds.git#abdd40cc645f1b024c3ee99cced7e287c4e4c441" From 38d951a2fdcc2498f7193c5c3f9401f95f458eae Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Thu, 4 Jun 2026 23:06:54 +0200 Subject: [PATCH 08/13] Rename kernel_api dir to waku_node and tidy node module layout (#3927) --- apps/wakucanary/wakucanary.nim | 1 + library/kernel_api/discovery_api.nim | 3 +- library/kernel_api/protocols/filter_api.nim | 3 +- library/kernel_api/protocols/relay_api.nim | 2 +- tests/api/test_api_subscription.nim | 2 +- tests/factory/test_node_factory.nim | 9 +- tests/node/test_wakunode_filter.nim | 3 +- tests/node/test_wakunode_health_monitor.nim | 8 +- tests/node/test_wakunode_legacy_lightpush.nim | 4 +- tests/node/test_wakunode_lightpush.nim | 10 +- tests/node/test_wakunode_peer_exchange.nim | 10 +- tests/node/test_wakunode_peer_manager.nim | 3 +- tests/node/test_wakunode_relay_rln.nim | 2 - tests/node/test_wakunode_sharding.nim | 3 +- tests/node/test_wakunode_store.nim | 3 +- tests/test_waku_keepalive.nim | 7 +- tests/testlib/wakunode.nim | 1 + tests/waku_discv5/test_waku_discv5.nim | 3 +- tests/waku_filter_v2/test_waku_client.nim | 3 +- waku/factory/builder.nim | 1 + waku/factory/node_factory.nim | 1 + waku/factory/waku.nim | 1 + waku/node/edge_filter_sub_state.nim | 13 ++ .../health_monitor/node_health_monitor.nim | 2 +- waku/node/kernel_api.nim | 9 -- waku/node/node_types.nim | 116 ------------------ waku/node/shard_subscription.nim | 11 ++ waku/node/subscription_manager.nim | 2 +- waku/node/waku_node.nim | 66 +++++++++- .../node/{kernel_api => waku_node}/filter.nim | 0 .../{kernel_api => waku_node}/lightpush.nim | 0 .../peer_exchange.nim | 0 waku/node/{kernel_api => waku_node}/ping.nim | 0 waku/node/{kernel_api => waku_node}/relay.nim | 0 waku/node/{kernel_api => waku_node}/store.nim | 0 waku/rest_api/endpoint/builder.nim | 1 + waku/rest_api/endpoint/health/handlers.nim | 3 +- waku/rest_api/endpoint/health/types.nim | 2 +- waku/waku_node.nim | 13 +- 39 files changed, 140 insertions(+), 181 deletions(-) create mode 100644 waku/node/edge_filter_sub_state.nim delete mode 100644 waku/node/kernel_api.nim delete mode 100644 waku/node/node_types.nim create mode 100644 waku/node/shard_subscription.nim rename waku/node/{kernel_api => waku_node}/filter.nim (100%) rename waku/node/{kernel_api => waku_node}/lightpush.nim (100%) rename waku/node/{kernel_api => waku_node}/peer_exchange.nim (100%) rename waku/node/{kernel_api => waku_node}/ping.nim (100%) rename waku/node/{kernel_api => waku_node}/relay.nim (100%) rename waku/node/{kernel_api => waku_node}/store.nim (100%) diff --git a/apps/wakucanary/wakucanary.nim b/apps/wakucanary/wakucanary.nim index e7b1ff9aa..f9023c45c 100644 --- a/apps/wakucanary/wakucanary.nim +++ b/apps/wakucanary/wakucanary.nim @@ -13,6 +13,7 @@ import import ./certsgenerator, waku/[waku_enr, node/peer_manager, waku_core, waku_node, factory/builder], + waku/net/net_config, waku/waku_metadata/protocol, waku/common/callbacks diff --git a/library/kernel_api/discovery_api.nim b/library/kernel_api/discovery_api.nim index f61b7bad1..882c91686 100644 --- a/library/kernel_api/discovery_api.nim +++ b/library/kernel_api/discovery_api.nim @@ -5,8 +5,7 @@ import waku/discovery/waku_dnsdisc, waku/discovery/waku_discv5, waku/waku_core/peers, - waku/node/waku_node, - waku/node/kernel_api, + waku/waku_node, library/declare_lib proc retrieveBootstrapNodes( diff --git a/library/kernel_api/protocols/filter_api.nim b/library/kernel_api/protocols/filter_api.nim index c4f99510a..866b70ca2 100644 --- a/library/kernel_api/protocols/filter_api.nim +++ b/library/kernel_api/protocols/filter_api.nim @@ -8,8 +8,7 @@ import waku/waku_filter_v2/common, waku/waku_core/subscription/push_handler, waku/node/peer_manager/peer_manager, - waku/node/waku_node, - waku/node/kernel_api, + waku/waku_node, waku/waku_core/topics/pubsub_topic, waku/waku_core/topics/content_topic, library/events/json_message_event, diff --git a/library/kernel_api/protocols/relay_api.nim b/library/kernel_api/protocols/relay_api.nim index b184d6011..4364a4170 100644 --- a/library/kernel_api/protocols/relay_api.nim +++ b/library/kernel_api/protocols/relay_api.nim @@ -7,7 +7,7 @@ import waku/waku_core/message, waku/waku_core/topics/pubsub_topic, waku/waku_core/topics, - waku/node/kernel_api/relay, + waku/node/waku_node/relay, waku/waku_relay/protocol, waku/node/peer_manager, library/events/json_message_event, diff --git a/tests/api/test_api_subscription.nim b/tests/api/test_api_subscription.nim index 8f587b535..7cb0e981a 100644 --- a/tests/api/test_api_subscription.nim +++ b/tests/api/test_api_subscription.nim @@ -14,7 +14,7 @@ import waku_core, events/message_events, waku_relay/protocol, - node/kernel_api/filter, + node/waku_node/filter, node/subscription_manager, ] import waku/factory/waku_conf diff --git a/tests/factory/test_node_factory.nim b/tests/factory/test_node_factory.nim index 1fe242532..63dd730c2 100644 --- a/tests/factory/test_node_factory.nim +++ b/tests/factory/test_node_factory.nim @@ -11,7 +11,14 @@ import import tests/testlib/[wakunode, wakucore], - waku/[waku_node, waku_enr, net/auto_port, discovery/waku_discv5, node/waku_metrics], + waku/[ + waku_node, + net/net_config, + waku_enr, + net/auto_port, + discovery/waku_discv5, + node/waku_metrics, + ], waku/factory/[ node_factory, internal_config, diff --git a/tests/node/test_wakunode_filter.nim b/tests/node/test_wakunode_filter.nim index 2777b0124..b0dbaa198 100644 --- a/tests/node/test_wakunode_filter.nim +++ b/tests/node/test_wakunode_filter.nim @@ -11,8 +11,7 @@ import waku/[ waku_core, node/peer_manager, - node/waku_node, - node/kernel_api, + waku_node, waku_filter_v2, waku_filter_v2/client, waku_filter_v2/subscriptions, diff --git a/tests/node/test_wakunode_health_monitor.nim b/tests/node/test_wakunode_health_monitor.nim index a85056d51..be779c586 100644 --- a/tests/node/test_wakunode_health_monitor.nim +++ b/tests/node/test_wakunode_health_monitor.nim @@ -16,10 +16,10 @@ import node/health_monitor/topic_health, node/health_monitor/node_health_monitor, messaging_client, - node/kernel_api/relay, - node/kernel_api/store, - node/kernel_api/lightpush, - node/kernel_api/filter, + node/waku_node/relay, + node/waku_node/store, + node/waku_node/lightpush, + node/waku_node/filter, events/health_events, events/peer_events, waku_archive, diff --git a/tests/node/test_wakunode_legacy_lightpush.nim b/tests/node/test_wakunode_legacy_lightpush.nim index 68c6cacde..cdd29b398 100644 --- a/tests/node/test_wakunode_legacy_lightpush.nim +++ b/tests/node/test_wakunode_legacy_lightpush.nim @@ -11,9 +11,7 @@ import waku/[ waku_core, node/peer_manager, - node/waku_node, - node/kernel_api, - node/kernel_api/lightpush, + waku_node, waku_lightpush_legacy, waku_lightpush_legacy/common, waku_lightpush_legacy/protocol_metrics, diff --git a/tests/node/test_wakunode_lightpush.nim b/tests/node/test_wakunode_lightpush.nim index b407327e3..4f5476701 100644 --- a/tests/node/test_wakunode_lightpush.nim +++ b/tests/node/test_wakunode_lightpush.nim @@ -8,15 +8,7 @@ import libp2p/crypto/crypto import - waku/[ - waku_core, - node/peer_manager, - node/waku_node, - node/kernel_api, - node/kernel_api/lightpush, - waku_lightpush, - waku_rln_relay, - ], + waku/[waku_core, node/peer_manager, waku_node, waku_lightpush, waku_rln_relay], ../testlib/[wakucore, wakunode, testasync, futures], ../resources/payloads, ../waku_rln_relay/[rln/waku_rln_relay_utils, utils_onchain] diff --git a/tests/node/test_wakunode_peer_exchange.nim b/tests/node/test_wakunode_peer_exchange.nim index 82ca25868..ac263c92f 100644 --- a/tests/node/test_wakunode_peer_exchange.nim +++ b/tests/node/test_wakunode_peer_exchange.nim @@ -13,14 +13,8 @@ import brokers/broker_context import - waku/[ - waku_node, - node/kernel_api, - discovery/waku_discv5, - waku_peer_exchange, - node/peer_manager, - waku_core, - ], + waku/ + [waku_node, discovery/waku_discv5, waku_peer_exchange, node/peer_manager, waku_core], ../waku_peer_exchange/utils, ../testlib/[wakucore, wakunode, testasync] diff --git a/tests/node/test_wakunode_peer_manager.nim b/tests/node/test_wakunode_peer_manager.nim index ed58db7fe..b0c4354cf 100644 --- a/tests/node/test_wakunode_peer_manager.nim +++ b/tests/node/test_wakunode_peer_manager.nim @@ -16,8 +16,7 @@ import waku/[ waku_core, node/peer_manager, - node/waku_node, - node/kernel_api, + waku_node, discovery/waku_discv5, waku_filter_v2/common, waku_relay/protocol, diff --git a/tests/node/test_wakunode_relay_rln.nim b/tests/node/test_wakunode_relay_rln.nim index 3a2a8a67c..b78255ce9 100644 --- a/tests/node/test_wakunode_relay_rln.nim +++ b/tests/node/test_wakunode_relay_rln.nim @@ -13,11 +13,9 @@ from std/times import epochTime import ../../../waku/[ - node/waku_node, node/peer_manager, waku_core, waku_node, - node/kernel_api, common/error_handling, waku_rln_relay, waku_rln_relay/rln, diff --git a/tests/node/test_wakunode_sharding.nim b/tests/node/test_wakunode_sharding.nim index f482b6abc..88bf63efa 100644 --- a/tests/node/test_wakunode_sharding.nim +++ b/tests/node/test_wakunode_sharding.nim @@ -14,8 +14,7 @@ import waku/[ waku_core/topics/pubsub_topic, waku_core/topics/sharding, - node/waku_node, - node/kernel_api, + waku_node, common/paging, waku_core, waku_store/common, diff --git a/tests/node/test_wakunode_store.nim b/tests/node/test_wakunode_store.nim index 01deb2903..daa1db682 100644 --- a/tests/node/test_wakunode_store.nim +++ b/tests/node/test_wakunode_store.nim @@ -5,8 +5,7 @@ import std/[options, sequtils, sets], testutils/unittests, chronos, libp2p/crypt import waku/[ common/paging, - node/waku_node, - node/kernel_api, + waku_node, node/peer_manager, waku_core, waku_core/message/digest, diff --git a/tests/test_waku_keepalive.nim b/tests/test_waku_keepalive.nim index 5d8402268..32cfb245d 100644 --- a/tests/test_waku_keepalive.nim +++ b/tests/test_waku_keepalive.nim @@ -9,7 +9,12 @@ import libp2p/stream/bufferstream, libp2p/stream/connection, libp2p/crypto/crypto -import waku/waku_core, waku/waku_node, ./testlib/wakucore, ./testlib/wakunode +import + waku/waku_core, + waku/waku_node, + waku/node/health_monitor, + ./testlib/wakucore, + ./testlib/wakunode suite "Waku Keepalive": asyncTest "handle ping keepalives": diff --git a/tests/testlib/wakunode.nim b/tests/testlib/wakunode.nim index 77c017d96..c23854f08 100644 --- a/tests/testlib/wakunode.nim +++ b/tests/testlib/wakunode.nim @@ -10,6 +10,7 @@ import import waku/[ waku_node, + net/net_config, waku_core/topics, node/peer_manager, waku_enr, diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 36d34058c..58d7d5bb8 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -21,8 +21,7 @@ import waku_enr/capabilities, factory/conf_builder/conf_builder, factory/waku, - node/waku_node, - node/kernel_api, + waku_node, node/peer_manager, ], ../testlib/[wakucore, testasync, assertions, futures, wakunode, testutils], diff --git a/tests/waku_filter_v2/test_waku_client.nim b/tests/waku_filter_v2/test_waku_client.nim index c57699d39..b34c22018 100644 --- a/tests/waku_filter_v2/test_waku_client.nim +++ b/tests/waku_filter_v2/test_waku_client.nim @@ -3,7 +3,8 @@ import std/[options, sequtils, json], testutils/unittests, results, chronos import - waku/node/[peer_manager, waku_node, kernel_api], + waku/node/peer_manager, + waku/waku_node, waku/waku_core, waku/waku_filter_v2/[common, client, subscriptions, protocol, rpc_codec], ../testlib/[wakucore, testasync, testutils, futures, sequtils, wakunode], diff --git a/waku/factory/builder.nim b/waku/factory/builder.nim index 4212cb92d..953d95a34 100644 --- a/waku/factory/builder.nim +++ b/waku/factory/builder.nim @@ -15,6 +15,7 @@ import ../waku_enr, ../discovery/waku_discv5, ../waku_node, + ../net/net_config, ../node/peer_manager, ../common/rate_limit/setting, ../common/utils/parse_size_units diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 52b719b8f..2a2b6e5d9 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -17,6 +17,7 @@ import ./validator_signed, ../waku_enr/sharding, ../waku_node, + ../net/net_config, ../waku_core, ../waku_core/codecs, ../waku_rln_relay, diff --git a/waku/factory/waku.nim b/waku/factory/waku.nim index ee70cf713..edd02ade8 100644 --- a/waku/factory/waku.nim +++ b/waku/factory/waku.nim @@ -34,6 +34,7 @@ import common/logging, node/peer_manager, node/health_monitor, + net/net_config, node/waku_metrics, node/subscription_manager, rest_api/message_cache, diff --git a/waku/node/edge_filter_sub_state.nim b/waku/node/edge_filter_sub_state.nim new file mode 100644 index 000000000..9863f876a --- /dev/null +++ b/waku/node/edge_filter_sub_state.nim @@ -0,0 +1,13 @@ +{.push raises: [].} + +import std/sets +import chronos, libp2p/peerid +import ../waku_core, ./health_monitor/topic_health + +type EdgeFilterSubState* = object + peers*: seq[RemotePeerInfo] + pending*: seq[Future[void]] + pendingPeers*: HashSet[PeerId] + currentHealth*: TopicHealth + +{.pop.} diff --git a/waku/node/health_monitor/node_health_monitor.nim b/waku/node/health_monitor/node_health_monitor.nim index 98c0f6c7a..e5c941191 100644 --- a/waku/node/health_monitor/node_health_monitor.nim +++ b/waku/node/health_monitor/node_health_monitor.nim @@ -16,7 +16,7 @@ import node/waku_node, node/node_telemetry, node/peer_manager, - node/kernel_api, + node/waku_node/ping, node/health_monitor/online_monitor, node/health_monitor/health_status, node/health_monitor/health_report, diff --git a/waku/node/kernel_api.nim b/waku/node/kernel_api.nim deleted file mode 100644 index 9d19acb07..000000000 --- a/waku/node/kernel_api.nim +++ /dev/null @@ -1,9 +0,0 @@ -import - ./kernel_api/filter as filter_api, - ./kernel_api/lightpush as lightpush_api, - ./kernel_api/store as store_api, - ./kernel_api/relay as relay_api, - ./kernel_api/peer_exchange as peer_exchange_api, - ./kernel_api/ping as ping_api - -export filter_api, lightpush_api, store_api, relay_api, peer_exchange_api, ping_api diff --git a/waku/node/node_types.nim b/waku/node/node_types.nim deleted file mode 100644 index f5c2a56b6..000000000 --- a/waku/node/node_types.nim +++ /dev/null @@ -1,116 +0,0 @@ -{.push raises: [].} - -import - std/[options, tables, sets], - chronos, - results, - eth/keys, - bearssl/rand, - eth/p2p/discoveryv5/enr, - libp2p/crypto/crypto, - libp2p/[multiaddress, multicodec], - libp2p/protocols/ping, - libp2p/protocols/mix/mix_protocol, - brokers/broker_context - -import - waku/[ - waku_core, - waku_relay, - waku_archive, - waku_store/protocol as store, - waku_store/client as store_client, - waku_store/resume, - waku_store_sync, - waku_filter_v2, - waku_filter_v2/client as filter_client, - waku_metadata, - waku_rendezvous/protocol, - waku_rendezvous/client as rendezvous_client, - waku_lightpush_legacy/client as legacy_lightpush_client, - waku_lightpush_legacy as legacy_lightpush_protocol, - waku_lightpush/client as lightpush_client, - waku_lightpush as lightpush_protocol, - waku_peer_exchange, - waku_rln_relay, - waku_mix, - common/rate_limit/setting, - discovery/waku_kademlia, - net/bound_ports, - events/peer_events, - ], - ./peer_manager, - ./health_monitor/topic_health - -# key and crypto modules different -type - # TODO: Move to application instance (e.g., `WakuNode2`) - WakuInfo* = object # NOTE One for simplicity, can extend later as needed - listenAddresses*: seq[string] - enrUri*: string #multiaddrStrings*: seq[string] - mixPubKey*: Option[string] - - # NOTE based on Eth2Node in NBC eth2_network.nim - WakuNode* = ref object - peerManager*: PeerManager - switch*: Switch - wakuRelay*: WakuRelay - wakuArchive*: waku_archive.WakuArchive - wakuStore*: store.WakuStore - wakuStoreClient*: store_client.WakuStoreClient - wakuStoreResume*: StoreResume - wakuStoreReconciliation*: SyncReconciliation - wakuStoreTransfer*: SyncTransfer - wakuFilter*: waku_filter_v2.WakuFilter - wakuFilterClient*: filter_client.WakuFilterClient - wakuRlnRelay*: WakuRLNRelay - wakuLegacyLightPush*: WakuLegacyLightPush - wakuLegacyLightpushClient*: WakuLegacyLightPushClient - wakuLightPush*: WakuLightPush - wakuLightpushClient*: WakuLightPushClient - wakuPeerExchange*: WakuPeerExchange - wakuPeerExchangeClient*: WakuPeerExchangeClient - wakuMetadata*: WakuMetadata - wakuAutoSharding*: Option[Sharding] - enr*: enr.Record - libp2pPing*: Ping - rng*: ref rand.HmacDrbgContext - brokerCtx*: BrokerContext - wakuRendezvous*: WakuRendezVous - wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient - announcedAddresses*: seq[MultiAddress] - extMultiAddrsOnly*: bool # When true, skip automatic IP address replacement - started*: bool # Indicates that node has started listening - topicSubscriptionQueue*: AsyncEventQueue[SubscriptionEvent] - rateLimitSettings*: ProtocolRateLimitSettings - legacyAppHandlers*: Table[PubsubTopic, WakuRelayHandler] - ## Kernel API Relay appHandlers (if any) - subscriptionManager*: SubscriptionManager - wakuMix*: WakuMix - kademliaDiscoveryLoop*: Future[void] - wakuKademlia*: WakuKademlia - ports*: BoundPorts - - ShardSubscription* = object - contentTopics*: HashSet[ContentTopic] - directShardSub*: bool - ## shard subscribed directly (PubsubSub), independent of content-topic interest - - EdgeFilterSubState* = object - peers*: seq[RemotePeerInfo] - pending*: seq[Future[void]] - pendingPeers*: HashSet[PeerId] - currentHealth*: TopicHealth - - SubscriptionManager* = ref object of RootObj - node*: WakuNode - shards*: Table[PubsubTopic, ShardSubscription] - edgeFilterSubStates*: Table[PubsubTopic, EdgeFilterSubState] - edgeFilterWakeup*: AsyncEvent - edgeFilterSubLoopFut*: Future[void] - edgeFilterConnectionLoopFut*: Future[void] - peerEventListener*: WakuPeerEventListener - ownsEdgeShardHealthProvider*: bool - ownsEdgeFilterPeerCountProvider*: bool - -{.pop.} diff --git a/waku/node/shard_subscription.nim b/waku/node/shard_subscription.nim new file mode 100644 index 000000000..9801fb32d --- /dev/null +++ b/waku/node/shard_subscription.nim @@ -0,0 +1,11 @@ +{.push raises: [].} + +import std/sets +import ../waku_core + +type ShardSubscription* = object + contentTopics*: HashSet[ContentTopic] + directShardSub*: bool + ## shard subscribed directly (PubsubSub), independent of content-topic interest + +{.pop.} diff --git a/waku/node/subscription_manager.nim b/waku/node/subscription_manager.nim index 409fab53f..8bcb7bb46 100644 --- a/waku/node/subscription_manager.nim +++ b/waku/node/subscription_manager.nim @@ -6,7 +6,7 @@ import waku/[ waku_core, waku_core/topics/sharding, - node/node_types, + node/waku_node, node/node_telemetry, waku_relay, waku_archive, diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 9ac3c5d00..6a8826d2a 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -67,7 +67,11 @@ import ./peer_manager, ./health_monitor/health_status, ./health_monitor/topic_health, - ./node_telemetry + ./node_telemetry, + ./shard_subscription, + ./edge_filter_sub_state + +export shard_subscription, edge_filter_sub_state logScope: topics = "waku node" @@ -85,8 +89,64 @@ const clientId* = "Nimbus Waku v2 node" const WakuNodeVersionString* = "version / git commit hash: " & git_version -import ./node_types -export node_types +type + # TODO: Move to application instance (e.g., `WakuNode2`) + WakuInfo* = object # NOTE One for simplicity, can extend later as needed + listenAddresses*: seq[string] + enrUri*: string #multiaddrStrings*: seq[string] + mixPubKey*: Option[string] + + # NOTE based on Eth2Node in NBC eth2_network.nim + WakuNode* = ref object + peerManager*: PeerManager + switch*: Switch + wakuRelay*: WakuRelay + wakuArchive*: waku_archive.WakuArchive + wakuStore*: store.WakuStore + wakuStoreClient*: store_client.WakuStoreClient + wakuStoreResume*: StoreResume + wakuStoreReconciliation*: SyncReconciliation + wakuStoreTransfer*: SyncTransfer + wakuFilter*: waku_filter_v2.WakuFilter + wakuFilterClient*: filter_client.WakuFilterClient + wakuRlnRelay*: WakuRLNRelay + wakuLegacyLightPush*: WakuLegacyLightPush + wakuLegacyLightpushClient*: WakuLegacyLightPushClient + wakuLightPush*: WakuLightPush + wakuLightpushClient*: WakuLightPushClient + wakuPeerExchange*: WakuPeerExchange + wakuPeerExchangeClient*: WakuPeerExchangeClient + wakuMetadata*: WakuMetadata + wakuAutoSharding*: Option[Sharding] + enr*: enr.Record + libp2pPing*: Ping + rng*: ref rand.HmacDrbgContext + brokerCtx*: BrokerContext + wakuRendezvous*: WakuRendezVous + wakuRendezvousClient*: rendezvous_client.WakuRendezVousClient + announcedAddresses*: seq[MultiAddress] + extMultiAddrsOnly*: bool # When true, skip automatic IP address replacement + started*: bool # Indicates that node has started listening + topicSubscriptionQueue*: AsyncEventQueue[SubscriptionEvent] + rateLimitSettings*: ProtocolRateLimitSettings + legacyAppHandlers*: Table[PubsubTopic, WakuRelayHandler] + ## Kernel API Relay appHandlers (if any) + subscriptionManager*: SubscriptionManager + wakuMix*: WakuMix + kademliaDiscoveryLoop*: Future[void] + wakuKademlia*: WakuKademlia + ports*: BoundPorts + + SubscriptionManager* = ref object of RootObj + node*: WakuNode + shards*: Table[PubsubTopic, ShardSubscription] + edgeFilterSubStates*: Table[PubsubTopic, EdgeFilterSubState] + edgeFilterWakeup*: AsyncEvent + edgeFilterSubLoopFut*: Future[void] + edgeFilterConnectionLoopFut*: Future[void] + peerEventListener*: WakuPeerEventListener + ownsEdgeShardHealthProvider*: bool + ownsEdgeFilterPeerCountProvider*: bool import ./subscription_manager diff --git a/waku/node/kernel_api/filter.nim b/waku/node/waku_node/filter.nim similarity index 100% rename from waku/node/kernel_api/filter.nim rename to waku/node/waku_node/filter.nim diff --git a/waku/node/kernel_api/lightpush.nim b/waku/node/waku_node/lightpush.nim similarity index 100% rename from waku/node/kernel_api/lightpush.nim rename to waku/node/waku_node/lightpush.nim diff --git a/waku/node/kernel_api/peer_exchange.nim b/waku/node/waku_node/peer_exchange.nim similarity index 100% rename from waku/node/kernel_api/peer_exchange.nim rename to waku/node/waku_node/peer_exchange.nim diff --git a/waku/node/kernel_api/ping.nim b/waku/node/waku_node/ping.nim similarity index 100% rename from waku/node/kernel_api/ping.nim rename to waku/node/waku_node/ping.nim diff --git a/waku/node/kernel_api/relay.nim b/waku/node/waku_node/relay.nim similarity index 100% rename from waku/node/kernel_api/relay.nim rename to waku/node/waku_node/relay.nim diff --git a/waku/node/kernel_api/store.nim b/waku/node/waku_node/store.nim similarity index 100% rename from waku/node/kernel_api/store.nim rename to waku/node/waku_node/store.nim diff --git a/waku/rest_api/endpoint/builder.nim b/waku/rest_api/endpoint/builder.nim index 9b4ecf662..16cdde988 100644 --- a/waku/rest_api/endpoint/builder.nim +++ b/waku/rest_api/endpoint/builder.nim @@ -4,6 +4,7 @@ import net, tables import presto import waku/waku_node, + waku/node/health_monitor, waku/discovery/waku_discv5, waku/rest_api/message_cache, waku/rest_api/handlers, diff --git a/waku/rest_api/endpoint/health/handlers.nim b/waku/rest_api/endpoint/health/handlers.nim index 865133245..dc7588d16 100644 --- a/waku/rest_api/endpoint/health/handlers.nim +++ b/waku/rest_api/endpoint/health/handlers.nim @@ -1,7 +1,8 @@ {.push raises: [].} import chronicles, json_serialization, presto/route -import ../../../waku_node, ../responses, ../serdes, ./types +import + ../../../waku_node, ../../../node/health_monitor, ../responses, ../serdes, ./types logScope: topics = "waku node rest health_api" diff --git a/waku/rest_api/endpoint/health/types.nim b/waku/rest_api/endpoint/health/types.nim index 88fa736a8..4f85ebde5 100644 --- a/waku/rest_api/endpoint/health/types.nim +++ b/waku/rest_api/endpoint/health/types.nim @@ -3,7 +3,7 @@ import results import chronicles, json_serialization, json_serialization/std/options import ../serdes -import waku/[waku_node, api/types] +import waku/[waku_node, api/types, node/health_monitor] #### Serialization and deserialization diff --git a/waku/waku_node.nim b/waku/waku_node.nim index c8b13d4ea..674ac96e6 100644 --- a/waku/waku_node.nim +++ b/waku/waku_node.nim @@ -1,8 +1,13 @@ import - ./net/net_config, ./node/waku_switch as switch, ./node/waku_node as node, - ./node/health_monitor as health_monitor, - ./node/kernel_api as kernel_api + ./node/waku_node/filter as filter_api, + ./node/waku_node/lightpush as lightpush_api, + ./node/waku_node/store as store_api, + ./node/waku_node/relay as relay_api, + ./node/waku_node/peer_exchange as peer_exchange_api, + ./node/waku_node/ping as ping_api -export net_config, switch, node, health_monitor, kernel_api +export + switch, node, filter_api, lightpush_api, store_api, relay_api, peer_exchange_api, + ping_api From 3b03ca29b10fb67c9d7aadaa182a866a6ba712d7 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Mon, 8 Jun 2026 13:37:53 +0200 Subject: [PATCH 09/13] refactor: introduce proper logos_delivery layers folder structure (#3935) Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bump_dependencies.md | 4 +-- .github/ISSUE_TEMPLATE/prepare_release.md | 2 +- .github/workflows/ci.yml | 7 ++-- .github/workflows/container-image.yml | 2 +- .github/workflows/pr-lint.yml | 4 +-- .github/workflows/release-assets.yml | 14 ++++---- .github/workflows/version-check.yml | 16 ++++----- .gitignore | 1 + AGENTS.md | 10 +++--- Makefile | 31 +++++++++-------- apps/benchmarks/benchmarks.nim | 2 +- apps/chat2/chat2.nim | 4 +-- apps/chat2/config_chat2.nim | 2 +- apps/chat2bridge/chat2bridge.nim | 5 +-- apps/chat2mix/chat2mix.nim | 4 +-- apps/chat2mix/config_chat2mix.nim | 2 +- .../diagnose_connections.nim | 3 +- apps/liteprotocoltester/legacy_publisher.nim | 2 +- .../liteprotocoltester/liteprotocoltester.nim | 5 ++- apps/liteprotocoltester/publisher.nim | 2 +- apps/liteprotocoltester/publisher_base.nim | 2 +- apps/liteprotocoltester/receiver.nim | 2 +- .../service_peer_management.nim | 3 +- apps/liteprotocoltester/tester_config.nim | 2 +- apps/liteprotocoltester/tester_message.nim | 2 +- apps/liteprotocoltester/v3_publisher.nim | 2 +- apps/networkmonitor/networkmonitor.nim | 2 +- apps/wakucanary/wakucanary.nim | 9 ++--- apps/wakunode2/wakunode2.nim | 2 +- ci/Jenkinsfile.prs | 4 +-- examples/api_example/api_example.nim | 2 +- examples/filter_subscriber.nim | 2 +- .../lightpush_mix/lightpush_publisher_mix.nim | 2 +- .../lightpush_publisher_mix_config.nim | 2 +- examples/lightpush_publisher.nim | 2 +- examples/publisher.nim | 2 +- examples/subscriber.nim | 2 +- examples/wakustealthcommitments/node_spec.nim | 5 ++- .../stealth_commitment_protocol.nim | 2 +- examples/wakustealthcommitments/wire_spec.nim | 2 +- flake.nix | 4 +-- liblogosdelivery/declare_lib.nim | 2 +- liblogosdelivery/liblogosdelivery.nim | 3 +- .../logos_delivery_api/debug_api.nim | 2 +- .../logos_delivery_api/messaging_api.nim | 8 ++--- .../logos_delivery_api/node_api.nim | 8 ++--- library/declare_lib.nim | 2 +- .../events/json_connection_change_event.nim | 2 +- .../json_connection_status_change_event.nim | 2 +- library/events/json_message_event.nim | 6 ++-- .../events/json_topic_health_change_event.nim | 4 +-- library/kernel_api/debug_node_api.nim | 5 ++- library/kernel_api/discovery_api.nim | 10 +++--- library/kernel_api/node_lifecycle_api.nim | 10 +++--- library/kernel_api/peer_manager_api.nim | 6 +++- library/kernel_api/ping_api.nim | 4 ++- library/kernel_api/protocols/filter_api.nim | 20 +++++------ .../kernel_api/protocols/lightpush_api.nim | 14 ++++---- library/kernel_api/protocols/relay_api.nim | 16 ++++----- library/kernel_api/protocols/store_api.nim | 12 +++---- library/libwaku.nim | 14 ++++---- waku.nim => logos_delivery.nim | 4 +-- waku.nimble => logos_delivery.nimble | 3 +- .../channels}/encryption/encryption.nim | 0 .../channels}/encryption/noop_encryption.nim | 0 .../channels}/events.nim | 2 +- .../rate_limit_manager/rate_limit_manager.nim | 0 .../channels}/reliable_channel.nim | 10 +++--- .../channels}/reliable_channel_manager.nim | 15 +++------ .../scalable_data_sync/scalable_data_sync.nim | 0 .../scalable_data_sync/sds_persistence.nim | 0 .../segmentation/segment_message_proto.nim | 0 .../channels}/segmentation/segmentation.nim | 0 .../segmentation/segmentation_persistence.nim | 0 .../channels}/types.nim | 2 +- .../not_delivered_storage/migrations.nim | 4 ++- .../not_delivered_storage.nim | 6 ++-- .../delivery_service/recv_service.nim | 0 .../recv_service/recv_service.nim | 2 +- .../delivery_service/send_service.nim | 0 .../send_service/delivery_task.nim | 5 ++- .../send_service/lightpush_processor.nim | 5 ++- .../send_service/relay_processor.nim | 6 ++-- .../send_service/send_processor.nim | 0 .../send_service/send_service.nim | 4 +-- .../messaging}/messaging_client.nim | 12 +++---- {waku => logos_delivery/waku}/README.md | 0 {waku => logos_delivery/waku}/api.nim | 0 {waku => logos_delivery/waku}/api/api.nim | 12 +++---- .../waku}/api/api_conf.nim | 10 +++--- {waku => logos_delivery/waku}/api/send_api.md | 0 {waku => logos_delivery/waku}/api/types.nim | 6 ++-- .../waku}/common/base64.nim | 0 .../waku}/common/callbacks.nim | 4 ++- .../waku}/common/databases/common.nim | 0 .../waku}/common/databases/db_postgres.nim | 0 .../common/databases/db_postgres/dbconn.nim | 0 .../databases/db_postgres/pgasyncpool.nim | 0 .../databases/db_postgres/query_metrics.nim | 0 .../waku}/common/databases/db_sqlite.nim | 0 .../waku}/common/databases/dburl.nim | 0 {waku => logos_delivery/waku}/common/enr.nim | 0 .../waku}/common/enr/builder.nim | 0 .../waku}/common/enr/typed_record.nim | 0 .../waku}/common/error_handling.nim | 0 .../waku}/common/hexstrings.nim | 0 .../waku}/common/logging.nim | 0 .../waku}/common/nimchronos.nim | 0 .../waku}/common/paging.nim | 0 .../waku}/common/protobuf.nim | 0 .../common/rate_limit/per_peer_limiter.nim | 0 .../common/rate_limit/request_limiter.nim | 0 .../common/rate_limit/service_metrics.nim | 0 .../waku}/common/rate_limit/setting.nim | 0 .../rate_limit/single_token_limiter.nim | 0 .../waku}/common/rate_limit/timed_map.nim | 0 .../waku}/common/utils/DEPRECATION_NOTICE.md | 0 .../common/utils/matterbridge_client.nim | 0 .../waku}/common/utils/nat.nim | 0 .../waku}/common/utils/parse_size_units.nim | 0 .../waku}/common/utils/sequence.nim | 0 .../waku}/common/waku_protocol.nim | 0 .../waku}/discovery/autonat_service.nim | 0 .../waku}/discovery/waku_discv5.nim | 4 ++- .../waku}/discovery/waku_dnsdisc.nim | 0 .../waku}/discovery/waku_kademlia.nim | 2 +- .../waku}/events/delivery_events.nim | 2 +- .../waku}/events/events.nim | 0 .../waku}/events/health_events.nim | 6 ++-- .../waku}/events/message_events.nim | 2 +- .../waku}/events/peer_events.nim | 0 .../waku}/factory/app_callbacks.nim | 0 .../waku}/factory/builder.nim | 0 .../factory/conf_builder/conf_builder.nim | 0 .../conf_builder/discv5_conf_builder.nim | 0 .../dns_discovery_conf_builder.nim | 0 .../filter_service_conf_builder.nim | 0 .../kademlia_discovery_conf_builder.nim | 2 +- .../metrics_server_conf_builder.nim | 0 .../factory/conf_builder/mix_conf_builder.nim | 2 +- .../conf_builder/rate_limit_conf_builder.nim | 2 +- .../conf_builder/rest_server_conf_builder.nim | 0 .../conf_builder/rln_relay_conf_builder.nim | 0 .../store_service_conf_builder.nim | 0 .../conf_builder/store_sync_conf_builder.nim | 0 .../conf_builder/waku_conf_builder.nim | 2 +- .../conf_builder/web_socket_conf_builder.nim | 2 +- .../waku}/factory/internal_config.nim | 4 ++- .../waku}/factory/networks_config.nim | 0 .../waku}/factory/node_factory.nim | 0 .../waku}/factory/validator_signed.nim | 0 .../waku}/factory/waku.nim | 6 ++-- .../waku}/factory/waku_conf.nim | 0 .../waku}/factory/waku_state_info.nim | 2 +- .../waku}/incentivization/common.nim | 2 +- .../incentivization/eligibility_manager.nim | 2 +- .../incentivization/reputation_manager.nim | 0 .../waku}/incentivization/rpc.nim | 0 .../waku}/incentivization/rpc_codec.nim | 0 .../waku}/net/auto_port.nim | 0 .../waku}/net/bound_ports.nim | 0 .../waku}/net/net_config.nim | 0 .../waku}/node/edge_filter_sub_state.nim | 0 .../waku}/node/health_monitor.nim | 0 .../node/health_monitor/connection_status.nim | 0 .../health_monitor/event_loop_monitor.nim | 0 .../node/health_monitor/health_report.nim | 0 .../node/health_monitor/health_status.nim | 0 .../health_monitor/node_health_monitor.nim | 2 +- .../node/health_monitor/online_monitor.nim | 2 +- .../node/health_monitor/protocol_health.nim | 2 +- .../node/health_monitor/topic_health.nim | 2 +- .../waku}/node/node_telemetry.nim | 0 .../waku}/node/peer_manager.nim | 0 .../waku}/node/peer_manager/peer_manager.nim | 2 +- .../peer_manager/peer_store/migrations.nim | 0 .../peer_manager/peer_store/peer_storage.nim | 0 .../peer_store/waku_peer_storage.nim | 0 .../node/peer_manager/waku_peer_store.nim | 0 .../waku}/node/shard_subscription.nim | 0 .../waku}/node/subscription_manager.nim | 2 +- .../waku}/node/waku_metrics.nim | 3 +- .../waku}/node/waku_node.nim | 6 ++-- .../waku}/node/waku_node/filter.nim | 0 .../waku}/node/waku_node/lightpush.nim | 0 .../waku}/node/waku_node/peer_exchange.nim | 0 .../waku}/node/waku_node/ping.nim | 0 .../waku}/node/waku_node/relay.nim | 2 +- .../waku}/node/waku_node/store.nim | 0 .../waku}/node/waku_switch.nim | 0 .../waku}/persistency/backend_comm.nim | 0 .../waku}/persistency/backend_sqlite.nim | 0 .../waku}/persistency/backend_thread.nim | 0 .../waku}/persistency/keys.nim | 0 .../waku}/persistency/payload.nim | 0 .../waku}/persistency/persistency.nim | 0 .../waku}/persistency/schema.nim | 0 .../waku}/persistency/sds_persistency.nim | 0 .../waku}/persistency/types.nim | 0 .../waku}/requests/health_requests.nim | 9 ++--- .../waku}/requests/node_requests.nim | 2 +- .../waku}/requests/requests.nim | 0 .../waku}/requests/rln_requests.nim | 2 +- .../waku}/rest_api/endpoint/admin/client.nim | 0 .../rest_api/endpoint/admin/handlers.nim | 2 +- .../waku}/rest_api/endpoint/admin/types.nim | 2 +- .../waku}/rest_api/endpoint/builder.nim | 33 ++++++++++--------- .../waku}/rest_api/endpoint/client.nim | 0 .../waku}/rest_api/endpoint/debug/client.nim | 0 .../rest_api/endpoint/debug/handlers.nim | 0 .../waku}/rest_api/endpoint/debug/types.nim | 0 .../waku}/rest_api/endpoint/filter/client.nim | 0 .../rest_api/endpoint/filter/handlers.nim | 0 .../waku}/rest_api/endpoint/filter/types.nim | 0 .../waku}/rest_api/endpoint/health/client.nim | 2 +- .../rest_api/endpoint/health/handlers.nim | 0 .../waku}/rest_api/endpoint/health/types.nim | 2 +- .../endpoint/legacy_lightpush/client.nim | 0 .../endpoint/legacy_lightpush/handlers.nim | 4 +-- .../endpoint/legacy_lightpush/types.nim | 0 .../rest_api/endpoint/lightpush/client.nim | 0 .../rest_api/endpoint/lightpush/handlers.nim | 4 +-- .../rest_api/endpoint/lightpush/types.nim | 0 .../rest_api/endpoint/origin_handler.nim | 0 .../waku}/rest_api/endpoint/relay/client.nim | 0 .../rest_api/endpoint/relay/handlers.nim | 0 .../waku}/rest_api/endpoint/relay/types.nim | 0 .../waku}/rest_api/endpoint/responses.nim | 0 .../waku}/rest_api/endpoint/rest_serdes.nim | 0 .../waku}/rest_api/endpoint/serdes.nim | 0 .../waku}/rest_api/endpoint/server.nim | 0 .../waku}/rest_api/endpoint/store/client.nim | 0 .../rest_api/endpoint/store/handlers.nim | 0 .../waku}/rest_api/endpoint/store/types.nim | 0 .../waku}/rest_api/handlers.nim | 0 .../waku}/rest_api/message_cache.nim | 0 .../waku}/utils/DEPRECATION_NOTICE.md | 0 .../waku}/utils/collector.nim | 0 {waku => logos_delivery/waku}/utils/noise.nim | 0 .../waku}/utils/requests.nim | 0 .../waku}/utils/tableutils.nim | 0 .../waku}/waku_archive.nim | 0 .../waku}/waku_archive/archive.nim | 2 +- .../waku}/waku_archive/archive_metrics.nim | 0 .../waku}/waku_archive/common.nim | 0 .../waku}/waku_archive/driver.nim | 0 .../waku}/waku_archive/driver/builder.nim | 0 .../waku_archive/driver/postgres_driver.nim | 0 .../driver/postgres_driver/migrations.nim | 2 +- .../postgres_driver/partitions_manager.nim | 0 .../postgres_driver/postgres_driver.nim | 0 .../postgres_driver/postgres_healthcheck.nim | 0 .../waku_archive/driver/queue_driver.nim | 0 .../driver/queue_driver/index.nim | 0 .../driver/queue_driver/queue_driver.nim | 0 .../waku_archive/driver/sqlite_driver.nim | 0 .../driver/sqlite_driver/migrations.nim | 0 .../driver/sqlite_driver/queries.nim | 0 .../driver/sqlite_driver/sqlite_driver.nim | 0 .../waku}/waku_archive/retention_policy.nim | 0 .../waku_archive/retention_policy/builder.nim | 0 .../retention_policy_capacity.nim | 0 .../retention_policy_size.nim | 0 .../retention_policy_time.nim | 0 {waku => logos_delivery/waku}/waku_core.nim | 0 .../waku}/waku_core/codecs.nim | 0 .../waku}/waku_core/message.nim | 0 .../waku}/waku_core/message/codec.nim | 0 .../waku_core/message/default_values.nim | 0 .../waku}/waku_core/message/digest.nim | 0 .../waku}/waku_core/message/message.nim | 0 .../waku}/waku_core/multiaddrstr.nim | 0 .../waku}/waku_core/peers.nim | 0 .../waku}/waku_core/subscription.nim | 0 .../waku_core/subscription/push_handler.nim | 0 .../waku}/waku_core/time.nim | 0 .../waku}/waku_core/topics.nim | 0 .../waku}/waku_core/topics/content_topic.nim | 0 .../waku}/waku_core/topics/parsing.nim | 0 .../waku}/waku_core/topics/pubsub_topic.nim | 0 .../waku}/waku_core/topics/sharding.nim | 0 {waku => logos_delivery/waku}/waku_enr.nim | 0 .../waku}/waku_enr/capabilities.nim | 0 .../waku}/waku_enr/multiaddr.nim | 0 .../waku}/waku_enr/sharding.nim | 0 .../waku}/waku_filter_v2.nim | 0 .../waku}/waku_filter_v2/client.nim | 2 +- .../waku}/waku_filter_v2/common.nim | 0 .../waku}/waku_filter_v2/protocol.nim | 0 .../waku}/waku_filter_v2/protocol_metrics.nim | 0 .../waku}/waku_filter_v2/rpc.nim | 0 .../waku}/waku_filter_v2/rpc_codec.nim | 0 .../waku}/waku_filter_v2/subscriptions.nim | 0 .../waku}/waku_keystore.nim | 0 .../waku}/waku_keystore/conversion_utils.nim | 0 .../waku}/waku_keystore/keyfile.nim | 0 .../waku}/waku_keystore/keystore.nim | 0 .../waku}/waku_keystore/protocol_types.nim | 0 .../waku}/waku_keystore/utils.nim | 0 .../waku}/waku_lightpush.nim | 0 .../waku}/waku_lightpush/callbacks.nim | 0 .../waku}/waku_lightpush/client.nim | 0 .../waku}/waku_lightpush/common.nim | 0 .../waku}/waku_lightpush/protocol.nim | 0 .../waku}/waku_lightpush/protocol_metrics.nim | 0 .../waku}/waku_lightpush/rpc.nim | 0 .../waku}/waku_lightpush/rpc_codec.nim | 0 .../waku}/waku_lightpush/self_req_handler.nim | 0 .../waku}/waku_lightpush_legacy.nim | 0 .../waku}/waku_lightpush_legacy/README.md | 0 .../waku}/waku_lightpush_legacy/callbacks.nim | 0 .../waku}/waku_lightpush_legacy/client.nim | 0 .../waku}/waku_lightpush_legacy/common.nim | 0 .../waku}/waku_lightpush_legacy/protocol.nim | 0 .../protocol_metrics.nim | 0 .../waku}/waku_lightpush_legacy/rpc.nim | 0 .../waku}/waku_lightpush_legacy/rpc_codec.nim | 0 .../self_req_handler.nim | 0 .../waku}/waku_metadata.nim | 0 .../waku}/waku_metadata/protocol.nim | 0 .../waku}/waku_metadata/rpc.nim | 0 {waku => logos_delivery/waku}/waku_mix.nim | 0 .../waku}/waku_mix/protocol.nim | 8 ++--- {waku => logos_delivery/waku}/waku_node.nim | 0 .../waku}/waku_noise/noise.nim | 0 .../waku_noise/noise_handshake_processing.nim | 0 .../waku}/waku_noise/noise_types.nim | 0 .../waku}/waku_noise/noise_utils.nim | 0 .../waku}/waku_peer_exchange.nim | 0 .../waku}/waku_peer_exchange/README.md | 0 .../waku}/waku_peer_exchange/client.nim | 0 .../waku}/waku_peer_exchange/common.nim | 0 .../waku}/waku_peer_exchange/protocol.nim | 0 .../waku}/waku_peer_exchange/rpc.nim | 0 .../waku}/waku_peer_exchange/rpc_codec.nim | 0 logos_delivery/waku/waku_persistency.nim | 3 ++ {waku => logos_delivery/waku}/waku_relay.nim | 2 +- .../waku}/waku_relay/message_id.nim | 0 .../waku}/waku_relay/protocol.nim | 12 +++---- .../waku}/waku_rendezvous.nim | 0 .../waku}/waku_rendezvous/client.nim | 6 ++-- .../waku}/waku_rendezvous/common.nim | 0 .../waku}/waku_rendezvous/protocol.nim | 0 .../waku_rendezvous/waku_peer_record.nim | 0 {waku => logos_delivery/waku}/waku_rest.nim | 0 .../waku}/waku_rln_relay.nim | 0 .../waku}/waku_rln_relay/constants.nim | 0 .../waku}/waku_rln_relay/contract.nim | 0 .../waku}/waku_rln_relay/conversion_utils.nim | 0 .../waku}/waku_rln_relay/group_manager.nim | 0 .../group_manager/group_manager_base.nim | 0 .../waku_rln_relay/group_manager/on_chain.nim | 0 .../group_manager/on_chain/group_manager.nim | 0 .../group_manager/on_chain/retry_wrapper.nim | 0 .../group_manager/on_chain/rpc_wrapper.nim | 0 .../waku}/waku_rln_relay/nonce_manager.nim | 0 .../waku}/waku_rln_relay/protocol_metrics.nim | 0 .../waku}/waku_rln_relay/protocol_types.nim | 0 .../waku}/waku_rln_relay/rln.nim | 0 .../waku_rln_relay/rln/rln_interface.nim | 0 .../waku}/waku_rln_relay/rln/wrappers.nim | 0 .../waku}/waku_rln_relay/rln_relay.nim | 2 +- {waku => logos_delivery/waku}/waku_store.nim | 0 .../waku}/waku_store/client.nim | 0 .../waku}/waku_store/common.nim | 0 .../waku}/waku_store/protocol.nim | 0 .../waku}/waku_store/protocol_metrics.nim | 0 .../waku}/waku_store/resume.nim | 0 .../waku}/waku_store/rpc_codec.nim | 0 .../waku}/waku_store/self_req_handler.nim | 0 .../waku}/waku_store_sync.nim | 0 .../waku}/waku_store_sync/codec.nim | 0 .../waku}/waku_store_sync/common.nim | 0 .../waku_store_sync/protocols_metrics.nim | 0 .../waku}/waku_store_sync/reconciliation.nim | 0 .../storage/range_processing.nim | 0 .../waku_store_sync/storage/seq_storage.nim | 0 .../waku}/waku_store_sync/storage/storage.nim | 0 .../waku}/waku_store_sync/transfer.nim | 0 tests/api/test_api_health.nim | 17 +++++----- tests/api/test_api_receive.nim | 10 +++--- tests/api/test_api_send.nim | 4 +-- tests/api/test_api_subscription.nim | 8 ++--- tests/api/test_node_conf.nim | 12 +++---- .../test_reliable_channel_send_receive.nim | 12 +++---- tests/common/test_base64_codec.nim | 2 +- tests/common/test_enr_builder.nim | 2 +- tests/common/test_parse_size.nim | 2 +- tests/common/test_protobuf_validation.nim | 2 +- tests/common/test_ratelimit_setting.nim | 4 +-- tests/common/test_requestratelimiter.nim | 4 +-- tests/common/test_sqlite_migrations.nim | 3 +- tests/common/test_timed_map.nim | 2 +- tests/factory/test_node_factory.nim | 4 +-- tests/factory/test_waku_conf.nim | 8 ++--- .../incentivization/test_poc_eligibility.nim | 4 +-- tests/incentivization/test_poc_reputation.nim | 4 ++- tests/incentivization/test_rpc_codec.nim | 2 +- .../peer_store/test_migrations.nim | 6 ++-- .../peer_store/test_peer_storage.nim | 4 ++- .../peer_store/test_waku_peer_storage.nim | 4 ++- tests/node/peer_manager/peer_store/utils.nim | 2 +- tests/node/peer_manager/test_peer_manager.nim | 6 ++-- tests/node/test_wakunode_filter.nim | 2 +- tests/node/test_wakunode_health_monitor.nim | 6 ++-- tests/node/test_wakunode_legacy_lightpush.nim | 2 +- tests/node/test_wakunode_lightpush.nim | 3 +- tests/node/test_wakunode_peer_exchange.nim | 2 +- tests/node/test_wakunode_peer_manager.nim | 2 +- tests/node/test_wakunode_relay_rln.nim | 4 +-- tests/node/test_wakunode_sharding.nim | 2 +- tests/node/test_wakunode_store.nim | 2 +- tests/node/utils.nim | 3 +- tests/persistency/test_backend.nim | 2 +- tests/persistency/test_encoding.nim | 2 +- tests/persistency/test_facade.nim | 2 +- tests/persistency/test_keys.nim | 2 +- tests/persistency/test_lifecycle.nim | 4 +-- tests/persistency/test_sds_persistency.nim | 6 ++-- tests/persistency/test_singleton.nim | 2 +- tests/persistency/test_string_lookup.nim | 2 +- tests/test_message_cache.nim | 5 ++- tests/test_peer_manager.nim | 2 +- tests/test_peer_storage.nim | 2 +- tests/test_peer_store_extended.nim | 2 +- tests/test_relay_peer_exchange.nim | 6 +++- tests/test_utils_compat.nim | 6 +++- tests/test_waku.nim | 2 +- tests/test_waku_dnsdisc.nim | 6 ++-- tests/test_waku_enr.nim | 2 +- tests/test_waku_keepalive.nim | 6 ++-- tests/test_waku_keystore.nim | 4 +-- tests/test_waku_keystore_keyfile.nim | 4 +-- tests/test_waku_metadata.nim | 2 +- tests/test_waku_netconfig.nim | 8 ++--- tests/test_waku_noise.nim | 2 +- tests/test_waku_noise_sessions.nim | 2 +- tests/test_waku_protobufs.nim | 5 ++- tests/test_waku_rendezvous.nim | 16 ++++----- tests/test_waku_switch.nim | 2 +- tests/test_wakunode.nim | 4 ++- tests/testlib/futures.nim | 2 +- tests/testlib/postgres.nim | 2 +- tests/testlib/tables.nim | 2 +- tests/testlib/wakucore.nim | 2 +- tests/testlib/wakunode.nim | 2 +- tests/waku_archive/archive_utils.nim | 2 +- tests/waku_archive/test_driver_postgres.nim | 2 +- .../test_driver_postgres_query.nim | 2 +- tests/waku_archive/test_driver_queue.nim | 2 +- .../waku_archive/test_driver_queue_index.nim | 4 ++- .../test_driver_queue_pagination.nim | 2 +- .../waku_archive/test_driver_queue_query.nim | 2 +- tests/waku_archive/test_driver_sqlite.nim | 2 +- .../waku_archive/test_driver_sqlite_query.nim | 2 +- tests/waku_archive/test_partition_manager.nim | 4 ++- tests/waku_archive/test_retention_policy.nim | 2 +- tests/waku_archive/test_waku_archive.nim | 2 +- tests/waku_core/test_message_digest.nim | 2 +- tests/waku_core/test_namespaced_topics.nim | 2 +- tests/waku_core/test_peers.nim | 2 +- tests/waku_core/test_time.nim | 2 +- tests/waku_core/topics/test_pubsub_topic.nim | 2 +- tests/waku_core/topics/test_sharding.nim | 2 +- tests/waku_discv5/test_waku_discv5.nim | 2 +- tests/waku_discv5/utils.nim | 2 +- tests/waku_enr/test_sharding.nim | 2 +- tests/waku_enr/utils.nim | 4 ++- tests/waku_filter_v2/test_waku_client.nim | 9 ++--- .../test_waku_filter_dos_protection.nim | 4 +-- tests/waku_filter_v2/waku_filter_utils.nim | 2 +- tests/waku_keystore/utils.nim | 3 +- tests/waku_lightpush/lightpush_utils.nim | 12 +++---- tests/waku_lightpush/test_client.nim | 2 +- tests/waku_lightpush/test_ratelimit.nim | 3 +- .../waku_lightpush_legacy/lightpush_utils.nim | 8 ++--- tests/waku_lightpush_legacy/test_client.nim | 2 +- .../waku_lightpush_legacy/test_ratelimit.nim | 2 +- tests/waku_peer_exchange/test_protocol.nim | 2 +- tests/waku_peer_exchange/test_rpc_codec.nim | 2 +- tests/waku_peer_exchange/utils.nim | 2 +- tests/waku_relay/test_message_id.nim | 2 +- tests/waku_relay/test_protocol.nim | 2 +- tests/waku_relay/test_wakunode_relay.nim | 2 +- tests/waku_relay/utils.nim | 2 +- .../waku_rln_relay/rln/test_rln_interface.nim | 4 +-- tests/waku_rln_relay/rln/test_wrappers.nim | 5 ++- .../rln/waku_rln_relay_utils.nim | 4 +-- .../test_rln_contract_deployment.nim | 2 +- .../test_rln_group_manager_onchain.nim | 2 +- .../waku_rln_relay/test_rln_nonce_manager.nim | 2 +- tests/waku_rln_relay/test_waku_rln_relay.nim | 2 +- .../test_wakunode_rln_relay.nim | 2 +- tests/waku_rln_relay/utils_offchain.nim | 2 +- tests/waku_rln_relay/utils_onchain.nim | 2 +- tests/waku_store/store_utils.nim | 3 +- tests/waku_store/test_client.nim | 3 +- tests/waku_store/test_resume.nim | 2 +- tests/waku_store/test_rpc_codec.nim | 2 +- tests/waku_store/test_waku_store.nim | 2 +- tests/waku_store/test_wakunode_store.nim | 2 +- tests/waku_store_sync/sync_utils.nim | 2 +- tests/waku_store_sync/test_codec.nim | 10 +++--- tests/waku_store_sync/test_protocol.nim | 2 +- tests/waku_store_sync/test_range_split.nim | 10 +++--- .../waku_store_sync/test_state_transition.nim | 10 +++--- tests/waku_store_sync/test_storage.nim | 6 ++-- tests/wakunode2/test_app.nim | 4 +-- tests/wakunode2/test_cli_args.nim | 10 +++--- tests/wakunode2/test_validators.nim | 3 +- tests/wakunode_rest/test_rest_admin.nim | 2 +- tests/wakunode_rest/test_rest_cors.nim | 2 +- tests/wakunode_rest/test_rest_debug.nim | 2 +- .../wakunode_rest/test_rest_debug_serdes.nim | 4 ++- tests/wakunode_rest/test_rest_filter.nim | 2 +- tests/wakunode_rest/test_rest_health.nim | 2 +- tests/wakunode_rest/test_rest_lightpush.nim | 2 +- .../test_rest_lightpush_legacy.nim | 2 +- tests/wakunode_rest/test_rest_relay.nim | 2 +- .../wakunode_rest/test_rest_relay_serdes.nim | 2 +- tests/wakunode_rest/test_rest_serdes.nim | 4 ++- tests/wakunode_rest/test_rest_store.nim | 2 +- tools/confutils/cli_args.nim | 6 ++-- tools/confutils/entry_nodes.nim | 2 +- .../rln_keystore_generator.nim | 2 +- tools/sync-nimble-lock.sh | 16 ++++----- waku/waku_persistency.nim | 3 -- 527 files changed, 610 insertions(+), 539 deletions(-) rename waku.nim => logos_delivery.nim (73%) rename waku.nimble => logos_delivery.nimble (99%) rename {channels => logos_delivery/channels}/encryption/encryption.nim (100%) rename {channels => logos_delivery/channels}/encryption/noop_encryption.nim (100%) rename {channels => logos_delivery/channels}/events.nim (95%) rename {channels => logos_delivery/channels}/rate_limit_manager/rate_limit_manager.nim (100%) rename {channels => logos_delivery/channels}/reliable_channel.nim (98%) rename {channels => logos_delivery/channels}/reliable_channel_manager.nim (93%) rename {channels => logos_delivery/channels}/scalable_data_sync/scalable_data_sync.nim (100%) rename {channels => logos_delivery/channels}/scalable_data_sync/sds_persistence.nim (100%) rename {channels => logos_delivery/channels}/segmentation/segment_message_proto.nim (100%) rename {channels => logos_delivery/channels}/segmentation/segmentation.nim (100%) rename {channels => logos_delivery/channels}/segmentation/segmentation_persistence.nim (100%) rename {channels => logos_delivery/channels}/types.nim (85%) rename {waku/node => logos_delivery/messaging}/delivery_service/not_delivered_storage/migrations.nim (88%) rename {waku/node => logos_delivery/messaging}/delivery_service/not_delivered_storage/not_delivered_storage.nim (87%) rename {waku/node => logos_delivery/messaging}/delivery_service/recv_service.nim (100%) rename {waku/node => logos_delivery/messaging}/delivery_service/recv_service/recv_service.nim (99%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service.nim (100%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service/delivery_task.nim (94%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service/lightpush_processor.nim (95%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service/relay_processor.nim (93%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service/send_processor.nim (100%) rename {waku/node => logos_delivery/messaging}/delivery_service/send_service/send_service.nim (99%) rename {waku => logos_delivery/messaging}/messaging_client.nim (89%) rename {waku => logos_delivery/waku}/README.md (100%) rename {waku => logos_delivery/waku}/api.nim (100%) rename {waku => logos_delivery/waku}/api/api.nim (81%) rename {waku => logos_delivery/waku}/api/api_conf.nim (98%) rename {waku => logos_delivery/waku}/api/send_api.md (100%) rename {waku => logos_delivery/waku}/api/types.nim (91%) rename {waku => logos_delivery/waku}/common/base64.nim (100%) rename {waku => logos_delivery/waku}/common/callbacks.nim (68%) rename {waku => logos_delivery/waku}/common/databases/common.nim (100%) rename {waku => logos_delivery/waku}/common/databases/db_postgres.nim (100%) rename {waku => logos_delivery/waku}/common/databases/db_postgres/dbconn.nim (100%) rename {waku => logos_delivery/waku}/common/databases/db_postgres/pgasyncpool.nim (100%) rename {waku => logos_delivery/waku}/common/databases/db_postgres/query_metrics.nim (100%) rename {waku => logos_delivery/waku}/common/databases/db_sqlite.nim (100%) rename {waku => logos_delivery/waku}/common/databases/dburl.nim (100%) rename {waku => logos_delivery/waku}/common/enr.nim (100%) rename {waku => logos_delivery/waku}/common/enr/builder.nim (100%) rename {waku => logos_delivery/waku}/common/enr/typed_record.nim (100%) rename {waku => logos_delivery/waku}/common/error_handling.nim (100%) rename {waku => logos_delivery/waku}/common/hexstrings.nim (100%) rename {waku => logos_delivery/waku}/common/logging.nim (100%) rename {waku => logos_delivery/waku}/common/nimchronos.nim (100%) rename {waku => logos_delivery/waku}/common/paging.nim (100%) rename {waku => logos_delivery/waku}/common/protobuf.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/per_peer_limiter.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/request_limiter.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/service_metrics.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/setting.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/single_token_limiter.nim (100%) rename {waku => logos_delivery/waku}/common/rate_limit/timed_map.nim (100%) rename {waku => logos_delivery/waku}/common/utils/DEPRECATION_NOTICE.md (100%) rename {waku => logos_delivery/waku}/common/utils/matterbridge_client.nim (100%) rename {waku => logos_delivery/waku}/common/utils/nat.nim (100%) rename {waku => logos_delivery/waku}/common/utils/parse_size_units.nim (100%) rename {waku => logos_delivery/waku}/common/utils/sequence.nim (100%) rename {waku => logos_delivery/waku}/common/waku_protocol.nim (100%) rename {waku => logos_delivery/waku}/discovery/autonat_service.nim (100%) rename {waku => logos_delivery/waku}/discovery/waku_discv5.nim (99%) rename {waku => logos_delivery/waku}/discovery/waku_dnsdisc.nim (100%) rename {waku => logos_delivery/waku}/discovery/waku_kademlia.nim (99%) rename {waku => logos_delivery/waku}/events/delivery_events.nim (78%) rename {waku => logos_delivery/waku}/events/events.nim (100%) rename {waku => logos_delivery/waku}/events/health_events.nim (82%) rename {waku => logos_delivery/waku}/events/message_events.nim (92%) rename {waku => logos_delivery/waku}/events/peer_events.nim (100%) rename {waku => logos_delivery/waku}/factory/app_callbacks.nim (100%) rename {waku => logos_delivery/waku}/factory/builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/discv5_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/dns_discovery_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/filter_service_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/kademlia_discovery_conf_builder.nim (96%) rename {waku => logos_delivery/waku}/factory/conf_builder/metrics_server_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/mix_conf_builder.nim (96%) rename {waku => logos_delivery/waku}/factory/conf_builder/rate_limit_conf_builder.nim (95%) rename {waku => logos_delivery/waku}/factory/conf_builder/rest_server_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/rln_relay_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/store_service_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/store_sync_conf_builder.nim (100%) rename {waku => logos_delivery/waku}/factory/conf_builder/waku_conf_builder.nim (99%) rename {waku => logos_delivery/waku}/factory/conf_builder/web_socket_conf_builder.nim (97%) rename {waku => logos_delivery/waku}/factory/internal_config.nim (98%) rename {waku => logos_delivery/waku}/factory/networks_config.nim (100%) rename {waku => logos_delivery/waku}/factory/node_factory.nim (100%) rename {waku => logos_delivery/waku}/factory/validator_signed.nim (100%) rename {waku => logos_delivery/waku}/factory/waku.nim (99%) rename {waku => logos_delivery/waku}/factory/waku_conf.nim (100%) rename {waku => logos_delivery/waku}/factory/waku_state_info.nim (97%) rename {waku => logos_delivery/waku}/incentivization/common.nim (84%) rename {waku => logos_delivery/waku}/incentivization/eligibility_manager.nim (97%) rename {waku => logos_delivery/waku}/incentivization/reputation_manager.nim (100%) rename {waku => logos_delivery/waku}/incentivization/rpc.nim (100%) rename {waku => logos_delivery/waku}/incentivization/rpc_codec.nim (100%) rename {waku => logos_delivery/waku}/net/auto_port.nim (100%) rename {waku => logos_delivery/waku}/net/bound_ports.nim (100%) rename {waku => logos_delivery/waku}/net/net_config.nim (100%) rename {waku => logos_delivery/waku}/node/edge_filter_sub_state.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor/connection_status.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor/event_loop_monitor.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor/health_report.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor/health_status.nim (100%) rename {waku => logos_delivery/waku}/node/health_monitor/node_health_monitor.nim (99%) rename {waku => logos_delivery/waku}/node/health_monitor/online_monitor.nim (97%) rename {waku => logos_delivery/waku}/node/health_monitor/protocol_health.nim (96%) rename {waku => logos_delivery/waku}/node/health_monitor/topic_health.nim (92%) rename {waku => logos_delivery/waku}/node/node_telemetry.nim (100%) rename {waku => logos_delivery/waku}/node/peer_manager.nim (100%) rename {waku => logos_delivery/waku}/node/peer_manager/peer_manager.nim (99%) rename {waku => logos_delivery/waku}/node/peer_manager/peer_store/migrations.nim (100%) rename {waku => logos_delivery/waku}/node/peer_manager/peer_store/peer_storage.nim (100%) rename {waku => logos_delivery/waku}/node/peer_manager/peer_store/waku_peer_storage.nim (100%) rename {waku => logos_delivery/waku}/node/peer_manager/waku_peer_store.nim (100%) rename {waku => logos_delivery/waku}/node/shard_subscription.nim (100%) rename {waku => logos_delivery/waku}/node/subscription_manager.nim (99%) rename {waku => logos_delivery/waku}/node/waku_metrics.nim (96%) rename {waku => logos_delivery/waku}/node/waku_node.nim (99%) rename {waku => logos_delivery/waku}/node/waku_node/filter.nim (100%) rename {waku => logos_delivery/waku}/node/waku_node/lightpush.nim (100%) rename {waku => logos_delivery/waku}/node/waku_node/peer_exchange.nim (100%) rename {waku => logos_delivery/waku}/node/waku_node/ping.nim (100%) rename {waku => logos_delivery/waku}/node/waku_node/relay.nim (99%) rename {waku => logos_delivery/waku}/node/waku_node/store.nim (100%) rename {waku => logos_delivery/waku}/node/waku_switch.nim (100%) rename {waku => logos_delivery/waku}/persistency/backend_comm.nim (100%) rename {waku => logos_delivery/waku}/persistency/backend_sqlite.nim (100%) rename {waku => logos_delivery/waku}/persistency/backend_thread.nim (100%) rename {waku => logos_delivery/waku}/persistency/keys.nim (100%) rename {waku => logos_delivery/waku}/persistency/payload.nim (100%) rename {waku => logos_delivery/waku}/persistency/persistency.nim (100%) rename {waku => logos_delivery/waku}/persistency/schema.nim (100%) rename {waku => logos_delivery/waku}/persistency/sds_persistency.nim (100%) rename {waku => logos_delivery/waku}/persistency/types.nim (100%) rename {waku => logos_delivery/waku}/requests/health_requests.nim (87%) rename {waku => logos_delivery/waku}/requests/node_requests.nim (85%) rename {waku => logos_delivery/waku}/requests/requests.nim (100%) rename {waku => logos_delivery/waku}/requests/rln_requests.nim (81%) rename {waku => logos_delivery/waku}/rest_api/endpoint/admin/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/admin/handlers.nim (99%) rename {waku => logos_delivery/waku}/rest_api/endpoint/admin/types.nim (99%) rename {waku => logos_delivery/waku}/rest_api/endpoint/builder.nim (87%) rename {waku => logos_delivery/waku}/rest_api/endpoint/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/debug/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/debug/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/debug/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/filter/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/filter/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/filter/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/health/client.nim (74%) rename {waku => logos_delivery/waku}/rest_api/endpoint/health/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/health/types.nim (97%) rename {waku => logos_delivery/waku}/rest_api/endpoint/legacy_lightpush/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/legacy_lightpush/handlers.nim (96%) rename {waku => logos_delivery/waku}/rest_api/endpoint/legacy_lightpush/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/lightpush/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/lightpush/handlers.nim (97%) rename {waku => logos_delivery/waku}/rest_api/endpoint/lightpush/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/origin_handler.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/relay/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/relay/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/relay/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/responses.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/rest_serdes.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/serdes.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/server.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/store/client.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/store/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/endpoint/store/types.nim (100%) rename {waku => logos_delivery/waku}/rest_api/handlers.nim (100%) rename {waku => logos_delivery/waku}/rest_api/message_cache.nim (100%) rename {waku => logos_delivery/waku}/utils/DEPRECATION_NOTICE.md (100%) rename {waku => logos_delivery/waku}/utils/collector.nim (100%) rename {waku => logos_delivery/waku}/utils/noise.nim (100%) rename {waku => logos_delivery/waku}/utils/requests.nim (100%) rename {waku => logos_delivery/waku}/utils/tableutils.nim (100%) rename {waku => logos_delivery/waku}/waku_archive.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/archive.nim (99%) rename {waku => logos_delivery/waku}/waku_archive/archive_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/common.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/builder.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/postgres_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/postgres_driver/migrations.nim (97%) rename {waku => logos_delivery/waku}/waku_archive/driver/postgres_driver/partitions_manager.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/postgres_driver/postgres_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/postgres_driver/postgres_healthcheck.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/queue_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/queue_driver/index.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/queue_driver/queue_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/sqlite_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/sqlite_driver/migrations.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/sqlite_driver/queries.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/driver/sqlite_driver/sqlite_driver.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/retention_policy.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/retention_policy/builder.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/retention_policy/retention_policy_capacity.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/retention_policy/retention_policy_size.nim (100%) rename {waku => logos_delivery/waku}/waku_archive/retention_policy/retention_policy_time.nim (100%) rename {waku => logos_delivery/waku}/waku_core.nim (100%) rename {waku => logos_delivery/waku}/waku_core/codecs.nim (100%) rename {waku => logos_delivery/waku}/waku_core/message.nim (100%) rename {waku => logos_delivery/waku}/waku_core/message/codec.nim (100%) rename {waku => logos_delivery/waku}/waku_core/message/default_values.nim (100%) rename {waku => logos_delivery/waku}/waku_core/message/digest.nim (100%) rename {waku => logos_delivery/waku}/waku_core/message/message.nim (100%) rename {waku => logos_delivery/waku}/waku_core/multiaddrstr.nim (100%) rename {waku => logos_delivery/waku}/waku_core/peers.nim (100%) rename {waku => logos_delivery/waku}/waku_core/subscription.nim (100%) rename {waku => logos_delivery/waku}/waku_core/subscription/push_handler.nim (100%) rename {waku => logos_delivery/waku}/waku_core/time.nim (100%) rename {waku => logos_delivery/waku}/waku_core/topics.nim (100%) rename {waku => logos_delivery/waku}/waku_core/topics/content_topic.nim (100%) rename {waku => logos_delivery/waku}/waku_core/topics/parsing.nim (100%) rename {waku => logos_delivery/waku}/waku_core/topics/pubsub_topic.nim (100%) rename {waku => logos_delivery/waku}/waku_core/topics/sharding.nim (100%) rename {waku => logos_delivery/waku}/waku_enr.nim (100%) rename {waku => logos_delivery/waku}/waku_enr/capabilities.nim (100%) rename {waku => logos_delivery/waku}/waku_enr/multiaddr.nim (100%) rename {waku => logos_delivery/waku}/waku_enr/sharding.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/client.nim (99%) rename {waku => logos_delivery/waku}/waku_filter_v2/common.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/protocol_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/rpc.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/rpc_codec.nim (100%) rename {waku => logos_delivery/waku}/waku_filter_v2/subscriptions.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore/conversion_utils.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore/keyfile.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore/keystore.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore/protocol_types.nim (100%) rename {waku => logos_delivery/waku}/waku_keystore/utils.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/callbacks.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/client.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/common.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/protocol_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/rpc.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/rpc_codec.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush/self_req_handler.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/README.md (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/callbacks.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/client.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/common.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/protocol_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/rpc.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/rpc_codec.nim (100%) rename {waku => logos_delivery/waku}/waku_lightpush_legacy/self_req_handler.nim (100%) rename {waku => logos_delivery/waku}/waku_metadata.nim (100%) rename {waku => logos_delivery/waku}/waku_metadata/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_metadata/rpc.nim (100%) rename {waku => logos_delivery/waku}/waku_mix.nim (100%) rename {waku => logos_delivery/waku}/waku_mix/protocol.nim (94%) rename {waku => logos_delivery/waku}/waku_node.nim (100%) rename {waku => logos_delivery/waku}/waku_noise/noise.nim (100%) rename {waku => logos_delivery/waku}/waku_noise/noise_handshake_processing.nim (100%) rename {waku => logos_delivery/waku}/waku_noise/noise_types.nim (100%) rename {waku => logos_delivery/waku}/waku_noise/noise_utils.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/README.md (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/client.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/common.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/rpc.nim (100%) rename {waku => logos_delivery/waku}/waku_peer_exchange/rpc_codec.nim (100%) create mode 100644 logos_delivery/waku/waku_persistency.nim rename {waku => logos_delivery/waku}/waku_relay.nim (50%) rename {waku => logos_delivery/waku}/waku_relay/message_id.nim (100%) rename {waku => logos_delivery/waku}/waku_relay/protocol.nim (98%) rename {waku => logos_delivery/waku}/waku_rendezvous.nim (100%) rename {waku => logos_delivery/waku}/waku_rendezvous/client.nim (97%) rename {waku => logos_delivery/waku}/waku_rendezvous/common.nim (100%) rename {waku => logos_delivery/waku}/waku_rendezvous/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_rendezvous/waku_peer_record.nim (100%) rename {waku => logos_delivery/waku}/waku_rest.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/constants.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/contract.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/conversion_utils.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager/group_manager_base.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager/on_chain.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager/on_chain/group_manager.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/nonce_manager.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/protocol_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/protocol_types.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/rln.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/rln/rln_interface.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/rln/wrappers.nim (100%) rename {waku => logos_delivery/waku}/waku_rln_relay/rln_relay.nim (99%) rename {waku => logos_delivery/waku}/waku_store.nim (100%) rename {waku => logos_delivery/waku}/waku_store/client.nim (100%) rename {waku => logos_delivery/waku}/waku_store/common.nim (100%) rename {waku => logos_delivery/waku}/waku_store/protocol.nim (100%) rename {waku => logos_delivery/waku}/waku_store/protocol_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_store/resume.nim (100%) rename {waku => logos_delivery/waku}/waku_store/rpc_codec.nim (100%) rename {waku => logos_delivery/waku}/waku_store/self_req_handler.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/codec.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/common.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/protocols_metrics.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/reconciliation.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/storage/range_processing.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/storage/seq_storage.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/storage/storage.nim (100%) rename {waku => logos_delivery/waku}/waku_store_sync/transfer.nim (100%) delete mode 100644 waku/waku_persistency.nim diff --git a/.github/ISSUE_TEMPLATE/bump_dependencies.md b/.github/ISSUE_TEMPLATE/bump_dependencies.md index 59f46f08b..56f95eb00 100644 --- a/.github/ISSUE_TEMPLATE/bump_dependencies.md +++ b/.github/ISSUE_TEMPLATE/bump_dependencies.md @@ -11,8 +11,8 @@ assignees: '' ### Bumped items - [ ] Update nimble dependencies - 1. Edit manually waku.nimble. For some dependencies, we want to bump versions manually and use a pinned version, f.e., nim-libp2p and all its dependencies. - 2. Run `nimble lock` (make sure `nimble --version` shows the Nimble version pinned in waku.nimble) + 1. Edit manually logos_delivery.nimble. For some dependencies, we want to bump versions manually and use a pinned version, f.e., nim-libp2p and all its dependencies. + 2. Run `nimble lock` (make sure `nimble --version` shows the Nimble version pinned in logos_delivery.nimble) 3. Run `./tools/gen-nix-deps.sh nimble.lock nix/deps.nix` to update nix deps - [ ] Update vendor/zerokit dependency. diff --git a/.github/ISSUE_TEMPLATE/prepare_release.md b/.github/ISSUE_TEMPLATE/prepare_release.md index 3c2e2f729..095e54257 100644 --- a/.github/ISSUE_TEMPLATE/prepare_release.md +++ b/.github/ISSUE_TEMPLATE/prepare_release.md @@ -18,7 +18,7 @@ For detailed info on the release process refer to https://github.com/logos-messa All items below are to be completed by the owner of the given release. - [ ] Create release branch with major and minor only ( e.g. release/v0.X ) if it doesn't exist. -- [ ] Update the `version` field in `waku.nimble` to match the release version (e.g. `version = "0.X.0"`) **and merge it before assigning any tag** - the `release-assets` workflow gates artifact build/upload. +- [ ] Update the `version` field in `logos_delivery.nimble` to match the release version (e.g. `version = "0.X.0"`) **and merge it before assigning any tag** - the `release-assets` workflow gates artifact build/upload. - [ ] Assign release candidate tag to the release branch HEAD (e.g. `v0.X.0-rc.0`, `v0.X.0-rc.1`, ... `v0.X.0-rc.N`). - [ ] Generate and edit release notes in CHANGELOG.md. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67a29fa31..72b385dce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: common: - '.github/workflows/**' - 'nimble.lock' - - 'waku.nimble' + - 'logos_delivery.nimble' - 'Makefile' - 'scripts/**' - 'flake.nix' @@ -42,12 +42,11 @@ jobs: - 'library/**' - 'liblogosdelivery/**' v2: - - 'waku/**' + - 'logos_delivery/**' - 'apps/**' - 'tools/**' - 'tests/all_tests_v2.nim' - 'tests/**' - - 'channels/**' docker: - 'docker/**' @@ -235,5 +234,5 @@ jobs: shopt -s extglob # Enable extended globbing NPH=$(make print-nph-path) echo "using nph at ${NPH}" - "${NPH}" examples waku tests tools apps *.@(nim|nims|nimble) + "${NPH}" examples logos_delivery tests tools apps *.@(nim|nims|nimble) git diff --exit-code diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml index b2066438b..4b0e7dcd2 100644 --- a/.github/workflows/container-image.yml +++ b/.github/workflows/container-image.yml @@ -15,7 +15,7 @@ env: NPROC: 2 MAKEFLAGS: "-j${NPROC}" NIMFLAGS: "--parallelBuild:${NPROC}" - # waku.nimble reads compile flags from NIM_PARAMS, not NIMFLAGS. Without + # logos_delivery.nimble reads compile flags from NIM_PARAMS, not NIMFLAGS. Without # -d:disableMarchNative here, config.nims applies -march=native and # secp256k1 fails to compile. NIM_PARAMS: "-d:disableMarchNative" diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index d3ac05f46..56ff0dc46 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -26,8 +26,8 @@ jobs: - 'apps/chat2bridge/config_chat2bridge.nim' db_schema: - - 'waku/waku_archive/driver/postgres_driver/postgres_driver.nim' - - 'waku/waku_archive/driver/sqlite_driver/queries.nim' + - 'logos_delivery/waku/waku_archive/driver/postgres_driver/postgres_driver.nim' + - 'logos_delivery/waku/waku_archive/driver/sqlite_driver/queries.nim' - name: Comment config change uses: thollander/actions-comment-pull-request@v2 if: ${{steps.filter.outputs.config == 'true'}} diff --git a/.github/workflows/release-assets.yml b/.github/workflows/release-assets.yml index 77862d11b..fb631c975 100644 --- a/.github/workflows/release-assets.yml +++ b/.github/workflows/release-assets.yml @@ -11,7 +11,7 @@ env: NPROC: 2 jobs: - # Release gate: the pushed tag MUST exactly match waku.nimble's version, + # Release gate: the pushed tag MUST exactly match logos_delivery.nimble's version, # so every published artifact reports the correct getNodeInfo Version. # CI cannot reject/remove a tag, so we gate artifact build & upload on # this instead: a mismatched tag yields no released artifacts. @@ -19,24 +19,24 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - name: Assert pushed tag equals waku.nimble version + - name: Assert pushed tag equals logos_delivery.nimble version if: startsWith(github.ref, 'refs/tags/') run: | set -euo pipefail - NIMBLE_VERSION=$(grep -m1 '^version = ' waku.nimble | sed -E 's/version = "([^"]+)"/\1/') + NIMBLE_VERSION=$(grep -m1 '^version = ' logos_delivery.nimble | sed -E 's/version = "([^"]+)"/\1/') # Strip leading v and any prerelease suffix (e.g. v0.38.0-rc.1 -> # 0.38.0) so release-candidate tags build against the same - # waku.nimble version as the final tag. + # logos_delivery.nimble version as the final tag. TAG_VERSION="${GITHUB_REF_NAME#v}" BASE_VERSION="${TAG_VERSION%%-*}" echo "tag: ${GITHUB_REF_NAME} (base ${BASE_VERSION})" - echo "waku.nimble version: ${NIMBLE_VERSION}" + echo "logos_delivery.nimble version: ${NIMBLE_VERSION}" if [ "${BASE_VERSION}" != "${NIMBLE_VERSION}" ]; then echo "::error::Tag ${GITHUB_REF_NAME} (base ${BASE_VERSION}) does not match" - echo "::error::waku.nimble version (${NIMBLE_VERSION}). Bump waku.nimble before tagging." + echo "::error::logos_delivery.nimble version (${NIMBLE_VERSION}). Bump logos_delivery.nimble before tagging." exit 1 fi - echo "OK: tag base matches waku.nimble." + echo "OK: tag base matches logos_delivery.nimble." build-and-upload: needs: verify-version diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml index ee01a9f1a..d412ae138 100644 --- a/.github/workflows/version-check.yml +++ b/.github/workflows/version-check.yml @@ -7,12 +7,12 @@ on: branches: [master] jobs: - # PR check: waku.nimble version must be >= the nearest tag reachable from + # PR check: logos_delivery.nimble version must be >= the nearest tag reachable from # this branch (`git describe --tags --abbrev=0`, i.e. ancestor-aware). # Because we check out the PR HEAD (not the simulated merge ref), a branch # that predates a release tag does not see that tag in its history, so a # newly pushed tag does NOT break in-flight PRs. Once the branch merges/ - # rebases past the tag, the bump is then enforced. This keeps waku.nimble + # rebases past the tag, the bump is then enforced. This keeps logos_delivery.nimble # fixed as early as possible, independent of whether a release is cut. # The exact tag==nimble guarantee at release time lives in # release-assets.yml, which gates artifact publishing on it. @@ -23,10 +23,10 @@ jobs: with: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} - - name: Compare waku.nimble version with nearest ancestor tag + - name: Compare logos_delivery.nimble version with nearest ancestor tag run: | set -euo pipefail - NIMBLE_VERSION=$(grep -m1 '^version = ' waku.nimble | sed -E 's/version = "([^"]+)"/\1/') + NIMBLE_VERSION=$(grep -m1 '^version = ' logos_delivery.nimble | sed -E 's/version = "([^"]+)"/\1/') # Nearest tag reachable from HEAD; --abbrev=0 drops the --g # suffix so we get the bare tag (e.g. v0.38.0). `--match 'v*'` skips # the moving `nightly` tag (auto-updated by the daily CI to point at @@ -36,7 +36,7 @@ jobs: BASE_TAG=${BASE_TAG#v} # Compare on the base version, ignoring any -rc.N prerelease suffix. BASE_TAG=${BASE_TAG%%-*} - echo "waku.nimble version: ${NIMBLE_VERSION}" + echo "logos_delivery.nimble version: ${NIMBLE_VERSION}" echo "ancestor git tag: ${BASE_TAG:-}" if [ -z "${BASE_TAG}" ]; then echo "No ancestor release tag; skipping." @@ -45,8 +45,8 @@ jobs: # lowest of the two by version sort must be the tag => nimble >= tag LOWEST=$(printf '%s\n%s\n' "${NIMBLE_VERSION}" "${BASE_TAG}" | sort -V | head -1) if [ "${LOWEST}" != "${BASE_TAG}" ] && [ "${NIMBLE_VERSION}" != "${BASE_TAG}" ]; then - echo "::error::waku.nimble version (${NIMBLE_VERSION}) is behind its" - echo "::error::ancestor git tag (v${BASE_TAG}). Bump 'version' in waku.nimble." + echo "::error::logos_delivery.nimble version (${NIMBLE_VERSION}) is behind its" + echo "::error::ancestor git tag (v${BASE_TAG}). Bump 'version' in logos_delivery.nimble." exit 1 fi - echo "OK: waku.nimble is not behind its ancestor tag." + echo "OK: logos_delivery.nimble is not behind its ancestor tag." diff --git a/.gitignore b/.gitignore index 0f9751f9b..bfd8f269f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ /tags # a symlink that can't be added to the repo because of Windows +/logos_delivery.nims /waku.nims # Ignore dynamic, static libs and libtool archive files diff --git a/AGENTS.md b/AGENTS.md index ff7d29a39..6deaa4055 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -78,7 +78,7 @@ type WakuFilter* = ref object of LPProtocol ## Development Essentials ### Build Requirements -- Nim 2.x (check `waku.nimble` for minimum version) +- Nim 2.x (check `logos_delivery.nimble` for minimum version) - Rust toolchain (required for RLN dependencies) - Build system: Make driven by Nimble (dependencies pinned in `nimble.lock`) @@ -94,7 +94,7 @@ make wakunode2 make wakunode2 NIMFLAGS="-d:chronicles_log_level=DEBUG" ``` -Note: The build uses `--mm:refc` memory management (passed automatically by the Nimble tasks in `waku.nimble`). Only relevant if compiling outside the standard build system. +Note: The build uses `--mm:refc` memory management (passed automatically by the Nimble tasks in `logos_delivery.nimble`). Only relevant if compiling outside the standard build system. ### Common Make Targets ```bash @@ -476,7 +476,7 @@ nim c -r \ ### Memory Management - Uses `refc` (reference counting with cycle collection) -- Automatically enforced by the build system (hardcoded in `waku.nimble`) +- Automatically enforced by the build system (hardcoded in `logos_delivery.nimble`) - Do not override unless absolutely necessary, as it breaks compatibility ### RLN Dependencies @@ -489,7 +489,7 @@ Language: Nim 2.x | License: MIT or Apache 2.0 ### Important Files - `Makefile` - Primary build interface -- `waku.nimble` - Package definition and build tasks (invoked by the Makefile via Nimble) +- `logos_delivery.nimble` - Package definition and build tasks (invoked by the Makefile via Nimble) - `nimble.lock` - Pinned dependency versions resolved into `nimbledeps/` - `waku/node/waku_node.nim` - Core node implementation - `apps/wakunode2/wakunode2.nim` - Main CLI application @@ -511,7 +511,7 @@ Language: Nim 2.x | License: MIT or Apache 2.0 - `presto` - REST server - `nimcrypto` - Cryptographic primitives -Note: For specific version requirements, check `waku.nimble`. +Note: For specific version requirements, check `logos_delivery.nimble`. # GitNexus — Code Intelligence diff --git a/Makefile b/Makefile index 344743c86..2eabc6017 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,14 @@ export PATH := $(HOME)/.nimble/bin:$(PATH) # NIM binary location NIM_BINARY := $(shell which nim 2>/dev/null) NPH := $(HOME)/.nimble/bin/nph + +NIMBLE := nimble +ifeq ($(detected_OS),Windows) # Resolve nimble via PATH (Windows has no $(HOME)/.nimble/bin); --useSystemNim # reuses the nim on PATH so nimble never re-clones the locked nim. -NIMBLE := nimble --useSystemNim + NIMBLE := nimble --useSystemNim +endif + NIMBLEDEPS_STAMP := nimbledeps/.nimble-setup # Compilation parameters @@ -70,10 +75,10 @@ endif %: @true -waku.nims: - ln -s waku.nimble $@ +logos_delivery.nims: + ln -s logos_delivery.nimble $@ -$(NIMBLEDEPS_STAMP): nimble.lock | install-nimble build-nph waku.nims +$(NIMBLEDEPS_STAMP): nimble.lock | install-nimble build-nph logos_delivery.nims $(NIMBLE) setup --localdeps touch $@ @@ -91,8 +96,8 @@ clean: rm nimble.paths 2> /dev/null || true nimble clean -REQUIRED_NIM_VERSION := $(shell grep -E '^const RequiredNimVersion\s*=' waku.nimble | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"') -REQUIRED_NIMBLE_VERSION := $(shell grep -E '^const RequiredNimbleVersion\s*=' waku.nimble | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"') +REQUIRED_NIM_VERSION := $(shell grep -E '^const RequiredNimVersion\s*=' logos_delivery.nimble | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"') +REQUIRED_NIMBLE_VERSION := $(shell grep -E '^const RequiredNimbleVersion\s*=' logos_delivery.nimble | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"') install-nim: ifneq ($(detected_OS),Windows) @@ -218,7 +223,7 @@ testwaku: | build-deps build rln-deps librln $(NIMBLE) test # Windows: build with nim directly — `nimble ` re-clones git deps every -# build and they intermittently hang on the MSYS2 runner. Flags mirror waku.nimble. +# build and they intermittently hang on the MSYS2 runner. Flags mirror logos_delivery.nimble. wakunode2: | build-deps build deps librln ifeq ($(detected_OS),Windows) echo -e $(BUILD_MSG) "build/$@" && \ @@ -266,7 +271,7 @@ lightpushwithmix: | build-deps build deps librln api_example: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$@" && \ - $(ENV_SCRIPT) nim api_example $(NIM_PARAMS) waku.nims + $(ENV_SCRIPT) nim api_example $(NIM_PARAMS) logos_delivery.nims build/%: | build-deps build deps librln echo -e $(BUILD_MSG) "build/$*" && \ @@ -336,7 +341,7 @@ clean: docs: | build deps echo -e $(BUILD_MSG) "build/$@" && \ - $(NIMBLE) doc --run --index:on --project --out:.gh-pages waku/waku.nim waku.nims + $(NIMBLE) doc --run --index:on --project --out:.gh-pages logos-delivery/logos-delivery.nim logos_delivery.nims coverage: echo -e $(BUILD_MSG) "build/$@" && \ @@ -432,16 +437,16 @@ else ifeq ($(detected_OS),Linux) BUILD_COMMAND := $(BUILD_COMMAND)Linux endif -# Windows: build with nim directly (see wakunode2). Flags mirror waku.nimble. +# Windows: build with nim directly (see wakunode2). Flags mirror logos_delivery.nimble. libwaku: | build-deps librln ifeq ($(detected_OS),Windows) nim c --out:build/libwaku.dll --threads:on --app:lib --opt:speed --noMain --mm:refc --header -d:metrics --nimMainPrefix:libwaku --skipParentCfg:off -d:discv5_protocol_id=d5waku --cpu:amd64 $(NIM_PARAMS) library/libwaku.nim else - $(NIMBLE) --verbose libwaku$(BUILD_COMMAND) waku.nimble + $(NIMBLE) --verbose libwaku$(BUILD_COMMAND) logos_delivery.nimble endif liblogosdelivery: | build-deps librln - $(NIMBLE) --verbose liblogosdelivery$(BUILD_COMMAND) waku.nimble + $(NIMBLE) --verbose liblogosdelivery$(BUILD_COMMAND) logos_delivery.nimble logosdelivery_example: | build liblogosdelivery @echo -e $(BUILD_MSG) "build/$@" @@ -603,4 +608,4 @@ release-notes: -u $(shell id -u) \ docker.io/wakuorg/sv4git:latest \ release-notes |\ - sed -E 's@#([0-9]+)@[#\1](https://github.com/waku-org/nwaku/issues/\1)@g' \ No newline at end of file + sed -E 's@#([0-9]+)@[#\1](https://github.com/logos-messaging/logos-delivery/issues/\1)@g' diff --git a/apps/benchmarks/benchmarks.nim b/apps/benchmarks/benchmarks.nim index 3896cd765..65ad7a525 100644 --- a/apps/benchmarks/benchmarks.nim +++ b/apps/benchmarks/benchmarks.nim @@ -2,7 +2,7 @@ import std/[strutils, times, sequtils, osproc], math, results, options, testutils/unittests import - waku/[ + logos_delivery/waku/[ waku_rln_relay/protocol_types, waku_rln_relay/rln, waku_rln_relay, diff --git a/apps/chat2/chat2.nim b/apps/chat2/chat2.nim index 282e17bfd..a1b101022 100644 --- a/apps/chat2/chat2.nim +++ b/apps/chat2/chat2.nim @@ -31,7 +31,7 @@ import nameresolving/dnsresolver, ] # define DNS resolution import - waku/[ + logos_delivery/waku/[ waku_core, waku_lightpush_legacy/common, waku_lightpush_legacy/rpc, @@ -48,7 +48,7 @@ import ./config_chat2 import libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/pubsub -import ../../waku/waku_rln_relay +import ../../logos_delivery/waku/waku_rln_relay const Help = """ Commands: /[?|help|connect|nick|exit] diff --git a/apps/chat2/config_chat2.nim b/apps/chat2/config_chat2.nim index b0e38c6bc..dfb26eb56 100644 --- a/apps/chat2/config_chat2.nim +++ b/apps/chat2/config_chat2.nim @@ -10,7 +10,7 @@ import nimcrypto/utils, std/strutils, regex -import waku/waku_core +import logos_delivery/waku/waku_core type Fleet* = enum diff --git a/apps/chat2bridge/chat2bridge.nim b/apps/chat2bridge/chat2bridge.nim index eeeea328b..4e8842dab 100644 --- a/apps/chat2bridge/chat2bridge.nim +++ b/apps/chat2bridge/chat2bridge.nim @@ -15,7 +15,7 @@ import # Waku v2 imports libp2p/crypto/crypto, libp2p/errors, - waku/[ + logos_delivery/waku/[ waku_core, waku_node, node/peer_manager, @@ -242,7 +242,8 @@ proc stop*(cmb: Chat2MatterBridge) {.async: (raises: [Exception]).} = {.pop.} # @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError when isMainModule: - import waku/common/utils/nat, waku/rest_api/message_cache + import + logos_delivery/waku/common/utils/nat, logos_delivery/waku/rest_api/message_cache let rng = newRng() diff --git a/apps/chat2mix/chat2mix.nim b/apps/chat2mix/chat2mix.nim index 8b786d7b6..8f48396cf 100644 --- a/apps/chat2mix/chat2mix.nim +++ b/apps/chat2mix/chat2mix.nim @@ -33,7 +33,7 @@ import protocols/mix/mix_protocol, ] # define DNS resolution import - waku/[ + logos_delivery/waku/[ waku_core, waku_lightpush/common, waku_lightpush/rpc, @@ -52,7 +52,7 @@ import ./config_chat2mix import libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/pubsub -import ../../waku/waku_rln_relay +import ../../logos_delivery/waku/waku_rln_relay logScope: topics = "chat2 mix" diff --git a/apps/chat2mix/config_chat2mix.nim b/apps/chat2mix/config_chat2mix.nim index 639e14986..f77a729f4 100644 --- a/apps/chat2mix/config_chat2mix.nim +++ b/apps/chat2mix/config_chat2mix.nim @@ -12,7 +12,7 @@ import confutils/defs, confutils/std/net -import waku/waku_core, waku/waku_mix +import logos_delivery/waku/waku_core, logos_delivery/waku/waku_mix type Fleet* = enum diff --git a/apps/liteprotocoltester/diagnose_connections.nim b/apps/liteprotocoltester/diagnose_connections.nim index d2cc75516..1b5b79b4b 100644 --- a/apps/liteprotocoltester/diagnose_connections.nim +++ b/apps/liteprotocoltester/diagnose_connections.nim @@ -8,14 +8,13 @@ import chronicles, chronos, metrics, - libbacktrace, libp2p/crypto/crypto, confutils, libp2p/wire import tools/confutils/cli_args, - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_lightpush/common, waku_relay, diff --git a/apps/liteprotocoltester/legacy_publisher.nim b/apps/liteprotocoltester/legacy_publisher.nim index 12733ad2d..c2b729b8b 100644 --- a/apps/liteprotocoltester/legacy_publisher.nim +++ b/apps/liteprotocoltester/legacy_publisher.nim @@ -1,5 +1,5 @@ import chronos, results, options -import waku/[waku_node, waku_core] +import logos_delivery/waku/[waku_node, waku_core] import publisher_base type LegacyPublisher* = ref object of PublisherBase diff --git a/apps/liteprotocoltester/liteprotocoltester.nim b/apps/liteprotocoltester/liteprotocoltester.nim index 1877b8477..bcfe2cdec 100644 --- a/apps/liteprotocoltester/liteprotocoltester.nim +++ b/apps/liteprotocoltester/liteprotocoltester.nim @@ -5,14 +5,13 @@ import chronicles, chronos, metrics, - libbacktrace, system/ansi_c, libp2p/crypto/crypto, confutils import tools/confutils/cli_args, - waku/[ + logos_delivery/waku/[ common/enr, common/logging, factory/waku as waku_factory, @@ -156,7 +155,7 @@ when isMainModule: when defined(posix): proc handleSigsegv(signal: cint) {.noconv.} = # Require --debugger:native - fatal "Shutting down after receiving SIGSEGV", stacktrace = getBacktrace() + fatal "Shutting down after receiving SIGSEGV" # Not available in -d:release mode writeStackTrace() diff --git a/apps/liteprotocoltester/publisher.nim b/apps/liteprotocoltester/publisher.nim index 0df3f3e3e..cbd36ce68 100644 --- a/apps/liteprotocoltester/publisher.nim +++ b/apps/liteprotocoltester/publisher.nim @@ -8,7 +8,7 @@ import results, json_serialization as js import - waku/[ + logos_delivery/waku/[ common/logging, waku_node, node/peer_manager, diff --git a/apps/liteprotocoltester/publisher_base.nim b/apps/liteprotocoltester/publisher_base.nim index de88d82f8..aaa85b5f8 100644 --- a/apps/liteprotocoltester/publisher_base.nim +++ b/apps/liteprotocoltester/publisher_base.nim @@ -1,5 +1,5 @@ import chronos, results -import waku/[waku_node, waku_core] +import logos_delivery/waku/[waku_node, waku_core] type PublisherBase* = ref object of RootObj wakuNode*: WakuNode diff --git a/apps/liteprotocoltester/receiver.nim b/apps/liteprotocoltester/receiver.nim index b62094ec6..457626af6 100644 --- a/apps/liteprotocoltester/receiver.nim +++ b/apps/liteprotocoltester/receiver.nim @@ -13,7 +13,7 @@ import json_serialization as js import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_node, diff --git a/apps/liteprotocoltester/service_peer_management.nim b/apps/liteprotocoltester/service_peer_management.nim index d5cfafef1..6198bc448 100644 --- a/apps/liteprotocoltester/service_peer_management.nim +++ b/apps/liteprotocoltester/service_peer_management.nim @@ -5,14 +5,13 @@ import chronicles, chronos, metrics, - libbacktrace, libp2p/crypto/crypto, confutils, libp2p/wire import tools/confutils/cli_args, - waku/[ + logos_delivery/waku/[ common/enr, waku_node, node/peer_manager, diff --git a/apps/liteprotocoltester/tester_config.nim b/apps/liteprotocoltester/tester_config.nim index 1f4bedaa8..79fc6bf1d 100644 --- a/apps/liteprotocoltester/tester_config.nim +++ b/apps/liteprotocoltester/tester_config.nim @@ -14,7 +14,7 @@ import import ../../tools/confutils/ [cli_args, envvar as confEnvvarDefs, envvar_net as confEnvvarNet], - waku/[common/logging, waku_core, waku_core/topics/pubsub_topic] + logos_delivery/waku/[common/logging, waku_core, waku_core/topics/pubsub_topic] export confTomlDefs, confTomlNet, confEnvvarDefs, confEnvvarNet diff --git a/apps/liteprotocoltester/tester_message.nim b/apps/liteprotocoltester/tester_message.nim index 38028e4a7..1a169db04 100644 --- a/apps/liteprotocoltester/tester_message.nim +++ b/apps/liteprotocoltester/tester_message.nim @@ -6,7 +6,7 @@ import json_serialization/std/options, json_serialization/lexer -import waku/rest_api/endpoint/serdes +import logos_delivery/waku/rest_api/endpoint/serdes type ProtocolTesterMessage* = object sender*: string diff --git a/apps/liteprotocoltester/v3_publisher.nim b/apps/liteprotocoltester/v3_publisher.nim index c8353b5a3..bdfea75ec 100644 --- a/apps/liteprotocoltester/v3_publisher.nim +++ b/apps/liteprotocoltester/v3_publisher.nim @@ -1,5 +1,5 @@ import results, options, chronos -import waku/[waku_node, waku_core, waku_lightpush, waku_lightpush/common] +import logos_delivery/waku/[waku_node, waku_core, waku_lightpush, waku_lightpush/common] import publisher_base type V3Publisher* = ref object of PublisherBase diff --git a/apps/networkmonitor/networkmonitor.nim b/apps/networkmonitor/networkmonitor.nim index 23607b118..61bb8d07a 100644 --- a/apps/networkmonitor/networkmonitor.nim +++ b/apps/networkmonitor/networkmonitor.nim @@ -17,7 +17,7 @@ import metrics/chronos_httpserver, presto/[route, server, client] import - waku/[ + logos_delivery/waku/[ waku_core, node/peer_manager, waku_node, diff --git a/apps/wakucanary/wakucanary.nim b/apps/wakucanary/wakucanary.nim index f9023c45c..7d5581d8e 100644 --- a/apps/wakucanary/wakucanary.nim +++ b/apps/wakucanary/wakucanary.nim @@ -12,10 +12,11 @@ import libp2p/multicodec import ./certsgenerator, - waku/[waku_enr, node/peer_manager, waku_core, waku_node, factory/builder], - waku/net/net_config, - waku/waku_metadata/protocol, - waku/common/callbacks + logos_delivery/waku/ + [waku_enr, node/peer_manager, waku_core, waku_node, factory/builder], + logos_delivery/waku/net/net_config, + logos_delivery/waku/waku_metadata/protocol, + logos_delivery/waku/common/callbacks # protocols and their tag const ProtocolsTable = { diff --git a/apps/wakunode2/wakunode2.nim b/apps/wakunode2/wakunode2.nim index be3a83f57..e61b76e9c 100644 --- a/apps/wakunode2/wakunode2.nim +++ b/apps/wakunode2/wakunode2.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto import ../../tools/[rln_keystore_generator/rln_keystore_generator, confutils/cli_args], - waku/[ + logos_delivery/waku/[ common/logging, factory/waku, node/health_monitor, diff --git a/ci/Jenkinsfile.prs b/ci/Jenkinsfile.prs index 2aa56543c..f37a8c6b4 100644 --- a/ci/Jenkinsfile.prs +++ b/ci/Jenkinsfile.prs @@ -124,13 +124,13 @@ def versionWasChanged(version) { script: "git diff --name-only origin/${env.CHANGE_TARGET}", returnStdout: true ) - if (changes =~ "(?m)^(Makefile|waku.nimble|config.nims|vendor|ci|shell.nix).*") { + if (changes =~ "(?m)^(Makefile|logos_delivery.nimble|config.nims|vendor|ci|shell.nix).*") { return true } if (version == 'v2' && changes =~ "(?m)^(apps|tools)/.*") { return true } - if (changes =~ "(?m)^(waku|tests|examples)/(${version}|common)/.*") { + if (changes =~ "(?m)^(logos_delivery|tests|examples)/(${version}|common)/.*") { return true } return false diff --git a/examples/api_example/api_example.nim b/examples/api_example/api_example.nim index 207e83429..9e96858db 100644 --- a/examples/api_example/api_example.nim +++ b/examples/api_example/api_example.nim @@ -1,6 +1,6 @@ import std/options import chronos, results, confutils, confutils/defs -import waku +import logos_delivery type CliArgs = object ethRpcEndpoint* {. diff --git a/examples/filter_subscriber.nim b/examples/filter_subscriber.nim index 03a5de4eb..5fa47d976 100644 --- a/examples/filter_subscriber.nim +++ b/examples/filter_subscriber.nim @@ -9,7 +9,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_core, diff --git a/examples/lightpush_mix/lightpush_publisher_mix.nim b/examples/lightpush_mix/lightpush_publisher_mix.nim index 104de8552..ae022e226 100644 --- a/examples/lightpush_mix/lightpush_publisher_mix.nim +++ b/examples/lightpush_mix/lightpush_publisher_mix.nim @@ -16,7 +16,7 @@ import metrics/chronos_httpserver import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_core, diff --git a/examples/lightpush_mix/lightpush_publisher_mix_config.nim b/examples/lightpush_mix/lightpush_publisher_mix_config.nim index b541dcd8c..100364415 100644 --- a/examples/lightpush_mix/lightpush_publisher_mix_config.nim +++ b/examples/lightpush_mix/lightpush_publisher_mix_config.nim @@ -5,7 +5,7 @@ import libp2p/multicodec, nimcrypto/utils as ncrutils -import waku/waku_mix +import logos_delivery/waku/waku_mix type LightPushMixConf* = object destPeerAddr* {.desc: "Destination peer address with peerId.", name: "dp-addr".}: diff --git a/examples/lightpush_publisher.nim b/examples/lightpush_publisher.nim index c7eacdd30..fe4134072 100644 --- a/examples/lightpush_publisher.nim +++ b/examples/lightpush_publisher.nim @@ -10,7 +10,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_core, diff --git a/examples/publisher.nim b/examples/publisher.nim index 6f5d34bc4..edae12157 100644 --- a/examples/publisher.nim +++ b/examples/publisher.nim @@ -9,7 +9,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_core, diff --git a/examples/subscriber.nim b/examples/subscriber.nim index ce64bb803..541d3ddec 100644 --- a/examples/subscriber.nim +++ b/examples/subscriber.nim @@ -9,7 +9,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ common/logging, node/peer_manager, waku_core, diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index 7751878ca..8eb11595c 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -1,18 +1,17 @@ {.push raises: [].} import tools/confutils/cli_args -import waku/[common/logging, factory/[waku, networks_config]] +import logos_delivery/waku/[common/logging, factory/[waku, networks_config]] import std/[options, strutils, os, sequtils], chronicles, chronos, metrics, - libbacktrace, libp2p/crypto/crypto export networks_config, waku, logging, options, strutils, os, sequtils, stewNet, chronicles, - chronos, metrics, libbacktrace, crypto + chronos, metrics, crypto proc setup*(): Waku = const versionString = "version / git commit hash: " & waku.git_version diff --git a/examples/wakustealthcommitments/stealth_commitment_protocol.nim b/examples/wakustealthcommitments/stealth_commitment_protocol.nim index 63311bf7b..653cfe4b1 100644 --- a/examples/wakustealthcommitments/stealth_commitment_protocol.nim +++ b/examples/wakustealthcommitments/stealth_commitment_protocol.nim @@ -2,7 +2,7 @@ import results, - waku/[common/logging, waku_node, waku_rln_relay], + logos_delivery/waku/[common/logging, waku_node, waku_rln_relay], ./erc_5564_interface as StealthCommitmentFFI, ./node_spec, ./wire_spec diff --git a/examples/wakustealthcommitments/wire_spec.nim b/examples/wakustealthcommitments/wire_spec.nim index fa3d5a888..cd32d24a8 100644 --- a/examples/wakustealthcommitments/wire_spec.nim +++ b/examples/wakustealthcommitments/wire_spec.nim @@ -1,7 +1,7 @@ import std/[times, options] import confutils, chronicles, chronos, results -import waku/[waku_core, common/protobuf] +import logos_delivery/waku/[waku_core, common/protobuf] import libp2p/protobuf/minprotobuf export diff --git a/flake.nix b/flake.nix index b32a53455..67f516359 100644 --- a/flake.nix +++ b/flake.nix @@ -32,11 +32,11 @@ lib = nixpkgs.lib; # Single source of truth for the semver: the `version` field of - # waku.nimble. Kept in sync with git tags by the version-check CI. + # logos_delivery.nimble. Kept in sync with git tags by the version-check CI. nimbleVersion = let line = lib.findFirst (l: lib.hasPrefix "version = " l) "version = \"unknown\"" - (lib.splitString "\n" (builtins.readFile ./waku.nimble)); + (lib.splitString "\n" (builtins.readFile ./logos_delivery.nimble)); in lib.removeSuffix "\"" (lib.removePrefix "version = \"" line); # A flake sandbox has no .git, so `git describe` is impossible; the diff --git a/liblogosdelivery/declare_lib.nim b/liblogosdelivery/declare_lib.nim index 5087a0dee..77e992eea 100644 --- a/liblogosdelivery/declare_lib.nim +++ b/liblogosdelivery/declare_lib.nim @@ -1,6 +1,6 @@ import ffi import std/locks -import waku/factory/waku +import logos_delivery/waku/factory/waku declareLibrary("logosdelivery") diff --git a/liblogosdelivery/liblogosdelivery.nim b/liblogosdelivery/liblogosdelivery.nim index fc907498a..001f793a7 100644 --- a/liblogosdelivery/liblogosdelivery.nim +++ b/liblogosdelivery/liblogosdelivery.nim @@ -1,6 +1,7 @@ import std/[atomics, options] import chronicles, chronos, chronos/threadsync, ffi -import waku/factory/waku, waku/node/waku_node, ./declare_lib +import + logos_delivery/waku/factory/waku, logos_delivery/waku/node/waku_node, ./declare_lib ################################################################################ ## Include different APIs, i.e. all procs with {.ffi.} pragma diff --git a/liblogosdelivery/logos_delivery_api/debug_api.nim b/liblogosdelivery/logos_delivery_api/debug_api.nim index bb66a0e3f..e93467d84 100644 --- a/liblogosdelivery/logos_delivery_api/debug_api.nim +++ b/liblogosdelivery/logos_delivery_api/debug_api.nim @@ -1,5 +1,5 @@ import std/[json, strutils] -import waku/factory/waku_state_info +import logos_delivery/waku/factory/waku_state_info import tools/confutils/[cli_args, config_option_meta] proc logosdelivery_get_available_node_info_ids( diff --git a/liblogosdelivery/logos_delivery_api/messaging_api.nim b/liblogosdelivery/logos_delivery_api/messaging_api.nim index cb2771034..ff7c7f6d0 100644 --- a/liblogosdelivery/logos_delivery_api/messaging_api.nim +++ b/liblogosdelivery/logos_delivery_api/messaging_api.nim @@ -2,10 +2,10 @@ import std/[json] import chronos, results, ffi import stew/byteutils import - waku/common/base64, - waku/factory/waku, - waku/waku_core/topics/content_topic, - waku/api/[api, types], + logos_delivery/waku/common/base64, + logos_delivery/waku/factory/waku, + logos_delivery/waku/waku_core/topics/content_topic, + logos_delivery/waku/api/[api, types], ../declare_lib proc logosdelivery_subscribe( diff --git a/liblogosdelivery/logos_delivery_api/node_api.nim b/liblogosdelivery/logos_delivery_api/node_api.nim index 042bdb3a8..de6f69c19 100644 --- a/liblogosdelivery/logos_delivery_api/node_api.nim +++ b/liblogosdelivery/logos_delivery_api/node_api.nim @@ -1,10 +1,10 @@ import std/[json, strutils, tables] import chronos, chronicles, results, confutils, confutils/std/net, ffi import - waku/factory/waku, - waku/node/waku_node, - waku/api/[api, types], - waku/events/[message_events, health_events], + logos_delivery/waku/factory/waku, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/api/[api, types], + logos_delivery/waku/events/[message_events, health_events], tools/confutils/cli_args, ../declare_lib, ../json_event diff --git a/library/declare_lib.nim b/library/declare_lib.nim index 188de8549..ab75ac6b6 100644 --- a/library/declare_lib.nim +++ b/library/declare_lib.nim @@ -1,5 +1,5 @@ import ffi -import waku/factory/waku +import logos_delivery/waku/factory/waku declareLibrary("waku") diff --git a/library/events/json_connection_change_event.nim b/library/events/json_connection_change_event.nim index ff2823640..f78dcbe59 100644 --- a/library/events/json_connection_change_event.nim +++ b/library/events/json_connection_change_event.nim @@ -1,6 +1,6 @@ import system, std/json, libp2p/[connmanager, peerid] -import ../../waku/common/base64, ./json_base_event +import ../../logos_delivery/waku/common/base64, ./json_base_event type JsonConnectionChangeEvent* = ref object of JsonEvent peerId*: string diff --git a/library/events/json_connection_status_change_event.nim b/library/events/json_connection_status_change_event.nim index 86bfda780..9b8a0f9e6 100644 --- a/library/events/json_connection_status_change_event.nim +++ b/library/events/json_connection_status_change_event.nim @@ -2,7 +2,7 @@ import system, std/json import ./json_base_event -import ../../waku/api/types +import ../../logos_delivery/waku/api/types type JsonConnectionStatusChangeEvent* = ref object of JsonEvent status*: ConnectionStatus diff --git a/library/events/json_message_event.nim b/library/events/json_message_event.nim index f79fef86f..61278b4fa 100644 --- a/library/events/json_message_event.nim +++ b/library/events/json_message_event.nim @@ -1,9 +1,9 @@ import system, results, std/json, std/strutils import stew/byteutils import - ../../waku/common/base64, - ../../waku/waku_core/message, - ../../waku/waku_core/message/message, + ../../logos_delivery/waku/common/base64, + ../../logos_delivery/waku/waku_core/message, + ../../logos_delivery/waku/waku_core/message/message, ../utils, ./json_base_event diff --git a/library/events/json_topic_health_change_event.nim b/library/events/json_topic_health_change_event.nim index c194e890c..810e89b2e 100644 --- a/library/events/json_topic_health_change_event.nim +++ b/library/events/json_topic_health_change_event.nim @@ -1,7 +1,7 @@ import system, results, std/json import stew/byteutils -import ../../waku/common/base64, ./json_base_event -import ../../waku/waku_relay +import ../../logos_delivery/waku/common/base64, ./json_base_event +import ../../logos_delivery/waku/waku_relay type JsonTopicHealthChangeEvent* = ref object of JsonEvent pubsubTopic*: string diff --git a/library/kernel_api/debug_node_api.nim b/library/kernel_api/debug_node_api.nim index 9d5a7f134..bbce84939 100644 --- a/library/kernel_api/debug_node_api.nim +++ b/library/kernel_api/debug_node_api.nim @@ -9,7 +9,10 @@ import metrics, ffi import - waku/factory/waku, waku/node/waku_node, waku/node/health_monitor, library/declare_lib + logos_delivery/waku/factory/waku, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/node/health_monitor, + library/declare_lib proc getMultiaddresses(node: WakuNode): seq[string] = return node.info().listenAddresses diff --git a/library/kernel_api/discovery_api.nim b/library/kernel_api/discovery_api.nim index 882c91686..847e21efb 100644 --- a/library/kernel_api/discovery_api.nim +++ b/library/kernel_api/discovery_api.nim @@ -1,11 +1,11 @@ import std/json import chronos, chronicles, results, strutils, libp2p/multiaddress, ffi import - waku/factory/waku, - waku/discovery/waku_dnsdisc, - waku/discovery/waku_discv5, - waku/waku_core/peers, - waku/waku_node, + logos_delivery/waku/factory/waku, + logos_delivery/waku/discovery/waku_dnsdisc, + logos_delivery/waku/discovery/waku_discv5, + logos_delivery/waku/waku_core/peers, + logos_delivery/waku/waku_node, library/declare_lib proc retrieveBootstrapNodes( diff --git a/library/kernel_api/node_lifecycle_api.nim b/library/kernel_api/node_lifecycle_api.nim index 55dd7cd55..45de64c5b 100644 --- a/library/kernel_api/node_lifecycle_api.nim +++ b/library/kernel_api/node_lifecycle_api.nim @@ -2,12 +2,12 @@ import std/[options, json, strutils, net] import chronos, chronicles, results, confutils, confutils/std/net, ffi import - waku/node/peer_manager/peer_manager, + logos_delivery/waku/node/peer_manager/peer_manager, tools/confutils/cli_args, - waku/factory/waku, - waku/factory/node_factory, - waku/factory/app_callbacks, - waku/rest_api/endpoint/builder, + logos_delivery/waku/factory/waku, + logos_delivery/waku/factory/node_factory, + logos_delivery/waku/factory/app_callbacks, + logos_delivery/waku/rest_api/endpoint/builder, library/declare_lib proc createWaku( diff --git a/library/kernel_api/peer_manager_api.nim b/library/kernel_api/peer_manager_api.nim index f0ae37f00..a7dfe0a70 100644 --- a/library/kernel_api/peer_manager_api.nim +++ b/library/kernel_api/peer_manager_api.nim @@ -1,6 +1,10 @@ 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 +import + logos_delivery/waku/factory/waku, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/node/peer_manager, + ../declare_lib type PeerInfo = object protocols: seq[string] diff --git a/library/kernel_api/ping_api.nim b/library/kernel_api/ping_api.nim index 4f10dcf59..da830bc5d 100644 --- a/library/kernel_api/ping_api.nim +++ b/library/kernel_api/ping_api.nim @@ -1,7 +1,9 @@ import std/[json, strutils] import chronos, results, ffi import libp2p/[protocols/ping, switch, multiaddress, multicodec] -import waku/[factory/waku, waku_core/peers, node/waku_node], library/declare_lib +import + logos_delivery/waku/[factory/waku, waku_core/peers, node/waku_node], + library/declare_lib proc waku_ping_peer( ctx: ptr FFIContext[Waku], diff --git a/library/kernel_api/protocols/filter_api.nim b/library/kernel_api/protocols/filter_api.nim index 866b70ca2..ac1f372be 100644 --- a/library/kernel_api/protocols/filter_api.nim +++ b/library/kernel_api/protocols/filter_api.nim @@ -1,16 +1,16 @@ import options, std/[strutils, sequtils] import chronicles, chronos, results, ffi import - waku/waku_filter_v2/client, - waku/waku_core/message/message, - waku/factory/waku, - waku/waku_relay, - waku/waku_filter_v2/common, - waku/waku_core/subscription/push_handler, - waku/node/peer_manager/peer_manager, - waku/waku_node, - waku/waku_core/topics/pubsub_topic, - waku/waku_core/topics/content_topic, + logos_delivery/waku/waku_filter_v2/client, + logos_delivery/waku/waku_core/message/message, + logos_delivery/waku/factory/waku, + logos_delivery/waku/waku_relay, + logos_delivery/waku/waku_filter_v2/common, + logos_delivery/waku/waku_core/subscription/push_handler, + logos_delivery/waku/node/peer_manager/peer_manager, + logos_delivery/waku/waku_node, + logos_delivery/waku/waku_core/topics/pubsub_topic, + logos_delivery/waku/waku_core/topics/content_topic, library/events/json_message_event, library/declare_lib diff --git a/library/kernel_api/protocols/lightpush_api.nim b/library/kernel_api/protocols/lightpush_api.nim index e9251a3f3..da32ab7b2 100644 --- a/library/kernel_api/protocols/lightpush_api.nim +++ b/library/kernel_api/protocols/lightpush_api.nim @@ -1,13 +1,13 @@ import options, std/[json, strformat] import chronicles, chronos, results, ffi import - waku/waku_core/message/message, - waku/waku_core/codecs, - waku/factory/waku, - waku/waku_core/message, - waku/waku_core/topics/pubsub_topic, - waku/waku_lightpush_legacy/client, - waku/node/peer_manager/peer_manager, + logos_delivery/waku/waku_core/message/message, + logos_delivery/waku/waku_core/codecs, + logos_delivery/waku/factory/waku, + logos_delivery/waku/waku_core/message, + logos_delivery/waku/waku_core/topics/pubsub_topic, + logos_delivery/waku/waku_lightpush_legacy/client, + logos_delivery/waku/node/peer_manager/peer_manager, library/events/json_message_event, library/declare_lib diff --git a/library/kernel_api/protocols/relay_api.nim b/library/kernel_api/protocols/relay_api.nim index 4364a4170..739856104 100644 --- a/library/kernel_api/protocols/relay_api.nim +++ b/library/kernel_api/protocols/relay_api.nim @@ -1,15 +1,15 @@ import std/[net, sequtils, strutils, json], strformat import chronicles, chronos, stew/byteutils, results, ffi import - waku/waku_core/message/message, - waku/factory/[validator_signed, waku], + logos_delivery/waku/waku_core/message/message, + logos_delivery/waku/factory/[validator_signed, waku], tools/confutils/cli_args, - waku/waku_core/message, - waku/waku_core/topics/pubsub_topic, - waku/waku_core/topics, - waku/node/waku_node/relay, - waku/waku_relay/protocol, - waku/node/peer_manager, + logos_delivery/waku/waku_core/message, + logos_delivery/waku/waku_core/topics/pubsub_topic, + logos_delivery/waku/waku_core/topics, + logos_delivery/waku/node/waku_node/relay, + logos_delivery/waku/waku_relay/protocol, + logos_delivery/waku/node/peer_manager, library/events/json_message_event, library/declare_lib diff --git a/library/kernel_api/protocols/store_api.nim b/library/kernel_api/protocols/store_api.nim index 0df4d9b1f..c66b64839 100644 --- a/library/kernel_api/protocols/store_api.nim +++ b/library/kernel_api/protocols/store_api.nim @@ -1,13 +1,13 @@ import std/[json, sugar, strutils, options] import chronos, chronicles, results, stew/byteutils, ffi import - waku/factory/waku, + logos_delivery/waku/factory/waku, library/utils, - waku/waku_core/peers, - waku/waku_core/message/digest, - waku/waku_store/common, - waku/waku_store/client, - waku/common/paging, + logos_delivery/waku/waku_core/peers, + logos_delivery/waku/waku_core/message/digest, + logos_delivery/waku/waku_store/common, + logos_delivery/waku/waku_store/client, + logos_delivery/waku/common/paging, library/declare_lib func fromJsonNode(jsonContent: JsonNode): Result[StoreQueryRequest, string] = diff --git a/library/libwaku.nim b/library/libwaku.nim index dd1ee9fd9..ab7fb5bdf 100644 --- a/library/libwaku.nim +++ b/library/libwaku.nim @@ -1,17 +1,17 @@ import std/[atomics, options, atomics, macros] import chronicles, chronos, chronos/threadsync, ffi import - waku/waku_core/message/message, - waku/waku_core/topics/pubsub_topic, - waku/waku_relay, + logos_delivery/waku/waku_core/message/message, + logos_delivery/waku/waku_core/topics/pubsub_topic, + logos_delivery/waku/waku_relay, ./events/json_message_event, ./events/json_topic_health_change_event, ./events/json_connection_change_event, ./events/json_connection_status_change_event, - ../waku/factory/app_callbacks, - waku/factory/waku, - waku/node/waku_node, - waku/node/health_monitor/health_status, + ../logos_delivery/waku/factory/app_callbacks, + logos_delivery/waku/factory/waku, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/node/health_monitor/health_status, ./declare_lib ################################################################################ diff --git a/waku.nim b/logos_delivery.nim similarity index 73% rename from waku.nim rename to logos_delivery.nim index 65a017c5a..c4edbe6d6 100644 --- a/waku.nim +++ b/logos_delivery.nim @@ -3,8 +3,8 @@ ## This module re-exports the public API for creating and managing Waku nodes ## when using nwaku as a library dependency. -import waku/api +import logos_delivery/waku/api export api -import waku/factory/waku +import logos_delivery/waku/factory/waku export waku diff --git a/waku.nimble b/logos_delivery.nimble similarity index 99% rename from waku.nimble rename to logos_delivery.nimble index 38548b5dc..db83d5690 100644 --- a/waku.nimble +++ b/logos_delivery.nimble @@ -6,8 +6,9 @@ mode = ScriptMode.Verbose ### Package version = "0.38.1" author = "Status Research & Development GmbH" -description = "Waku, Private P2P Messaging for Resource-Restricted Devices" +description = "Logos-delivery, Private P2P Messaging for Resource-Restricted Devices" license = "MIT or Apache License 2.0" +skipDirs = @["tests", "examples", "tools", "apps", "simulations", "metrics"] const RequiredNimVersion = "2.2.4" ## This is the nim compiler version that we are working on. Other versions may behave differently. diff --git a/channels/encryption/encryption.nim b/logos_delivery/channels/encryption/encryption.nim similarity index 100% rename from channels/encryption/encryption.nim rename to logos_delivery/channels/encryption/encryption.nim diff --git a/channels/encryption/noop_encryption.nim b/logos_delivery/channels/encryption/noop_encryption.nim similarity index 100% rename from channels/encryption/noop_encryption.nim rename to logos_delivery/channels/encryption/noop_encryption.nim diff --git a/channels/events.nim b/logos_delivery/channels/events.nim similarity index 95% rename from channels/events.nim rename to logos_delivery/channels/events.nim index 3e271976e..5f69095e4 100644 --- a/channels/events.nim +++ b/logos_delivery/channels/events.nim @@ -9,7 +9,7 @@ ## no analogue in the lower layer (reassembled application payload, ## senderId, channelId), so it lives here. -import waku/events/message_events as waku_message_events +import logos_delivery/waku/events/message_events as waku_message_events import brokers/event_broker import ./types as channel_types diff --git a/channels/rate_limit_manager/rate_limit_manager.nim b/logos_delivery/channels/rate_limit_manager/rate_limit_manager.nim similarity index 100% rename from channels/rate_limit_manager/rate_limit_manager.nim rename to logos_delivery/channels/rate_limit_manager/rate_limit_manager.nim diff --git a/channels/reliable_channel.nim b/logos_delivery/channels/reliable_channel.nim similarity index 98% rename from channels/reliable_channel.nim rename to logos_delivery/channels/reliable_channel.nim index 6aa7086e5..4f4851aca 100644 --- a/channels/reliable_channel.nim +++ b/logos_delivery/channels/reliable_channel.nim @@ -20,9 +20,9 @@ import bearssl/rand import stew/byteutils import libp2p/crypto/crypto as libp2p_crypto -import waku/api/types -import waku/node/delivery_service/send_service -import waku/waku_core/topics +import logos_delivery/waku/api/types +import logos_delivery/messaging/delivery_service/send_service +import logos_delivery/waku/waku_core/topics import ./events import ./segmentation/segmentation @@ -277,7 +277,9 @@ proc onReadyToSend( MessageErrorEvent.emit( self.brokerCtx, MessageErrorEvent( - requestId: channelReqId, messageHash: "", error: "messaging send failed: " & error + requestId: channelReqId, + messageHash: "", + error: "messaging send failed: " & error, ), ) self.markSegmentFailed(channelReqId) diff --git a/channels/reliable_channel_manager.nim b/logos_delivery/channels/reliable_channel_manager.nim similarity index 93% rename from channels/reliable_channel_manager.nim rename to logos_delivery/channels/reliable_channel_manager.nim index 68ae82388..a21dfc54e 100644 --- a/channels/reliable_channel_manager.nim +++ b/logos_delivery/channels/reliable_channel_manager.nim @@ -12,9 +12,9 @@ import stew/byteutils import brokers/broker_context -import waku/events/message_events as waku_message_events -import waku/messaging_client -import waku/waku_core/topics +import logos_delivery/waku/events/message_events as waku_message_events +import logos_delivery/messaging/messaging_client +import logos_delivery/waku/waku_core/topics import ./reliable_channel import ./encryption/noop_encryption @@ -23,8 +23,7 @@ export reliable_channel type ReliableChannelManager* = ref object channels: Table[ChannelId, ReliableChannel] - messagingClient: MessagingClient - ## Borrowed from the owning `Waku`. + messagingClient: MessagingClient ## Borrowed from the owning `Waku`. sendHandler: SendHandler ## Default egress dispatch for channels created through this manager. ## Constructed at mount time as a closure over `MessagingClient.send` @@ -97,11 +96,7 @@ proc createReliableChannel*( epochPeriodSec: DefaultEpochPeriodSec, messagesPerEpoch: DefaultMessagesPerEpoch ) - let effectiveSendHandler = - if sendHandler.isNil(): - self.sendHandler - else: - sendHandler + let effectiveSendHandler = if sendHandler.isNil(): self.sendHandler else: sendHandler let chn = ReliableChannel.new( sendHandler = effectiveSendHandler, diff --git a/channels/scalable_data_sync/scalable_data_sync.nim b/logos_delivery/channels/scalable_data_sync/scalable_data_sync.nim similarity index 100% rename from channels/scalable_data_sync/scalable_data_sync.nim rename to logos_delivery/channels/scalable_data_sync/scalable_data_sync.nim diff --git a/channels/scalable_data_sync/sds_persistence.nim b/logos_delivery/channels/scalable_data_sync/sds_persistence.nim similarity index 100% rename from channels/scalable_data_sync/sds_persistence.nim rename to logos_delivery/channels/scalable_data_sync/sds_persistence.nim diff --git a/channels/segmentation/segment_message_proto.nim b/logos_delivery/channels/segmentation/segment_message_proto.nim similarity index 100% rename from channels/segmentation/segment_message_proto.nim rename to logos_delivery/channels/segmentation/segment_message_proto.nim diff --git a/channels/segmentation/segmentation.nim b/logos_delivery/channels/segmentation/segmentation.nim similarity index 100% rename from channels/segmentation/segmentation.nim rename to logos_delivery/channels/segmentation/segmentation.nim diff --git a/channels/segmentation/segmentation_persistence.nim b/logos_delivery/channels/segmentation/segmentation_persistence.nim similarity index 100% rename from channels/segmentation/segmentation_persistence.nim rename to logos_delivery/channels/segmentation/segmentation_persistence.nim diff --git a/channels/types.nim b/logos_delivery/channels/types.nim similarity index 85% rename from channels/types.nim rename to logos_delivery/channels/types.nim index 4070ed620..ec663cf7b 100644 --- a/channels/types.nim +++ b/logos_delivery/channels/types.nim @@ -1,7 +1,7 @@ ## Core identifier types for the Reliable Channel API. import std/hashes -import waku/api/types as api_types +import logos_delivery/waku/api/types as api_types import ./scalable_data_sync/scalable_data_sync diff --git a/waku/node/delivery_service/not_delivered_storage/migrations.nim b/logos_delivery/messaging/delivery_service/not_delivered_storage/migrations.nim similarity index 88% rename from waku/node/delivery_service/not_delivered_storage/migrations.nim rename to logos_delivery/messaging/delivery_service/not_delivered_storage/migrations.nim index 807074d64..da636dbcb 100644 --- a/waku/node/delivery_service/not_delivered_storage/migrations.nim +++ b/logos_delivery/messaging/delivery_service/not_delivered_storage/migrations.nim @@ -1,7 +1,9 @@ {.push raises: [].} import std/[tables, strutils, os], results, chronicles -import ../../../common/databases/db_sqlite, ../../../common/databases/common +import + logos_delivery/waku/common/databases/db_sqlite, + logos_delivery/waku/common/databases/common logScope: topics = "waku node delivery_service" diff --git a/waku/node/delivery_service/not_delivered_storage/not_delivered_storage.nim b/logos_delivery/messaging/delivery_service/not_delivered_storage/not_delivered_storage.nim similarity index 87% rename from waku/node/delivery_service/not_delivered_storage/not_delivered_storage.nim rename to logos_delivery/messaging/delivery_service/not_delivered_storage/not_delivered_storage.nim index b0f5f5828..852c33c9a 100644 --- a/waku/node/delivery_service/not_delivered_storage/not_delivered_storage.nim +++ b/logos_delivery/messaging/delivery_service/not_delivered_storage/not_delivered_storage.nim @@ -9,9 +9,9 @@ import results import - ../../../common/databases/db_sqlite, - ../../../waku_core/message/message, - ../../../node/delivery_service/not_delivered_storage/migrations + logos_delivery/waku/common/databases/db_sqlite, + logos_delivery/waku/waku_core/message/message, + ./migrations const NotDeliveredMessagesDbUrl = "not-delivered-messages.db" diff --git a/waku/node/delivery_service/recv_service.nim b/logos_delivery/messaging/delivery_service/recv_service.nim similarity index 100% rename from waku/node/delivery_service/recv_service.nim rename to logos_delivery/messaging/delivery_service/recv_service.nim diff --git a/waku/node/delivery_service/recv_service/recv_service.nim b/logos_delivery/messaging/delivery_service/recv_service/recv_service.nim similarity index 99% rename from waku/node/delivery_service/recv_service/recv_service.nim rename to logos_delivery/messaging/delivery_service/recv_service/recv_service.nim index 500926cc7..09bcaa815 100644 --- a/waku/node/delivery_service/recv_service/recv_service.nim +++ b/logos_delivery/messaging/delivery_service/recv_service/recv_service.nim @@ -6,7 +6,7 @@ import std/[tables, sequtils, options, sets] import chronos, chronicles, libp2p/utility import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_core, waku_core/topics, waku_store/client, diff --git a/waku/node/delivery_service/send_service.nim b/logos_delivery/messaging/delivery_service/send_service.nim similarity index 100% rename from waku/node/delivery_service/send_service.nim rename to logos_delivery/messaging/delivery_service/send_service.nim diff --git a/waku/node/delivery_service/send_service/delivery_task.nim b/logos_delivery/messaging/delivery_service/send_service/delivery_task.nim similarity index 94% rename from waku/node/delivery_service/send_service/delivery_task.nim rename to logos_delivery/messaging/delivery_service/send_service/delivery_task.nim index aa1dc17d7..e56536baa 100644 --- a/waku/node/delivery_service/send_service/delivery_task.nim +++ b/logos_delivery/messaging/delivery_service/send_service/delivery_task.nim @@ -1,6 +1,9 @@ import std/[options, times], chronos import brokers/broker_context -import waku/waku_core, waku/api/types, waku/requests/node_requests +import + logos_delivery/waku/waku_core, + logos_delivery/waku/api/types, + logos_delivery/waku/requests/node_requests type DeliveryState* {.pure.} = enum Entry diff --git a/waku/node/delivery_service/send_service/lightpush_processor.nim b/logos_delivery/messaging/delivery_service/send_service/lightpush_processor.nim similarity index 95% rename from waku/node/delivery_service/send_service/lightpush_processor.nim rename to logos_delivery/messaging/delivery_service/send_service/lightpush_processor.nim index 7a9f65c71..100c27f52 100644 --- a/waku/node/delivery_service/send_service/lightpush_processor.nim +++ b/logos_delivery/messaging/delivery_service/send_service/lightpush_processor.nim @@ -1,7 +1,10 @@ import chronicles, chronos, results import std/options import brokers/broker_context -import waku/node/peer_manager, waku/waku_core, waku/waku_lightpush/[common, client, rpc] +import + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_lightpush/[common, client, rpc] import ./[delivery_task, send_processor] diff --git a/waku/node/delivery_service/send_service/relay_processor.nim b/logos_delivery/messaging/delivery_service/send_service/relay_processor.nim similarity index 93% rename from waku/node/delivery_service/send_service/relay_processor.nim rename to logos_delivery/messaging/delivery_service/send_service/relay_processor.nim index e06b664fb..2fdc39f8e 100644 --- a/waku/node/delivery_service/send_service/relay_processor.nim +++ b/logos_delivery/messaging/delivery_service/send_service/relay_processor.nim @@ -1,9 +1,9 @@ import std/options import chronos, chronicles import brokers/broker_context -import waku/[waku_core], waku/waku_lightpush/[common, rpc] -import waku/requests/health_requests -import waku/api/types +import logos_delivery/waku/[waku_core], logos_delivery/waku/waku_lightpush/[common, rpc] +import logos_delivery/waku/requests/health_requests +import logos_delivery/waku/api/types import ./[delivery_task, send_processor] logScope: diff --git a/waku/node/delivery_service/send_service/send_processor.nim b/logos_delivery/messaging/delivery_service/send_service/send_processor.nim similarity index 100% rename from waku/node/delivery_service/send_service/send_processor.nim rename to logos_delivery/messaging/delivery_service/send_service/send_processor.nim diff --git a/waku/node/delivery_service/send_service/send_service.nim b/logos_delivery/messaging/delivery_service/send_service/send_service.nim similarity index 99% rename from waku/node/delivery_service/send_service/send_service.nim rename to logos_delivery/messaging/delivery_service/send_service/send_service.nim index e60b26124..43b73fa26 100644 --- a/waku/node/delivery_service/send_service/send_service.nim +++ b/logos_delivery/messaging/delivery_service/send_service/send_service.nim @@ -1,12 +1,12 @@ ## This module reinforces the publish operation with regular store-v3 requests. ## -import std/[sequtils, tables, options] +import std/[sequtils, tables, options, typetraits] import chronos, chronicles, libp2p/utility import brokers/broker_context import ./[send_processor, relay_processor, lightpush_processor, delivery_task], - waku/[ + logos_delivery/waku/[ waku_core, node/waku_node, node/subscription_manager, diff --git a/waku/messaging_client.nim b/logos_delivery/messaging/messaging_client.nim similarity index 89% rename from waku/messaging_client.nim rename to logos_delivery/messaging/messaging_client.nim index 1fc4deb3c..1d3892250 100644 --- a/waku/messaging_client.nim +++ b/logos_delivery/messaging/messaging_client.nim @@ -1,14 +1,10 @@ import results, chronos import chronicles import - ./api/types, - ./node/[ - waku_node, - subscription_manager, - delivery_service/recv_service, - delivery_service/send_service, - delivery_service/send_service/delivery_task, - ] + logos_delivery/waku/api/types, + logos_delivery/waku/node/[waku_node, subscription_manager], + logos_delivery/messaging/delivery_service/[recv_service, send_service], + logos_delivery/messaging/delivery_service/send_service/delivery_task type MessagingClient* = ref object node: WakuNode diff --git a/waku/README.md b/logos_delivery/waku/README.md similarity index 100% rename from waku/README.md rename to logos_delivery/waku/README.md diff --git a/waku/api.nim b/logos_delivery/waku/api.nim similarity index 100% rename from waku/api.nim rename to logos_delivery/waku/api.nim diff --git a/waku/api/api.nim b/logos_delivery/waku/api/api.nim similarity index 81% rename from waku/api/api.nim rename to logos_delivery/waku/api/api.nim index 24049002b..1cbe47256 100644 --- a/waku/api/api.nim +++ b/logos_delivery/waku/api/api.nim @@ -1,12 +1,12 @@ import chronicles, chronos, results -import waku/factory/waku -import waku/messaging_client -import waku/[requests/health_requests, waku_core, waku_node] -import waku/node/delivery_service/send_service -import waku/node/subscription_manager +import logos_delivery/waku/factory/waku +import logos_delivery/messaging/messaging_client +import logos_delivery/waku/[requests/health_requests, waku_core, waku_node] +import logos_delivery/messaging/delivery_service/send_service +import logos_delivery/waku/node/subscription_manager import libp2p/peerid -import ../../tools/confutils/cli_args +import tools/confutils/cli_args import ./[api_conf, types] export cli_args diff --git a/waku/api/api_conf.nim b/logos_delivery/waku/api/api_conf.nim similarity index 98% rename from waku/api/api_conf.nim rename to logos_delivery/waku/api/api_conf.nim index 3606be596..b01fae8bd 100644 --- a/waku/api/api_conf.nim +++ b/logos_delivery/waku/api/api_conf.nim @@ -4,11 +4,11 @@ import results import json_serialization, json_serialization/std/options as json_options import - waku/common/utils/parse_size_units, - waku/common/logging, - waku/factory/waku_conf, - waku/factory/conf_builder/conf_builder, - waku/factory/networks_config, + logos_delivery/waku/common/utils/parse_size_units, + logos_delivery/waku/common/logging, + logos_delivery/waku/factory/waku_conf, + logos_delivery/waku/factory/conf_builder/conf_builder, + logos_delivery/waku/factory/networks_config, tools/confutils/entry_nodes export json_serialization, json_options diff --git a/waku/api/send_api.md b/logos_delivery/waku/api/send_api.md similarity index 100% rename from waku/api/send_api.md rename to logos_delivery/waku/api/send_api.md diff --git a/waku/api/types.nim b/logos_delivery/waku/api/types.nim similarity index 91% rename from waku/api/types.nim rename to logos_delivery/waku/api/types.nim index 2b7edd616..6b2b621de 100644 --- a/waku/api/types.nim +++ b/logos_delivery/waku/api/types.nim @@ -2,9 +2,9 @@ import bearssl/rand, std/times, chronos import stew/byteutils -import waku/utils/requests as request_utils -import waku/waku_core/[topics/content_topic, message/message, time] -import waku/requests/requests +import logos_delivery/waku/utils/requests as request_utils +import logos_delivery/waku/waku_core/[topics/content_topic, message/message, time] +import logos_delivery/waku/requests/requests type MessageEnvelope* = object diff --git a/waku/common/base64.nim b/logos_delivery/waku/common/base64.nim similarity index 100% rename from waku/common/base64.nim rename to logos_delivery/waku/common/base64.nim diff --git a/waku/common/callbacks.nim b/logos_delivery/waku/common/callbacks.nim similarity index 68% rename from waku/common/callbacks.nim rename to logos_delivery/waku/common/callbacks.nim index 83209ef24..9935a8d76 100644 --- a/waku/common/callbacks.nim +++ b/logos_delivery/waku/common/callbacks.nim @@ -1,4 +1,6 @@ -import waku/waku_enr/capabilities, waku/waku_rendezvous/waku_peer_record +import + logos_delivery/waku/waku_enr/capabilities, + logos_delivery/waku/waku_rendezvous/waku_peer_record type GetShards* = proc(): seq[uint16] {.closure, gcsafe, raises: [].} diff --git a/waku/common/databases/common.nim b/logos_delivery/waku/common/databases/common.nim similarity index 100% rename from waku/common/databases/common.nim rename to logos_delivery/waku/common/databases/common.nim diff --git a/waku/common/databases/db_postgres.nim b/logos_delivery/waku/common/databases/db_postgres.nim similarity index 100% rename from waku/common/databases/db_postgres.nim rename to logos_delivery/waku/common/databases/db_postgres.nim diff --git a/waku/common/databases/db_postgres/dbconn.nim b/logos_delivery/waku/common/databases/db_postgres/dbconn.nim similarity index 100% rename from waku/common/databases/db_postgres/dbconn.nim rename to logos_delivery/waku/common/databases/db_postgres/dbconn.nim diff --git a/waku/common/databases/db_postgres/pgasyncpool.nim b/logos_delivery/waku/common/databases/db_postgres/pgasyncpool.nim similarity index 100% rename from waku/common/databases/db_postgres/pgasyncpool.nim rename to logos_delivery/waku/common/databases/db_postgres/pgasyncpool.nim diff --git a/waku/common/databases/db_postgres/query_metrics.nim b/logos_delivery/waku/common/databases/db_postgres/query_metrics.nim similarity index 100% rename from waku/common/databases/db_postgres/query_metrics.nim rename to logos_delivery/waku/common/databases/db_postgres/query_metrics.nim diff --git a/waku/common/databases/db_sqlite.nim b/logos_delivery/waku/common/databases/db_sqlite.nim similarity index 100% rename from waku/common/databases/db_sqlite.nim rename to logos_delivery/waku/common/databases/db_sqlite.nim diff --git a/waku/common/databases/dburl.nim b/logos_delivery/waku/common/databases/dburl.nim similarity index 100% rename from waku/common/databases/dburl.nim rename to logos_delivery/waku/common/databases/dburl.nim diff --git a/waku/common/enr.nim b/logos_delivery/waku/common/enr.nim similarity index 100% rename from waku/common/enr.nim rename to logos_delivery/waku/common/enr.nim diff --git a/waku/common/enr/builder.nim b/logos_delivery/waku/common/enr/builder.nim similarity index 100% rename from waku/common/enr/builder.nim rename to logos_delivery/waku/common/enr/builder.nim diff --git a/waku/common/enr/typed_record.nim b/logos_delivery/waku/common/enr/typed_record.nim similarity index 100% rename from waku/common/enr/typed_record.nim rename to logos_delivery/waku/common/enr/typed_record.nim diff --git a/waku/common/error_handling.nim b/logos_delivery/waku/common/error_handling.nim similarity index 100% rename from waku/common/error_handling.nim rename to logos_delivery/waku/common/error_handling.nim diff --git a/waku/common/hexstrings.nim b/logos_delivery/waku/common/hexstrings.nim similarity index 100% rename from waku/common/hexstrings.nim rename to logos_delivery/waku/common/hexstrings.nim diff --git a/waku/common/logging.nim b/logos_delivery/waku/common/logging.nim similarity index 100% rename from waku/common/logging.nim rename to logos_delivery/waku/common/logging.nim diff --git a/waku/common/nimchronos.nim b/logos_delivery/waku/common/nimchronos.nim similarity index 100% rename from waku/common/nimchronos.nim rename to logos_delivery/waku/common/nimchronos.nim diff --git a/waku/common/paging.nim b/logos_delivery/waku/common/paging.nim similarity index 100% rename from waku/common/paging.nim rename to logos_delivery/waku/common/paging.nim diff --git a/waku/common/protobuf.nim b/logos_delivery/waku/common/protobuf.nim similarity index 100% rename from waku/common/protobuf.nim rename to logos_delivery/waku/common/protobuf.nim diff --git a/waku/common/rate_limit/per_peer_limiter.nim b/logos_delivery/waku/common/rate_limit/per_peer_limiter.nim similarity index 100% rename from waku/common/rate_limit/per_peer_limiter.nim rename to logos_delivery/waku/common/rate_limit/per_peer_limiter.nim diff --git a/waku/common/rate_limit/request_limiter.nim b/logos_delivery/waku/common/rate_limit/request_limiter.nim similarity index 100% rename from waku/common/rate_limit/request_limiter.nim rename to logos_delivery/waku/common/rate_limit/request_limiter.nim diff --git a/waku/common/rate_limit/service_metrics.nim b/logos_delivery/waku/common/rate_limit/service_metrics.nim similarity index 100% rename from waku/common/rate_limit/service_metrics.nim rename to logos_delivery/waku/common/rate_limit/service_metrics.nim diff --git a/waku/common/rate_limit/setting.nim b/logos_delivery/waku/common/rate_limit/setting.nim similarity index 100% rename from waku/common/rate_limit/setting.nim rename to logos_delivery/waku/common/rate_limit/setting.nim diff --git a/waku/common/rate_limit/single_token_limiter.nim b/logos_delivery/waku/common/rate_limit/single_token_limiter.nim similarity index 100% rename from waku/common/rate_limit/single_token_limiter.nim rename to logos_delivery/waku/common/rate_limit/single_token_limiter.nim diff --git a/waku/common/rate_limit/timed_map.nim b/logos_delivery/waku/common/rate_limit/timed_map.nim similarity index 100% rename from waku/common/rate_limit/timed_map.nim rename to logos_delivery/waku/common/rate_limit/timed_map.nim diff --git a/waku/common/utils/DEPRECATION_NOTICE.md b/logos_delivery/waku/common/utils/DEPRECATION_NOTICE.md similarity index 100% rename from waku/common/utils/DEPRECATION_NOTICE.md rename to logos_delivery/waku/common/utils/DEPRECATION_NOTICE.md diff --git a/waku/common/utils/matterbridge_client.nim b/logos_delivery/waku/common/utils/matterbridge_client.nim similarity index 100% rename from waku/common/utils/matterbridge_client.nim rename to logos_delivery/waku/common/utils/matterbridge_client.nim diff --git a/waku/common/utils/nat.nim b/logos_delivery/waku/common/utils/nat.nim similarity index 100% rename from waku/common/utils/nat.nim rename to logos_delivery/waku/common/utils/nat.nim diff --git a/waku/common/utils/parse_size_units.nim b/logos_delivery/waku/common/utils/parse_size_units.nim similarity index 100% rename from waku/common/utils/parse_size_units.nim rename to logos_delivery/waku/common/utils/parse_size_units.nim diff --git a/waku/common/utils/sequence.nim b/logos_delivery/waku/common/utils/sequence.nim similarity index 100% rename from waku/common/utils/sequence.nim rename to logos_delivery/waku/common/utils/sequence.nim diff --git a/waku/common/waku_protocol.nim b/logos_delivery/waku/common/waku_protocol.nim similarity index 100% rename from waku/common/waku_protocol.nim rename to logos_delivery/waku/common/waku_protocol.nim diff --git a/waku/discovery/autonat_service.nim b/logos_delivery/waku/discovery/autonat_service.nim similarity index 100% rename from waku/discovery/autonat_service.nim rename to logos_delivery/waku/discovery/autonat_service.nim diff --git a/waku/discovery/waku_discv5.nim b/logos_delivery/waku/discovery/waku_discv5.nim similarity index 99% rename from waku/discovery/waku_discv5.nim rename to logos_delivery/waku/discovery/waku_discv5.nim index c1b253c8c..d1b22a6d4 100644 --- a/waku/discovery/waku_discv5.nim +++ b/logos_delivery/waku/discovery/waku_discv5.nim @@ -10,7 +10,9 @@ import eth/keys as eth_keys, eth/p2p/discoveryv5/node, eth/p2p/discoveryv5/protocol -import waku/[net/auto_port, node/peer_manager/peer_manager, waku_core, waku_enr] +import + logos_delivery/waku/ + [net/auto_port, node/peer_manager/peer_manager, waku_core, waku_enr] export protocol, waku_enr diff --git a/waku/discovery/waku_dnsdisc.nim b/logos_delivery/waku/discovery/waku_dnsdisc.nim similarity index 100% rename from waku/discovery/waku_dnsdisc.nim rename to logos_delivery/waku/discovery/waku_dnsdisc.nim diff --git a/waku/discovery/waku_kademlia.nim b/logos_delivery/waku/discovery/waku_kademlia.nim similarity index 99% rename from waku/discovery/waku_kademlia.nim rename to logos_delivery/waku/discovery/waku_kademlia.nim index 94b63a321..6c64edace 100644 --- a/waku/discovery/waku_kademlia.nim +++ b/logos_delivery/waku/discovery/waku_kademlia.nim @@ -13,7 +13,7 @@ import libp2p/protocols/kademlia_discovery/types as kad_types, libp2p/protocols/mix/mix_protocol -import waku/waku_core, waku/node/peer_manager +import logos_delivery/waku/waku_core, logos_delivery/waku/node/peer_manager logScope: topics = "waku extended kademlia discovery" diff --git a/waku/events/delivery_events.nim b/logos_delivery/waku/events/delivery_events.nim similarity index 78% rename from waku/events/delivery_events.nim rename to logos_delivery/waku/events/delivery_events.nim index 5730335e0..5238e0403 100644 --- a/waku/events/delivery_events.nim +++ b/logos_delivery/waku/events/delivery_events.nim @@ -1,5 +1,5 @@ import brokers/event_broker -import waku/waku_core/[message/message, message/digest] +import logos_delivery/waku/waku_core/[message/message, message/digest] EventBroker: type OnFilterSubscribeEvent* = object diff --git a/waku/events/events.nim b/logos_delivery/waku/events/events.nim similarity index 100% rename from waku/events/events.nim rename to logos_delivery/waku/events/events.nim diff --git a/waku/events/health_events.nim b/logos_delivery/waku/events/health_events.nim similarity index 82% rename from waku/events/health_events.nim rename to logos_delivery/waku/events/health_events.nim index 95912941e..4ff6f0c6c 100644 --- a/waku/events/health_events.nim +++ b/logos_delivery/waku/events/health_events.nim @@ -1,8 +1,8 @@ import brokers/event_broker -import waku/api/types -import waku/node/health_monitor/[protocol_health, topic_health] -import waku/waku_core/topics +import logos_delivery/waku/api/types +import logos_delivery/waku/node/health_monitor/[protocol_health, topic_health] +import logos_delivery/waku/waku_core/topics export protocol_health, topic_health diff --git a/waku/events/message_events.nim b/logos_delivery/waku/events/message_events.nim similarity index 92% rename from waku/events/message_events.nim rename to logos_delivery/waku/events/message_events.nim index b45f91249..9338fda67 100644 --- a/waku/events/message_events.nim +++ b/logos_delivery/waku/events/message_events.nim @@ -1,5 +1,5 @@ import brokers/event_broker -import waku/[api/types, waku_core/message, waku_core/topics] +import logos_delivery/waku/[api/types, waku_core/message, waku_core/topics] export types EventBroker: diff --git a/waku/events/peer_events.nim b/logos_delivery/waku/events/peer_events.nim similarity index 100% rename from waku/events/peer_events.nim rename to logos_delivery/waku/events/peer_events.nim diff --git a/waku/factory/app_callbacks.nim b/logos_delivery/waku/factory/app_callbacks.nim similarity index 100% rename from waku/factory/app_callbacks.nim rename to logos_delivery/waku/factory/app_callbacks.nim diff --git a/waku/factory/builder.nim b/logos_delivery/waku/factory/builder.nim similarity index 100% rename from waku/factory/builder.nim rename to logos_delivery/waku/factory/builder.nim diff --git a/waku/factory/conf_builder/conf_builder.nim b/logos_delivery/waku/factory/conf_builder/conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/conf_builder.nim diff --git a/waku/factory/conf_builder/discv5_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/discv5_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim diff --git a/waku/factory/conf_builder/dns_discovery_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/dns_discovery_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/dns_discovery_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/dns_discovery_conf_builder.nim diff --git a/waku/factory/conf_builder/filter_service_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/filter_service_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim diff --git a/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim similarity index 96% rename from waku/factory/conf_builder/kademlia_discovery_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim index 916d71be1..576b6b7d9 100644 --- a/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim @@ -1,6 +1,6 @@ import chronicles, std/options, results import libp2p/[peerid, multiaddress, peerinfo] -import waku/factory/waku_conf +import logos_delivery/waku/factory/waku_conf logScope: topics = "waku conf builder kademlia discovery" diff --git a/waku/factory/conf_builder/metrics_server_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/metrics_server_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim diff --git a/waku/factory/conf_builder/mix_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim similarity index 96% rename from waku/factory/conf_builder/mix_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim index 145ccb76e..971e63588 100644 --- a/waku/factory/conf_builder/mix_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim @@ -1,6 +1,6 @@ import chronicles, std/options, results import libp2p/crypto/crypto, libp2p/crypto/curve25519, libp2p/protocols/mix/curve25519 -import ../waku_conf, waku/waku_mix +import ../waku_conf, logos_delivery/waku/waku_mix logScope: topics = "waku conf builder mix" diff --git a/waku/factory/conf_builder/rate_limit_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/rate_limit_conf_builder.nim similarity index 95% rename from waku/factory/conf_builder/rate_limit_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/rate_limit_conf_builder.nim index b2edbef03..f3a28c5dc 100644 --- a/waku/factory/conf_builder/rate_limit_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/rate_limit_conf_builder.nim @@ -1,5 +1,5 @@ import chronicles, std/[net, options], results -import waku/common/rate_limit/setting +import logos_delivery/waku/common/rate_limit/setting logScope: topics = "waku conf builder rate limit" diff --git a/waku/factory/conf_builder/rest_server_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/rest_server_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim diff --git a/waku/factory/conf_builder/rln_relay_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/rln_relay_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim diff --git a/waku/factory/conf_builder/store_service_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/store_service_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim diff --git a/waku/factory/conf_builder/store_sync_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim similarity index 100% rename from waku/factory/conf_builder/store_sync_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim diff --git a/waku/factory/conf_builder/waku_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim similarity index 99% rename from waku/factory/conf_builder/waku_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim index 96e34eeed..7d7189fac 100644 --- a/waku/factory/conf_builder/waku_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim @@ -8,7 +8,7 @@ import results import - waku/[ + logos_delivery/waku/[ factory/waku_conf, factory/networks_config, common/logging, diff --git a/waku/factory/conf_builder/web_socket_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim similarity index 97% rename from waku/factory/conf_builder/web_socket_conf_builder.nim rename to logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim index 61334d958..285e678e8 100644 --- a/waku/factory/conf_builder/web_socket_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim @@ -1,5 +1,5 @@ import chronicles, std/[net, options], results -import waku/factory/waku_conf +import logos_delivery/waku/factory/waku_conf logScope: topics = "waku conf builder websocket" diff --git a/waku/factory/internal_config.nim b/logos_delivery/waku/factory/internal_config.nim similarity index 98% rename from waku/factory/internal_config.nim rename to logos_delivery/waku/factory/internal_config.nim index fa36aff57..a3306eadc 100644 --- a/waku/factory/internal_config.nim +++ b/logos_delivery/waku/factory/internal_config.nim @@ -8,7 +8,9 @@ import std/[options, sequtils, net], results -import waku/[common/utils/nat, net/net_config, waku_enr, waku_core], ./waku_conf +import + logos_delivery/waku/[common/utils/nat, net/net_config, waku_enr, waku_core], + ./waku_conf proc tryBuildEnrRecord( conf: WakuConf, netConfig: NetConfig, multiaddrs: seq[MultiAddress] diff --git a/waku/factory/networks_config.nim b/logos_delivery/waku/factory/networks_config.nim similarity index 100% rename from waku/factory/networks_config.nim rename to logos_delivery/waku/factory/networks_config.nim diff --git a/waku/factory/node_factory.nim b/logos_delivery/waku/factory/node_factory.nim similarity index 100% rename from waku/factory/node_factory.nim rename to logos_delivery/waku/factory/node_factory.nim diff --git a/waku/factory/validator_signed.nim b/logos_delivery/waku/factory/validator_signed.nim similarity index 100% rename from waku/factory/validator_signed.nim rename to logos_delivery/waku/factory/validator_signed.nim diff --git a/waku/factory/waku.nim b/logos_delivery/waku/factory/waku.nim similarity index 99% rename from waku/factory/waku.nim rename to logos_delivery/waku/factory/waku.nim index edd02ade8..56e2748e2 100644 --- a/waku/factory/waku.nim +++ b/logos_delivery/waku/factory/waku.nim @@ -19,7 +19,7 @@ import metrics, metrics/chronos_httpserver, brokers/broker_context, - waku/[ + logos_delivery/waku/[ waku_core, waku_node, waku_archive, @@ -30,7 +30,6 @@ import waku_enr/sharding, waku_enr/multiaddr, api/types, - messaging_client, common/logging, node/peer_manager, node/health_monitor, @@ -49,7 +48,8 @@ import factory/app_callbacks, persistency/persistency, ], - channels/reliable_channel_manager, + logos_delivery/channels/reliable_channel_manager, + logos_delivery/messaging/messaging_client, ./waku_conf, ./waku_state_info diff --git a/waku/factory/waku_conf.nim b/logos_delivery/waku/factory/waku_conf.nim similarity index 100% rename from waku/factory/waku_conf.nim rename to logos_delivery/waku/factory/waku_conf.nim diff --git a/waku/factory/waku_state_info.nim b/logos_delivery/waku/factory/waku_state_info.nim similarity index 97% rename from waku/factory/waku_state_info.nim rename to logos_delivery/waku/factory/waku_state_info.nim index 5796e04f5..e608d5dd2 100644 --- a/waku/factory/waku_state_info.nim +++ b/logos_delivery/waku/factory/waku_state_info.nim @@ -6,7 +6,7 @@ import std/[tables, sequtils, strutils] import metrics, eth/p2p/discoveryv5/enr, libp2p/peerid, stew/byteutils -import waku/[waku_node, net/bound_ports] +import logos_delivery/waku/[waku_node, net/bound_ports] type NodeInfoId* {.pure.} = enum diff --git a/waku/incentivization/common.nim b/logos_delivery/waku/incentivization/common.nim similarity index 84% rename from waku/incentivization/common.nim rename to logos_delivery/waku/incentivization/common.nim index 071b4c18f..1fdfb05a9 100644 --- a/waku/incentivization/common.nim +++ b/logos_delivery/waku/incentivization/common.nim @@ -1,6 +1,6 @@ import std/options -import waku/incentivization/rpc +import logos_delivery/waku/incentivization/rpc proc init*(T: type EligibilityStatus, isEligible: bool): T = if isEligible: diff --git a/waku/incentivization/eligibility_manager.nim b/logos_delivery/waku/incentivization/eligibility_manager.nim similarity index 97% rename from waku/incentivization/eligibility_manager.nim rename to logos_delivery/waku/incentivization/eligibility_manager.nim index cbbf4774c..ad0f3b67e 100644 --- a/waku/incentivization/eligibility_manager.nim +++ b/logos_delivery/waku/incentivization/eligibility_manager.nim @@ -1,6 +1,6 @@ import std/[options, sets], chronos, web3, stew/byteutils, stint, results, chronicles -import waku/incentivization/rpc, tests/waku_rln_relay/utils_onchain +import logos_delivery/waku/incentivization/rpc, tests/waku_rln_relay/utils_onchain const SimpleTransferGasUsed = Quantity(21000) const TxReceiptQueryTimeout = 3.seconds diff --git a/waku/incentivization/reputation_manager.nim b/logos_delivery/waku/incentivization/reputation_manager.nim similarity index 100% rename from waku/incentivization/reputation_manager.nim rename to logos_delivery/waku/incentivization/reputation_manager.nim diff --git a/waku/incentivization/rpc.nim b/logos_delivery/waku/incentivization/rpc.nim similarity index 100% rename from waku/incentivization/rpc.nim rename to logos_delivery/waku/incentivization/rpc.nim diff --git a/waku/incentivization/rpc_codec.nim b/logos_delivery/waku/incentivization/rpc_codec.nim similarity index 100% rename from waku/incentivization/rpc_codec.nim rename to logos_delivery/waku/incentivization/rpc_codec.nim diff --git a/waku/net/auto_port.nim b/logos_delivery/waku/net/auto_port.nim similarity index 100% rename from waku/net/auto_port.nim rename to logos_delivery/waku/net/auto_port.nim diff --git a/waku/net/bound_ports.nim b/logos_delivery/waku/net/bound_ports.nim similarity index 100% rename from waku/net/bound_ports.nim rename to logos_delivery/waku/net/bound_ports.nim diff --git a/waku/net/net_config.nim b/logos_delivery/waku/net/net_config.nim similarity index 100% rename from waku/net/net_config.nim rename to logos_delivery/waku/net/net_config.nim diff --git a/waku/node/edge_filter_sub_state.nim b/logos_delivery/waku/node/edge_filter_sub_state.nim similarity index 100% rename from waku/node/edge_filter_sub_state.nim rename to logos_delivery/waku/node/edge_filter_sub_state.nim diff --git a/waku/node/health_monitor.nim b/logos_delivery/waku/node/health_monitor.nim similarity index 100% rename from waku/node/health_monitor.nim rename to logos_delivery/waku/node/health_monitor.nim diff --git a/waku/node/health_monitor/connection_status.nim b/logos_delivery/waku/node/health_monitor/connection_status.nim similarity index 100% rename from waku/node/health_monitor/connection_status.nim rename to logos_delivery/waku/node/health_monitor/connection_status.nim diff --git a/waku/node/health_monitor/event_loop_monitor.nim b/logos_delivery/waku/node/health_monitor/event_loop_monitor.nim similarity index 100% rename from waku/node/health_monitor/event_loop_monitor.nim rename to logos_delivery/waku/node/health_monitor/event_loop_monitor.nim diff --git a/waku/node/health_monitor/health_report.nim b/logos_delivery/waku/node/health_monitor/health_report.nim similarity index 100% rename from waku/node/health_monitor/health_report.nim rename to logos_delivery/waku/node/health_monitor/health_report.nim diff --git a/waku/node/health_monitor/health_status.nim b/logos_delivery/waku/node/health_monitor/health_status.nim similarity index 100% rename from waku/node/health_monitor/health_status.nim rename to logos_delivery/waku/node/health_monitor/health_status.nim diff --git a/waku/node/health_monitor/node_health_monitor.nim b/logos_delivery/waku/node/health_monitor/node_health_monitor.nim similarity index 99% rename from waku/node/health_monitor/node_health_monitor.nim rename to logos_delivery/waku/node/health_monitor/node_health_monitor.nim index e5c941191..74f3defec 100644 --- a/waku/node/health_monitor/node_health_monitor.nim +++ b/logos_delivery/waku/node/health_monitor/node_health_monitor.nim @@ -7,7 +7,7 @@ import libp2p/protocols/rendezvous, libp2p/protocols/pubsub, libp2p/protocols/pubsub/rpc/messages, - waku/[ + logos_delivery/waku/[ waku_relay, waku_rln_relay, api/types, diff --git a/waku/node/health_monitor/online_monitor.nim b/logos_delivery/waku/node/health_monitor/online_monitor.nim similarity index 97% rename from waku/node/health_monitor/online_monitor.nim rename to logos_delivery/waku/node/health_monitor/online_monitor.nim index 27bd53bc3..b2b87acd2 100644 --- a/waku/node/health_monitor/online_monitor.nim +++ b/logos_delivery/waku/node/health_monitor/online_monitor.nim @@ -1,7 +1,7 @@ import std/sequtils import chronos, chronicles, libp2p/nameresolving/dnsresolver, libp2p/peerstore -import ../peer_manager/waku_peer_store, waku/waku_core/peers +import ../peer_manager/waku_peer_store, logos_delivery/waku/waku_core/peers type OnOnlineStateChange* = proc(online: bool) {.gcsafe, raises: [].} diff --git a/waku/node/health_monitor/protocol_health.nim b/logos_delivery/waku/node/health_monitor/protocol_health.nim similarity index 96% rename from waku/node/health_monitor/protocol_health.nim rename to logos_delivery/waku/node/health_monitor/protocol_health.nim index 4479888c8..50d9c5572 100644 --- a/waku/node/health_monitor/protocol_health.nim +++ b/logos_delivery/waku/node/health_monitor/protocol_health.nim @@ -1,6 +1,6 @@ import std/[options, strformat] import ./health_status -import waku/common/waku_protocol +import logos_delivery/waku/common/waku_protocol export waku_protocol diff --git a/waku/node/health_monitor/topic_health.nim b/logos_delivery/waku/node/health_monitor/topic_health.nim similarity index 92% rename from waku/node/health_monitor/topic_health.nim rename to logos_delivery/waku/node/health_monitor/topic_health.nim index 5a1ea0a16..9273f4835 100644 --- a/waku/node/health_monitor/topic_health.nim +++ b/logos_delivery/waku/node/health_monitor/topic_health.nim @@ -1,6 +1,6 @@ import chronos -import waku/waku_core +import logos_delivery/waku/waku_core type TopicHealth* = enum UNHEALTHY diff --git a/waku/node/node_telemetry.nim b/logos_delivery/waku/node/node_telemetry.nim similarity index 100% rename from waku/node/node_telemetry.nim rename to logos_delivery/waku/node/node_telemetry.nim diff --git a/waku/node/peer_manager.nim b/logos_delivery/waku/node/peer_manager.nim similarity index 100% rename from waku/node/peer_manager.nim rename to logos_delivery/waku/node/peer_manager.nim diff --git a/waku/node/peer_manager/peer_manager.nim b/logos_delivery/waku/node/peer_manager/peer_manager.nim similarity index 99% rename from waku/node/peer_manager/peer_manager.nim rename to logos_delivery/waku/node/peer_manager/peer_manager.nim index 6602c049b..6c916c3c6 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/logos_delivery/waku/node/peer_manager/peer_manager.nim @@ -11,7 +11,7 @@ import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_core, waku_relay, waku_metadata, diff --git a/waku/node/peer_manager/peer_store/migrations.nim b/logos_delivery/waku/node/peer_manager/peer_store/migrations.nim similarity index 100% rename from waku/node/peer_manager/peer_store/migrations.nim rename to logos_delivery/waku/node/peer_manager/peer_store/migrations.nim diff --git a/waku/node/peer_manager/peer_store/peer_storage.nim b/logos_delivery/waku/node/peer_manager/peer_store/peer_storage.nim similarity index 100% rename from waku/node/peer_manager/peer_store/peer_storage.nim rename to logos_delivery/waku/node/peer_manager/peer_store/peer_storage.nim diff --git a/waku/node/peer_manager/peer_store/waku_peer_storage.nim b/logos_delivery/waku/node/peer_manager/peer_store/waku_peer_storage.nim similarity index 100% rename from waku/node/peer_manager/peer_store/waku_peer_storage.nim rename to logos_delivery/waku/node/peer_manager/peer_store/waku_peer_storage.nim diff --git a/waku/node/peer_manager/waku_peer_store.nim b/logos_delivery/waku/node/peer_manager/waku_peer_store.nim similarity index 100% rename from waku/node/peer_manager/waku_peer_store.nim rename to logos_delivery/waku/node/peer_manager/waku_peer_store.nim diff --git a/waku/node/shard_subscription.nim b/logos_delivery/waku/node/shard_subscription.nim similarity index 100% rename from waku/node/shard_subscription.nim rename to logos_delivery/waku/node/shard_subscription.nim diff --git a/waku/node/subscription_manager.nim b/logos_delivery/waku/node/subscription_manager.nim similarity index 99% rename from waku/node/subscription_manager.nim rename to logos_delivery/waku/node/subscription_manager.nim index 8bcb7bb46..a8acb58dd 100644 --- a/waku/node/subscription_manager.nim +++ b/logos_delivery/waku/node/subscription_manager.nim @@ -3,7 +3,7 @@ import libp2p/[peerid, peerinfo] import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_core, waku_core/topics/sharding, node/waku_node, diff --git a/waku/node/waku_metrics.nim b/logos_delivery/waku/node/waku_metrics.nim similarity index 96% rename from waku/node/waku_metrics.nim rename to logos_delivery/waku/node/waku_metrics.nim index bb4c10fff..feb767878 100644 --- a/waku/node/waku_metrics.nim +++ b/logos_delivery/waku/node/waku_metrics.nim @@ -2,7 +2,8 @@ import chronicles, chronos, metrics, metrics/chronos_httpserver import - waku/[net/auto_port, waku_rln_relay/protocol_metrics as rln_metrics, utils/collector], + logos_delivery/waku/ + [net/auto_port, waku_rln_relay/protocol_metrics as rln_metrics, utils/collector], ./peer_manager, ./node_telemetry, ./waku_node diff --git a/waku/node/waku_node.nim b/logos_delivery/waku/node/waku_node.nim similarity index 99% rename from waku/node/waku_node.nim rename to logos_delivery/waku/node/waku_node.nim index 6a8826d2a..a852fa13e 100644 --- a/waku/node/waku_node.nim +++ b/logos_delivery/waku/node/waku_node.nim @@ -29,7 +29,7 @@ import brokers/request_broker import - waku/[ + logos_delivery/waku/[ waku_core, waku_core/topics/sharding, waku_relay, @@ -62,8 +62,8 @@ import events/message_events, events/peer_events, ], - waku/discovery/waku_kademlia, - waku/net/[bound_ports, net_config], + logos_delivery/waku/discovery/waku_kademlia, + logos_delivery/waku/net/[bound_ports, net_config], ./peer_manager, ./health_monitor/health_status, ./health_monitor/topic_health, diff --git a/waku/node/waku_node/filter.nim b/logos_delivery/waku/node/waku_node/filter.nim similarity index 100% rename from waku/node/waku_node/filter.nim rename to logos_delivery/waku/node/waku_node/filter.nim diff --git a/waku/node/waku_node/lightpush.nim b/logos_delivery/waku/node/waku_node/lightpush.nim similarity index 100% rename from waku/node/waku_node/lightpush.nim rename to logos_delivery/waku/node/waku_node/lightpush.nim diff --git a/waku/node/waku_node/peer_exchange.nim b/logos_delivery/waku/node/waku_node/peer_exchange.nim similarity index 100% rename from waku/node/waku_node/peer_exchange.nim rename to logos_delivery/waku/node/waku_node/peer_exchange.nim diff --git a/waku/node/waku_node/ping.nim b/logos_delivery/waku/node/waku_node/ping.nim similarity index 100% rename from waku/node/waku_node/ping.nim rename to logos_delivery/waku/node/waku_node/ping.nim diff --git a/waku/node/waku_node/relay.nim b/logos_delivery/waku/node/waku_node/relay.nim similarity index 99% rename from waku/node/waku_node/relay.nim rename to logos_delivery/waku/node/waku_node/relay.nim index 30fc22ec3..b90992e9b 100644 --- a/waku/node/waku_node/relay.nim +++ b/logos_delivery/waku/node/waku_node/relay.nim @@ -20,7 +20,7 @@ import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_relay, waku_core, waku_core/topics/sharding, diff --git a/waku/node/waku_node/store.nim b/logos_delivery/waku/node/waku_node/store.nim similarity index 100% rename from waku/node/waku_node/store.nim rename to logos_delivery/waku/node/waku_node/store.nim diff --git a/waku/node/waku_switch.nim b/logos_delivery/waku/node/waku_switch.nim similarity index 100% rename from waku/node/waku_switch.nim rename to logos_delivery/waku/node/waku_switch.nim diff --git a/waku/persistency/backend_comm.nim b/logos_delivery/waku/persistency/backend_comm.nim similarity index 100% rename from waku/persistency/backend_comm.nim rename to logos_delivery/waku/persistency/backend_comm.nim diff --git a/waku/persistency/backend_sqlite.nim b/logos_delivery/waku/persistency/backend_sqlite.nim similarity index 100% rename from waku/persistency/backend_sqlite.nim rename to logos_delivery/waku/persistency/backend_sqlite.nim diff --git a/waku/persistency/backend_thread.nim b/logos_delivery/waku/persistency/backend_thread.nim similarity index 100% rename from waku/persistency/backend_thread.nim rename to logos_delivery/waku/persistency/backend_thread.nim diff --git a/waku/persistency/keys.nim b/logos_delivery/waku/persistency/keys.nim similarity index 100% rename from waku/persistency/keys.nim rename to logos_delivery/waku/persistency/keys.nim diff --git a/waku/persistency/payload.nim b/logos_delivery/waku/persistency/payload.nim similarity index 100% rename from waku/persistency/payload.nim rename to logos_delivery/waku/persistency/payload.nim diff --git a/waku/persistency/persistency.nim b/logos_delivery/waku/persistency/persistency.nim similarity index 100% rename from waku/persistency/persistency.nim rename to logos_delivery/waku/persistency/persistency.nim diff --git a/waku/persistency/schema.nim b/logos_delivery/waku/persistency/schema.nim similarity index 100% rename from waku/persistency/schema.nim rename to logos_delivery/waku/persistency/schema.nim diff --git a/waku/persistency/sds_persistency.nim b/logos_delivery/waku/persistency/sds_persistency.nim similarity index 100% rename from waku/persistency/sds_persistency.nim rename to logos_delivery/waku/persistency/sds_persistency.nim diff --git a/waku/persistency/types.nim b/logos_delivery/waku/persistency/types.nim similarity index 100% rename from waku/persistency/types.nim rename to logos_delivery/waku/persistency/types.nim diff --git a/waku/requests/health_requests.nim b/logos_delivery/waku/requests/health_requests.nim similarity index 87% rename from waku/requests/health_requests.nim rename to logos_delivery/waku/requests/health_requests.nim index ccf08f83d..1c9ed4d70 100644 --- a/waku/requests/health_requests.nim +++ b/logos_delivery/waku/requests/health_requests.nim @@ -1,9 +1,10 @@ import brokers/request_broker -import waku/api/types -import waku/node/health_monitor/[protocol_health, topic_health, health_report] -import waku/waku_core/topics -import waku/common/waku_protocol +import logos_delivery/waku/api/types +import + logos_delivery/waku/node/health_monitor/[protocol_health, topic_health, health_report] +import logos_delivery/waku/waku_core/topics +import logos_delivery/waku/common/waku_protocol export protocol_health, topic_health diff --git a/waku/requests/node_requests.nim b/logos_delivery/waku/requests/node_requests.nim similarity index 85% rename from waku/requests/node_requests.nim rename to logos_delivery/waku/requests/node_requests.nim index 93c6b1159..a5ca263cd 100644 --- a/waku/requests/node_requests.nim +++ b/logos_delivery/waku/requests/node_requests.nim @@ -1,6 +1,6 @@ import std/options import brokers/[request_broker, multi_request_broker] -import waku/waku_core/[topics] +import logos_delivery/waku/waku_core/[topics] RequestBroker(sync): type RequestRelayShard* = object diff --git a/waku/requests/requests.nim b/logos_delivery/waku/requests/requests.nim similarity index 100% rename from waku/requests/requests.nim rename to logos_delivery/waku/requests/requests.nim diff --git a/waku/requests/rln_requests.nim b/logos_delivery/waku/requests/rln_requests.nim similarity index 81% rename from waku/requests/rln_requests.nim rename to logos_delivery/waku/requests/rln_requests.nim index ffd747bed..04843e170 100644 --- a/waku/requests/rln_requests.nim +++ b/logos_delivery/waku/requests/rln_requests.nim @@ -1,5 +1,5 @@ import brokers/request_broker -import waku/waku_core/message/message +import logos_delivery/waku/waku_core/message/message RequestBroker: type RequestGenerateRlnProof* = object diff --git a/waku/rest_api/endpoint/admin/client.nim b/logos_delivery/waku/rest_api/endpoint/admin/client.nim similarity index 100% rename from waku/rest_api/endpoint/admin/client.nim rename to logos_delivery/waku/rest_api/endpoint/admin/client.nim diff --git a/waku/rest_api/endpoint/admin/handlers.nim b/logos_delivery/waku/rest_api/endpoint/admin/handlers.nim similarity index 99% rename from waku/rest_api/endpoint/admin/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/admin/handlers.nim index 304fdabf8..c82401d87 100644 --- a/waku/rest_api/endpoint/admin/handlers.nim +++ b/logos_delivery/waku/rest_api/endpoint/admin/handlers.nim @@ -9,7 +9,7 @@ import libp2p/[peerinfo, switch, peerid, protocols/pubsub/pubsubpeer] import - waku/[ + logos_delivery/waku/[ waku_core, waku_core/topics/pubsub_topic, waku_store/common, diff --git a/waku/rest_api/endpoint/admin/types.nim b/logos_delivery/waku/rest_api/endpoint/admin/types.nim similarity index 99% rename from waku/rest_api/endpoint/admin/types.nim rename to logos_delivery/waku/rest_api/endpoint/admin/types.nim index 483acf8b8..846f5a2fa 100644 --- a/waku/rest_api/endpoint/admin/types.nim +++ b/logos_delivery/waku/rest_api/endpoint/admin/types.nim @@ -7,7 +7,7 @@ import json_serialization/lexer, results, libp2p/protocols/pubsub/pubsubpeer -import waku/[waku_core, node/peer_manager], ../serdes +import logos_delivery/waku/[waku_core, node/peer_manager], ../serdes #### Types type WakuPeer* = object diff --git a/waku/rest_api/endpoint/builder.nim b/logos_delivery/waku/rest_api/endpoint/builder.nim similarity index 87% rename from waku/rest_api/endpoint/builder.nim rename to logos_delivery/waku/rest_api/endpoint/builder.nim index 16cdde988..6762aebdf 100644 --- a/waku/rest_api/endpoint/builder.nim +++ b/logos_delivery/waku/rest_api/endpoint/builder.nim @@ -3,22 +3,23 @@ import net, tables import presto import - waku/waku_node, - waku/node/health_monitor, - waku/discovery/waku_discv5, - waku/rest_api/message_cache, - waku/rest_api/handlers, - waku/rest_api/endpoint/server, - waku/rest_api/endpoint/debug/handlers as rest_debug_endpoint, - waku/rest_api/endpoint/relay/handlers as rest_relay_endpoint, - waku/rest_api/endpoint/filter/handlers as rest_filter_endpoint, - waku/rest_api/endpoint/legacy_lightpush/handlers as rest_legacy_lightpush_endpoint, - waku/rest_api/endpoint/lightpush/handlers as rest_lightpush_endpoint, - waku/rest_api/endpoint/store/handlers as rest_store_endpoint, - waku/rest_api/endpoint/health/handlers as rest_health_endpoint, - waku/rest_api/endpoint/admin/handlers as rest_admin_endpoint, - waku/waku_core/topics, - waku/waku_relay/protocol + logos_delivery/waku/waku_node, + logos_delivery/waku/node/health_monitor, + logos_delivery/waku/discovery/waku_discv5, + logos_delivery/waku/rest_api/message_cache, + logos_delivery/waku/rest_api/handlers, + logos_delivery/waku/rest_api/endpoint/server, + logos_delivery/waku/rest_api/endpoint/debug/handlers as rest_debug_endpoint, + logos_delivery/waku/rest_api/endpoint/relay/handlers as rest_relay_endpoint, + logos_delivery/waku/rest_api/endpoint/filter/handlers as rest_filter_endpoint, + logos_delivery/waku/rest_api/endpoint/legacy_lightpush/handlers as + rest_legacy_lightpush_endpoint, + logos_delivery/waku/rest_api/endpoint/lightpush/handlers as rest_lightpush_endpoint, + logos_delivery/waku/rest_api/endpoint/store/handlers as rest_store_endpoint, + logos_delivery/waku/rest_api/endpoint/health/handlers as rest_health_endpoint, + logos_delivery/waku/rest_api/endpoint/admin/handlers as rest_admin_endpoint, + logos_delivery/waku/waku_core/topics, + logos_delivery/waku/waku_relay/protocol ## Monitoring and external interfaces diff --git a/waku/rest_api/endpoint/client.nim b/logos_delivery/waku/rest_api/endpoint/client.nim similarity index 100% rename from waku/rest_api/endpoint/client.nim rename to logos_delivery/waku/rest_api/endpoint/client.nim diff --git a/waku/rest_api/endpoint/debug/client.nim b/logos_delivery/waku/rest_api/endpoint/debug/client.nim similarity index 100% rename from waku/rest_api/endpoint/debug/client.nim rename to logos_delivery/waku/rest_api/endpoint/debug/client.nim diff --git a/waku/rest_api/endpoint/debug/handlers.nim b/logos_delivery/waku/rest_api/endpoint/debug/handlers.nim similarity index 100% rename from waku/rest_api/endpoint/debug/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/debug/handlers.nim diff --git a/waku/rest_api/endpoint/debug/types.nim b/logos_delivery/waku/rest_api/endpoint/debug/types.nim similarity index 100% rename from waku/rest_api/endpoint/debug/types.nim rename to logos_delivery/waku/rest_api/endpoint/debug/types.nim diff --git a/waku/rest_api/endpoint/filter/client.nim b/logos_delivery/waku/rest_api/endpoint/filter/client.nim similarity index 100% rename from waku/rest_api/endpoint/filter/client.nim rename to logos_delivery/waku/rest_api/endpoint/filter/client.nim diff --git a/waku/rest_api/endpoint/filter/handlers.nim b/logos_delivery/waku/rest_api/endpoint/filter/handlers.nim similarity index 100% rename from waku/rest_api/endpoint/filter/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/filter/handlers.nim diff --git a/waku/rest_api/endpoint/filter/types.nim b/logos_delivery/waku/rest_api/endpoint/filter/types.nim similarity index 100% rename from waku/rest_api/endpoint/filter/types.nim rename to logos_delivery/waku/rest_api/endpoint/filter/types.nim diff --git a/waku/rest_api/endpoint/health/client.nim b/logos_delivery/waku/rest_api/endpoint/health/client.nim similarity index 74% rename from waku/rest_api/endpoint/health/client.nim rename to logos_delivery/waku/rest_api/endpoint/health/client.nim index 97f4a2c6d..9af8a138f 100644 --- a/waku/rest_api/endpoint/health/client.nim +++ b/logos_delivery/waku/rest_api/endpoint/health/client.nim @@ -1,7 +1,7 @@ {.push raises: [].} import chronicles, json_serialization, presto/[route, client] -import ./types, ../serdes, ../rest_serdes, waku/node/health_monitor +import ./types, ../serdes, ../rest_serdes, logos_delivery/waku/node/health_monitor logScope: topics = "waku node rest health_api" diff --git a/waku/rest_api/endpoint/health/handlers.nim b/logos_delivery/waku/rest_api/endpoint/health/handlers.nim similarity index 100% rename from waku/rest_api/endpoint/health/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/health/handlers.nim diff --git a/waku/rest_api/endpoint/health/types.nim b/logos_delivery/waku/rest_api/endpoint/health/types.nim similarity index 97% rename from waku/rest_api/endpoint/health/types.nim rename to logos_delivery/waku/rest_api/endpoint/health/types.nim index 4f85ebde5..00e101133 100644 --- a/waku/rest_api/endpoint/health/types.nim +++ b/logos_delivery/waku/rest_api/endpoint/health/types.nim @@ -3,7 +3,7 @@ import results import chronicles, json_serialization, json_serialization/std/options import ../serdes -import waku/[waku_node, api/types, node/health_monitor] +import logos_delivery/waku/[waku_node, api/types, node/health_monitor] #### Serialization and deserialization diff --git a/waku/rest_api/endpoint/legacy_lightpush/client.nim b/logos_delivery/waku/rest_api/endpoint/legacy_lightpush/client.nim similarity index 100% rename from waku/rest_api/endpoint/legacy_lightpush/client.nim rename to logos_delivery/waku/rest_api/endpoint/legacy_lightpush/client.nim diff --git a/waku/rest_api/endpoint/legacy_lightpush/handlers.nim b/logos_delivery/waku/rest_api/endpoint/legacy_lightpush/handlers.nim similarity index 96% rename from waku/rest_api/endpoint/legacy_lightpush/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/legacy_lightpush/handlers.nim index 7a3c5b1ed..4344f0481 100644 --- a/waku/rest_api/endpoint/legacy_lightpush/handlers.nim +++ b/logos_delivery/waku/rest_api/endpoint/legacy_lightpush/handlers.nim @@ -10,8 +10,8 @@ import presto/common import - waku/node/peer_manager, - waku/waku_lightpush_legacy/common, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_lightpush_legacy/common, ../../../waku_node, ../../handlers, ../serdes, diff --git a/waku/rest_api/endpoint/legacy_lightpush/types.nim b/logos_delivery/waku/rest_api/endpoint/legacy_lightpush/types.nim similarity index 100% rename from waku/rest_api/endpoint/legacy_lightpush/types.nim rename to logos_delivery/waku/rest_api/endpoint/legacy_lightpush/types.nim diff --git a/waku/rest_api/endpoint/lightpush/client.nim b/logos_delivery/waku/rest_api/endpoint/lightpush/client.nim similarity index 100% rename from waku/rest_api/endpoint/lightpush/client.nim rename to logos_delivery/waku/rest_api/endpoint/lightpush/client.nim diff --git a/waku/rest_api/endpoint/lightpush/handlers.nim b/logos_delivery/waku/rest_api/endpoint/lightpush/handlers.nim similarity index 97% rename from waku/rest_api/endpoint/lightpush/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/lightpush/handlers.nim index 342053e72..2afe3c7e7 100644 --- a/waku/rest_api/endpoint/lightpush/handlers.nim +++ b/logos_delivery/waku/rest_api/endpoint/lightpush/handlers.nim @@ -10,8 +10,8 @@ import presto/common import - waku/node/peer_manager, - waku/waku_lightpush/common, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_lightpush/common, ../../../waku_node, ../../handlers, ../serdes, diff --git a/waku/rest_api/endpoint/lightpush/types.nim b/logos_delivery/waku/rest_api/endpoint/lightpush/types.nim similarity index 100% rename from waku/rest_api/endpoint/lightpush/types.nim rename to logos_delivery/waku/rest_api/endpoint/lightpush/types.nim diff --git a/waku/rest_api/endpoint/origin_handler.nim b/logos_delivery/waku/rest_api/endpoint/origin_handler.nim similarity index 100% rename from waku/rest_api/endpoint/origin_handler.nim rename to logos_delivery/waku/rest_api/endpoint/origin_handler.nim diff --git a/waku/rest_api/endpoint/relay/client.nim b/logos_delivery/waku/rest_api/endpoint/relay/client.nim similarity index 100% rename from waku/rest_api/endpoint/relay/client.nim rename to logos_delivery/waku/rest_api/endpoint/relay/client.nim diff --git a/waku/rest_api/endpoint/relay/handlers.nim b/logos_delivery/waku/rest_api/endpoint/relay/handlers.nim similarity index 100% rename from waku/rest_api/endpoint/relay/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/relay/handlers.nim diff --git a/waku/rest_api/endpoint/relay/types.nim b/logos_delivery/waku/rest_api/endpoint/relay/types.nim similarity index 100% rename from waku/rest_api/endpoint/relay/types.nim rename to logos_delivery/waku/rest_api/endpoint/relay/types.nim diff --git a/waku/rest_api/endpoint/responses.nim b/logos_delivery/waku/rest_api/endpoint/responses.nim similarity index 100% rename from waku/rest_api/endpoint/responses.nim rename to logos_delivery/waku/rest_api/endpoint/responses.nim diff --git a/waku/rest_api/endpoint/rest_serdes.nim b/logos_delivery/waku/rest_api/endpoint/rest_serdes.nim similarity index 100% rename from waku/rest_api/endpoint/rest_serdes.nim rename to logos_delivery/waku/rest_api/endpoint/rest_serdes.nim diff --git a/waku/rest_api/endpoint/serdes.nim b/logos_delivery/waku/rest_api/endpoint/serdes.nim similarity index 100% rename from waku/rest_api/endpoint/serdes.nim rename to logos_delivery/waku/rest_api/endpoint/serdes.nim diff --git a/waku/rest_api/endpoint/server.nim b/logos_delivery/waku/rest_api/endpoint/server.nim similarity index 100% rename from waku/rest_api/endpoint/server.nim rename to logos_delivery/waku/rest_api/endpoint/server.nim diff --git a/waku/rest_api/endpoint/store/client.nim b/logos_delivery/waku/rest_api/endpoint/store/client.nim similarity index 100% rename from waku/rest_api/endpoint/store/client.nim rename to logos_delivery/waku/rest_api/endpoint/store/client.nim diff --git a/waku/rest_api/endpoint/store/handlers.nim b/logos_delivery/waku/rest_api/endpoint/store/handlers.nim similarity index 100% rename from waku/rest_api/endpoint/store/handlers.nim rename to logos_delivery/waku/rest_api/endpoint/store/handlers.nim diff --git a/waku/rest_api/endpoint/store/types.nim b/logos_delivery/waku/rest_api/endpoint/store/types.nim similarity index 100% rename from waku/rest_api/endpoint/store/types.nim rename to logos_delivery/waku/rest_api/endpoint/store/types.nim diff --git a/waku/rest_api/handlers.nim b/logos_delivery/waku/rest_api/handlers.nim similarity index 100% rename from waku/rest_api/handlers.nim rename to logos_delivery/waku/rest_api/handlers.nim diff --git a/waku/rest_api/message_cache.nim b/logos_delivery/waku/rest_api/message_cache.nim similarity index 100% rename from waku/rest_api/message_cache.nim rename to logos_delivery/waku/rest_api/message_cache.nim diff --git a/waku/utils/DEPRECATION_NOTICE.md b/logos_delivery/waku/utils/DEPRECATION_NOTICE.md similarity index 100% rename from waku/utils/DEPRECATION_NOTICE.md rename to logos_delivery/waku/utils/DEPRECATION_NOTICE.md diff --git a/waku/utils/collector.nim b/logos_delivery/waku/utils/collector.nim similarity index 100% rename from waku/utils/collector.nim rename to logos_delivery/waku/utils/collector.nim diff --git a/waku/utils/noise.nim b/logos_delivery/waku/utils/noise.nim similarity index 100% rename from waku/utils/noise.nim rename to logos_delivery/waku/utils/noise.nim diff --git a/waku/utils/requests.nim b/logos_delivery/waku/utils/requests.nim similarity index 100% rename from waku/utils/requests.nim rename to logos_delivery/waku/utils/requests.nim diff --git a/waku/utils/tableutils.nim b/logos_delivery/waku/utils/tableutils.nim similarity index 100% rename from waku/utils/tableutils.nim rename to logos_delivery/waku/utils/tableutils.nim diff --git a/waku/waku_archive.nim b/logos_delivery/waku/waku_archive.nim similarity index 100% rename from waku/waku_archive.nim rename to logos_delivery/waku/waku_archive.nim diff --git a/waku/waku_archive/archive.nim b/logos_delivery/waku/waku_archive/archive.nim similarity index 99% rename from waku/waku_archive/archive.nim rename to logos_delivery/waku/waku_archive/archive.nim index 976d7d035..a257a55b1 100644 --- a/waku/waku_archive/archive.nim +++ b/logos_delivery/waku/waku_archive/archive.nim @@ -15,7 +15,7 @@ import ../waku_core/message/digest, ./common, ./archive_metrics, - waku/waku_archive/retention_policy/retention_policy_time + logos_delivery/waku/waku_archive/retention_policy/retention_policy_time logScope: topics = "waku archive" diff --git a/waku/waku_archive/archive_metrics.nim b/logos_delivery/waku/waku_archive/archive_metrics.nim similarity index 100% rename from waku/waku_archive/archive_metrics.nim rename to logos_delivery/waku/waku_archive/archive_metrics.nim diff --git a/waku/waku_archive/common.nim b/logos_delivery/waku/waku_archive/common.nim similarity index 100% rename from waku/waku_archive/common.nim rename to logos_delivery/waku/waku_archive/common.nim diff --git a/waku/waku_archive/driver.nim b/logos_delivery/waku/waku_archive/driver.nim similarity index 100% rename from waku/waku_archive/driver.nim rename to logos_delivery/waku/waku_archive/driver.nim diff --git a/waku/waku_archive/driver/builder.nim b/logos_delivery/waku/waku_archive/driver/builder.nim similarity index 100% rename from waku/waku_archive/driver/builder.nim rename to logos_delivery/waku/waku_archive/driver/builder.nim diff --git a/waku/waku_archive/driver/postgres_driver.nim b/logos_delivery/waku/waku_archive/driver/postgres_driver.nim similarity index 100% rename from waku/waku_archive/driver/postgres_driver.nim rename to logos_delivery/waku/waku_archive/driver/postgres_driver.nim diff --git a/waku/waku_archive/driver/postgres_driver/migrations.nim b/logos_delivery/waku/waku_archive/driver/postgres_driver/migrations.nim similarity index 97% rename from waku/waku_archive/driver/postgres_driver/migrations.nim rename to logos_delivery/waku/waku_archive/driver/postgres_driver/migrations.nim index 700f2a162..a1a3e93fe 100644 --- a/waku/waku_archive/driver/postgres_driver/migrations.nim +++ b/logos_delivery/waku/waku_archive/driver/postgres_driver/migrations.nim @@ -3,7 +3,7 @@ import std/strutils, results, chronicles, chronos import ../../../common/databases/common, - ../../../../migrations/message_store_postgres/pg_migration_manager, + ../../../../../migrations/message_store_postgres/pg_migration_manager, ../postgres_driver logScope: diff --git a/waku/waku_archive/driver/postgres_driver/partitions_manager.nim b/logos_delivery/waku/waku_archive/driver/postgres_driver/partitions_manager.nim similarity index 100% rename from waku/waku_archive/driver/postgres_driver/partitions_manager.nim rename to logos_delivery/waku/waku_archive/driver/postgres_driver/partitions_manager.nim diff --git a/waku/waku_archive/driver/postgres_driver/postgres_driver.nim b/logos_delivery/waku/waku_archive/driver/postgres_driver/postgres_driver.nim similarity index 100% rename from waku/waku_archive/driver/postgres_driver/postgres_driver.nim rename to logos_delivery/waku/waku_archive/driver/postgres_driver/postgres_driver.nim diff --git a/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim b/logos_delivery/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim similarity index 100% rename from waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim rename to logos_delivery/waku/waku_archive/driver/postgres_driver/postgres_healthcheck.nim diff --git a/waku/waku_archive/driver/queue_driver.nim b/logos_delivery/waku/waku_archive/driver/queue_driver.nim similarity index 100% rename from waku/waku_archive/driver/queue_driver.nim rename to logos_delivery/waku/waku_archive/driver/queue_driver.nim diff --git a/waku/waku_archive/driver/queue_driver/index.nim b/logos_delivery/waku/waku_archive/driver/queue_driver/index.nim similarity index 100% rename from waku/waku_archive/driver/queue_driver/index.nim rename to logos_delivery/waku/waku_archive/driver/queue_driver/index.nim diff --git a/waku/waku_archive/driver/queue_driver/queue_driver.nim b/logos_delivery/waku/waku_archive/driver/queue_driver/queue_driver.nim similarity index 100% rename from waku/waku_archive/driver/queue_driver/queue_driver.nim rename to logos_delivery/waku/waku_archive/driver/queue_driver/queue_driver.nim diff --git a/waku/waku_archive/driver/sqlite_driver.nim b/logos_delivery/waku/waku_archive/driver/sqlite_driver.nim similarity index 100% rename from waku/waku_archive/driver/sqlite_driver.nim rename to logos_delivery/waku/waku_archive/driver/sqlite_driver.nim diff --git a/waku/waku_archive/driver/sqlite_driver/migrations.nim b/logos_delivery/waku/waku_archive/driver/sqlite_driver/migrations.nim similarity index 100% rename from waku/waku_archive/driver/sqlite_driver/migrations.nim rename to logos_delivery/waku/waku_archive/driver/sqlite_driver/migrations.nim diff --git a/waku/waku_archive/driver/sqlite_driver/queries.nim b/logos_delivery/waku/waku_archive/driver/sqlite_driver/queries.nim similarity index 100% rename from waku/waku_archive/driver/sqlite_driver/queries.nim rename to logos_delivery/waku/waku_archive/driver/sqlite_driver/queries.nim diff --git a/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim b/logos_delivery/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim similarity index 100% rename from waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim rename to logos_delivery/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim diff --git a/waku/waku_archive/retention_policy.nim b/logos_delivery/waku/waku_archive/retention_policy.nim similarity index 100% rename from waku/waku_archive/retention_policy.nim rename to logos_delivery/waku/waku_archive/retention_policy.nim diff --git a/waku/waku_archive/retention_policy/builder.nim b/logos_delivery/waku/waku_archive/retention_policy/builder.nim similarity index 100% rename from waku/waku_archive/retention_policy/builder.nim rename to logos_delivery/waku/waku_archive/retention_policy/builder.nim diff --git a/waku/waku_archive/retention_policy/retention_policy_capacity.nim b/logos_delivery/waku/waku_archive/retention_policy/retention_policy_capacity.nim similarity index 100% rename from waku/waku_archive/retention_policy/retention_policy_capacity.nim rename to logos_delivery/waku/waku_archive/retention_policy/retention_policy_capacity.nim diff --git a/waku/waku_archive/retention_policy/retention_policy_size.nim b/logos_delivery/waku/waku_archive/retention_policy/retention_policy_size.nim similarity index 100% rename from waku/waku_archive/retention_policy/retention_policy_size.nim rename to logos_delivery/waku/waku_archive/retention_policy/retention_policy_size.nim diff --git a/waku/waku_archive/retention_policy/retention_policy_time.nim b/logos_delivery/waku/waku_archive/retention_policy/retention_policy_time.nim similarity index 100% rename from waku/waku_archive/retention_policy/retention_policy_time.nim rename to logos_delivery/waku/waku_archive/retention_policy/retention_policy_time.nim diff --git a/waku/waku_core.nim b/logos_delivery/waku/waku_core.nim similarity index 100% rename from waku/waku_core.nim rename to logos_delivery/waku/waku_core.nim diff --git a/waku/waku_core/codecs.nim b/logos_delivery/waku/waku_core/codecs.nim similarity index 100% rename from waku/waku_core/codecs.nim rename to logos_delivery/waku/waku_core/codecs.nim diff --git a/waku/waku_core/message.nim b/logos_delivery/waku/waku_core/message.nim similarity index 100% rename from waku/waku_core/message.nim rename to logos_delivery/waku/waku_core/message.nim diff --git a/waku/waku_core/message/codec.nim b/logos_delivery/waku/waku_core/message/codec.nim similarity index 100% rename from waku/waku_core/message/codec.nim rename to logos_delivery/waku/waku_core/message/codec.nim diff --git a/waku/waku_core/message/default_values.nim b/logos_delivery/waku/waku_core/message/default_values.nim similarity index 100% rename from waku/waku_core/message/default_values.nim rename to logos_delivery/waku/waku_core/message/default_values.nim diff --git a/waku/waku_core/message/digest.nim b/logos_delivery/waku/waku_core/message/digest.nim similarity index 100% rename from waku/waku_core/message/digest.nim rename to logos_delivery/waku/waku_core/message/digest.nim diff --git a/waku/waku_core/message/message.nim b/logos_delivery/waku/waku_core/message/message.nim similarity index 100% rename from waku/waku_core/message/message.nim rename to logos_delivery/waku/waku_core/message/message.nim diff --git a/waku/waku_core/multiaddrstr.nim b/logos_delivery/waku/waku_core/multiaddrstr.nim similarity index 100% rename from waku/waku_core/multiaddrstr.nim rename to logos_delivery/waku/waku_core/multiaddrstr.nim diff --git a/waku/waku_core/peers.nim b/logos_delivery/waku/waku_core/peers.nim similarity index 100% rename from waku/waku_core/peers.nim rename to logos_delivery/waku/waku_core/peers.nim diff --git a/waku/waku_core/subscription.nim b/logos_delivery/waku/waku_core/subscription.nim similarity index 100% rename from waku/waku_core/subscription.nim rename to logos_delivery/waku/waku_core/subscription.nim diff --git a/waku/waku_core/subscription/push_handler.nim b/logos_delivery/waku/waku_core/subscription/push_handler.nim similarity index 100% rename from waku/waku_core/subscription/push_handler.nim rename to logos_delivery/waku/waku_core/subscription/push_handler.nim diff --git a/waku/waku_core/time.nim b/logos_delivery/waku/waku_core/time.nim similarity index 100% rename from waku/waku_core/time.nim rename to logos_delivery/waku/waku_core/time.nim diff --git a/waku/waku_core/topics.nim b/logos_delivery/waku/waku_core/topics.nim similarity index 100% rename from waku/waku_core/topics.nim rename to logos_delivery/waku/waku_core/topics.nim diff --git a/waku/waku_core/topics/content_topic.nim b/logos_delivery/waku/waku_core/topics/content_topic.nim similarity index 100% rename from waku/waku_core/topics/content_topic.nim rename to logos_delivery/waku/waku_core/topics/content_topic.nim diff --git a/waku/waku_core/topics/parsing.nim b/logos_delivery/waku/waku_core/topics/parsing.nim similarity index 100% rename from waku/waku_core/topics/parsing.nim rename to logos_delivery/waku/waku_core/topics/parsing.nim diff --git a/waku/waku_core/topics/pubsub_topic.nim b/logos_delivery/waku/waku_core/topics/pubsub_topic.nim similarity index 100% rename from waku/waku_core/topics/pubsub_topic.nim rename to logos_delivery/waku/waku_core/topics/pubsub_topic.nim diff --git a/waku/waku_core/topics/sharding.nim b/logos_delivery/waku/waku_core/topics/sharding.nim similarity index 100% rename from waku/waku_core/topics/sharding.nim rename to logos_delivery/waku/waku_core/topics/sharding.nim diff --git a/waku/waku_enr.nim b/logos_delivery/waku/waku_enr.nim similarity index 100% rename from waku/waku_enr.nim rename to logos_delivery/waku/waku_enr.nim diff --git a/waku/waku_enr/capabilities.nim b/logos_delivery/waku/waku_enr/capabilities.nim similarity index 100% rename from waku/waku_enr/capabilities.nim rename to logos_delivery/waku/waku_enr/capabilities.nim diff --git a/waku/waku_enr/multiaddr.nim b/logos_delivery/waku/waku_enr/multiaddr.nim similarity index 100% rename from waku/waku_enr/multiaddr.nim rename to logos_delivery/waku/waku_enr/multiaddr.nim diff --git a/waku/waku_enr/sharding.nim b/logos_delivery/waku/waku_enr/sharding.nim similarity index 100% rename from waku/waku_enr/sharding.nim rename to logos_delivery/waku/waku_enr/sharding.nim diff --git a/waku/waku_filter_v2.nim b/logos_delivery/waku/waku_filter_v2.nim similarity index 100% rename from waku/waku_filter_v2.nim rename to logos_delivery/waku/waku_filter_v2.nim diff --git a/waku/waku_filter_v2/client.nim b/logos_delivery/waku/waku_filter_v2/client.nim similarity index 99% rename from waku/waku_filter_v2/client.nim rename to logos_delivery/waku/waku_filter_v2/client.nim index 7798f41b7..6fb473e27 100644 --- a/waku/waku_filter_v2/client.nim +++ b/logos_delivery/waku/waku_filter_v2/client.nim @@ -12,7 +12,7 @@ import brokers/broker_context import - waku/[node/peer_manager, waku_core, events/delivery_events], + logos_delivery/waku/[node/peer_manager, waku_core, events/delivery_events], ./common, ./protocol_metrics, ./rpc_codec, diff --git a/waku/waku_filter_v2/common.nim b/logos_delivery/waku/waku_filter_v2/common.nim similarity index 100% rename from waku/waku_filter_v2/common.nim rename to logos_delivery/waku/waku_filter_v2/common.nim diff --git a/waku/waku_filter_v2/protocol.nim b/logos_delivery/waku/waku_filter_v2/protocol.nim similarity index 100% rename from waku/waku_filter_v2/protocol.nim rename to logos_delivery/waku/waku_filter_v2/protocol.nim diff --git a/waku/waku_filter_v2/protocol_metrics.nim b/logos_delivery/waku/waku_filter_v2/protocol_metrics.nim similarity index 100% rename from waku/waku_filter_v2/protocol_metrics.nim rename to logos_delivery/waku/waku_filter_v2/protocol_metrics.nim diff --git a/waku/waku_filter_v2/rpc.nim b/logos_delivery/waku/waku_filter_v2/rpc.nim similarity index 100% rename from waku/waku_filter_v2/rpc.nim rename to logos_delivery/waku/waku_filter_v2/rpc.nim diff --git a/waku/waku_filter_v2/rpc_codec.nim b/logos_delivery/waku/waku_filter_v2/rpc_codec.nim similarity index 100% rename from waku/waku_filter_v2/rpc_codec.nim rename to logos_delivery/waku/waku_filter_v2/rpc_codec.nim diff --git a/waku/waku_filter_v2/subscriptions.nim b/logos_delivery/waku/waku_filter_v2/subscriptions.nim similarity index 100% rename from waku/waku_filter_v2/subscriptions.nim rename to logos_delivery/waku/waku_filter_v2/subscriptions.nim diff --git a/waku/waku_keystore.nim b/logos_delivery/waku/waku_keystore.nim similarity index 100% rename from waku/waku_keystore.nim rename to logos_delivery/waku/waku_keystore.nim diff --git a/waku/waku_keystore/conversion_utils.nim b/logos_delivery/waku/waku_keystore/conversion_utils.nim similarity index 100% rename from waku/waku_keystore/conversion_utils.nim rename to logos_delivery/waku/waku_keystore/conversion_utils.nim diff --git a/waku/waku_keystore/keyfile.nim b/logos_delivery/waku/waku_keystore/keyfile.nim similarity index 100% rename from waku/waku_keystore/keyfile.nim rename to logos_delivery/waku/waku_keystore/keyfile.nim diff --git a/waku/waku_keystore/keystore.nim b/logos_delivery/waku/waku_keystore/keystore.nim similarity index 100% rename from waku/waku_keystore/keystore.nim rename to logos_delivery/waku/waku_keystore/keystore.nim diff --git a/waku/waku_keystore/protocol_types.nim b/logos_delivery/waku/waku_keystore/protocol_types.nim similarity index 100% rename from waku/waku_keystore/protocol_types.nim rename to logos_delivery/waku/waku_keystore/protocol_types.nim diff --git a/waku/waku_keystore/utils.nim b/logos_delivery/waku/waku_keystore/utils.nim similarity index 100% rename from waku/waku_keystore/utils.nim rename to logos_delivery/waku/waku_keystore/utils.nim diff --git a/waku/waku_lightpush.nim b/logos_delivery/waku/waku_lightpush.nim similarity index 100% rename from waku/waku_lightpush.nim rename to logos_delivery/waku/waku_lightpush.nim diff --git a/waku/waku_lightpush/callbacks.nim b/logos_delivery/waku/waku_lightpush/callbacks.nim similarity index 100% rename from waku/waku_lightpush/callbacks.nim rename to logos_delivery/waku/waku_lightpush/callbacks.nim diff --git a/waku/waku_lightpush/client.nim b/logos_delivery/waku/waku_lightpush/client.nim similarity index 100% rename from waku/waku_lightpush/client.nim rename to logos_delivery/waku/waku_lightpush/client.nim diff --git a/waku/waku_lightpush/common.nim b/logos_delivery/waku/waku_lightpush/common.nim similarity index 100% rename from waku/waku_lightpush/common.nim rename to logos_delivery/waku/waku_lightpush/common.nim diff --git a/waku/waku_lightpush/protocol.nim b/logos_delivery/waku/waku_lightpush/protocol.nim similarity index 100% rename from waku/waku_lightpush/protocol.nim rename to logos_delivery/waku/waku_lightpush/protocol.nim diff --git a/waku/waku_lightpush/protocol_metrics.nim b/logos_delivery/waku/waku_lightpush/protocol_metrics.nim similarity index 100% rename from waku/waku_lightpush/protocol_metrics.nim rename to logos_delivery/waku/waku_lightpush/protocol_metrics.nim diff --git a/waku/waku_lightpush/rpc.nim b/logos_delivery/waku/waku_lightpush/rpc.nim similarity index 100% rename from waku/waku_lightpush/rpc.nim rename to logos_delivery/waku/waku_lightpush/rpc.nim diff --git a/waku/waku_lightpush/rpc_codec.nim b/logos_delivery/waku/waku_lightpush/rpc_codec.nim similarity index 100% rename from waku/waku_lightpush/rpc_codec.nim rename to logos_delivery/waku/waku_lightpush/rpc_codec.nim diff --git a/waku/waku_lightpush/self_req_handler.nim b/logos_delivery/waku/waku_lightpush/self_req_handler.nim similarity index 100% rename from waku/waku_lightpush/self_req_handler.nim rename to logos_delivery/waku/waku_lightpush/self_req_handler.nim diff --git a/waku/waku_lightpush_legacy.nim b/logos_delivery/waku/waku_lightpush_legacy.nim similarity index 100% rename from waku/waku_lightpush_legacy.nim rename to logos_delivery/waku/waku_lightpush_legacy.nim diff --git a/waku/waku_lightpush_legacy/README.md b/logos_delivery/waku/waku_lightpush_legacy/README.md similarity index 100% rename from waku/waku_lightpush_legacy/README.md rename to logos_delivery/waku/waku_lightpush_legacy/README.md diff --git a/waku/waku_lightpush_legacy/callbacks.nim b/logos_delivery/waku/waku_lightpush_legacy/callbacks.nim similarity index 100% rename from waku/waku_lightpush_legacy/callbacks.nim rename to logos_delivery/waku/waku_lightpush_legacy/callbacks.nim diff --git a/waku/waku_lightpush_legacy/client.nim b/logos_delivery/waku/waku_lightpush_legacy/client.nim similarity index 100% rename from waku/waku_lightpush_legacy/client.nim rename to logos_delivery/waku/waku_lightpush_legacy/client.nim diff --git a/waku/waku_lightpush_legacy/common.nim b/logos_delivery/waku/waku_lightpush_legacy/common.nim similarity index 100% rename from waku/waku_lightpush_legacy/common.nim rename to logos_delivery/waku/waku_lightpush_legacy/common.nim diff --git a/waku/waku_lightpush_legacy/protocol.nim b/logos_delivery/waku/waku_lightpush_legacy/protocol.nim similarity index 100% rename from waku/waku_lightpush_legacy/protocol.nim rename to logos_delivery/waku/waku_lightpush_legacy/protocol.nim diff --git a/waku/waku_lightpush_legacy/protocol_metrics.nim b/logos_delivery/waku/waku_lightpush_legacy/protocol_metrics.nim similarity index 100% rename from waku/waku_lightpush_legacy/protocol_metrics.nim rename to logos_delivery/waku/waku_lightpush_legacy/protocol_metrics.nim diff --git a/waku/waku_lightpush_legacy/rpc.nim b/logos_delivery/waku/waku_lightpush_legacy/rpc.nim similarity index 100% rename from waku/waku_lightpush_legacy/rpc.nim rename to logos_delivery/waku/waku_lightpush_legacy/rpc.nim diff --git a/waku/waku_lightpush_legacy/rpc_codec.nim b/logos_delivery/waku/waku_lightpush_legacy/rpc_codec.nim similarity index 100% rename from waku/waku_lightpush_legacy/rpc_codec.nim rename to logos_delivery/waku/waku_lightpush_legacy/rpc_codec.nim diff --git a/waku/waku_lightpush_legacy/self_req_handler.nim b/logos_delivery/waku/waku_lightpush_legacy/self_req_handler.nim similarity index 100% rename from waku/waku_lightpush_legacy/self_req_handler.nim rename to logos_delivery/waku/waku_lightpush_legacy/self_req_handler.nim diff --git a/waku/waku_metadata.nim b/logos_delivery/waku/waku_metadata.nim similarity index 100% rename from waku/waku_metadata.nim rename to logos_delivery/waku/waku_metadata.nim diff --git a/waku/waku_metadata/protocol.nim b/logos_delivery/waku/waku_metadata/protocol.nim similarity index 100% rename from waku/waku_metadata/protocol.nim rename to logos_delivery/waku/waku_metadata/protocol.nim diff --git a/waku/waku_metadata/rpc.nim b/logos_delivery/waku/waku_metadata/rpc.nim similarity index 100% rename from waku/waku_metadata/rpc.nim rename to logos_delivery/waku/waku_metadata/rpc.nim diff --git a/waku/waku_mix.nim b/logos_delivery/waku/waku_mix.nim similarity index 100% rename from waku/waku_mix.nim rename to logos_delivery/waku/waku_mix.nim diff --git a/waku/waku_mix/protocol.nim b/logos_delivery/waku/waku_mix/protocol.nim similarity index 94% rename from waku/waku_mix/protocol.nim rename to logos_delivery/waku/waku_mix/protocol.nim index ac8b69eaf..c0c3adadc 100644 --- a/waku/waku_mix/protocol.nim +++ b/logos_delivery/waku/waku_mix/protocol.nim @@ -14,10 +14,10 @@ import eth/common/keys import - waku/node/peer_manager, - waku/waku_core, - waku/waku_enr, - waku/node/peer_manager/waku_peer_store + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_enr, + logos_delivery/waku/node/peer_manager/waku_peer_store logScope: topics = "waku mix" diff --git a/waku/waku_node.nim b/logos_delivery/waku/waku_node.nim similarity index 100% rename from waku/waku_node.nim rename to logos_delivery/waku/waku_node.nim diff --git a/waku/waku_noise/noise.nim b/logos_delivery/waku/waku_noise/noise.nim similarity index 100% rename from waku/waku_noise/noise.nim rename to logos_delivery/waku/waku_noise/noise.nim diff --git a/waku/waku_noise/noise_handshake_processing.nim b/logos_delivery/waku/waku_noise/noise_handshake_processing.nim similarity index 100% rename from waku/waku_noise/noise_handshake_processing.nim rename to logos_delivery/waku/waku_noise/noise_handshake_processing.nim diff --git a/waku/waku_noise/noise_types.nim b/logos_delivery/waku/waku_noise/noise_types.nim similarity index 100% rename from waku/waku_noise/noise_types.nim rename to logos_delivery/waku/waku_noise/noise_types.nim diff --git a/waku/waku_noise/noise_utils.nim b/logos_delivery/waku/waku_noise/noise_utils.nim similarity index 100% rename from waku/waku_noise/noise_utils.nim rename to logos_delivery/waku/waku_noise/noise_utils.nim diff --git a/waku/waku_peer_exchange.nim b/logos_delivery/waku/waku_peer_exchange.nim similarity index 100% rename from waku/waku_peer_exchange.nim rename to logos_delivery/waku/waku_peer_exchange.nim diff --git a/waku/waku_peer_exchange/README.md b/logos_delivery/waku/waku_peer_exchange/README.md similarity index 100% rename from waku/waku_peer_exchange/README.md rename to logos_delivery/waku/waku_peer_exchange/README.md diff --git a/waku/waku_peer_exchange/client.nim b/logos_delivery/waku/waku_peer_exchange/client.nim similarity index 100% rename from waku/waku_peer_exchange/client.nim rename to logos_delivery/waku/waku_peer_exchange/client.nim diff --git a/waku/waku_peer_exchange/common.nim b/logos_delivery/waku/waku_peer_exchange/common.nim similarity index 100% rename from waku/waku_peer_exchange/common.nim rename to logos_delivery/waku/waku_peer_exchange/common.nim diff --git a/waku/waku_peer_exchange/protocol.nim b/logos_delivery/waku/waku_peer_exchange/protocol.nim similarity index 100% rename from waku/waku_peer_exchange/protocol.nim rename to logos_delivery/waku/waku_peer_exchange/protocol.nim diff --git a/waku/waku_peer_exchange/rpc.nim b/logos_delivery/waku/waku_peer_exchange/rpc.nim similarity index 100% rename from waku/waku_peer_exchange/rpc.nim rename to logos_delivery/waku/waku_peer_exchange/rpc.nim diff --git a/waku/waku_peer_exchange/rpc_codec.nim b/logos_delivery/waku/waku_peer_exchange/rpc_codec.nim similarity index 100% rename from waku/waku_peer_exchange/rpc_codec.nim rename to logos_delivery/waku/waku_peer_exchange/rpc_codec.nim diff --git a/logos_delivery/waku/waku_persistency.nim b/logos_delivery/waku/waku_persistency.nim new file mode 100644 index 000000000..dc577199e --- /dev/null +++ b/logos_delivery/waku/waku_persistency.nim @@ -0,0 +1,3 @@ +import logos_delivery/waku/persistency/persistency + +export persistency diff --git a/waku/waku_relay.nim b/logos_delivery/waku/waku_relay.nim similarity index 50% rename from waku/waku_relay.nim rename to logos_delivery/waku/waku_relay.nim index a91033cf1..606fb16e2 100644 --- a/waku/waku_relay.nim +++ b/logos_delivery/waku/waku_relay.nim @@ -1,4 +1,4 @@ import ./waku_relay/protocol -import waku/node/health_monitor/topic_health +import logos_delivery/waku/node/health_monitor/topic_health export protocol, topic_health diff --git a/waku/waku_relay/message_id.nim b/logos_delivery/waku/waku_relay/message_id.nim similarity index 100% rename from waku/waku_relay/message_id.nim rename to logos_delivery/waku/waku_relay/message_id.nim diff --git a/waku/waku_relay/protocol.nim b/logos_delivery/waku/waku_relay/protocol.nim similarity index 98% rename from waku/waku_relay/protocol.nim rename to logos_delivery/waku/waku_relay/protocol.nim index d0b1ddb48..c35854be3 100644 --- a/waku/waku_relay/protocol.nim +++ b/logos_delivery/waku/waku_relay/protocol.nim @@ -20,14 +20,14 @@ import brokers/broker_context import - waku/waku_core, - waku/node/health_monitor/topic_health, - waku/requests/health_requests, - waku/events/health_events, + logos_delivery/waku/waku_core, + logos_delivery/waku/node/health_monitor/topic_health, + logos_delivery/waku/requests/health_requests, + logos_delivery/waku/events/health_events, ./message_id, - waku/events/peer_events + logos_delivery/waku/events/peer_events -from waku/waku_core/codecs import WakuRelayCodec +from logos_delivery/waku/waku_core/codecs import WakuRelayCodec export WakuRelayCodec type ShardMetrics = object diff --git a/waku/waku_rendezvous.nim b/logos_delivery/waku/waku_rendezvous.nim similarity index 100% rename from waku/waku_rendezvous.nim rename to logos_delivery/waku/waku_rendezvous.nim diff --git a/waku/waku_rendezvous/client.nim b/logos_delivery/waku/waku_rendezvous/client.nim similarity index 97% rename from waku/waku_rendezvous/client.nim rename to logos_delivery/waku/waku_rendezvous/client.nim index 09e789774..433ce361e 100644 --- a/waku/waku_rendezvous/client.nim +++ b/logos_delivery/waku/waku_rendezvous/client.nim @@ -13,9 +13,9 @@ import import metrics except collect import - waku/node/peer_manager, - waku/waku_core/peers, - waku/waku_core/codecs, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_core/peers, + logos_delivery/waku/waku_core/codecs, ./common, ./waku_peer_record diff --git a/waku/waku_rendezvous/common.nim b/logos_delivery/waku/waku_rendezvous/common.nim similarity index 100% rename from waku/waku_rendezvous/common.nim rename to logos_delivery/waku/waku_rendezvous/common.nim diff --git a/waku/waku_rendezvous/protocol.nim b/logos_delivery/waku/waku_rendezvous/protocol.nim similarity index 100% rename from waku/waku_rendezvous/protocol.nim rename to logos_delivery/waku/waku_rendezvous/protocol.nim diff --git a/waku/waku_rendezvous/waku_peer_record.nim b/logos_delivery/waku/waku_rendezvous/waku_peer_record.nim similarity index 100% rename from waku/waku_rendezvous/waku_peer_record.nim rename to logos_delivery/waku/waku_rendezvous/waku_peer_record.nim diff --git a/waku/waku_rest.nim b/logos_delivery/waku/waku_rest.nim similarity index 100% rename from waku/waku_rest.nim rename to logos_delivery/waku/waku_rest.nim diff --git a/waku/waku_rln_relay.nim b/logos_delivery/waku/waku_rln_relay.nim similarity index 100% rename from waku/waku_rln_relay.nim rename to logos_delivery/waku/waku_rln_relay.nim diff --git a/waku/waku_rln_relay/constants.nim b/logos_delivery/waku/waku_rln_relay/constants.nim similarity index 100% rename from waku/waku_rln_relay/constants.nim rename to logos_delivery/waku/waku_rln_relay/constants.nim diff --git a/waku/waku_rln_relay/contract.nim b/logos_delivery/waku/waku_rln_relay/contract.nim similarity index 100% rename from waku/waku_rln_relay/contract.nim rename to logos_delivery/waku/waku_rln_relay/contract.nim diff --git a/waku/waku_rln_relay/conversion_utils.nim b/logos_delivery/waku/waku_rln_relay/conversion_utils.nim similarity index 100% rename from waku/waku_rln_relay/conversion_utils.nim rename to logos_delivery/waku/waku_rln_relay/conversion_utils.nim diff --git a/waku/waku_rln_relay/group_manager.nim b/logos_delivery/waku/waku_rln_relay/group_manager.nim similarity index 100% rename from waku/waku_rln_relay/group_manager.nim rename to logos_delivery/waku/waku_rln_relay/group_manager.nim diff --git a/waku/waku_rln_relay/group_manager/group_manager_base.nim b/logos_delivery/waku/waku_rln_relay/group_manager/group_manager_base.nim similarity index 100% rename from waku/waku_rln_relay/group_manager/group_manager_base.nim rename to logos_delivery/waku/waku_rln_relay/group_manager/group_manager_base.nim diff --git a/waku/waku_rln_relay/group_manager/on_chain.nim b/logos_delivery/waku/waku_rln_relay/group_manager/on_chain.nim similarity index 100% rename from waku/waku_rln_relay/group_manager/on_chain.nim rename to logos_delivery/waku/waku_rln_relay/group_manager/on_chain.nim diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/logos_delivery/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim similarity index 100% rename from waku/waku_rln_relay/group_manager/on_chain/group_manager.nim rename to logos_delivery/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim diff --git a/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim b/logos_delivery/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim similarity index 100% rename from waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim rename to logos_delivery/waku/waku_rln_relay/group_manager/on_chain/retry_wrapper.nim diff --git a/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim b/logos_delivery/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim similarity index 100% rename from waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim rename to logos_delivery/waku/waku_rln_relay/group_manager/on_chain/rpc_wrapper.nim diff --git a/waku/waku_rln_relay/nonce_manager.nim b/logos_delivery/waku/waku_rln_relay/nonce_manager.nim similarity index 100% rename from waku/waku_rln_relay/nonce_manager.nim rename to logos_delivery/waku/waku_rln_relay/nonce_manager.nim diff --git a/waku/waku_rln_relay/protocol_metrics.nim b/logos_delivery/waku/waku_rln_relay/protocol_metrics.nim similarity index 100% rename from waku/waku_rln_relay/protocol_metrics.nim rename to logos_delivery/waku/waku_rln_relay/protocol_metrics.nim diff --git a/waku/waku_rln_relay/protocol_types.nim b/logos_delivery/waku/waku_rln_relay/protocol_types.nim similarity index 100% rename from waku/waku_rln_relay/protocol_types.nim rename to logos_delivery/waku/waku_rln_relay/protocol_types.nim diff --git a/waku/waku_rln_relay/rln.nim b/logos_delivery/waku/waku_rln_relay/rln.nim similarity index 100% rename from waku/waku_rln_relay/rln.nim rename to logos_delivery/waku/waku_rln_relay/rln.nim diff --git a/waku/waku_rln_relay/rln/rln_interface.nim b/logos_delivery/waku/waku_rln_relay/rln/rln_interface.nim similarity index 100% rename from waku/waku_rln_relay/rln/rln_interface.nim rename to logos_delivery/waku/waku_rln_relay/rln/rln_interface.nim diff --git a/waku/waku_rln_relay/rln/wrappers.nim b/logos_delivery/waku/waku_rln_relay/rln/wrappers.nim similarity index 100% rename from waku/waku_rln_relay/rln/wrappers.nim rename to logos_delivery/waku/waku_rln_relay/rln/wrappers.nim diff --git a/waku/waku_rln_relay/rln_relay.nim b/logos_delivery/waku/waku_rln_relay/rln_relay.nim similarity index 99% rename from waku/waku_rln_relay/rln_relay.nim rename to logos_delivery/waku/waku_rln_relay/rln_relay.nim index 7c36300b2..7c9028dd6 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/logos_delivery/waku/waku_rln_relay/rln_relay.nim @@ -26,7 +26,7 @@ import ./nonce_manager import - waku/[ + logos_delivery/waku/[ common/error_handling, waku_relay, # for WakuRelayHandler waku_core, diff --git a/waku/waku_store.nim b/logos_delivery/waku/waku_store.nim similarity index 100% rename from waku/waku_store.nim rename to logos_delivery/waku/waku_store.nim diff --git a/waku/waku_store/client.nim b/logos_delivery/waku/waku_store/client.nim similarity index 100% rename from waku/waku_store/client.nim rename to logos_delivery/waku/waku_store/client.nim diff --git a/waku/waku_store/common.nim b/logos_delivery/waku/waku_store/common.nim similarity index 100% rename from waku/waku_store/common.nim rename to logos_delivery/waku/waku_store/common.nim diff --git a/waku/waku_store/protocol.nim b/logos_delivery/waku/waku_store/protocol.nim similarity index 100% rename from waku/waku_store/protocol.nim rename to logos_delivery/waku/waku_store/protocol.nim diff --git a/waku/waku_store/protocol_metrics.nim b/logos_delivery/waku/waku_store/protocol_metrics.nim similarity index 100% rename from waku/waku_store/protocol_metrics.nim rename to logos_delivery/waku/waku_store/protocol_metrics.nim diff --git a/waku/waku_store/resume.nim b/logos_delivery/waku/waku_store/resume.nim similarity index 100% rename from waku/waku_store/resume.nim rename to logos_delivery/waku/waku_store/resume.nim diff --git a/waku/waku_store/rpc_codec.nim b/logos_delivery/waku/waku_store/rpc_codec.nim similarity index 100% rename from waku/waku_store/rpc_codec.nim rename to logos_delivery/waku/waku_store/rpc_codec.nim diff --git a/waku/waku_store/self_req_handler.nim b/logos_delivery/waku/waku_store/self_req_handler.nim similarity index 100% rename from waku/waku_store/self_req_handler.nim rename to logos_delivery/waku/waku_store/self_req_handler.nim diff --git a/waku/waku_store_sync.nim b/logos_delivery/waku/waku_store_sync.nim similarity index 100% rename from waku/waku_store_sync.nim rename to logos_delivery/waku/waku_store_sync.nim diff --git a/waku/waku_store_sync/codec.nim b/logos_delivery/waku/waku_store_sync/codec.nim similarity index 100% rename from waku/waku_store_sync/codec.nim rename to logos_delivery/waku/waku_store_sync/codec.nim diff --git a/waku/waku_store_sync/common.nim b/logos_delivery/waku/waku_store_sync/common.nim similarity index 100% rename from waku/waku_store_sync/common.nim rename to logos_delivery/waku/waku_store_sync/common.nim diff --git a/waku/waku_store_sync/protocols_metrics.nim b/logos_delivery/waku/waku_store_sync/protocols_metrics.nim similarity index 100% rename from waku/waku_store_sync/protocols_metrics.nim rename to logos_delivery/waku/waku_store_sync/protocols_metrics.nim diff --git a/waku/waku_store_sync/reconciliation.nim b/logos_delivery/waku/waku_store_sync/reconciliation.nim similarity index 100% rename from waku/waku_store_sync/reconciliation.nim rename to logos_delivery/waku/waku_store_sync/reconciliation.nim diff --git a/waku/waku_store_sync/storage/range_processing.nim b/logos_delivery/waku/waku_store_sync/storage/range_processing.nim similarity index 100% rename from waku/waku_store_sync/storage/range_processing.nim rename to logos_delivery/waku/waku_store_sync/storage/range_processing.nim diff --git a/waku/waku_store_sync/storage/seq_storage.nim b/logos_delivery/waku/waku_store_sync/storage/seq_storage.nim similarity index 100% rename from waku/waku_store_sync/storage/seq_storage.nim rename to logos_delivery/waku/waku_store_sync/storage/seq_storage.nim diff --git a/waku/waku_store_sync/storage/storage.nim b/logos_delivery/waku/waku_store_sync/storage/storage.nim similarity index 100% rename from waku/waku_store_sync/storage/storage.nim rename to logos_delivery/waku/waku_store_sync/storage/storage.nim diff --git a/waku/waku_store_sync/transfer.nim b/logos_delivery/waku/waku_store_sync/transfer.nim similarity index 100% rename from waku/waku_store_sync/transfer.nim rename to logos_delivery/waku/waku_store_sync/transfer.nim diff --git a/tests/api/test_api_health.nim b/tests/api/test_api_health.nim index 62fe39b9e..e38439cbd 100644 --- a/tests/api/test_api_health.nim +++ b/tests/api/test_api_health.nim @@ -6,14 +6,15 @@ import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] import - waku, - waku/[waku_node, waku_core, waku_relay/protocol], - waku/node/health_monitor/[topic_health, health_status, protocol_health, health_report], - waku/requests/health_requests, - waku/requests/node_requests, - waku/events/health_events, - waku/common/waku_protocol, - waku/factory/waku_conf + logos_delivery, + logos_delivery/waku/[waku_node, waku_core, waku_relay/protocol], + logos_delivery/waku/node/health_monitor/ + [topic_health, health_status, protocol_health, health_report], + logos_delivery/waku/requests/health_requests, + logos_delivery/waku/requests/node_requests, + logos_delivery/waku/events/health_events, + logos_delivery/waku/common/waku_protocol, + logos_delivery/waku/factory/waku_conf import tools/confutils/cli_args const TestTimeout = chronos.seconds(10) diff --git a/tests/api/test_api_receive.nim b/tests/api/test_api_receive.nim index 85e522afc..3280f0609 100644 --- a/tests/api/test_api_receive.nim +++ b/tests/api/test_api_receive.nim @@ -6,20 +6,20 @@ import libp2p/[peerid, peerinfo, crypto/crypto] import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] import ../waku_archive/archive_utils -import waku/messaging_client +import logos_delivery/messaging/messaging_client +import logos_delivery/messaging/delivery_service/recv_service import - waku, - waku/[ + logos_delivery, + logos_delivery/waku/[ waku_node, waku_core, events/message_events, waku_relay/protocol, waku_archive, waku_archive/common as archive_common, - node/delivery_service/recv_service, ] -import waku/factory/waku_conf +import logos_delivery/waku/factory/waku_conf import tools/confutils/cli_args const TestTimeout = chronos.seconds(60) diff --git a/tests/api/test_api_send.nim b/tests/api/test_api_send.nim index 679d6a419..3e9a4b717 100644 --- a/tests/api/test_api_send.nim +++ b/tests/api/test_api_send.nim @@ -5,8 +5,8 @@ import chronos, testutils/unittests, stew/byteutils, libp2p/[switch, peerinfo] import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] import ../waku_archive/archive_utils -import waku, waku/[waku_node, waku_core, waku_relay/protocol] -import waku/factory/waku_conf +import logos_delivery, logos_delivery/waku/[waku_node, waku_core, waku_relay/protocol] +import logos_delivery/waku/factory/waku_conf import tools/confutils/cli_args type SendEventOutcome {.pure.} = enum diff --git a/tests/api/test_api_subscription.nim b/tests/api/test_api_subscription.nim index 7cb0e981a..e20250791 100644 --- a/tests/api/test_api_subscription.nim +++ b/tests/api/test_api_subscription.nim @@ -5,11 +5,11 @@ import chronos, testutils/unittests, stew/byteutils import libp2p/[peerid, peerinfo, multiaddress, crypto/crypto] import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] -import waku/messaging_client +import logos_delivery/messaging/messaging_client import - waku, - waku/[ + logos_delivery, + logos_delivery/waku/[ waku_node, waku_core, events/message_events, @@ -17,7 +17,7 @@ import node/waku_node/filter, node/subscription_manager, ] -import waku/factory/waku_conf +import logos_delivery/waku/factory/waku_conf import tools/confutils/cli_args const TestTimeout = chronos.seconds(10) diff --git a/tests/api/test_node_conf.nim b/tests/api/test_node_conf.nim index 8798c5cc5..2da1362af 100644 --- a/tests/api/test_node_conf.nim +++ b/tests/api/test_node_conf.nim @@ -4,11 +4,11 @@ import std/[options, json, strutils], results, stint, testutils/unittests import json_serialization, confutils, confutils/std/net import tools/confutils/cli_args, - waku/api/api_conf, - waku/factory/waku_conf, - waku/factory/networks_config, - waku/factory/conf_builder/conf_builder, - waku/common/logging + logos_delivery/waku/api/api_conf, + logos_delivery/waku/factory/waku_conf, + logos_delivery/waku/factory/networks_config, + logos_delivery/waku/factory/conf_builder/conf_builder, + logos_delivery/waku/common/logging # Helper: parse JSON into WakuNodeConf using fieldPairs (same as liblogosdelivery) proc parseWakuNodeConfFromJson(jsonStr: string): Result[WakuNodeConf, string] = @@ -345,7 +345,7 @@ suite "WakuNodeConf JSON -> WakuConf integration": {.push warning[Deprecated]: off.} -import waku/api/api_conf +import logos_delivery/waku/api/api_conf suite "NodeConfig (deprecated) - toWakuConf": test "Minimal configuration": diff --git a/tests/channels/test_reliable_channel_send_receive.nim b/tests/channels/test_reliable_channel_send_receive.nim index dabc4497f..16577899e 100644 --- a/tests/channels/test_reliable_channel_send_receive.nim +++ b/tests/channels/test_reliable_channel_send_receive.nim @@ -6,14 +6,14 @@ import brokers/broker_context import ../testlib/[common, wakucore, wakunode, testasync] -import waku -import waku/[waku_node, waku_core] -import waku/factory/waku_conf -import waku/events/message_events as waku_message_events +import logos_delivery +import logos_delivery/waku/[waku_node, waku_core] +import logos_delivery/waku/factory/waku_conf +import logos_delivery/waku/events/message_events as waku_message_events import tools/confutils/cli_args -import channels/reliable_channel_manager -import channels/encryption/noop_encryption +import logos_delivery/channels/reliable_channel_manager +import logos_delivery/channels/encryption/noop_encryption const TestTimeout = chronos.seconds(15) diff --git a/tests/common/test_base64_codec.nim b/tests/common/test_base64_codec.nim index b9ac9e464..ff2477312 100644 --- a/tests/common/test_base64_codec.nim +++ b/tests/common/test_base64_codec.nim @@ -1,7 +1,7 @@ {.used.} import std/strutils, results, stew/byteutils, testutils/unittests -import waku/common/base64 +import logos_delivery/waku/common/base64 suite "Waku Common - stew base64 wrapper": const TestData = @[ diff --git a/tests/common/test_enr_builder.nim b/tests/common/test_enr_builder.nim index 0cf7bcb55..0c87cf744 100644 --- a/tests/common/test_enr_builder.nim +++ b/tests/common/test_enr_builder.nim @@ -1,7 +1,7 @@ {.used.} import std/[options, net], results, testutils/unittests -import waku/common/enr, ../testlib/wakucore +import logos_delivery/waku/common/enr, ../testlib/wakucore suite "nim-eth ENR - builder and typed record": test "Non-supported private key (ECDSA)": diff --git a/tests/common/test_parse_size.nim b/tests/common/test_parse_size.nim index 009cb9637..708c6f066 100644 --- a/tests/common/test_parse_size.nim +++ b/tests/common/test_parse_size.nim @@ -1,7 +1,7 @@ {.used.} import testutils/unittests, results -import waku/common/utils/parse_size_units +import logos_delivery/waku/common/utils/parse_size_units suite "Size serialization test": test "parse normal sizes": diff --git a/tests/common/test_protobuf_validation.nim b/tests/common/test_protobuf_validation.nim index 30254d3d4..ea81f7ba2 100644 --- a/tests/common/test_protobuf_validation.nim +++ b/tests/common/test_protobuf_validation.nim @@ -1,7 +1,7 @@ {.used.} import testutils/unittests -import waku/common/protobuf +import logos_delivery/waku/common/protobuf ## Fixtures diff --git a/tests/common/test_ratelimit_setting.nim b/tests/common/test_ratelimit_setting.nim index 2bc95fbfb..e33f13db5 100644 --- a/tests/common/test_ratelimit_setting.nim +++ b/tests/common/test_ratelimit_setting.nim @@ -12,8 +12,8 @@ import testutils/unittests import chronos, libp2p/stream/connection import std/[options, tables] -import ../../waku/common/rate_limit/request_limiter -import ../../waku/common/rate_limit/timed_map +import ../../logos_delivery/waku/common/rate_limit/request_limiter +import ../../logos_delivery/waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" diff --git a/tests/common/test_requestratelimiter.nim b/tests/common/test_requestratelimiter.nim index be910b38e..9a662d0bb 100644 --- a/tests/common/test_requestratelimiter.nim +++ b/tests/common/test_requestratelimiter.nim @@ -12,8 +12,8 @@ import testutils/unittests import chronos, libp2p/stream/connection import std/options -import ../../waku/common/rate_limit/request_limiter -import ../../waku/common/rate_limit/timed_map +import ../../logos_delivery/waku/common/rate_limit/request_limiter +import ../../logos_delivery/waku/common/rate_limit/timed_map let proto = "ProtocolDescriptor" diff --git a/tests/common/test_sqlite_migrations.nim b/tests/common/test_sqlite_migrations.nim index 2a9cae609..438c97096 100644 --- a/tests/common/test_sqlite_migrations.nim +++ b/tests/common/test_sqlite_migrations.nim @@ -1,7 +1,8 @@ {.used.} import std/[strutils, os], results, testutils/unittests -import waku/common/databases/db_sqlite {.all.}, ../waku_archive/archive_utils +import + logos_delivery/waku/common/databases/db_sqlite {.all.}, ../waku_archive/archive_utils template sourceDir(): string = currentSourcePath.rsplit(DirSep, 1)[0] diff --git a/tests/common/test_timed_map.nim b/tests/common/test_timed_map.nim index 3b063d9dd..e008b6e22 100644 --- a/tests/common/test_timed_map.nim +++ b/tests/common/test_timed_map.nim @@ -2,7 +2,7 @@ import unittest2 import chronos/timer -import ../../waku/common/rate_limit/timed_map +import ../../logos_delivery/waku/common/rate_limit/timed_map suite "TimedMap": test "put/get": diff --git a/tests/factory/test_node_factory.nim b/tests/factory/test_node_factory.nim index 63dd730c2..a31452c55 100644 --- a/tests/factory/test_node_factory.nim +++ b/tests/factory/test_node_factory.nim @@ -11,7 +11,7 @@ import import tests/testlib/[wakunode, wakucore], - waku/[ + logos_delivery/waku/[ waku_node, net/net_config, waku_enr, @@ -19,7 +19,7 @@ import discovery/waku_discv5, node/waku_metrics, ], - waku/factory/[ + logos_delivery/waku/factory/[ node_factory, internal_config, conf_builder/conf_builder, diff --git a/tests/factory/test_waku_conf.nim b/tests/factory/test_waku_conf.nim index 885e22867..8a033c008 100644 --- a/tests/factory/test_waku_conf.nim +++ b/tests/factory/test_waku_conf.nim @@ -8,10 +8,10 @@ import results, testutils/unittests import - waku/factory/waku_conf, - waku/factory/conf_builder/conf_builder, - waku/factory/networks_config, - waku/common/utils/parse_size_units + logos_delivery/waku/factory/waku_conf, + logos_delivery/waku/factory/conf_builder/conf_builder, + logos_delivery/waku/factory/networks_config, + logos_delivery/waku/common/utils/parse_size_units suite "Waku Conf - build with cluster conf": test "Cluster Conf is passed and relay is enabled": diff --git a/tests/incentivization/test_poc_eligibility.nim b/tests/incentivization/test_poc_eligibility.nim index be9018898..f9f1c53fa 100644 --- a/tests/incentivization/test_poc_eligibility.nim +++ b/tests/incentivization/test_poc_eligibility.nim @@ -3,8 +3,8 @@ import std/options, testutils/unittests, chronos, web3, stint, tests/testlib/testasync import - waku/node/peer_manager, - waku/incentivization/[rpc, eligibility_manager], + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/incentivization/[rpc, eligibility_manager], ../waku_rln_relay/[utils_onchain, utils] const TxHashNonExisting = diff --git a/tests/incentivization/test_poc_reputation.nim b/tests/incentivization/test_poc_reputation.nim index 0547b9744..f64947614 100644 --- a/tests/incentivization/test_poc_reputation.nim +++ b/tests/incentivization/test_poc_reputation.nim @@ -1,6 +1,8 @@ import std/options, testutils/unittests, chronos, web3 -import waku/incentivization/reputation_manager, waku/waku_lightpush_legacy/rpc +import + logos_delivery/waku/incentivization/reputation_manager, + logos_delivery/waku/waku_lightpush_legacy/rpc suite "Waku Incentivization PoC Reputation": var manager {.threadvar.}: ReputationManager diff --git a/tests/incentivization/test_rpc_codec.nim b/tests/incentivization/test_rpc_codec.nim index 30befd8c1..672633113 100644 --- a/tests/incentivization/test_rpc_codec.nim +++ b/tests/incentivization/test_rpc_codec.nim @@ -1,6 +1,6 @@ import std/options, testutils/unittests, chronos, libp2p/crypto/crypto, web3 -import waku/incentivization/[rpc, rpc_codec, common] +import logos_delivery/waku/incentivization/[rpc, rpc_codec, common] suite "Waku Incentivization Eligibility Codec": asyncTest "encode eligibility proof from txid": diff --git a/tests/node/peer_manager/peer_store/test_migrations.nim b/tests/node/peer_manager/peer_store/test_migrations.nim index d6b86a15b..7925af92d 100644 --- a/tests/node/peer_manager/peer_store/test_migrations.nim +++ b/tests/node/peer_manager/peer_store/test_migrations.nim @@ -1,13 +1,15 @@ import std/[options], results, testutils/unittests import - waku/node/peer_manager/peer_store/migrations, + logos_delivery/waku/node/peer_manager/peer_store/migrations, ../../waku_archive/archive_utils, ../../testlib/[simple_mock] import std/[tables, strutils, os], results, chronicles -import waku/common/databases/db_sqlite, waku/common/databases/common +import + logos_delivery/waku/common/databases/db_sqlite, + logos_delivery/waku/common/databases/common suite "Migrations": test "migrate ok": diff --git a/tests/node/peer_manager/peer_store/test_peer_storage.nim b/tests/node/peer_manager/peer_store/test_peer_storage.nim index 871df8644..aaee96ab3 100644 --- a/tests/node/peer_manager/peer_store/test_peer_storage.nim +++ b/tests/node/peer_manager/peer_store/test_peer_storage.nim @@ -1,6 +1,8 @@ import results, testutils/unittests -import waku/node/peer_manager/peer_store/peer_storage, waku/waku_core/peers +import + logos_delivery/waku/node/peer_manager/peer_store/peer_storage, + logos_delivery/waku/waku_core/peers suite "PeerStorage": var peerStorage {.threadvar.}: PeerStorage diff --git a/tests/node/peer_manager/peer_store/test_waku_peer_storage.nim b/tests/node/peer_manager/peer_store/test_waku_peer_storage.nim index bf052205b..e7dd2a151 100644 --- a/tests/node/peer_manager/peer_store/test_waku_peer_storage.nim +++ b/tests/node/peer_manager/peer_store/test_waku_peer_storage.nim @@ -7,7 +7,9 @@ import eth/p2p/discoveryv5/enr, nimcrypto/utils -import waku/waku_core/peers, waku/node/peer_manager/peer_store/waku_peer_storage +import + logos_delivery/waku/waku_core/peers, + logos_delivery/waku/node/peer_manager/peer_store/waku_peer_storage proc `==`(a, b: RemotePeerInfo): bool = let comparisons = @[ diff --git a/tests/node/peer_manager/peer_store/utils.nim b/tests/node/peer_manager/peer_store/utils.nim index 891c5fdab..c7c380b43 100644 --- a/tests/node/peer_manager/peer_store/utils.nim +++ b/tests/node/peer_manager/peer_store/utils.nim @@ -1,7 +1,7 @@ import std/options, results import - waku/node/peer_manager/[waku_peer_store, peer_store/waku_peer_storage], + logos_delivery/waku/node/peer_manager/[waku_peer_store, peer_store/waku_peer_storage], ../../../waku_archive/archive_utils proc newTestWakuPeerStorage*(path: Option[string] = string.none()): WakuPeerStorage = diff --git a/tests/node/peer_manager/test_peer_manager.nim b/tests/node/peer_manager/test_peer_manager.nim index 7697e0af7..25e6f4916 100644 --- a/tests/node/peer_manager/test_peer_manager.nim +++ b/tests/node/peer_manager/test_peer_manager.nim @@ -1,11 +1,11 @@ import chronicles, std/[options, tables, strutils], chronos, testutils/unittests import - waku/node/waku_node, - waku/waku_core, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/waku_core, ../../waku_lightpush/[lightpush_utils], ../../testlib/[wakucore, wakunode, futures, testasync], - waku/node/peer_manager/peer_manager + logos_delivery/waku/node/peer_manager/peer_manager suite "Peer Manager": suite "onPeerMetadata": diff --git a/tests/node/test_wakunode_filter.nim b/tests/node/test_wakunode_filter.nim index b0dbaa198..ebc529bfb 100644 --- a/tests/node/test_wakunode_filter.nim +++ b/tests/node/test_wakunode_filter.nim @@ -8,7 +8,7 @@ import libp2p/[peerstore, crypto/crypto] import - waku/[ + logos_delivery/waku/[ waku_core, node/peer_manager, waku_node, diff --git a/tests/node/test_wakunode_health_monitor.nim b/tests/node/test_wakunode_health_monitor.nim index be779c586..480cb235c 100644 --- a/tests/node/test_wakunode_health_monitor.nim +++ b/tests/node/test_wakunode_health_monitor.nim @@ -5,7 +5,7 @@ import import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_core, common/waku_protocol, node/waku_node, @@ -15,7 +15,6 @@ import node/health_monitor/protocol_health, node/health_monitor/topic_health, node/health_monitor/node_health_monitor, - messaging_client, node/waku_node/relay, node/waku_node/store, node/waku_node/lightpush, @@ -26,7 +25,8 @@ import ] import ../testlib/[wakunode, wakucore], ../waku_archive/archive_utils -import waku/node/subscription_manager +import logos_delivery/waku/node/subscription_manager +import logos_delivery/messaging/messaging_client const MockDLow = 4 # Mocked GossipSub DLow value diff --git a/tests/node/test_wakunode_legacy_lightpush.nim b/tests/node/test_wakunode_legacy_lightpush.nim index cdd29b398..ec61c2cdf 100644 --- a/tests/node/test_wakunode_legacy_lightpush.nim +++ b/tests/node/test_wakunode_legacy_lightpush.nim @@ -8,7 +8,7 @@ import libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ waku_core, node/peer_manager, waku_node, diff --git a/tests/node/test_wakunode_lightpush.nim b/tests/node/test_wakunode_lightpush.nim index 4f5476701..be36b8d98 100644 --- a/tests/node/test_wakunode_lightpush.nim +++ b/tests/node/test_wakunode_lightpush.nim @@ -8,7 +8,8 @@ import libp2p/crypto/crypto import - waku/[waku_core, node/peer_manager, waku_node, waku_lightpush, waku_rln_relay], + logos_delivery/waku/ + [waku_core, node/peer_manager, waku_node, waku_lightpush, waku_rln_relay], ../testlib/[wakucore, wakunode, testasync, futures], ../resources/payloads, ../waku_rln_relay/[rln/waku_rln_relay_utils, utils_onchain] diff --git a/tests/node/test_wakunode_peer_exchange.nim b/tests/node/test_wakunode_peer_exchange.nim index ac263c92f..47bd5b8af 100644 --- a/tests/node/test_wakunode_peer_exchange.nim +++ b/tests/node/test_wakunode_peer_exchange.nim @@ -13,7 +13,7 @@ import brokers/broker_context import - waku/ + logos_delivery/waku/ [waku_node, discovery/waku_discv5, waku_peer_exchange, node/peer_manager, waku_core], ../waku_peer_exchange/utils, ../testlib/[wakucore, wakunode, testasync] diff --git a/tests/node/test_wakunode_peer_manager.nim b/tests/node/test_wakunode_peer_manager.nim index b0c4354cf..09fa4cbe9 100644 --- a/tests/node/test_wakunode_peer_manager.nim +++ b/tests/node/test_wakunode_peer_manager.nim @@ -13,7 +13,7 @@ import from times import getTime, toUnix import - waku/[ + logos_delivery/waku/[ waku_core, node/peer_manager, waku_node, diff --git a/tests/node/test_wakunode_relay_rln.nim b/tests/node/test_wakunode_relay_rln.nim index b78255ce9..e521abcca 100644 --- a/tests/node/test_wakunode_relay_rln.nim +++ b/tests/node/test_wakunode_relay_rln.nim @@ -12,7 +12,7 @@ import from std/times import epochTime import - ../../../waku/[ + ../../../logos_delivery/waku/[ node/peer_manager, waku_core, waku_node, @@ -28,7 +28,7 @@ import ../resources/payloads, ../waku_rln_relay/[utils_static, utils_onchain] -from ../../waku/waku_noise/noise_utils import randomSeqByte +from ../../logos_delivery/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) diff --git a/tests/node/test_wakunode_sharding.nim b/tests/node/test_wakunode_sharding.nim index 88bf63efa..d1b19c361 100644 --- a/tests/node/test_wakunode_sharding.nim +++ b/tests/node/test_wakunode_sharding.nim @@ -11,7 +11,7 @@ import libp2p/protocols/pubsub/pubsub import - waku/[ + logos_delivery/waku/[ waku_core/topics/pubsub_topic, waku_core/topics/sharding, waku_node, diff --git a/tests/node/test_wakunode_store.nim b/tests/node/test_wakunode_store.nim index daa1db682..3d62a17c7 100644 --- a/tests/node/test_wakunode_store.nim +++ b/tests/node/test_wakunode_store.nim @@ -3,7 +3,7 @@ import std/[options, sequtils, sets], testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ common/paging, waku_node, node/peer_manager, diff --git a/tests/node/utils.nim b/tests/node/utils.nim index 61c6c4a5c..e6addf9cf 100644 --- a/tests/node/utils.nim +++ b/tests/node/utils.nim @@ -1,6 +1,7 @@ import std/options, results import - waku/[node/peer_manager, node/waku_node, waku_enr/sharding, common/enr/typed_record], + logos_delivery/waku/ + [node/peer_manager, node/waku_node, waku_enr/sharding, common/enr/typed_record], ../testlib/[wakucore] proc relayShards*(node: WakuNode): RelayShards = diff --git a/tests/persistency/test_backend.nim b/tests/persistency/test_backend.nim index e5689d95f..d375bf3a4 100644 --- a/tests/persistency/test_backend.nim +++ b/tests/persistency/test_backend.nim @@ -3,7 +3,7 @@ import std/options import results import testutils/unittests -import waku/persistency/[types, keys, backend_sqlite] +import logos_delivery/waku/persistency/[types, keys, backend_sqlite] template str(b: seq[byte]): string = var s = newString(b.len) diff --git a/tests/persistency/test_encoding.nim b/tests/persistency/test_encoding.nim index 22bd58209..4912bdcf1 100644 --- a/tests/persistency/test_encoding.nim +++ b/tests/persistency/test_encoding.nim @@ -3,7 +3,7 @@ import std/[algorithm, options, os, times] import chronos, results import testutils/unittests -import waku/persistency/persistency +import logos_delivery/waku/persistency/persistency # Reusable byte-wise comparator (Key has its own `<`, but we sometimes # want to sort `seq[Key]` here without relying on it for double-checking). diff --git a/tests/persistency/test_facade.nim b/tests/persistency/test_facade.nim index 5b5f9eac1..a3af22d91 100644 --- a/tests/persistency/test_facade.nim +++ b/tests/persistency/test_facade.nim @@ -3,7 +3,7 @@ import std/[options, os, strutils, times] import chronos, results import testutils/unittests -import waku/persistency/persistency +import logos_delivery/waku/persistency/persistency proc payload(s: string): seq[byte] = result = newSeq[byte](s.len) diff --git a/tests/persistency/test_keys.nim b/tests/persistency/test_keys.nim index e33020849..d40563aad 100644 --- a/tests/persistency/test_keys.nim +++ b/tests/persistency/test_keys.nim @@ -2,7 +2,7 @@ import std/[algorithm, sequtils] import testutils/unittests -import waku/persistency/[types, keys] +import logos_delivery/waku/persistency/[types, keys] proc cmpBytes(a, b: Key): int = let ab = bytes(a) diff --git a/tests/persistency/test_lifecycle.nim b/tests/persistency/test_lifecycle.nim index 6b1a6ee60..2626cb01b 100644 --- a/tests/persistency/test_lifecycle.nim +++ b/tests/persistency/test_lifecycle.nim @@ -4,8 +4,8 @@ import std/[options, os, times] import chronos, results import testutils/unittests import brokers/[event_broker, request_broker] -import waku/persistency/persistency -import waku/persistency/backend_comm +import logos_delivery/waku/persistency/persistency +import logos_delivery/waku/persistency/backend_comm proc payloadBytes(s: string): seq[byte] = result = newSeq[byte](s.len) diff --git a/tests/persistency/test_sds_persistency.nim b/tests/persistency/test_sds_persistency.nim index ed14f904b..e5e0654d5 100644 --- a/tests/persistency/test_sds_persistency.nim +++ b/tests/persistency/test_sds_persistency.nim @@ -10,9 +10,9 @@ import std/[options, os, times] import chronos, results import testutils/unittests -import waku/persistency/persistency -import waku/persistency/keys -import waku/persistency/sds_persistency +import logos_delivery/waku/persistency/persistency +import logos_delivery/waku/persistency/keys +import logos_delivery/waku/persistency/sds_persistency proc tmpRoot(label: string): string = let p = getTempDir() / ("sds_persistency_test_" & label & "_" & $epochTime().int) diff --git a/tests/persistency/test_singleton.nim b/tests/persistency/test_singleton.nim index f17841611..01542f409 100644 --- a/tests/persistency/test_singleton.nim +++ b/tests/persistency/test_singleton.nim @@ -4,7 +4,7 @@ import std/[os, strutils, times] import chronos, results import testutils/unittests import brokers/multi_request_broker -import waku/persistency/persistency +import logos_delivery/waku/persistency/persistency proc tmpRoot(label: string): string = let p = getTempDir() / ("persistency_singleton_" & label & "_" & $epochTime().int) diff --git a/tests/persistency/test_string_lookup.nim b/tests/persistency/test_string_lookup.nim index 11ac5fed3..46bbce2b6 100644 --- a/tests/persistency/test_string_lookup.nim +++ b/tests/persistency/test_string_lookup.nim @@ -3,7 +3,7 @@ import std/[options, os, times] import chronos, results import testutils/unittests -import waku/persistency/persistency +import logos_delivery/waku/persistency/persistency proc payloadBytes(s: string): seq[byte] = result = newSeq[byte](s.len) diff --git a/tests/test_message_cache.nim b/tests/test_message_cache.nim index 95904f8f2..10dcd2e66 100644 --- a/tests/test_message_cache.nim +++ b/tests/test_message_cache.nim @@ -1,7 +1,10 @@ {.used.} import std/[sets, random], results, stew/byteutils, testutils/unittests -import waku/waku_core, waku/rest_api/message_cache, ./testlib/wakucore +import + logos_delivery/waku/waku_core, + logos_delivery/waku/rest_api/message_cache, + ./testlib/wakucore randomize() diff --git a/tests/test_peer_manager.nim b/tests/test_peer_manager.nim index 608889d32..1ad29b90b 100644 --- a/tests/test_peer_manager.nim +++ b/tests/test_peer_manager.nim @@ -16,7 +16,7 @@ import libp2p/protocols/pubsub/rpc/message, libp2p/peerid import - waku/[ + logos_delivery/waku/[ common/databases/db_sqlite, node/peer_manager/peer_manager, node/peer_manager/peer_store/waku_peer_storage, diff --git a/tests/test_peer_storage.nim b/tests/test_peer_storage.nim index 6cb48d71e..123556b45 100644 --- a/tests/test_peer_storage.nim +++ b/tests/test_peer_storage.nim @@ -2,7 +2,7 @@ import std/options, testutils/unittests, eth/p2p/discoveryv5/enr, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ common/databases/db_sqlite, node/peer_manager/peer_manager, node/peer_manager/peer_store/waku_peer_storage, diff --git a/tests/test_peer_store_extended.nim b/tests/test_peer_store_extended.nim index 16926c7c2..225ac6b9c 100644 --- a/tests/test_peer_store_extended.nim +++ b/tests/test_peer_store_extended.nim @@ -9,7 +9,7 @@ import libp2p/multiaddress, testutils/unittests import - waku/ + logos_delivery/waku/ [node/peer_manager/peer_manager, node/peer_manager/waku_peer_store, waku_core/peers], ./testlib/wakucore diff --git a/tests/test_relay_peer_exchange.nim b/tests/test_relay_peer_exchange.nim index 84976bd9a..058576d4c 100644 --- a/tests/test_relay_peer_exchange.nim +++ b/tests/test_relay_peer_exchange.nim @@ -7,7 +7,11 @@ import libp2p/peerid, libp2p/protocols/pubsub/gossipsub -import waku/waku_core, waku/waku_node, ./testlib/wakucore, ./testlib/wakunode +import + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_node, + ./testlib/wakucore, + ./testlib/wakunode procSuite "Relay (GossipSub) Peer Exchange": asyncTest "Mount relay without peer exchange handler": diff --git a/tests/test_utils_compat.nim b/tests/test_utils_compat.nim index 1394982ef..aa353f8e5 100644 --- a/tests/test_utils_compat.nim +++ b/tests/test_utils_compat.nim @@ -1,7 +1,11 @@ {.used.} import testutils/unittests -import results, waku/waku_core/message, waku/waku_core/time, ./testlib/common +import + results, + logos_delivery/waku/waku_core/message, + logos_delivery/waku/waku_core/time, + ./testlib/common suite "Waku Payload": test "Encode/Decode waku message with timestamp": diff --git a/tests/test_waku.nim b/tests/test_waku.nim index cf5675716..310356a44 100644 --- a/tests/test_waku.nim +++ b/tests/test_waku.nim @@ -2,7 +2,7 @@ import chronos, testutils/unittests, std/options -import waku +import logos_delivery import tools/confutils/cli_args suite "Waku API - Create node": diff --git a/tests/test_waku_dnsdisc.nim b/tests/test_waku_dnsdisc.nim index 758bdb3ca..848f2c441 100644 --- a/tests/test_waku_dnsdisc.nim +++ b/tests/test_waku_dnsdisc.nim @@ -11,9 +11,9 @@ import eth/keys, dnsdisc/builder import - waku/node/peer_manager, - waku/waku_node, - waku/discovery/waku_dnsdisc, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_node, + logos_delivery/waku/discovery/waku_dnsdisc, ./testlib/common, ./testlib/wakucore, ./testlib/wakunode diff --git a/tests/test_waku_enr.nim b/tests/test_waku_enr.nim index 10183adf5..5b1688682 100644 --- a/tests/test_waku_enr.nim +++ b/tests/test_waku_enr.nim @@ -1,7 +1,7 @@ {.used.} import std/[options, sequtils], results, testutils/unittests -import waku/waku_core, waku/waku_enr, ./testlib/wakucore +import logos_delivery/waku/waku_core, logos_delivery/waku/waku_enr, ./testlib/wakucore suite "Waku ENR - Capabilities bitfield": test "check capabilities support": diff --git a/tests/test_waku_keepalive.nim b/tests/test_waku_keepalive.nim index 32cfb245d..8c4845f55 100644 --- a/tests/test_waku_keepalive.nim +++ b/tests/test_waku_keepalive.nim @@ -10,9 +10,9 @@ import libp2p/stream/connection, libp2p/crypto/crypto import - waku/waku_core, - waku/waku_node, - waku/node/health_monitor, + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_node, + logos_delivery/waku/node/health_monitor, ./testlib/wakucore, ./testlib/wakunode diff --git a/tests/test_waku_keystore.nim b/tests/test_waku_keystore.nim index 8fd8ad297..cba5d87b2 100644 --- a/tests/test_waku_keystore.nim +++ b/tests/test_waku_keystore.nim @@ -1,9 +1,9 @@ {.used.} import std/[os, json], chronos, testutils/unittests -import waku/waku_keystore, ./testlib/common +import logos_delivery/waku/waku_keystore, ./testlib/common -from waku/waku_noise/noise_utils import randomSeqByte +from logos_delivery/waku/waku_noise/noise_utils import randomSeqByte procSuite "Credentials test suite": let testAppInfo = AppInfo(application: "test", appIdentifier: "1234", version: "0.1") diff --git a/tests/test_waku_keystore_keyfile.nim b/tests/test_waku_keystore_keyfile.nim index afdb7e44b..4413659e8 100644 --- a/tests/test_waku_keystore_keyfile.nim +++ b/tests/test_waku_keystore_keyfile.nim @@ -1,9 +1,9 @@ {.used.} import std/[json, os], stew/byteutils, testutils/unittests, chronos, eth/keys -import waku/waku_keystore, ./testlib/common +import logos_delivery/waku/waku_keystore, ./testlib/common -from waku/waku_noise/noise_utils import randomSeqByte +from logos_delivery/waku/waku_noise/noise_utils import randomSeqByte suite "KeyFile test suite": test "Create/Save/Load single keyfile": diff --git a/tests/test_waku_metadata.nim b/tests/test_waku_metadata.nim index cfceb89b5..0252d3f77 100644 --- a/tests/test_waku_metadata.nim +++ b/tests/test_waku_metadata.nim @@ -13,7 +13,7 @@ import eth/keys, eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ waku_node, waku_core/topics, waku_core, diff --git a/tests/test_waku_netconfig.nim b/tests/test_waku_netconfig.nim index 0aff64121..697777233 100644 --- a/tests/test_waku_netconfig.nim +++ b/tests/test_waku_netconfig.nim @@ -2,12 +2,12 @@ import chronos, confutils/toml/std/net, libp2p/multiaddress, testutils/unittests -import ./testlib/wakunode, waku/waku_enr/capabilities +import ./testlib/wakunode, logos_delivery/waku/waku_enr/capabilities include - waku/net/net_config, - waku/factory/conf_builder/web_socket_conf_builder, - waku/factory/conf_builder/conf_builder + logos_delivery/waku/net/net_config, + logos_delivery/waku/factory/conf_builder/web_socket_conf_builder, + logos_delivery/waku/factory/conf_builder/conf_builder proc defaultTestWakuFlags(): CapabilitiesBitfield = CapabilitiesBitfield.init( diff --git a/tests/test_waku_noise.nim b/tests/test_waku_noise.nim index 6566f9eed..3709f9176 100644 --- a/tests/test_waku_noise.nim +++ b/tests/test_waku_noise.nim @@ -9,7 +9,7 @@ import libp2p/protobuf/minprotobuf, stew/endians2 import - waku/[ + logos_delivery/waku/[ utils/noise as waku_message_utils, waku_noise/noise_types, waku_noise/noise_utils, diff --git a/tests/test_waku_noise_sessions.nim b/tests/test_waku_noise_sessions.nim index 543653982..8393a7ba5 100644 --- a/tests/test_waku_noise_sessions.nim +++ b/tests/test_waku_noise_sessions.nim @@ -2,7 +2,7 @@ import std/tables, results, stew/byteutils, testutils/unittests import - waku/[ + logos_delivery/waku/[ common/protobuf, utils/noise as waku_message_utils, waku_noise/noise_types, diff --git a/tests/test_waku_protobufs.nim b/tests/test_waku_protobufs.nim index cd5e3dd02..d893f0fde 100644 --- a/tests/test_waku_protobufs.nim +++ b/tests/test_waku_protobufs.nim @@ -2,7 +2,10 @@ import std/[options, sequtils, tables], testutils/unittests, chronos, chronicles import - waku/waku_metadata, waku/waku_metadata/rpc, ./testlib/wakucore, ./testlib/wakunode + logos_delivery/waku/waku_metadata, + logos_delivery/waku/waku_metadata/rpc, + ./testlib/wakucore, + ./testlib/wakunode procSuite "Waku Protobufs": # TODO: Missing test coverage in many encode/decode protobuf functions diff --git a/tests/test_waku_rendezvous.nim b/tests/test_waku_rendezvous.nim index 88845dc25..0ebe648fa 100644 --- a/tests/test_waku_rendezvous.nim +++ b/tests/test_waku_rendezvous.nim @@ -8,14 +8,14 @@ import libp2p/protocols/rendezvous import - waku/waku_core/peers, - waku/waku_core/codecs, - waku/waku_core, - waku/node/waku_node, - waku/node/peer_manager/peer_manager, - waku/waku_rendezvous/protocol, - waku/waku_rendezvous/common, - waku/waku_rendezvous/waku_peer_record, + logos_delivery/waku/waku_core/peers, + logos_delivery/waku/waku_core/codecs, + logos_delivery/waku/waku_core, + logos_delivery/waku/node/waku_node, + logos_delivery/waku/node/peer_manager/peer_manager, + logos_delivery/waku/waku_rendezvous/protocol, + logos_delivery/waku/waku_rendezvous/common, + logos_delivery/waku/waku_rendezvous/waku_peer_record, ./testlib/[wakucore, wakunode] procSuite "Waku Rendezvous": diff --git a/tests/test_waku_switch.nim b/tests/test_waku_switch.nim index 9f11a41a1..c3f635c17 100644 --- a/tests/test_waku_switch.nim +++ b/tests/test_waku_switch.nim @@ -8,7 +8,7 @@ import libp2p/protocols/connectivity/relay/relay, libp2p/protocols/connectivity/relay/client, stew/byteutils -import waku/node/waku_switch, ./testlib/common, ./testlib/wakucore +import logos_delivery/waku/node/waku_switch, ./testlib/common, ./testlib/wakucore proc newCircuitRelayClientSwitch(relayClient: RelayClient): Switch = SwitchBuilder diff --git a/tests/test_wakunode.nim b/tests/test_wakunode.nim index a7f1084fb..574e35d7b 100644 --- a/tests/test_wakunode.nim +++ b/tests/test_wakunode.nim @@ -17,7 +17,9 @@ import eth/p2p/discoveryv5/enr, eth/net/utils import - waku/[waku_core, waku_node, node/peer_manager], ./testlib/wakucore, ./testlib/wakunode + logos_delivery/waku/[waku_core, waku_node, node/peer_manager], + ./testlib/wakucore, + ./testlib/wakunode suite "WakuNode": asyncTest "Protocol matcher works as expected": diff --git a/tests/testlib/futures.nim b/tests/testlib/futures.nim index dad1baec8..2661600d6 100644 --- a/tests/testlib/futures.nim +++ b/tests/testlib/futures.nim @@ -1,6 +1,6 @@ import chronos -import waku/[waku_core/message, waku_store] +import logos_delivery/waku/[waku_core/message, waku_store] const FUTURE_TIMEOUT* = 1.seconds diff --git a/tests/testlib/postgres.nim b/tests/testlib/postgres.nim index 1449a5936..3edff6582 100644 --- a/tests/testlib/postgres.nim +++ b/tests/testlib/postgres.nim @@ -1,6 +1,6 @@ import chronicles, chronos import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver as driver_module, waku_archive/driver/builder, diff --git a/tests/testlib/tables.nim b/tests/testlib/tables.nim index 2abb2d6eb..c6eba9582 100644 --- a/tests/testlib/tables.nim +++ b/tests/testlib/tables.nim @@ -1,6 +1,6 @@ import std/[tables, sequtils, options] -import waku/waku_core/topics, ../testlib/wakucore +import logos_delivery/waku/waku_core/topics, ../testlib/wakucore proc `==`*( table: Table[pubsub_topic.RelayShard, seq[NsContentTopic]], diff --git a/tests/testlib/wakucore.nim b/tests/testlib/wakucore.nim index 0c5b5199d..d681adc31 100644 --- a/tests/testlib/wakucore.nim +++ b/tests/testlib/wakucore.nim @@ -7,7 +7,7 @@ import libp2p/builders, libp2p/crypto/crypto as libp2p_keys, eth/keys as eth_keys -import waku/waku_core, ./common +import logos_delivery/waku/waku_core, ./common export switch diff --git a/tests/testlib/wakunode.nim b/tests/testlib/wakunode.nim index c23854f08..bab8c5764 100644 --- a/tests/testlib/wakunode.nim +++ b/tests/testlib/wakunode.nim @@ -8,7 +8,7 @@ import libp2p/crypto/crypto as libp2p_keys, eth/keys as eth_keys import - waku/[ + logos_delivery/waku/[ waku_node, net/net_config, waku_core/topics, diff --git a/tests/waku_archive/archive_utils.nim b/tests/waku_archive/archive_utils.nim index 498855075..126607c59 100644 --- a/tests/waku_archive/archive_utils.nim +++ b/tests/waku_archive/archive_utils.nim @@ -3,7 +3,7 @@ import std/options, results, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_core, waku_archive, diff --git a/tests/waku_archive/test_driver_postgres.nim b/tests/waku_archive/test_driver_postgres.nim index 34a428615..1295aebb6 100644 --- a/tests/waku_archive/test_driver_postgres.nim +++ b/tests/waku_archive/test_driver_postgres.nim @@ -2,7 +2,7 @@ import std/[sequtils, options], testutils/unittests, chronos import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver/postgres_driver, waku_core, diff --git a/tests/waku_archive/test_driver_postgres_query.nim b/tests/waku_archive/test_driver_postgres_query.nim index 240ac28dd..9a015c2f2 100644 --- a/tests/waku_archive/test_driver_postgres_query.nim +++ b/tests/waku_archive/test_driver_postgres_query.nim @@ -6,7 +6,7 @@ import chronos, chronicles import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver as driver_module, waku_archive/driver/postgres_driver, diff --git a/tests/waku_archive/test_driver_queue.nim b/tests/waku_archive/test_driver_queue.nim index 584ea9d7e..571b3790c 100644 --- a/tests/waku_archive/test_driver_queue.nim +++ b/tests/waku_archive/test_driver_queue.nim @@ -2,7 +2,7 @@ import std/options, results, testutils/unittests import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver/queue_driver/queue_driver {.all.}, waku_archive/driver/queue_driver/index, diff --git a/tests/waku_archive/test_driver_queue_index.nim b/tests/waku_archive/test_driver_queue_index.nim index f34e181af..eb1584ec2 100644 --- a/tests/waku_archive/test_driver_queue_index.nim +++ b/tests/waku_archive/test_driver_queue_index.nim @@ -1,7 +1,9 @@ {.used.} import std/random, testutils/unittests -import waku/waku_core, waku/waku_archive/driver/queue_driver/index +import + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_archive/driver/queue_driver/index var rng = initRand() diff --git a/tests/waku_archive/test_driver_queue_pagination.nim b/tests/waku_archive/test_driver_queue_pagination.nim index 45543c570..1cc18d9ec 100644 --- a/tests/waku_archive/test_driver_queue_pagination.nim +++ b/tests/waku_archive/test_driver_queue_pagination.nim @@ -3,7 +3,7 @@ import std/[options, sequtils, algorithm], testutils/unittests, libp2p/protobuf/minprotobuf import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver/queue_driver/queue_driver {.all.}, waku_archive/driver/queue_driver/index, diff --git a/tests/waku_archive/test_driver_queue_query.nim b/tests/waku_archive/test_driver_queue_query.nim index b93e79bf6..ee371da41 100644 --- a/tests/waku_archive/test_driver_queue_query.nim +++ b/tests/waku_archive/test_driver_queue_query.nim @@ -3,7 +3,7 @@ import std/[options, sequtils, random, algorithm], testutils/unittests, chronos, chronicles import - waku/[ + logos_delivery/waku/[ waku_archive, waku_archive/driver/queue_driver, waku_core, waku_core/message/digest ], ../testlib/common, diff --git a/tests/waku_archive/test_driver_sqlite.nim b/tests/waku_archive/test_driver_sqlite.nim index 5809a8492..1eb30cb44 100644 --- a/tests/waku_archive/test_driver_sqlite.nim +++ b/tests/waku_archive/test_driver_sqlite.nim @@ -2,7 +2,7 @@ import std/sequtils, testutils/unittests, chronos import - waku/[waku_archive, waku_archive/driver/sqlite_driver, waku_core], + logos_delivery/waku/[waku_archive, waku_archive/driver/sqlite_driver, waku_core], ../waku_archive/archive_utils, ../testlib/wakucore diff --git a/tests/waku_archive/test_driver_sqlite_query.nim b/tests/waku_archive/test_driver_sqlite_query.nim index 6ae7c5b9d..fcd52e7fb 100644 --- a/tests/waku_archive/test_driver_sqlite_query.nim +++ b/tests/waku_archive/test_driver_sqlite_query.nim @@ -4,7 +4,7 @@ import std/[options, sequtils, random, algorithm], testutils/unittests, chronos, chronicles import - waku/[waku_archive, waku_core, waku_core/message/digest], + logos_delivery/waku/[waku_archive, waku_core, waku_core/message/digest], ../testlib/common, ../testlib/wakucore, ../waku_archive/archive_utils diff --git a/tests/waku_archive/test_partition_manager.nim b/tests/waku_archive/test_partition_manager.nim index dbfdd846c..e612c88e3 100644 --- a/tests/waku_archive/test_partition_manager.nim +++ b/tests/waku_archive/test_partition_manager.nim @@ -1,7 +1,9 @@ {.used.} import testutils/unittests, chronos -import waku/waku_archive/driver/postgres_driver/partitions_manager, waku/waku_core/time +import + logos_delivery/waku/waku_archive/driver/postgres_driver/partitions_manager, + logos_delivery/waku/waku_core/time suite "Partition Manager": test "Calculate end partition time": diff --git a/tests/waku_archive/test_retention_policy.nim b/tests/waku_archive/test_retention_policy.nim index 394d5711d..5a500d2cf 100644 --- a/tests/waku_archive/test_retention_policy.nim +++ b/tests/waku_archive/test_retention_policy.nim @@ -2,7 +2,7 @@ import std/[sequtils, times], results, testutils/unittests, chronos import - waku/[ + logos_delivery/waku/[ waku_core, waku_core/message/digest, waku_archive, diff --git a/tests/waku_archive/test_waku_archive.nim b/tests/waku_archive/test_waku_archive.nim index 9b235dd57..b6eb8d98e 100644 --- a/tests/waku_archive/test_waku_archive.nim +++ b/tests/waku_archive/test_waku_archive.nim @@ -3,7 +3,7 @@ import std/[options, sequtils], testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ common/databases/db_postgres/dbconn, common/paging, waku_core, diff --git a/tests/waku_core/test_message_digest.nim b/tests/waku_core/test_message_digest.nim index 22a10d84d..babf84f8f 100644 --- a/tests/waku_core/test_message_digest.nim +++ b/tests/waku_core/test_message_digest.nim @@ -1,7 +1,7 @@ {.used.} import std/sequtils, stew/byteutils, stew/endians2, testutils/unittests -import waku/waku_core, ../testlib/wakucore +import logos_delivery/waku/waku_core, ../testlib/wakucore suite "Waku Message - Deterministic hashing": test "digest computation - empty meta field": diff --git a/tests/waku_core/test_namespaced_topics.nim b/tests/waku_core/test_namespaced_topics.nim index 8c3cee1fc..9cb378b57 100644 --- a/tests/waku_core/test_namespaced_topics.nim +++ b/tests/waku_core/test_namespaced_topics.nim @@ -1,7 +1,7 @@ {.used.} import std/options, results, testutils/unittests -import waku/waku_core/topics +import logos_delivery/waku/waku_core/topics suite "Waku Message - Content topics namespacing": test "Stringify namespaced content topic": diff --git a/tests/waku_core/test_peers.nim b/tests/waku_core/test_peers.nim index 0ba3e5b04..246a1d6d8 100644 --- a/tests/waku_core/test_peers.nim +++ b/tests/waku_core/test_peers.nim @@ -8,7 +8,7 @@ import libp2p/peerid, libp2p/errors, confutils/toml/std/net -import waku/[waku_core, waku_enr], ../testlib/wakucore +import logos_delivery/waku/[waku_core, waku_enr], ../testlib/wakucore suite "Waku Core - Peers": test "Peer info parses correctly": diff --git a/tests/waku_core/test_time.nim b/tests/waku_core/test_time.nim index c54afeb36..af0401c84 100644 --- a/tests/waku_core/test_time.nim +++ b/tests/waku_core/test_time.nim @@ -1,7 +1,7 @@ {.used.} import testutils/unittests -import waku/waku_core/time +import logos_delivery/waku/waku_core/time suite "Waku Core - Time": test "Test timestamp conversion": diff --git a/tests/waku_core/topics/test_pubsub_topic.nim b/tests/waku_core/topics/test_pubsub_topic.nim index 4807d30d1..5ebf92b51 100644 --- a/tests/waku_core/topics/test_pubsub_topic.nim +++ b/tests/waku_core/topics/test_pubsub_topic.nim @@ -2,7 +2,7 @@ import std/[options], testutils/unittests, results -import waku/waku_core/topics/pubsub_topic, ../../testlib/[wakucore] +import logos_delivery/waku/waku_core/topics/pubsub_topic, ../../testlib/[wakucore] suite "Static Sharding Functionality": test "Shard Cluster Identification": diff --git a/tests/waku_core/topics/test_sharding.nim b/tests/waku_core/topics/test_sharding.nim index 33c38b430..5979269e8 100644 --- a/tests/waku_core/topics/test_sharding.nim +++ b/tests/waku_core/topics/test_sharding.nim @@ -1,6 +1,6 @@ import std/[options, tables], testutils/unittests -import waku/waku_core/topics, ../../testlib/[wakucore, tables, testutils] +import logos_delivery/waku/waku_core/topics, ../../testlib/[wakucore, tables, testutils] const GenerationZeroShardsCount = 8 const ClusterId = 1 diff --git a/tests/waku_discv5/test_waku_discv5.nim b/tests/waku_discv5/test_waku_discv5.nim index 58d7d5bb8..e7c53a58d 100644 --- a/tests/waku_discv5/test_waku_discv5.nim +++ b/tests/waku_discv5/test_waku_discv5.nim @@ -13,7 +13,7 @@ import libp2p/protocols/rendezvous import - waku/[ + logos_delivery/waku/[ waku_core/topics, waku_core/codecs, waku_enr, diff --git a/tests/waku_discv5/utils.nim b/tests/waku_discv5/utils.nim index 5a69108c5..bbb47308e 100644 --- a/tests/waku_discv5/utils.nim +++ b/tests/waku_discv5/utils.nim @@ -1,7 +1,7 @@ import std/options, chronos, libp2p/crypto/crypto as libp2p_keys, eth/keys as eth_keys import - waku/ + logos_delivery/waku/ [waku_core/topics, waku_enr, discovery/waku_discv5, node/peer_manager/peer_manager], ../testlib/[common, wakucore] diff --git a/tests/waku_enr/test_sharding.nim b/tests/waku_enr/test_sharding.nim index 789f8faec..eddf22448 100644 --- a/tests/waku_enr/test_sharding.nim +++ b/tests/waku_enr/test_sharding.nim @@ -8,7 +8,7 @@ import eth/keys as eth_keys import - waku/[waku_enr, discovery/waku_discv5, waku_core, common/enr], + logos_delivery/waku/[waku_enr, discovery/waku_discv5, waku_core, common/enr], ../testlib/wakucore, ../waku_discv5/utils, ./utils diff --git a/tests/waku_enr/utils.nim b/tests/waku_enr/utils.nim index 7302c2112..c9948e268 100644 --- a/tests/waku_enr/utils.nim +++ b/tests/waku_enr/utils.nim @@ -6,7 +6,9 @@ import libp2p/crypto/crypto as libp2p_keys, eth/keys as eth_keys -import waku/[waku_enr, discovery/waku_discv5, waku_enr/sharding], ../testlib/wakucore +import + logos_delivery/waku/[waku_enr, discovery/waku_discv5, waku_enr/sharding], + ../testlib/wakucore proc newTestEnrRecord*( privKey: libp2p_keys.PrivateKey, diff --git a/tests/waku_filter_v2/test_waku_client.nim b/tests/waku_filter_v2/test_waku_client.nim index b34c22018..c5bd3c558 100644 --- a/tests/waku_filter_v2/test_waku_client.nim +++ b/tests/waku_filter_v2/test_waku_client.nim @@ -3,10 +3,11 @@ import std/[options, sequtils, json], testutils/unittests, results, chronos import - waku/node/peer_manager, - waku/waku_node, - waku/waku_core, - waku/waku_filter_v2/[common, client, subscriptions, protocol, rpc_codec], + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_node, + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_filter_v2/ + [common, client, subscriptions, protocol, rpc_codec], ../testlib/[wakucore, testasync, testutils, futures, sequtils, wakunode], ./waku_filter_utils, ../resources/payloads diff --git a/tests/waku_filter_v2/test_waku_filter_dos_protection.nim b/tests/waku_filter_v2/test_waku_filter_dos_protection.nim index be92fc409..c55a9b4cd 100644 --- a/tests/waku_filter_v2/test_waku_filter_dos_protection.nim +++ b/tests/waku_filter_v2/test_waku_filter_dos_protection.nim @@ -9,8 +9,8 @@ import libp2p/peerstore import - waku/[node/peer_manager, waku_core], - waku/waku_filter_v2/[common, client, subscriptions, protocol], + logos_delivery/waku/[node/peer_manager, waku_core], + logos_delivery/waku/waku_filter_v2/[common, client, subscriptions, protocol], ../testlib/[wakucore, testasync, futures], ./waku_filter_utils diff --git a/tests/waku_filter_v2/waku_filter_utils.nim b/tests/waku_filter_v2/waku_filter_utils.nim index 2f04ceb36..fce601a09 100644 --- a/tests/waku_filter_v2/waku_filter_utils.nim +++ b/tests/waku_filter_v2/waku_filter_utils.nim @@ -1,7 +1,7 @@ import std/[options, tables, sets, algorithm], chronos, chronicles, os import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_filter_v2, waku_filter_v2/client, diff --git a/tests/waku_keystore/utils.nim b/tests/waku_keystore/utils.nim index 8af2d2a26..9d86df9bb 100644 --- a/tests/waku_keystore/utils.nim +++ b/tests/waku_keystore/utils.nim @@ -4,7 +4,8 @@ import stint import - waku/[waku_keystore/protocol_types, waku_rln_relay, waku_rln_relay/protocol_types] + logos_delivery/waku/ + [waku_keystore/protocol_types, waku_rln_relay, waku_rln_relay/protocol_types] func fromStrToBytesLe*(v: string): seq[byte] = try: diff --git a/tests/waku_lightpush/lightpush_utils.nim b/tests/waku_lightpush/lightpush_utils.nim index 7bd44a311..8eb133d99 100644 --- a/tests/waku_lightpush/lightpush_utils.nim +++ b/tests/waku_lightpush/lightpush_utils.nim @@ -3,12 +3,12 @@ import std/options, chronos, chronicles, libp2p/crypto/crypto import - waku/node/peer_manager, - waku/waku_core, - waku/waku_core/topics/sharding, - waku/waku_lightpush, - waku/waku_lightpush/[client, common], - waku/common/rate_limit/setting, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_core, + logos_delivery/waku/waku_core/topics/sharding, + logos_delivery/waku/waku_lightpush, + logos_delivery/waku/waku_lightpush/[client, common], + logos_delivery/waku/common/rate_limit/setting, ../testlib/[common, wakucore] proc newTestWakuLightpushNode*( diff --git a/tests/waku_lightpush/test_client.nim b/tests/waku_lightpush/test_client.nim index 0bc9afdd4..c7bf7b4a6 100644 --- a/tests/waku_lightpush/test_client.nim +++ b/tests/waku_lightpush/test_client.nim @@ -8,7 +8,7 @@ import libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_core, waku_lightpush, diff --git a/tests/waku_lightpush/test_ratelimit.nim b/tests/waku_lightpush/test_ratelimit.nim index e023bf3f5..8500ad8b2 100644 --- a/tests/waku_lightpush/test_ratelimit.nim +++ b/tests/waku_lightpush/test_ratelimit.nim @@ -3,7 +3,8 @@ import std/options, testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[node/peer_manager, waku_core, waku_lightpush, waku_lightpush/client], + logos_delivery/waku/ + [node/peer_manager, waku_core, waku_lightpush, waku_lightpush/client], ../testlib/wakucore, ./lightpush_utils diff --git a/tests/waku_lightpush_legacy/lightpush_utils.nim b/tests/waku_lightpush_legacy/lightpush_utils.nim index d5602173a..1e549859b 100644 --- a/tests/waku_lightpush_legacy/lightpush_utils.nim +++ b/tests/waku_lightpush_legacy/lightpush_utils.nim @@ -6,10 +6,10 @@ logScope: topics = "test waku_lightpush_legacy" import - waku/node/peer_manager, - waku/waku_lightpush_legacy, - waku/waku_lightpush_legacy/[client, common], - waku/common/rate_limit/setting, + logos_delivery/waku/node/peer_manager, + logos_delivery/waku/waku_lightpush_legacy, + logos_delivery/waku/waku_lightpush_legacy/[client, common], + logos_delivery/waku/common/rate_limit/setting, ../testlib/[common, wakucore] proc newTestWakuLegacyLightpushNode*( diff --git a/tests/waku_lightpush_legacy/test_client.nim b/tests/waku_lightpush_legacy/test_client.nim index 3d3027e9c..d60595a1e 100644 --- a/tests/waku_lightpush_legacy/test_client.nim +++ b/tests/waku_lightpush_legacy/test_client.nim @@ -3,7 +3,7 @@ import std/[options, strscans], testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_core, waku_lightpush_legacy, diff --git a/tests/waku_lightpush_legacy/test_ratelimit.nim b/tests/waku_lightpush_legacy/test_ratelimit.nim index ae5f5ed28..345501d0b 100644 --- a/tests/waku_lightpush_legacy/test_ratelimit.nim +++ b/tests/waku_lightpush_legacy/test_ratelimit.nim @@ -3,7 +3,7 @@ import std/options, testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_core, waku_lightpush_legacy, diff --git a/tests/waku_peer_exchange/test_protocol.nim b/tests/waku_peer_exchange/test_protocol.nim index 29ec45d1e..93c522c06 100644 --- a/tests/waku_peer_exchange/test_protocol.nim +++ b/tests/waku_peer_exchange/test_protocol.nim @@ -9,7 +9,7 @@ import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_node, node/peer_manager, discovery/waku_discv5, diff --git a/tests/waku_peer_exchange/test_rpc_codec.nim b/tests/waku_peer_exchange/test_rpc_codec.nim index 84aec7ec4..ca86ce294 100644 --- a/tests/waku_peer_exchange/test_rpc_codec.nim +++ b/tests/waku_peer_exchange/test_rpc_codec.nim @@ -11,7 +11,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ node/peer_manager, discovery/waku_discv5, waku_peer_exchange/rpc, diff --git a/tests/waku_peer_exchange/utils.nim b/tests/waku_peer_exchange/utils.nim index ce7660bf0..c72405c51 100644 --- a/tests/waku_peer_exchange/utils.nim +++ b/tests/waku_peer_exchange/utils.nim @@ -11,7 +11,7 @@ import eth/p2p/discoveryv5/enr import - waku/[ + logos_delivery/waku/[ waku_node, discovery/waku_discv5, waku_peer_exchange, diff --git a/tests/waku_relay/test_message_id.nim b/tests/waku_relay/test_message_id.nim index 6dcd72ab7..96022a2d9 100644 --- a/tests/waku_relay/test_message_id.nim +++ b/tests/waku_relay/test_message_id.nim @@ -5,7 +5,7 @@ import nimcrypto/sha2, libp2p/protocols/pubsub/rpc/messages -import waku/waku_relay/message_id +import logos_delivery/waku/waku_relay/message_id suite "Message ID Provider": test "Non-empty string": diff --git a/tests/waku_relay/test_protocol.nim b/tests/waku_relay/test_protocol.nim index 46032b693..77466d32a 100644 --- a/tests/waku_relay/test_protocol.nim +++ b/tests/waku_relay/test_protocol.nim @@ -10,7 +10,7 @@ import std/json import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_relay/protocol, waku_relay, diff --git a/tests/waku_relay/test_wakunode_relay.nim b/tests/waku_relay/test_wakunode_relay.nim index a687119bd..58e4b734f 100644 --- a/tests/waku_relay/test_wakunode_relay.nim +++ b/tests/waku_relay/test_wakunode_relay.nim @@ -9,7 +9,7 @@ import libp2p/protocols/pubsub/pubsub, libp2p/protocols/pubsub/gossipsub import - waku/[waku_core, node/peer_manager, waku_node, waku_relay], + logos_delivery/waku/[waku_core, node/peer_manager, waku_node, waku_relay], ../testlib/testutils, ../testlib/wakucore, ../testlib/wakunode diff --git a/tests/waku_relay/utils.nim b/tests/waku_relay/utils.nim index 069600106..4a37a3292 100644 --- a/tests/waku_relay/utils.nim +++ b/tests/waku_relay/utils.nim @@ -13,7 +13,7 @@ import brokers/broker_context from std/times import epochTime import - waku/[ + logos_delivery/waku/[ waku_relay, node/waku_node, node/peer_manager, waku_core, waku_node, waku_rln_relay ], ../waku_store/store_utils, diff --git a/tests/waku_rln_relay/rln/test_rln_interface.nim b/tests/waku_rln_relay/rln/test_rln_interface.nim index 7b8ea3878..5ace0c8bb 100644 --- a/tests/waku_rln_relay/rln/test_rln_interface.nim +++ b/tests/waku_rln_relay/rln/test_rln_interface.nim @@ -1,7 +1,7 @@ import testutils/unittests, results -import waku/waku_rln_relay/rln/rln_interface -import waku/waku_rln_relay/rln/wrappers +import logos_delivery/waku/waku_rln_relay/rln/rln_interface +import logos_delivery/waku/waku_rln_relay/rln/wrappers suite "Vec_uint8": suite "toVecUint8": diff --git a/tests/waku_rln_relay/rln/test_wrappers.nim b/tests/waku_rln_relay/rln/test_wrappers.nim index 8cd9251c0..8d969a31b 100644 --- a/tests/waku_rln_relay/rln/test_wrappers.nim +++ b/tests/waku_rln_relay/rln/test_wrappers.nim @@ -1,6 +1,9 @@ import testutils/unittests, results -import waku/waku_rln_relay/rln, waku/waku_rln_relay/rln/wrappers, ./waku_rln_relay_utils +import + logos_delivery/waku/waku_rln_relay/rln, + logos_delivery/waku/waku_rln_relay/rln/wrappers, + ./waku_rln_relay_utils suite "membershipKeyGen": test "ok": 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 4bdcbbdc3..065610065 100644 --- a/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim +++ b/tests/waku_rln_relay/rln/waku_rln_relay_utils.nim @@ -1,8 +1,8 @@ import std/tempfiles import - waku/waku_rln_relay, - waku/waku_rln_relay/[ + logos_delivery/waku/waku_rln_relay, + logos_delivery/waku/waku_rln_relay/[ group_manager, rln, conversion_utils, constants, protocol_types, protocol_metrics, nonce_manager, ] diff --git a/tests/waku_rln_relay/test_rln_contract_deployment.nim b/tests/waku_rln_relay/test_rln_contract_deployment.nim index 5a9624ce8..f903a2382 100644 --- a/tests/waku_rln_relay/test_rln_contract_deployment.nim +++ b/tests/waku_rln_relay/test_rln_contract_deployment.nim @@ -5,7 +5,7 @@ import std/[options, os], results, testutils/unittests, chronos, web3 import - waku/[ + logos_delivery/waku/[ waku_rln_relay, waku_rln_relay/conversion_utils, waku_rln_relay/group_manager/on_chain/group_manager, diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index 6af5bb0f2..e818af94f 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -17,7 +17,7 @@ import tests/testlib/testutils import - waku/[ + logos_delivery/waku/[ waku_rln_relay, waku_rln_relay/protocol_types, waku_rln_relay/constants, diff --git a/tests/waku_rln_relay/test_rln_nonce_manager.nim b/tests/waku_rln_relay/test_rln_nonce_manager.nim index 3a473f186..fb24f0e29 100644 --- a/tests/waku_rln_relay/test_rln_nonce_manager.nim +++ b/tests/waku_rln_relay/test_rln_nonce_manager.nim @@ -1,7 +1,7 @@ {.used.} import testutils/unittests, chronos, os -import waku/waku_rln_relay/nonce_manager +import logos_delivery/waku/waku_rln_relay/nonce_manager suite "Nonce manager": test "should initialize successfully": diff --git a/tests/waku_rln_relay/test_waku_rln_relay.nim b/tests/waku_rln_relay/test_waku_rln_relay.nim index 7694b8112..e71bc3593 100644 --- a/tests/waku_rln_relay/test_waku_rln_relay.nim +++ b/tests/waku_rln_relay/test_waku_rln_relay.nim @@ -12,7 +12,7 @@ import import brokers/broker_context import - waku/[ + logos_delivery/waku/[ waku_core, waku_rln_relay, waku_rln_relay/rln, diff --git a/tests/waku_rln_relay/test_wakunode_rln_relay.nim b/tests/waku_rln_relay/test_wakunode_rln_relay.nim index 414a445fa..0056e575e 100644 --- a/tests/waku_rln_relay/test_wakunode_rln_relay.nim +++ b/tests/waku_rln_relay/test_wakunode_rln_relay.nim @@ -11,7 +11,7 @@ import brokers/broker_context import - waku/[waku_core, waku_node, waku_rln_relay], + logos_delivery/waku/[waku_core, waku_node, waku_rln_relay], ../testlib/[wakucore, futures, wakunode, testutils], ./utils_onchain, ./rln/waku_rln_relay_utils diff --git a/tests/waku_rln_relay/utils_offchain.nim b/tests/waku_rln_relay/utils_offchain.nim index e0e1bd1f7..575a3c525 100644 --- a/tests/waku_rln_relay/utils_offchain.nim +++ b/tests/waku_rln_relay/utils_offchain.nim @@ -11,7 +11,7 @@ import from std/times import epochTime import - ../../../waku/ + ../../../logos_delivery/waku/ [node/waku_node, node/peer_manager, waku_core, waku_node, waku_rln_relay], ../waku_store/store_utils, ../waku_archive/archive_utils, diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index db07d3cd6..f8fa11d28 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -19,7 +19,7 @@ import results import - waku/[ + logos_delivery/waku/[ waku_rln_relay, waku_rln_relay/protocol_types, waku_rln_relay/constants, diff --git a/tests/waku_store/store_utils.nim b/tests/waku_store/store_utils.nim index 4586a0631..1e241ec95 100644 --- a/tests/waku_store/store_utils.nim +++ b/tests/waku_store/store_utils.nim @@ -3,7 +3,8 @@ import std/options, chronos, chronicles import - waku/[node/peer_manager, waku_store, waku_store/client], ../testlib/[common, wakucore] + logos_delivery/waku/[node/peer_manager, waku_store, waku_store/client], + ../testlib/[common, wakucore] proc newTestWakuStore*( switch: Switch, handler: StoreQueryRequestHandler diff --git a/tests/waku_store/test_client.nim b/tests/waku_store/test_client.nim index d9c94a10c..ce9f5f802 100644 --- a/tests/waku_store/test_client.nim +++ b/tests/waku_store/test_client.nim @@ -3,7 +3,8 @@ import std/[options, sets], testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[node/peer_manager, waku_core, waku_store, waku_store/client, common/paging], + logos_delivery/waku/ + [node/peer_manager, waku_core, waku_store, waku_store/client, common/paging], ../testlib/[wakucore, testasync, futures], ./store_utils diff --git a/tests/waku_store/test_resume.nim b/tests/waku_store/test_resume.nim index eb11b8f8e..612aa1e1d 100644 --- a/tests/waku_store/test_resume.nim +++ b/tests/waku_store/test_resume.nim @@ -3,7 +3,7 @@ import std/[options, net], testutils/unittests, chronos, results import - waku/[ + logos_delivery/waku/[ node/peer_manager, node/waku_node, waku_core, diff --git a/tests/waku_store/test_rpc_codec.nim b/tests/waku_store/test_rpc_codec.nim index 961e3c029..43543560a 100644 --- a/tests/waku_store/test_rpc_codec.nim +++ b/tests/waku_store/test_rpc_codec.nim @@ -2,7 +2,7 @@ import std/options, testutils/unittests, chronos import - waku/ + logos_delivery/waku/ [common/protobuf, common/paging, waku_core, waku_store/common, waku_store/rpc_codec], ../testlib/wakucore diff --git a/tests/waku_store/test_waku_store.nim b/tests/waku_store/test_waku_store.nim index 815b3ac7d..b210e6b44 100644 --- a/tests/waku_store/test_waku_store.nim +++ b/tests/waku_store/test_waku_store.nim @@ -3,7 +3,7 @@ import std/options, testutils/unittests, chronos, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ common/paging, node/peer_manager, waku_core, diff --git a/tests/waku_store/test_wakunode_store.nim b/tests/waku_store/test_wakunode_store.nim index fa73cd16d..478a91178 100644 --- a/tests/waku_store/test_wakunode_store.nim +++ b/tests/waku_store/test_wakunode_store.nim @@ -13,7 +13,7 @@ import libp2p/protocols/pubsub/pubsub, libp2p/protocols/pubsub/gossipsub import - waku/[ + logos_delivery/waku/[ common/paging, waku_core, waku_core/message/digest, diff --git a/tests/waku_store_sync/sync_utils.nim b/tests/waku_store_sync/sync_utils.nim index 888b10a83..38538b354 100644 --- a/tests/waku_store_sync/sync_utils.nim +++ b/tests/waku_store_sync/sync_utils.nim @@ -1,7 +1,7 @@ import std/[options, random], chronos, chronicles import - waku/[ + logos_delivery/waku/[ node/peer_manager, waku_core, waku_store_sync/common, diff --git a/tests/waku_store_sync/test_codec.nim b/tests/waku_store_sync/test_codec.nim index fdfd3f2f0..c9bce7111 100644 --- a/tests/waku_store_sync/test_codec.nim +++ b/tests/waku_store_sync/test_codec.nim @@ -3,11 +3,11 @@ import std/[options, random], testutils/unittests, chronos import - ../../waku/waku_core, - ../../waku/waku_core/message/digest, - ../../waku/waku_core/time, - ../../waku/waku_store_sync/common, - ../../waku/waku_store_sync/codec, + ../../logos_delivery/waku/waku_core, + ../../logos_delivery/waku/waku_core/message/digest, + ../../logos_delivery/waku/waku_core/time, + ../../logos_delivery/waku/waku_store_sync/common, + ../../logos_delivery/waku/waku_store_sync/codec, ./sync_utils proc randomItemSet(count: int, startTime: Timestamp, rng: var Rand): ItemSet = diff --git a/tests/waku_store_sync/test_protocol.nim b/tests/waku_store_sync/test_protocol.nim index 3ffa7ad4a..62fd568a1 100644 --- a/tests/waku_store_sync/test_protocol.nim +++ b/tests/waku_store_sync/test_protocol.nim @@ -8,7 +8,7 @@ import import chronos, chronos/asyncsync import nimcrypto import - ../../waku/[ + ../../logos_delivery/waku/[ node/peer_manager, waku_core, waku_core/message, diff --git a/tests/waku_store_sync/test_range_split.nim b/tests/waku_store_sync/test_range_split.nim index fe5252416..9015d29d8 100644 --- a/tests/waku_store_sync/test_range_split.nim +++ b/tests/waku_store_sync/test_range_split.nim @@ -1,9 +1,9 @@ import unittest, nimcrypto, std/sequtils, results -import ../../waku/waku_store_sync/[reconciliation, common] -import ../../waku/waku_store_sync/storage/seq_storage -import ../../waku/waku_core/message/digest -import ../../waku/waku_core/topics/pubsub_topic -import ../../waku/waku_core/topics/content_topic +import ../../logos_delivery/waku/waku_store_sync/[reconciliation, common] +import ../../logos_delivery/waku/waku_store_sync/storage/seq_storage +import ../../logos_delivery/waku/waku_core/message/digest +import ../../logos_delivery/waku/waku_core/topics/pubsub_topic +import ../../logos_delivery/waku/waku_core/topics/content_topic proc toDigest(s: string): WakuMessageHash = let d = nimcrypto.keccak256.digest((s & "").toOpenArrayByte(0, (s.len - 1))) diff --git a/tests/waku_store_sync/test_state_transition.nim b/tests/waku_store_sync/test_state_transition.nim index 2e6bb30c3..d8129e0e5 100644 --- a/tests/waku_store_sync/test_state_transition.nim +++ b/tests/waku_store_sync/test_state_transition.nim @@ -1,9 +1,9 @@ import unittest, nimcrypto, std/sequtils -import ../../waku/waku_store_sync/[reconciliation, common] -import ../../waku/waku_store_sync/storage/seq_storage -import ../../waku/waku_core/message/digest -import ../../waku/waku_core/topics/pubsub_topic -import ../../waku/waku_core/topics/content_topic +import ../../logos_delivery/waku/waku_store_sync/[reconciliation, common] +import ../../logos_delivery/waku/waku_store_sync/storage/seq_storage +import ../../logos_delivery/waku/waku_core/message/digest +import ../../logos_delivery/waku/waku_core/topics/pubsub_topic +import ../../logos_delivery/waku/waku_core/topics/content_topic proc toDigest*(s: string): WakuMessageHash = let d = nimcrypto.keccak256.digest((s & "").toOpenArrayByte(0, s.high)) diff --git a/tests/waku_store_sync/test_storage.nim b/tests/waku_store_sync/test_storage.nim index 930d3f7dc..ba0879375 100644 --- a/tests/waku_store_sync/test_storage.nim +++ b/tests/waku_store_sync/test_storage.nim @@ -3,9 +3,9 @@ import std/[options, random, sequtils, packedsets], testutils/unittests, chronos import - ../../waku/waku_core, - ../../waku/waku_store_sync/common, - ../../waku/waku_store_sync/storage/seq_storage, + ../../logos_delivery/waku/waku_core, + ../../logos_delivery/waku/waku_store_sync/common, + ../../logos_delivery/waku/waku_store_sync/storage/seq_storage, ./sync_utils suite "Waku Sync Storage": diff --git a/tests/wakunode2/test_app.nim b/tests/wakunode2/test_app.nim index 8dc9e3582..45a268ed6 100644 --- a/tests/wakunode2/test_app.nim +++ b/tests/wakunode2/test_app.nim @@ -7,9 +7,9 @@ import chronos, libp2p/[crypto/crypto, crypto/secp, multiaddress, switch], tests/testlib/[wakucore, wakunode], - waku/factory/conf_builder/conf_builder + logos_delivery/waku/factory/conf_builder/conf_builder -include waku/factory/waku, waku/common/enr/typed_record +include logos_delivery/waku/factory/waku, logos_delivery/waku/common/enr/typed_record suite "Wakunode2 - Waku": test "compilation version should be reported": diff --git a/tests/wakunode2/test_cli_args.nim b/tests/wakunode2/test_cli_args.nim index d08544c2c..36bb947f2 100644 --- a/tests/wakunode2/test_cli_args.nim +++ b/tests/wakunode2/test_cli_args.nim @@ -14,11 +14,11 @@ import import tools/confutils/cli_args import - ../../waku/factory/networks_config, - ../../waku/factory/waku_conf, - ../../waku/common/logging, - ../../waku/common/utils/parse_size_units, - ../../waku/waku_core/message/default_values + ../../logos_delivery/waku/factory/networks_config, + ../../logos_delivery/waku/factory/waku_conf, + ../../logos_delivery/waku/common/logging, + ../../logos_delivery/waku/common/utils/parse_size_units, + ../../logos_delivery/waku/waku_core/message/default_values suite "Waku external config - default values": test "Default sharding value": diff --git a/tests/wakunode2/test_validators.nim b/tests/wakunode2/test_validators.nim index 83928e4df..dc6e8eb28 100644 --- a/tests/wakunode2/test_validators.nim +++ b/tests/wakunode2/test_validators.nim @@ -12,7 +12,8 @@ import libp2p/multihash, secp256k1 import - waku/[waku_core, node/peer_manager, waku_node, factory/validator_signed], + logos_delivery/waku/ + [waku_core, node/peer_manager, waku_node, factory/validator_signed], tools/confutils/cli_args, ../testlib/wakucore, ../testlib/wakunode diff --git a/tests/wakunode_rest/test_rest_admin.nim b/tests/wakunode_rest/test_rest_admin.nim index ef82b8dfc..e1247fb62 100644 --- a/tests/wakunode_rest/test_rest_admin.nim +++ b/tests/wakunode_rest/test_rest_admin.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ waku_core, waku_node, waku_filter_v2/client, diff --git a/tests/wakunode_rest/test_rest_cors.nim b/tests/wakunode_rest/test_rest_cors.nim index 0393b0d72..2d198f878 100644 --- a/tests/wakunode_rest/test_rest_cors.nim +++ b/tests/wakunode_rest/test_rest_cors.nim @@ -8,7 +8,7 @@ import libp2p/multiaddress, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ waku_node, node/waku_node as waku_node2, rest_api/endpoint/server, diff --git a/tests/wakunode_rest/test_rest_debug.nim b/tests/wakunode_rest/test_rest_debug.nim index 1171f5878..923f28fa4 100644 --- a/tests/wakunode_rest/test_rest_debug.nim +++ b/tests/wakunode_rest/test_rest_debug.nim @@ -9,7 +9,7 @@ import libp2p/multiaddress, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ waku_node, node/waku_node as waku_node2, # TODO: Remove after moving `git_version` to the app code. diff --git a/tests/wakunode_rest/test_rest_debug_serdes.nim b/tests/wakunode_rest/test_rest_debug_serdes.nim index d3232e571..f14912b85 100644 --- a/tests/wakunode_rest/test_rest_debug_serdes.nim +++ b/tests/wakunode_rest/test_rest_debug_serdes.nim @@ -1,7 +1,9 @@ {.used.} import results, stew/byteutils, testutils/unittests, json_serialization -import waku/rest_api/endpoint/serdes, waku/rest_api/endpoint/debug/types +import + logos_delivery/waku/rest_api/endpoint/serdes, + logos_delivery/waku/rest_api/endpoint/debug/types suite "Waku v2 REST API - Debug - serialization": suite "DebugWakuInfo - decode": diff --git a/tests/wakunode_rest/test_rest_filter.nim b/tests/wakunode_rest/test_rest_filter.nim index 1a4731d6a..76de0112e 100644 --- a/tests/wakunode_rest/test_rest_filter.nim +++ b/tests/wakunode_rest/test_rest_filter.nim @@ -8,7 +8,7 @@ import presto/client as presto_client, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ rest_api/message_cache, waku_core, waku_node, diff --git a/tests/wakunode_rest/test_rest_health.nim b/tests/wakunode_rest/test_rest_health.nim index 0bdb93123..1f51877ec 100644 --- a/tests/wakunode_rest/test_rest_health.nim +++ b/tests/wakunode_rest/test_rest_health.nim @@ -9,7 +9,7 @@ import libp2p/multiaddress, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ common/waku_protocol, waku_node, node/waku_node as waku_node2, diff --git a/tests/wakunode_rest/test_rest_lightpush.nim b/tests/wakunode_rest/test_rest_lightpush.nim index deba7de22..ae417d11a 100644 --- a/tests/wakunode_rest/test_rest_lightpush.nim +++ b/tests/wakunode_rest/test_rest_lightpush.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ rest_api/message_cache, waku_core, waku_node, diff --git a/tests/wakunode_rest/test_rest_lightpush_legacy.nim b/tests/wakunode_rest/test_rest_lightpush_legacy.nim index 4043eeed9..5b2e3494e 100644 --- a/tests/wakunode_rest/test_rest_lightpush_legacy.nim +++ b/tests/wakunode_rest/test_rest_lightpush_legacy.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ rest_api/message_cache, waku_core, waku_node, diff --git a/tests/wakunode_rest/test_rest_relay.nim b/tests/wakunode_rest/test_rest_relay.nim index a98b75520..def933021 100644 --- a/tests/wakunode_rest/test_rest_relay.nim +++ b/tests/wakunode_rest/test_rest_relay.nim @@ -9,7 +9,7 @@ import libp2p/crypto/crypto import brokers/broker_context import - waku/[ + logos_delivery/waku/[ common/base64, waku_core, waku_node, diff --git a/tests/wakunode_rest/test_rest_relay_serdes.nim b/tests/wakunode_rest/test_rest_relay_serdes.nim index 21d21e281..24ce80b9e 100644 --- a/tests/wakunode_rest/test_rest_relay_serdes.nim +++ b/tests/wakunode_rest/test_rest_relay_serdes.nim @@ -2,7 +2,7 @@ import results, stew/byteutils, unittest2, json_serialization import - waku/ + logos_delivery/waku/ [common/base64, rest_api/endpoint/serdes, rest_api/endpoint/relay/types, waku_core] suite "Waku v2 Rest API - Relay - serialization": diff --git a/tests/wakunode_rest/test_rest_serdes.nim b/tests/wakunode_rest/test_rest_serdes.nim index 2237e9216..12f0ae9da 100644 --- a/tests/wakunode_rest/test_rest_serdes.nim +++ b/tests/wakunode_rest/test_rest_serdes.nim @@ -1,7 +1,9 @@ {.used.} import results, stew/byteutils, chronicles, unittest2, json_serialization -import waku/rest_api/endpoint/serdes, waku/rest_api/endpoint/debug/types +import + logos_delivery/waku/rest_api/endpoint/serdes, + logos_delivery/waku/rest_api/endpoint/debug/types # TODO: Decouple this test suite from the `debug_rest_interface` module by defining # private custom types for this test suite module diff --git a/tests/wakunode_rest/test_rest_store.nim b/tests/wakunode_rest/test_rest_store.nim index 01ccea9dd..0f4ed10ea 100644 --- a/tests/wakunode_rest/test_rest_store.nim +++ b/tests/wakunode_rest/test_rest_store.nim @@ -10,7 +10,7 @@ import presto/client as presto_client, libp2p/crypto/crypto import - waku/[ + logos_delivery/waku/[ waku_core/message, waku_core/message/digest, waku_core/topics, diff --git a/tools/confutils/cli_args.nim b/tools/confutils/cli_args.nim index f965c3a06..cbd707a2d 100644 --- a/tools/confutils/cli_args.nim +++ b/tools/confutils/cli_args.nim @@ -21,9 +21,9 @@ import json import - waku/factory/[waku_conf, conf_builder/conf_builder, networks_config], - waku/common/[logging], - waku/[ + logos_delivery/waku/factory/[waku_conf, conf_builder/conf_builder, networks_config], + logos_delivery/waku/common/[logging], + logos_delivery/waku/[ waku_enr, node/peer_manager, waku_core/topics/pubsub_topic, diff --git a/tools/confutils/entry_nodes.nim b/tools/confutils/entry_nodes.nim index 2dad853b8..347bf5114 100644 --- a/tools/confutils/entry_nodes.nim +++ b/tools/confutils/entry_nodes.nim @@ -2,7 +2,7 @@ import std/strutils import results, eth/p2p/discoveryv5/enr -import waku/waku_core/peers +import logos_delivery/waku/waku_core/peers type EntryNodeType {.pure.} = enum EnrTree diff --git a/tools/rln_keystore_generator/rln_keystore_generator.nim b/tools/rln_keystore_generator/rln_keystore_generator.nim index 503e8d58e..16508178b 100644 --- a/tools/rln_keystore_generator/rln_keystore_generator.nim +++ b/tools/rln_keystore_generator/rln_keystore_generator.nim @@ -6,7 +6,7 @@ else: import chronicles, results, std/[tempfiles, sequtils] import - waku/[ + logos_delivery/waku/[ waku_keystore, waku_rln_relay/rln, waku_rln_relay/conversion_utils, diff --git a/tools/sync-nimble-lock.sh b/tools/sync-nimble-lock.sh index b55826327..29d30afb2 100755 --- a/tools/sync-nimble-lock.sh +++ b/tools/sync-nimble-lock.sh @@ -2,7 +2,7 @@ # # sync-nimble-lock.sh # -# Cross-check git-URL pinned `requires` in waku.nimble against nimble.lock and +# Cross-check git-URL pinned `requires` in logos_delivery.nimble against nimble.lock and # sync the lock entry for any pin that CHANGED relative to a git base ref # (default: HEAD) -- and ONLY those entries. No other package is touched. # @@ -19,7 +19,7 @@ # # For each changed pin it updates exactly three fields of the matching lock # entry, preserving all formatting and every other entry byte-for-byte: -# version = "#" + (commit or tag) +# version = "#" + (commit or tag) # vcsRevision = git rev-parse of the ref (resolves tags) # checksums.sha1 = the self-computed checksum # @@ -82,7 +82,7 @@ APPLY = os.environ["SYNC_APPLY"] == "1" BASE = os.environ["SYNC_BASE"] PKGCACHE = os.environ["SYNC_PKGCACHE"] -NIMBLE_FILE = os.path.join(ROOT, "waku.nimble") +NIMBLE_FILE = os.path.join(ROOT, "logos_delivery.nimble") LOCK_FILE = os.path.join(ROOT, "nimble.lock") REQ_RE = re.compile(r'requires\s+"(https?://[^"#]+)#([^"]+)"') @@ -180,7 +180,7 @@ def dep_requires_count(checkout_dir): # detect changes # --------------------------------------------------------------------------- def parse_changed(base): - r = git(["-C", ROOT, "diff", base, "--", "waku.nimble"], check=False) + r = git(["-C", ROOT, "diff", base, "--", "logos_delivery.nimble"], check=False) if r.returncode != 0: fail("git diff against %r failed: %s" % (base, r.stderr.strip())) changed, seen = [], set() @@ -245,7 +245,7 @@ def main(): changed = parse_changed(BASE) if not changed: - print("No changed git-URL `requires` in waku.nimble vs %s — nothing to sync." % BASE) + print("No changed git-URL `requires` in logos_delivery.nimble vs %s — nothing to sync." % BASE) return 0 lock = json.load(open(LOCK_FILE)) @@ -264,13 +264,13 @@ def main(): drift.append((url, rev, hit[0], hit[1].get("version"))) if not drift: - print("nimble.lock already in sync with waku.nimble (%d changed pin(s) checked)." % len(changed)) + print("nimble.lock already in sync with logos_delivery.nimble (%d changed pin(s) checked)." % len(changed)) return 0 - print("Dependency drift (waku.nimble vs nimble.lock):") + print("Dependency drift (logos_delivery.nimble vs nimble.lock):") for url, rev, name, cur in drift: tag = name or "(missing)" - print(" ~ %s [%s]\n waku.nimble: #%s\n nimble.lock: %s" % (url, tag, rev, cur)) + print(" ~ %s [%s]\n logos_delivery.nimble: #%s\n nimble.lock: %s" % (url, tag, rev, cur)) if not APPLY: print("\nRun with --apply to update nimble.lock (computes checksum itself; no `nimble lock`).") diff --git a/waku/waku_persistency.nim b/waku/waku_persistency.nim deleted file mode 100644 index 5eb94e3f0..000000000 --- a/waku/waku_persistency.nim +++ /dev/null @@ -1,3 +0,0 @@ -import waku/persistency/persistency - -export persistency From faa674131124f93fc55573c247c8b60d84e2d71b Mon Sep 17 00:00:00 2001 From: Darshan <35736874+darshankabariya@users.noreply.github.com> Date: Mon, 8 Jun 2026 18:42:26 +0530 Subject: [PATCH 10/13] fix: build zerokit rln from source via fixed nixpkgs, drop prebuilt fetch (#3930) --- flake.lock | 54 +++++++++++++++++++++++++++++--- flake.nix | 83 +++++++------------------------------------------ nix/zerokit.nix | 9 ++++++ 3 files changed, 69 insertions(+), 77 deletions(-) create mode 100644 nix/zerokit.nix diff --git a/flake.lock b/flake.lock index 411bf2430..225bfc3ed 100644 --- a/flake.lock +++ b/flake.lock @@ -2,24 +2,25 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1770464364, - "narHash": "sha256-z5NJPSBwsLf/OfD8WTmh79tlSU8XgIbwmk6qB1/TFzY=", + "lastModified": 1780511130, + "narHash": "sha256-2v9lT4ya59Lh1FqPeLnz1MoX9y/wz2huqfe9RtQZITk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "23d72dabcb3b12469f57b37170fcbc1789bd7457", + "rev": "535f3e6942cb1cead3929c604320d3db54b542b9", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "23d72dabcb3b12469f57b37170fcbc1789bd7457", + "rev": "535f3e6942cb1cead3929c604320d3db54b542b9", "type": "github" } }, "root": { "inputs": { "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "zerokit": "zerokit" } }, "rust-overlay": { @@ -41,6 +42,49 @@ "repo": "rust-overlay", "type": "github" } + }, + "rust-overlay_2": { + "inputs": { + "nixpkgs": [ + "zerokit", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1771297684, + "narHash": "sha256-wieWskQxZLPlNXX06JEB0bMoS/ZYQ89xBzF0RL9lyLs=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "755d3669699a7c62aef35af187d75dc2728cfd85", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "zerokit": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay_2" + }, + "locked": { + "lastModified": 1779168423, + "narHash": "sha256-OmCnpM+ZcI79EVozdKADj9h4sFsLwfCs5w7OK8Ir6fc=", + "owner": "vacp2p", + "repo": "zerokit", + "rev": "5e64cb8822bee65eed6cf459f95ae72b80c6ba63", + "type": "github" + }, + "original": { + "owner": "vacp2p", + "repo": "zerokit", + "rev": "5e64cb8822bee65eed6cf459f95ae72b80c6ba63", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 67f516359..5b76fd9ac 100644 --- a/flake.nix +++ b/flake.nix @@ -11,15 +11,22 @@ inputs = { # Pinning the commit to use same commit across different projects. # A commit from nixpkgs 25.11 release: https://github.com/NixOS/nixpkgs/tree/release-25.11 - nixpkgs.url = "github:NixOS/nixpkgs?rev=23d72dabcb3b12469f57b37170fcbc1789bd7457"; + # Includes the fetchCargoVendor crates.io CDN fix (nixpkgs 0fb82de3). + nixpkgs.url = "github:NixOS/nixpkgs?rev=535f3e6942cb1cead3929c604320d3db54b542b9"; rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; + + # Zerokit v2.0.2; keep rev in sync with the vendor/zerokit submodule. + zerokit = { + url = "github:vacp2p/zerokit/5e64cb8822bee65eed6cf459f95ae72b80c6ba63"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, rust-overlay }: + outputs = { self, nixpkgs, rust-overlay, zerokit }: let systems = [ "x86_64-linux" "aarch64-linux" @@ -59,78 +66,12 @@ inherit system; overlays = [ (import rust-overlay) nimbleOverlay ]; }; - - # Prebuilt zerokit librln, fetched from the upstream GitHub release - # rather than compiled from source. Compiling zerokit makes Nix download - # its many crate dependencies from crates.io in one parallel burst, which - # crates.io intermittently rejects with HTTP 403 (rate limiting from the - # self-hosted runners' shared IP), breaking the nix build. The release - # ships the exact `stateless` library this project links (see - # scripts/build_rln.sh), so we use it directly — no Rust toolchain and - # no crates.io access needed. - # - # Keep `rlnVersion` aligned with `LIBRLN_VERSION` in the Makefile and the - # vendor/zerokit submodule. Each hash is the sha256 of the release tarball - # for that platform; refresh all four when bumping the version. - rlnVersion = "v2.0.2"; - rlnAssets = { - "x86_64-linux" = { triple = "x86_64-unknown-linux-gnu"; hash = "sha256-qbrUdaetYKFhjzxUP/QcwD3JHWJ8qk/tCMK3yXceIAk="; }; - "aarch64-linux" = { triple = "aarch64-unknown-linux-gnu"; hash = "sha256-s4bWrmCcNTWHNyJwV73ilWNp58ZdAVG+TAgtWN1cTQs="; }; - "x86_64-darwin" = { triple = "x86_64-apple-darwin"; hash = "sha256-ZaHP5CApN66FYY7jxwOmGcF9kJR78Fng3k1qE2W08Mk="; }; - "aarch64-darwin" = { triple = "aarch64-apple-darwin"; hash = "sha256-f2YppkPsKFdN00j+IY8fpvsebWTIb9lW/V1/vOTiVKU="; }; - }; - - mkZerokitRln = system: pkgs: - let - asset = rlnAssets.${system} or - (throw "zerokit ${rlnVersion} has no prebuilt rln asset for system '${system}'"); - in pkgs.stdenv.mkDerivation { - pname = "librln"; - version = lib.removePrefix "v" rlnVersion; - - src = pkgs.fetchurl { - url = "https://github.com/vacp2p/zerokit/releases/download/" - + "${rlnVersion}/${asset.triple}-stateless-rln.tar.gz"; - hash = asset.hash; - }; - - # The tarball lays its files out under release/. - sourceRoot = "release"; - dontConfigure = true; - dontBuild = true; - - # The release .so was linked outside Nix, so it references system - # libraries (libgcc_s, libstdc++, glibc) by bare name. autoPatchelfHook - # points those at the Nix versions so the library loads correctly when - # used by the Nix build. It does nothing for the static .a, and the - # step is skipped on macOS (dylib paths are fixed in nix/default.nix). - nativeBuildInputs = - pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.autoPatchelfHook ]; - buildInputs = - pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.stdenv.cc.cc.lib ]; - - installPhase = '' - runHook preInstall - mkdir -p $out/lib - cp librln.a $out/lib/ 2>/dev/null || true - cp librln.so $out/lib/ 2>/dev/null || true - cp librln.dylib $out/lib/ 2>/dev/null || true - runHook postInstall - ''; - - meta = with pkgs.lib; { - description = "Prebuilt zerokit RLN library (stateless flavor)"; - homepage = "https://github.com/vacp2p/zerokit"; - license = with licenses; [ mit asl20 ]; - platforms = builtins.attrNames rlnAssets; - }; - }; in { packages = forAllSystems (system: let pkgs = pkgsFor system; - zerokitRln = mkZerokitRln system pkgs; + zerokitRln = import ./nix/zerokit.nix { inherit zerokit system; }; liblogosdelivery = pkgs.callPackage ./nix/default.nix { inherit pkgs; @@ -147,9 +88,7 @@ }; in { inherit liblogosdelivery wakucanary; - # Expose the prebuilt librln so downstream consumers - # (e.g. logos-delivery-module) bundle the exact same librln this - # build links against. + # Expose librln so downstream consumers link the exact same build. rln = zerokitRln; default = liblogosdelivery; } diff --git a/nix/zerokit.nix b/nix/zerokit.nix new file mode 100644 index 000000000..a112186c3 --- /dev/null +++ b/nix/zerokit.nix @@ -0,0 +1,9 @@ +# zerokit rln built from source; overrides the stale v2.0.2 vendor cargoHash. +{ zerokit, system }: +zerokit.packages.${system}.rln.overrideAttrs (old: { + cargoDeps = old.cargoDeps.overrideAttrs (oldCargoDeps: { + vendorStaging = oldCargoDeps.vendorStaging.overrideAttrs (_: { + outputHash = "sha256-PNwEdZLgGQPqQDrEK2hsQtSybVfBbD6xn4K47fPFJUU="; + }); + }); +}) From c7350abb58d492dd66feffffa574954dc088b051 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Tue, 9 Jun 2026 10:32:42 +0200 Subject: [PATCH 11/13] clean waku_noise because it is not used in prod code (#3934) --- logos_delivery/waku/utils/noise.nim | 36 - logos_delivery/waku/waku_noise/noise.nim | 364 ------- .../waku_noise/noise_handshake_processing.nim | 668 ------------- .../waku/waku_noise/noise_types.nim | 284 ------ .../waku/waku_noise/noise_utils.nim | 588 ------------ tests/all_tests_waku.nim | 2 - tests/node/test_wakunode_relay_rln.nim | 2 - tests/test_waku_keystore.nim | 2 - tests/test_waku_keystore_keyfile.nim | 2 - tests/test_waku_noise.nim | 901 ------------------ tests/test_waku_noise_sessions.nim | 421 -------- tests/testlib/common.nim | 5 + 12 files changed, 5 insertions(+), 3270 deletions(-) delete mode 100644 logos_delivery/waku/utils/noise.nim delete mode 100644 logos_delivery/waku/waku_noise/noise.nim delete mode 100644 logos_delivery/waku/waku_noise/noise_handshake_processing.nim delete mode 100644 logos_delivery/waku/waku_noise/noise_types.nim delete mode 100644 logos_delivery/waku/waku_noise/noise_utils.nim delete mode 100644 tests/test_waku_noise.nim delete mode 100644 tests/test_waku_noise_sessions.nim diff --git a/logos_delivery/waku/utils/noise.nim b/logos_delivery/waku/utils/noise.nim deleted file mode 100644 index c225ad9bf..000000000 --- a/logos_delivery/waku/utils/noise.nim +++ /dev/null @@ -1,36 +0,0 @@ -{.push raises: [].} - -import results -import ../waku_core, ../waku_noise/noise_types, ../waku_noise/noise_utils - -# Decodes a WakuMessage to a PayloadV2 -# Currently, this is just a wrapper over deserializePayloadV2 and encryption/decryption is done on top (no KeyInfo) -proc decodePayloadV2*( - message: WakuMessage -): Result[PayloadV2, cstring] {.raises: [NoiseMalformedHandshake, NoisePublicKeyError].} = - # We check message version (only 2 is supported in this proc) - case message.version - of 2: - # We attempt to decode the WakuMessage payload - let deserializedPayload2 = deserializePayloadV2(message.payload).valueOr: - return err("Failed to decode WakuMessage") - return ok(deserializedPayload2) - else: - return err("Wrong message version while decoding payload") - -# Encodes a PayloadV2 to a WakuMessage -# Currently, this is just a wrapper over serializePayloadV2 and encryption/decryption is done on top (no KeyInfo) -proc encodePayloadV2*( - payload2: PayloadV2, contentTopic: ContentTopic = default(ContentTopic) -): Result[WakuMessage, cstring] {. - raises: [NoiseMalformedHandshake, NoisePublicKeyError] -.} = - # We attempt to encode the PayloadV2 - let serializedPayload2 = serializePayloadV2(payload2).valueOr: - return err("Failed to encode PayloadV2") - - # If successful, we create and return a WakuMessage - let msg = - WakuMessage(payload: serializedPayload2, version: 2, contentTopic: contentTopic) - - return ok(msg) diff --git a/logos_delivery/waku/waku_noise/noise.nim b/logos_delivery/waku/waku_noise/noise.nim deleted file mode 100644 index 9c5dd76e7..000000000 --- a/logos_delivery/waku/waku_noise/noise.nim +++ /dev/null @@ -1,364 +0,0 @@ -# Waku Noise Protocols for Waku Payload Encryption -# Noise module implementing the Noise State Objects and ChaChaPoly encryption/decryption primitives -## See spec for more details: -## https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/35 -## -## Implementation partially inspired by noise-libp2p: -## https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/secure/noise.nim - -{.push raises: [].} - -import std/[options, strutils] -import stew/byteutils -import chronos -import chronicles -import bearssl/rand -import stew/endians2 -import nimcrypto/[sha2, hmac] - -import libp2p/utility -import libp2p/crypto/[crypto, chacha20poly1305, hkdf] -import libp2p/protocols/secure/secure - -import ./noise_types - -logScope: - topics = "waku noise" - -################################################################# - -# Noise state machine primitives - -# Overview : -# - Alice and Bob process (i.e. read and write, based on their role) each token appearing in a handshake pattern, consisting of pre-message and message patterns; -# - Both users initialize and update according to processed tokens a Handshake State, a Symmetric State and a Cipher State; -# - A preshared key psk is processed by calling MixKeyAndHash(psk); -# - When an ephemeral public key e is read or written, the handshake hash value h is updated by calling mixHash(e); If the handshake expects a psk, MixKey(e) is further called -# - When an encrypted static public key s or a payload message m is read, it is decrypted with decryptAndHash; -# - When a static public key s or a payload message is writted, it is encrypted with encryptAndHash; -# - When any Diffie-Hellman token ee, es, se, ss is read or written, the chaining key ck is updated by calling MixKey on the computed secret; -# - If all tokens are processed, users compute two new Cipher States by calling Split; -# - The two Cipher States obtained from Split are used to encrypt/decrypt outbound/inbound messages. - -################################# -# Cipher State Primitives -################################# - -# Checks if a Cipher State has an encryption key set -proc hasKey*(cs: CipherState): bool = - return (cs.k != EmptyKey) - -# Encrypts a plaintext using key material in a Noise Cipher State -# The CipherState is updated increasing the nonce (used as a counter in Noise) by one -proc encryptWithAd*( - state: var CipherState, ad, plaintext: openArray[byte] -): seq[byte] {.raises: [Defect, NoiseNonceMaxError].} = - # We raise an error if encryption is called using a Cipher State with nonce greater than MaxNonce - if state.n > NonceMax: - raise newException(NoiseNonceMaxError, "Noise max nonce value reached") - - var ciphertext: seq[byte] - - # If an encryption key is set in the Cipher state, we proceed with encryption - if state.hasKey: - # The output is the concatenation of the ciphertext and authorization tag - # We define its length accordingly - ciphertext = newSeqOfCap[byte](plaintext.len + sizeof(ChaChaPolyTag)) - - # Since ChaChaPoly encryption primitive overwrites the input with the output, - # we copy the plaintext in the output ciphertext variable and we pass it to encryption - ciphertext.add(plaintext) - - # The nonce is read from the input CipherState - # By Noise specification the nonce is 8 bytes long out of the 12 bytes supported by ChaChaPoly - var nonce: ChaChaPolyNonce - nonce[4 ..< 12] = toBytesLE(state.n) - - # We perform encryption and we store the authorization tag - var authorizationTag: ChaChaPolyTag - ChaChaPoly.encrypt(state.k, nonce, authorizationTag, ciphertext, ad) - - # We append the authorization tag to ciphertext - ciphertext.add(authorizationTag) - - # We increase the Cipher state nonce - inc state.n - # If the nonce is greater than the maximum allowed nonce, we raise an exception - if state.n > NonceMax: - raise newException(NoiseNonceMaxError, "Noise max nonce value reached") - - trace "encryptWithAd", - authorizationTag = byteutils.toHex(authorizationTag), - ciphertext = ciphertext, - nonce = state.n - 1 - - # Otherwise we return the input plaintext according to specification http://www.noiseprotocol.org/noise.html#the-cipherstate-object - else: - ciphertext = @plaintext - info "encryptWithAd called with no encryption key set. Returning plaintext." - - return ciphertext - -# Decrypts a ciphertext using key material in a Noise Cipher State -# The CipherState is updated increasing the nonce (used as a counter in Noise) by one -proc decryptWithAd*( - state: var CipherState, ad, ciphertext: openArray[byte] -): seq[byte] {.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} = - # We raise an error if encryption is called using a Cipher State with nonce greater than MaxNonce - if state.n > NonceMax: - raise newException(NoiseNonceMaxError, "Noise max nonce value reached") - - var plaintext: seq[byte] - - # If an encryption key is set in the Cipher state, we proceed with decryption - if state.hasKey: - # We read the authorization appendend at the end of a ciphertext - let inputAuthorizationTag = ciphertext.toOpenArray( - ciphertext.len - ChaChaPolyTag.len, ciphertext.high - ).intoChaChaPolyTag - - var - authorizationTag: ChaChaPolyTag - nonce: ChaChaPolyNonce - - # The nonce is read from the input CipherState - # By Noise specification the nonce is 8 bytes long out of the 12 bytes supported by ChaChaPoly - nonce[4 ..< 12] = toBytesLE(state.n) - - # Since ChaChaPoly decryption primitive overwrites the input with the output, - # we copy the ciphertext (authorization tag excluded) in the output plaintext variable and we pass it to decryption - plaintext = ciphertext[0 .. (ciphertext.high - ChaChaPolyTag.len)] - - ChaChaPoly.decrypt(state.k, nonce, authorizationTag, plaintext, ad) - - # We check if the input authorization tag matches the decryption authorization tag - if inputAuthorizationTag != authorizationTag: - info "decryptWithAd failed", - plaintext = plaintext, - ciphertext = ciphertext, - inputAuthorizationTag = inputAuthorizationTag, - authorizationTag = authorizationTag - raise - newException(NoiseDecryptTagError, "decryptWithAd failed tag authentication.") - - # We increase the Cipher state nonce - inc state.n - # If the nonce is greater than the maximum allowed nonce, we raise an exception - if state.n > NonceMax: - raise newException(NoiseNonceMaxError, "Noise max nonce value reached") - - trace "decryptWithAd", - inputAuthorizationTag = inputAuthorizationTag, - authorizationTag = authorizationTag, - nonce = state.n - - # Otherwise we return the input ciphertext according to specification http://www.noiseprotocol.org/noise.html#the-cipherstate-object - else: - plaintext = @ciphertext - info "decryptWithAd called with no encryption key set. Returning ciphertext." - - return plaintext - -# Sets the nonce of a Cipher State -proc setNonce*(cs: var CipherState, nonce: uint64) = - cs.n = nonce - -# Sets the key of a Cipher State -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 = - var randomCipherState: CipherState - hmacDrbgGenerate(rng, randomCipherState.k) - setNonce(randomCipherState, nonce) - return randomCipherState - -# Gets the key of a Cipher State -proc getKey*(cs: CipherState): ChaChaPolyKey = - return cs.k - -# Gets the nonce of a Cipher State -proc getNonce*(cs: CipherState): uint64 = - return cs.n - -################################# -# Symmetric State primitives -################################# - -# Initializes a Symmetric State -proc init*(_: type[SymmetricState], hsPattern: HandshakePattern): SymmetricState = - var ss: SymmetricState - # We compute the hash of the protocol name - ss.h = hsPattern.name.hashProtocol - # We initialize the chaining key ck - ss.ck = ss.h.data.intoChaChaPolyKey - # We initialize the Cipher state - ss.cs = CipherState(k: EmptyKey) - return ss - -# MixKey as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Updates a Symmetric state chaining key and symmetric state -proc mixKey*(ss: var SymmetricState, inputKeyMaterial: openArray[byte]) = - # We derive two keys using HKDF - var tempKeys: array[2, ChaChaPolyKey] - sha256.hkdf(ss.ck, inputKeyMaterial, [], tempKeys) - # We update ck and the Cipher state's key k using the output of HDKF - ss.ck = tempKeys[0] - ss.cs = CipherState(k: tempKeys[1]) - trace "mixKey", ck = ss.ck, k = ss.cs.k - -# MixHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Hashes data into a Symmetric State's handshake hash value h -proc mixHash*(ss: var SymmetricState, data: openArray[byte]) = - # We prepare the hash context - var ctx: sha256 - ctx.init() - # We add the previous handshake hash - ctx.update(ss.h.data) - # We append the input data - ctx.update(data) - # We hash and store the result in the Symmetric State's handshake hash value - ss.h = ctx.finish() - trace "mixHash", hash = ss.h.data - -# mixKeyAndHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Combines MixKey and MixHash -proc mixKeyAndHash*( - ss: var SymmetricState, inputKeyMaterial: openArray[byte] -) {.used.} = - var tempKeys: array[3, ChaChaPolyKey] - # Derives 3 keys using HKDF, the chaining key and the input key material - sha256.hkdf(ss.ck, inputKeyMaterial, [], tempKeys) - # Sets the chaining key - ss.ck = tempKeys[0] - # Updates the handshake hash value - ss.mixHash(tempKeys[1]) - # Updates the Cipher state's key - # Note for later support of 512 bits hash functions: "If HASHLEN is 64, then truncates tempKeys[2] to 32 bytes." - ss.cs = CipherState(k: tempKeys[2]) - -# EncryptAndHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Combines encryptWithAd and mixHash -# Note that by setting extraAd, it is possible to pass extra additional data that will be concatenated to the ad specified by Noise (can be used to authenticate messageNametag) -proc encryptAndHash*( - ss: var SymmetricState, plaintext: openArray[byte], extraAd: openArray[byte] = [] -): seq[byte] {.raises: [Defect, NoiseNonceMaxError].} = - # The output ciphertext - var ciphertext: seq[byte] - # The additional data - let ad = @(ss.h.data) & @(extraAd) - # Note that if an encryption key is not set yet in the Cipher state, ciphertext will be equal to plaintex - ciphertext = ss.cs.encryptWithAd(ad, plaintext) - # We call mixHash over the result - ss.mixHash(ciphertext) - return ciphertext - -# DecryptAndHash as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Combines decryptWithAd and mixHash -proc decryptAndHash*( - ss: var SymmetricState, ciphertext: openArray[byte], extraAd: openArray[byte] = [] -): seq[byte] {.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} = - # The output plaintext - var plaintext: seq[byte] - # The additional data - let ad = @(ss.h.data) & @(extraAd) - # Note that if an encryption key is not set yet in the Cipher state, plaintext will be equal to ciphertext - plaintext = ss.cs.decryptWithAd(ad, ciphertext) - # According to specification, the ciphertext enters mixHash (and not the plaintext) - ss.mixHash(ciphertext) - return plaintext - -# Split as per Noise specification http://www.noiseprotocol.org/noise.html#the-symmetricstate-object -# Once a handshake is complete, returns two Cipher States to encrypt/decrypt outbound/inbound messages -proc split*(ss: var SymmetricState): tuple[cs1, cs2: CipherState] = - # Derives 2 keys using HKDF and the chaining key - var tempKeys: array[2, ChaChaPolyKey] - sha256.hkdf(ss.ck, [], [], tempKeys) - # Returns a tuple of two Cipher States initialized with the derived keys - return (CipherState(k: tempKeys[0]), CipherState(k: tempKeys[1])) - -# Gets the chaining key field of a Symmetric State -proc getChainingKey*(ss: SymmetricState): ChaChaPolyKey = - return ss.ck - -# Gets the handshake hash field of a Symmetric State -proc getHandshakeHash*(ss: SymmetricState): MDigest[256] = - return ss.h - -# Gets the Cipher State field of a Symmetric State -proc getCipherState*(ss: SymmetricState): CipherState = - return ss.cs - -################################# -# Handshake State primitives -################################# - -# Initializes a Handshake State -proc init*( - _: type[HandshakeState], hsPattern: HandshakePattern, psk: seq[byte] = @[] -): HandshakeState = - # The output Handshake State - var hs: HandshakeState - # By default the Handshake State initiator flag is set to false - # Will be set to true when the user associated to the handshake state starts an handshake - hs.initiator = false - # We copy the information on the handshake pattern for which the state is initialized (protocol name, handshake pattern, psk) - hs.handshakePattern = hsPattern - hs.psk = psk - # We initialize the Symmetric State - hs.ss = SymmetricState.init(hsPattern) - return hs - -################################################################# - -################################# -# ChaChaPoly Symmetric Cipher -################################# - -# ChaChaPoly encryption -# It takes a Cipher State (with key, nonce, and associated data) and encrypts a plaintext -# The cipher state in not changed -proc encrypt*( - state: ChaChaPolyCipherState, plaintext: openArray[byte] -): ChaChaPolyCiphertext {.noinit, raises: [Defect, NoiseEmptyChaChaPolyInput].} = - # If plaintext is empty, we raise an error - if plaintext == @[]: - raise newException(NoiseEmptyChaChaPolyInput, "Tried to encrypt empty plaintext") - var ciphertext: ChaChaPolyCiphertext - # Since ChaChaPoly's library "encrypt" primitive directly changes the input plaintext to the ciphertext, - # we copy the plaintext into the ciphertext variable and we pass the latter to encrypt - ciphertext.data.add plaintext - # TODO: add padding - # ChaChaPoly.encrypt takes as input: the key (k), the nonce (nonce), a data structure for storing the computed authorization tag (tag), - # the plaintext (overwritten to ciphertext) (data), the associated data (ad) - ChaChaPoly.encrypt(state.k, state.nonce, ciphertext.tag, ciphertext.data, state.ad) - return ciphertext - -# ChaChaPoly decryption -# It takes a Cipher State (with key, nonce, and associated data) and decrypts a ciphertext -# The cipher state is not changed -proc decrypt*( - state: ChaChaPolyCipherState, ciphertext: ChaChaPolyCiphertext -): seq[byte] {.raises: [Defect, NoiseEmptyChaChaPolyInput, NoiseDecryptTagError].} = - # If ciphertext is empty, we raise an error - if ciphertext.data == @[]: - raise newException(NoiseEmptyChaChaPolyInput, "Tried to decrypt empty ciphertext") - var - # The input authorization tag - tagIn = ciphertext.tag - # The authorization tag computed during decryption - tagOut: ChaChaPolyTag - # Since ChaChaPoly's library "decrypt" primitive directly changes the input ciphertext to the plaintext, - # we copy the ciphertext into the plaintext variable and we pass the latter to decrypt - var plaintext = ciphertext.data - # ChaChaPoly.decrypt takes as input: the key (k), the nonce (nonce), a data structure for storing the computed authorization tag (tag), - # the ciphertext (overwritten to plaintext) (data), the associated data (ad) - ChaChaPoly.decrypt(state.k, state.nonce, tagOut, plaintext, state.ad) - # TODO: add unpadding - trace "decrypt", tagIn = tagIn, tagOut = tagOut, nonce = state.nonce - # We check if the authorization tag computed while decrypting is the same as the input tag - if tagIn != tagOut: - info "decrypt failed", plaintext = shortLog(plaintext) - raise newException(NoiseDecryptTagError, "decrypt tag authentication failed.") - return plaintext diff --git a/logos_delivery/waku/waku_noise/noise_handshake_processing.nim b/logos_delivery/waku/waku_noise/noise_handshake_processing.nim deleted file mode 100644 index 8b84bf958..000000000 --- a/logos_delivery/waku/waku_noise/noise_handshake_processing.nim +++ /dev/null @@ -1,668 +0,0 @@ -# Waku Noise Protocols for Waku Payload Encryption -## See spec for more details: -## https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/35 - -{.push raises: [].} - -import std/[options, strutils, tables] -import chronos -import chronicles -import bearssl/rand -import results - -import libp2p/crypto/[chacha20poly1305, curve25519] - -import ./noise_types -import ./noise -import ./noise_utils - -logScope: - topics = "waku noise" - -################################################################# - -# Handshake Processing - -################################# -## Utilities -################################# - -# Based on the message handshake direction and if the user is or not the initiator, returns a boolean tuple telling if the user -# has to read or write the next handshake message -proc getReadingWritingState( - hs: HandshakeState, direction: MessageDirection -): (bool, bool) = - var reading, writing: bool - - if hs.initiator and direction == D_r: - # I'm Alice and direction is -> - reading = false - writing = true - elif hs.initiator and direction == D_l: - # I'm Alice and direction is <- - reading = true - writing = false - elif not hs.initiator and direction == D_r: - # I'm Bob and direction is -> - reading = true - writing = false - elif not hs.initiator and direction == D_l: - # I'm Bob and direction is <- - reading = false - writing = true - - return (reading, writing) - -# Checks if a pre-message is valid according to Noise specifications -# http://www.noiseprotocol.org/noise.html#handshake-patterns -proc isValid(msg: seq[PreMessagePattern]): bool = - var isValid: bool = true - - # Non-empty pre-messages can only have patterns "e", "s", "e,s" in each direction - let allowedPatterns: seq[PreMessagePattern] = @[ - PreMessagePattern(direction: D_r, tokens: @[T_s]), - PreMessagePattern(direction: D_r, tokens: @[T_e]), - PreMessagePattern(direction: D_r, tokens: @[T_e, T_s]), - PreMessagePattern(direction: D_l, tokens: @[T_s]), - PreMessagePattern(direction: D_l, tokens: @[T_e]), - PreMessagePattern(direction: D_l, tokens: @[T_e, T_s]), - ] - - # We check if pre message patterns are allowed - for pattern in msg: - if not (pattern in allowedPatterns): - isValid = false - break - - return isValid - -################################# -# Handshake messages processing procedures -################################# - -# Processes pre-message patterns -proc processPreMessagePatternTokens( - hs: var HandshakeState, inPreMessagePKs: seq[NoisePublicKey] = @[] -) {. - raises: [Defect, NoiseMalformedHandshake, NoiseHandshakeError, NoisePublicKeyError] -.} = - var - # I make a copy of the input pre-message public keys, so that I can easily delete processed ones without using iterators/counters - preMessagePKs = inPreMessagePKs - # Here we store currently processed pre message public key - currPK: NoisePublicKey - - # We retrieve the pre-message patterns to process, if any - # If none, there's nothing to do - if hs.handshakePattern.preMessagePatterns == EmptyPreMessage: - return - - # If not empty, we check that pre-message is valid according to Noise specifications - if isValid(hs.handshakePattern.preMessagePatterns) == false: - raise newException(NoiseMalformedHandshake, "Invalid pre-message in handshake") - - # We iterate over each pattern contained in the pre-message - for messagePattern in hs.handshakePattern.preMessagePatterns: - let - direction = messagePattern.direction - tokens = messagePattern.tokens - - # We get if the user is reading or writing the current pre-message pattern - var (reading, writing) = getReadingWritingState(hs, direction) - - # We process each message pattern token - for token in tokens: - # We process the pattern token - case token - of T_e: - # We expect an ephemeral key, so we attempt to read it (next PK to process will always be at index 0 of preMessagePKs) - if preMessagePKs.len > 0: - currPK = preMessagePKs[0] - else: - raise newException( - NoiseHandshakeError, "Noise pre-message read e, expected a public key" - ) - - # If user is reading the "e" token - if reading: - trace "noise pre-message read e" - - # We check if current key is encrypted or not. We assume pre-message public keys are all unencrypted on users' end - if currPK.flag == 0.uint8: - # Sets re and calls MixHash(re.public_key). - hs.re = intoCurve25519Key(currPK.pk) - hs.ss.mixHash(hs.re) - else: - raise newException( - NoisePublicKeyError, - "Noise read e, incorrect encryption flag for pre-message public key", - ) - - # If user is writing the "e" token - elif writing: - trace "noise pre-message write e" - - # When writing, the user is sending a public key, - # We check that the public part corresponds to the set local key and we call MixHash(e.public_key). - if hs.e.publicKey == intoCurve25519Key(currPK.pk): - hs.ss.mixHash(hs.e.publicKey) - else: - raise newException( - NoisePublicKeyError, - "Noise pre-message e key doesn't correspond to locally set e key pair", - ) - - # Noise specification: section 9.2 - # In non-PSK handshakes, the "e" token in a pre-message pattern or message pattern always results - # in a call to MixHash(e.public_key). - # In a PSK handshake, all of these calls are followed by MixKey(e.public_key). - if "psk" in hs.handshakePattern.name: - hs.ss.mixKey(currPK.pk) - - # We delete processed public key - preMessagePKs.delete(0) - of T_s: - # We expect a static key, so we attempt to read it (next PK to process will always be at index of preMessagePKs) - if preMessagePKs.len > 0: - currPK = preMessagePKs[0] - else: - raise newException( - NoiseHandshakeError, "Noise pre-message read s, expected a public key" - ) - - # If user is reading the "s" token - if reading: - trace "noise pre-message read s" - - # We check if current key is encrypted or not. We assume pre-message public keys are all unencrypted on users' end - if currPK.flag == 0.uint8: - # Sets re and calls MixHash(re.public_key). - hs.rs = intoCurve25519Key(currPK.pk) - hs.ss.mixHash(hs.rs) - else: - raise newException( - NoisePublicKeyError, - "Noise read s, incorrect encryption flag for pre-message public key", - ) - - # If user is writing the "s" token - elif writing: - trace "noise pre-message write s" - - # If writing, it means that the user is sending a public key, - # We check that the public part corresponds to the set local key and we call MixHash(s.public_key). - if hs.s.publicKey == intoCurve25519Key(currPK.pk): - hs.ss.mixHash(hs.s.publicKey) - else: - raise newException( - NoisePublicKeyError, - "Noise pre-message s key doesn't correspond to locally set s key pair", - ) - - # Noise specification: section 9.2 - # In non-PSK handshakes, the "e" token in a pre-message pattern or message pattern always results - # in a call to MixHash(e.public_key). - # In a PSK handshake, all of these calls are followed by MixKey(e.public_key). - if "psk" in hs.handshakePattern.name: - hs.ss.mixKey(currPK.pk) - - # We delete processed public key - preMessagePKs.delete(0) - else: - raise - newException(NoiseMalformedHandshake, "Invalid Token for pre-message pattern") - -# This procedure encrypts/decrypts the implicit payload attached at the end of every message pattern -# An optional extraAd to pass extra additional data in encryption/decryption can be set (useful to authenticate messageNametag) -proc processMessagePatternPayload( - hs: var HandshakeState, transportMessage: seq[byte], extraAd: openArray[byte] = [] -): seq[byte] {.raises: [Defect, NoiseDecryptTagError, NoiseNonceMaxError].} = - var payload: seq[byte] - - # We retrieve current message pattern (direction + tokens) to process - let direction = hs.handshakePattern.messagePatterns[hs.msgPatternIdx].direction - - # We get if the user is reading or writing the input handshake message - var (reading, writing) = getReadingWritingState(hs, direction) - - # We decrypt the transportMessage, if any - if reading: - payload = hs.ss.decryptAndHash(transportMessage, extraAd) - payload = pkcs7_unpad(payload, NoisePaddingBlockSize) - elif writing: - payload = pkcs7_pad(transportMessage, NoisePaddingBlockSize) - payload = hs.ss.encryptAndHash(payload, extraAd) - - return payload - -# 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, - hs: var HandshakeState, - inputHandshakeMessage: seq[NoisePublicKey] = @[], -): Result[seq[NoisePublicKey], cstring] {. - raises: [ - Defect, NoiseHandshakeError, NoiseMalformedHandshake, NoisePublicKeyError, - NoiseDecryptTagError, NoiseNonceMaxError, - ] -.} = - # We retrieve current message pattern (direction + tokens) to process - let - messagePattern = hs.handshakePattern.messagePatterns[hs.msgPatternIdx] - direction = messagePattern.direction - tokens = messagePattern.tokens - - # We get if the user is reading or writing the input handshake message - var (reading, writing) = getReadingWritingState(hs, direction) - - # I make a copy of the handshake message so that I can easily delete processed PKs without using iterators/counters - # (Possibly) non-empty if reading - var inHandshakeMessage = inputHandshakeMessage - - # The party's output public keys - # (Possibly) non-empty if writing - var outHandshakeMessage: seq[NoisePublicKey] = @[] - - # In currPK we store the currently processed public key from the handshake message - var currPK: NoisePublicKey - - # We process each message pattern token - for token in tokens: - case token - of T_e: - # If user is reading the "s" token - if reading: - trace "noise read e" - - # We expect an ephemeral key, so we attempt to read it (next PK to process will always be at index 0 of preMessagePKs) - if inHandshakeMessage.len > 0: - currPK = inHandshakeMessage[0] - else: - raise newException(NoiseHandshakeError, "Noise read e, expected a public key") - - # We check if current key is encrypted or not - # Note: by specification, ephemeral keys should always be unencrypted. But we support encrypted ones. - if currPK.flag == 0.uint8: - # Unencrypted Public Key - # Sets re and calls MixHash(re.public_key). - hs.re = intoCurve25519Key(currPK.pk) - hs.ss.mixHash(hs.re) - - # The following is out of specification: we call decryptAndHash for encrypted ephemeral keys, similarly as happens for (encrypted) static keys - elif currPK.flag == 1.uint8: - # Encrypted public key - # Decrypts re, sets re and calls MixHash(re.public_key). - hs.re = intoCurve25519Key(hs.ss.decryptAndHash(currPK.pk)) - else: - raise newException( - NoisePublicKeyError, - "Noise read e, incorrect encryption flag for public key", - ) - - # Noise specification: section 9.2 - # In non-PSK handshakes, the "e" token in a pre-message pattern or message pattern always results - # in a call to MixHash(e.public_key). - # In a PSK handshake, all of these calls are followed by MixKey(e.public_key). - if "psk" in hs.handshakePattern.name: - hs.ss.mixKey(hs.re) - - # We delete processed public key - inHandshakeMessage.delete(0) - - # If user is writing the "e" token - elif writing: - trace "noise write e" - - # We generate a new ephemeral keypair - hs.e = genKeyPair(rng) - - # We update the state - hs.ss.mixHash(hs.e.publicKey) - - # Noise specification: section 9.2 - # In non-PSK handshakes, the "e" token in a pre-message pattern or message pattern always results - # in a call to MixHash(e.public_key). - # In a PSK handshake, all of these calls are followed by MixKey(e.public_key). - if "psk" in hs.handshakePattern.name: - hs.ss.mixKey(hs.e.publicKey) - - # We add the ephemeral public key to the Waku payload - outHandshakeMessage.add toNoisePublicKey(getPublicKey(hs.e)) - of T_s: - # If user is reading the "s" token - if reading: - trace "noise read s" - - # We expect a static key, so we attempt to read it (next PK to process will always be at index 0 of preMessagePKs) - if inHandshakeMessage.len > 0: - currPK = inHandshakeMessage[0] - else: - raise newException(NoiseHandshakeError, "Noise read s, expected a public key") - - # We check if current key is encrypted or not - if currPK.flag == 0.uint8: - # Unencrypted Public Key - # Sets re and calls MixHash(re.public_key). - hs.rs = intoCurve25519Key(currPK.pk) - hs.ss.mixHash(hs.rs) - elif currPK.flag == 1.uint8: - # Encrypted public key - # Decrypts rs, sets rs and calls MixHash(rs.public_key). - hs.rs = intoCurve25519Key(hs.ss.decryptAndHash(currPK.pk)) - else: - raise newException( - NoisePublicKeyError, - "Noise read s, incorrect encryption flag for public key", - ) - - # We delete processed public key - inHandshakeMessage.delete(0) - - # If user is writing the "s" token - elif writing: - trace "noise write s" - - # If the local static key is not set (the handshake state was not properly initialized), we raise an error - if isDefault(hs.s): - raise newException(NoisePublicKeyError, "Static key not set") - - # We encrypt the public part of the static key in case a key is set in the Cipher State - # That is, encS may either be an encrypted or unencrypted static key. - let encS = hs.ss.encryptAndHash(hs.s.publicKey) - - # We add the (encrypted) static public key to the Waku payload - # Note that encS = (Enc(s) || tag) if encryption key is set, otherwise encS = s. - # We distinguish these two cases by checking length of encryption and we set the proper encryption flag - if encS.len > Curve25519Key.len: - outHandshakeMessage.add NoisePublicKey(flag: 1, pk: encS) - else: - outHandshakeMessage.add NoisePublicKey(flag: 0, pk: encS) - of T_psk: - # If user is reading the "psk" token - - trace "noise psk" - - # Calls MixKeyAndHash(psk) - hs.ss.mixKeyAndHash(hs.psk) - of T_ee: - # If user is reading the "ee" token - - trace "noise dh ee" - - # If local and/or remote ephemeral keys are not set, we raise an error - if isDefault(hs.e) or isDefault(hs.re): - raise newException(NoisePublicKeyError, "Local or remote ephemeral key not set") - - # Calls MixKey(DH(e, re)). - hs.ss.mixKey(dh(hs.e.privateKey, hs.re)) - of T_es: - # If user is reading the "es" token - - trace "noise dh es" - - # We check if keys are correctly set. - # If both present, we call MixKey(DH(e, rs)) if initiator, MixKey(DH(s, re)) if responder. - if hs.initiator: - if isDefault(hs.e) or isDefault(hs.rs): - raise newException( - NoisePublicKeyError, "Local or remote ephemeral/static key not set" - ) - hs.ss.mixKey(dh(hs.e.privateKey, hs.rs)) - else: - if isDefault(hs.re) or isDefault(hs.s): - raise newException( - NoisePublicKeyError, "Local or remote ephemeral/static key not set" - ) - hs.ss.mixKey(dh(hs.s.privateKey, hs.re)) - of T_se: - # If user is reading the "se" token - - trace "noise dh se" - - # We check if keys are correctly set. - # If both present, call MixKey(DH(s, re)) if initiator, MixKey(DH(e, rs)) if responder. - if hs.initiator: - if isDefault(hs.s) or isDefault(hs.re): - raise newException( - NoiseMalformedHandshake, "Local or remote ephemeral/static key not set" - ) - hs.ss.mixKey(dh(hs.s.privateKey, hs.re)) - else: - if isDefault(hs.rs) or isDefault(hs.e): - raise newException( - NoiseMalformedHandshake, "Local or remote ephemeral/static key not set" - ) - hs.ss.mixKey(dh(hs.e.privateKey, hs.rs)) - of T_ss: - # If user is reading the "ss" token - - trace "noise dh ss" - - # If local and/or remote static keys are not set, we raise an error - if isDefault(hs.s) or isDefault(hs.rs): - raise - newException(NoiseMalformedHandshake, "Local or remote static key not set") - - # Calls MixKey(DH(s, rs)). - hs.ss.mixKey(dh(hs.s.privateKey, hs.rs)) - - return ok(outHandshakeMessage) - -################################# -## Procedures to progress handshakes between users -################################# - -# Initializes a Handshake State -proc initialize*( - hsPattern: HandshakePattern, - ephemeralKey: KeyPair = default(KeyPair), - staticKey: KeyPair = default(KeyPair), - prologue: seq[byte] = @[], - psk: seq[byte] = @[], - preMessagePKs: seq[NoisePublicKey] = @[], - initiator: bool = false, -): HandshakeState {. - raises: [Defect, NoiseMalformedHandshake, NoiseHandshakeError, NoisePublicKeyError] -.} = - var hs = HandshakeState.init(hsPattern) - hs.ss.mixHash(prologue) - hs.e = ephemeralKey - hs.s = staticKey - hs.psk = psk - hs.msgPatternIdx = 0 - hs.initiator = initiator - # We process any eventual handshake pre-message pattern by processing pre-message public keys - processPreMessagePatternTokens(hs, preMessagePKs) - return hs - -# Advances 1 step in handshake -# Each user in a handshake alternates writing and reading of handshake messages. -# 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, - hs: var HandshakeState, - readPayloadV2: PayloadV2 = default(PayloadV2), - transportMessage: seq[byte] = @[], - messageNametag: openArray[byte] = [], -): Result[HandshakeStepResult, cstring] {. - raises: [ - Defect, NoiseHandshakeError, NoiseMessageNametagError, NoiseMalformedHandshake, - NoisePublicKeyError, NoiseDecryptTagError, NoiseNonceMaxError, - ] -.} = - var hsStepResult: HandshakeStepResult - - # If there are no more message patterns left for processing - # we return an empty HandshakeStepResult - if hs.msgPatternIdx > uint8(hs.handshakePattern.messagePatterns.len - 1): - info "stepHandshake called more times than the number of message patterns present in handshake" - return ok(hsStepResult) - - # We process the next handshake message pattern - - # We get if the user is reading or writing the input handshake message - let direction = hs.handshakePattern.messagePatterns[hs.msgPatternIdx].direction - var (reading, writing) = getReadingWritingState(hs, direction) - - # If we write an answer at this handshake step - if writing: - # We initialize a payload v2 and we set proper protocol ID (if supported) - try: - hsStepResult.payload2.protocolId = PayloadV2ProtocolIDs[hs.handshakePattern.name] - except CatchableError: - raise newException(NoiseMalformedHandshake, "Handshake Pattern not supported") - - # We set the messageNametag and the handshake and transport messages - hsStepResult.payload2.messageNametag = toMessageNametag(messageNametag) - hsStepResult.payload2.handshakeMessage = processMessagePatternTokens(rng, hs).get() - # We write the payload by passing the messageNametag as extra additional data - hsStepResult.payload2.transportMessage = processMessagePatternPayload( - hs, transportMessage, extraAd = hsStepResult.payload2.messageNametag - ) - - # If we read an answer during this handshake step - elif reading: - # If the read message nametag doesn't match the expected input one we raise an error - if readPayloadV2.messageNametag != toMessageNametag(messageNametag): - raise newException( - NoiseMessageNametagError, - "The message nametag of the read message doesn't match the expected one", - ) - - # We process the read public keys and (eventually decrypt) the read transport message - let - readHandshakeMessage = readPayloadV2.handshakeMessage - readTransportMessage = readPayloadV2.transportMessage - - # Since we only read, nothing meanigful (i.e. public keys) is returned - discard processMessagePatternTokens(rng, hs, readHandshakeMessage) - # We retrieve and store the (decrypted) received transport message by passing the messageNametag as extra additional data - hsStepResult.transportMessage = processMessagePatternPayload( - hs, readTransportMessage, extraAd = readPayloadV2.messageNametag - ) - else: - raise newException( - NoiseHandshakeError, "Handshake Error: neither writing or reading user" - ) - - # We increase the handshake state message pattern index to progress to next step - hs.msgPatternIdx += 1 - - return ok(hsStepResult) - -# Finalizes the handshake by calling Split and assigning the proper Cipher States to users -proc finalizeHandshake*(hs: var HandshakeState): HandshakeResult = - var hsResult: HandshakeResult - - ## Noise specification, Section 5: - ## Processing the final handshake message returns two CipherState objects, - ## the first for encrypting transport messages from initiator to responder, - ## and the second for messages in the other direction. - - # We call Split() - let (cs1, cs2) = hs.ss.split() - - # Optional: We derive a secret for the nametag derivation - let (nms1, nms2) = genMessageNametagSecrets(hs) - - # We assign the proper Cipher States - if hs.initiator: - hsResult.csOutbound = cs1 - hsResult.csInbound = cs2 - # and nametags secrets - hsResult.nametagsInbound.secret = some(nms1) - hsResult.nametagsOutbound.secret = some(nms2) - else: - hsResult.csOutbound = cs2 - hsResult.csInbound = cs1 - # and nametags secrets - hsResult.nametagsInbound.secret = some(nms2) - hsResult.nametagsOutbound.secret = some(nms1) - - # We initialize the message nametags inbound/outbound buffers - hsResult.nametagsInbound.initNametagsBuffer - hsResult.nametagsOutbound.initNametagsBuffer - - # We store the optional fields rs and h - hsResult.rs = hs.rs - hsResult.h = hs.ss.h - - return hsResult - -################################# -# After-handshake procedures -################################# - -## Noise specification, Section 5: -## Transport messages are then encrypted and decrypted by calling EncryptWithAd() -## and DecryptWithAd() on the relevant CipherState with zero-length associated data. -## If DecryptWithAd() signals an error due to DECRYPT() failure, then the input message is discarded. -## The application may choose to delete the CipherState and terminate the session on such an error, -## or may continue to attempt communications. If EncryptWithAd() or DecryptWithAd() signal an error -## due to nonce exhaustion, then the application must delete the CipherState and terminate the session. - -# Writes an encrypted message using the proper Cipher State -proc writeMessage*( - hsr: var HandshakeResult, - transportMessage: seq[byte], - outboundMessageNametagBuffer: var MessageNametagBuffer, -): PayloadV2 {.raises: [Defect, NoiseNonceMaxError].} = - var payload2: PayloadV2 - - # We set the message nametag using the input buffer - payload2.messageNametag = pop(outboundMessageNametagBuffer) - - # According to 35/WAKU2-NOISE RFC, no Handshake protocol information is sent when exchanging messages - # This correspond to setting protocol-id to 0 - payload2.protocolId = 0.uint8 - # We pad the transport message - let paddedTransportMessage = pkcs7_pad(transportMessage, NoisePaddingBlockSize) - # Encryption is done with zero-length associated data as per specification - payload2.transportMessage = encryptWithAd( - hsr.csOutbound, ad = @(payload2.messageNametag), plaintext = paddedTransportMessage - ) - - return payload2 - -# Reads an encrypted message using the proper Cipher State -# Decryption is attempted only if the input PayloadV2 has a messageNametag equal to the one expected -proc readMessage*( - hsr: var HandshakeResult, - readPayload2: PayloadV2, - inboundMessageNametagBuffer: var MessageNametagBuffer, -): Result[seq[byte], cstring] {. - raises: [ - Defect, NoiseDecryptTagError, NoiseMessageNametagError, NoiseNonceMaxError, - NoiseSomeMessagesWereLost, - ] -.} = - # The output decrypted message - var message: seq[byte] - - # If the message nametag does not correspond to the nametag expected in the inbound message nametag buffer - # an error is raised (to be handled externally, i.e. re-request lost messages, discard, etc.) - let nametagIsOk = - checkNametag(readPayload2.messageNametag, inboundMessageNametagBuffer).isOk - assert(nametagIsOk) - - # At this point the messageNametag matches the expected nametag. - # According to 35/WAKU2-NOISE RFC, no Handshake protocol information is sent when exchanging messages - if readPayload2.protocolId == 0.uint8: - # On application level we decide to discard messages which fail decryption, without raising an error - try: - # Decryption is done with messageNametag as associated data - let paddedMessage = decryptWithAd( - hsr.csInbound, - ad = @(readPayload2.messageNametag), - ciphertext = readPayload2.transportMessage, - ) - # We unpdad the decrypted message - message = pkcs7_unpad(paddedMessage, NoisePaddingBlockSize) - # The message successfully decrypted, we can delete the first element of the inbound Message Nametag Buffer - delete(inboundMessageNametagBuffer, 1) - except NoiseDecryptTagError: - info "A read message failed decryption. Returning empty message as plaintext." - message = @[] - - return ok(message) diff --git a/logos_delivery/waku/waku_noise/noise_types.nim b/logos_delivery/waku/waku_noise/noise_types.nim deleted file mode 100644 index 543bd4329..000000000 --- a/logos_delivery/waku/waku_noise/noise_types.nim +++ /dev/null @@ -1,284 +0,0 @@ -# Waku Noise Protocols for Waku Payload Encryption -## See spec for more details: -## https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/35 -## -## Implementation partially inspired by noise-libp2p: -## https://github.com/status-im/nim-libp2p/blob/master/libp2p/protocols/secure/noise.nim - -{.push raises: [].} - -import std/[options, tables] -import chronos -import chronicles -import bearssl -import nimcrypto/sha2 - -import libp2p/errors -import libp2p/crypto/[crypto, chacha20poly1305, curve25519] - -logScope: - topics = "waku noise" - -################################################################# - -# Constants and data structures - -const - # EmptyKey represents a non-initialized ChaChaPolyKey - EmptyKey* = default(ChaChaPolyKey) - # The maximum ChaChaPoly allowed nonce in Noise Handshakes - NonceMax* = uint64.high - 1 - # The padding blocksize of a transport message - NoisePaddingBlockSize* = 248 - # The default length of a message nametag - MessageNametagLength* = 16 - # The default length of the secret to generate Inbound/Outbound nametags buffer - MessageNametagSecretLength* = 32 - # The default size of an Inbound/outbound MessageNametagBuffer - MessageNametagBufferSize* = 50 - -type - - ################################# - # Elliptic Curve arithemtic - ################################# - - # Default underlying elliptic curve arithmetic (useful for switching to multiple ECs) - # Current default is Curve25519 - EllipticCurve* = Curve25519 - EllipticCurveKey* = Curve25519Key - - # An EllipticCurveKey (public, private) key pair - KeyPair* = object - privateKey*: EllipticCurveKey - publicKey*: EllipticCurveKey - - ################################# - # Noise Public Keys - ################################# - - # A Noise public key is a public key exchanged during Noise handshakes (no private part) - # This follows https://rfc.vac.dev/spec/35/#public-keys-serialization - # pk contains the X coordinate of the public key, if unencrypted (this implies flag = 0) - # or the encryption of the X coordinate concatenated with the authorization tag, if encrypted (this implies flag = 1) - # Note: besides encryption, flag can be used to distinguish among multiple supported Elliptic Curves - NoisePublicKey* = object - flag*: uint8 - pk*: seq[byte] - - ################################# - # ChaChaPoly Encryption - ################################# - - # A ChaChaPoly ciphertext (data) + authorization tag (tag) - ChaChaPolyCiphertext* = object - data*: seq[byte] - tag*: ChaChaPolyTag - - # A ChaChaPoly Cipher State containing key (k), nonce (nonce) and associated data (ad) - ChaChaPolyCipherState* = object - k*: ChaChaPolyKey - nonce*: ChaChaPolyNonce - ad*: seq[byte] - - ################################# - # Noise handshake patterns - ################################# - - # The Noise tokens appearing in Noise (pre)message patterns - # as in http://www.noiseprotocol.org/noise.html#handshake-pattern-basics - NoiseTokens* = enum - T_e = "e" - T_s = "s" - T_es = "es" - T_ee = "ee" - T_se = "se" - T_ss = "ss" - T_psk = "psk" - - # The direction of a (pre)message pattern in canonical form (i.e. Alice-initiated form) - # as in http://www.noiseprotocol.org/noise.html#alice-and-bob - MessageDirection* = enum - D_r = "->" - D_l = "<-" - - # The pre message pattern consisting of a message direction and some Noise tokens, if any. - # (if non empty, only tokens e and s are allowed: http://www.noiseprotocol.org/noise.html#handshake-pattern-basics) - PreMessagePattern* = object - direction*: MessageDirection - tokens*: seq[NoiseTokens] - - # The message pattern consisting of a message direction and some Noise tokens - # All Noise tokens are allowed - MessagePattern* = object - direction*: MessageDirection - tokens*: seq[NoiseTokens] - - # The handshake pattern object. It stores the handshake protocol name, the handshake pre message patterns and the handshake message patterns - HandshakePattern* = object - name*: string - preMessagePatterns*: seq[PreMessagePattern] - messagePatterns*: seq[MessagePattern] - - ################################# - # Noise state machine - ################################# - - # The Cipher State as in https://noiseprotocol.org/noise.html#the-cipherstate-object - # Contains an encryption key k and a nonce n (used in Noise as a counter) - CipherState* = object - k*: ChaChaPolyKey - n*: uint64 - - # The Symmetric State as in https://noiseprotocol.org/noise.html#the-symmetricstate-object - # Contains a Cipher State cs, the chaining key ck and the handshake hash value h - SymmetricState* = object - cs*: CipherState - ck*: ChaChaPolyKey - h*: MDigest[256] - - # The Handshake State as in https://noiseprotocol.org/noise.html#the-handshakestate-object - # Contains - # - the local and remote ephemeral/static keys e,s,re,rs (if any) - # - the initiator flag (true if the user creating the state is the handshake initiator, false otherwise) - # - the handshakePattern (containing the handshake protocol name, and (pre)message patterns) - # This object is futher extended from specifications by storing: - # - a message pattern index msgPatternIdx indicating the next handshake message pattern to process - # - the user's preshared psk, if any - HandshakeState* = object - s*: KeyPair - e*: KeyPair - rs*: EllipticCurveKey - re*: EllipticCurveKey - ss*: SymmetricState - initiator*: bool - handshakePattern*: HandshakePattern - msgPatternIdx*: uint8 - psk*: seq[byte] - - # While processing messages patterns, users either: - # - read (decrypt) the other party's (encrypted) transport message - # - write (encrypt) a message, sent through a PayloadV2 - # These two intermediate results are stored in the HandshakeStepResult data structure - HandshakeStepResult* = object - payload2*: PayloadV2 - transportMessage*: seq[byte] - - # When a handshake is complete, the HandhshakeResult will contain the two - # Cipher States used to encrypt/decrypt outbound/inbound messages - # The recipient static key rs and handshake hash values h are stored to address some possible future applications (channel-binding, session management, etc.). - # However, are not required by Noise specifications and are thus optional - HandshakeResult* = object - csOutbound*: CipherState - csInbound*: CipherState - # Optional fields: - nametagsInbound*: MessageNametagBuffer - nametagsOutbound*: MessageNametagBuffer - rs*: EllipticCurveKey - h*: MDigest[256] - - ################################# - # Waku Payload V2 - ################################# - - # PayloadV2 defines an object for Waku payloads with version 2 as in - # https://rfc.vac.dev/spec/35/#public-keys-serialization - # It contains a message nametag, protocol ID field, the handshake message (for Noise handshakes) and - # a transport message (for Noise handshakes and ChaChaPoly encryptions) - MessageNametag* = array[MessageNametagLength, byte] - - MessageNametagBuffer* = object - buffer*: array[MessageNametagBufferSize, MessageNametag] - counter*: uint64 - secret*: Option[array[MessageNametagSecretLength, byte]] - - PayloadV2* = object - messageNametag*: MessageNametag - protocolId*: uint8 - handshakeMessage*: seq[NoisePublicKey] - transportMessage*: seq[byte] - - ################################# - # Some useful error types - ################################# - NoiseError* = object of LPError - NoiseHandshakeError* = object of NoiseError - NoiseEmptyChaChaPolyInput* = object of NoiseError - NoiseDecryptTagError* = object of NoiseError - NoiseNonceMaxError* = object of NoiseError - NoisePublicKeyError* = object of NoiseError - NoiseMalformedHandshake* = object of NoiseError - NoiseMessageNametagError* = object of NoiseError - NoiseSomeMessagesWereLost* = object of NoiseError - -################################# -# Constants (supported protocols) -################################# -const - - # The empty pre message patterns - EmptyPreMessage*: seq[PreMessagePattern] = @[] - - # Supported Noise handshake patterns as defined in https://rfc.vac.dev/spec/35/#specification - NoiseHandshakePatterns* = { - "K1K1": HandshakePattern( - name: "Noise_K1K1_25519_ChaChaPoly_SHA256", - preMessagePatterns: @[ - PreMessagePattern(direction: D_r, tokens: @[T_s]), - PreMessagePattern(direction: D_l, tokens: @[T_s]), - ], - messagePatterns: @[ - MessagePattern(direction: D_r, tokens: @[T_e]), - MessagePattern(direction: D_l, tokens: @[T_e, T_ee, T_es]), - MessagePattern(direction: D_r, tokens: @[T_se]), - ], - ), - "XK1": HandshakePattern( - name: "Noise_XK1_25519_ChaChaPoly_SHA256", - preMessagePatterns: @[PreMessagePattern(direction: D_l, tokens: @[T_s])], - messagePatterns: @[ - MessagePattern(direction: D_r, tokens: @[T_e]), - MessagePattern(direction: D_l, tokens: @[T_e, T_ee, T_es]), - MessagePattern(direction: D_r, tokens: @[T_s, T_se]), - ], - ), - "XX": HandshakePattern( - name: "Noise_XX_25519_ChaChaPoly_SHA256", - preMessagePatterns: EmptyPreMessage, - messagePatterns: @[ - MessagePattern(direction: D_r, tokens: @[T_e]), - MessagePattern(direction: D_l, tokens: @[T_e, T_ee, T_s, T_es]), - MessagePattern(direction: D_r, tokens: @[T_s, T_se]), - ], - ), - "XXpsk0": HandshakePattern( - name: "Noise_XXpsk0_25519_ChaChaPoly_SHA256", - preMessagePatterns: EmptyPreMessage, - messagePatterns: @[ - MessagePattern(direction: D_r, tokens: @[T_psk, T_e]), - MessagePattern(direction: D_l, tokens: @[T_e, T_ee, T_s, T_es]), - MessagePattern(direction: D_r, tokens: @[T_s, T_se]), - ], - ), - "WakuPairing": HandshakePattern( - name: "Noise_WakuPairing_25519_ChaChaPoly_SHA256", - preMessagePatterns: @[PreMessagePattern(direction: D_l, tokens: @[T_e])], - messagePatterns: @[ - MessagePattern(direction: D_r, tokens: @[T_e, T_ee]), - MessagePattern(direction: D_l, tokens: @[T_s, T_es]), - MessagePattern(direction: D_r, tokens: @[T_s, T_se, T_ss]), - ], - ), - }.toTable() - - # Supported Protocol ID for PayloadV2 objects - # Protocol IDs are defined according to https://rfc.vac.dev/spec/35/#specification - PayloadV2ProtocolIDs* = { - "": 0.uint8, - "Noise_K1K1_25519_ChaChaPoly_SHA256": 10.uint8, - "Noise_XK1_25519_ChaChaPoly_SHA256": 11.uint8, - "Noise_XX_25519_ChaChaPoly_SHA256": 12.uint8, - "Noise_XXpsk0_25519_ChaChaPoly_SHA256": 13.uint8, - "Noise_WakuPairing_25519_ChaChaPoly_SHA256": 14.uint8, - "ChaChaPoly": 30.uint8, - }.toTable() diff --git a/logos_delivery/waku/waku_noise/noise_utils.nim b/logos_delivery/waku/waku_noise/noise_utils.nim deleted file mode 100644 index 177dc6557..000000000 --- a/logos_delivery/waku/waku_noise/noise_utils.nim +++ /dev/null @@ -1,588 +0,0 @@ -# Waku Noise Protocols for Waku Payload Encryption -# Noise utilities module -## See spec for more details: -## https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/35 - -{.push raises: [].} - -import std/[algorithm, base64, oids, options, strutils, tables, sequtils] -import chronos -import chronicles -import bearssl/rand -import results -import stew/[endians2, byteutils] -import nimcrypto/sha2 - -import libp2p/crypto/[chacha20poly1305, curve25519, hkdf] - -import ./noise_types -import ./noise - -logScope: - topics = "waku noise" - -################################################################# - -################################# -# Generic Utilities -################################# - -# Generates random byte sequences of given size -proc randomSeqByte*(rng: var HmacDrbgContext, size: int): seq[byte] = - var output = newSeq[byte](size.uint32) - hmacDrbgGenerate(rng, output) - return output - -# Pads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3 -proc pkcs7_pad*(payload: seq[byte], paddingSize: int): seq[byte] = - assert(paddingSize < 256) - - let k = paddingSize - (payload.len mod paddingSize) - - var padding: seq[byte] - - if k != 0: - padding = newSeqWith(k, k.byte) - else: - padding = newSeqWith(paddingSize, paddingSize.byte) - - let padded = concat(payload, padding) - - return padded - -# Unpads a payload according to PKCS#7 as per RFC 5652 https://datatracker.ietf.org/doc/html/rfc5652#section-6.3 -proc pkcs7_unpad*(payload: seq[byte], paddingSize: int): seq[byte] = - let k = payload[payload.high] - let unpadded = payload[0 .. payload.high - k.int] - return unpadded - -proc seqToDigest256*(sequence: seq[byte]): MDigest[256] = - var digest: MDigest[256] - for i in 0 ..< digest.data.len: - digest.data[i] = sequence[i] - return digest - -proc digestToSeq*[T](digest: MDigest[T]): seq[byte] = - var sequence: seq[byte] - for i in 0 ..< digest.data.len: - sequence.add digest.data[i] - return sequence - -# Serializes input parameters to a base64 string for exposure through QR code (used by WakuPairing) -proc toQr*( - applicationName: string, - applicationVersion: string, - shardId: string, - ephemeralKey: EllipticCurveKey, - committedStaticKey: MDigest[256], -): string = - var qr: string - qr.add encode(applicationName, safe = true) & ":" - qr.add encode(applicationVersion, safe = true) & ":" - qr.add encode(shardId, safe = true) & ":" - qr.add encode(ephemeralKey, safe = true) & ":" - qr.add encode(committedStaticKey.data, safe = true) - - return qr - -# Deserializes input string in base64 to the corresponding (applicationName, applicationVersion, shardId, ephemeralKey, committedStaticKey) -proc fromQr*( - qr: string -): (string, string, string, EllipticCurveKey, MDigest[256]) {. - raises: [Defect, ValueError] -.} = - let values = qr.split(":") - - assert(values.len == 5) - - let applicationName: string = decode(values[0]) - let applicationVersion: string = decode(values[1]) - let shardId: string = decode(values[2]) - - let decodedEphemeralKey = decode(values[3]).toBytes - var ephemeralKey: EllipticCurveKey - for i in 0 ..< ephemeralKey.len: - ephemeralKey[i] = decodedEphemeralKey[i] - - let committedStaticKey = seqToDigest256(decode(values[4]).toBytes) - - return - (applicationName, applicationVersion, shardId, ephemeralKey, committedStaticKey) - -# Converts a sequence or array (arbitrary size) to a MessageNametag -proc toMessageNametag*(input: openArray[byte]): MessageNametag = - var byte_seq: seq[byte] = @input - - # We set its length to the default message nametag length (will be truncated or 0-padded) - byte_seq.setLen(MessageNametagLength) - - # We copy it to a MessageNametag - var messageNametag: MessageNametag - for i in 0 ..< MessageNametagLength: - messageNametag[i] = byte_seq[i] - - return messageNametag - -# Uses the cryptographic information stored in the input handshake state to generate a random message nametag -# In current implementation the messageNametag = HKDF(handshake hash value), but other derivation mechanisms can be implemented -proc toMessageNametag*(hs: HandshakeState): MessageNametag = - var output: array[1, array[MessageNametagLength, byte]] - sha256.hkdf(hs.ss.h.data, [], [], output) - return output[0] - -proc genMessageNametagSecrets*( - hs: HandshakeState -): (array[MessageNametagSecretLength, byte], array[MessageNametagSecretLength, byte]) = - var output: array[2, array[MessageNametagSecretLength, byte]] - sha256.hkdf(hs.ss.h.data, [], [], output) - return (output[0], output[1]) - -# Simple utility that checks if the given variable is "default", -# Therefore, it has not been initialized -proc isDefault*[T](value: T): bool = - value == static(default(T)) - -################################################################# - -################################# -# Noise Handhshake Utilities -################################# - -# Generate random (public, private) Elliptic Curve key pairs -proc genKeyPair*(rng: var HmacDrbgContext): KeyPair = - var keyPair: KeyPair - keyPair.privateKey = EllipticCurveKey.random(rng) - keyPair.publicKey = keyPair.privateKey.public() - return keyPair - -# Gets private key from a key pair -proc getPrivateKey*(keypair: KeyPair): EllipticCurveKey = - return keypair.privateKey - -# Gets public key from a key pair -proc getPublicKey*(keypair: KeyPair): EllipticCurveKey = - return keypair.publicKey - -# Prints Handshake Patterns using Noise pattern layout -proc print*(self: HandshakePattern) {.raises: [IOError, NoiseMalformedHandshake].} = - try: - if self.name != "": - stdout.write self.name, ":\n" - stdout.flushFile() - # We iterate over pre message patterns, if any - if self.preMessagePatterns != EmptyPreMessage: - for pattern in self.preMessagePatterns: - stdout.write " ", pattern.direction - var first = true - for token in pattern.tokens: - if first: - stdout.write " ", token - first = false - else: - stdout.write ", ", token - stdout.write "\n" - stdout.flushFile() - stdout.write " ...\n" - stdout.flushFile() - # We iterate over message patterns - for pattern in self.messagePatterns: - stdout.write " ", pattern.direction - var first = true - for token in pattern.tokens: - if first: - stdout.write " ", token - first = false - else: - stdout.write ", ", token - stdout.write "\n" - stdout.flushFile() - except CatchableError: - raise newException(NoiseMalformedHandshake, "HandshakePattern malformed") - -# Hashes a Noise protocol name using SHA256 -proc hashProtocol*(protocolName: string): MDigest[256] = - # The output hash value - var hash: MDigest[256] - - # From Noise specification: Section 5.2 - # http://www.noiseprotocol.org/noise.html#the-symmetricstate-object - # If protocol_name is less than or equal to HASHLEN bytes in length, - # sets h equal to protocol_name with zero bytes appended to make HASHLEN bytes. - # Otherwise sets h = HASH(protocol_name). - if protocolName.len <= 32: - hash.data[0 .. protocolName.high] = protocolName.toBytes - else: - hash = sha256.digest(protocolName) - - return hash - -# Commits a public key pk for randomness r as H(pk || s) -proc commitPublicKey*(publicKey: EllipticCurveKey, r: seq[byte]): MDigest[256] = - var hashInput: seq[byte] - hashInput.add getBytes(publicKey) - hashInput.add r - - # The output hash value - var hash: MDigest[256] - hash = sha256.digest(hashInput) - - return hash - -# Generates an 8 decimal digits authorization code using HKDF and the handshake state -proc genAuthcode*(hs: HandshakeState): string = - var output: array[1, array[8, byte]] - sha256.hkdf(hs.ss.h.data, [], [], output) - let code = cast[uint64](output[0]) mod 100_000_000 - return $code - -# Initializes the empty Message nametag buffer. The n-th nametag is equal to HKDF( secret || n ) -proc initNametagsBuffer*(mntb: var MessageNametagBuffer) = - # We default the counter and buffer fields - mntb.counter = 0 - mntb.buffer = default(array[MessageNametagBufferSize, MessageNametag]) - - if mntb.secret.isSome: - for i in 0 ..< mntb.buffer.len: - mntb.buffer[i] = toMessageNametag( - sha256.digest(@(mntb.secret.get()) & @(toBytesLE(mntb.counter))).data - ) - mntb.counter += 1 - else: - # We warn users if no secret is set - info "The message nametags buffer has not a secret set" - -# Deletes the first n elements in buffer and appends n new ones -proc delete*(mntb: var MessageNametagBuffer, n: int) = - if n <= 0: - return - - # We ensure n is at most MessageNametagBufferSize (the buffer will be fully replaced) - let n = min(n, MessageNametagBufferSize) - - # We update the last n values in the array if a secret is set - # Note that if the input MessageNametagBuffer is set to default, nothing is done here - if mntb.secret.isSome: - # We rotate left the array by n - mntb.buffer.rotateLeft(n) - - for i in 0 ..< n: - mntb.buffer[mntb.buffer.len - n + i] = toMessageNametag( - sha256.digest(@(mntb.secret.get()) & @(toBytesLE(mntb.counter))).data - ) - mntb.counter += 1 - else: - # We warn users that no secret is set - info "The message nametags buffer has no secret set" - -# Checks if the input messageNametag is contained in the input MessageNametagBuffer -proc checkNametag*( - messageNametag: MessageNametag, mntb: var MessageNametagBuffer -): Result[bool, cstring] {. - raises: [Defect, NoiseMessageNametagError, NoiseSomeMessagesWereLost] -.} = - let index = mntb.buffer.find(messageNametag) - - if index == -1: - raise newException(NoiseMessageNametagError, "Message nametag not found in buffer") - elif index > 0: - raise newException( - NoiseSomeMessagesWereLost, - "Message nametag is present in buffer but is not the next expected nametag. One or more messages were probably lost", - ) - - # index is 0, hence the read message tag is the next expected one - return ok(true) - -# Deletes the first n elements in buffer and appends n new ones -proc pop*(mntb: var MessageNametagBuffer): MessageNametag = - # Note that if the input MessageNametagBuffer is set to default, an all 0 messageNametag is returned - let messageNametag = mntb.buffer[0] - delete(mntb, 1) - return messageNametag - -# Performs a Diffie-Hellman operation between two elliptic curve keys (one private, one public) -proc dh*(private: EllipticCurveKey, public: EllipticCurveKey): EllipticCurveKey = - # The output result of the Diffie-Hellman operation - var output: EllipticCurveKey - - # Since the EC multiplication writes the result to the input, we copy the input to the output variable - output = public - # We execute the DH operation - EllipticCurve.mul(output, private) - - return output - -################################################################# - -################################# -# ChaChaPoly Cipher utilities -################################# - -# Generates a random ChaChaPolyKey for testing encryption/decryption -proc randomChaChaPolyKey*(rng: var HmacDrbgContext): ChaChaPolyKey = - var key: ChaChaPolyKey - hmacDrbgGenerate(rng, key) - return key - -# Generates a random ChaChaPoly Cipher State for testing encryption/decryption -proc randomChaChaPolyCipherState*(rng: var HmacDrbgContext): ChaChaPolyCipherState = - var randomCipherState: ChaChaPolyCipherState - randomCipherState.k = randomChaChaPolyKey(rng) - hmacDrbgGenerate(rng, randomCipherState.nonce) - randomCipherState.ad = newSeq[byte](32) - hmacDrbgGenerate(rng, randomCipherState.ad) - return randomCipherState - -################################################################# - -################################# -# Noise Public keys utilities -################################# - -# Checks equality between two Noise public keys -proc `==`*(k1, k2: NoisePublicKey): bool = - return (k1.flag == k2.flag) and (k1.pk == k2.pk) - -# Converts a public Elliptic Curve key to an unencrypted Noise public key -proc toNoisePublicKey*(publicKey: EllipticCurveKey): NoisePublicKey = - var noisePublicKey: NoisePublicKey - noisePublicKey.flag = 0 - noisePublicKey.pk = getBytes(publicKey) - return noisePublicKey - -# Generates a random Noise public key -proc genNoisePublicKey*(rng: var HmacDrbgContext): NoisePublicKey = - var noisePublicKey: NoisePublicKey - # We generate a random key pair - let keyPair: KeyPair = genKeyPair(rng) - # Since it is unencrypted, flag is 0 - noisePublicKey.flag = 0 - # We copy the public X coordinate of the key pair to the output Noise public key - noisePublicKey.pk = getBytes(keyPair.publicKey) - return noisePublicKey - -# Converts a Noise public key to a stream of bytes as in -# https://rfc.vac.dev/spec/35/#public-keys-serialization -proc serializeNoisePublicKey*(noisePublicKey: NoisePublicKey): seq[byte] = - var serializedNoisePublicKey: seq[byte] - # Public key is serialized as (flag || pk) - # Note that pk contains the X coordinate of the public key if unencrypted - # or the encryption concatenated with the authorization tag if encrypted - serializedNoisePublicKey.add noisePublicKey.flag - serializedNoisePublicKey.add noisePublicKey.pk - return serializedNoisePublicKey - -# Converts a serialized Noise public key to a NoisePublicKey object as in -# https://rfc.vac.dev/spec/35/#public-keys-serialization -proc intoNoisePublicKey*( - serializedNoisePublicKey: seq[byte] -): NoisePublicKey {.raises: [Defect, NoisePublicKeyError].} = - var noisePublicKey: NoisePublicKey - # We retrieve the encryption flag - noisePublicKey.flag = serializedNoisePublicKey[0] - # If not 0 or 1 we raise a new exception - if not (noisePublicKey.flag == 0 or noisePublicKey.flag == 1): - raise newException(NoisePublicKeyError, "Invalid flag in serialized public key") - # We set the remaining sequence to the pk value (this may be an encrypted or not encrypted X coordinate) - noisePublicKey.pk = serializedNoisePublicKey[1 ..< serializedNoisePublicKey.len] - return noisePublicKey - -# Encrypts a Noise public key using a ChaChaPoly Cipher State -proc encryptNoisePublicKey*( - cs: ChaChaPolyCipherState, noisePublicKey: NoisePublicKey -): NoisePublicKey {.raises: [Defect, NoiseEmptyChaChaPolyInput, NoiseNonceMaxError].} = - var encryptedNoisePublicKey: NoisePublicKey - # We proceed with encryption only if - # - a key is set in the cipher state - # - the public key is unencrypted - if cs.k != EmptyKey and noisePublicKey.flag == 0: - let encPk = encrypt(cs, noisePublicKey.pk) - # We set the flag to 1, since encrypted - encryptedNoisePublicKey.flag = 1 - # Authorization tag is appendend to the ciphertext - encryptedNoisePublicKey.pk = encPk.data - encryptedNoisePublicKey.pk.add encPk.tag - # Otherwise we return the public key as it is - else: - encryptedNoisePublicKey = noisePublicKey - return encryptedNoisePublicKey - -# Decrypts a Noise public key using a ChaChaPoly Cipher State -proc decryptNoisePublicKey*( - cs: ChaChaPolyCipherState, noisePublicKey: NoisePublicKey -): NoisePublicKey {.raises: [Defect, NoiseEmptyChaChaPolyInput, NoiseDecryptTagError].} = - var decryptedNoisePublicKey: NoisePublicKey - # We proceed with decryption only if - # - a key is set in the cipher state - # - the public key is encrypted - if cs.k != EmptyKey and noisePublicKey.flag == 1: - # Since the pk field would contain an encryption + tag, we retrieve the ciphertext length - let pkLen = noisePublicKey.pk.len - ChaChaPolyTag.len - # We isolate the ciphertext and the authorization tag - let pk = noisePublicKey.pk[0 ..< pkLen] - let pkAuth = - intoChaChaPolyTag(noisePublicKey.pk[pkLen ..< pkLen + ChaChaPolyTag.len]) - # We convert it to a ChaChaPolyCiphertext - let ciphertext = ChaChaPolyCiphertext(data: pk, tag: pkAuth) - # We run decryption and store its value to a non-encrypted Noise public key (flag = 0) - decryptedNoisePublicKey.pk = decrypt(cs, ciphertext) - decryptedNoisePublicKey.flag = 0 - # Otherwise we return the public key as it is - else: - decryptedNoisePublicKey = noisePublicKey - return decryptedNoisePublicKey - -################################################################# - -################################# -# Payload encoding/decoding procedures -################################# - -# Checks equality between two PayloadsV2 objects -proc `==`*(p1, p2: PayloadV2): bool = - return - (p1.messageNametag == p2.messageNametag) and (p1.protocolId == p2.protocolId) and - (p1.handshakeMessage == p2.handshakeMessage) and - (p1.transportMessage == p2.transportMessage) - -# Generates a random PayloadV2 -proc randomPayloadV2*(rng: var HmacDrbgContext): PayloadV2 = - var payload2: PayloadV2 - # We set a random messageNametag - let randMessageNametag = randomSeqByte(rng, MessageNametagLength) - for i in 0 ..< MessageNametagLength: - payload2.messageNametag[i] = randMessageNametag[i] - # To generate a random protocol id, we generate a random 1-byte long sequence, and we convert the first element to uint8 - payload2.protocolId = randomSeqByte(rng, 1)[0].uint8 - # We set the handshake message to three unencrypted random Noise Public Keys - payload2.handshakeMessage = - @[genNoisePublicKey(rng), genNoisePublicKey(rng), genNoisePublicKey(rng)] - # We set the transport message to a random 128-bytes long sequence - payload2.transportMessage = randomSeqByte(rng, 128) - return payload2 - -# Serializes a PayloadV2 object to a byte sequences according to https://rfc.vac.dev/spec/35/. -# The output serialized payload concatenates the input PayloadV2 object fields as -# payload = ( protocolId || serializedHandshakeMessageLen || serializedHandshakeMessage || transportMessageLen || transportMessage) -# The output can be then passed to the payload field of a WakuMessage https://rfc.vac.dev/spec/14/ -proc serializePayloadV2*(self: PayloadV2): Result[seq[byte], cstring] = - # We collect public keys contained in the handshake message - var - # According to https://rfc.vac.dev/spec/35/, the maximum size for the handshake message is 256 bytes, that is - # the handshake message length can be represented with 1 byte only. (its length can be stored in 1 byte) - # However, to ease public keys length addition operation, we declare it as int and later cast to uit8 - serializedHandshakeMessageLen: int = 0 - # This variables will store the concatenation of the serializations of all public keys in the handshake message - serializedHandshakeMessage = newSeqOfCap[byte](256) - # A variable to store the currently processed public key serialization - serializedPk: seq[byte] - # For each public key in the handshake message - for pk in self.handshakeMessage: - # We serialize the public key - serializedPk = serializeNoisePublicKey(pk) - # We sum its serialized length to the total - serializedHandshakeMessageLen += serializedPk.len - # We add its serialization to the concatenation of all serialized public keys in the handshake message - serializedHandshakeMessage.add serializedPk - # If we are processing more than 256 byte, we return an error - if serializedHandshakeMessageLen > uint8.high.int: - info "PayloadV2 malformed: too many public keys contained in the handshake message" - return err("Too many public keys in handshake message") - - # We get the transport message byte length - let transportMessageLen = self.transportMessage.len - - # The output payload as in https://rfc.vac.dev/spec/35/. We concatenate all the PayloadV2 fields as - # payload = ( protocolId || serializedHandshakeMessageLen || serializedHandshakeMessage || transportMessageLen || transportMessage) - # We declare it as a byte sequence of length accordingly to the PayloadV2 information read - var payload = newSeqOfCap[byte]( - MessageNametagLength + #MessageNametagLength bytes for messageNametag - 1 + # 1 byte for protocol ID - 1 + # 1 byte for length of serializedHandshakeMessage field - serializedHandshakeMessageLen + - # serializedHandshakeMessageLen bytes for serializedHandshakeMessage - 8 + # 8 bytes for transportMessageLen - transportMessageLen # transportMessageLen bytes for transportMessage - ) - - # We concatenate all the data - # The protocol ID (1 byte) and handshake message length (1 byte) can be directly casted to byte to allow direct copy to the payload byte sequence - payload.add @(self.messageNametag) - payload.add self.protocolId.byte - payload.add serializedHandshakeMessageLen.byte - payload.add serializedHandshakeMessage - # The transport message length is converted from uint64 to bytes in Little-Endian - payload.add toBytesLE(transportMessageLen.uint64) - payload.add self.transportMessage - - return ok(payload) - -# Deserializes a byte sequence to a PayloadV2 object according to https://rfc.vac.dev/spec/35/. -# The input serialized payload concatenates the output PayloadV2 object fields as -# payload = ( messageNametag || protocolId || serializedHandshakeMessageLen || serializedHandshakeMessage || transportMessageLen || transportMessage) -proc deserializePayloadV2*( - payload: seq[byte] -): Result[PayloadV2, cstring] {.raises: [Defect, NoisePublicKeyError].} = - # The output PayloadV2 - var payload2: PayloadV2 - - # i is the read input buffer position index - var i: uint64 = 0 - - # We start by reading the messageNametag - for j in 0 ..< MessageNametagLength: - payload2.messageNametag[j] = payload[i + j.uint64] - i += MessageNametagLength - - # We read the Protocol ID - # TODO: when the list of supported protocol ID is defined, check if read protocol ID is supported - payload2.protocolId = payload[i].uint8 - i += 1 - - # We read the Handshake Message lenght (1 byte) - var handshakeMessageLen = payload[i].uint64 - if handshakeMessageLen > uint8.high.uint64: - info "Payload malformed: too many public keys contained in the handshake message" - return err("Too many public keys in handshake message") - - i += 1 - - # We now read for handshakeMessageLen bytes the buffer and we deserialize each (encrypted/unencrypted) public key read - var - # In handshakeMessage we accumulate the read deserialized Noise Public keys - handshakeMessage: seq[NoisePublicKey] - flag: byte - pkLen: uint64 - written: uint64 = 0 - - # We read the buffer until handshakeMessageLen are read - while written != handshakeMessageLen: - # We obtain the current Noise Public key encryption flag - flag = payload[i] - # If the key is unencrypted, we only read the X coordinate of the EC public key and we deserialize into a Noise Public Key - if flag == 0: - pkLen = 1 + EllipticCurveKey.len - handshakeMessage.add intoNoisePublicKey(payload[i ..< i + pkLen]) - i += pkLen - written += pkLen - # If the key is encrypted, we only read the encrypted X coordinate and the authorization tag, and we deserialize into a Noise Public Key - elif flag == 1: - pkLen = 1 + EllipticCurveKey.len + ChaChaPolyTag.len - handshakeMessage.add intoNoisePublicKey(payload[i ..< i + pkLen]) - i += pkLen - written += pkLen - else: - return err("Invalid flag for Noise public key") - - # We save in the output PayloadV2 the read handshake message - payload2.handshakeMessage = handshakeMessage - - # We read the transport message length (8 bytes) and we convert to uint64 in Little Endian - let transportMessageLen = fromBytesLE(uint64, payload[i .. (i + 8 - 1)]) - i += 8 - - # We read the transport message (handshakeMessage bytes) - payload2.transportMessage = payload[i .. i + transportMessageLen - 1] - i += transportMessageLen - - return ok(payload2) diff --git a/tests/all_tests_waku.nim b/tests/all_tests_waku.nim index 963a948a3..442d78b03 100644 --- a/tests/all_tests_waku.nim +++ b/tests/all_tests_waku.nim @@ -64,8 +64,6 @@ import ./test_waku_enr, ./test_waku_dnsdisc, ./test_relay_peer_exchange, - ./test_waku_noise, - ./test_waku_noise_sessions, ./test_waku_netconfig, ./test_waku_switch, ./test_waku_rendezvous, diff --git a/tests/node/test_wakunode_relay_rln.nim b/tests/node/test_wakunode_relay_rln.nim index e521abcca..140009846 100644 --- a/tests/node/test_wakunode_relay_rln.nim +++ b/tests/node/test_wakunode_relay_rln.nim @@ -28,8 +28,6 @@ import ../resources/payloads, ../waku_rln_relay/[utils_static, utils_onchain] -from ../../logos_delivery/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 diff --git a/tests/test_waku_keystore.nim b/tests/test_waku_keystore.nim index cba5d87b2..89304380a 100644 --- a/tests/test_waku_keystore.nim +++ b/tests/test_waku_keystore.nim @@ -3,8 +3,6 @@ import std/[os, json], chronos, testutils/unittests import logos_delivery/waku/waku_keystore, ./testlib/common -from logos_delivery/waku/waku_noise/noise_utils import randomSeqByte - procSuite "Credentials test suite": let testAppInfo = AppInfo(application: "test", appIdentifier: "1234", version: "0.1") diff --git a/tests/test_waku_keystore_keyfile.nim b/tests/test_waku_keystore_keyfile.nim index 4413659e8..8c19f82f3 100644 --- a/tests/test_waku_keystore_keyfile.nim +++ b/tests/test_waku_keystore_keyfile.nim @@ -3,8 +3,6 @@ import std/[json, os], stew/byteutils, testutils/unittests, chronos, eth/keys import logos_delivery/waku/waku_keystore, ./testlib/common -from logos_delivery/waku/waku_noise/noise_utils import randomSeqByte - suite "KeyFile test suite": test "Create/Save/Load single keyfile": # The password we use to encrypt our secret diff --git a/tests/test_waku_noise.nim b/tests/test_waku_noise.nim deleted file mode 100644 index 3709f9176..000000000 --- a/tests/test_waku_noise.nim +++ /dev/null @@ -1,901 +0,0 @@ -{.used.} - -import - testutils/unittests, - std/random, - std/tables, - stew/byteutils, - libp2p/crypto/chacha20poly1305, - libp2p/protobuf/minprotobuf, - stew/endians2 -import - logos_delivery/waku/[ - utils/noise as waku_message_utils, - waku_noise/noise_types, - waku_noise/noise_utils, - waku_noise/noise, - waku_noise/noise_handshake_processing, - waku_core, - ], - ./testlib/common - -procSuite "Waku Noise": - common.randomize() - - test "PKCS#7 Padding/Unpadding": - # We test padding for different message lengths - let maxMessageLength = 3 * NoisePaddingBlockSize - for messageLen in 0 .. maxMessageLength: - let - message = randomSeqByte(rng[], messageLen) - padded = pkcs7_pad(message, NoisePaddingBlockSize) - unpadded = pkcs7_unpad(padded, NoisePaddingBlockSize) - - check: - padded.len != 0 - padded.len mod NoisePaddingBlockSize == 0 - message == unpadded - - test "ChaChaPoly Encryption/Decryption: random byte sequences": - let cipherState = randomChaChaPolyCipherState(rng[]) - - # We encrypt/decrypt random byte sequences - let - plaintext: seq[byte] = randomSeqByte(rng[], rand(1 .. 128)) - ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext) - decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext) - - check: - plaintext == decryptedCiphertext - - test "ChaChaPoly Encryption/Decryption: random strings": - let cipherState = randomChaChaPolyCipherState(rng[]) - - # We encrypt/decrypt random strings - var plaintext: string - for _ in 1 .. rand(1 .. 128): - add(plaintext, char(rand(int('A') .. int('z')))) - - let - ciphertext: ChaChaPolyCiphertext = encrypt(cipherState, plaintext.toBytes()) - decryptedCiphertext: seq[byte] = decrypt(cipherState, ciphertext) - - check: - plaintext.toBytes() == decryptedCiphertext - - test "Noise public keys: encrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) - - let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) - encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) - decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) - - check: - noisePublicKey == decryptedPk - - test "Noise public keys: decrypt an unencrypted public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) - - let - 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 - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) - encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) - encryptedPk2: NoisePublicKey = encryptNoisePublicKey(cs, encryptedPk) - - check: - encryptedPk == encryptedPk2 - - test "Noise public keys: encrypt, decrypt and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) - - let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) - encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) - decryptedPk: NoisePublicKey = decryptNoisePublicKey(cs, encryptedPk) - decryptedPk2: NoisePublicKey = decryptNoisePublicKey(cs, decryptedPk) - - check: - decryptedPk == decryptedPk2 - - test "Noise public keys: serialize and deserialize an unencrypted public key": - let - noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) - serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(noisePublicKey) - deserializedNoisePublicKey: NoisePublicKey = - intoNoisePublicKey(serializedNoisePublicKey) - - check: - noisePublicKey == deserializedNoisePublicKey - - test "Noise public keys: encrypt, serialize, deserialize and decrypt a public key": - let noisePublicKey: NoisePublicKey = genNoisePublicKey(rng[]) - - let - cs: ChaChaPolyCipherState = randomChaChaPolyCipherState(rng[]) - encryptedPk: NoisePublicKey = encryptNoisePublicKey(cs, noisePublicKey) - serializedNoisePublicKey: seq[byte] = serializeNoisePublicKey(encryptedPk) - deserializedNoisePublicKey: NoisePublicKey = - intoNoisePublicKey(serializedNoisePublicKey) - decryptedPk: NoisePublicKey = - decryptNoisePublicKey(cs, deserializedNoisePublicKey) - - check: - noisePublicKey == decryptedPk - - test "PayloadV2: serialize/deserialize PayloadV2 to byte sequence": - let - payload2: PayloadV2 = randomPayloadV2(rng[]) - serializedPayload = serializePayloadV2(payload2) - - check: - serializedPayload.isOk() - - let deserializedPayload = deserializePayloadV2(serializedPayload.get()) - - check: - deserializedPayload.isOk() - payload2 == deserializedPayload.get() - - test "PayloadV2: Encode/Decode a Waku Message (version 2) to a PayloadV2": - # We encode to a WakuMessage a random PayloadV2 - let - payload2 = randomPayloadV2(rng[]) - msg = encodePayloadV2(payload2) - - check: - msg.isOk() - - # We create ProtoBuffer from WakuMessage - let pb = msg.get().encode() - - # We decode the WakuMessage from the ProtoBuffer - let msgFromPb = WakuMessage.decode(pb.buffer) - - check: - msgFromPb.isOk() - - let decoded = decodePayloadV2(msgFromPb.get()) - - check: - decoded.isOk() - payload2 == decoded.get() - - test "Noise State Machine: Diffie-Hellman operation": - #We generate random keypairs - let - 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 - let - dh1 = dh(getPrivateKey(aliceKey), getPublicKey(bobKey)) - dh2 = dh(getPrivateKey(bobKey), getPublicKey(aliceKey)) - - check: - dh1 == dh2 - - test "Noise State Machine: Cipher State primitives": - # We generate a random Cipher State, associated data ad and plaintext - var - 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)) - - # We set the random nonce generated in the cipher state - setNonce(cipherState, nonce) - - # We perform encryption - var ciphertext: seq[byte] = encryptWithAd(cipherState, ad, plaintext) - - # After any encryption/decryption operation, the Cipher State's nonce increases by 1 - check: - getNonce(cipherState) == nonce + 1 - - # We set the nonce back to its original value for decryption - setNonce(cipherState, nonce) - - # We decrypt (using the original nonce) - var decrypted: seq[byte] = decryptWithAd(cipherState, ad, ciphertext) - - # We check if encryption and decryption are correct and that nonce correctly increased after decryption - check: - getNonce(cipherState) == nonce + 1 - plaintext == decrypted - - # If a Cipher State has no key set, encryptWithAd should return the plaintext without increasing the nonce - setCipherStateKey(cipherState, EmptyKey) - nonce = getNonce(cipherState) - - plaintext = randomSeqByte(rng[], rand(1 .. 128)) - ciphertext = encryptWithAd(cipherState, ad, plaintext) - - check: - ciphertext == plaintext - getNonce(cipherState) == nonce - - # If a Cipher State has no key set, decryptWithAd should return the ciphertext without increasing the nonce - setCipherStateKey(cipherState, EmptyKey) - 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)) - plaintext = decryptWithAd(cipherState, ad, ciphertext) - - check: - ciphertext == plaintext - getNonce(cipherState) == nonce - - # A Cipher State cannot have a nonce greater or equal 2^64-1 - # 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[]) - setNonce(cipherState, NonceMax) - 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]: - expect NoiseNonceMaxError: - ciphertext = encryptWithAd(cipherState, ad, plaintext) - - check: - getNonce(cipherState) == NonceMax + 1 - - # We generate a test Cipher State - # 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[]) - setNonce(cipherState, NonceMax) - 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 - var - encNonce: ChaChaPolyNonce - authorizationTag: ChaChaPolyTag - encNonce[4 ..< 12] = toBytesLE(NonceMax) - ChaChaPoly.encrypt(getKey(cipherState), encNonce, authorizationTag, plaintext, ad) - - # The output ciphertext is stored in the plaintext variable after ChaChaPoly.encrypt is called: we copy it along with the authorization tag. - ciphertext = @[] - ciphertext.add(plaintext) - ciphertext.add(authorizationTag) - - # At this point ciphertext is a proper encryption of the original plaintext obtained with nonce equal to NonceMax - # We can now test if decryption fails with a NoiseNonceMaxError error. Any subsequent decryption call over the Cipher State should fail similarly and leave the nonce unchanged - # Note that decryptWithAd doesn't fail in decrypting the ciphertext (otherwise a NoiseDecryptTagError would have been triggered) - for _ in [1 .. 5]: - expect NoiseNonceMaxError: - plaintext = decryptWithAd(cipherState, ad, ciphertext) - - check: - getNonce(cipherState) == NonceMax + 1 - - test "Noise State Machine: Symmetric State primitives": - # We select one supported handshake pattern and we initialize a symmetric state - var - hsPattern = NoiseHandshakePatterns["XX"] - symmetricState: SymmetricState = SymmetricState.init(hsPattern) - - # We get all the Symmetric State field - # cs : Cipher State - # ck : chaining key - # h : handshake hash - var - cs = getCipherState(symmetricState) - ck = getChainingKey(symmetricState) - h = getHandshakeHash(symmetricState) - - # When a Symmetric state is initialized, handshake hash and chaining key are (byte-wise) equal - check: - h.data.intoChaChaPolyKey == ck - - ######################################## - # mixHash - ######################################## - - # We generate a random byte sequence and execute a mixHash over it - mixHash(symmetricState, randomSeqByte(rng[], rand(1 .. 128))) - - # mixHash changes only the handshake hash value of the Symmetric state - check: - cs == getCipherState(symmetricState) - ck == getChainingKey(symmetricState) - h != getHandshakeHash(symmetricState) - - # We update test values - h = getHandshakeHash(symmetricState) - - ######################################## - # mixKey - ######################################## - - # We generate random input key material and we execute mixKey - 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 - # It further sets to 0 the nonce of the embedded Cipher State - check: - getKey(cs) != getKey(getCipherState(symmetricState)) - getNonce(getCipherState(symmetricState)) == 0.uint64 - cs != getCipherState(symmetricState) - ck != getChainingKey(symmetricState) - h == getHandshakeHash(symmetricState) - - # We update test values - cs = getCipherState(symmetricState) - ck = getChainingKey(symmetricState) - - ######################################## - # mixKeyAndHash - ######################################## - - # We generate random input key material and we execute mixKeyAndHash - inputKeyMaterial = randomSeqByte(rng[], rand(1 .. 128)) - mixKeyAndHash(symmetricState, inputKeyMaterial) - - # mixKeyAndHash executes a mixKey and a mixHash using the input key material - # All Symmetric State's fields are updated - check: - cs != getCipherState(symmetricState) - ck != getChainingKey(symmetricState) - h != getHandshakeHash(symmetricState) - - # We update test values - cs = getCipherState(symmetricState) - ck = getChainingKey(symmetricState) - h = getHandshakeHash(symmetricState) - - ######################################## - # encryptAndHash and decryptAndHash - ######################################## - - # We store the initial symmetricState in order to correctly perform decryption - var initialSymmetricState = symmetricState - - # We generate random plaintext and we execute encryptAndHash - var plaintext = randomChaChaPolyKey(rng[]) - var nonce = getNonce(getCipherState(symmetricState)) - var ciphertext = encryptAndHash(symmetricState, plaintext) - - # encryptAndHash combines encryptWithAd and mixHash over the ciphertext (encryption increases the nonce of the embedded Cipher State but does not change its key) - # We check if only the handshake hash value and the Symmetric State changed accordingly - check: - cs != getCipherState(symmetricState) - getKey(cs) == getKey(getCipherState(symmetricState)) - getNonce(getCipherState(symmetricState)) == nonce + 1 - ck == getChainingKey(symmetricState) - h != getHandshakeHash(symmetricState) - - # We restore the symmetric State to its initial value to test decryption - symmetricState = initialSymmetricState - - # We execute decryptAndHash over the ciphertext - var decrypted = decryptAndHash(symmetricState, ciphertext) - - # decryptAndHash combines decryptWithAd and mixHash over the ciphertext (encryption increases the nonce of the embedded Cipher State but does not change its key) - # We check if only the handshake hash value and the Symmetric State changed accordingly - # We further check if decryption corresponds to the original plaintext - check: - cs != getCipherState(symmetricState) - getKey(cs) == getKey(getCipherState(symmetricState)) - getNonce(getCipherState(symmetricState)) == nonce + 1 - ck == getChainingKey(symmetricState) - h != getHandshakeHash(symmetricState) - decrypted == plaintext - - ######################################## - # split - ######################################## - - # If at least one mixKey is executed (as above), ck is non-empty - check: - getChainingKey(symmetricState) != EmptyKey - - # When a Symmetric State's ck is non-empty, we can execute split, which creates two distinct Cipher States cs1 and cs2 - # with non-empty encryption keys and nonce set to 0 - var (cs1, cs2) = split(symmetricState) - - check: - getKey(cs1) != EmptyKey - getKey(cs2) != EmptyKey - getNonce(cs1) == 0.uint64 - getNonce(cs2) == 0.uint64 - getKey(cs1) != getKey(cs2) - - test "Noise XX Handhshake and message encryption (extended test)": - let hsPattern = NoiseHandshakePatterns["XX"] - - # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - var aliceHS = - initialize(hsPattern = hsPattern, staticKey = aliceStaticKey, initiator = true) - - let bobStaticKey = genKeyPair(rng[]) - var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey) - - var - sentTransportMessage: seq[byte] - aliceStep, bobStep: HandshakeStepResult - - # Here the handshake starts - # Write and read calls alternate between Alice and Bob: the handhshake progresses by alternatively calling stepHandshake for each user - - ############### - # 1st step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - ############### - # 2nd step - ############### - - # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) - - # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() - - # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() - - check: - aliceStep.transportMessage == sentTransportMessage - - ############### - # 3rd step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - # Note that for this handshake pattern, no more message patterns are left for processing - # Another call to stepHandshake would return an empty HandshakeStepResult - # We test that extra calls to stepHandshake do not affect parties' handshake states - # and that the intermediate HandshakeStepResult are empty - let prevAliceHS = aliceHS - let prevBobHS = bobHS - - let bobStep1 = - stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() - let aliceStep1 = - stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep1.payload2).get() - let aliceStep2 = - stepHandshake(rng[], aliceHS, transportMessage = sentTransportMessage).get() - let bobStep2 = - stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep2.payload2).get() - - check: - aliceStep1 == default(HandshakeStepResult) - aliceStep2 == default(HandshakeStepResult) - bobStep1 == default(HandshakeStepResult) - bobStep2 == default(HandshakeStepResult) - aliceHS == prevAliceHS - bobHS == prevBobHS - - ######################### - # After Handshake - ######################### - - # We finalize the handshake to retrieve the Inbound/Outbound symmetric states - var aliceHSResult, bobHSResult: HandshakeResult - - aliceHSResult = finalizeHandshake(aliceHS) - bobHSResult = finalizeHandshake(bobHS) - - # We test read/write of random messages exchanged between Alice and Bob - var - payload2: PayloadV2 - message: seq[byte] - readMessage: seq[byte] - defaultMessageNametagBuffer: MessageNametagBuffer - - for _ in 0 .. 10: - # Alice writes to Bob - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - # Bob writes to Alice - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - test "Noise XXpsk0 Handhshake and message encryption (short test)": - let hsPattern = NoiseHandshakePatterns["XXpsk0"] - - # We generate a random psk - let psk = randomSeqByte(rng[], 32) - - # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - var aliceHS = initialize( - hsPattern = hsPattern, staticKey = aliceStaticKey, psk = psk, initiator = true - ) - - let bobStaticKey = genKeyPair(rng[]) - var bobHS = initialize(hsPattern = hsPattern, staticKey = bobStaticKey, psk = psk) - - var - sentTransportMessage: seq[byte] - aliceStep, bobStep: HandshakeStepResult - - # Here the handshake starts - # Write and read calls alternate between Alice and Bob: the handhshake progresses by alternatively calling stepHandshake for each user - - ############### - # 1st step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - ############### - # 2nd step - ############### - - # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) - - # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() - - # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() - - check: - aliceStep.transportMessage == sentTransportMessage - - ############### - # 3rd step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - # Note that for this handshake pattern, no more message patterns are left for processing - - ######################### - # After Handshake - ######################### - - # We finalize the handshake to retrieve the Inbound/Outbound Symmetric States - var aliceHSResult, bobHSResult: HandshakeResult - - aliceHSResult = finalizeHandshake(aliceHS) - bobHSResult = finalizeHandshake(bobHS) - - # We test read/write of random messages exchanged between Alice and Bob - var - payload2: PayloadV2 - message: seq[byte] - readMessage: seq[byte] - defaultMessageNametagBuffer: MessageNametagBuffer - - for _ in 0 .. 10: - # Alice writes to Bob - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - # Bob writes to Alice - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - test "Noise K1K1 Handhshake and message encryption (short test)": - let hsPattern = NoiseHandshakePatterns["K1K1"] - - # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) - - # This handshake has the following pre-message pattern: - # -> s - # <- s - # ... - # So we define accordingly the sequence of the pre-message public keys - let preMessagePKs: seq[NoisePublicKey] = @[ - toNoisePublicKey(getPublicKey(aliceStaticKey)), - toNoisePublicKey(getPublicKey(bobStaticKey)), - ] - - var aliceHS = initialize( - hsPattern = hsPattern, - staticKey = aliceStaticKey, - preMessagePKs = preMessagePKs, - initiator = true, - ) - var bobHS = initialize( - hsPattern = hsPattern, staticKey = bobStaticKey, preMessagePKs = preMessagePKs - ) - - var - sentTransportMessage: seq[byte] - aliceStep, bobStep: HandshakeStepResult - - # Here the handshake starts - # Write and read calls alternate between Alice and Bob: the handhshake progresses by alternatively calling stepHandshake for each user - - ############### - # 1st step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - ############### - # 2nd step - ############### - - # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) - - # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() - - # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() - - check: - aliceStep.transportMessage == sentTransportMessage - - ############### - # 3rd step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transportMessage alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - # Note that for this handshake pattern, no more message patterns are left for processing - - ######################### - # After Handshake - ######################### - - # We finalize the handshake to retrieve the Inbound/Outbound Symmetric States - var aliceHSResult, bobHSResult: HandshakeResult - - aliceHSResult = finalizeHandshake(aliceHS) - bobHSResult = finalizeHandshake(bobHS) - - # We test read/write of random messages between Alice and Bob - var - payload2: PayloadV2 - message: seq[byte] - readMessage: seq[byte] - defaultMessageNametagBuffer: MessageNametagBuffer - - for _ in 0 .. 10: - # Alice writes to Bob - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - # Bob writes to Alice - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - test "Noise XK1 Handhshake and message encryption (short test)": - let hsPattern = NoiseHandshakePatterns["XK1"] - - # We initialize Alice's and Bob's Handshake State - let aliceStaticKey = genKeyPair(rng[]) - let bobStaticKey = genKeyPair(rng[]) - - # This handshake has the following pre-message pattern: - # <- s - # ... - # So we define accordingly the sequence of the pre-message public keys - let preMessagePKs: seq[NoisePublicKey] = - @[toNoisePublicKey(getPublicKey(bobStaticKey))] - - var aliceHS = initialize( - hsPattern = hsPattern, - staticKey = aliceStaticKey, - preMessagePKs = preMessagePKs, - initiator = true, - ) - var bobHS = initialize( - hsPattern = hsPattern, staticKey = bobStaticKey, preMessagePKs = preMessagePKs - ) - - var - sentTransportMessage: seq[byte] - aliceStep, bobStep: HandshakeStepResult - - # Here the handshake starts - # Write and read calls alternate between Alice and Bob: the handhshake progresses by alternatively calling stepHandshake for each user - - ############### - # 1st step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - ############### - # 2nd step - ############### - - # We generate a random transport message - sentTransportMessage = randomSeqByte(rng[], 32) - - # At this step, Bob writes and returns a payload - bobStep = stepHandshake(rng[], bobHS, transportMessage = sentTransportMessage).get() - - # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake(rng[], aliceHS, readPayloadV2 = bobStep.payload2).get() - - check: - aliceStep.transportMessage == sentTransportMessage - - ############### - # 3rd step - ############### - - # We generate a random transport message - 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() - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake(rng[], bobHS, readPayloadV2 = aliceStep.payload2).get() - - check: - bobStep.transportMessage == sentTransportMessage - - # Note that for this handshake pattern, no more message patterns are left for processing - - ######################### - # After Handshake - ######################### - - # We finalize the handshake to retrieve the Inbound/Outbound Symmetric States - var aliceHSResult, bobHSResult: HandshakeResult - - aliceHSResult = finalizeHandshake(aliceHS) - bobHSResult = finalizeHandshake(bobHS) - - # We test read/write of random messages exchanged between Alice and Bob - var - payload2: PayloadV2 - message: seq[byte] - readMessage: seq[byte] - defaultMessageNametagBuffer: MessageNametagBuffer - - for _ in 0 .. 10: - # Alice writes to Bob - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(aliceHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(bobHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage - - # Bob writes to Alice - message = randomSeqByte(rng[], 32) - payload2 = writeMessage(bobHSResult, message, defaultMessageNametagBuffer) - readMessage = - readMessage(aliceHSResult, payload2, defaultMessageNametagBuffer).get() - - check: - message == readMessage diff --git a/tests/test_waku_noise_sessions.nim b/tests/test_waku_noise_sessions.nim deleted file mode 100644 index 8393a7ba5..000000000 --- a/tests/test_waku_noise_sessions.nim +++ /dev/null @@ -1,421 +0,0 @@ -{.used.} - -import std/tables, results, stew/byteutils, testutils/unittests -import - logos_delivery/waku/[ - common/protobuf, - utils/noise as waku_message_utils, - waku_noise/noise_types, - waku_noise/noise_utils, - waku_noise/noise_handshake_processing, - waku_core, - ], - ./testlib/common - -procSuite "Waku Noise Sessions": - randomize() - - # This test implements the Device pairing and Secure Transfers with Noise - # detailed in the 43/WAKU2-DEVICE-PAIRING RFC https://rfc.vac.dev/spec/43/ - test "Noise Waku Pairing Handhshake and Secure transfer": - ######################### - # Pairing Phase - ######################### - - 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 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 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) - - # Out-of-band Communication - - # Bob prepares the QR and sends it out-of-band to Alice - let qr = toQr( - applicationName, - applicationVersion, - shardId, - getPublicKey(bobEphemeralKey), - bobCommittedStaticKey, - ) - - # Alice deserializes the QR code - let ( - readApplicationName, readApplicationVersion, readShardId, readEphemeralKey, - readCommittedStaticKey, - ) = fromQr(qr) - - # We check if QR serialization/deserialization works - check: - applicationName == readApplicationName - applicationVersion == readApplicationVersion - shardId == readShardId - getPublicKey(bobEphemeralKey) == readEphemeralKey - bobCommittedStaticKey == readCommittedStaticKey - - # We set the contentTopic from the content topic parameters exchanged in the QR - let contentTopic: ContentTopic = - "/" & applicationName & "/" & applicationVersion & "/wakunoise/1/sessions_shard-" & - shardId & "/proto" - - ############### - # Pre-handshake message - # - # <- eB {H(sB||r), contentTopicParams, messageNametag} - ############### - let preMessagePKs: seq[NoisePublicKey] = - @[toNoisePublicKey(getPublicKey(bobEphemeralKey))] - - # We initialize the Handshake states. - # Note that we pass the whole qr serialization as prologue information - var aliceHS = initialize( - hsPattern = hsPattern, - ephemeralKey = aliceEphemeralKey, - staticKey = aliceStaticKey, - prologue = qr.toBytes, - preMessagePKs = preMessagePKs, - initiator = true, - ) - var bobHS = initialize( - hsPattern = hsPattern, - ephemeralKey = bobEphemeralKey, - staticKey = bobStaticKey, - prologue = qr.toBytes, - preMessagePKs = preMessagePKs, - ) - - ############### - # Pairing Handshake - ############### - - var - sentTransportMessage: seq[byte] - aliceStep, bobStep: HandshakeStepResult - msgFromPb: ProtobufResult[WakuMessage] - wakuMsg: Result[WakuMessage, cstring] - pb: ProtoBuffer - readPayloadV2: PayloadV2 - aliceMessageNametag, bobMessageNametag: MessageNametag - - # Write and read calls alternate between Alice and Bob: the handhshake progresses by alternatively calling stepHandshake for each user - - ############### - # 1st step - # - # -> eA, eAeB {H(sA||s)} [authcode] - ############### - - # The messageNametag for the first handshake message is randomly generated and exchanged out-of-band - # and corresponds to qrMessageNametag - - # We set the transport message to be H(sA||s) - sentTransportMessage = digestToSeq(aliceCommittedStaticKey) - - # We ensure that digestToSeq and its inverse seqToDigest256 are correct - check: - seqToDigest256(sentTransportMessage) == aliceCommittedStaticKey - - # By being the handshake initiator, Alice writes a Waku2 payload v2 containing her handshake message - # and the (encrypted) transport message - # The message is sent with a messageNametag equal to the one received through the QR code - aliceStep = stepHandshake( - rng[], - aliceHS, - transportMessage = sentTransportMessage, - messageNametag = qrMessageNametag, - ) - .get() - - ############################################### - # We prepare a Waku message from Alice's payload2 - wakuMsg = encodePayloadV2(aliceStep.payload2, contentTopic) - - check: - wakuMsg.isOk() - wakuMsg.get().contentTopic == contentTopic - - # At this point wakuMsg is sent over the Waku network and is received - # We simulate this by creating the ProtoBuffer from wakuMsg - pb = wakuMsg.get().encode() - - # We decode the WakuMessage from the ProtoBuffer - msgFromPb = WakuMessage.decode(pb.buffer) - - check: - msgFromPb.isOk() - - # We decode the payloadV2 from the WakuMessage - readPayloadV2 = decodePayloadV2(msgFromPb.get()).get() - - check: - readPayloadV2 == aliceStep.payload2 - ############################################### - - # 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 - ) - .get() - - check: - bobStep.transportMessage == sentTransportMessage - - # We generate an authorization code using the handshake state - let aliceAuthcode = genAuthcode(aliceHS) - let bobAuthcode = genAuthcode(bobHS) - - # We check that they are equal. Note that this check has to be confirmed with a user interaction. - check: - aliceAuthcode == bobAuthcode - - ############### - # 2nd step - # - # <- sB, eAsB {r} - ############### - - # Alice and Bob update their local next messageNametag using the available handshake information - # During the handshake, messageNametag = HKDF(h), where h is the handshake hash value at the end of the last processed message - aliceMessageNametag = toMessageNametag(aliceHS) - bobMessageNametag = toMessageNametag(bobHS) - - # We set as a transport message the commitment randomness r - sentTransportMessage = r - - # At this step, Bob writes and returns a payload - bobStep = stepHandshake( - rng[], - bobHS, - transportMessage = sentTransportMessage, - messageNametag = bobMessageNametag, - ) - .get() - - ############################################### - # We prepare a Waku message from Bob's payload2 - wakuMsg = encodePayloadV2(bobStep.payload2, contentTopic) - - check: - wakuMsg.isOk() - wakuMsg.get().contentTopic == contentTopic - - # At this point wakuMsg is sent over the Waku network and is received - # We simulate this by creating the ProtoBuffer from wakuMsg - pb = wakuMsg.get().encode() - - # We decode the WakuMessage from the ProtoBuffer - msgFromPb = WakuMessage.decode(pb.buffer) - - check: - msgFromPb.isOk() - - # We decode the payloadV2 from the WakuMessage - readPayloadV2 = decodePayloadV2(msgFromPb.get()).get() - - check: - readPayloadV2 == bobStep.payload2 - ############################################### - - # While Alice reads and returns the (decrypted) transport message - aliceStep = stepHandshake( - rng[], - aliceHS, - readPayloadV2 = readPayloadV2, - messageNametag = aliceMessageNametag, - ) - .get() - - check: - aliceStep.transportMessage == sentTransportMessage - - # Alice further checks if Bob's commitment opens to Bob's static key she just received - let expectedBobCommittedStaticKey = - commitPublicKey(aliceHS.rs, aliceStep.transportMessage) - - check: - expectedBobCommittedStaticKey == bobCommittedStaticKey - - ############### - # 3rd step - # - # -> sA, sAeB, sAsB {s} - ############### - - # Alice and Bob update their local next messageNametag using the available handshake information - aliceMessageNametag = toMessageNametag(aliceHS) - bobMessageNametag = toMessageNametag(bobHS) - - # We set as a transport message the commitment randomness s - sentTransportMessage = s - - # 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, - messageNametag = aliceMessageNametag, - ) - .get() - - ############################################### - # We prepare a Waku message from Bob's payload2 - wakuMsg = encodePayloadV2(aliceStep.payload2, contentTopic) - - check: - wakuMsg.isOk() - wakuMsg.get().contentTopic == contentTopic - - # At this point wakuMsg is sent over the Waku network and is received - # We simulate this by creating the ProtoBuffer from wakuMsg - pb = wakuMsg.get().encode() - - # We decode the WakuMessage from the ProtoBuffer - msgFromPb = WakuMessage.decode(pb.buffer) - - check: - msgFromPb.isOk() - - # We decode the payloadV2 from the WakuMessage - readPayloadV2 = decodePayloadV2(msgFromPb.get()).get() - - check: - readPayloadV2 == aliceStep.payload2 - ############################################### - - # Bob reads Alice's payloads, and returns the (decrypted) transport message Alice sent to him - bobStep = stepHandshake( - rng[], bobHS, readPayloadV2 = readPayloadV2, messageNametag = bobMessageNametag - ) - .get() - - check: - bobStep.transportMessage == sentTransportMessage - - # Bob further checks if Alice's commitment opens to Alice's static key he just received - let expectedAliceCommittedStaticKey = - commitPublicKey(bobHS.rs, bobStep.transportMessage) - - check: - expectedAliceCommittedStaticKey == aliceCommittedStaticKey - - ######################### - # Secure Transfer Phase - ######################### - - # We finalize the handshake to retrieve the Inbound/Outbound Symmetric States - var aliceHSResult, bobHSResult: HandshakeResult - - aliceHSResult = finalizeHandshake(aliceHS) - bobHSResult = finalizeHandshake(bobHS) - - # We test read/write of random messages exchanged between Alice and Bob - var - payload2: PayloadV2 - message: seq[byte] - readMessage: seq[byte] - - # We test message exchange - # 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) - payload2 = writeMessage( - aliceHSResult, - message, - outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, - ) - readMessage = readMessage( - bobHSResult, - payload2, - inboundMessageNametagBuffer = bobHSResult.nametagsInbound, - ) - .get() - - check: - message == readMessage - - # Bob writes to Alice - message = randomSeqByte(rng[], 32) - payload2 = writeMessage( - bobHSResult, - message, - outboundMessageNametagBuffer = bobHSResult.nametagsOutbound, - ) - readMessage = readMessage( - aliceHSResult, - payload2, - inboundMessageNametagBuffer = aliceHSResult.nametagsInbound, - ) - .get() - - check: - message == readMessage - - # 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) - payload2 = writeMessage( - aliceHSResult, - message, - outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, - ) - message = randomSeqByte(rng[], 32) - payload2 = writeMessage( - aliceHSResult, - message, - outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, - ) - expect NoiseSomeMessagesWereLost: - readMessage = readMessage( - bobHSResult, - payload2, - inboundMessageNametagBuffer = bobHSResult.nametagsInbound, - ) - .get() - - # We adjust bob nametag buffer for next test (i.e. the missed message is correctly recovered) - delete(bobHSResult.nametagsInbound, 2) - message = randomSeqByte(rng[], 32) - payload2 = writeMessage( - bobHSResult, message, outboundMessageNametagBuffer = bobHSResult.nametagsOutbound - ) - readMessage = readMessage( - aliceHSResult, - payload2, - inboundMessageNametagBuffer = aliceHSResult.nametagsInbound, - ) - .get() - - check: - message == readMessage - - # We test if a missing nametag is correctly detected - message = randomSeqByte(rng[], 32) - payload2 = writeMessage( - aliceHSResult, - message, - outboundMessageNametagBuffer = aliceHSResult.nametagsOutbound, - ) - delete(bobHSResult.nametagsInbound, 1) - expect NoiseMessageNametagError: - readMessage = readMessage( - bobHSResult, - payload2, - inboundMessageNametagBuffer = bobHSResult.nametagsInbound, - ) - .get() diff --git a/tests/testlib/common.nim b/tests/testlib/common.nim index 216320692..ddd80b71b 100644 --- a/tests/testlib/common.nim +++ b/tests/testlib/common.nim @@ -30,3 +30,8 @@ proc getRng(): ref HmacDrbgContext = template rng*(): ref HmacDrbgContext = getRng() + +proc randomSeqByte*(rng: var HmacDrbgContext, size: int): seq[byte] = + var output = newSeq[byte](size.uint32) + hmacDrbgGenerate(rng, output) + return output From 362c35f2fb134707e1d2586c357ea27ac4ddd629 Mon Sep 17 00:00:00 2001 From: Tanya S <120410716+stubbsta@users.noreply.github.com> Date: Tue, 9 Jun 2026 14:25:13 +0200 Subject: [PATCH 12/13] Install specific foundry anvil version directly (#3937) * Install specific foundry anvil version directly * clean verbose comments --- scripts/install_anvil.sh | 88 +++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/scripts/install_anvil.sh b/scripts/install_anvil.sh index c573ac31c..90062ef56 100755 --- a/scripts/install_anvil.sh +++ b/scripts/install_anvil.sh @@ -1,52 +1,74 @@ #!/usr/bin/env bash -# Install Anvil +# Install Foundry binaries (forge, cast, anvil, chisel). +# +# We bypass `foundryup` and pull the release tarball straight from GitHub. -REQUIRED_FOUNDRY_VERSION="$1" +set -euo pipefail -if command -v anvil &> /dev/null; then - # Foundry is already installed; check the current version. +REQUIRED_FOUNDRY_VERSION="${1:-}" +if [ -z "$REQUIRED_FOUNDRY_VERSION" ]; then + echo "usage: install_anvil.sh " >&2 + exit 1 +fi + +if command -v anvil >/dev/null 2>&1; then CURRENT_FOUNDRY_VERSION=$(anvil --version 2>/dev/null | awk '{print $2}') if [ -n "$CURRENT_FOUNDRY_VERSION" ]; then - # Compare CURRENT_FOUNDRY_VERSION < REQUIRED_FOUNDRY_VERSION using sort -V lower_version=$(printf '%s\n%s\n' "$CURRENT_FOUNDRY_VERSION" "$REQUIRED_FOUNDRY_VERSION" | sort -V | head -n1) if [ "$lower_version" != "$REQUIRED_FOUNDRY_VERSION" ]; then echo "Anvil is already installed with version $CURRENT_FOUNDRY_VERSION, which is older than the required $REQUIRED_FOUNDRY_VERSION. Please update Foundry manually if needed." fi fi -else - BASE_DIR="${XDG_CONFIG_HOME:-$HOME}" - FOUNDRY_DIR="${FOUNDRY_DIR:-"$BASE_DIR/.foundry"}" - FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" + exit 0 +fi - echo "Installing Foundry..." - curl -L https://foundry.paradigm.xyz | bash +case "$(uname -s)" in + Darwin) PLATFORM=darwin ;; + Linux) PLATFORM=linux ;; + *) echo "Unsupported platform: $(uname -s)" >&2; exit 1 ;; +esac - # Add Foundry to PATH for this script session - export PATH="$FOUNDRY_BIN_DIR:$PATH" +case "$(uname -m)" in + x86_64|amd64) ARCH=amd64 ;; + arm64|aarch64) ARCH=arm64 ;; + *) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;; +esac - # Verify foundryup is available - if ! command -v foundryup >/dev/null 2>&1; then - echo "Error: foundryup installation failed or not found in $FOUNDRY_BIN_DIR" - exit 1 - fi +BASE_DIR="${XDG_CONFIG_HOME:-$HOME}" +FOUNDRY_DIR="${FOUNDRY_DIR:-"$BASE_DIR/.foundry"}" +FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" - # Run foundryup to install the required version - if [ -n "$REQUIRED_FOUNDRY_VERSION" ]; then - echo "Installing Foundry tools version $REQUIRED_FOUNDRY_VERSION..." - foundryup --install "$REQUIRED_FOUNDRY_VERSION" - else - echo "Installing latest Foundry tools..." - foundryup - fi +TAG="v${REQUIRED_FOUNDRY_VERSION}" +ASSET="foundry_${TAG}_${PLATFORM}_${ARCH}.tar.gz" +URL="https://github.com/foundry-rs/foundry/releases/download/${TAG}/${ASSET}" - # Verify anvil was installed - if ! command -v anvil >/dev/null 2>&1; then - echo "Error: anvil installation failed" - exit 1 - fi +echo "Installing Foundry ${TAG} for ${PLATFORM}/${ARCH}..." +mkdir -p "$FOUNDRY_BIN_DIR" - echo "Anvil successfully installed: $(anvil --version)" -fi \ No newline at end of file +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT +archive="$tmpdir/foundry.tar.gz" + +curl -fL --retry 5 --retry-delay 2 --retry-all-errors -o "$archive" "$URL" + +# Validate the archive before extracting -- catches truncated/HTML responses +# loudly instead of leaving a half-installed Foundry on disk. +tar tzf "$archive" >/dev/null + +tar -xzf "$archive" -C "$FOUNDRY_BIN_DIR" forge cast anvil chisel +chmod +x "$FOUNDRY_BIN_DIR"/{forge,cast,anvil,chisel} + +export PATH="$FOUNDRY_BIN_DIR:$PATH" +if [ -n "${GITHUB_PATH:-}" ]; then + echo "$FOUNDRY_BIN_DIR" >> "$GITHUB_PATH" +fi + +if ! command -v anvil >/dev/null 2>&1; then + echo "Error: anvil installation failed" >&2 + exit 1 +fi + +echo "Anvil successfully installed: $(anvil --version)" From 41b5c4906ff341b5212edd39ce6889e7c45cb58d Mon Sep 17 00:00:00 2001 From: Fabiana Cecin Date: Wed, 10 Jun 2026 09:09:22 -0300 Subject: [PATCH 13/13] feat: Improve config (v2) (#3925) * rename NetworkConf -> NetworkPresetConf and related procs/vars * Rewrite applyNetworkPresetConf to apply user-set fields over preset fields * New dedicated parser for configJson * Fix tests to use actual extract JSON nodeconf parser * Change all confbuilder defaults from literal values to DefaultXXX consts * Change int/bool WakuNodeConf fields to Option to get user intent w/o sentinels * Make Option CLI default-value help mention defaults now owned by confbuilder * Document CLI defaults that differ from confbuilder defaults * Fix agent-string builder default deviating from CLI default * Add WakuConfBuilder.enforceSecurityConstraints() * Fail on RLN user preset overrides instead of drop-and-continue * Add regression tests for initial set of conf constraints * fix kademliaDiscoveryConfBuilder.build() enable/disable kad logic * Misc refactors, fixes * Add tests Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> --- .../liteprotocoltester/liteprotocoltester.nim | 2 +- apps/networkmonitor/networkmonitor.nim | 2 +- examples/wakustealthcommitments/node_spec.nim | 14 +- .../logos_delivery_api/node_api.nim | 64 +--- logos_delivery/waku/api/api.nim | 4 +- .../conf_builder/discv5_conf_builder.nim | 18 +- .../filter_service_conf_builder.nim | 14 +- .../kademlia_discovery_conf_builder.nim | 15 +- .../metrics_server_conf_builder.nim | 12 +- .../factory/conf_builder/mix_conf_builder.nim | 4 +- .../conf_builder/rest_server_conf_builder.nim | 9 +- .../conf_builder/rln_relay_conf_builder.nim | 16 +- .../store_service_conf_builder.nim | 20 +- .../conf_builder/store_sync_conf_builder.nim | 4 +- .../conf_builder/waku_conf_builder.nim | 338 +++++++++++------- .../conf_builder/web_socket_conf_builder.nim | 9 +- .../waku/factory/networks_config.nim | 20 +- tests/api/test_api_health.nim | 4 +- tests/api/test_api_receive.nim | 4 +- tests/api/test_api_send.nim | 4 +- tests/api/test_api_subscription.nim | 4 +- tests/api/test_node_conf.nim | 71 ++-- .../test_reliable_channel_send_receive.nim | 6 +- tests/factory/test_waku_conf.nim | 205 ++++++----- tests/test_waku.nim | 24 +- tests/wakunode2/test_cli_args.nim | 6 +- tools/confutils/cli_args.nim | 140 +++++--- tools/confutils/conf_from_json.nim | 121 +++++++ 28 files changed, 709 insertions(+), 445 deletions(-) create mode 100644 tools/confutils/conf_from_json.nim diff --git a/apps/liteprotocoltester/liteprotocoltester.nim b/apps/liteprotocoltester/liteprotocoltester.nim index bcfe2cdec..dd3097e49 100644 --- a/apps/liteprotocoltester/liteprotocoltester.nim +++ b/apps/liteprotocoltester/liteprotocoltester.nim @@ -95,7 +95,7 @@ when isMainModule: wakuNodeConf.shards = @[conf.shard] wakuNodeConf.contentTopics = conf.contentTopics - wakuNodeConf.clusterId = conf.clusterId + wakuNodeConf.clusterId = some(conf.clusterId) ## TODO: Depending on the tester needs we might extend here with shards, clusterId, etc... wakuNodeConf.metricsServer = true diff --git a/apps/networkmonitor/networkmonitor.nim b/apps/networkmonitor/networkmonitor.nim index 61bb8d07a..4fed6da01 100644 --- a/apps/networkmonitor/networkmonitor.nim +++ b/apps/networkmonitor/networkmonitor.nim @@ -550,7 +550,7 @@ when isMainModule: info "cli flags", conf = conf if conf.clusterId == 1: - let twnNetworkConf = NetworkConf.TheWakuNetworkConf() + let twnNetworkConf = NetworkPresetConf.TheWakuNetworkConf() conf.bootstrapNodes = twnNetworkConf.discv5BootstrapNodes conf.rlnRelayDynamic = twnNetworkConf.rlnRelayDynamic diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index 8eb11595c..3f4deeb08 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -21,7 +21,7 @@ proc setup*(): Waku = error "failure while loading the configuration", error = $error quit(QuitFailure) - let twnNetworkConf = NetworkConf.TheWakuNetworkConf() + let twnNetworkConf = NetworkPresetConf.TheWakuNetworkConf() if len(conf.shards) != 0: conf.pubsubTopics = conf.shards.mapIt(twnNetworkConf.pubsubTopics[it.uint16]) else: @@ -29,18 +29,18 @@ proc setup*(): Waku = # Override configuration conf.maxMessageSize = twnNetworkConf.maxMessageSize - conf.clusterId = twnNetworkConf.clusterId + conf.clusterId = some(twnNetworkConf.clusterId) conf.rlnRelayEthContractAddress = twnNetworkConf.rlnRelayEthContractAddress - conf.rlnRelayDynamic = twnNetworkConf.rlnRelayDynamic - conf.discv5Discovery = twnNetworkConf.discv5Discovery + conf.rlnRelayDynamic = some(twnNetworkConf.rlnRelayDynamic) + conf.discv5Discovery = some(twnNetworkConf.discv5Discovery) conf.discv5BootstrapNodes = conf.discv5BootstrapNodes & twnNetworkConf.discv5BootstrapNodes - conf.rlnEpochSizeSec = twnNetworkConf.rlnEpochSizeSec - conf.rlnRelayUserMessageLimit = twnNetworkConf.rlnRelayUserMessageLimit + conf.rlnEpochSizeSec = some(twnNetworkConf.rlnEpochSizeSec) + conf.rlnRelayUserMessageLimit = some(twnNetworkConf.rlnRelayUserMessageLimit) # Only set rlnRelay to true if relay is configured if conf.relay: - conf.rlnRelay = twnNetworkConf.rlnRelay + conf.rlnRelay = some(twnNetworkConf.rlnRelay) info "Starting node" var waku = (waitFor Waku.new(conf)).valueOr: diff --git a/liblogosdelivery/logos_delivery_api/node_api.nim b/liblogosdelivery/logos_delivery_api/node_api.nim index de6f69c19..58785e80d 100644 --- a/liblogosdelivery/logos_delivery_api/node_api.nim +++ b/liblogosdelivery/logos_delivery_api/node_api.nim @@ -1,11 +1,11 @@ -import std/[json, strutils, tables] -import chronos, chronicles, results, confutils, confutils/std/net, ffi +import std/json +import chronos, chronicles, results, ffi import logos_delivery/waku/factory/waku, logos_delivery/waku/node/waku_node, logos_delivery/waku/api/[api, types], logos_delivery/waku/events/[message_events, health_events], - tools/confutils/cli_args, + tools/confutils/conf_from_json, ../declare_lib, ../json_event @@ -15,59 +15,11 @@ proc `%`*(id: RequestId): JsonNode = registerReqFFI(CreateNodeRequest, ctx: ptr FFIContext[Waku]): proc(configJson: cstring): Future[Result[string, string]] {.async.} = - ## Parse the JSON configuration using fieldPairs approach (WakuNodeConf) - var conf = defaultWakuNodeConf().valueOr: - return err("Failed creating default conf: " & error) + let conf = parseNodeConfFromJson($configJson).valueOr: + error "Failed to assemble WakuNodeConf from JSON", + error = error, configJson = $configJson + return err("failed parseNodeConfFromJson " & error) - var jsonNode: JsonNode - try: - jsonNode = parseJson($configJson) - except Exception: - let exceptionMsg = getCurrentExceptionMsg() - error "Failed to parse config JSON", - error = exceptionMsg, configJson = $configJson - return err( - "Failed to parse config JSON: " & exceptionMsg & " configJson string: " & - $configJson - ) - - var jsonFields: Table[string, (string, JsonNode)] - for key, value in jsonNode: - let lowerKey = key.toLowerAscii() - - if jsonFields.hasKey(lowerKey): - error "Duplicate configuration option found when normalized to lowercase", - key = key - return err( - "Duplicate configuration option found when normalized to lowercase: '" & key & - "'" - ) - - jsonFields[lowerKey] = (key, value) - - for confField, confValue in fieldPairs(conf): - let lowerField = confField.toLowerAscii() - if jsonFields.hasKey(lowerField): - let (jsonKey, jsonValue) = jsonFields[lowerField] - let formattedString = ($jsonValue).strip(chars = {'\"'}) - try: - confValue = parseCmdArg(typeof(confValue), formattedString) - except Exception: - return err( - "Failed to parse field '" & confField & "' from JSON key '" & jsonKey & "': " & - getCurrentExceptionMsg() & ". Value: " & formattedString - ) - - jsonFields.del(lowerField) - - if jsonFields.len > 0: - var unknownKeys = newSeq[string]() - for _, (jsonKey, _) in pairs(jsonFields): - unknownKeys.add(jsonKey) - error "Unrecognized configuration option(s) found", option = unknownKeys - return err("Unrecognized configuration option(s) found: " & $unknownKeys) - - # Create the node ctx.myLib[] = (await api.createNode(conf)).valueOr: let errMsg = $error chronicles.error "CreateNodeRequest failed", err = errMsg @@ -96,7 +48,7 @@ proc logosdelivery_create_node( ): pointer {.dynlib, exportc, cdecl.} = initializeLibrary() - if isNil(callback): + if callback.isNil(): echo "error: missing callback in logosdelivery_create_node" return nil diff --git a/logos_delivery/waku/api/api.nim b/logos_delivery/waku/api/api.nim index 1cbe47256..74cf5888b 100644 --- a/logos_delivery/waku/api/api.nim +++ b/logos_delivery/waku/api/api.nim @@ -1,4 +1,6 @@ -import chronicles, chronos, results +import std/[net, options] + +import chronicles, chronos, libp2p/peerid, results import logos_delivery/waku/factory/waku import logos_delivery/messaging/messaging_client diff --git a/logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim index 5dd269d23..e28cb10fb 100644 --- a/logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/discv5_conf_builder.nim @@ -4,7 +4,13 @@ import ../waku_conf logScope: topics = "waku conf builder discv5" -const DefaultDiscv5UdpPort*: Port = Port(9000) +const + DefaultDiscv5Enabled*: bool = false + DefaultDiscv5BitsPerHop: int = 1 + DefaultDiscv5BucketIpLimit: uint = 2 + DefaultDiscv5EnrAutoUpdate: bool = true + DefaultDiscv5TableIpLimit: uint = 10 + DefaultDiscv5UdpPort: Port = Port(9000) ########################### ## Discv5 Config Builder ## @@ -48,17 +54,17 @@ proc withBootstrapNodes*(b: var Discv5ConfBuilder, bootstrapNodes: seq[string]) b.bootstrapNodes = concat(b.bootstrapNodes, bootstrapNodes) proc build*(b: Discv5ConfBuilder): Result[Option[Discv5Conf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultDiscv5Enabled): return ok(none(Discv5Conf)) return ok( some( Discv5Conf( bootstrapNodes: b.bootstrapNodes, - bitsPerHop: b.bitsPerHop.get(1), - bucketIpLimit: b.bucketIpLimit.get(2), - enrAutoUpdate: b.enrAutoUpdate.get(true), - tableIpLimit: b.tableIpLimit.get(10), + bitsPerHop: b.bitsPerHop.get(DefaultDiscv5BitsPerHop), + bucketIpLimit: b.bucketIpLimit.get(DefaultDiscv5BucketIpLimit), + enrAutoUpdate: b.enrAutoUpdate.get(DefaultDiscv5EnrAutoUpdate), + tableIpLimit: b.tableIpLimit.get(DefaultDiscv5TableIpLimit), udpPort: b.udpPort.get(DefaultDiscv5UdpPort), ) ) diff --git a/logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim index 0a6617430..dafd6b5ab 100644 --- a/logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/filter_service_conf_builder.nim @@ -4,6 +4,12 @@ import ../waku_conf logScope: topics = "waku conf builder filter service" +const + DefaultFilterEnabled: bool = false + DefaultFilterMaxPeersToServe: uint32 = 500 + DefaultFilterSubscriptionTimeout: uint16 = 300 + DefaultFilterMaxCriteria: uint32 = 1000 + ################################### ## Filter Service Config Builder ## ################################### @@ -37,15 +43,15 @@ proc withMaxCriteria*(b: var FilterServiceConfBuilder, maxCriteria: uint32) = b.maxCriteria = some(maxCriteria) proc build*(b: FilterServiceConfBuilder): Result[Option[FilterServiceConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultFilterEnabled): return ok(none(FilterServiceConf)) return ok( some( FilterServiceConf( - maxPeersToServe: b.maxPeersToServe.get(500), - subscriptionTimeout: b.subscriptionTimeout.get(300), - maxCriteria: b.maxCriteria.get(1000), + maxPeersToServe: b.maxPeersToServe.get(DefaultFilterMaxPeersToServe), + subscriptionTimeout: b.subscriptionTimeout.get(DefaultFilterSubscriptionTimeout), + maxCriteria: b.maxCriteria.get(DefaultFilterMaxCriteria), ) ) ) diff --git a/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim index 576b6b7d9..62fe42e27 100644 --- a/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/kademlia_discovery_conf_builder.nim @@ -5,18 +5,20 @@ import logos_delivery/waku/factory/waku_conf logScope: topics = "waku conf builder kademlia discovery" +const DefaultKadEnabled*: bool = false + ####################################### ## Kademlia Discovery Config Builder ## ####################################### type KademliaDiscoveryConfBuilder* = object - enabled*: bool + enabled*: Option[bool] bootstrapNodes*: seq[string] proc init*(T: type KademliaDiscoveryConfBuilder): KademliaDiscoveryConfBuilder = KademliaDiscoveryConfBuilder() proc withEnabled*(b: var KademliaDiscoveryConfBuilder, enabled: bool) = - b.enabled = enabled + b.enabled = some(enabled) proc withBootstrapNodes*( b: var KademliaDiscoveryConfBuilder, bootstrapNodes: seq[string] @@ -26,11 +28,12 @@ proc withBootstrapNodes*( proc build*( b: KademliaDiscoveryConfBuilder ): Result[Option[KademliaDiscoveryConf], string] = - # Kademlia is enabled if explicitly enabled OR if bootstrap nodes are provided - let enabled = b.enabled or b.bootstrapNodes.len > 0 - if not enabled: + # Explicit disable wins: enabled=false disables regardless of bootstrap nodes. + if b.enabled == some(false): + return ok(none(KademliaDiscoveryConf)) + # Otherwise enabled if config-enabled or any bootstrap nodes are provided. + if not b.enabled.get(DefaultKadEnabled) and b.bootstrapNodes.len == 0: return ok(none(KademliaDiscoveryConf)) - var parsedNodes: seq[(PeerId, seq[MultiAddress])] for nodeStr in b.bootstrapNodes: let (peerId, ma) = parseFullAddress(nodeStr).valueOr: diff --git a/logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim index 8b2ea4eb8..ec3245f97 100644 --- a/logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/metrics_server_conf_builder.nim @@ -4,7 +4,11 @@ import ../waku_conf logScope: topics = "waku conf builder metrics server" -const DefaultMetricsHttpPort*: Port = Port(8008) +const + DefaultMetricsEnabled: bool = false + DefaultMetricsHttpAddress: IpAddress = static parseIpAddress("127.0.0.1") + DefaultMetricsHttpPort: Port = Port(8008) + DefaultMetricsLogging: bool = false ################################### ## Metrics Server Config Builder ## @@ -35,15 +39,15 @@ proc withLogging*(b: var MetricsServerConfBuilder, logging: bool) = b.logging = some(logging) proc build*(b: MetricsServerConfBuilder): Result[Option[MetricsServerConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultMetricsEnabled): return ok(none(MetricsServerConf)) return ok( some( MetricsServerConf( - httpAddress: b.httpAddress.get(static parseIpAddress("127.0.0.1")), + httpAddress: b.httpAddress.get(DefaultMetricsHttpAddress), httpPort: b.httpPort.get(DefaultMetricsHttpPort), - logging: b.logging.get(false), + logging: b.logging.get(DefaultMetricsLogging), ) ) ) diff --git a/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim index 971e63588..68aca5f68 100644 --- a/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/mix_conf_builder.nim @@ -5,6 +5,8 @@ import ../waku_conf, logos_delivery/waku/waku_mix logScope: topics = "waku conf builder mix" +const DefaultMixEnabled: bool = false + ################################## ## Mix Config Builder ## ################################## @@ -26,7 +28,7 @@ proc withMixNodes*(b: var MixConfBuilder, mixNodes: seq[MixNodePubInfo]) = b.mixNodes = mixNodes proc build*(b: MixConfBuilder): Result[Option[MixConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultMixEnabled): return ok(none[MixConf]()) else: if b.mixKey.isSome(): diff --git a/logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim index dcafbb56a..1bf7d17ff 100644 --- a/logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/rest_server_conf_builder.nim @@ -4,7 +4,10 @@ import ../waku_conf logScope: topics = "waku conf builder rest server" -const DefaultRestPort*: Port = Port(8645) +const + DefaultRestEnabled: bool = false + DefaultRestPort: Port = Port(8645) + DefaultRestAdmin: bool = false ################################ ## REST Server Config Builder ## @@ -43,7 +46,7 @@ proc withRelayCacheCapacity*(b: var RestServerConfBuilder, relayCacheCapacity: u b.relayCacheCapacity = some(relayCacheCapacity) proc build*(b: RestServerConfBuilder): Result[Option[RestServerConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultRestEnabled): return ok(none(RestServerConf)) if b.listenAddress.isNone(): @@ -57,7 +60,7 @@ proc build*(b: RestServerConfBuilder): Result[Option[RestServerConf], string] = allowOrigin: b.allowOrigin, listenAddress: b.listenAddress.get(), port: b.port.get(DefaultRestPort), - admin: b.admin.get(false), + admin: b.admin.get(DefaultRestAdmin), relayCacheCapacity: b.relayCacheCapacity.get(), ) ) diff --git a/logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim index 4cdcf8324..f4e70767e 100644 --- a/logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/rln_relay_conf_builder.nim @@ -4,6 +4,11 @@ import ../waku_conf logScope: topics = "waku conf builder rln relay" +const + DefaultRlnRelayEnabled*: bool = false + DefaultRlnRelayEpochSizeSec*: uint64 = 1 + DefaultRlnRelayUserMessageLimit*: uint64 = 1 + ############################## ## RLN Relay Config Builder ## ############################## @@ -56,7 +61,7 @@ proc withUserMessageLimit*(b: var RlnRelayConfBuilder, userMessageLimit: uint64) b.userMessageLimit = some(userMessageLimit) proc build*(b: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultRlnRelayEnabled): return ok(none(RlnRelayConf)) if b.chainId.isNone(): @@ -78,11 +83,6 @@ proc build*(b: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] = return err("rlnRelay.ethClientUrls is not specified") if b.ethContractAddress.get("") == "": return err("rlnRelay.ethContractAddress is not specified") - if b.epochSizeSec.isNone(): - return err("rlnRelay.epochSizeSec is not specified") - if b.userMessageLimit.isNone(): - return err("rlnRelay.userMessageLimit is not specified") - return ok( some( RlnRelayConf( @@ -92,8 +92,8 @@ proc build*(b: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] = dynamic: b.dynamic.get(), ethClientUrls: b.ethClientUrls.get(), ethContractAddress: b.ethContractAddress.get(), - epochSizeSec: b.epochSizeSec.get(), - userMessageLimit: b.userMessageLimit.get(), + epochSizeSec: b.epochSizeSec.get(DefaultRlnRelayEpochSizeSec), + userMessageLimit: b.userMessageLimit.get(DefaultRlnRelayUserMessageLimit), ) ) ) diff --git a/logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim index f1b0b1402..1df3da61f 100644 --- a/logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/store_service_conf_builder.nim @@ -5,6 +5,14 @@ import ../waku_conf, ./store_sync_conf_builder logScope: topics = "waku conf builder store service" +const + DefaultStoreEnabled: bool = false + DefaultStoreDbMigration: bool = true + DefaultStoreDbVacuum: bool = false + DefaultStoreMaxNumDbConnections: int = 50 + DefaultStoreResume: bool = false + DefaultStoreRetentionPolicy: string = "time:" & $2.days.seconds + ################################## ## Store Service Config Builder ## ################################## @@ -77,7 +85,7 @@ proc validateRetentionPolicies(policies: seq[string]): Result[void, string] = return ok() proc build*(b: StoreServiceConfBuilder): Result[Option[StoreServiceConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultStoreEnabled): return ok(none(StoreServiceConf)) if b.dbUrl.get("") == "": @@ -88,7 +96,7 @@ proc build*(b: StoreServiceConfBuilder): Result[Option[StoreServiceConf], string let retentionPolicies = if b.retentionPolicies.len == 0: - @["time:" & $2.days.seconds] + @[DefaultStoreRetentionPolicy] else: validateRetentionPolicies(b.retentionPolicies).isOkOr: return err("invalid retention policies: " & error) @@ -97,12 +105,12 @@ proc build*(b: StoreServiceConfBuilder): Result[Option[StoreServiceConf], string return ok( some( StoreServiceConf( - dbMigration: b.dbMigration.get(true), + dbMigration: b.dbMigration.get(DefaultStoreDbMigration), dbURl: b.dbUrl.get(), - dbVacuum: b.dbVacuum.get(false), - maxNumDbConnections: b.maxNumDbConnections.get(50), + dbVacuum: b.dbVacuum.get(DefaultStoreDbVacuum), + maxNumDbConnections: b.maxNumDbConnections.get(DefaultStoreMaxNumDbConnections), retentionPolicies: retentionPolicies, - resume: b.resume.get(false), + resume: b.resume.get(DefaultStoreResume), storeSyncConf: storeSyncConf, ) ) diff --git a/logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim index 4c7177b71..74cbcece0 100644 --- a/logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/store_sync_conf_builder.nim @@ -4,6 +4,8 @@ import ../waku_conf logScope: topics = "waku conf builder store sync" +const DefaultStoreSyncEnabled: bool = false + ################################## ## Store Sync Config Builder ## ################################## @@ -30,7 +32,7 @@ proc withRelayJitterSec*(b: var StoreSyncConfBuilder, relayJitterSec: uint32) = b.relayJitterSec = some(relayJitterSec) proc build*(b: StoreSyncConfBuilder): Result[Option[StoreSyncConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultStoreSyncEnabled): return ok(none(StoreSyncConf)) if b.rangeSec.isNone(): diff --git a/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim index 7d7189fac..d034e0bd0 100644 --- a/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/waku_conf_builder.nim @@ -13,6 +13,9 @@ import factory/networks_config, common/logging, common/utils/parse_size_units, + node/peer_manager, + waku_core/message/default_values, + waku_core/topics/pubsub_topic, waku_enr/capabilities, persistency/persistency, ], @@ -35,9 +38,38 @@ import logScope: topics = "waku conf builder" +# Picks up the same -d:git_version=... build flag that cli_args.nim defines. +const git_version {.strdefine.} = "(unknown)" + const - DefaultMaxConnections* = 150 - DefaultP2pTcpPort*: Port = Port(60000) + DefaultMaxConnections = 150 + DefaultRelay: bool = false + # historical confbuilder default; wakunode2 CLI deviates (true) + DefaultLightPush: bool = false + DefaultPeerExchange: bool = false + # historical confbuilder default; wakunode2 CLI deviates (true) + DefaultStoreSyncMount: bool = false + DefaultRendezvous: bool = false + # historical confbuilder default; wakunode2 CLI deviates (true) + DefaultMix*: bool = false + DefaultRelayPeerExchange: bool = false + DefaultLogLevel: logging.LogLevel = logging.LogLevel.INFO + DefaultLogFormat: logging.LogFormat = logging.LogFormat.TEXT + DefaultNatStrategy: string = "none" + DefaultP2pTcpPort: Port = Port(60000) + DefaultP2pListenAddress: IpAddress = static parseIpAddress("0.0.0.0") + DefaultPortsShift: uint16 = 0 + DefaultExtMultiAddrsOnly: bool = false + DefaultDnsAddrsNameServers: seq[IpAddress] = + @[static parseIpAddress("1.1.1.1"), static parseIpAddress("1.0.0.1")] + DefaultPeerPersistence: bool = false + DefaultAgentString*: string = "logos-delivery-" & git_version + DefaultRelayShardedPeerManagement: bool = false + DefaultRelayServiceRatio: string = "50:50" + DefaultCircuitRelayClient: bool = false + DefaultP2pReliability*: bool = true + DefaultNumShardsInCluster: uint16 = 1 + DefaultShardingConfKind: ShardingConfKind = AutoSharding type MaxMessageSizeKind* = enum mmskNone @@ -99,7 +131,7 @@ type WakuConfBuilder* = object # TODO: move within a relayConf rendezvous: Option[bool] - networkConf: Option[NetworkConf] + networkPresetConf: Option[NetworkPresetConf] staticNodes: seq[string] @@ -153,8 +185,10 @@ proc init*(T: type WakuConfBuilder): WakuConfBuilder = kademliaDiscoveryConf: KademliaDiscoveryConfBuilder.init(), ) -proc withNetworkConf*(b: var WakuConfBuilder, networkConf: NetworkConf) = - b.networkConf = some(networkConf) +proc withNetworkPresetConf*( + b: var WakuConfBuilder, networkPresetConf: NetworkPresetConf +) = + b.networkPresetConf = some(networkPresetConf) proc withNodeKey*(b: var WakuConfBuilder, nodeKey: crypto.PrivateKey) = b.nodeKey = some(nodeKey) @@ -309,121 +343,129 @@ proc buildShardingConf( bNumShardsInCluster: Option[uint16], bSubscribeShards: Option[seq[uint16]], ): (ShardingConf, seq[uint16]) = - case bShardingConfKind.get(AutoSharding) + case bShardingConfKind.get(DefaultShardingConfKind) of StaticSharding: (ShardingConf(kind: StaticSharding), bSubscribeShards.get(@[])) of AutoSharding: - let numShardsInCluster = bNumShardsInCluster.get(1) + let numShardsInCluster = bNumShardsInCluster.get(DefaultNumShardsInCluster) let shardingConf = ShardingConf(kind: AutoSharding, numShardsInCluster: numShardsInCluster) let upperShard = uint16(numShardsInCluster - 1) (shardingConf, bSubscribeShards.get(toSeq(0.uint16 .. upperShard))) -proc applyNetworkConf(builder: var WakuConfBuilder) = - # Apply network conf, overrides most values passed individually - # If you want to tweak values, don't use networkConf - # TODO: networkconf should be one field of the conf builder so that this function becomes unnecessary - if builder.networkConf.isNone(): - return - let networkConf = builder.networkConf.get() +template checkSetPresetValueToField[T]( + field: var Option[T], presetVal: T, msg: static string +) = + ## Set the field to the preset's value, unless the field is already set + ## (explicit wins). Warn iff the field's existing value differs from the + ## preset's. No-op if they agree. - if builder.clusterId.isSome(): - warn "Cluster id was provided alongside a network conf", - used = networkConf.clusterId, discarded = builder.clusterId.get() - builder.clusterId = some(networkConf.clusterId) + if field.isSome(): + if field.get() != presetVal: + warn msg, used = field.get(), discarded = presetVal + else: + field = some(presetVal) + +proc checkAddPresetValueToField[T](field: var seq[T], presetVals: seq[T]) = + ## Append the preset's list values to the field's existing list. Lists + ## concat rather than override; both the user's and the preset's entries + ## end up in the final list. + + field = field & presetVals + +proc applyNetworkPresetConf(builder: var WakuConfBuilder) = + ## NetworkPresetConf = network presets. + ## Cascade the chosen preset's values onto builder fields the user hasn't set. + ## User-set fields stay; preset fills the gaps and warns on conflict (explicit wins). + ## List fields concat (preset's nodes appended to user's). + + if builder.networkPresetConf.isNone(): + return # If there is no preset given, then nothing to do. + + let networkPresetConf = builder.networkPresetConf.get() + + checkSetPresetValueToField( + builder.clusterId, networkPresetConf.clusterId, + "Cluster id was provided alongside a network conf", + ) # Apply relay parameters - if builder.relay.get(false) and networkConf.rlnRelay: - if builder.rlnRelayConf.enabled.isSome(): - warn "RLN Relay was provided alongside a network conf", - used = networkConf.rlnRelay, discarded = builder.rlnRelayConf.enabled - builder.rlnRelayConf.withEnabled(true) - - if builder.rlnRelayConf.ethContractAddress.get("") != "": - warn "RLN Relay ETH Contract Address was provided alongside a network conf", - used = networkConf.rlnRelayEthContractAddress.string, - discarded = builder.rlnRelayConf.ethContractAddress.get().string - builder.rlnRelayConf.withEthContractAddress(networkConf.rlnRelayEthContractAddress) - - if builder.rlnRelayConf.chainId.isSome(): - warn "RLN Relay Chain Id was provided alongside a network conf", - used = networkConf.rlnRelayChainId, discarded = builder.rlnRelayConf.chainId - builder.rlnRelayConf.withChainId(networkConf.rlnRelayChainId) - - if builder.rlnRelayConf.dynamic.isSome(): - warn "RLN Relay Dynamic was provided alongside a network conf", - used = networkConf.rlnRelayDynamic, discarded = builder.rlnRelayConf.dynamic - builder.rlnRelayConf.withDynamic(networkConf.rlnRelayDynamic) - - if builder.rlnRelayConf.epochSizeSec.isSome(): - warn "RLN Epoch Size in Seconds was provided alongside a network conf", - used = networkConf.rlnEpochSizeSec, - discarded = builder.rlnRelayConf.epochSizeSec - builder.rlnRelayConf.withEpochSizeSec(networkConf.rlnEpochSizeSec) - - if builder.rlnRelayConf.userMessageLimit.isSome(): - warn "RLN Relay User Message Limit was provided alongside a network conf", - used = networkConf.rlnRelayUserMessageLimit, - discarded = builder.rlnRelayConf.userMessageLimit - if builder.rlnRelayConf.userMessageLimit.get(0) == 0: - ## only override with the "preset" value if there was not explicit set value - builder.rlnRelayConf.withUserMessageLimit(networkConf.rlnRelayUserMessageLimit) - + if builder.relay.get(DefaultRelay) and networkPresetConf.rlnRelay: + checkSetPresetValueToField( + builder.rlnRelayConf.enabled, + networkPresetConf.rlnRelay, # true + "RLN Relay was provided alongside a network conf", + ) + checkSetPresetValueToField( + builder.rlnRelayConf.ethContractAddress, + networkPresetConf.rlnRelayEthContractAddress, + "RLN Relay ETH Contract Address was provided alongside a network conf", + ) + checkSetPresetValueToField( + builder.rlnRelayConf.chainId, networkPresetConf.rlnRelayChainId, + "RLN Relay Chain Id was provided alongside a network conf", + ) + checkSetPresetValueToField( + builder.rlnRelayConf.dynamic, networkPresetConf.rlnRelayDynamic, + "RLN Relay Dynamic was provided alongside a network conf", + ) + checkSetPresetValueToField( + builder.rlnRelayConf.epochSizeSec, networkPresetConf.rlnEpochSizeSec, + "RLN Epoch Size in Seconds was provided alongside a network conf", + ) + checkSetPresetValueToField( + builder.rlnRelayConf.userMessageLimit, networkPresetConf.rlnRelayUserMessageLimit, + "RLN Relay User Message Limit was provided alongside a network conf", + ) # End Apply relay parameters case builder.maxMessageSize.kind of mmskNone: - discard + builder.withMaxMessageSize(parseCorrectMsgSize(networkPresetConf.maxMessageSize)) of mmskStr, mmskInt: warn "Max Message Size was provided alongside a network conf", - used = networkConf.maxMessageSize, discarded = $builder.maxMessageSize - builder.withMaxMessageSize(parseCorrectMsgSize(networkConf.maxMessageSize)) + used = $builder.maxMessageSize, discarded = networkPresetConf.maxMessageSize - if builder.shardingConf.isSome(): - warn "Sharding Conf was provided alongside a network conf", - used = networkConf.shardingConf.kind, discarded = builder.shardingConf - - case networkConf.shardingConf.kind - of StaticSharding: - builder.shardingConf = some(StaticSharding) + checkSetPresetValueToField( + builder.shardingConf, networkPresetConf.shardingConf.kind, + "Sharding Conf was provided alongside a network conf", + ) + case networkPresetConf.shardingConf.kind of AutoSharding: - builder.shardingConf = some(AutoSharding) - if builder.numShardsInCluster.isSome(): - warn "Num Shards In Cluster overrides network conf preset", - used = builder.numShardsInCluster.get(), - ignored = networkConf.shardingConf.numShardsInCluster - else: - builder.numShardsInCluster = some(networkConf.shardingConf.numShardsInCluster) + checkSetPresetValueToField( + builder.numShardsInCluster, networkPresetConf.shardingConf.numShardsInCluster, + "Num Shards In Cluster overrides network conf preset", + ) + of StaticSharding: + discard - if networkConf.discv5Discovery: - if builder.discv5Conf.enabled.isNone: - builder.discv5Conf.withEnabled(networkConf.discv5Discovery) + checkSetPresetValueToField( + builder.discv5Conf.enabled, networkPresetConf.discv5Discovery, + "Discv5 Discovery was provided alongside a network conf", + ) + checkAddPresetValueToField( + builder.discv5Conf.bootstrapNodes, networkPresetConf.discv5BootstrapNodes + ) - if builder.discv5Conf.bootstrapNodes.len == 0 and - networkConf.discv5BootstrapNodes.len > 0: - warn "Discv5 Bootstrap nodes were provided alongside a network conf", - used = networkConf.discv5BootstrapNodes, - discarded = builder.discv5Conf.bootstrapNodes - builder.discv5Conf.withBootstrapNodes(networkConf.discv5BootstrapNodes) + checkSetPresetValueToField( + builder.kademliaDiscoveryConf.enabled, networkPresetConf.enableKadDiscovery, + "Kademlia Discovery was provided alongside a network conf", + ) + checkAddPresetValueToField( + builder.kademliaDiscoveryConf.bootstrapNodes, networkPresetConf.kadBootstrapNodes + ) - if networkConf.enableKadDiscovery: - if not builder.kademliaDiscoveryConf.enabled: - builder.kademliaDiscoveryConf.withEnabled(networkConf.enableKadDiscovery) - - if builder.kademliaDiscoveryConf.bootstrapNodes.len == 0 and - networkConf.kadBootstrapNodes.len > 0: - builder.kademliaDiscoveryConf.withBootstrapNodes(networkConf.kadBootstrapNodes) - - if networkConf.mix: - if builder.mix.isNone: - builder.mix = some(networkConf.mix) - - if builder.p2pReliability.isNone: - builder.withP2pReliability(networkConf.p2pReliability) + checkSetPresetValueToField( + builder.mix, networkPresetConf.mix, "Mix was provided alongside a network conf" + ) + checkSetPresetValueToField( + builder.p2pReliability, networkPresetConf.p2pReliability, + "P2P Reliability was provided alongside a network conf", + ) # Process entry nodes from network config - classify and distribute - if networkConf.entryNodes.len > 0: - let processed = processEntryNodes(networkConf.entryNodes) + if networkPresetConf.entryNodes.len > 0: + let processed = processEntryNodes(networkPresetConf.entryNodes) if processed.isOk(): let (enrTreeUrls, bootstrapEnrs, staticNodesFromEntry) = processed.get() @@ -442,6 +484,47 @@ proc applyNetworkConf(builder: var WakuConfBuilder) = else: warn "Failed to process entry nodes from network conf", error = processed.error() +proc rejectOverride[T]( + field: Option[T], presetValue: T, msg: string +): Result[void, string] = + ## Errors with `msg` if `field` is set to anything other than the preset's value. + if field.isSome() and field.get() != presetValue: + return err(msg) + ok() + +proc enforceSecurityConstraints(builder: WakuConfBuilder): Result[void, string] = + ## Errors if the resolved config violates a security constraint. + + if builder.networkPresetConf.isSome(): + let preset = builder.networkPresetConf.get() + let relayEnabled = builder.relay.get(DefaultRelay) + let rlnRelayConf = builder.rlnRelayConf + let rlnRelayEnabled = rlnRelayConf.enabled.get(DefaultRlnRelayEnabled) + + if relayEnabled and preset.rlnRelay: + if not rlnRelayEnabled: + return + err("network preset mandates RLN relay: cannot relay with rln-relay disabled") + + ?rejectOverride( + rlnRelayConf.ethContractAddress, preset.rlnRelayEthContractAddress, + "network preset mandates its RLN contract: cannot relay with a different rln-relay-eth-contract-address", + ) + ?rejectOverride( + rlnRelayConf.chainId, preset.rlnRelayChainId, + "network preset mandates its RLN chain id: cannot relay with a different rln-relay-chain-id", + ) + ?rejectOverride( + rlnRelayConf.dynamic, preset.rlnRelayDynamic, + "network preset mandates its RLN membership mode: cannot relay with a different rln-relay-dynamic", + ) + ?rejectOverride( + rlnRelayConf.epochSizeSec, preset.rlnEpochSizeSec, + "network preset mandates its RLN epoch size: cannot relay with a different rln-relay-epoch-sec", + ) + + ok() + proc build*( builder: var WakuConfBuilder, rng: ref HmacDrbgContext = crypto.newRng() ): Result[WakuConf, string] = @@ -450,51 +533,59 @@ proc build*( ## of libwaku. It aims to be agnostic so it does not apply a ## default when it is opinionated. - applyNetworkConf(builder) + applyNetworkPresetConf(builder) + + # We should not ignore any user-supplied config parameter: the user is + # allowed to override any preset parameter with any explicit config + # parameter. However, we do gate config building with an error if any + # one of these preset overrides is considered a security concern. + # This eliminates ambiguous behavior such as warning of an override and + # then ignoring it: either fail-fast or accept the override. + ?enforceSecurityConstraints(builder) let relay = if builder.relay.isSome(): builder.relay.get() else: warn "whether to mount relay is not specified, defaulting to not mounting" - false + DefaultRelay let lightPush = if builder.lightPush.isSome(): builder.lightPush.get() else: warn "whether to mount lightPush is not specified, defaulting to not mounting" - false + DefaultLightPush let peerExchange = if builder.peerExchange.isSome(): builder.peerExchange.get() else: warn "whether to mount peerExchange is not specified, defaulting to not mounting" - false + DefaultPeerExchange let storeSync = if builder.storeSync.isSome(): builder.storeSync.get() else: warn "whether to mount storeSync is not specified, defaulting to not mounting" - false + DefaultStoreSyncMount let rendezvous = if builder.rendezvous.isSome(): builder.rendezvous.get() else: warn "whether to mount rendezvous is not specified, defaulting to not mounting" - false + DefaultRendezvous let mix = if builder.mix.isSome(): builder.mix.get() else: warn "whether to mount mix is not specified, defaulting to not mounting" - false + DefaultMix - let relayPeerExchange = builder.relayPeerExchange.get(false) + let relayPeerExchange = builder.relayPeerExchange.get(DefaultRelayPeerExchange) let nodeKey = ?nodeKey(builder, rng) @@ -503,7 +594,7 @@ proc build*( # TODO: ClusterId should never be defaulted, instead, presets # should be defined and used warn("Cluster Id was not specified, defaulting to 0") - 0.uint16 + DefaultClusterId else: builder.clusterId.get().uint16 @@ -522,8 +613,9 @@ proc build*( of mmskStr: ?parseMsgSize(builder.maxMessageSize.str) else: - warn "Max Message Size not specified, defaulting to 150KiB" - parseCorrectMsgSize("150KiB") + warn "Max Message Size not specified, defaulting to DefaultMaxWakuMessageSize", + default = DefaultMaxWakuMessageSizeStr + DefaultMaxWakuMessageSize let contentTopics = builder.contentTopics.get(@[]) @@ -568,21 +660,21 @@ proc build*( builder.logLevel.get() else: warn "Log Level not specified, defaulting to INFO" - logging.LogLevel.INFO + DefaultLogLevel let logFormat = if builder.logFormat.isSome(): builder.logFormat.get() else: warn "Log Format not specified, defaulting to TEXT" - logging.LogFormat.TEXT + DefaultLogFormat let natStrategy = if builder.natStrategy.isSome(): builder.natStrategy.get() else: warn "Nat Strategy is not specified, defaulting to none" - "none" + DefaultNatStrategy let p2pTcpPort = builder.p2pTcpPort.get(DefaultP2pTcpPort) @@ -591,14 +683,14 @@ proc build*( builder.p2pListenAddress.get() else: warn "P2P listening address not specified, listening on 0.0.0.0" - (static parseIpAddress("0.0.0.0")) + DefaultP2pListenAddress let portsShift = if builder.portsShift.isSome(): builder.portsShift.get() else: warn "Ports Shift is not specified, defaulting to 0" - 0.uint16 + DefaultPortsShift let dns4DomainName = if builder.dns4DomainName.isSome(): @@ -621,21 +713,21 @@ proc build*( builder.extMultiAddrsOnly.get() else: warn "Whether to only announce external multiaddresses is not specified, defaulting to false" - false + DefaultExtMultiAddrsOnly let dnsAddrsNameServers = if builder.dnsAddrsNameServers.len != 0: builder.dnsAddrsNameServers else: warn "DNS name servers IPs not provided, defaulting to Cloudflare's." - @[static parseIpAddress("1.1.1.1"), static parseIpAddress("1.0.0.1")] + DefaultDnsAddrsNameServers let peerPersistence = if builder.peerPersistence.isSome(): builder.peerPersistence.get() else: warn "Peer persistence not specified, defaulting to false" - false + DefaultPeerPersistence let maxConnections = if builder.maxConnections.isSome(): @@ -649,15 +741,13 @@ proc build*( warn "max-connections less than DefaultMaxConnections; we suggest using DefaultMaxConnections or more for better connectivity", provided = maxConnections, recommended = DefaultMaxConnections - # TODO: Do the git version thing here - let agentString = builder.agentString.get("logos-delivery") + let agentString = builder.agentString.get(DefaultAgentString) - # TODO: use `DefaultColocationLimit`. the user of this value should - # probably be defining a config object - let colocationLimit = builder.colocationLimit.get(5) + let colocationLimit = builder.colocationLimit.get(DefaultColocationLimit) # TODO: is there a strategy for experimental features? delete vs promote - let relayShardedPeerManagement = builder.relayShardedPeerManagement.get(false) + let relayShardedPeerManagement = + builder.relayShardedPeerManagement.get(DefaultRelayShardedPeerManagement) let wakuFlags = CapabilitiesBitfield.init( lightpush = lightPush and relay, @@ -718,12 +808,12 @@ proc build*( agentString: agentString, colocationLimit: colocationLimit, maxRelayPeers: builder.maxRelayPeers, - relayServiceRatio: builder.relayServiceRatio.get("50:50"), + relayServiceRatio: builder.relayServiceRatio.get(DefaultRelayServiceRatio), rateLimit: rateLimit, - circuitRelayClient: builder.circuitRelayClient.get(false), + circuitRelayClient: builder.circuitRelayClient.get(DefaultCircuitRelayClient), staticNodes: builder.staticNodes, relayShardedPeerManagement: relayShardedPeerManagement, - p2pReliability: builder.p2pReliability.get(false), + p2pReliability: builder.p2pReliability.get(DefaultP2pReliability), wakuFlags: wakuFlags, localStoragePath: builder.localStoragePath.get(DefaultStoragePath), ) diff --git a/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim b/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim index 285e678e8..d71ffbc1f 100644 --- a/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim +++ b/logos_delivery/waku/factory/conf_builder/web_socket_conf_builder.nim @@ -4,7 +4,10 @@ import logos_delivery/waku/factory/waku_conf logScope: topics = "waku conf builder websocket" -const DefaultWebSocketPort*: Port = Port(8000) +const + DefaultWebSocketEnabled: bool = false + DefaultWebSocketSecureEnabled: bool = false + DefaultWebSocketPort: Port = Port(8000) ############################## ## WebSocket Config Builder ## @@ -40,10 +43,10 @@ proc withCertPath*(b: var WebSocketConfBuilder, certPath: string) = b.certPath = some(certPath) proc build*(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] = - if not b.enabled.get(false): + if not b.enabled.get(DefaultWebSocketEnabled): return ok(none(WebSocketConf)) - if not b.secureEnabled.get(false): + if not b.secureEnabled.get(DefaultWebSocketSecureEnabled): return ok( some( WebSocketConf( diff --git a/logos_delivery/waku/factory/networks_config.nim b/logos_delivery/waku/factory/networks_config.nim index 488f58464..3d1e296fe 100644 --- a/logos_delivery/waku/factory/networks_config.nim +++ b/logos_delivery/waku/factory/networks_config.nim @@ -1,6 +1,7 @@ {.push raises: [].} import chronicles, results, stint +import logos_delivery/waku/waku_core/message/default_values logScope: topics = "waku networks conf" @@ -17,7 +18,8 @@ type of StaticSharding: discard -type NetworkConf* = object +type NetworkPresetConf* = object + ## A network "preset" (--preset=twn, --preset=logos.dev). maxMessageSize*: string # TODO: static convert to a uint64 clusterId*: uint16 rlnRelay*: bool @@ -38,10 +40,10 @@ type NetworkConf* = object # cluster-id=1 (aka The Waku Network) # Cluster configuration corresponding to The Waku Network. Note that it # overrides existing cli configuration -proc TheWakuNetworkConf*(T: type NetworkConf): NetworkConf = +proc TheWakuNetworkConf*(T: type NetworkPresetConf): NetworkPresetConf = const RelayChainId = 59141'u256 - return NetworkConf( - maxMessageSize: "150KiB", + return NetworkPresetConf( + maxMessageSize: DefaultMaxWakuMessageSizeStr, clusterId: 1, rlnRelay: true, rlnRelayEthContractAddress: "0xB9cd878C90E49F797B4431fBF4fb333108CB90e6", @@ -65,10 +67,10 @@ proc TheWakuNetworkConf*(T: type NetworkConf): NetworkConf = # cluster-id=2 (Logos Dev Network) # Cluster configuration for the Logos Dev Network. -proc LogosDevConf*(T: type NetworkConf): NetworkConf = +proc LogosDevConf*(T: type NetworkPresetConf): NetworkPresetConf = const ZeroChainId = 0'u256 - return NetworkConf( - maxMessageSize: "150KiB", + return NetworkPresetConf( + maxMessageSize: DefaultMaxWakuMessageSizeStr, clusterId: 2, rlnRelay: false, rlnRelayEthContractAddress: "", @@ -94,9 +96,9 @@ proc LogosDevConf*(T: type NetworkConf): NetworkConf = # cluster-id=2 (Logos Test Network) # Cluster configuration for the Logos Test Network. -proc LogosTestConf*(T: type NetworkConf): NetworkConf = +proc LogosTestConf*(T: type NetworkPresetConf): NetworkPresetConf = const ZeroChainId = 0'u256 - return NetworkConf( + return NetworkPresetConf( maxMessageSize: "150KiB", clusterId: 2, rlnRelay: false, diff --git a/tests/api/test_api_health.nim b/tests/api/test_api_health.nim index e38439cbd..d8a7eabf2 100644 --- a/tests/api/test_api_health.nim +++ b/tests/api/test_api_health.nim @@ -98,7 +98,7 @@ suite "LM API health checking": conf.listenAddress = parseIpAddress("0.0.0.0") conf.tcpPort = Port(0) conf.discv5UdpPort = Port(0) - conf.clusterId = 3'u16 + conf.clusterId = some(3'u16) conf.numShardsInNetwork = 1 conf.rest = false @@ -277,7 +277,7 @@ suite "LM API health checking": edgeConf.listenAddress = parseIpAddress("0.0.0.0") edgeConf.tcpPort = Port(0) edgeConf.discv5UdpPort = Port(0) - edgeConf.clusterId = 3'u16 + edgeConf.clusterId = some(3'u16) edgeConf.maxMessageSize = "150 KiB" edgeConf.rest = false diff --git a/tests/api/test_api_receive.nim b/tests/api/test_api_receive.nim index 3280f0609..d7b6e3d7b 100644 --- a/tests/api/test_api_receive.nim +++ b/tests/api/test_api_receive.nim @@ -67,9 +67,9 @@ proc createApiNodeConf(numShards: uint16 = 1): WakuNodeConf = conf.listenAddress = parseIpAddress("0.0.0.0") conf.tcpPort = Port(0) conf.discv5UdpPort = Port(0) - conf.clusterId = 3'u16 + conf.clusterId = some(3'u16) conf.numShardsInNetwork = numShards - conf.reliabilityEnabled = true + conf.reliabilityEnabled = some(true) conf.rest = false result = conf diff --git a/tests/api/test_api_send.nim b/tests/api/test_api_send.nim index 3e9a4b717..e51473b17 100644 --- a/tests/api/test_api_send.nim +++ b/tests/api/test_api_send.nim @@ -126,9 +126,9 @@ proc createApiNodeConf(mode: cli_args.WakuMode = cli_args.WakuMode.Core): WakuNo conf.listenAddress = parseIpAddress("0.0.0.0") conf.tcpPort = Port(0) conf.discv5UdpPort = Port(0) - conf.clusterId = 3'u16 + conf.clusterId = some(3'u16) conf.numShardsInNetwork = 1 - conf.reliabilityEnabled = true + conf.reliabilityEnabled = some(true) conf.rest = false result = conf diff --git a/tests/api/test_api_subscription.nim b/tests/api/test_api_subscription.nim index e20250791..2a6ce36ee 100644 --- a/tests/api/test_api_subscription.nim +++ b/tests/api/test_api_subscription.nim @@ -77,9 +77,9 @@ proc createApiNodeConf( conf.listenAddress = parseIpAddress("0.0.0.0") conf.tcpPort = Port(0) conf.discv5UdpPort = Port(0) - conf.clusterId = 3'u16 + conf.clusterId = some(3'u16) conf.numShardsInNetwork = numShards - conf.reliabilityEnabled = true + conf.reliabilityEnabled = some(true) conf.rest = false result = conf diff --git a/tests/api/test_node_conf.nim b/tests/api/test_node_conf.nim index 2da1362af..ce0e2b28e 100644 --- a/tests/api/test_node_conf.nim +++ b/tests/api/test_node_conf.nim @@ -1,43 +1,23 @@ {.used.} -import std/[options, json, strutils], results, stint, testutils/unittests +import std/[options, strutils], results, stint, testutils/unittests import json_serialization, confutils, confutils/std/net import tools/confutils/cli_args, + tools/confutils/conf_from_json, logos_delivery/waku/api/api_conf, logos_delivery/waku/factory/waku_conf, logos_delivery/waku/factory/networks_config, logos_delivery/waku/factory/conf_builder/conf_builder, logos_delivery/waku/common/logging -# Helper: parse JSON into WakuNodeConf using fieldPairs (same as liblogosdelivery) -proc parseWakuNodeConfFromJson(jsonStr: string): Result[WakuNodeConf, string] = - var conf = defaultWakuNodeConf().valueOr: - return err(error) - var jsonNode: JsonNode - try: - jsonNode = parseJson(jsonStr) - except Exception: - return err("JSON parse error: " & getCurrentExceptionMsg()) - for confField, confValue in fieldPairs(conf): - if jsonNode.contains(confField): - let formattedString = ($jsonNode[confField]).strip(chars = {'\"'}) - try: - confValue = parseCmdArg(typeof(confValue), formattedString) - except Exception: - return err( - "Field '" & confField & "' parse error: " & getCurrentExceptionMsg() & - ". Value: " & formattedString - ) - return ok(conf) - suite "WakuNodeConf - mode-driven toWakuConf": test "Core mode enables service protocols": ## Given var conf = defaultWakuNodeConf().valueOr: raiseAssert error conf.mode = Core - conf.clusterId = 1 + conf.clusterId = some(1'u16) ## When let wakuConfRes = conf.toWakuConf() @@ -58,7 +38,7 @@ suite "WakuNodeConf - mode-driven toWakuConf": var conf = defaultWakuNodeConf().valueOr: raiseAssert error conf.mode = Edge - conf.clusterId = 1 + conf.clusterId = some(1'u16) ## When let wakuConfRes = conf.toWakuConf() @@ -81,7 +61,7 @@ suite "WakuNodeConf - mode-driven toWakuConf": conf.mode = cli_args.WakuMode.noMode conf.relay = true conf.lightpush = false - conf.clusterId = 5 + conf.clusterId = some(5'u16) ## When let wakuConfRes = conf.toWakuConf() @@ -115,30 +95,30 @@ suite "WakuNodeConf - mode-driven toWakuConf": suite "WakuNodeConf - JSON parsing with fieldPairs": test "Empty JSON produces valid default conf": ## Given / When - let confRes = parseWakuNodeConfFromJson("{}") + let confRes = parseNodeConfFromJson("{}") ## Then require confRes.isOk() let conf = confRes.get() check: conf.mode == cli_args.WakuMode.noMode - conf.clusterId == 0 + conf.clusterId.isNone() conf.logLevel == logging.LogLevel.INFO test "JSON with mode and clusterId": ## Given / When - let confRes = parseWakuNodeConfFromJson("""{"mode": "Core", "clusterId": 42}""") + let confRes = parseNodeConfFromJson("""{"mode": "Core", "clusterId": 42}""") ## Then require confRes.isOk() let conf = confRes.get() check: conf.mode == Core - conf.clusterId == 42 + conf.clusterId == some(42'u16) test "JSON with Edge mode": ## Given / When - let confRes = parseWakuNodeConfFromJson("""{"mode": "Edge"}""") + let confRes = parseNodeConfFromJson("""{"mode": "Edge"}""") ## Then require confRes.isOk() @@ -148,7 +128,7 @@ suite "WakuNodeConf - JSON parsing with fieldPairs": test "JSON with logLevel": ## Given / When - let confRes = parseWakuNodeConfFromJson("""{"logLevel": "DEBUG"}""") + let confRes = parseNodeConfFromJson("""{"logLevel": "DEBUG"}""") ## Then require confRes.isOk() @@ -159,29 +139,25 @@ suite "WakuNodeConf - JSON parsing with fieldPairs": test "JSON with sharding config": ## Given / When let confRes = - parseWakuNodeConfFromJson("""{"clusterId": 99, "numShardsInNetwork": 16}""") + parseNodeConfFromJson("""{"clusterId": 99, "numShardsInNetwork": 16}""") ## Then require confRes.isOk() let conf = confRes.get() check: - conf.clusterId == 99 + conf.clusterId == some(99'u16) conf.numShardsInNetwork == 16 - test "JSON with unknown fields is silently ignored": + test "JSON with unknown fields is rejected": ## Given / When - let confRes = - parseWakuNodeConfFromJson("""{"unknownField": true, "clusterId": 5}""") + let confRes = parseNodeConfFromJson("""{"unknownField": true, "clusterId": 5}""") - ## Then - unknown fields are just ignored (not in fieldPairs) - require confRes.isOk() - let conf = confRes.get() - check: - conf.clusterId == 5 + ## Then - the parser rejects unrecognized config keys + check confRes.isErr() test "Invalid JSON syntax returns error": ## Given / When - let confRes = parseWakuNodeConfFromJson("{ not valid json }") + let confRes = parseNodeConfFromJson("{ not valid json }") ## Then check confRes.isErr() @@ -250,7 +226,7 @@ suite "WakuNodeConf - preset integration": suite "WakuNodeConf JSON -> WakuConf integration": test "Core mode JSON config produces valid WakuConf": ## Given - let confRes = parseWakuNodeConfFromJson( + let confRes = parseNodeConfFromJson( """{"mode": "Core", "clusterId": 55, "numShardsInNetwork": 6}""" ) require confRes.isOk() @@ -272,7 +248,7 @@ suite "WakuNodeConf JSON -> WakuConf integration": test "Edge mode JSON config produces valid WakuConf": ## Given - let confRes = parseWakuNodeConfFromJson("""{"mode": "Edge", "clusterId": 1}""") + let confRes = parseNodeConfFromJson("""{"mode": "Edge", "clusterId": 1}""") require confRes.isOk() let conf = confRes.get() @@ -290,8 +266,7 @@ suite "WakuNodeConf JSON -> WakuConf integration": test "JSON with preset produces valid WakuConf": ## Given - let confRes = - parseWakuNodeConfFromJson("""{"mode": "Core", "preset": "logosdev"}""") + let confRes = parseNodeConfFromJson("""{"mode": "Core", "preset": "logosdev"}""") require confRes.isOk() let conf = confRes.get() @@ -308,7 +283,7 @@ suite "WakuNodeConf JSON -> WakuConf integration": test "JSON with static nodes": ## Given - let confRes = parseWakuNodeConfFromJson( + let confRes = parseNodeConfFromJson( """{"mode": "Core", "clusterId": 42, "staticnodes": ["/ip4/127.0.0.1/tcp/60000/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc"]}""" ) require confRes.isOk() @@ -327,7 +302,7 @@ suite "WakuNodeConf JSON -> WakuConf integration": test "JSON with max message size": ## Given let confRes = - parseWakuNodeConfFromJson("""{"clusterId": 42, "maxMessageSize": "100KiB"}""") + parseNodeConfFromJson("""{"clusterId": 42, "maxMessageSize": "100KiB"}""") require confRes.isOk() let conf = confRes.get() diff --git a/tests/channels/test_reliable_channel_send_receive.nim b/tests/channels/test_reliable_channel_send_receive.nim index 16577899e..5a80d104c 100644 --- a/tests/channels/test_reliable_channel_send_receive.nim +++ b/tests/channels/test_reliable_channel_send_receive.nim @@ -1,6 +1,6 @@ {.used.} -import std/[net] +import std/[net, options] import chronos, testutils/unittests, stew/byteutils import brokers/broker_context @@ -24,9 +24,9 @@ proc createApiNodeConf(): WakuNodeConf = conf.listenAddress = parseIpAddress("0.0.0.0") conf.tcpPort = Port(0) conf.discv5UdpPort = Port(0) - conf.clusterId = 3'u16 + conf.clusterId = some(3'u16) conf.numShardsInNetwork = 1 - conf.reliabilityEnabled = true + conf.reliabilityEnabled = some(true) conf.rest = false return conf diff --git a/tests/factory/test_waku_conf.nim b/tests/factory/test_waku_conf.nim index 8a033c008..117f23250 100644 --- a/tests/factory/test_waku_conf.nim +++ b/tests/factory/test_waku_conf.nim @@ -16,7 +16,7 @@ import suite "Waku Conf - build with cluster conf": test "Cluster Conf is passed and relay is enabled": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() builder.discv5Conf.withUdpPort(9000) builder.withRelayServiceRatio("50:50") @@ -26,7 +26,7 @@ suite "Waku Conf - build with cluster conf": ## Given builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withRelay(true) builder.rlnRelayConf.withUserMessageLimit(userMessageLimit) @@ -38,29 +38,29 @@ suite "Waku Conf - build with cluster conf": ## Then let resValidate = conf.validate() assert resValidate.isOk(), $resValidate.error - check conf.clusterId == networkConf.clusterId - check conf.shardingConf.kind == networkConf.shardingConf.kind + check conf.clusterId == networkPresetConf.clusterId + check conf.shardingConf.kind == networkPresetConf.shardingConf.kind check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster + networkPresetConf.shardingConf.numShardsInCluster check conf.subscribeShards == expectedShards check conf.maxMessageSizeBytes == - uint64(parseCorrectMsgSize(networkConf.maxMessageSize)) - check conf.discv5Conf.get().bootstrapNodes == networkConf.discv5BootstrapNodes + uint64(parseCorrectMsgSize(networkPresetConf.maxMessageSize)) + check conf.discv5Conf.get().bootstrapNodes == networkPresetConf.discv5BootstrapNodes - if networkConf.rlnRelay: + if networkPresetConf.rlnRelay: assert conf.rlnRelayConf.isSome(), "RLN Relay conf is disabled" let rlnRelayConf = conf.rlnRelayConf.get() check rlnRelayConf.ethContractAddress.string == - networkConf.rlnRelayEthContractAddress - check rlnRelayConf.dynamic == networkConf.rlnRelayDynamic - check rlnRelayConf.chainId == networkConf.rlnRelayChainId - check rlnRelayConf.epochSizeSec == networkConf.rlnEpochSizeSec + networkPresetConf.rlnRelayEthContractAddress + check rlnRelayConf.dynamic == networkPresetConf.rlnRelayDynamic + check rlnRelayConf.chainId == networkPresetConf.rlnRelayChainId + check rlnRelayConf.epochSizeSec == networkPresetConf.rlnEpochSizeSec check rlnRelayConf.userMessageLimit == userMessageLimit.uint test "Cluster Conf is passed, but relay is disabled": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() builder.withRelayServiceRatio("50:50") builder.discv5Conf.withUdpPort(9000) @@ -69,7 +69,7 @@ suite "Waku Conf - build with cluster conf": ## Given builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withRelay(false) ## When @@ -80,20 +80,20 @@ suite "Waku Conf - build with cluster conf": ## Then let resValidate = conf.validate() assert resValidate.isOk(), $resValidate.error - check conf.clusterId == networkConf.clusterId - check conf.shardingConf.kind == networkConf.shardingConf.kind + check conf.clusterId == networkPresetConf.clusterId + check conf.shardingConf.kind == networkPresetConf.shardingConf.kind check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster + networkPresetConf.shardingConf.numShardsInCluster check conf.subscribeShards == expectedShards check conf.maxMessageSizeBytes == - uint64(parseCorrectMsgSize(networkConf.maxMessageSize)) - check conf.discv5Conf.get().bootstrapNodes == networkConf.discv5BootstrapNodes + uint64(parseCorrectMsgSize(networkPresetConf.maxMessageSize)) + check conf.discv5Conf.get().bootstrapNodes == networkPresetConf.discv5BootstrapNodes assert conf.rlnRelayConf.isNone test "Cluster Conf is passed, but rln relay is disabled": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() let # Mount all shards in network @@ -101,7 +101,7 @@ suite "Waku Conf - build with cluster conf": ## Given builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.rlnRelayConf.withEnabled(false) ## When @@ -112,25 +112,25 @@ suite "Waku Conf - build with cluster conf": ## Then let resValidate = conf.validate() assert resValidate.isOk(), $resValidate.error - check conf.clusterId == networkConf.clusterId - check conf.shardingConf.kind == networkConf.shardingConf.kind + check conf.clusterId == networkPresetConf.clusterId + check conf.shardingConf.kind == networkPresetConf.shardingConf.kind check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster + networkPresetConf.shardingConf.numShardsInCluster check conf.subscribeShards == expectedShards check conf.maxMessageSizeBytes == - uint64(parseCorrectMsgSize(networkConf.maxMessageSize)) - check conf.discv5Conf.get().bootstrapNodes == networkConf.discv5BootstrapNodes + uint64(parseCorrectMsgSize(networkPresetConf.maxMessageSize)) + check conf.discv5Conf.get().bootstrapNodes == networkPresetConf.discv5BootstrapNodes assert conf.rlnRelayConf.isNone test "Cluster Conf is passed and valid shards are specified": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() let shards = @[2.uint16, 3.uint16] ## Given builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withSubscribeShards(shards) ## When @@ -141,24 +141,24 @@ suite "Waku Conf - build with cluster conf": ## Then let resValidate = conf.validate() assert resValidate.isOk(), $resValidate.error - check conf.clusterId == networkConf.clusterId - check conf.shardingConf.kind == networkConf.shardingConf.kind + check conf.clusterId == networkPresetConf.clusterId + check conf.shardingConf.kind == networkPresetConf.shardingConf.kind check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster + networkPresetConf.shardingConf.numShardsInCluster check conf.subscribeShards == shards check conf.maxMessageSizeBytes == - uint64(parseCorrectMsgSize(networkConf.maxMessageSize)) - check conf.discv5Conf.get().bootstrapNodes == networkConf.discv5BootstrapNodes + uint64(parseCorrectMsgSize(networkPresetConf.maxMessageSize)) + check conf.discv5Conf.get().bootstrapNodes == networkPresetConf.discv5BootstrapNodes test "Cluster Conf is passed and invalid shards are specified": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() let shards = @[2.uint16, 10.uint16] ## Given builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withSubscribeShards(shards) ## When @@ -167,63 +167,112 @@ suite "Waku Conf - build with cluster conf": ## Then assert resConf.isErr(), "Invalid shard was accepted" - test "Cluster Conf is passed and RLN contract is **not** overridden": + test "Cluster Conf mandating RLN fails conf build if user disables rln relay": ## Setup - let networkConf = NetworkConf.TheWakuNetworkConf() + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() var builder = WakuConfBuilder.init() - builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - - # Mount all shards in network - let expectedShards = toSeq[0.uint16 .. 7.uint16] - let contractAddress = "0x0123456789ABCDEF" - let userMessageLimit = rand(1 .. 1000).uint64 ## Given - builder.rlnRelayConf.withEthContractAddress(contractAddress) - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withRelay(true) - builder.rlnRelayConf.withUserMessageLimit(userMessageLimit) + builder.rlnRelayConf.withEnabled(false) ## When let resConf = builder.build() - assert resConf.isOk(), $resConf.error - let conf = resConf.get() ## Then - let resValidate = conf.validate() - assert resValidate.isOk(), $resValidate.error - check conf.clusterId == networkConf.clusterId - check conf.shardingConf.kind == networkConf.shardingConf.kind - check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster - check conf.subscribeShards == expectedShards - check conf.maxMessageSizeBytes == - uint64(parseCorrectMsgSize(networkConf.maxMessageSize)) - check conf.discv5Conf.isSome == networkConf.discv5Discovery - check conf.discv5Conf.get().bootstrapNodes == networkConf.discv5BootstrapNodes + assert networkPresetConf.rlnRelay, "precondition: preset must mandate RLN" + assert resConf.isErr(), "relay with rln relay disabled was accepted" - if networkConf.rlnRelay: - assert conf.rlnRelayConf.isSome + test "Cluster Conf mandating RLN fails conf build if user overrides the rln contract": + ## Setup + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() + var builder = WakuConfBuilder.init() + # otherwise-valid RLN, so only the security gate can fail the build + builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) - let rlnRelayConf = conf.rlnRelayConf.get() - check rlnRelayConf.ethContractAddress.string == - networkConf.rlnRelayEthContractAddress - check rlnRelayConf.dynamic == networkConf.rlnRelayDynamic - check rlnRelayConf.chainId == networkConf.rlnRelayChainId - check rlnRelayConf.epochSizeSec == networkConf.rlnEpochSizeSec - check rlnRelayConf.userMessageLimit == userMessageLimit.uint + ## Given + builder.withNetworkPresetConf(networkPresetConf) + builder.withRelay(true) + builder.rlnRelayConf.withEthContractAddress( + networkPresetConf.rlnRelayEthContractAddress & "0" + ) + + ## When + let resConf = builder.build() + + ## Then + assert networkPresetConf.rlnRelay, "precondition: preset must mandate RLN" + assert resConf.isErr(), "relay with an overridden rln contract was accepted" + + test "Cluster Conf mandating RLN fails conf build if user overrides the rln chain id": + ## Setup + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() + var builder = WakuConfBuilder.init() + # otherwise-valid RLN, so only the security gate can fail the build + builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) + + ## Given + builder.withNetworkPresetConf(networkPresetConf) + builder.withRelay(true) + builder.rlnRelayConf.withChainId(1'u) # chain id 1 differs from the preset's + + ## When + let resConf = builder.build() + + ## Then + assert networkPresetConf.rlnRelay, "precondition: preset must mandate RLN" + assert resConf.isErr(), "relay with an overridden rln chain id was accepted" + + test "Cluster Conf mandating RLN fails conf build if user overrides rln dynamic mode": + ## Setup + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() + var builder = WakuConfBuilder.init() + # otherwise-valid RLN, so only the security gate can fail the build + builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) + + ## Given + builder.withNetworkPresetConf(networkPresetConf) + builder.withRelay(true) + builder.rlnRelayConf.withDynamic(not networkPresetConf.rlnRelayDynamic) + + ## When + let resConf = builder.build() + + ## Then + assert networkPresetConf.rlnRelay, "precondition: preset must mandate RLN" + assert resConf.isErr(), "relay with an overridden rln dynamic mode was accepted" + + test "Cluster Conf mandating RLN fails conf build if user overrides the rln epoch size": + ## Setup + let networkPresetConf = NetworkPresetConf.TheWakuNetworkConf() + var builder = WakuConfBuilder.init() + # otherwise-valid RLN, so only the security gate can fail the build + builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"]) + + ## Given + builder.withNetworkPresetConf(networkPresetConf) + builder.withRelay(true) + builder.rlnRelayConf.withEpochSizeSec(networkPresetConf.rlnEpochSizeSec + 1'u64) + + ## When + let resConf = builder.build() + + ## Then + assert networkPresetConf.rlnRelay, "precondition: preset must mandate RLN" + assert resConf.isErr(), "relay with an overridden rln epoch size was accepted" test "num-shards-in-network > 0 overrides preset": ## Setup - let networkConf = NetworkConf.LogosDevConf() + let networkPresetConf = NetworkPresetConf.LogosDevConf() var builder = WakuConfBuilder.init() # Sanity check - check networkConf.shardingConf.kind == AutoSharding - check networkConf.shardingConf.numShardsInCluster > 1 + check networkPresetConf.shardingConf.kind == AutoSharding + check networkPresetConf.shardingConf.numShardsInCluster > 1 ## Given: preset says >1 shards but user explicitly sets 1 - builder.withNetworkConf(networkConf) + builder.withNetworkPresetConf(networkPresetConf) builder.withNumShardsInCluster(1) builder.withShardingConf(AutoSharding) @@ -244,22 +293,18 @@ suite "Waku Conf - build with cluster conf": ## StaticSharding shouldn't make any sense (that is, no use case). ## Given: emulate --preset=logos.dev --num-shards-in-network=0 - let networkConf = NetworkConf.LogosDevConf() + let networkPresetConf = NetworkPresetConf.LogosDevConf() var builder = WakuConfBuilder.init() - builder.withNetworkConf(networkConf) - # Note: builder.withNumShardsInCluster() is not called when the - # value that comes from the CLI path is 0 (which means it was - # either set to 0 or was left unset). - builder.withShardingConf(StaticSharding) + builder.withNetworkPresetConf(networkPresetConf) ## When let conf = builder.build().expect("build should succeed") ## Then: preset wins and StaticSharding user intent is lost conf.validate().expect("conf should validate") - check conf.shardingConf.kind == networkConf.shardingConf.kind + check conf.shardingConf.kind == networkPresetConf.shardingConf.kind check conf.shardingConf.numShardsInCluster == - networkConf.shardingConf.numShardsInCluster + networkPresetConf.shardingConf.numShardsInCluster suite "Waku Conf - node key": test "Node key is generated": diff --git a/tests/test_waku.nim b/tests/test_waku.nim index 310356a44..ff009c3ba 100644 --- a/tests/test_waku.nim +++ b/tests/test_waku.nim @@ -1,24 +1,28 @@ {.used.} -import chronos, testutils/unittests, std/options +import std/[net, options] + +import chronos, testutils/unittests import logos_delivery import tools/confutils/cli_args +import logos_delivery/waku/factory/networks_config +import logos_delivery/waku/factory/conf_builder/conf_builder suite "Waku API - Create node": asyncTest "Create node with minimal configuration": ## Given var nodeConf = defaultWakuNodeConf().valueOr: - raiseAssert error + raiseAssert "defaultWakuNodeConf failed: " & error nodeConf.mode = Core - nodeConf.clusterId = 3'u16 + nodeConf.clusterId = some(3'u16) nodeConf.rest = false # This is the actual minimal config but as the node auto-start, it is not suitable for tests ## When let node = (await createNode(nodeConf)).valueOr: - raiseAssert error + raiseAssert "createNode (minimal config) failed: " & error ## Then check: @@ -29,9 +33,9 @@ suite "Waku API - Create node": asyncTest "Create node with full configuration": ## Given var nodeConf = defaultWakuNodeConf().valueOr: - raiseAssert error + raiseAssert "defaultWakuNodeConf failed: " & error nodeConf.mode = Core - nodeConf.clusterId = 99'u16 + nodeConf.clusterId = some(99'u16) nodeConf.rest = false nodeConf.numShardsInNetwork = 16 nodeConf.maxMessageSize = "1024 KiB" @@ -44,7 +48,7 @@ suite "Waku API - Create node": ## When let node = (await createNode(nodeConf)).valueOr: - raiseAssert error + raiseAssert "createNode (full config) failed: " & error ## Then check: @@ -61,9 +65,9 @@ suite "Waku API - Create node": asyncTest "Create node with mixed entry nodes (enrtree, multiaddr)": ## Given var nodeConf = defaultWakuNodeConf().valueOr: - raiseAssert error + raiseAssert "defaultWakuNodeConf failed: " & error nodeConf.mode = Core - nodeConf.clusterId = 42'u16 + nodeConf.clusterId = some(42'u16) nodeConf.rest = false nodeConf.entryNodes = @[ "enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im", @@ -72,7 +76,7 @@ suite "Waku API - Create node": ## When let node = (await createNode(nodeConf)).valueOr: - raiseAssert error + raiseAssert "createNode (mixed entry nodes) failed: " & error ## Then check: diff --git a/tests/wakunode2/test_cli_args.nim b/tests/wakunode2/test_cli_args.nim index 36bb947f2..5b21bd327 100644 --- a/tests/wakunode2/test_cli_args.nim +++ b/tests/wakunode2/test_cli_args.nim @@ -57,7 +57,7 @@ suite "Waku external config - default values": suite "Waku external config - apply preset": test "Preset is TWN": ## Setup - let expectedConf = NetworkConf.TheWakuNetworkConf() + let expectedConf = NetworkPresetConf.TheWakuNetworkConf() ## Given let preConfig = WakuNodeConf( @@ -94,7 +94,7 @@ suite "Waku external config - apply preset": test "Subscribes to all valid shards in twn": ## Setup - let expectedConf = NetworkConf.TheWakuNetworkConf() + let expectedConf = NetworkPresetConf.TheWakuNetworkConf() ## Given let shards: seq[uint16] = @[0, 1, 2, 3, 4, 5, 6, 7] @@ -110,7 +110,7 @@ suite "Waku external config - apply preset": test "Subscribes to some valid shards in twn": ## Setup - let expectedConf = NetworkConf.TheWakuNetworkConf() + let expectedConf = NetworkPresetConf.TheWakuNetworkConf() ## Given let shards: seq[uint16] = @[0, 4, 7] diff --git a/tools/confutils/cli_args.nim b/tools/confutils/cli_args.nim index cbd707a2d..00a9b0794 100644 --- a/tools/confutils/cli_args.nim +++ b/tools/confutils/cli_args.nim @@ -37,7 +37,7 @@ import ./envvar as confEnvvarDefs, ./envvar_net as confEnvvarNet export confTomlDefs, confTomlNet, confEnvvarDefs, confEnvvarNet, ProtectedShard, - DefaultMaxWakuMessageSizeStr + DefaultMaxWakuMessageSizeStr, DefaultAgentString logScope: topics = "waku cli args" @@ -45,6 +45,13 @@ logScope: # Git version in git describe format (defined at compile time) const git_version* {.strdefine.} = "n/a" +# CLI defaults that differ from confbuilder defaults +const + DefaultCLIRelay* = true + DefaultCLIPeerExchange* = true + DefaultCLIRendezvous* = true + DefaultCLINat* = "any" + type ConfResult*[T] = Result[T, string] type EthRpcUrl* = distinct string @@ -117,20 +124,23 @@ type WakuNodeConf* = object name: "rln-relay-eth-private-key" .}: string - # TODO: Remove "Default is" when it's already visible on the CLI + # Option-typed; desc states the default since the CLI can't auto-show it for none(). rlnRelayUserMessageLimit* {. desc: - "Set a user message limit for the rln membership registration. Must be a positive integer. Default is 1.", - defaultValue: 1, + "Set a user message limit for the rln membership registration. Must be a positive integer. Default is " & + $DefaultRlnRelayUserMessageLimit & ".", + defaultValue: none(uint64), name: "rln-relay-user-message-limit" - .}: uint64 + .}: Option[uint64] + # Option-typed; desc states the default since the CLI can't auto-show it for none(). rlnEpochSizeSec* {. desc: - "Epoch size in seconds used to rate limit RLN memberships. Default is 1 second.", - defaultValue: 1, + "Epoch size in seconds used to rate limit RLN memberships. Default is " & + $DefaultRlnRelayEpochSizeSec & " second.", + defaultValue: none(uint64), name: "rln-relay-epoch-sec" - .}: uint64 + .}: Option[uint64] maxMessageSize* {. desc: @@ -170,15 +180,18 @@ type WakuNodeConf* = object name: "preset" .}: string + # Option-typed; desc states the default since the CLI can't auto-show it for none(). clusterId* {. - desc: - "Cluster id that the node is running in. Node in a different cluster id is disconnected.", - defaultValue: 0, + desc: static( + "Cluster id that the node is running in. Node in a different cluster id is disconnected. Default is " & + $DefaultClusterId & "." + ), + defaultValue: none(uint16), name: "cluster-id" - .}: uint16 + .}: Option[uint16] agentString* {. - defaultValue: "logos-delivery-" & cli_args.git_version, + defaultValue: DefaultAgentString, desc: "Node agent string which is used as identifier in network", name: "agent-string" .}: string @@ -203,7 +216,7 @@ type WakuNodeConf* = object desc: "Specify method to use for determining public address. " & "Must be one of: any, none, upnp, pmp, extip:.", - defaultValue: "any" + defaultValue: DefaultCLINat .}: string extMultiAddrs* {. @@ -275,7 +288,9 @@ hence would have reachability issues.""", ## Relay config relay* {. - desc: "Enable relay protocol: true|false", defaultValue: true, name: "relay" + desc: "Enable relay protocol: true|false", + defaultValue: DefaultCLIRelay, + name: "relay" .}: bool relayPeerExchange* {. @@ -291,11 +306,14 @@ hence would have reachability issues.""", name: "relay-shard-manager" .}: bool + # Option-typed; desc states the default since the CLI can't auto-show it for none(). rlnRelay* {. - desc: "Enable spam protection through rln-relay: true|false.", - defaultValue: false, + desc: + "Enable spam protection through rln-relay: true|false. Default is " & + $DefaultRlnRelayEnabled & ".", + defaultValue: none(bool), name: "rln-relay" - .}: bool + .}: Option[bool] rlnRelayCredIndex* {. desc: "the index of the onchain commitment to use", @@ -304,9 +322,9 @@ hence would have reachability issues.""", rlnRelayDynamic* {. desc: "Enable waku-rln-relay with on-chain dynamic group management: true|false.", - defaultValue: false, + defaultValue: none(bool), name: "rln-relay-dynamic" - .}: bool + .}: Option[bool] entryNodes* {. desc: @@ -466,13 +484,14 @@ hence would have reachability issues.""", .}: string ## Reliability config + # Option-typed; desc states the default since the CLI can't auto-show it for none(). reliabilityEnabled* {. desc: - """Adds an extra effort in the delivery/reception of messages by leveraging store-v3 requests. -with the drawback of consuming some more bandwidth.""", - defaultValue: true, + """Adds an extra effort in the delivery/reception of messages by leveraging store-v3 requests, with the drawback of consuming some more bandwidth. Default is """ & + $DefaultP2pReliability & ".", + defaultValue: none(bool), name: "reliability" - .}: bool + .}: Option[bool] ## REST HTTP config rest* {. @@ -557,8 +576,11 @@ with the drawback of consuming some more bandwidth.""", .}: string ## Discovery v5 config + # Option-typed; desc states the default since the CLI can't auto-show it for none(). discv5Discovery* {. - desc: "Enable discovering nodes via Node Discovery v5.", + desc: + "Enable discovering nodes via Node Discovery v5. Default is " & + $DefaultDiscv5Enabled & ".", defaultValue: none(bool), name: "discv5-discovery" .}: Option[bool] @@ -608,7 +630,7 @@ with the drawback of consuming some more bandwidth.""", ## waku peer exchange config peerExchange* {. desc: "Enable waku peer exchange protocol (responder side): true|false", - defaultValue: true, + defaultValue: DefaultCLIPeerExchange, name: "peer-exchange" .}: bool @@ -622,13 +644,17 @@ with the drawback of consuming some more bandwidth.""", ## Rendez vous rendezvous* {. desc: "Enable waku rendezvous discovery server", - defaultValue: true, + defaultValue: DefaultCLIRendezvous, name: "rendezvous" .}: bool #Mix config - mix* {.desc: "Enable mix protocol: true|false", defaultValue: false, name: "mix".}: - bool + # Option-typed; desc states the default since the CLI can't auto-show it for none(). + mix* {. + desc: "Enable mix protocol: true|false. Default is " & $DefaultMix & ".", + defaultValue: none(bool), + name: "mix" + .}: Option[bool] mixkey* {. desc: @@ -643,12 +669,14 @@ with the drawback of consuming some more bandwidth.""", .}: seq[MixNodePubInfo] # Kademlia Discovery config + # Option-typed; desc states the default since the CLI can't auto-show it for none(). enableKadDiscovery* {. desc: - "Enable extended kademlia discovery. Can be enabled without bootstrap nodes for the first node in the network.", - defaultValue: false, + "Enable extended kademlia discovery. Can be enabled without bootstrap nodes for the first node in the network. Default is " & + $DefaultKadEnabled & ".", + defaultValue: none(bool), name: "enable-kad-discovery" - .}: bool + .}: Option[bool] kadBootstrapNodes* {. desc: @@ -919,15 +947,15 @@ proc toKeystoreGeneratorConf*(n: WakuNodeConf): RlnKeystoreGeneratorConf = chainId: UInt256.fromBytesBE(n.rlnRelayChainId.toBytesBE()), ethClientUrls: n.ethClientUrls.mapIt(string(it)), ethContractAddress: n.rlnRelayEthContractAddress, - userMessageLimit: n.rlnRelayUserMessageLimit, + userMessageLimit: n.rlnRelayUserMessageLimit.get(DefaultRlnRelayUserMessageLimit), ethPrivateKey: n.rlnRelayEthPrivateKey, credPath: n.rlnRelayCredPath, credPassword: n.rlnRelayCredPassword, ) -proc toNetworkConf( +proc toNetworkPresetConf( preset: string, clusterId: Option[uint16] -): ConfResult[Option[NetworkConf]] = +): ConfResult[Option[NetworkPresetConf]] = var lcPreset = toLowerAscii(preset) if clusterId.isSome() and clusterId.get() == 1: warn( @@ -942,29 +970,30 @@ proc toNetworkConf( case lcPreset of "": - ok(none(NetworkConf)) + ok(none(NetworkPresetConf)) of "twn": - ok(some(NetworkConf.TheWakuNetworkConf())) + ok(some(NetworkPresetConf.TheWakuNetworkConf())) of "logos.dev", "logosdev": - ok(some(NetworkConf.LogosDevConf())) + ok(some(NetworkPresetConf.LogosDevConf())) of "logos.test", "logostest": - ok(some(NetworkConf.LogosTestConf())) + ok(some(NetworkPresetConf.LogosTestConf())) else: err("Invalid --preset value passed: " & lcPreset) proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = var b = WakuConfBuilder.init() - let networkConf = toNetworkConf(n.preset, some(n.clusterId)).valueOr: + let networkPresetConf = toNetworkPresetConf(n.preset, n.clusterId).valueOr: return err("Error determining cluster from preset: " & $error) - if networkConf.isSome(): - b.withNetworkConf(networkConf.get()) + if networkPresetConf.isSome(): + b.withNetworkPresetConf(networkPresetConf.get()) b.withLogLevel(n.logLevel) b.withLogFormat(n.logFormat) - b.rlnRelayConf.withEnabled(n.rlnRelay) + if n.rlnRelay.isSome(): + b.rlnRelayConf.withEnabled(n.rlnRelay.get()) if n.rlnRelayCredPath != "": b.rlnRelayConf.withCredPath(n.rlnRelayCredPath) if n.rlnRelayCredPassword != "": @@ -976,18 +1005,22 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = if n.rlnRelayChainId != 0: b.rlnRelayConf.withChainId(n.rlnRelayChainId) - b.rlnRelayConf.withUserMessageLimit(n.rlnRelayUserMessageLimit) - b.rlnRelayConf.withEpochSizeSec(n.rlnEpochSizeSec) + if n.rlnRelayUserMessageLimit.isSome(): + b.rlnRelayConf.withUserMessageLimit(n.rlnRelayUserMessageLimit.get()) + if n.rlnEpochSizeSec.isSome(): + b.rlnRelayConf.withEpochSizeSec(n.rlnEpochSizeSec.get()) if n.rlnRelayCredIndex.isSome(): b.rlnRelayConf.withCredIndex(n.rlnRelayCredIndex.get()) - b.rlnRelayConf.withDynamic(n.rlnRelayDynamic) + if n.rlnRelayDynamic.isSome(): + b.rlnRelayConf.withDynamic(n.rlnRelayDynamic.get()) if n.maxMessageSize != "": b.withMaxMessageSize(n.maxMessageSize) b.withProtectedShards(n.protectedShards) - b.withClusterId(n.clusterId) + if n.clusterId.isSome(): + b.withClusterId(n.clusterId.get()) b.withAgentString(n.agentString) @@ -1041,7 +1074,7 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = if n.numShardsInNetwork != 0: b.withNumShardsInCluster(n.numShardsInNetwork) b.withShardingConf(AutoSharding) - else: + elif networkPresetConf.isNone(): b.withShardingConf(StaticSharding) # It is not possible to pass an empty sequence on the CLI @@ -1074,9 +1107,10 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = b.storeServiceConf.storeSyncConf.withRangeSec(n.storeSyncRange) b.storeServiceConf.storeSyncConf.withRelayJitterSec(n.storeSyncRelayJitter) - b.mixConf.withEnabled(n.mix) + if n.mix.isSome(): + b.mixConf.withEnabled(n.mix.get()) + b.withMix(n.mix.get()) b.mixConf.withMixNodes(n.mixnodes) - b.withMix(n.mix) if n.mixkey.isSome(): b.mixConf.withMixKey(n.mixkey.get()) @@ -1086,7 +1120,8 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = b.filterServiceConf.withMaxCriteria(n.filterMaxCriteria) b.withLightPush(n.lightpush) - b.withP2pReliability(n.reliabilityEnabled) + if n.reliabilityEnabled.isSome(): + b.withP2pReliability(n.reliabilityEnabled.get()) b.restServerConf.withEnabled(n.rest) b.restServerConf.withListenAddress(n.restAddress) @@ -1129,7 +1164,8 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] = b.withLocalStoragePath(n.localStoragePath) - b.kademliaDiscoveryConf.withEnabled(n.enableKadDiscovery) + if n.enableKadDiscovery.isSome(): + b.kademliaDiscoveryConf.withEnabled(n.enableKadDiscovery.get()) b.kademliaDiscoveryConf.withBootstrapNodes(n.kadBootstrapNodes) # Mode-driven configuration overrides diff --git a/tools/confutils/conf_from_json.nim b/tools/confutils/conf_from_json.nim new file mode 100644 index 000000000..1f305774e --- /dev/null +++ b/tools/confutils/conf_from_json.nim @@ -0,0 +1,121 @@ +import std/[json, strutils, tables] +import confutils, confutils/std/net, results +import ./cli_args + +proc collectJsonFields*( + jsonNode: JsonNode +): Result[Table[string, (string, JsonNode)], string] = + ## Walk the top-level JSON object and key it by lowercased names. + if jsonNode.kind != JObject: + return err("config JSON must be a JSON object, got " & $jsonNode.kind) + var jsonFields: Table[string, (string, JsonNode)] + for key, value in jsonNode: + let lowerKey = key.toLowerAscii() + if jsonFields.hasKey(lowerKey): + let firstKey = jsonFields[lowerKey][0] + return err( + "Duplicate configuration option (case-insensitive): '" & firstKey & "' and '" & + key & "'" + ) + jsonFields[lowerKey] = (key, value) + return ok(jsonFields) + +proc unknownKeysError( + jsonFields: Table[string, (string, JsonNode)], prefix: string +): string = + ## Format leftover JSON keys as an error message. + var keys = newSeq[string]() + for _, (jsonKey, _) in pairs(jsonFields): + keys.add(jsonKey) + return prefix & ": " & $keys + +proc jsonScalarToString(node: JsonNode): Result[string, string] = + ## Convert a scalar JSON value to its string form. + case node.kind + of JString: + return ok(node.getStr()) + of JInt: + return ok($node.getInt()) + of JFloat: + return ok($node.getFloat()) + of JBool: + return ok($node.getBool()) + of JNull: + return ok("") + else: + return err("expected scalar JSON value, got " & $node.kind) + +proc applyJsonFieldsToConf( + conf: var WakuNodeConf, + jsonFields: var Table[string, (string, JsonNode)], + parseErrPrefix: string, + unknownErrPrefix: string, +): Result[void, string] = + ## Walk `conf`'s fields and write each one matched (case-insensitive) by + ## `jsonFields`. seq fields take a JArray (full replace); scalar fields + ## take any scalar JSON kind. Errors on leftover unknown keys. + for confField, confValue in fieldPairs(conf): + let lowerField = confField.toLowerAscii() + if jsonFields.hasKey(lowerField): + let (jsonKey, jsonValue) = jsonFields[lowerField] + when confValue is seq: + if jsonValue.kind != JArray: + return err( + parseErrPrefix & " '" & confField & "' from JSON key '" & jsonKey & + "' must be a JSON array" + ) + var newSeq: typeof(confValue) = @[] + for item in jsonValue: + let formattedItem = jsonScalarToString(item).valueOr: + return err( + parseErrPrefix & " '" & confField & "' from JSON key '" & jsonKey & "': " & + error + ) + try: + type ElemType = typeof(confValue[0]) + newSeq.add(parseCmdArg(ElemType, formattedItem)) + except CatchableError as e: + return err( + parseErrPrefix & " '" & confField & "' from JSON key '" & jsonKey & "': " & + e.msg & ". Value: " & formattedItem + ) + confValue = newSeq + else: + let formattedString = jsonScalarToString(jsonValue).valueOr: + return err( + parseErrPrefix & " '" & confField & "' from JSON key '" & jsonKey & "': " & + error + ) + try: + confValue = parseCmdArg(typeof(confValue), formattedString) + except CatchableError as e: + return err( + parseErrPrefix & " '" & confField & "' from JSON key '" & jsonKey & "': " & + e.msg & ". Value: " & formattedString + ) + jsonFields.del(lowerField) + if jsonFields.len > 0: + return err(unknownKeysError(jsonFields, unknownErrPrefix)) + return ok() + +proc assembleFullConf*( + jsonFields: Table[string, (string, JsonNode)] +): Result[WakuNodeConf, string] = + ## Build a WakuNodeConf from a flat JSON object whose keys are WakuNodeConf field names. + var conf = ?defaultWakuNodeConf() + var fields = jsonFields + ?applyJsonFieldsToConf( + conf, fields, "Failed to parse field", "Unrecognized configuration option(s) found" + ) + return ok(conf) + +proc parseNodeConfFromJson*(jsonStr: string): Result[WakuNodeConf, string] = + ## Parse a flat JSON config whose keys are WakuNodeConf field names. + var jsonNode: JsonNode + try: + jsonNode = parseJson(jsonStr) + except CatchableError as e: + return err("Failed to parse config JSON: " & e.msg) + + let jsonFields = ?collectJsonFields(jsonNode) + return assembleFullConf(jsonFields)