From 2cac33d0d674b1c95091a8b508e095ba070c55b9 Mon Sep 17 00:00:00 2001 From: Ulrich Petri Date: Tue, 15 Sep 2020 15:50:35 +0200 Subject: [PATCH] Return PFS broadcast room id in info response This is necessary after - raiden-network/raiden-service-bundle#187 - raiden-network/raiden#6442 With those PRs the set of federation servers can become disjunct between different Raiden client versions. Therefore we can't rely on the previous check in the Raiden client if the PFS' server is in the known servers set. The RoomID is uniquely identifying a specific broadcasting room and can therefore be used as a better information source for this check. --- pyproject.toml | 14 ++++++++++++++ src/pathfinding_service/api.py | 6 +++++- src/raiden_libs/matrix.py | 12 +++++------- 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1cd8677f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.black] +line-length = 99 +target-version = ['py37'] +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.mypy_cache + | \.tox + | \.venv + | build + | dist +)/ +''' diff --git a/src/pathfinding_service/api.py b/src/pathfinding_service/api.py index 673387f1..cfb20475 100644 --- a/src/pathfinding_service/api.py +++ b/src/pathfinding_service/api.py @@ -417,6 +417,7 @@ def get(self) -> Tuple[dict, int]: "payment_address": to_checksum_address(self.pathfinding_service.address), "UTC": datetime.utcnow().isoformat(), "matrix_server": self.api.pathfinding_service.matrix_listener.base_url, + "matrix_room_id": self.api.pathfinding_service.matrix_listener.broadcast_room_id, } return info, 200 @@ -445,7 +446,10 @@ def get(self, token_network_address: str) -> Tuple[List[Dict[str, Any]], int]: class DebugPathResource(PathfinderResource): def get( # pylint: disable=no-self-use - self, token_network_address: str, source_address: str, target_address: Optional[str] = None + self, + token_network_address: str, + source_address: str, + target_address: Optional[str] = None, ) -> Tuple[dict, int]: request_count = 0 responses = [] diff --git a/src/raiden_libs/matrix.py b/src/raiden_libs/matrix.py index 80c94816..86b3d32b 100644 --- a/src/raiden_libs/matrix.py +++ b/src/raiden_libs/matrix.py @@ -41,7 +41,7 @@ from raiden.storage.serialization.serializer import MessageSerializer from raiden.utils.cli import get_matrix_servers from raiden.utils.signer import LocalSigner -from raiden.utils.typing import Address, ChainID +from raiden.utils.typing import Address, ChainID, RoomID from raiden_contracts.utils.type_aliases import PrivateKey log = structlog.get_logger(__name__) @@ -162,6 +162,7 @@ def __init__( http_retry_timeout=40, http_retry_delay=matrix_http_retry_delay, ) + self.broadcast_room_id: Optional[RoomID] = None self._broadcast_room: Optional[Room] = None self._displayname_cache = DisplayNameCache() self.base_url = self._client.api.base_url @@ -205,10 +206,7 @@ def _start_client(self) -> None: try: self.user_manager.start() - login( - self._client, - signer=LocalSigner(private_key=self.private_key), - ) + login(self._client, signer=LocalSigner(private_key=self.private_key)) except (MatrixRequestError, ValueError): raise ConnectionError("Could not login/register to matrix.") @@ -219,6 +217,7 @@ def _start_client(self) -> None: self._broadcast_room = join_broadcast_room( client=self._client, broadcast_room_alias=room_alias ) + self.broadcast_room_id = self._broadcast_room.room_id sync_filter_id = self._client.create_sync_filter(rooms=[self._broadcast_room]) self._client.set_sync_filter_id(sync_filter_id) @@ -231,8 +230,7 @@ def follow_address_presence(self, address: Address, refresh: bool = False) -> No if refresh: self.user_manager.populate_userids_for_address(address) self.user_manager.track_address_presence( - address=address, - user_ids=self.user_manager.get_userids_for_address(address), + address=address, user_ids=self.user_manager.get_userids_for_address(address) ) log.debug(