8. LAN shared node on RPi 4 (20.05.2023 UPDATE) - HaroldSP/Harold GitHub Wiki

Idena is a new blockchain and cool community with proof-of-person technology, more about you can read here.

The basic idea of this article is to show how to make a LAN-shared node on Raspberry Pi 4. It would be an easy guide and advanced users will not find here anything new.

1. Burning the image (Ubuntu 22.04.2 LTS for Raspberry Pi)

It's not a big deal and there are a lot of tutorials on how to do that. The official image and all the info one can find on the official Canonical web page. Ubuntu 21.10, server, 64-bit.

Micro SD card 256 GB, Samsung. Later on, I will provide some similar tutorials where the author is using M.2 SSD disk due to the better performance and less harmful operation mode, but after checking the prices I have decided that I will only use my 256 GB card because I need it only on the validation and the rest of the time it will be off.

27.03.2023 UPDATE:

Now I decided to try to use it for mining as well, let's see what will happen.

2. Wi-Fi connection issues

27.03.2023 UPDATE:

DOUBLE CHECK that you have an appropriate (good) cable and adaptor for powering your Pi! In my case, Pi was not loading because of the bad cable. And it would be a good idea to set a static IP address. But I will leave below what I wrote last year:

For some unknown reason for me, there is some pain in connecting to wi-fi. This is that usually you just edit the network-config file on the system-boot partition (from Windows), put your credentials, and, voila, you are connected to wi-fi and can easily SSH into Raspberry. But this time it was different. I will leave links at the end of this section for those who are interested in more details, but that's what you should do:

2.1. Comment all code in that file except for the wi-fi section:

version: 2
wifis:
  wlan0:
    dhcp4: true
    optional: true
    access-points:
      "your-wifi-name":
        password: "your-password"

That actually differs from the official website. Strictly spaces, no tabs, indentation matters.

2.2. Append this to the end of 'user-data':

##Reboot after cloud-init completes
power_state:
  mode: reboot

2.3. Link to the thread

2.4. It's really amazing how this problem appears again and again in different shapes. This time [06.01.2024] it was solved thanks to this article.

3. Code

I will not go through the details, I will just leave some links to similar articles. The basic principle is that you need to prepare the environment and install a regular node, afterward make a shared node but the LAN one. Making a globally accessible shared node is a little bit more sophisticated and out of this article, though you can find some useful info in the provided links.

sudo apt update && sudo apt upgrade -y
sudo reboot now

#getting your pi ip
sudo apt install net-tools
ifconfig

# We are installing tmux to be able to keep certain programs running even when PuTTY is closed, give this time to install
sudo apt-get install tmux

# golang is needed for us to use the Idena node, give this time to load. 
# If you are having issues with this command - make sure you have the newest Ubuntu OS. See the software requirements above.
wget https://golang.org/dl/go1.17.2.linux-arm64.tar.gz
sudo tar -C /usr/local -xzf go1.17.2.linux-arm64.tar.gz
rm go1.17.2.linux-arm64.tar.gz

# setup path for go
echo "PATH=$PATH:/usr/local/go/binGOPATH=$HOME/go" >> ~/.profile
source ~/.profile

# install go c compiler
sudo apt install gcc -y

# checking if go and c is installed
go version
gcc -v

# setup 1GB of swap
sudo fallocate -l 1G /swapfile2 && sudo chmod 600 /swapfile2 && sudo mkswap /swapfile2 && sudo swapon /swapfile2 && echo "/swapfile2 none swap sw 0 0" | sudo tee -a /etc/fstab

# 12.06.2023 update: downloading the v1.0.4 node. 
# The link you can find here https://github.com/idena-network/idena-go/releases/download/v1.0.4/idena-node-linux-aarch64-1.0.4.tar.gz.
# later on when updating, simply repeat these steps starting from here and before enabling port
# don't forget to manually change the version you need
# you can check whether you got or not an updated version by starting idena, not in a screen mode

node_version="1.1.0" 
# node_version="1.0.4" 

# download idena node source code and compile it
# wget https://github.com/idena-network/idena-go/releases/download/v$node_version/idena-node-linux-aarch64-$node_version.tar.gz
wget https://github.com/idena-network/idena-go/archive/refs/tags/v$node_version.tar.gz
# tar -xf idena-node-linux-aarch64-$node_version.tar.gz
tar -xf v$node_version.tar.gz                                                                                                                
cd idena-go-$node_version                                                                  
go build -ldflags "-X main.version=$node_version"
mv idena-go ..
cd ..
rm -r idena-go-$node_version v$node_version.tar.gz

# ensure you have enabled 9009 port in the firewall: 
sudo ufw allow 9009

# making a shared node configuration file
# type it manually via nano or vim or do it with just one command. It's not very necessary. 
bash -c 'echo "{\"IpfsConf\":{\"Profile\": \"server\" ,\"FlipPinThreshold\":1},\"Sync\": {\"LoadAllFlips\": true}}" > config.json'

# starting idena node with an apikey flag (you can set whatever you want) 
# a shared node flag is unnecessary for a LAN shared node, but it is better to use it I guess.
screen -dmS idena ./idena-go --rpcaddr=0.0.0.0 --apikey=123 config=config.json --profile=shared
# screen -dmS idena ./idena-go --rpcaddr=0.0.0.0 --apikey=123 config=config.json

And that's it for the RPi part.

4. Make a tunnel or connect in the idena app. Laptop part

Via PC App

Now you can go to your idena app on a PC, go to settings 🠊 Node, and enter shared node URL http://192.168.x.x:9009 (http://192.168.x.x:9009 is an example) and an API key, that you used in the flag. And it should work. You will see a new crypto identity in the app, you need to copy your node key (which is somewhere in C:\Users\user\AppData\Roaming\Idena\node\datadir\keystore and paste it (overwriting) the one that is in ~/datadir/keystore folder. If youu need that node key - save it before overwriting it. Usually, you don't need it. Use nano or vim.

Via Web App

Or if you want to use it via the web browser you need to make a shh tunnel to your localhost. You need Putty installed. Check path. Simply make the .bat file with the following contents:

@echo off
start "Putty" "C:\Program Files\PuTTY\putty.exe" -ssh -L 9009:localhost:9009 ubuntu@YOURRPIIP 22 -pw your-rpi-user-password-without-quotes

5. Verification (Via Web App) and extra links

Now you can go to the web-idena page, log in using your crypto identity's private key and your password, then go settings 🠊 Node and enter shared node url http://localhost:9009 and an API key, that you used in the flag.

That's it, now it should work.

5.1. Extra links:

Step by step instructions on how to run Idena node on Raspberry Pi 4 + m.2 drive

Script for Idena node setup on 64-bit Ubuntu server

oficcial article shared-node-setup-on-vps

running-your-own-shared-node-step-by-step-tutorial

enabling-ssl-for-the-shared-node-proxy-step-by-step-tutorial

Rusian article about shared node

Riaoda's global shred node

Adding your shared node to an Idena node marketplace

how-to-connect-web-app-to-my-node-on-vps

idena-go releases

indonesian guy sets up a shared node on DO vps

This is an interesting and very in-deep article about shared node, maybe someday I will look through it more thoroughly:

Idena public shared node setup guide using your own SSL termination

5.2. Auto reboot and auto restart of the node (20.05.2023 UPDATE)

In some cases for reasons unknown Raspberry freezes, but after reboot, everything works fine. So the idea is to make a regular Pi reboot and script restart, at, let's say 7 A.M. Generally, this is not a good approach, plus you must be sure that you are not updating/installing anything in around that time (7 A.M. in my case), but since I have nothing important on Pi and I use it only for idena mining, I can give it a try. This is how it works:

  1. Setting up a regular reboot schedule with cron

You can use the crontab command to schedule tasks to run at regular intervals. To set up a reboot schedule:

Open your crontab file in an editor (sudo for the root user, without - for the current user):

sudo crontab -e

Add the following line to the file to schedule a reboot every day at 7 AM:

0 7 * * * /sbin/shutdown -r now

In this line, 0 7 * * * specifies the schedule (7 AM daily), and /sbin/shutdown -r now is the command that will be run (to reboot the system).

0 0 * * * /sbin/shutdown -r now
0 12 * * * /sbin/shutdown -r now

The first line (0 0 * * *) will reboot the system at midnight (00:00), and the second line (0 12 * * *) will reboot the system at noon (12:00).

  1. Running a command after boot with systemd

You can use systemd, the init system used in most Linux distributions, to run a command after boot.

Create a systemd service to run your command. You can do this by creating a file called /etc/systemd/system/idenastart.service with the following contents:

[Unit]
Description=My idena startup command
After=network.target

[Service]
ExecStartPre=/bin/sleep 60
ExecStart=/home/ubuntu/idena-go --rpcaddr=0.0.0.0 --apikey=123 config=config.json --profile=shared

[Install]
WantedBy=default.target

In this file, ExecStartPre=/bin/sleep 60 makes the service wait for 60 seconds before running your command, and ExecStart=/home/ubuntu/idena-go --rpcaddr=0.0.0.0 --apikey=123 config=config.json --profile=shared specifies the command to run.

Then, enable and start the service with the following commands:

sudo systemctl enable idenastart.service
sudo systemctl start idenastart.service

You can check the status of the service with:

sudo systemctl status idenastart.service

These steps should help you set up your Raspberry Pi to reboot at regular intervals and run a specific command after each boot.

Good luck with your validation!