refactor(pubsub): do not raise exceptions on publish (#1244)

This commit is contained in:
richΛrd 2025-02-06 21:30:21 -04:00 committed by GitHub
parent a4f0a638e7
commit 78a4344054
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 7 additions and 7 deletions

View File

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

View File

@ -705,7 +705,7 @@ method onTopicSubscription*(g: GossipSub, topic: string, subscribed: bool) =
method publish*( method publish*(
g: GossipSub, topic: string, data: seq[byte] g: GossipSub, topic: string, data: seq[byte]
): Future[int] {.async: (raises: [LPError]).} = ): Future[int] {.async: (raises: []).} =
logScope: logScope:
topic topic

View File

@ -555,7 +555,7 @@ proc subscribe*(p: PubSub, topic: string, handler: TopicHandler) {.public.} =
method publish*( method publish*(
p: PubSub, topic: string, data: seq[byte] p: PubSub, topic: string, data: seq[byte]
): Future[int] {.base, async: (raises: [LPError]), public.} = ): Future[int] {.base, async: (raises: []), public.} =
## publish to a ``topic`` ## publish to a ``topic``
## ##
## The return value is the number of neighbours that we attempted to send the ## The return value is the number of neighbours that we attempted to send the

View File

@ -65,7 +65,10 @@ proc init*(
topic: string, topic: string,
seqno: Option[uint64], seqno: Option[uint64],
sign: bool = true, 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) var msg = Message(data: data, topic: topic)
# order matters, we want to include seqno in the signature # order matters, we want to include seqno in the signature
@ -81,9 +84,6 @@ proc init*(
.expect("Invalid private key!") .expect("Invalid private key!")
.getBytes() .getBytes()
.expect("Couldn't get public key bytes!") .expect("Couldn't get public key bytes!")
else:
if sign:
raise (ref LPError)(msg: "Cannot sign message without peer info")
msg msg