Skip to content

Commit 5d24d41

Browse files
committed
Fixes from Ivan's review
* Change generateRlnProof error handling * Fix imports * Remove result use
1 parent 2315927 commit 5d24d41

10 files changed

Lines changed: 69 additions & 73 deletions

File tree

apps/chat2/chat2.nim

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import
4848
./config_chat2
4949

5050
import libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/pubsub
51-
import ../../logos_delivery/waku/rln
51+
import logos_delivery/waku/rln
5252

5353
const Help = """
5454
Commands: /[?|help|connect|nick|exit]
@@ -193,12 +193,7 @@ proc publish(c: Chat, line: string) =
193193
# for future version when we support more than one rln protected content topic,
194194
# we should check the message content topic as well
195195
let proofRes =
196-
try:
197-
waitFor c.node.rln.generateRLNProof(message.toRLNSignal(), float64(time))
198-
except CatchableError:
199-
Result[seq[byte], string].err(
200-
"exception generating rln proof: " & getCurrentExceptionMsg()
201-
)
196+
waitFor c.node.rln.generateRLNProof(message.toRLNSignal(), float64(time))
202197
if proofRes.isErr():
203198
info "could not append rate limit proof to the message"
204199
else:

library/liblogosdelivery.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import std/[atomics, macros], chronicles, chronos, chronos/threadsync, ffi
1+
import std/[atomics, macros]
2+
import chronicles, chronos, chronos/threadsync, ffi
23
import
34
logos_delivery/waku/waku_core/message/message,
45
logos_delivery/waku/waku_core/topics/pubsub_topic,

logos_delivery/waku/incentivization/eligibility_manager.nim

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import
2-
std/sets,
3-
chronos,
4-
web3,
5-
stew/byteutils,
6-
stint,
7-
results,
8-
chronicles,
9-
logos_delivery/waku/incentivization/rpc,
10-
tests/waku_rln_relay/utils_onchain
1+
import std/sets, chronos, web3, stew/byteutils, stint, results
2+
3+
import chronicles
4+
5+
import logos_delivery/waku/incentivization/rpc, tests/waku_rln_relay/utils_onchain
116

127
const SimpleTransferGasUsed = Quantity(21000)
138
const TxReceiptQueryTimeout = 3.seconds

logos_delivery/waku/node/subscription_manager.nim

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import
2-
std/[sequtils, sets, tables],
3-
chronos,
4-
chronicles,
5-
metrics,
6-
results,
7-
libp2p/[peerid, peerinfo]
1+
import std/[sequtils, sets, tables], chronos, chronicles, metrics, results
2+
3+
import libp2p/[peerid, peerinfo]
84
import brokers/broker_context
95

106
import

logos_delivery/waku/persistency/backend_comm.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ proc mtMarshalSizeValue*[T](value: Opt[T]): int {.gcsafe.} =
8181
# Opt[T] is generic: for a copyMem-able T the generic size pass takes the
8282
# sizeof() branch (padding included) while our marshal writes flag+payload.
8383
mixin mtMarshalSizeValue
84-
result = sizeof(uint8)
84+
var size = sizeof(uint8)
8585
if value.isSome():
86-
result += mtMarshalSizeValue(value.get())
86+
size += mtMarshalSizeValue(value.get())
87+
return size
8788

8889
proc mtMarshalValue*(
8990
buf: ptr UncheckedArray[byte], cap: int, value: TxOp, pos: var int

logos_delivery/waku/rest_api/endpoint/origin_handler.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{.push raises: [].}
22

3-
import
4-
std/[strutils, net], regex, results, chronicles, chronos, chronos/apps/http/httpserver
3+
import std/[strutils, net], regex, results
4+
import chronicles, chronos, chronos/apps/http/httpserver
55

66
type OriginHandlerMiddlewareRef* = ref object of HttpServerMiddlewareRef
77
allowedOriginMatcher: Opt[Regex2]

logos_delivery/waku/rest_api/endpoint/store/handlers.nim

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
{.push raises: [].}
22

3+
import std/options, std/[strformat, sugar], results
4+
5+
import chronicles, uri, json_serialization, presto/route
36
import
4-
std/options,
5-
std/[strformat, sugar],
6-
results,
7-
chronicles,
8-
uri,
9-
json_serialization,
10-
presto/route
11-
import
12-
../../../waku_core,
13-
../../../waku_store/common,
14-
../../../waku_store/self_req_handler,
15-
../../../waku_node,
16-
../../../node/peer_manager,
17-
../../../common/paging,
18-
../../handlers,
19-
../responses,
20-
../serdes,
21-
./types
7+
logos_delivery/waku/[
8+
waku_core,
9+
waku_store/common,
10+
waku_store/self_req_handler,
11+
waku_node,
12+
node/peer_manager,
13+
common/paging,
14+
rest_api/handlers,
15+
rest_api/endpoint/responses,
16+
rest_api/endpoint/serdes,
17+
rest_api/endpoint/store/types,
18+
]
2219

2320
export types
2421

logos_delivery/waku/rln/proof.nim

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
import std/[times, sequtils]
44
import chronos, chronicles, results, stew/byteutils
55

6-
import ./types, ./protocol_types, ./conversion_utils, ./group_manager, ./nonce_manager
7-
8-
import logos_delivery/waku/waku_core
6+
import
7+
logos_delivery/waku/[
8+
rln/types,
9+
rln/protocol_types,
10+
rln/conversion_utils,
11+
rln/group_manager,
12+
rln/nonce_manager,
13+
waku_core,
14+
]
915

1016
proc calcEpoch*(rln: Rln, t: float64): Epoch =
1117
## gets time `t` as `flaot64` with subseconds resolution in the fractional part
@@ -56,13 +62,16 @@ proc toRLNSignal*(wakumessage: WakuMessage): seq[byte] =
5662

5763
proc generateRLNProof*(
5864
rln: Rln, input: seq[byte], senderEpochTime: float64
59-
): Future[Result[seq[byte], string]] {.async.} =
65+
): Future[Result[seq[byte], string]] {.async: (raises: []).} =
6066
let epoch = rln.calcEpoch(senderEpochTime)
6167
let nonce = rln.nonceManager.getNonce().valueOr:
6268
return err("could not get new message id to generate an rln proof: " & $error)
63-
let proof = (await rln.groupManager.generateProof(input, epoch, nonce)).valueOr:
64-
return err("could not generate rln-v2 proof: " & $error)
65-
return ok(proof.encode().buffer)
69+
try:
70+
let proof = (await rln.groupManager.generateProof(input, epoch, nonce)).valueOr:
71+
return err("could not generate rln-v2 proof: " & $error)
72+
return ok(proof.encode().buffer)
73+
except CatchableError as e:
74+
return err("exception generating rln proof: " & e.msg)
6675

6776
proc generateRLNProofWithRootRefresh*(
6877
rln: Rln, input: seq[byte], senderEpochTime: float64

logos_delivery/waku/rln/rln/wrappers.nim

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import stew/[arrayops, endians2], stint, results
2+
3+
import chronicles, eth/keys
4+
15
import
2-
chronicles,
3-
eth/keys,
4-
stew/[arrayops, endians2],
5-
stint,
6-
results,
7-
./rln_interface,
8-
../conversion_utils,
9-
../protocol_types,
10-
../protocol_metrics
11-
import ../../waku_core, ../../waku_keystore
6+
logos_delivery/waku/[
7+
rln/rln/rln_interface,
8+
rln/conversion_utils,
9+
rln/protocol_types,
10+
rln/protocol_metrics,
11+
waku_core,
12+
waku_keystore,
13+
]
1214

1315
{.push raises: [], gcsafe.}
1416

logos_delivery/waku/waku_peer_exchange/client.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import results
2+
import chronicles, chronos, metrics
13
import
2-
results,
3-
chronicles,
4-
chronos,
5-
metrics,
6-
./common,
7-
./rpc,
8-
./rpc_codec,
9-
../node/peer_manager
4+
logos_delivery/waku/[
5+
waku_peer_exchange/common,
6+
waku_peer_exchange/rpc,
7+
waku_peer_exchange/rpc_codec,
8+
node/peer_manager,
9+
]
1010

11-
from ../waku_core/codecs import WakuPeerExchangeCodec
11+
from logos_delivery/waku/waku_core/codecs import WakuPeerExchangeCodec
1212

1313
declarePublicGauge waku_px_peers_received_total,
1414
"number of ENRs received via peer exchange"

0 commit comments

Comments
 (0)