Blockchain network deployment

This guide demonstrates how to deploy your own blockchain network.

Note

  • If you want to try the Apla blockchain network instead, check out Apla Testnet.
  • If you want to deploy a local testing environment quickly, consider using Apla quickstart which is based on Docker images.

Example deployment

This guide deploys the example blockchain network of three nodes.

The network has three nodes:

  • Node 1 is the first node in the blockchain network. It can generate new blocks and send transactions from the clients connected to it.
  • Node 2 is an extra validating node. It can generate new blocks and send transactions from the clients connected to it.
  • Node 3 is an extra node. It cannot generate new blocks but can send transactions from the clients connected to it.

Nodes are deployed in this configuration:

  • Each node will use its own instance of PostgreSQL database system.
  • Each node will use its own instance of Centrifugo service.
  • The go-apla services will be deployed on the same host with other backend components.

Addresses and ports used by nodes are described in the following table:

Node Component IP and Port
1 PostgreSQL 127.0.0.1:5432
1 Centrifugo 10.10.99.1:8000
1 go-apla (TCP-server) 10.10.99.1:7078
1 go-apla (API-server) 10.10.99.1:7079
2 PostgreSQL 127.0.0.1:5432
2 Centrifugo 10.10.99.2:8000
2 go-apla (TCP-server) 10.10.99.2:7078
2 go-apla (API-server) 10.10.99.2:7079
3 PostgreSQL 127.0.0.1:5432
3 Centrifugo 10.10.99.3:8000
3 go-apla (TCP-server) 10.10.99.3:7078
3 go-apla (API-server) 10.10.99.3:7079

Backend deployment

Deploying the first node

First node is a special node because it must be used to start the blockchain network. First block of the blockchain is generated by the first node and all other nodes download the blockchain from it. The owner of the first node becomes the platform founder.

Dependencies and environment setup

sudo

All commands for Debian 9 must be run as a non-root user. But some system commands need superuser privileges to be executed. By default, sudo is not installed on Debian 9, and you must install it first.

  1. Become the root superuser.
su -
  1. Upgrade your system.
apt update -y && apt upgrade -y && apt dist-upgrade -y
  1. Install sudo.
apt install sudo -y
  1. Add your user to the sudo group.
usermod -a -G sudo user
  1. After the reboot, the changes take effect.
Go language

Install Go as described in the official documentation.

  1. Download the latest stable version of Go (> 1.10.x) from the Golang official site or via the command line:
wget https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz
  1. Extract the package to /usr/local.
tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
  1. Add /usr/local/go/bin to the PATH environment variable (either to /etc/profile or $HOME/.profile).
export PATH=$PATH:/usr/local/go/bin
  1. For changes to take effect, source this file. For example:
source $HOME/.profile
  1. Remove the temporary file:
rm go1.11.2.linux-amd64.tar.gz
PostgreSQL
  1. Install PostgreSQL (> v.10) and psql:
sudo apt install -y postgresql
Centrifugo
  1. Download Centrifugo version 1.8.0 from GitHub or via command line:
wget https://github.com/centrifugal/centrifugo/releases/download/v1.8.0/centrifugo-1.8.0-linux-amd64.zip \
&& unzip centrifugo-1.8.0-linux-amd64.zip \
&& mkdir centrifugo \
&& mv centrifugo-1.8.0-linux-amd64/* centrifugo/
  1. Remove temporary files:
rm -R centrifugo-1.8.0-linux-amd64 \
&& rm centrifugo-1.8.0-linux-amd64.zip
Directories

For Debian 9 OS, it is recommended to store all software used by the blockchain platform in a separate directory.

This guide uses the /opt/apla directory, but you can use any directory. In this case, change all commands and configuration files accordingly.

  1. Make a directory for the blockchain platform:
sudo mkdir /opt/apla
  1. Make your user the owner of this directory:
sudo chown user /opt/apla/
  1. Make subdirectories for Centrifugo, go-apla, and node data. In this guide, all node data is stored in the directories with nodeX name, where X is the node number. Depending on which node you are deploying, this will be node1 for node 1, node2 for node 2, and so on.
mkdir /opt/apla/go-apla \
mkdir /opt/apla/go-apla/node1 \
mkdir /opt/apla/centrifugo \

Creating the database

  1. Change user’s password postgres to Apla’s default password. You can set your own password, but then you must change it in the node configuration file config.toml.
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'apla'"
  1. Create a node current state database, for example ‘apladb’:
sudo -u postgres psql -c "CREATE DATABASE apladb"

Configuring Centrifugo

  1. Create Centrifugo configuration file:
echo '{"secret":"CENT_SECRET"}' > /opt/apla/centrifugo/config.json

You can set your own “secret”, but then you also must change it in the node configuration file config.toml.

Installing go-apla

  1. Download and build the latest release of go-apla from GitHub:
go get -v github.com/AplaProject/go-apla
  1. Copy the go-apla binary to the /opt/apla/go-apla directory. If you use the default Go workspace then the binary is located in the $HOME/go/bin directory:
cp $HOME/go/bin/go-apla /opt/apla/go-apla

Configuring the first node

  1. Create the node 1 configuration file:
/opt/apla/go-apla/go-apla config \
    --dataDir=/opt/apla/go-apla/node1 \
    --dbName=apladb \
    --centSecret="CENT_SECRET" --centUrl=http://10.10.99.1:8000 \
    --httpHost=10.10.99.1 \
    --httpPort=7079 \
    --tcpHost=10.10.99.1 \
    --tcpPort=7078
  1. Generate node 1 keys:
/opt/apla/go-apla/go-apla generateKeys \
    --config=/opt/apla/go-apla/node1/config.toml
  1. Generate the first block:

Note

If you are creating your own blockchain network. you must use the --test=true option. Otherwise you will not be able to create new accounts.

/opt/apla/go-apla/go-apla generateFirstBlock \
    --config=/opt/apla/go-apla/node1/config.toml \
    --test=true
  1. Initialize the database:
/opt/apla/go-apla/go-apla initDatabase \
    --config=/opt/apla/go-apla/node1/config.toml

Starting the first node backend

To start the first node backend, you must start two services:

  • centrifugo
  • go-apla

If you did not create these as services, you can just execute binary files from their directories in different consoles.

  1. Run centrifugo:
/opt/apla/centrifugo/centrifugo \
    -a 10.10.99.1 -p 8000 \
    --config /opt/apla/centrifugo/config.json
  1. Run go-apla:
/opt/apla/go-apla/go-apla start \
    --config=/opt/apla/go-apla/node1/config.toml

Deploying additional nodes

All other nodes (Node 2 and Node 3) are deployed like the first node with three differences:

  • You do not need to generate the first block. Instead, it must be copied to the node data directory from node 1.
  • The node must be configured to download blocks from node 1 via --nodesAddr option.
  • The node must be configured to use its own addresses and ports.

Node 2

Follow this sequence of actions:

  1. Dependencies and environment setup

  2. Creating the database

  3. Configuring Centrifugo

  4. Installing go-apla

  5. Create the node 2 configuration file:

    /opt/apla/go-apla/go-apla config \
        --dataDir=/opt/apla/go-apla/node2 \
        --dbName=apladb \
        --centSecret="CENT_SECRET" --centUrl=http://10.10.99.2:8000 \
        --httpHost=10.10.99.2 \
        --httpPort=7079 \
        --tcpHost=10.10.99.2 \
        --tcpPort=7078 \
        --nodesAddr=10.10.99.1
    
  6. Copy the first block file to Node 2. For example, you can do it via scp on Node 2:

    scp user@10.10.99.1:/opt/apla/go-apla/node1/1block /opt/apla/go-apla/node2/
    
  7. Generate node 2 keys:

    /opt/apla/go-apla/go-apla generateKeys \
        --config=/opt/apla/go-apla/node2/config.toml
    
  8. Initialize the database:

    ./go-apla initDatabase --config=node2/config.toml
    
  9. Run centrifugo:

    /opt/apla/centrifugo/centrifugo \
        -a 10.10.99.2 -p 8000 \
        --config /opt/apla/centrifugo/config.json
    
  10. Run go-apla:

    /opt/apla/go-apla/go-apla start \
        --config=/opt/apla/go-apla/node2/config.toml
    

As a result, the node will download the blocks from the first node. This node is not the validating node, so it cannot generate new blocks. Node 2 will be added to the list of validating nodes later in this guide.

Node 3

Follow this sequence of actions:

  1. Dependencies and environment setup

  2. Creating the database

  3. Configuring Centrifugo

  4. Installing go-apla

  5. Create the node 3 configuration file:

    /opt/apla/go-apla/go-apla config \
        --dataDir=/opt/apla/go-apla/node3 \
        --dbName=apladb \
        --centSecret="CENT_SECRET" --centUrl=http://10.10.99.3:8000 \
        --httpHost=10.10.99.3 \
        --httpPort=7079 \
        --tcpHost=10.10.99.3 \
        --tcpPort=7078 \
        --nodesAddr=10.10.99.1
    
  6. Copy the first block file to Node 3. For example, you can do it via scp on Node 3:

    scp user@10.10.99.1:/opt/apla/go-apla/node1/1block /opt/apla/go-apla/node3/
    
  7. Generate node 3 keys:

    /opt/apla/go-apla/go-apla generateKeys \
        --config=/opt/apla/go-apla/node3/config.toml
    
  8. Initialize the database:

    ./go-apla initDatabase --config=node3/config.toml
    
  9. Run centrifugo:

    /opt/apla/centrifugo/centrifugo \
        -a 10.10.99.3 -p 8000 \
        --config /opt/apla/centrifugo/config.json
    
  10. Run go-apla:

    /opt/apla/go-apla/go-apla start \
        --config=/opt/apla/go-apla/node3/config.toml
    

As a result, the node will download the blocks from the first node. This node is not the validating node, so it cannot generate new blocks. Сlients can connect to this node and it can send transactions to the network.

Frontend deployment

Molis client can be build by the yarn package manager only on Debian 9 (Stretch) 64-bit official distributive with installed GNOME GUI.

Software prerequisites

Node.js

  1. Download Node.js LTS version 8.11 from the Node.js official site or via the command line:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash
  1. Install Node.js:
sudo apt install -y nodejs

Yarn

  1. Download Yarn version 1.7.0 from yarn GitHub repository or via command line:
cd /opt/apla \
&& wget https://github.com/yarnpkg/yarn/releases/download/v1.7.0/yarn_1.7.0_all.deb
  1. Install Yarn:
sudo dpkg -i yarn_1.7.0_all.deb && rm yarn_1.7.0_all.deb

Building Molis App

  1. Download latest release of Molis from Molis GitHub repository via git:
cd /opt/apla \
&& git clone https://github.com/AplaProject/apla-front.git
  1. Install Molis dependencies via Yarn:
cd /opt/apla/apla-front/ \
&& yarn install

Adding the blockchain network configuration

  1. Create settings.json file that contains connections information about full nodes:
cp /opt/apla/apla-front/public/settings.json.dist \
    /opt/apla/apla-front/public/public/settings.json
  1. Edit settings.json file in any text editor and add required settings in this format:
http://Node_IP-address:Node_HTTP-Port

Example settings.json file for three nodes:

{
    "fullNodes": [
        "http://10.10.99.1:7079",
        "http://10.10.99.2:7079",
        "http://10.10.99.3:7079"
    ]
}

Building as Molis Desktop App

  1. Build the desktop app with Yarn:
cd /opt/apla/apla-front \
&& yarn build-desktop
  1. The desktop app must be packed to the AppImage:
yarn release --publish never -l

After that, your application will be ready to use, but its connection settings cannot be changed in the future. If these settings will change, you must build a new version of the application.

Building as Molis Web App

  1. Build the web app:
cd /opt/apla/apla-front/ \
&& yarn build

After building, redistributable files will be placed to the ‘/build’ directory. You can serve it with any web-server of your choice. Settings.json file must be also placed there. Note that you do not need to build your application again if your connection settings will change. Instead, edit the settings.json file and restart web-server.

  1. For development or testing purposes, you can build Yarn’s web-server:
sudo yarn global add serve \
&& serve -s build

After this, your Molis Web App will be available at: http://localhost:5000

Blockchain network configuration

Creating the founder’s account

Create an account for the first node owner. This account is the founder of the new blockchain platform and will have administrator access rights.

  1. Run Molis (frontend).

  2. Import an existing account using the following data:

    • Backup payload is the node owner’s private key located in the /opt/apla/go-apla/node1/PrivateKey file.

      Note

      There are two private key files in this directory. PrivateKey file is for node owner’s account. It is used to create the node owner’s account. NodePrivateKey is the private key of the node itself and must be kept secret.

  3. Login under this new account. Because roles haven’t been created at this moment, use the Without role login option.

Importing apps, roles, and templates

At this moment, the blockchain platform is in the blank state. You can configure it by adding the framework of roles, templates and apps that support the basic ecosystem functions.

  1. Clone the applications repository.
cd /opt/apla \
&& git clone https://github.com/AplaProject/apps.git
  1. In Molis, navigate to Developer > Import.

  2. Import apps in this order:

    1. /opt/apla/apps/system.json
    2. /opt/apla/apps/lang_res.json
    3. /opt/apla/apps/basic.json
    4. /opt/apla/apps/conditions.json
  3. Navigate to Admin > Roles and click Install default roles.

  4. Sign out of the system via the profile menu.

  5. Log into the system under the Admin role.

  6. Navigate to Home > Votings > Templates list and click Install default templates.

Adding first node to the list of nodes

  1. Navigate to Admin > Platform parameters and click the cogwheel icon for the full_nodes parameter.
  2. Specify the parameters for the first blockchain network node. Node’s public key is located in the /opt/apla/go-apla/node1/NodePublicKey file. Node owner’s key identifier is located in the /opt/apla/go-apla/node1/KeyID file.
{"api_address":"http://10.10.99.1:7079","key_id":"%node_owner_key_id%","public_key":"%node_public_key%","tcp_address":"10.10.99.1:7078"}

Adding extra validating nodes

Adding a member to Consensus role

By default, only members of the Consensus role (Apla Consensus asbl) can participate in votings required for adding extra validating nodes. It means that a member of the ecosystem must be appointed to this role before new validating nodes can be added.

In this guide, the founder’s account will be appointed as a sole member of the Consensus. In a production environment, this role must be assigned to members that perform platform governance.

  1. As an ecosystem founder, navigate to Home > Roles and click the Consensus role (Apla Consensus asbl).
  2. Click Assign and assign founder’s account to this role.

Creating the node owner’s account

  1. Run Molis (frontend)

  2. Import an existing account using the following data:

    • Backup payload is the node owner’s private key located in the /opt/apla/go-apla/node2/PrivateKey file.
  3. Login under this new account. Because a role hasn’t been assigned to this account, use the Without role login option.

  4. Navigate to Home > Profile and click on the new profile name.

  5. Add account details (profile name, description, etc.)

Adding node owner to Validator role

  1. As a new node owner:

    1. Navigate to Home > Candidates for the validators.
    2. Click Create request and fill the Candidates for the validators request form.
    3. Click Send request.
  2. As a founder:

    1. Login under the Consensus role (Apla Consensus asbl).
    2. Navigate to Home > Candidates for the validators.
    3. Start the voting for by clicking the “play” icon by the candidate’s request.
    4. Navigate to Home > Votings and click Update votings statuses.
    5. Click the voting name and vote for the node owner (click Vote).

As a result, node owner’s account will be assigned the Validator role.

Adding the validating node via voting

  1. As a founder, login under the Consensus role (Apla Consensus asbl).

  2. Navigate to Admin > Platform parameters and click the cogwheel icon for the full_nodes parameter.

  3. Specify the node 2 parameters:

    • TCP address is 10.10.99.2:7078.
    • API address is http://10.10.99.2:7079.
    • Key ID of the node founder is located in the /opt/apla/go-apla/node2/KeyID file.
    • Node’s public key is located in the /opt/apla/go-apla/node2/NodePublicKey file.
  4. Click Vote.

  5. Navigate to Home > Votings and click Update votings statuses.

  6. Click the “Voting for System param value” voting and vote for the system parameter change (Click Accept).

As a result, a new node will be added to the list of validating nodes.