nim-chat-poc/cleanup/01-dry.md
Arseniy Klempner a018b24db6
cleanup: 8-agent code-quality pass post-squash summary
Reports for each of the 8 cleanup agents (DRY, types, unused, cycles,
weak-types, try/except, legacy, slop) recording verdicts + applied
changes + deferred items, plus the consolidated SUMMARY.md.

End-of-pass local sim ALL 15 PASSED.
2026-05-28 14:22:39 -06:00

3.9 KiB
Raw Blame History

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): 9240b8d0 (same SHA as loose — they share the remote branch; orphaned content-identical commit 2e9d59b9 discarded by resync)
  • 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.