From 012bca106484e98bce6854da4681b90a6c6a8730 Mon Sep 17 00:00:00 2001 From: "Andres D. Molins" Date: Tue, 23 Jan 2024 18:33:00 +0100 Subject: [PATCH] Fix: Applied PR review fixes. --- deployment/prepare_vrf_vms.py | 19 +++++-------------- src/aleph_vrf/coordinator/vrf.py | 6 ++---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/deployment/prepare_vrf_vms.py b/deployment/prepare_vrf_vms.py index cba5f63..7acedbc 100644 --- a/deployment/prepare_vrf_vms.py +++ b/deployment/prepare_vrf_vms.py @@ -25,13 +25,8 @@ async def prepare_executor_nodes(executor_item_hash: ItemHash) -> Tuple[List[Executor], List[Executor]]: aleph_selection_policy = ExecuteOnAleph(vm_function=executor_item_hash) executors = await aleph_selection_policy.get_candidate_executors() - prepare_tasks = [] - for executor in executors: - prepare_tasks.append( - asyncio.create_task( - prepare_executor_api_request(executor.api_url) - ) - ) + prepare_tasks = [asyncio.create_task(prepare_executor_api_request(executor.api_url)) + for executor in executors] vrf_prepare_responses = await asyncio.gather( *prepare_tasks, return_exceptions=True @@ -51,13 +46,9 @@ async def prepare_executor_nodes(executor_item_hash: ItemHash) -> Tuple[List[Exe def create_unauthorized_file(unauthorized_executors: List[Executor]): source_dir = Path(__file__).parent.parent / "src" - unauthorized_nodes = [] - for unauthorized_executor in unauthorized_executors: - unauthorized_nodes.append(unauthorized_executor.node.address) - + unauthorized_nodes = [executor.node.address for executor in unauthorized_executors] unauthorized_nodes_list_path = source_dir / "aleph_vrf" / "coordinator" / "unauthorized_node_list.json" - with open(unauthorized_nodes_list_path, mode="w") as unauthorized_file: - unauthorized_file.write(json.dumps(unauthorized_nodes)) + unauthorized_nodes_list_path.write_text(json.dumps(unauthorized_nodes)) print(f"Unauthorized node list file created on {unauthorized_nodes_list_path}") @@ -69,7 +60,7 @@ async def main(args: argparse.Namespace): print("Aleph.im VRF VMs nodes prepared.") - if len(failed_nodes) > 0: + if failed_nodes: print(f"{len(failed_nodes)} preload nodes failed.") create_unauthorized_file(failed_nodes) diff --git a/src/aleph_vrf/coordinator/vrf.py b/src/aleph_vrf/coordinator/vrf.py index a9da23d..59eee63 100644 --- a/src/aleph_vrf/coordinator/vrf.py +++ b/src/aleph_vrf/coordinator/vrf.py @@ -67,15 +67,13 @@ async def prepare_executor_api_request(url: str) -> bool: async with session.get(url, timeout=120) as resp: try: resp.raise_for_status() + response = await resp.json() + return response["name"] == "vrf_generate_api" except aiohttp.ClientResponseError as error: raise ExecutorHttpError( url=url, status_code=resp.status, response_text=await resp.text() ) from error - response = await resp.json() - - return response["name"] == "vrf_generate_api" - async def _generate_vrf( aleph_client: AuthenticatedAlephClient,