mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-27 20:10:02 +00:00
cleanup: DRY bytesToHexUpper + dead-code removal + narrowed exception handling
Combines the post-feature cleanup pass: - Extract bytesToHexUpper helper for idCommitment hex (was duplicated across logos_core_client.nim + node_factory.nim). - Drop dead helper functions, unused imports, and duplicate kademlia wiring left over from the feature commit. - Narrow waitForChainCommit's broad except, add CancelledError carve-outs to the self-registration watcher to avoid swallowing shutdown signals.
This commit is contained in:
parent
b40ee69e0f
commit
c042c8f837
@ -230,9 +230,7 @@ proc setupProtocols(
|
||||
return err("RLN config not set on gifter node")
|
||||
let holdingAccount =
|
||||
if walletAccount.len > 0: walletAccount else: configAccount
|
||||
var idCommitmentHex = newStringOfCap(idc.len * 2)
|
||||
for b in idc:
|
||||
idCommitmentHex.add(toHex(int(b), 2))
|
||||
let idCommitmentHex = mix_lez_client.bytesToHexUpper(idc)
|
||||
let params =
|
||||
"{\"configAccountId\":\"" & configAccount &
|
||||
"\",\"userHoldingAccountId\":\"" & holdingAccount &
|
||||
@ -262,9 +260,7 @@ proc setupProtocols(
|
||||
let (configAccount, _) = mix_lez_client.getRlnConfig()
|
||||
if configAccount.len == 0:
|
||||
return err("RLN config not set")
|
||||
var idHex = newStringOfCap(idc.len * 2)
|
||||
for b in idc:
|
||||
idHex.add(toHex(int(b), 2))
|
||||
let idHex = mix_lez_client.bytesToHexUpper(idc)
|
||||
let params =
|
||||
"{\"configAccountId\":\"" & configAccount &
|
||||
"\",\"idCommitment\":\"" & idHex & "\"}"
|
||||
@ -280,7 +276,13 @@ proc setupProtocols(
|
||||
parsed["registered"].getBool() and
|
||||
parsed.hasKey("leaf_index"):
|
||||
return ok(parsed["leaf_index"].getInt().uint64)
|
||||
except CatchableError:
|
||||
except JsonParsingError as e:
|
||||
warn "waitForChainCommit: bad JSON from is_member_registered",
|
||||
error = e.msg
|
||||
continue
|
||||
except JsonKindError as e:
|
||||
warn "waitForChainCommit: unexpected JSON shape",
|
||||
error = e.msg
|
||||
continue
|
||||
return err("confirmation timeout")
|
||||
|
||||
@ -364,9 +366,7 @@ proc setupProtocols(
|
||||
configAccountId: string, identityCommitment: seq[byte]
|
||||
): Future[Result[rln_gifter_protocol.MembershipStatusResponse, string]]
|
||||
{.async, gcsafe.} =
|
||||
var idHex = newStringOfCap(identityCommitment.len * 2)
|
||||
for b in identityCommitment:
|
||||
idHex.add(toHex(int(b), 2))
|
||||
let idHex = mix_lez_client.bytesToHexUpper(identityCommitment)
|
||||
let params =
|
||||
"{\"configAccountId\":\"" & configAccountId &
|
||||
"\",\"idCommitment\":\"" & idHex & "\"}"
|
||||
@ -735,12 +735,19 @@ proc startNode*(
|
||||
let deadline = Moment.now() +
|
||||
chronos.milliseconds(selfDeadlineMs)
|
||||
while Moment.now() < deadline:
|
||||
await sleepAsync(chronos.milliseconds(selfPollMs))
|
||||
try:
|
||||
await sleepAsync(chronos.milliseconds(selfPollMs))
|
||||
except CancelledError:
|
||||
return
|
||||
let qr =
|
||||
try:
|
||||
await gifter.statusHandler(
|
||||
watcherConfigAccount, watcherIdc)
|
||||
except CatchableError:
|
||||
except CancelledError:
|
||||
return
|
||||
except CatchableError as e:
|
||||
debug "Gifter self-reg watcher: statusHandler raised",
|
||||
error = e.msg
|
||||
continue
|
||||
if qr.isErr: continue
|
||||
let resp = qr.get()
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
import chronos, chronicles, std/options
|
||||
import
|
||||
../waku_core,
|
||||
../waku_core/topics/sharding,
|
||||
../waku_filter_v2/common,
|
||||
./peer_manager,
|
||||
../waku_filter_v2/client,
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
## The C++ delivery module registers an RLN fetcher at startup; event-push
|
||||
## caching avoids round-trips on the hot path.
|
||||
|
||||
import std/[json, strutils, locks, algorithm, options]
|
||||
import std/[json, strutils, locks, options]
|
||||
import chronos, chronos/threadsync
|
||||
import results
|
||||
import chronicles
|
||||
@ -285,6 +285,14 @@ proc callRlnFetcherAsync*(methodName: string, params: string): Future[Result[str
|
||||
return err("RLN fetcher returned empty response")
|
||||
return ok(fetchRes.json)
|
||||
|
||||
proc bytesToHexUpper*(bytes: openArray[byte]): string =
|
||||
## Uppercase hex without "0x" prefix. LEZ JSON RPC accepts both cases;
|
||||
## uppercase matches the existing register_member / is_member_registered
|
||||
## payload format.
|
||||
result = newStringOfCap(bytes.len * 2)
|
||||
for b in bytes:
|
||||
result.add(toHex(int(b), 2))
|
||||
|
||||
proc hexToBytes32(hex: string): Result[array[32, byte], string] =
|
||||
var h = hex
|
||||
if h.startsWith("0x") or h.startsWith("0X"):
|
||||
@ -299,16 +307,6 @@ proc hexToBytes32(hex: string): Result[array[32, byte], string] =
|
||||
return err("Invalid hex at position " & $i)
|
||||
ok(output)
|
||||
|
||||
proc hexToBytes32LE(hex: string): Result[array[32, byte], string] =
|
||||
## Parse hex string to bytes in little-endian order (for zerokit field elements).
|
||||
## LEZ/Ethereum return big-endian hex; zerokit expects LE internally.
|
||||
var res = hexToBytes32(hex).valueOr:
|
||||
return err(error)
|
||||
var reversed: array[32, byte]
|
||||
for i in 0 ..< 32:
|
||||
reversed[i] = res[31 - i]
|
||||
ok(reversed)
|
||||
|
||||
proc parseRootsJson*(snapshot: string): Result[seq[MerkleNode], string] =
|
||||
if snapshot.len == 0:
|
||||
return err("No roots data")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import chronicles, std/[options, sequtils], chronos, results, metrics
|
||||
import chronicles, std/options, chronos, results, metrics
|
||||
|
||||
import
|
||||
libp2p/crypto/curve25519,
|
||||
@ -19,7 +19,6 @@ import
|
||||
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,
|
||||
mix_rln_spam_protection,
|
||||
logos_delivery/waku/waku_relay,
|
||||
logos_delivery/waku/common/nimchronos
|
||||
|
||||
@ -1213,7 +1213,4 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
|
||||
of WakuMode.noMode:
|
||||
discard # use explicit CLI flags as-is
|
||||
|
||||
b.kademliaDiscoveryConf.withEnabled(n.enableKadDiscovery)
|
||||
b.kademliaDiscoveryConf.withBootstrapNodes(n.kadBootstrapNodes)
|
||||
|
||||
return b.build()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user