mirror of https://github.com/nucypher/nucypher.git
Modify script to either run for a specific ritual or across the entire network.
parent
33588a5e48
commit
d7672f41b6
|
@ -15,8 +15,11 @@
|
|||
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
import click
|
||||
import requests
|
||||
from eth_typing import ChecksumAddress
|
||||
from nucypher_core import NodeMetadata
|
||||
from urllib3.exceptions import InsecureRequestWarning
|
||||
|
||||
|
@ -37,7 +40,8 @@ GlobalLoggerSettings.start_console_logging()
|
|||
emitter = StdoutEmitter(verbosity=2)
|
||||
|
||||
|
||||
def get_node_urls():
|
||||
def get_node_urls(participants: Optional[List[ChecksumAddress]] = None):
|
||||
participants_set = set(participants) if participants else None
|
||||
node_urls = {}
|
||||
try:
|
||||
response = requests.get(
|
||||
|
@ -47,6 +51,9 @@ def get_node_urls():
|
|||
)
|
||||
all_nodes = response.json().get("known_nodes", [])
|
||||
for node in all_nodes:
|
||||
staker_address = node["staker_address"]
|
||||
if participants_set and staker_address not in participants_set:
|
||||
continue
|
||||
node_urls[node["staker_address"]] = f"https://{node['rest_url']}"
|
||||
except Exception:
|
||||
pass
|
||||
|
@ -75,7 +82,9 @@ def get_current_ferveo_key(node_url):
|
|||
type=click.STRING,
|
||||
required=True,
|
||||
)
|
||||
@click.option("--ritual-id", help="Ritual ID", type=click.INT, required=True)
|
||||
@click.option(
|
||||
"--ritual-id", help="Ritual ID", type=click.INT, required=False, default=None
|
||||
)
|
||||
def differing_ferveo_keys(
|
||||
polygon_endpoint,
|
||||
ritual_id,
|
||||
|
@ -93,26 +102,27 @@ def differing_ferveo_keys(
|
|||
blockchain_endpoint=polygon_endpoint,
|
||||
) # type: CoordinatorAgent
|
||||
|
||||
node_urls = get_node_urls()
|
||||
participants = None # None means all nodes
|
||||
if ritual_id:
|
||||
ritual = coordinator_agent.get_ritual(ritual_id)
|
||||
participants = ritual.providers # only nodes for ritual
|
||||
|
||||
ritual = coordinator_agent.get_ritual(ritual_id)
|
||||
participants = ritual.providers
|
||||
|
||||
current_ferveo_key = None
|
||||
reported_ferveo_key = None
|
||||
for provider in participants:
|
||||
node_url = node_urls.get(provider, None)
|
||||
node_urls = get_node_urls(participants)
|
||||
ritual_id_for_public_key_check = ritual_id or coordinator_agent.number_of_rituals()
|
||||
for provider, node_url in node_urls.items():
|
||||
if not node_url:
|
||||
print(f"Unable to determine public ip for {provider}")
|
||||
continue
|
||||
else:
|
||||
current_ferveo_key = get_current_ferveo_key(node_url)
|
||||
if not current_ferveo_key:
|
||||
print(f"Unable to obtain current public key from {node_url}")
|
||||
print(
|
||||
f"Unable to obtain current public key from {node_url} for {provider}"
|
||||
)
|
||||
continue
|
||||
|
||||
reported_ferveo_key = coordinator_agent.get_provider_public_key(
|
||||
provider, ritual_id
|
||||
provider, ritual_id_for_public_key_check
|
||||
)
|
||||
|
||||
if bytes(current_ferveo_key) != bytes(reported_ferveo_key):
|
||||
|
|
Loading…
Reference in New Issue