Merge pull request 'rpc_nodes: add bad node reason' (#11) from tobtoht/feather-ws:bad_node_reason into master

Reviewed-on: feather/feather-ws#11
tempfix
tobtoht 3 years ago
commit 4ebf4c6ff3

@ -44,12 +44,12 @@ class RPCNodeCheckTask(FeatherTask):
data.append(blob) data.append(blob)
except Exception as ex: except Exception as ex:
app.logger.warning(f"node {node} not reachable; {ex}") app.logger.warning(f"node {node} not reachable; {ex}")
data.append(self._bad_node(**{ data.append(self._bad_node({
"address": node, "address": node,
"nettype": network_type_coin, "nettype": network_type_coin,
"type": network_type, "type": network_type,
"height": 0 "height": 0
})) }, reason="unreachable"))
# not neccesary for stagenet/testnet nodes to be validated # not neccesary for stagenet/testnet nodes to be validated
if network_type_coin != "mainnet": if network_type_coin != "mainnet":
@ -61,18 +61,18 @@ class RPCNodeCheckTask(FeatherTask):
# Filter out nodes affected by < v0.17.1.3 sybil attack # Filter out nodes affected by < v0.17.1.3 sybil attack
data = list(map(lambda _node: _node if _node['target_height'] <= _node['height'] data = list(map(lambda _node: _node if _node['target_height'] <= _node['height']
else self._bad_node(**_node), data)) else self._bad_node(_node, reason="+2_attack"), data))
allowed_offset = 3 allowed_offset = 3
valid_heights = [] valid_heights = []
# current_blockheight = heights.get(network_type_coin, 0) # current_blockheight = heights.get(network_type_coin, 0)
# popularity contest # popularity contest
common_height = popularity_contest([z['height'] for z in data]) common_height = popularity_contest([z['height'] for z in data if z['height'] != 0])
valid_heights = range(common_height + allowed_offset, common_height - allowed_offset, -1) valid_heights = range(common_height + allowed_offset, common_height - allowed_offset, -1)
data = list(map(lambda _node: _node if _node['height'] in valid_heights data = list(map(lambda _node: _node if _node['height'] in valid_heights
else self._bad_node(**_node), data)) else self._bad_node(_node, reason="out_of_sync"), data))
nodes += data nodes += data
return nodes return nodes
@ -104,12 +104,13 @@ class RPCNodeCheckTask(FeatherTask):
"type": network_type "type": network_type
} }
def _bad_node(self, **kwargs): def _bad_node(self, node: dict, reason=""):
return { return {
"address": kwargs['address'], "address": node['address'],
"height": kwargs['height'], "height": node['height'],
"target_height": 0, "target_height": 0,
"online": False, "online": False,
"nettype": kwargs['nettype'], "nettype": node['nettype'],
"type": kwargs['type'] "type": node['type'],
"reason": reason
} }

Loading…
Cancel
Save