Deploy of Tron Node

Updated on 05.05.2020
As every SR and SR candidate we from TronLabs Romania had to deploy our nodes. The first ones ran on Ubuntu 16.04 LTS but now we’ve updated to Ubuntu 18.04 LTS. This guide has now been updated for Ubuntu 20.04 LTS.

Here is a guide how you can deploy a tron node, regardless if it’s a witness, a full node or a solidity node.

Note:
The Solidity Node is deprecated as the Full Node does take over all of its functions.


Part 1 – The base installation.

This is common for all 3 types.

First check the System requirements
Witness Node – minimum 16 CPU*, min 32 RAM and 1 TB HDD**.
Full Node – minimum 16 CPU*, min 16 Gb RAM and 1 TB HDD**.

Note:
*) Witness node runs the Tron Virtual Machine. TVM. You need the above CPU and RAM values as this is the minimum ! Solidity and Full nodes are not that demanding. Based on the volume and transactions, you can go as low as 2-4 CPU in the current state.
**) DISK capacity depends on the actual transaction volume after deployment, but it’s always better to leave some excess capacity.

The Node can run on Ubuntu 18.04 LTS or Ubuntu 20.04.LTS

Steps:
a) Download the Ubuntu images from these links for Ubuntu 18.04 LTS or Ubuntu 20.04 LTS. Pick the ubuntu-18.04.1-live-server-amd64.iso or the ubuntu-20.04-live-server-amd64.iso and install it on a VM or physical server.
b) During the installation you are asked to set your network settings, define the host name, the user and also choose if you want a specific partitioning for it (with and without LVM). We are not going to cover this as it’s pretty much generic and you should have no trouble doing it. A base image will be provided via our git later with a default user and password that can be used in the lab.
c) As soon as the system has rebooted and you’ve logged with your previously defined user we can proceed with the steps below.

– edit the sources list to add universe

 sudo nano /etc/apt/sources.list 

Add universe at the end of each line like you see in the example below. Then press F2 to Save, click Y to confirm that you save and then ENTER to keep the file name.

 
deb http://archive.ubuntu.com/ubuntu bionic main universe
deb http://archive.ubuntu.com/ubuntu bionic-security main universe
deb http://archive.ubuntu.com/ubuntu bionic-updates main universe

– update the package sources and upgrade the system

 sudo apt-get update && sudo apt-get -y upgrade  

it will fetch the sources list and then upgrade the system with new versions of the installed packages

– next we need to install the required packages to perform the build. this includes git, curl, wget, etc

 sudo apt-get -y -V install build-essential git git-core locate curl libcurl4-openssl-dev wget javascript-common libjs-jquery libcap2-bin software-properties-common unzip zip unattended-upgrades libcap2-bin aptitude  

– next we install npm

 sudo aptitude install npm  

– then we install Java via Oracle JDK. Please note that Open JDK does not work. As we need to install Oracle JDK you will need to register an account with Oracle first and download the file jdk-8u251-linux-x64.tar.gz from here. Once you have it available in your home directory you can proceed with the commands below.

sudo mkdir -p /usr/lib/jvm/
sudo tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/lib/jvm/
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_251/bin/java 1

Java should now be installed. Check the Java version using the following command.

java -version

Output

java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

– and the last step is to install grpc because it’s needed for the protobuf

 sudo npm install grpc  

Now the base installation is ready and you can proceed with the specific role installation.


PART 2 – Deploy Witness Node

– we clone the java-tron git master

 git clone https://github.com/tronprotocol/java-tron.git  

– then we need to fix 1 single file (build.gradle) from the java-tron folder, because the build will fail due to issues with the Maven repository.

 
cd java-tron
nano build.gradle

You need to change this two URL’s for the Maven repository. The first is on Line Nr. 3 and the second is on line Nr. 49. change the url from maven { url ‘http://mvnrepository.com’ } to maven { url ‘http://central.maven.org/maven2/’ }

  maven { url 'http://central.maven.org/maven2/' }  

This is the example for the first change of line 3

 
buildscript {
    repositories {
        maven { url 'http://central.maven.org/maven2/' }  
        mavenCentral()
        jcenter()
    }

This is the example for the second change of line 47

 
repositories {
    maven { url 'http://central.maven.org/maven2/' }   
    mavenLocal()
    mavenCentral()
    maven { url 'http://repo.spring.io/plugins-release' }

Save the File by Pressing F2, they confirm with Y and press ENTER

now we build it

 ./gradlew build 
 ./gradlew clean ShadowJar

Just be patient. based on the number of current CPU cores this build process goes faster or slower.

When ready you can use one of these 3 ways to start it

Method 01 – From command line (example from the official tron documentation)

java -jar FullNode.jar -p 650950B193DDDDB35B6E48912DD28F7AB0E7140C1BFDEFD493348F02295BD812 --witness -c /data/java-tron/config.conf

Method 02 – Via a simplified script

kill -9 `cat /home/tron/pid.txt`
nohup  java -jar /home/tron/java-tron/java-tron.jar -p $LOCAL_WITNESS_PRIVATE_KEY --witness -c /home/tron/config.conf > /home/tron/tron-shell.log 2>&1 & echo $! >/home/tron/pid.txt 

the nohup will allow it to run in the background.

Method 03 – via the work.sh script in the java-tron directory
You need to adapt the settings and variables to match yours. it will allow you to start, stop and restart it


Part 3 – Deploy Full Node

There is a tron deployment script available on the official git (https://github.com/tronprotocol/tron-deployment)

Note (05.10.2018)
Unfortunately since the build.gradle file is broken and the maven repository has issues the below ways will fail. You need to

Deployment of FullNode on the one host.

wget https://raw.githubusercontent.com/tronprotocol/TronDeployment/master/deploy_tron.sh -O deploy_tron.sh
bash deploy_tron.sh
Deployment of FullNode and SolidityNode on the same host.
 
# You need to configure different gRPC ports on the same host because gRPC port is available on SolidityNode and FullNodeConfigure and it cannot be set as default value 50051. In this case the default value of rpc port is set as 50041.
wget https://raw.githubusercontent.com/tronprotocol/TronDeployment/master/deploy_tron.sh -O deploy_tron.sh
bash deploy_tron.sh --app FullNode
bash deploy_tron.sh --app SolidityNode --rpc-port 50041

Workarounds:
We’ve forked the official java tron and corrected the build gradle file. You can get it and build from here

 
git clone https://github.com/myitlabro/java-tron
cd java-tron
./gradlew build 
./gradlew clean ShadowJar
The finished java build for the Full node can be found under the /build/libs subfolders of java-tron
FullNode.jar
java-tron-1.0.0.jar
java-tron.jar
KeystoreFactory.jar
SolidityNode.jar

Just start it with

nohup java -jar /home/tron/java-tron/java-tron.jar -c /home/tron/config.conf >> start.log 2>&1 &

Part 4 – Performance test

You can test the performance of your VM and generate a recommended start file

 wget https://github.com/tronprotocol/tron-deployment/blob/master/check-machine-config.sh
chmod +x check-machine-config.sh
./check-machine-config.sh

This is how it looks for us

And here are the contents of the start-recommend.sh file generated by the script

#!/bin/bash
kill -9 `cat /home/tron/pid.txt`
nohup java -Xmx51610m -jar /home/tron/java-tron/java-tron.jar -p $LOCAL_WITNESS_PRIVATE_KEY --witness -c /home/tron/config.conf > /home/tron/tron-shell.log 2>&1 & echo $! >/home/tron/pid.txt