DEV Community

Luis Ángel Méndez Gort
Luis Ángel Méndez Gort

Posted on

Running an Algorand node in Fly.io

decentralized network

Step by step guide

We need a directory with the following structure and contents:

algo_node
   + fly.toml
   + run.sh
Enter fullscreen mode Exit fullscreen mode

The file fly.toml looks the following way

app = 'algorand-node'
primary_region = 'cdg'

[experimental]
  cmd = ['/bin/bash', '/run.sh']

[build]
  image = 'algorand/algod:latest'

[[mounts]]
  source = 'node_vol'
  destination = '/algod/data'
  auto_extend_size_threshold = 80
  auto_extend_size_increment = '1GB'
  auto_extend_size_limit = '500GB'

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = 'off'
  auto_start_machines = true
  min_machines_running = 1
  processes = ['app']

[[files]]
  guest_path = '/run.sh'
  local_path = 'run.sh'

[[vm]]
  size = 'performance-8x'
  memory = '16gb'
  cpu_kind = 'performance'
  cpus = 8
Enter fullscreen mode Exit fullscreen mode

The above configuration relies on the run.sh script, which has this content

cp /node/run/genesis/mainnet/genesis.json /algod/data
/node/bin/algod -l 127.0.0.1:8080
Enter fullscreen mode Exit fullscreen mode

Now is time to launch our application with the command

fly launch
Enter fullscreen mode Exit fullscreen mode

Now you can answer Yes to the following question:

An existing fly.toml file was found for app algorand-node
? Would you like to copy its configuration to the new app?
Enter fullscreen mode Exit fullscreen mode

and No to the following

? Do you want to tweak these settings before proceeding? (y/N) 
Enter fullscreen mode Exit fullscreen mode

You should see an output like:

✓ Configuration is valid
==> Building image
Searching for image 'algorand/algod:latest' remotely...
image found: img_8y6w4zd58kx7v7rn

Watch your deployment at https://fly.io/apps/algorand-node/monitoring

Provisioning ips for algorand-node
  Dedicated ipv6: 2a09:8280:1::4a:fa1b:0
  Shared ipv4: 66.241.124.189
  Add a dedicated ipv4 with: fly ips allocate-v4

Creating a 1 GB volume named 'node_vol' for process group 'app'. Use 'fly vol extend' to increase its size
Enter fullscreen mode Exit fullscreen mode

To check if everything went well open a shell to the deployment with

fly ssh console
Enter fullscreen mode Exit fullscreen mode

Once there execute

/node/bin/goal node status -w 1000
Enter fullscreen mode Exit fullscreen mode

This will show you an output like

Last committed block: 25644
Time since last block: 0.0s
Sync Time: 126.7s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/5615adc36bad610c7f165fa2967f4ecfa75125f0
Round for next consensus protocol: 25645
Next consensus protocol supported: true
Last Catchpoint: 
Genesis ID: mainnet-v1.0
Genesis hash: wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=
Enter fullscreen mode Exit fullscreen mode

This shows the node is up and synchronizing with the network

If you don't want to continue running the node, execute

fly app destroy algorand-node
Enter fullscreen mode Exit fullscreen mode

The node synchronization progress can be tracked by comparing Last committed block: 25644 with the last block at Pera Explorer. Calculating 25644 / 43466969 we can see the synchronization progress so far is 0.05%.

Explanation

  • The run.sh script is needed because we need the genesis.json file in /algod/data. Once the node is running it will create there other files important for its operation, including blockchain data.

  • Since /algod/data contains blockchain data we need a volume, i.e. permanent and potentially large storage. The volume is specified above in the [[mounts]] section in fly.toml.

  • The beefy machine we have specified under [[vm]] makes possible to synchronize faster with the network. So far I've running my node for 4 days and it has checked 38423066/43466716 blocks, which is around the 88%. The accumulated cost is $35.

  • The settings auto_stop_machines = 'off' and min_machines_running = 1 are needed because Fly.io will try to stop the machine if there's no incoming traffic to the configured HTTP port.

Top comments (0)