Last updated: 2022-01-31
This is a quick “copy & paste guide” for data scientists and developers who are interested in storing the Ergo blockchain to a standardized database format using a Raspberry Pi 4.
We will be using the Ergo Blockchain Explorer (backend) but focus our efforts specifically on the Chain Grabber module.
A few prerequisites before we get started…
- Clean install of Raspberry Pi 4+
- Root file system mounted to SSD (60GB+)
- SSH enabled with stable internet connection
Preparing the RPi
sudo apt update
sudo apt full-upgrade
Download latest Java version
sudo apt install default-jdk
Download sbt
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
sudo apt update
sudo apt install sbt
Download and unzip precompiled JAR
If you are reading this from the future please visit the code repo and replace with the appropriate versions.
wget https://github.com/ergoplatform/explorer-backend/archive/refs/tags/9.4.3.zip
unzip explorer-backend-9.4.3
Install PostgreSQL
In the code snippet below we created “ergo” as the username.
sudo apt install postgresql
sudo su postgres
createuser ergo -P --interactive
As of this writing update on 2022-01-31, the Chain Grabber begins to stall at block height 350K or so if you use option a) below. Ideally, this is fixed in the future but until then I have listed a few other workarounds.
a) Setup and load database schema
psql
create database explorer;
\c explorer;
/i /explorer-backend-9.4.3/modules/explorer-core/src/main/resources/db/V9__Schema.sql
The final line of code above executes a SQL script that creates a bunch of tables and indices to be populated later by the Chain Grabber.
b) Load ErgoWatch DB dump
You can download the database dump here (13GB file) and it will put you on the fast track to block height 600K or higher. The module will pick up subsequent blocks after that.
pg_restore
--dbname=explorer
--create
--verbose /path/to/data_dump/grabberdb.dmp
c) Delete SQL index code
If you are comfortable with reading Scala, then another method is to delete all SQL code references to creating the database indices. This approach can work if the dump file is no longer available from option b).
Update app config
This is where you need to edit the database username and password you set up earlier.
sudo nano explorer-backend-9.4.3/modules/chain-grabber/src/main/resources/application.conf
Launch chain-grabber
sbt chain-grabber/run
Validate
If all goes well the code below returns the latest block height that was stored to the database.
select max(height) from node_headers;
If you found this tutorial remotely helpful, any $ERG sent my way to 9fsNArvL5VqZ4hJ6K8HVCatnWzgAwMd9Av7LTZZR8tVmbcL4a2S is always appreciated.
If that’s not your jam then I also have a cryptojar for other virtual currencies. :)
References
- Discord help: abchris & Glasgow
- How to Install Java on Raspberry Pi
- Installing sbt on debian
- Releases - Ergo Explorer Backend
- Setting up a PostgreSQL Database on a Raspberry Pi
- How to run an SQL file in Postgres
- Move the Raspberry Pi root file system to a USB drive
ERGO Seed Phrase #2: enough