Building Fetch.AI Ledger Node

Constellation is a C++ executable which houses several of the ledger components. It includes a transaction processing system, a block miner, the blockchain system, the “offchain” lanes, two runtime options (standalone and private network) and all the networking code that allows it to talk to other running Constellations.

It is written in cross-platform C++11 and should currently compile for MacOS using clang and Linux using either clang or Gnu C++.

Prerequisites

MacOS

We recommend familiarity with the following:

  • Using a command-line development environment.
  • Using the UNIX filesystem.
  • Using the Git source management system.
  • Using a code editor. (The development team use a selection of VIM, CLine and Emacs.)

Process:

  1. Install Apple’s XCode via the AppStore - ensure Xcode version is no later than 10.1.
  2. Install brew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

3. Configure the path for OpenSSL.

  • Edit your ~/.bash_profile
  • Add this line to the end of it. Note the BACKTICK ` characters.
export OPENSSL_ROOT_DIR="/usr/local/Cellar/openssl/`ls /usr/local/Cellar/openssl/ | sort | tail -1`"

4. Open a new shell window to pick up the changes or logout and login again.

5. Install git and add the alias pullall.

brew install git

git config --global alias.pullall '!f(){ git pull "$@" && git submodule sync --recursive && git submodule update --init --recursive; }; f'

6. Make sure you have cmake and OpenSSL .

brew install cmake
brew install openssl

NB: If you have any issues with OpenSSL, run the following:

cmake -DOPENSSL_ROOT_DIR=/usr/local/ssl -DOPENSSL_LIBRARIES=/usr/local/ssl/lib

Linux

We recommend you are familiar with the following topics:

  • Command-line development.
  • UNIX filesystem.
  • Git source management system.
  • Code editors. (The development team use Sublime, VIM, and Emacs.)

We recommend:

  • Ubuntu over other Linux distributions.
  • BASH as the login shell.

Ubuntu & Mint

Process:

  1. Update Ubuntu: apt-get update.
  2. Install compilers and the command-line toolchain.
apt-get install build-essential clang git cmake libssl-dev doxygen python3-dev python3-pip python3-venv
  1. apt-get update
  2. Set environment variables in the system profile /etc/profile or in your login script.
export CC=clang
export CXX=clang++

3. Now add the git alias.

git config --global alias.pullall '!f(){ git pull "$@" && git submodule sync --recursive && git submodule update --init --recursive; }; f'

RedHat & Derivatives

Process:

  1. Install compilers and the command-line toolchain.
yum install -y sudo
yum install -y make
yum install -y cmake
yum install -y libpng-devel
yum install -y zlib-devel
yum install -y openssl-devel
yum install -y python36-devel (replace 36 with your version of Python3)
yum install -y clang
yum install -y epel-release (dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm)
yum install -y python-pip (prb. already installed)
yum install -y git 
pip2 install --upgrade pip
pip3 install --upgrade pip
pip install --upgrade cldoc
yum install -y autoconf
yum install -y automake
yum install -y wget
yum install -y which
yum install -y tree

Make sure to use clang and not gcc.

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

Download and Build Fetch.AI Ledger

Download from Git

  1. Get the code:
  • Make a suitable directory for your checkouts.
  • If you need them, here are the Git SSH key generation instructions.
  • Change into that directory, run git init , and execute the git commands:
git clone git@github.com:fetchai/ledger.git

cd ledger
mkdir build/

git checkout master

2. Now execute:

git pull
git submodule update --recursive --init

Building the Source Code

Follow these steps:

cd build/
cmake ..
make -j constellation

If you have issues with make constellation, it can be that make cannot detect the number of CPUs on the system. In this case, you can limit the cores to 4.

make -j 4 constellation

If you wish to build the entire library, run:

make -j

Running Constellation

Command Line Arguments

Name Description Default
port The starting port for ledger services 8000
executors The number of executors to configure 4
lanes The number of lanes to be used 4
slices The number of slices to be used 4
peers The comma separated list of addresses to initially connect to
db-prefix The directory or prefix added to the node storage node_storage
network-id The network id 0x10
interface The network id 127.0.0.1
block-interval Block interval in milliseconds. 5000
bootstrap Bootstrap network address
token The authentication token to be used with bootstrapping the client
mine Enable mining on this node 0
external This node's global IP addr.
host-name The hostname / identifier for this node
config The path to the manifest configuration
processor-threads The number of processor threads Number of cores
verifier-threads The number of verification threads Number of cores in the system
max-peers The number of maximal peers to send to peer requests. 3
transient-peers The number of the peers which will be random in answer sent to peer requests. In milliseconds. 1
peers-update-cycle-ms How fast to do peering changes. 0 (0 means Trust system is disabled)
p2p-process-cycle-ms How fast the p2p inner cycle spins. 1000
p2p-manifest-update-cycle-ms Manifest update cycle. 500
p2p-block-catchup-cycle-ms Block catch up cycle. 1000

Running a Single Constellation Node

Start up a single Constellation node with a block mining period of 3 seconds on port 8000 from the build/ directory:

./apps/constellation/constellation -port 8000 -block-interval 3000 -standalone

Running a Network of Constellations

The flag for a private network of Constellation nodes is private-network. To start up a networked Constellation from the build/ folder, startup a node on port 8000 and set the block mining period to 3 seconds:

./apps/constellation/constellation -port 8000 -block-interval 3000 -private-network

Next, start a second node on port 8020.To connect this node to the first, we pass it the address of the first node +1. Connecting ports are always defined as +1 the node port to connect to.

./apps/constellation/constellation -port 8020 -peers tcp://127.0.0.1:8001

The third node will be on port 8040. This node connects to the first two nodes.

./apps/constellation/constellation -port 8040 -peers tcp://127.0.0.1:8021,tcp://127.0.0.1:8001

To add more nodes to the network, repeat the previous step using different ports and the same or different peers.

Address

St. John's Innovation Centre,
Cowley Road,
Cambridge,
CB4 0WS
UK

Go to map
General: info@fetch.ai
Technical: community@fetch.ai
Investors: corporate@fetch.ai