Skip to content

Commit

Permalink
Implemente VRF test endpoint (#33)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
nesitor authored Jun 20, 2024
1 parent d8e09a6 commit ccc24b2
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/aleph_vrf/coordinator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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")

Expand Down Expand Up @@ -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)

0 comments on commit ccc24b2

Please sign in to comment.