Walkthrough: Build and Deploy Index Level Worker Node

How to build a node that predicts the future price of Ether

Prerequisite

  1. Make sure you have checked the documentation on Deploying a worker Node.
  2. Clone the index provider repository once it is open sourced. It will serve as the base sample for your quick setup.

We will be working from the repository you just cloned. We will explain each part of the source code and make changes for your custom setup as required.

Setting up your Custom Index Node network

  1. As explained in the previous guide, any worker node is a peer in the Allora Network, and each peer needs to be identified. Hence, you must generate an identity for your node by running this command, which will automatically create the necessary keys and IDs in necessary folders.

  2. Unlike the Eth Prediction Walkthrough, this type of worker node does not need a Docker compose because there is only one service this works with, which is the Worker Service. There is no inference service here because the worker service requests inference from an external server managed independently of the worker node. You can see the request example in the main.py file once it is open-sourced, where most of your changes should happen.

    1. The worker service combines the allora-inference-base, the node function, and the custom main.py Python logic. The Allora chain makes requests to the head node, which will broadcast requests to the workers, which will then download the function from IPFS and then run the function to be able to call the main.py, which contains a request to the external service endpoint that channels request to your model server.
    2. The worker service is built on a Dockerfile, which extends the functionalities of the allora-inference-baseimage.
    3. The BOOT_NODES variable is the address to the head node; it states the head node peerId so that the worker node would know the particular head node request that it needs to listen to; that way, when the head node publishes a request, the node will attend to it.
  3. If the changes to main.py are made correctly, then you can run docker build -t image-name . and docker run -d -v ./:/data --name container-name image-name Your worker node should be running and listening for topics created by the appropriate head node and should respond accordingly based on the logic of the inference service and the data from the model.

  4. You can verify that your services are up by running docker-compose ps and running the test curl request in the previous guide with your appropriate arguments.

Issue an Execution Request

After the node is running locally, it may be queried. Using cURL, issue the following HTTP request to the head node.
Check the topicId to make sure to choose a topic id of an Upshot NFT Index (here it is 2 as an example).

curl --location 'http://u:pw@head-address:head-port/api/v1/functions/execute' --header 'Accept: application/json, text/plain, */*' --header 'Content-Type: application/json;charset=UTF-8' --data '{
    "function_id": "bafybeigpiwl3o73zvvl6dxdqu7zqcub5mhg65jiky2xqb4rdhfmikswzqm",
    "method": "allora-inference-function.wasm",
    "parameters": null,
    "topic": "2",
    "config": {
        "env_vars": [
            {                              
                "name": "BLS_REQUEST_PATH",
                "value": "/api"
            },
            {                              
                "name": "ALLORA_ARG_PARAMS",
                "value": "ETH"
            }
        ],
        "number_of_nodes": -1,
        "timeout" : 2
    }
}' | jq

The result will look like this:

{
    "code": "200",
    "request_id": "ef48fee9-d2da-43a4-84c4-936c5e8272e7",
    "results": [
        {
            "result": {
                "stdout": "{'value':'2400000000000000000000'}\n\n",
                "stderr": "",
                "exit_code": 0
            },
            "peers": [
                "12D3KooWAwcMzyxtHLw9ZzKqJvLoZdvYV2JQBs2sQ9opReQmUu6S"
            ],
            "frequency": 100
        }
    ],
    "cluster": {
        "peers": [
            "12D3KooWAwcMzyxtHLw9ZzKqJvLoZdvYV2JQBs2sQ9opReQmUu6S"
        ]
    }
}

Deploying your Custom Prediction Node

To get your node deployed to a remote production environment, you can deploy however you prefer or follow our Kubernetes deployment guide where you basically:

  1. Add the universal-helm chart to helm repo
  2. Update the values.yaml file to suit your case
  3. Install the universal helm chart and it will automatically deploy the node to production with the provided values
  4. Monitor your node in your Kubernetes cluster