Downloading, building, and running the node from source code
Table of Contents
- Introduction
- Step 1: Install Erlang
- Step 2: Download and build the node
- Step 3: Create directories and place the files
- Step 4: Start the node
- How to stop the node?
- Step 5: Get the certificate
- How to check, if my node works?
- What do I need to do if something goes wrong?
Introduction
If you want to go through the advanced way of building sources, this manual will help you do this.
Step 1: Install Erlang
You can install Erlang either using the package manager, or using kerl
.
Install Erlang using the package manager
If you use the recommended Ubuntu version (22.04.1), you can install Erlang using the package manager. To do this, run the following command:
apt install cmake clang gcc git curl libssl-dev build-essential automake autoconf libncurses5-dev elixir erlang
If you use another version of Ubuntu (20.04, for instance), refer to the section below to install Erlang using kerl
.
Install Erlang using kerl
To install erlang using kerl
:
-
Install the software you need to seamlessly install Erlang:
apt install cmake clang gcc git curl libssl-dev build-essential automake autoconf libncurses5-dev elixir erlang-base erlang-public-key erlang-asn1 erlang-ssl erlang-dev erlang-inets erlang-eunit
-
Create a directory, where Erlang will be installed to:
mkdir /opt/erlang
-
Create a directory, where you will work with your node:
mkdir /opt/<your_node>
-
Go to
/opt/erlang
directory:cd /opt/erlang
-
Install Erlang. To do this, download the
kerl
script:curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl
Hint
If you already have Erlang installed on your machine, we strongly recommend deleting it before the new installation, using the following command:
apt purge erlang*
-
Change script mode to executable by using the following command:
chmod a+x kerl
-
Update the list of Erlang releases using the following command:
./kerl update releases
-
Build the release 24.3 using the following command:
./kerl build 24.3
After installation is complete, you will see the following message in the console:
Erlang/OTP 24.3 (24.3) has been successfully built
-
Create a new subdirectory in
erlang
:mkdir /opt/erlang/<your_directory_name>
-
Install Erlang to the subdirectory you've created on step 10 using the following command:
./kerl install 24.3 /opt/erlang/<your_directory_name>
-
Run the following command to activate the Erlang installation:
source /opt/erlang/<your_directory_name>/activate
If your Erlang installation is not activated, you will NOT be able to run the Tea Ceremony and build the node.
Step 2: Download and build the node
Choose a project folder to clone your project into. Use this folder to build the node.
-
Download the node sources from Github into your working directory (
your_node
, for instance), using the following command:git clone https://github.com/thepower/tpnode.git -b e24
-
Go to
tpnode
directory, using the command:cd tpnode
-
Check and download the dependencies using the command:
./rebar3 get-deps
-
Compile the node source by running the following command:
./rebar3 compile
-
Build the release by running the following command:
./rebar3 release
-
Copy the node directory from
_build/default/rel/thepower
to/opt
by running the following command:cp -r _build/default/rel/thepower /opt
Step 3: Create directories and place the files
Hint
You can create an additional directory named
thepower
, for example, and placedb
andlog
as subdirectories there.
To create directories for files:
-
Go to your working directory using the following command:
cd /opt/thepower
-
Create
db
andlog
directories in your working directory (/opt/thepower
, for instance) using the following command:mkdir {db,log}
-
Place
genesis.txt
andnode.config
near these directories using the following commands:cp ~/tea_ceremony_directory/node.config /opt/thepower/node.config
cp ~/tea_ceremony_directory/genesis.txt /opt/thepower/genesis.txt
The private key you get with the node.config
file cannot be restored, if you lose it. Please, store it securely: place a backup onto your local machine.
Step 4: Start the node
Start the node using systemd
. To do this:
-
Create a file
tpnode.service
under/etc/systemd/system
directory. -
The file must contain the following:
[Unit]
Description=tpnode service
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/opt/thepower/bin/thepower start
ExecStop=/opt/thepower/bin/thepower stop
User=root
Group=root
Restart=on-failure
[Install]
WantedBy=multi-user.target -
Run the following command to rerun all generators , reload all unit files, and recreate the entire dependency tree. While the daemon is being reloaded, all sockets systemd listens on behalf of user configuration will stay accessible:
systemctl daemon-reload
-
Run the following command to enable the service after reboot:
systemctl enable tpnode.service
-
Start the node using the following command:
systemctl start tpnode.service
How to stop the node?
To stop the node, run:
systemctl stop tpnode.service
Step 5: Get the certificate
Obtain the SSL certificate for your node and place it into the db
directory.
How to check, if my node works?
To check, if your node works, run:
curl http://your_node.example.com:1080/api/node/status | jq
where:
your_node.example.com
— your node address;1080
— port, that your node uses forapi
.
Replace the example parameters with the ones you need.
What do I need to do if something goes wrong?
If something goes wrong, go to the log
folder, and read the logs. If there are errors, write to Power Ecosystem Telegram chat: https://t.me/thepower_chat
.
Troubleshooting
-
You get the following error:
===> Failed to boot tpnode for reason {{{badmatch,undefined},
[{nodekey,get_priv,0,
[{file,
"/home/thepower/tpnode/apps/tpnode/src/nodekey.erl"},
{line,26}]},
{tpic2,certificate,0,
[{file,
"/home/thepower/tpnode/apps/tpic2/src/tpic2.erl"},
{line,196}]},
{tpic2,
'-childspec/0-fun-0-',2,
[{file,
"/home/thepower/tpnode/apps/tpic2/src/tpic2.erl"},
{line,217}]},
{tpic2,childspec,0,
[{file,
"/home/thepower/tpnode/apps/tpic2/src/tpic2.erl"},
{line,229}]},
{tpnode_sup,init,1,
[{file,
"/home/thepower/tpnode/apps/tpnode/src/tpnode_sup.erl"},
{line,88}]},
{supervisor,init,1,
[{file,"supervisor.erl"},
{line,295}]},
{gen_server,init_it,2,
[{file,"gen_server.erl"},
{line,374}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},
{line,342}]}]},
{tpnode,start,[normal,[]]}}Reason
You don't have
genesis.txt
andnode.config
files.Solution
Start the Tea Ceremony client BEFORE starting the node. It will get proper
genesis.txt
andnode.config
. -
You get the following error when starting the Tea Ceremony client:
~/tpnode# ./teaclient DEE570BD76F3
-bash: ./teaclient: Permission deniedReason
Probably, you haven't changed
teaclient
file mode to executable.Solution
Change
teaclient
file mode to executable by running the following command:chmod +x tea*
-
You get the following error when starting the Tea Ceremony client:
~# ./teaclient -n demonode05 DEE570BD76F3
ceremony client connecting to tea.thepower.io:443
Server rejects connection, reason: bad_tokenReason
Token
DEE570BD76F3
has been used by another user.Solution
Get the new token from the Telegram bot.
-
You get the following error when starting the Tea Ceremony client:
ceremony client connecting to knuth.cleverfox.ru:1436
=WARNING REPORT==== 19-Oct-2022::14:32:54.056133 ===
Description: "Authenticity is not established by certificate path validation"
Reason: "Option {verify, verify_peer} and cacertfile/cacerts is missing"
Server rejects connection, reason: you_are_lateReason
You are late for the tea ceremony.
Solution
Stick to the bot recommendations and don't be late.
-
You see different ports displayed in server control panel and written in firewall rules.
Reason
Problems with ports.
Solution
Check your
iptables
rules:iptables -L -nv
Find the rules for all three ports among the entries:
- If the rules are absent, please contact or tech support in our Telegram chat.
- If you've found a corrupted port, try to recreate rule using the server control panel.
warningThe Power Ecosystem is not responsible for the result of actions described below! These actions can lead to loss of access to the server.
Another way of addressing the problem is to:
-
Save the rules into a file using the following command:
iptables-save -f iptables.save
-
Edit the corrupted port:
vim iptables.save
-
Restore the rules from the file:
iptables-restore iptables.save