How To Host An ElectrumX (Garlium) Node

From Garlicoin Wiki
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
  • 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.

Update the Server

  • Install the latest security updates

sudo apt update

sudo apt upgrade

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 vim /etc/hostname

  • Reboot the server

sudo reboot -n

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-essentials 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.

vim ~/.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/garlicoin-project/electrumx.git

  • Create the directory for the Electrumx_db

mkdir ~/electrumx_db

Patch the Server

  • Update coins.py

vim electrumx/electrumx/lib/coins.py

Coins.py includes the default information about the blockchain, as well as the default peers to reach. Update the Garlicoin class with the following.

NAME = "Garlicoin"
SHORTNAME = "GRLC"
NET = "mainnet"
XPUB_VERBYTES = bytes.fromhex("0488b21e")
XPRV_VERBYTES = bytes.fromhex("0488ade4")
P2PKH_VERBYTE = bytes.fromhex("26")
P2SH_VERBYTES = [bytes.fromhex("32"), bytes.fromhex("05")]
WIF_BYTE = bytes.fromhex("b0")
GENESIS_HASH = ('2ada80bf415a89358d697569c96eb98c'
'dbf4c3b8878ac5722c01284492e27228')
DESERIALIZER = lib_tx.DeserializerSegWit
TX_COUNT = 1031869
TX_COUNT_HEIGHT = 2343659
TX_PER_BLOCK = 2
RPC_PORT = 42068
REORG_LIMIT = 800
  • Optionally add the following peers to the end of the stanza. You can do a pull request to the github repository to request your server be added, but please only do this if you intend to keep it running long-term.
......
TX_COUNT_HEIGHT = 2343659
TX_PER_BLOCK = 2
RPC_PORT = 42068
REORG_LIMIT = 800
PEERS = [
        '192.34.61.215 s t',
        'garlic-us.0dayssey.com s t',
        'garlic-ca.0dayssey.com s t',
        'garlic-sg.0dayssey.com s t',
        'garlium.rshaw.space s t'
    ]
  • Save & exit coins.py

Optional Patch

  • The following is an optional patch that may help some users. If your server gets stuck, implement this path and re-run setup.py as shown later in the guide.
  • Patch Details
  • Change line 104 -> cache_room = max(self.min_cache_size // self.ave_size, 1)
  • Change line 106 -> count = min(500, count)

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 sudo python3 ~/electrumx/setup.py install

  • Exit the service user

sudo deluser garlicoin sudo

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://<user>:<password>@127.0.0.1:42068

#COIN AND SERVER
COIN = Garlicoin
HOST=0.0.0.0
TCP_PORT = 50001
SSL_PORT = 50002

#CERTS
#These will be made later
SSL_KEYFILE = /home/garlicoin/server.key
SSL_CERTFILE = /home/garlicoin/server.crt


#VISIBILITY
DONATION_ADDRESS = GcRZgg1EnLPimgLc8Fr4YrCLRDxJZb99aN
REPORT_HOST = eu.garlico.in
REPORT_TCP_PORT =  50001
REPORT_SSL_PORT =  50002
BANNER_FILE=/home/garlicoin/.electrumx/banner

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

#this allows larger wallets to sync and can be reduced
MAX_SEND = 10000000
PEER_DISCOVERY = on
PEER_ANNOUNCE = on
SERVICES = tcp://:50001,ssl://:50002
REPORT_SERVICES = tcp://eu.garlico.in:50001,ssl://eu.garlico.in:50002

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

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

Configure the Service

  • Create a systemd service as the user with sudo privileges

sudo vim /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/setup.py install