Deployment Guide

This guide goes into details on how to compile and deploy Gauss Explorer instance to work with Polygon-Edge. Gauss Explorer has its own documentation, but this guide focuses on simple but detailed step-by-step instructions on how to setup Gauss Explorer instance.

  • Operating System: Ubuntu Server 20.04 LTS download link with sudo permissions

  • Server Hardware: 8CPU / 16GB RAM / 50GB HDD (LVM)

  • Database Server: Dedicated server with 2 CPU / 4GB RAM / 100GB SSD / PostgreSQL 13.4

DB Server​

The requirement for following this guide is to have a database server ready, database and db user configured. This guide will not go into details on how to deploy and configure PostgreSQL server. There are plenty of guides on now to do this, for example DigitalOcean Guide

DISCLAIMER

This guide is meant only to help you to get Gauss Explorer up and running on a single instance which is not ideal production setup. For production, you'll probably want to introduce reverse proxy, load balancer, scalability options, etc. into the architecture.

Gauss Explorer Deployment Procedure

Before we start we need to make sure we have all the binaries installed that the Gauss Explorer is dependent on.

Update & upgrade system​

sudo apt -y update && sudo apt -y upgrade

Add erlang repos​

# go to your home dir
cd ~
# download deb
wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb
# download key
wget https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc
# install repo
sudo dpkg -i erlang-solutions_2.0_all.deb
# install key
sudo apt-key add erlang_solutions.asc
# remove deb
rm erlang-solutions_2.0_all.deb
# remove key
rm erlang_solutions.asc

Add NodeJS repo​

sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

Install Rust​

sudo curl https://sh.rustup.rs -sSf | sh -s -- -y

Install required version of Erlang​

sudo apt -y install esl-erlang=1:24.*

Install required version of Elixir​

The version of Elixir must be 1.13. If we try and install this version from the official repo, the erlang will update to Erlang/OTP 25 and we do not want that. Because of this, we need to install the specific precompiled elixir version from GitHub releases page.

cd ~
mkdir /usr/local/elixir
wget https://github.com/elixir-lang/elixir/releases/download/v1.13.4/Precompiled.zip
sudo unzip -d /usr/local/elixir/ Precompiled.zip
rm Precompiled.zip

Now we need to properly set up exlixir system binaries.

sudo ln -s /usr/local/elixir/bin/elixir /usr/local/bin/elixir
sudo ln -s /usr/local/elixir/bin/mix /usr/local/bin/mix
sudo ln -s /usr/local/elixir/bin/iex /usr/local/bin/iex
sudo ln -s /usr/local/elixir/bin/elixirc /usr/local/bin/elixirc

Check if elixir and erlang are properly installed by running elixir -v. This should be the output:

Erlang/OTP 24 [erts-12.3.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.13.4 (compiled with Erlang/OTP 22)

WARNING Erlang/OTP must be version 24 and Elixir must be version 1.13.*. If that is not the case, you will run into issues with compiling Gauss Explorer and/or running it.

Install NodeJS​

sudo apt -y install nodejs

Install Cargo​

sudo apt -y install cargo

Install other dependencies​

sudo apt -y install automake libtool inotify-tools gcc libgmp-dev make g++ git

Optionally install postgresql client to check your db connection​

sudo apt install -y postgresql-client

We need to set the environment variables, before we begin with Gauss Explorer compilation. In this guide we'll set only the basic minimum to get it working. Full list of variables that can be set you can find here

Set database connection as environment variable​

# postgresql connection example:  DATABASE_URL=postgresql://gaussExplorer:[email protected]:5432/gaussExplorer
export DATABASE_URL=postgresql://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name> # db_name does not have to be existing database

# we set these env vars to test the db connection with psql
export PGPASSWORD=Passw0Rd
export PGUSER=gaussExplorer
export PGHOST=db.instance.local
export PGDATABASE=postgres # on AWS RDS postgres database is always created

Now test your DB connection with provided parameters. Since you've provided PG env vars, you should be able to connect to the database only by running:

If the database is configured correctly, you should see a psql prompt:

psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

gaussExplorer=>

Otherwise, you might see an error like this:

psql: error: FATAL:  password authentication failed for user "gaussExplorer"
FATAL:  password authentication failed for user "gaussExplorer"

If this is the case these docs might help you.

DB Connection

Make sure you've sorted out all db connection issues before proceeding to the next part. You'll need to provide superuser privileges to gaussExplorer user.

[email protected]:~$ createuser --interactive
Enter name of role to add: gaussExplorer
Shall the new role be a superuser? (y/n) y

Now we finally get to start the Gauss Explorer installation.

Clone Gauss Explorer repo​

cd ~
git clone https://github.com/Gauss-Gang/Gauss-Explorer

Generate secret key base to protect production build​

cd Gauss-Explorer
mix deps.get
mix local.rebar --force
mix phx.gen.secret

At the very last line, you should see a long string of random characters. This should be set as your SECRET_KEY_BASE environment variable, before the next step. For example:

export SECRET_KEY_BASE="912X3UlQ9p9yFEBD0JU+g27v43HLAYl38nQzJGvnQsir2pMlcGYtSeRY0sSdLkV/"

Install and start Smart Contract Verification Microservice

nstall and start smart contract verification microservice. You can use docker, build from source, or use cargo directly (example below).

  1. cargo install --git https://github.com/blockscout/blockscout-rs smart-contract-verifier-http

  2. Run the binary as smart-contract-verifier-http

  3. Set ENV variables in CLI to enable the rust microservice for Blockscout (these can also be set at runtime).

export ENABLE_RUST_VERIFICATION_SERVICE=true
export RUST_VERIFICATION_SERVICE_URL=http://0.0.0.0:8043/

Set production mode​

Compile​

Cd into clone directory and start compiling

cd Gauss-Explorer
mix local.hex --force
mix do deps.get, local.rebar --force, deps.compile, compile

info

If you have deployed previously, remove static assets from the previous build mix phx.digest.clean.

Migrate databases​

info

This part will fail if you didn't set up your DB connection properly, you didn't provide, or you've defined wrong parameters at DATABASE_URL environment variable. The database user needs to have superuser privileges.

mix do ecto.create, ecto.migrate

If you need to drop the database first, run

mix do ecto.drop, ecto.create, ecto.migrate

Install npm dependencies and compile frontend assets​

You need to change directory to the folder which contains frontend assets.

cd apps/block_scout_web/assets
sudo npm install
sudo node_modules/webpack/bin/webpack.js --mode production

Be patient

Compilation of these assets can take a few minutes, and it will display no output. It can look like the process is stuck, but just be patient. When compile process is finished, it should output something like: webpack 5.69.1 compiled with 3 warnings in 104942 ms

Build static assets​

For this step you need to return to the root of your Gauss Explorer clone folder.

cd ~/Gauss-Explorer
sudo mix phx.digest

Generate self-signed certificates​

info

You can skip this step if you won't use https.

cd apps/block_scout_web
mix phx.gen.cert gaussExplorer gaussExplorer.local

In this part we need to set up a system service as we want Gauss Explorer to run in the background and persist after system reboot.

Create service file​

sudo touch /etc/systemd/system/explorer.service

Edit service file​

Use your favorite linux text editor to edit this file and configure the service.

sudo vi /etc/systemd/system/explorer.service

The contents of the explorer.service file should look like this:

[Unit]
Description=Gauss Explorer Server
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=root
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/usr/local/Gauss-Explorer
ExecStart=/usr/local/bin/mix phx.server
EnvironmentFile=/usr/local/Gauss-Explorer/env_vars.env

[Install]
WantedBy=multi-user.target

Enable starting service on system boot​

sudo systemctl daemon-reload
sudo systemctl enable explorer.service

Move your Gauss Explorer clone folder to system-wide location​

Gauss Explorer service needs to have access to the folder you've cloned from Gauss Explorer repo and compiled all the assets.

sudo mv ~/Gauss-Explorer /usr/local

Create env vars file which will be used by Gauss Explorer service​

sudo touch /usr/local/Gauss-Explorer/env_vars.env
# use your favorite text editor
sudo vi /usr/local/Gauss-Explorer/env_vars.env

# env_vars.env file should hold these values ( adjusted for your environment )
ETHEREUM_JSONRPC_HTTP_URL="IP:PORT"
ETHEREUM_JSONRPC_TRACE_URL="IP:PORT"
ETHEREUM_JSONRPC_WS_URL="ws://IP:PORT/ws"
JSON_RPC="https://rpc.giltestnet.com"
DATABASE_URL="postgresql_database_url"
SECRET_KEY_BASE="Secret_Base_Key"
CHAIN_ID="4242"
HEART_COMMAND="systemctl restart explorer.service"
NETWORK="Testnet"
SUBNETWORK="G.I.L."
COIN="GANG"
COIN_NAME="GANG Coin"
PORT="Explorer_PORT" 
DISABLE_EXCHANGE_RATES="true"
HEART_BEAT_TIMEOUT="60"
INDEXER_MEMORY_LIMIT="16Gb"
SHOW_TESTNET_LABEL="true"
TESTNET_LABEL_TEXT="Gauss Induction Lab"
INDEXER_DISABLE_EMPTY_BLOCK_SANITIZER="true"
INDEXER_DISABLE_BLOCK_REWARD_FETCHER="true"
INDEXER_DISABLE_PENDING_TRANSACTIONS_FETCHER="true"
INDEXER_DISABLE_INTERNAL_TRANSACTIONS_FETCHER="true"
INDEXER_DISABLE_ADDRESS_COIN_BALANCE_FETCHER="true"
FETCH_REWARDS_WAY="manual"
BLOCKSCOUT_VERSION="v1.2.0"
LINK_TO_OTHER_EXPLORERS="false"
SUPPORTED_CHAINS='[ {"title":"Gauss Mainnet", "url":"https://explorer.gaussgang.com"}, {"title":"G.I.L. Testnet", "url":"https://explorer.giltestnet.com", "test_net?": true } ]'
RE_CAPTCHA_SECRET_KEY="Secret_Key"
RE_CAPTCHA_CLIENT_KEY="Site_Key"
FOOTER_ENABLE_FORUM_LINK="true"
FOOTER_GITHUB_LINK="https://github.com/Gauss-Gang"
FOOTER_CHAT_LINK="mailto:support@gaussgang.com"
FOOTER_FORUM_LINK="https://discord.gg/gauss"
ENABLE_RUST_VERIFICATION_SERVICE="true"
RUST_VERIFICATION_SERVICE_URL="http://IP:PORT"

info

Use SECRET_KEY_BASE you've generated in Part 3.

Save the file and exit.

Finally, start Gauss Explorer service​

sudo systemctl start explorer.service

Now all that's left to do is to check if Gauss Explorer service is running. Check service status with:

sudo systemctl status explorer.service

To check service output:

sudo journalctl -u explorer.service -f

You can check if there are some new listening ports:

# if netstat is not installed
sudo apt install net-tools
sudo netstat -tulpn

You should get a list of listening ports and on the list there should be something like this:

tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      28142/postgres
tcp        0      0 0.0.0.0:4000            0.0.0.0:*               LISTEN      42148/beam.smp

Gauss Explorer web service runs the port and protocol defined in env file. In this example it runs on 4000(http). If everything is ok, you should be able to access the Gauss Explorer web portal with http://<host_ip>:4000.

For best performance, it is advisable to have a dedicated/local polygon-edge full archive non-validator node that will be used exclusively for Gauss Explorer queries. The json-rpc API of this node, doesn't need to be exposed publicly, as Gauss Explorer runs all queries from the backend.

We've just deployed a single Gauss Explorer instance, which works fine, but for production you should consider placing this instance behind a reverse proxy like Nginx. You should also think about database and instance scalability, depending on your use case.

You should definitely check out the official BlockScout documentation as there a lot of customization options.

Last updated