Skip to content

Commit

Permalink
fix(pubsub): revert async: raises: [] annotation for TopicHandler
Browse files Browse the repository at this point in the history
… and `ValidatorHandler`
  • Loading branch information
richard-ramos committed Jan 15, 2025
1 parent 483e1d9 commit 8b0dbdd
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 79 deletions.
6 changes: 2 additions & 4 deletions examples/tutorial_4_gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ proc oneNode(node: Node, rng: ref HmacDrbgContext) {.async.} =
# This procedure will handle one of the node of the network
node.gossip.addValidator(
["metrics"],
proc(
topic: string, message: Message
): Future[ValidationResult] {.async: (raises: []).} =
proc(topic: string, message: Message): Future[ValidationResult] {.async.} =
let decoded = MetricList.decode(message.data)
if decoded.isErr:
return ValidationResult.Reject
Expand All @@ -94,7 +92,7 @@ proc oneNode(node: Node, rng: ref HmacDrbgContext) {.async.} =
if node.hostname == "John":
node.gossip.subscribe(
"metrics",
proc(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc(topic: string, data: seq[byte]) {.async.} =
let m = MetricList.decode(data).expect("metric can be decoded")
echo m
,
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial_6_game.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ proc networking(g: Game) {.async.} =

gossip.subscribe(
"/tron/matchmaking",
proc(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc(topic: string, data: seq[byte]) {.async.} =
# If we are still looking for an opponent,
# try to match anyone broadcasting its address
if g.peerFound.finished or g.hasCandidate:
Expand Down
4 changes: 2 additions & 2 deletions libp2p/protocols/pubsub/pubsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ type
PeerMessageDecodeError* = object of CatchableError

TopicHandler* {.public.} =
proc(topic: string, data: seq[byte]): Future[void] {.gcsafe, async: (raises: []).}
proc(topic: string, data: seq[byte]): Future[void] {.gcsafe, raises: [].}

ValidatorHandler* {.public.} = proc(
topic: string, message: Message
): Future[ValidationResult] {.gcsafe, async: (raises: []).}
): Future[ValidationResult] {.gcsafe, raises: [].}

TopicPair* = tuple[topic: string, handler: TopicHandler]

Expand Down
4 changes: 2 additions & 2 deletions tests/commoninterop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ proc testPubSubDaemonPublish(

var finished = false
var times = 0
proc nativeHandler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc nativeHandler(topic: string, data: seq[byte]) {.async.} =
let smsg = string.fromBytes(data)
check smsg == pubsubData
times.inc()
Expand Down Expand Up @@ -146,7 +146,7 @@ proc testPubSubNodePublish(
result = true # don't cancel subscription

discard await daemonNode.pubsubSubscribe(testTopic, pubsubHandler)
proc nativeHandler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc nativeHandler(topic: string, data: seq[byte]) {.async.} =
discard

pubsub.subscribe(testTopic, nativeHandler)
Expand Down
24 changes: 12 additions & 12 deletions tests/pubsub/testfloodsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ suite "FloodSub":

asyncTest "FloodSub basic publish/subscribe A -> B":
var completionFut = newFuture[bool]()
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check topic == "foobar"
completionFut.complete(true)

Expand Down Expand Up @@ -77,7 +77,7 @@ suite "FloodSub":

asyncTest "FloodSub basic publish/subscribe B -> A":
var completionFut = newFuture[bool]()
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check topic == "foobar"
completionFut.complete(true)

Expand All @@ -102,7 +102,7 @@ suite "FloodSub":

asyncTest "FloodSub validation should succeed":
var handlerFut = newFuture[bool]()
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check topic == "foobar"
handlerFut.complete(true)

Expand All @@ -120,7 +120,7 @@ suite "FloodSub":
var validatorFut = newFuture[bool]()
proc validator(
topic: string, message: Message
): Future[ValidationResult] {.async: (raises: []).} =
): Future[ValidationResult] {.async.} =
check topic == "foobar"
validatorFut.complete(true)
result = ValidationResult.Accept
Expand All @@ -135,7 +135,7 @@ suite "FloodSub":
await allFuturesThrowing(nodesFut)

asyncTest "FloodSub validation should fail":
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check false # if we get here, it should fail

let
Expand All @@ -151,7 +151,7 @@ suite "FloodSub":
var validatorFut = newFuture[bool]()
proc validator(
topic: string, message: Message
): Future[ValidationResult] {.async: (raises: []).} =
): Future[ValidationResult] {.async.} =
validatorFut.complete(true)
result = ValidationResult.Reject

Expand All @@ -165,7 +165,7 @@ suite "FloodSub":

asyncTest "FloodSub validation one fails and one succeeds":
var handlerFut = newFuture[bool]()
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check topic == "foo"
handlerFut.complete(true)

Expand All @@ -183,7 +183,7 @@ suite "FloodSub":

proc validator(
topic: string, message: Message
): Future[ValidationResult] {.async: (raises: []).} =
): Future[ValidationResult] {.async.} =
if topic == "foo":
result = ValidationResult.Accept
else:
Expand All @@ -210,7 +210,7 @@ suite "FloodSub":
futs[i] = (
fut,
(
proc(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc(topic: string, data: seq[byte]) {.async.} =
check topic == "foobar"
inc counter[]
if counter[] == runs - 1:
Expand Down Expand Up @@ -257,7 +257,7 @@ suite "FloodSub":
futs[i] = (
fut,
(
proc(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc(topic: string, data: seq[byte]) {.async.} =
check topic == "foobar"
inc counter[]
if counter[] == runs - 1:
Expand Down Expand Up @@ -305,7 +305,7 @@ suite "FloodSub":

asyncTest "FloodSub message size validation":
var messageReceived = 0
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
check data.len < 50
inc(messageReceived)

Expand Down Expand Up @@ -343,7 +343,7 @@ suite "FloodSub":

asyncTest "FloodSub message size validation 2":
var messageReceived = 0
proc handler(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler(topic: string, data: seq[byte]) {.async.} =
inc(messageReceived)

let
Expand Down
10 changes: 4 additions & 6 deletions tests/pubsub/testgossipinternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ suite "GossipSub internal":
asyncTest "subscribe/unsubscribeAll":
let gossipSub = TestGossipSub.init(newStandardSwitch())

proc handler(
topic: string, data: seq[byte]
): Future[void] {.gcsafe, async: (raises: []).} =
proc handler(topic: string, data: seq[byte]): Future[void] {.gcsafe, raises: [].} =
discard

let topic = "foobar"
Expand Down Expand Up @@ -670,7 +668,7 @@ suite "GossipSub internal":
proc handler(peer: PubSubPeer, data: seq[byte]) {.async: (raises: []).} =
check false

proc handler2(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handler2(topic: string, data: seq[byte]) {.async.} =
discard

let topic = "foobar"
Expand Down Expand Up @@ -771,10 +769,10 @@ suite "GossipSub internal":

var receivedMessages = new(HashSet[seq[byte]])

proc handlerA(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handlerA(topic: string, data: seq[byte]) {.async.} =
receivedMessages[].incl(data)

proc handlerB(topic: string, data: seq[byte]) {.async: (raises: []).} =
proc handlerB(topic: string, data: seq[byte]) {.async.} =
discard

nodes[0].subscribe("foobar", handlerA)
Expand Down
Loading

0 comments on commit 8b0dbdd

Please sign in to comment.