Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: publish messages without being subscribed #1207

Open
richard-ramos opened this issue Aug 23, 2024 · 5 comments
Open

bug: publish messages without being subscribed #1207

richard-ramos opened this issue Aug 23, 2024 · 5 comments

Comments

@richard-ramos
Copy link
Member

As described in status-im/status-go#5759 (comment) by @igor-sirotin
The code as it is right now would allow publishing a message while not being subscribed to a pubsub topic.

I suggest either checking if a subscription to the pubsub topic before publishing and return an error or maybe attempt to subscribe with this code. I kinda prefer to return an error instead since then the user of the library can choose to subscribe or not depending on the error (and also because publishing without being subscribed does look like an incorrect usage of gowaku)

//Check if gossipsub subscription already exists for pubSubTopic
		if !w.IsSubscribed(pubSubTopic) {
			_, err := w.subscribeToPubsubTopic(cFilter.PubsubTopic)
			if err != nil {
				//TODO: Handle partial errors.
				w.log.Error("failed to subscribe to pubsubTopic", zap.Error(err), zap.String("pubsubTopic", cFilter.PubsubTopic))
				return nil, err
			}
		}
@richard-ramos richard-ramos changed the title bug: bug: publish messages without being subscribed Aug 27, 2024
@kaichaosun
Copy link
Contributor

I found this piece of code which check similar logic, wondering why is it not working in this case?
https://github.com/waku-org/go-waku/blob/master/waku/v2/protocol/relay/waku_relay.go#L285

@igor-sirotin
Copy link
Collaborator

wondering why is it not working in this case?

I think it works 🙂 Check the logs I attached in status-im/status-go#5759 (comment) - could not send message: not enough peers to publish.

The question is, should we maybe auto-subscribe to topic in such case.

@kaichaosun
Copy link
Contributor

should we maybe auto-subscribe to topic in such case.

It seems we need a wrapper API for auto subscribe. what do you think? @richard-ramos

@chaitanyaprem
Copy link
Collaborator

should we maybe auto-subscribe to topic in such case.

It seems we need a wrapper API for auto subscribe. what do you think? @richard-ramos

it may not be so straight-forward, because when you subscribe to a pubsubtopic doesn't mean you have peers connected wrt topic. So, doing it as part of publish may not solve the issue rather mislead further.

either we subscribe and wait to have atleast 1 peer for topic(which itself is not gauranteed msg will be reliably propagated).
or return an error so that caller can subscribe to topic and wait for it to be healthy before publishing.
wondering if we ca use topic-health to decide whether to publish or not rather than min-peers. wdyt @richard-ramos

@richard-ramos
Copy link
Member Author

I agree with Prem's observations about creating a wrapper not being straightforward. Subscribing to the principle of least surprise, i'd rather have the publish function return an error and handle it appropriately.

wondering if we ca use topic-health to decide whether to publish or not rather than min-peers

IMO yes. Using topic health is a pending topic we have for go-waku / status-go integration, so perhaps this is a good moment to work on this task!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

4 participants