Skip to content

Commit

Permalink
refactor(pubsub): do not raise exceptions on publish
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Feb 6, 2025
1 parent a4f0a63 commit ea57994
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/floodsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ method init*(f: FloodSub) =

method publish*(
f: FloodSub, topic: string, data: seq[byte]
): Future[int] {.async: (raises: [LPError]).} =
): Future[int] {.async: (raises: []).} =
# base returns always 0
discard await procCall PubSub(f).publish(topic, data)

Expand Down
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/gossipsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ method onTopicSubscription*(g: GossipSub, topic: string, subscribed: bool) =

method publish*(
g: GossipSub, topic: string, data: seq[byte]
): Future[int] {.async: (raises: [LPError]).} =
): Future[int] {.async: (raises: []).} =
logScope:
topic

Expand Down
2 changes: 1 addition & 1 deletion libp2p/protocols/pubsub/pubsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ proc subscribe*(p: PubSub, topic: string, handler: TopicHandler) {.public.} =

method publish*(
p: PubSub, topic: string, data: seq[byte]
): Future[int] {.base, async: (raises: [LPError]), public.} =
): Future[int] {.base, async: (raises: []), public.} =
## publish to a ``topic``
##
## The return value is the number of neighbours that we attempted to send the
Expand Down
8 changes: 4 additions & 4 deletions libp2p/protocols/pubsub/rpc/message.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ proc init*(
topic: string,
seqno: Option[uint64],
sign: bool = true,
): Message {.gcsafe, raises: [LPError].} =
): Message {.gcsafe, raises: [].} =
if sign and peer.isNone():
doAssert(false, "Cannot sign message without peer info")

var msg = Message(data: data, topic: topic)

# order matters, we want to include seqno in the signature
Expand All @@ -81,9 +84,6 @@ proc init*(
.expect("Invalid private key!")
.getBytes()
.expect("Couldn't get public key bytes!")
else:
if sign:
raise (ref LPError)(msg: "Cannot sign message without peer info")

msg

Expand Down

0 comments on commit ea57994

Please sign in to comment.