From d127825a7073ea600a831444a00b43a6f4989879 Mon Sep 17 00:00:00 2001 From: dsc Date: Tue, 22 Dec 2020 20:53:47 +0100 Subject: [PATCH] Correctly propogate websocket changes and modify RPC check to invalidate nodes by most common blockheight value --- fapi/tasks/__init__.py | 4 +--- fapi/tasks/rpc_nodes.py | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/fapi/tasks/__init__.py b/fapi/tasks/__init__.py index ef76b14..18dab97 100644 --- a/fapi/tasks/__init__.py +++ b/fapi/tasks/__init__.py @@ -97,9 +97,7 @@ class FeatherTask: for queue in connected_websockets: await queue.put({ "cmd": self._websocket_cmd, - "data": { - self._websocket_cmd: result - } + "data": result }) # optional: cache the result diff --git a/fapi/tasks/rpc_nodes.py b/fapi/tasks/rpc_nodes.py index e6453ed..8eb45e6 100644 --- a/fapi/tasks/rpc_nodes.py +++ b/fapi/tasks/rpc_nodes.py @@ -58,23 +58,19 @@ class RPCNodeCheckTask(FeatherTask): continue # Filter out nodes affected by < v0.17.1.3 sybil attack - data = list(map(lambda node: node if node['target_height'] <= node['height'] - else self._bad_node(**node), data)) + data = list(map(lambda _node: _node if _node['target_height'] <= _node['height'] + else self._bad_node(**_node), data)) allowed_offset = 3 valid_heights = [] - current_blockheight = heights.get(network_type_coin, 0) - - if isinstance(current_blockheight, int) and current_blockheight > 0: - # blockheight from cache has precedence - valid_heights = range(current_blockheight, current_blockheight - allowed_offset, -1) - else: - # popularity contest - common_height = popularity_contest([z['height'] for z in data]) - valid_heights = range(common_height, common_height - allowed_offset, -1) - - data = list(map(lambda node: node if node['height'] in valid_heights - else self._bad_node(**node), data)) + # current_blockheight = heights.get(network_type_coin, 0) + + # popularity contest + common_height = popularity_contest([z['height'] for z in data]) + valid_heights = range(common_height, common_height - allowed_offset, -1) + + data = list(map(lambda _node: _node if _node['height'] in valid_heights + else self._bad_node(**_node), data)) nodes += data return nodes