- Docs »
- Blockchain network deployment
- Edit on GitHub
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 |
Deployment stages¶
Your own blockchain network must be deployed in several stages:
Backend deployment
- Deploying the first node
- Deploying additional nodes
Frontend deployment
Blockchain network configuration
- Creating the founder’s account
- Importing apps, roles, and templates
- Adding first node to the list of nodes
Adding extra validating nodes
- Adding a member to Consensus role
- Creating the node owner’s account
- Adding node owner to Validators role
- Adding the validating node via voting
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.
- Become the root superuser.
su -
- Upgrade your system.
apt update -y && apt upgrade -y && apt dist-upgrade -y
- Install sudo.
apt install sudo -y
- Add your user to the sudo group.
usermod -a -G sudo user
- After the reboot, the changes take effect.
Go language¶
Install Go as described in the official documentation.
- 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
- Extract the package to
/usr/local
.
tar -C /usr/local -xzf go1.11.2.linux-amd64.tar.gz
- Add
/usr/local/go/bin
to the PATH environment variable (either to/etc/profile
or$HOME/.profile
).
export PATH=$PATH:/usr/local/go/bin
- For changes to take effect,
source
this file. For example:
source $HOME/.profile
- Remove the temporary file:
rm go1.11.2.linux-amd64.tar.gz
PostgreSQL¶
- Install PostgreSQL (> v.10) and psql:
sudo apt install -y postgresql
Centrifugo¶
- 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/
- 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.
- Make a directory for the blockchain platform:
sudo mkdir /opt/apla
- Make your user the owner of this directory:
sudo chown user /opt/apla/
- Make subdirectories for Centrifugo, go-apla, and node data. In this guide, all node data is stored in the directories with
nodeX
name, whereX
is the node number. Depending on which node you are deploying, this will benode1
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¶
- 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'"
- Create a node current state database, for example ‘apladb’:
sudo -u postgres psql -c "CREATE DATABASE apladb"
Configuring Centrifugo¶
- 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¶
- Download and build the latest release of go-apla from GitHub:
go get -v github.com/AplaProject/go-apla
- 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¶
- 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
- Generate node 1 keys:
/opt/apla/go-apla/go-apla generateKeys \ --config=/opt/apla/go-apla/node1/config.toml
- 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
- 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.
- Run centrifugo:
/opt/apla/centrifugo/centrifugo \ -a 10.10.99.1 -p 8000 \ --config /opt/apla/centrifugo/config.json
- 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:
Dependencies and environment setup
Creating the database
Configuring Centrifugo
Installing go-apla
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.1Copy 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/Generate node 2 keys:
/opt/apla/go-apla/go-apla generateKeys \ --config=/opt/apla/go-apla/node2/config.tomlInitialize the database:
./go-apla initDatabase --config=node2/config.toml
Run centrifugo:
/opt/apla/centrifugo/centrifugo \ -a 10.10.99.2 -p 8000 \ --config /opt/apla/centrifugo/config.jsonRun 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:
Dependencies and environment setup
Creating the database
Configuring Centrifugo
Installing go-apla
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.1Copy 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/Generate node 3 keys:
/opt/apla/go-apla/go-apla generateKeys \ --config=/opt/apla/go-apla/node3/config.tomlInitialize the database:
./go-apla initDatabase --config=node3/config.toml
Run centrifugo:
/opt/apla/centrifugo/centrifugo \ -a 10.10.99.3 -p 8000 \ --config /opt/apla/centrifugo/config.jsonRun 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¶
- 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
- Install Node.js:
sudo apt install -y nodejs
Yarn¶
- 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
- Install Yarn:
sudo dpkg -i yarn_1.7.0_all.deb && rm yarn_1.7.0_all.deb
Building Molis App¶
- Download latest release of Molis from Molis GitHub repository via git:
cd /opt/apla \&& git clone https://github.com/AplaProject/apla-front.git
- Install Molis dependencies via Yarn:
cd /opt/apla/apla-front/ \&& yarn install
Adding the blockchain network configuration¶
- 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
- 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¶
- Build the desktop app with Yarn:
cd /opt/apla/apla-front \&& yarn build-desktop
- 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¶
- 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.
- 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.
Run Molis (frontend).
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.
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.
- Clone the applications repository.
cd /opt/apla \&& git clone https://github.com/AplaProject/apps.git
In Molis, navigate to Developer > Import.
Import apps in this order:
- /opt/apla/apps/system.json
- /opt/apla/apps/lang_res.json
- /opt/apla/apps/basic.json
- /opt/apla/apps/conditions.json
Navigate to Admin > Roles and click Install default roles.
Sign out of the system via the profile menu.
Log into the system under the Admin role.
Navigate to Home > Votings > Templates list and click Install default templates.
Adding first node to the list of nodes¶
- Navigate to Admin > Platform parameters and click the cogwheel icon for the full_nodes parameter.
- 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.
- As an ecosystem founder, navigate to Home > Roles and click the Consensus role (Apla Consensus asbl).
- Click Assign and assign founder’s account to this role.
Creating the node owner’s account¶
Run Molis (frontend)
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.
- Backup payload is the node owner’s private key located in the
Login under this new account. Because a role hasn’t been assigned to this account, use the Without role login option.
Navigate to Home > Profile and click on the new profile name.
Add account details (profile name, description, etc.)
Adding node owner to Validator role¶
As a new node owner:
- Navigate to Home > Candidates for the validators.
- Click Create request and fill the Candidates for the validators request form.
- Click Send request.
As a founder:
- Login under the Consensus role (Apla Consensus asbl).
- Navigate to Home > Candidates for the validators.
- Start the voting for by clicking the “play” icon by the candidate’s request.
- Navigate to Home > Votings and click Update votings statuses.
- 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¶
As a founder, login under the Consensus role (Apla Consensus asbl).
Navigate to Admin > Platform parameters and click the cogwheel icon for the full_nodes parameter.
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.
- TCP address is
Click Vote.
Navigate to Home > Votings and click Update votings statuses.
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.