How To Host An ElectrumX (Garlium) Node

From Garlicoin Wiki
Revision as of 13:32, 2 July 2023 by Studio271 (talk | contribs) (added hard drive requirements)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Host an ElectrumX node on a Ubuntu 20.04 VPS

Pre-requisites

System Requirements

  • 1 vCPU core
  • 2 GB of memory
  • 25 GB hard drive space minimum (recommended at least 35 GB to allow for future expansion)
  • Port 50002 open

Prepare your server by setting up and syncing a full Garlicoin Core node.

You can use the bootstrap file to speed up this process.

Prepare the Server

Your Garlicoin node must be running and synced for ElectrumX to properly bind to it. It is also assumed you have two users, one with sudo privileges, and one without to run the services.

Setup Python <= 3.9

  • Some functions have been deprecated since Python 3.10, so an older verion should be used. These steps will break some things on Ubuntu-22.04-Desktop. They haven't yet been tested on Ubuntu-Server.

Check if you have a lower version than 3.10

python3 --version

If the output is Python 3.9 or lower, you can skip the next steps.

  • Install Python 3.9

sudo apt update

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt install python3.9 -y

sudo apt install python3.9-distutils -y

  • Change the default Python version

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1

sudo update-alternatives --config python3

This should have changed the default Python version. You can check with python3 --version

Domain name

It is recommended you acquire a domain name for your server for easy sharing. This is not required, but will allow for easier sharing. This guide assumed the server will have a domain name.

  • Add your domain name

sudo nano /etc/hostname

  • Reboot the server

sudo reboot -n

Update the Server

  • Install the latest security updates

sudo apt update

sudo apt upgrade

Create Swap Space

It is recommended if you configure at least 4GB of swap space, or double the memory, whichever is greater.

sudo fallocate -l 4G /swapfile

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

  • Then make it permanent by adding the swap file to /etc/fstab

sudo vi /etc/fstab

  • Add the following to the bottom:

/swapfile swap swap defaults 0 0

Install Missing Dependencies

  • Install any dependencies that are missing if the previous guide was not used

sudo apt install python3-pip python3-aiohttp git build-essential libleveldb-dev

  • Switch to the service user

sudo su - garlicoin

pip3 install plyvel pylru

  • The dependencies installed by pip may not be in your path. You can fix this by editing ~/.bashrc as follows.

nano ~/.bashrc

  • Add the following line somewhere in the middle.

# custom path

PATH=$PATH:~/.local/bin

  • Save & exit .bashrc, then do the following

source ~/.bashrc

Installation

Prepare the Directories

  • Download ElectrumX 1.6d by cloning the git repository

git clone https://github.com/MaxPuig/electrumx.git

  • Create the directory for the Electrumx_db

mkdir ~/electrumx_db

Install with setup.py

  • setup.py requires root, so switch back to the user with sudo privileges

sudo usermod -aG sudo garlicoin

Back to the service user

sudo su - garlicoin

cd ~/electrumx

sudo python3 setup.py install

Configure electrumx.conf

  • Create and edit electrumx.conf

sudo touch /etc/electrumx.conf

  • Add the following, but changes for your server
# Used by systemd
DB_DIRECTORY = /home/garlicoin/electrumx_db

# Bitcoin Node RPC Credentials
DAEMON_URL = http://<your_rpc_user>:<your_rpc_pass>@127.0.0.1:42068

#COIN AND SERVER
COIN = Garlicoin

#CERTS
SSL_KEYFILE = /home/garlicoin/privkey.pem
SSL_CERTFILE = /home/garlicoin/fullchain.pem

#VISIBILITY
DONATION_ADDRESS = M96h8h1tBimTcRdSzDPKiEZvC8T4nozLBe
BANNER_FILE=/home/garlicoin/.electrumx/banner

#SETTINGS
#this can be changed.  start with 500-750 max
MAX_SESSIONS = 500 

#this allows larger wallets to sync and can be reduced
MAX_SEND = 10000000
PEER_DISCOVERY = on
PEER_ANNOUNCE = on
SERVICES = tcp://:50001,ssl://:50002,wss://:50004,rpc://
REPORT_SERVICES = tcp://<your_server>:50001,ssl://<your_server>:50002,wss://<your_server>:50004

#this can be changed.  750 works well for 2GB servers
CACHE_MB = 750

## If we run it as root...
#change to true for root
ALLOW_ROOT = false

#API Request limit
COST_HARD_LIMIT=0
COST_SOFT_LIMIT=0
#REQUEST_SLEEP=100

To remove the sudo priviledges

  • Exit the service user

sudo deluser garlicoin sudo

Configure the Service

  • Create a systemd service as the user with sudo privileges

sudo nano /etc/systemd/system/electrumx.service

  • Paste in the following
[Unit]
Description=Electrumx
After=network.target


[Service]
EnvironmentFile=/etc/electrumx.conf
ExecStart=/usr/local/bin/electrumx_server
User=garlicoin
LimitNOFILE=8192
TimeoutStopSec=30min
Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target
  • Reload the daemon & enable

sudo systemctl daemon-reload

sudo systemctl enable electrumx.service

Create the Certificate

Self-signed

  • As the service user, create the certificates

sudo su - garlicoin

cd ~

openssl genrsa -out server.key 2048

  • The question prompts for the following command can be skipped with enter. It is not necessary to set a password.

openssl req -new -key server.key -out server.csr

openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt

Start the Service

  • Exit to the user with sudo privileges and start the service

sudo systemctl start electrumx.service

  • Check it is running

sudo systemctl status electrumx.service

  • Check it starts syncing & look for errors

sudo journalctl -u electrumx.service -f

  • Do a final check to make sure you've removed the sudo privileges for the service user

sudo deluser garlicoin sudo

Troubleshooting

  • If you see aiorpcx issues related to TaskList, remove aiorpcx and replace with aiorpcx 0.5.6
  • As the service user, do the following

pip3 uninstall aiorpcx

pip3 install aiorpc==0.5.6

  • Then after reinstalling aiorpcx, re-run setup.py. Remember you may need to give the service account sudo privileges, or run as another user.

sudo python3 ~/electrumx/electrumx/setup.py install