From ccc24b2f49b9be954ae7cad5007a54a478d2438c Mon Sep 17 00:00:00 2001 From: nesitor Date: Thu, 20 Jun 2024 12:39:45 +0200 Subject: [PATCH] Implemente VRF test endpoint (#33) * Feature: Implement VRF test endpoint just using 1 node as executor. * Fix: Changed endpoint description. * Fix: Changed endpoint method name. * Fix: Changed executor address to use the same Aleph structure. * Fix: Added missing AlephExecutor fields. --- src/aleph_vrf/coordinator/main.py | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/aleph_vrf/coordinator/main.py b/src/aleph_vrf/coordinator/main.py index 43ed916..16bded8 100644 --- a/src/aleph_vrf/coordinator/main.py +++ b/src/aleph_vrf/coordinator/main.py @@ -3,6 +3,7 @@ from pydantic import BaseModel +from aleph_vrf.coordinator.executor_selection import UsePredeterminedExecutors from aleph_vrf.settings import settings logger = logging.getLogger(__name__) @@ -16,7 +17,7 @@ logger.debug("local imports") from aleph_vrf.coordinator.vrf import generate_vrf -from aleph_vrf.models import APIError, APIResponse, PublishedVRFResponse +from aleph_vrf.models import APIError, APIResponse, PublishedVRFResponse, AlephExecutor, ComputeResourceNode logger.debug("imports done") @@ -59,3 +60,36 @@ async def receive_vrf( raise HTTPException(status_code=500, detail=str(err)) return APIResponse(data=response) + + +@app.post("/test_vrf") +async def receive_test_vrf( + request: Optional[VRFRequest] = None, +) -> APIResponse[Union[PublishedVRFResponse, APIError]]: + """ + Goes through the test VRF random number generation process and returns a random number + along with details on how the number was generated, but just using 1 predefined executor. + """ + + account = settings.aleph_account() + + response: Union[PublishedVRFResponse, APIError] + + request_id = request.request_id if request and request.request_id else None + try: + executor_url = ( + "https://CRN_URL" # CRN main URL, like https://hetzner.staging.aleph.sh + ) + executor_node = ComputeResourceNode(address=executor_url, hash="", score=0) + executors = [AlephExecutor(node=executor_node, vm_function=settings.FUNCTION)] + executor_policy = UsePredeterminedExecutors(executors) + response = await generate_vrf( + account=account, + request_id=request_id, + nb_executors=1, + executor_selection_policy=executor_policy, + ) + except Exception as err: + raise HTTPException(status_code=500, detail=str(err)) + + return APIResponse(data=response)