Running an Avalanche blockchain validator on Raspberry Pi 3b!

Vijay Lakshminarayanan
6 min readNov 17, 2020

--

I participated in the encode hackathon, and was excited to learn about Avalanche. One of the challenges was to build a subnet and adding a validator. Normally a blockchain validator consumes a lot of resources, and requires a PC with say Terabytes of data or an AWS instance. Avalanche node supports lightweight clients, and I had a spare Raspberry Pi with 1 GB RAM. The following is an attempt to run a validator on Avalanche Fuji testnet on a Raspberry Pi costing less than 35$!

Requirements:

  • Rapsberry Pi 3B 1GB RAM! (minimum requirements, Pi 4 will make things easier)
  • Micro SD card 32GB
  • official Power Supply or micro usb to usb cable with a phone charger
  • Cooling, fan recommended my Pi got hotter (> 60 degC)
Raspberry Pi 3 with fan and case
  1. Install Ubuntu 20.4:

We need a 64-bit system, and Ubuntu works,
Download Ubuntu 20.04 LTS 64-bit for RasPi4
To get the image on the SD card follow this tutorial. Skip step5 in the tutorial since we do not need a desktop.

2. SSH:

We don’t need to plug keyboard and mouse so use ssh to connect to the Pi. So create a file called ssh in the boot partition. No extensions just a blank ssh file. Following this tutorial. There will be issues connecting it, and most of the mistakes are due to wrong wireless router configuration. Verify the wpa_supplicant.conf file!

After configuration, start the Pi it should boot up to the login screen for ubuntu.

→ Using Keyboard+mouse for first boot:

For the very first boot I recommend connecting a keyboard and mouse with a TV just to check the sequence. There will be an intermediate cloud-init so ignore the username/password request and wait till SSH keys are printed out and then the login prompt comes up. Enter username as ubuntu and password as ubuntu. Change password.

→ Headless at first boot:

If you are experienced, connect to the Pi from any computer in the same network with ssh ubuntu@ubuntuinitial password is ubuntu.
Secure your Pi, e.g. using keys for ssh. Update your Pi with sudo apt update and sudo apt full-upgrade.

3. Add Swap space:

Since we are quite limited in resources with a 1 GB RAM an additional swap space is necessary to run the ava node. Check out this detailed step by step article by Digital ocean here. For a 1 GB RAM the following set of commands was used, and swappiness parameter was set to around 30. You need to reboot the Pi to make the changes. Cache pressure settings were not necessary, default worked ok.

sudo fallocate -l 1G //swapfile
ls -lh //swapfile
sudo chmod 600 //swapfile
ls -lh //swapfile only rootuser has read write enabled
sudo mkswap //swapfile
sudo swapon //swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak //backup in case things go wrongecho '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabsudo sysctl vm.swappiness=30 //configure swappiness

4. Install Avalanche on Pi:

I followed the avalanche tutorial here , and adapted this article for the Fuji testnet. Let us go through the steps:

Assuming that you have finished the swaps, and started the Pi again. Its good to use screen/tmux or Gecko but I made a simpler implementation as follows:

→ install Go language

sudo apt install golang

→ Clone the avalanche github repository

go get -v -d github.com/ava-labs/avalanchego/...
cd $GOPATH/src/github.com/ava-labs/avalanchego

→ Build Avalanche using the build script:

An avalanche go executable will be built at the end of this step

./scripts/build.sh

→ Connect the node to Fuji testnet

./build/avalanchego --network-id=fuji

This will start the process of bootstrapping, and you will see warnings such as renew traversal failed, ignore it for now…

Avalanche node bootstrapping
WARN [11-17|13:55:16] /home/ubuntu/go/src/github.com/ava-labs/gecko/nat/nat.go#120: Renew NAT Traversal failed from external port 9651 to internal port 9651 with goupnp: SOAP request got HTTP 500 Internal Server Error

After bootstrapping is complete, we can proceed to the next step.

5. Get some AVAX, and fund your Platform address:

Open up a new terminal window, and start creating the user wallet, addresses etc. This is adapted from the article. Most of the links in the article were not working, so please follow the avax documentation and their API info here.

→ Create a keystore user with a username, password

→ Create an address on the X-chain:

curl -X POST --data '{
"jsonrpc":"2.0",
"id" :2,
"method" :"avm.createAddress",
"params" :{
"username": "YOUR USERNAME",
"password": "YOUR PASSWORD"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X

→ Use the Fuji testnet faucet to get some AVAX on this address

→ Transfer funds between X-chain to P-chain as shown in the Avalanche tutorial

Since there are transaction fees involved request more than 1 AVAX to enable transfer. Atleast 1 AVAX must be staked to run the validator node.

→ The important aspect is that the transfer of funds involves export and import. It maybe frustrating sometimes, so ensure that the Curls are done correctly. My curls are as follows:

curl -X POST --data '{"jsonrpc":"2.0","id"     :1,"method" :"avm.exportAVAX","params" :{"to":"P-chain address","destinationChain": "P","changeAddr":"X-chain address","amount": 1000000000,"username": "your username","password": "your password"}}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/Xcurl -X POST --data '{"jsonrpc":"2.0","id"     :1,"method" :"platform.importAVAX","params" :{"to":"your P-chain address","sourceChain":"X","username": "your username","password": "your password"}}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/P

6. Become a Validator:

Follow the steps in the Avax tutorial to make this node into a validator.

→ Find your Node ID

→ Add it along with start, end time to the network

→ Check if it’s in the list of pending validators

→ After a few minutes it should be added to the network. I checked mine here.

Delegation rate was set to default value, so in theory the node is ready to validate transactions in a very lightweight manner.

It was a relatively painless (about a few hours of work) to get this setup.

7. Subnet validator

Avalanche is a network of networks, and to make exciting usecases a subnet was created with the node acting as a validator. As defined by Avalabs:

Subnets (short for “sub-network”) are a dynamic set of validators working together to achieve consensus on the state of a set of blockchains. Subnets are required to create custom incentive mechanisms for these validators.

Follow the tutorial here to create a subnet.

→ For the keystore user created in step 5, create a second P-chain address

→ use the two addresses to create a subnet

→ Verify that the subnet was successfully created

→Use the subnet validator curl to add the Pi as a node for the subnet

//Add subnet validatorcurl -X POST --data '{"jsonrpc": "2.0","method": "platform.addSubnetValidator","params": {"nodeID":"NodeID-Lcvjg5owBa79jHdQ3gumrERrxgz4xy62B","subnetID":"29qBsEDSg73epnzf4ozPxVbH42nBTMo7Six52qKm7w7zkrEoKW","startTime":'$(date --date="10 minutes" +%s)',"endTime":'$(date --date="29 days" +%s)',"weight": 10,"changeAddr": "P-chain address","username":"your username","password":"your password"},"id": 1}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/P

This will add the node as a subnet validator. You have to ensure that the end time is less than the end time for the testnet which this node is validating otherwise the transaction will not be committed.

→ Verify if the validator was added to the node same as step 6. Check in Ava explorer.

Subnet with validator

It was exciting to get the Pi3 up and running as a node! I plan to build a lightweight use case harnessing the power of tiny yet mighty raspberry Pi.

--

--

Vijay Lakshminarayanan
Vijay Lakshminarayanan

Written by Vijay Lakshminarayanan

Founder | VCred Full stack Developer: DeFi, ML

No responses yet