From 687d7b89c107b66743f63bb5fb461bca9b74c6b8 Mon Sep 17 00:00:00 2001 From: PatMulligan <43773168+PatMulligan@users.noreply.github.com> Date: Wed, 10 Sep 2025 15:35:25 +0200 Subject: [PATCH] Fix REQ message handling to support multiple filter subscriptions (#34) This fix addresses an issue where REQ messages with multiple filters were being rejected by the relay. Notably: The nostrmarket extension's "Refresh from Nostr" functionality sends a single REQ message containing 4 different filter subscriptions: - Direct Messages (kinds: [4]) - Stalls (kinds: [30017]) - Products (kinds: [30018]) - Profile (kinds: [0]) Changes: - Changed validation from `len(data) != 3` to `len(data) < 3` to allow multiple filters - Added loop to process all filters in a single REQ message (data[2:]) - Accumulate responses from all filters before returning This ensures compatibility with clients that batch multiple subscription filters in a single REQ message, which is a valid pattern according to NIP-01. --- relay/client_connection.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/relay/client_connection.py b/relay/client_connection.py index 46c2c73..dbe459e 100644 --- a/relay/client_connection.py +++ b/relay/client_connection.py @@ -115,9 +115,15 @@ class NostrClientConnection: await self._handle_event(event) return [] if message_type == NostrEventType.REQ: - if len(data) != 3: + if len(data) < 3: return [] - return await self._handle_request(data[1], NostrFilter.parse_obj(data[2])) + subscription_id = data[1] + # Handle multiple filters in REQ message + responses = [] + for filter_data in data[2:]: + response = await self._handle_request(subscription_id, NostrFilter.parse_obj(filter_data)) + responses.extend(response) + return responses if message_type == NostrEventType.CLOSE: self._handle_close(data[1]) if message_type == NostrEventType.AUTH: