Skip to content

Instantly share code, notes, and snippets.

@BellaMENG
Last active May 3, 2022 05:59
Show Gist options
  • Save BellaMENG/60a02debd1ceee0266ff469eb89176f8 to your computer and use it in GitHub Desktop.
Save BellaMENG/60a02debd1ceee0266ff469eb89176f8 to your computer and use it in GitHub Desktop.
How to install BlockSci on CentOS 7

Use BlockSci on CentOS 7

BlockSci

Dependencies

Use yum to install most of the packages first

First try to use yum install most of the libraries first.

The names of some packages are different for CentOS 7.

sudo yum install cmake3 libtool autoconf openssl-devel libcurl-devel snappy-devel zlib-devel libbz2-dev lz4-devel libzstd-devel jemalloc-devel sparsehash-devel python3-devel python3-pip

For the following packages, we need to build from source: jsoncpp, boost with at least version 1.58.0, and json-rpc-cpp.

Install devtoolset-8

sudo yum install devtoolset-8

Later on, we need to enable this toolset for the gcc/g++ compilers

scl enable devtoolset-8 bash
# I used zsh

Build from source

jsoncpp

We can use cmake3 to install jsoncpp. So first, install cmake3.

sudo yum install cmake3

I downloaded jsoncpp from GitHub first. Then,

cd jsoncpp
mkdir -p build/release
cd build/release
cmake3 -DCMAKE_BUILD_TYPE=release -DBUILD_STATIC_LIBS=OFF -DBUILD_SHARED_LIBS=ON -DARCHIVE_INSTALL_DIR=/usr/include/jsoncpp/lib -DINCLUDE_INSTALL_DIR=/usr/include/jsoncpp/include ../..
make
sudo make install

json-rpc-cpp

Source code can be accessed from here. "Build from source" session explained how the basic steps. Install the dependencies first.

sudo yum install libcurl libmicrohttpd hiredis catch-devel
sudo yum install libmicrohttpd-devel hiredis-devel argtable-devel

Then build.

git clone https://github.com/cinemast/libjson-rpc-cpp.git
mkdir -p libjson-rpc-cpp/build
cd libjson-rpc-cpp/build
cmake _DHTTP-SERVER=NO ..
make
sudo make install
sudo ldconfig

There are compilation flags, which you can choose to use according to your system.

boost

Install this dependency first.

sudo yum install bzip2-devel

Download boost source code.

Unzip it.

tar -xzf boost_1_*
cd boost_1_*
./bootstrap.sh
sudo ./b2 install -j N
# replace N with an integer. I used 256.
sudo ldconfig

Compile BlockSci

The first part is the same as the compiling page for linux.

git clone --recurse-submodules https://github.com/citp/BlockSci.git
cd BlockSci
mkdir release
cd release

Remember, before compiling it, enable out devtoolset-8 by the command mentioned before! If you did not enable it, run the following command.

scl enable devtoolset-8 bash

Then compile BlockSci.

CC=gcc CXX=g++ cmake3 _DCMAKE_BUILD_TYPE=Release ..
make -j $(nproc)
sudo make install
cd ..
CC=gcc CXX=g++ sudo pip3 install -e blockscipy

BlockSci should be installed successfully. You can try by the importing blocksci in python3 shell.

Setup BlockSci

After compiling blocksci, we can start to parse data for later analysis. We use blocksci_parser command. If you type blocksci_parser command, the help page should pop up.

However, you may also encounter the following error:

blocksci_parser: error while loading shared libraries: libboost_serialization.so.1.58.0: cannot open shared object file: No such file or directory

However, we are also sure that boost 1.58 is installed. Then we type in the following command:

ldd blocksci_parser

(If it says no such file, go to the directory where it is installed and run the command) There will be a list of dinamic dependencies. There might be several pointing to "not found". We can use the following commands to fix it.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<Your_non-Standard_path>
sudo ldconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
sudo ldconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
sudo ldconfig

Now we can use blocksci_parser command!

According to their FAQ page, the syntax for blocksci_parser is no longer the one on the documentation.

We first need to generate a config file.

blocksci_parser <config file> generate-config <coin type> <data directory> [--max-block <max block>] [--disk <coin directory>] [--rpc <username> <password> [--address <address>] [--port <port>]]

For example, if we are parsing bitcoin blockchain data on disk, we can just use the following command to generate the config file.

blocksci_parser blocksci.config generate-config bitcoin blocksci_data --max-block 600000 --disk blockchain

We can see that coin type is bitcoin, the output directory is ./blocksci_data, the coin directory is ./blockchain, max block number is 600k, and the config file generated will be blocksci.config.

After generating the config file, we can start to parse the data using blocksci_parser by the following command:

blocksci_parser <config file> update

In our case, it is blocksci_parser blocksci.config update.

If the data to parse is big, e.g. 600k blocks, it may take some time to finish parsing. If you are working on a remote server by ssh sesssion, we can use tmux to create session so that it will run in the background while you may log out safely. Install tmux first. Then type in tmux, run the blocksci_parser <config file> update command, then if you want to detach from the current session, just type ctrl + b then d, you will be successfully detached. Whenever you want to attach, just type tmux attach, you will be able to see the previous session.

Other possible errors

When trying to reinstall it from the beginning, remember to delete blockscipy/build and the following:

rm -rf /usr/local/include/blocksci
rm /usr/local/lib/libblocksci*
rm /usr/local/bin/blocksci*
rm /usr/local/bin/mempool_recorder

I hope this tutorial will be able to help you!

@18580764418
Copy link

yum install centos-release-scl -y
yum install devtoolset-8 -y

@18580764418
Copy link

json-rpc-cpp
install:

CC=gcc CXX=g++ cmake3 sudo pip3 install -e blockscipy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment