nips icon indicating copy to clipboard operation
nips copied to clipboard

NIP-01 duplicate subscription

Open bezysoftware opened this issue 1 year ago • 2 comments

I think NIP-01 is inconsistent regarding how duplicate subscriptions should be handled (REQ message with the same subscriptionId). I find the wording of this paragraph (specifically the last sentence) weird:

Upon receiving a REQ message, the relay SHOULD query its internal database and return events that match the filter, then store that filter and send again all future events it receives to that same websocket until the websocket is closed. The CLOSE event is received with the same <subscription_id> or a new REQ is sent using the same <subscription_id>, in which case relay MUST overwrite the previous subscription.

But from what I was able to decode (English as a 2nd language..) when the relay receives a SUB with the same subscriptionId the new filters will overwrite the initial subscription and restart?

This is however in conflict with this example error code:

["CLOSED", "sub1", "duplicate: sub1 already opened"]

This should never be sent by the relay because duplicate subscriptions are replaced, so there should be no conflict.

What I also find odd the the "...MUST overwrite the previous subscription" was introduced in PR #731 with no additional details as to why the verb "should" changed to "MUST". Can @viktorvsk maybe comment?

bezysoftware avatar Jun 27 '24 20:06 bezysoftware

I think you're right, good catch. Just opened a PR to clarify this and remove the offending CLOSED example.

staab avatar Jun 28 '24 00:06 staab

Yes this has been wrong. I have always coded subscriptions to be replaced. Some relays bitch with "duplicate" so we have code taking both sides here. But I think duplicates should be accepted, erasing the former and restarting.

mikedilger avatar Jun 28 '24 02:06 mikedilger