From b96ef0e6c7e9dbf42b69d97caf84c4f708d711f9 Mon Sep 17 00:00:00 2001 From: NIC619 Date: Mon, 5 Aug 2019 18:20:04 +0800 Subject: [PATCH] Fix: `_is_subscribed_to_msg` need only subscribe to one of the topics --- libp2p/pubsub/pubsub.py | 18 +++--------------- tests/pubsub/test_pubsub.py | 8 +------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index 5402cac1..0dcee671 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -1,17 +1,7 @@ import asyncio from collections import namedtuple import time -from typing import ( - Any, - Awaitable, - Callable, - Dict, - Iterable, - List, - Tuple, - Union, - TYPE_CHECKING, -) +from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Iterable, List, Tuple, Union from lru import LRU @@ -381,9 +371,7 @@ class Pubsub: async_topic_validator_futures = [] for topic_validator in self.get_msg_validators(msg): if topic_validator.is_async: - async_topic_validator_futures.append( - topic_validator.validator(msg_forwarder, msg) - ) + async_topic_validator_futures.append(topic_validator.validator(msg_forwarder, msg)) else: sync_topic_validators.append(topic_validator.validator) @@ -448,4 +436,4 @@ class Pubsub: def _is_subscribed_to_msg(self, msg: rpc_pb2.Message) -> bool: if not self.my_topics: return False - return all([topic in self.my_topics for topic in msg.topicIDs]) + return any([topic in self.my_topics for topic in msg.topicIDs]) diff --git a/tests/pubsub/test_pubsub.py b/tests/pubsub/test_pubsub.py index d66960ae..ad9dd434 100644 --- a/tests/pubsub/test_pubsub.py +++ b/tests/pubsub/test_pubsub.py @@ -183,16 +183,10 @@ async def test_get_msg_validators(pubsubs_fsub): @pytest.mark.parametrize("num_hosts", (1,)) @pytest.mark.parametrize( - "is_topic_1_val_passed, is_topic_2_val_passed", - ( - (False, True), - (True, False), - (True, True), - ) + "is_topic_1_val_passed, is_topic_2_val_passed", ((False, True), (True, False), (True, True)) ) @pytest.mark.asyncio async def test_validate_msg(pubsubs_fsub, is_topic_1_val_passed, is_topic_2_val_passed): - def passed_sync_validator(peer_id, msg): return True