cleanup(01-dry): bytesToHexUpper helper + report

- Bumps vendor/nwaku to d08083c5 (bytesToHexUpper extraction).
- Adds cleanup/01-dry.md report for the DRY pass.

Code change deduplicates three identical hex-encoding loops in the
gifter section of node_factory.nim. Net -4 lines.
This commit is contained in:
Arseniy Klempner 2026-05-28 12:09:56 -06:00
parent 29c64b340d
commit 253489b3c7
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
2 changed files with 61 additions and 1 deletions

60
cleanup/01-dry.md Normal file
View File

@ -0,0 +1,60 @@
# Cleanup 01 — DRY (post-squash, 2026-05-28)
## Research notes
Re-scanned in-scope Nim files after the May 28 squash (`29c64b3` etc.):
- `src/chat/delivery/waku_client.nim`
- `vendor/nwaku/waku/factory/node_factory.nim` (mirrored in loose `vendor/logos-lez-rln/logos-delivery/` and canonical `vendor/logos-lez-rln/logos-delivery-module/vendor/logos-delivery/`)
- `vendor/nwaku/waku/waku_mix/logos_core_client.nim` (same three-way mirror)
- `vendor/nwaku/waku/waku_rln_relay/rln_gifter/{client,protocol,rpc,rpc_codec}.nim`
Cross-checked all three mirror trees — byte-identical pre- and post-edit.
Findings still standing from the prior (pre-squash) pass:
1. **`watchMembershipConfirmation`** helper in `rln_gifter/client.nim` — already extracted; both call sites (mix-node self-reg in `node_factory.nim` and chat-client cushion in `waku_client.nim`) use it. **No further work.**
2. **Hex-encoding loops** — now 3 sites in `node_factory.nim` (gifterSubmitOnce, waitForChainCommit, statusHandler), all producing uppercase hex from `seq[byte]`. Previous pass deferred this; with a third site added, extraction now meets rule-of-three cleanly.
3. **`is_member_registered` JSON params** — 2 sites, but with different post-processing contracts (raw `uint64` vs `MembershipStatusResponse`). The shared prefix is only the param string + parseJson. Not worth a wrapper.
4. **`callRlnFetcher + parseJson` patterns** — different field shapes per call. No real duplication.
5. **rpc_codec.nim getField sequences** — standard protobuf decoder shape, not duplication.
## Critical assessment
| Candidate | Verdict | Reason |
|---|---|---|
| `watchMembershipConfirmation` | DONE in prior pass | Already a single helper in `rln_gifter/client.nim`. |
| Hex-encoding loops (3 sites) | EXTRACT | Three byte-identical 3-line loops, all uppercase. Natural home is `logos_core_client.nim` (already houses the matching `hexToBytes32` decoder). |
| `is_member_registered` params | SKIP | 2 sites, distinct return contracts. Wrapping the shared 4-line prefix would still need 2 callers that diverge on parsing — net loss. |
| `callRlnFetcher` + parseJson | SKIP | Each callsite parses a different schema. No common middle. |
| Gifter rpc_codec getField | SKIP | Protobuf field decode — already minimal. |
## Recommendations
1. **High confidence**: add `bytesToHexUpper*` to `logos_core_client.nim`, replace 3 hex loops in `node_factory.nim`. Done.
2. **Deferred**: none worth pursuing.
## Applied
Added `proc bytesToHexUpper*(bytes: openArray[byte]): string` (8 lines incl. doc-comment) to `vendor/nwaku/waku/waku_mix/logos_core_client.nim`, placed adjacent to the existing `hexToBytes32` decoder.
Replaced 3 inline `newStringOfCap + for-loop + toHex` blocks in `vendor/nwaku/waku/factory/node_factory.nim` with `mix_lez_client.bytesToHexUpper(...)` calls. Net change: 12 lines in node_factory.nim, +8 in logos_core_client.nim = **4 lines** plus clarity gain (intent visible at call site).
Mirrored byte-for-byte to:
- `vendor/logos-lez-rln/logos-delivery/waku/...` (loose checkout)
- `vendor/logos-lez-rln/logos-delivery-module/vendor/logos-delivery/waku/...` (canonical submodule)
Builds: `liblogoschat` and `liblogosdelivery` both compile cleanly.
### Commit SHAs
- `vendor/nwaku` (feat/sim-rln-gifter-auth): `d08083c5`
- `vendor/logos-lez-rln/logos-delivery` (feat/sim-rln-gifter-auth-debug, loose): `9240b8d0`
- `vendor/logos-lez-rln/logos-delivery-module/vendor/logos-delivery` (feat/sim-rln-gifter-auth-debug, canonical): `2e9d59b9`
- outer logos-chat (feat/sim-rln-gifter-auth-v2): report-only commit (see git log)
## Deferred
- `is_member_registered` JSON param prefix — divergent post-parse contracts make a wrapper net-neutral at best.
- `callRlnFetcher`/`parseJson` glue — schemas differ per call.
- Watcher proc — already factored in prior pass.

2
vendor/nwaku vendored

@ -1 +1 @@
Subproject commit 8e6ba04d5c7bb1829cffbbb6e682461373246987
Subproject commit d08083c507fffeda32572f3c7895406bf299c73d