Welcome to Trinity documentation

Trinity documentation

Trinity Network Configuration Guide

[TOC]

note:Trinity routing nodes require the configuration environment be no less than python3.6.As Trinity develops, this file may not apply to the new version. This file was tested on Ubuntu16.04 desktop.

Trinity Runtime Environment Preparation

Install system library and system tools

sudo apt-get install screen git libleveldb-dev libssl-dev g++

Install mongodb and launch the service

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

sudo apt-get update

sudo apt-get install mongodb-org

sudo service mongod start

Ref:mongodb configuration details, please visit: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Configure python3.6

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:jonathonf/python-3.6

sudo apt-get update

sudo apt-get install python3.6 python3.6-dev

Install pip3.6

sudo wget https://bootstrap.pypa.io/get-pip.py

sudo python3.6 get-pip.py

Install virtualenv

sudo pip3.6 install virtualenv

Get Trinity Source Code

git clone https://github.com/trinity-project/trinity.git /home

Open trinity source code catalo

cd /home/trinity

Create and activate virtual environment

virtualenv -p /usr/bin/python3.6 venv

source venv/bin/activate

Install trinity node requirement package

pip install -r requirements

Install Trinity Routing Node Gateway

Open gateway configuration file

vi gateway/config.py

Find’cg_public_ip_port = “localhost:8089”’ and Put user’s public ip address at the localhost

eg:cg_public_ip_port = “8.8.8.8:8089”

Create a new session window

screen -S TrinityGateway #TrinityGateway: 用户可替换该名称

Enter virtual environment

source venv/bin/activate

Run the Gateway service

python start.py

The code below indicates the Gateway successfully started

###### Trinity Gateway Start Successfully! ######

Use ctrl+a+d to close current TrinityGateway session window

Note: call the function below to re-open the existing TrinityGateway session window

screen -r TrinityGateway

Install Trinity Routing Node Wallet

Revise configuration file

vi wallet/configure.py 

The default configure file applies to the testnet, for which configure_testnet.py and configure_mainnet.py co-exist in the wallet catalog. For the mainnet, simply copy configure_mainnet.py and paste it to configure.py.

Please refer to notes for configuration details.

Create a new session window

    screen -S TrinityWallet

Activate python3.6 virtualenv

   source venv/bin/activate

Run the Gateway service(Enter trinity/ wallet source code catelog)

  • Mainnet Wallet
    python3.6 prompt.py -m
  • Testnet Wallet
   python3.6 prompt.py

close or reopen the gateway session please refer to the details of ‘run the gateway service’

Channel Nodes Interworking

After trinity CLI wallet running, the subsequent channel and wallet operations can be performed on the wallet console.

Input help to the wallet console to view all trinity CLI wallet commands.

Here are a few channel-related commands:

1.Use create wallet command to create an address before using state channels.

trinity> create wallet /root/test/test.json # /root/test/test.json is the path of wallet

2.Use open wallet command to open existing wallet. Note: open a wallet with channel function, or the function will be restricted.

trinity> open wallet /root/test/test.json

Note:After creating or re-opening a wallet, the wallet will automatically connect to the gateway and enable channel function. If channel function was not enabled within 30s, please call channel function to open it manually

3.Use channel enable command to activate channel function before operating on state channels.

trinity> channel enable 

4.channel show uri

trinity> channel show uri

5.Use channel create

trinity> channel create xxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 80000

6.Call channel tx to execute off-chain transactions. tx parameters supports pymentlink code, or use uri + asset + value

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # payment link code

or

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 10

7.Call channel payment to generate payment code

trinity> channel payment TNC 10 "mytest"

8.Call channel close to complete settlement and close the channel

trinity> channel close xxxxxxxxxxxxxxx

9.channel peer is for peer node review

trinity> channel peer

Trinity-ETH Network Configuration Guide

Note: Trinity node deployment process requires the configuration environment be python 3.6 and above versions. As the Trinity project continues to evolve, this file may not apply to the Trinity network released in the future; this file was tested on Ubuntu 16.04.

Trinity Runtime Environment Preparation

Description: Trinity is developed based on Python 3.6. A very useful tool with python is virtualenv, which is used to build an isolated virtual python environment for the project. It is key to maintain a clean environment during configuration. This file recommends using vitraulenv to keep you in the process of building a node. Details of virtualenv can be found at: https://virtualenv.pypa.io/ En/stable/. Another package management tool with python is Pip, which helps developer easily installed and manage the project. For more information on Pip, please refer to: https://pip.pypa.io/en/stable/
Trinity uses mongodb as local data base. Mongodb is a well-known open source no-sql database. It has high performance, easy to deploy and use for data storage. For more information about mongodb, please refer to: https ://www.mongodb.com/
The Trinity node needs to specify a public IP that can be reached in the external communication and the ports you use in the next configuration. Please make sure that the firewall does not block the ports. If you use a cloud server, please refer to your service provider document. If you use a local server, please contact your network service provider for more details.
This file uses Screen as terminals. For more info on Screen, please visit: http://man7.org/linux/man-pages/man1/screen.1.html
Install the Dependency Tools

Install system libraries and system tools

sudo apt-get install screen git libleveldb-dev libssl-dev g++

Install mongodb and launch the service

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sourcves.list.d/mongodb-org-3.6.list

sudo apt-get update

sudo apt-get install mongodb-org

sudo service mongod start

Ref: Mongodb configuration details, please visit https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Install python3.6

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:jonathonf/python-3.6

sudo apt-get update

sudo apt-get install python3.6 python3.6-dev

Install pip 3.6

sudo wget https://bootstrap.pypa.io/get-pip.py

sudo python3.6 get-pip.py

Install virtualenv

sudo pip3.6 install virtualenv

Get Trinity Source Code

git clone https://github.com/trinity-project/trinity-eth.git <your dictionary> ##get wallet code
git clone https://github.com/trinity-project/trinity-gateway.git <your dictionary> ##get gateway code

Enter the trinity-eth directory

cd <your dictionary>/trinity-eth

Create and activate a virtual environment

virtualenv -p /usr/bin/python3.6 venv

source venv/bin/activate

Install the trinity node dependency package

pip install -r requirements

Enter the wallet directory

cd <your dictionary>/trinity-eth

Create and activate a virtual environment

virtualenv -p /usr/bin/python3.6 venv

source venv/bin/activate

Install the trinity node dependency package

pip install -r requirements

Install Trinity Routing Node Gateway

Open gateway configuration file

vi gateway/config.py

Find cg_public_ip_port = “localhost:8189” in the localhost and set it as user’s public ip address. Eg: cg_public_ip_port = “8.8.8.8:8189”

Create a new session window

screen -S TrinityGateway #TrinityGateway: users can change this name

Enter virtual environment

source venv/bin/activate

Run the Gateway service

python start.py

The message below on the console indicates the Gateway successfully started.

###### Trinity Gateway Start Successfully! ######

Use ctrl+a+d to detach the current TrinityGateway session window.

Note: Call the function below to reopen the existing TrinityGateway session window

screen -r TrinityGateway

Install Trinity Routing Node Wallet

Modify configuration file

cd <your dictionary>/trinity-eth/wallet

The default configuration file applies to the testnet. Both configure_testnet.py and configure_mainnet.py exist in the wallet directory. When deploying on the mainnet, users can simply copy configure_mainnet.py into configure.py. Please refer to notes for configuration details.

Create a new session window

screen -S TrinityWallet #TrinityWallet: users can change this name

Activate python3.6 virtualenv (find it in venv directory)

source venv/bin/activate

Run the Wallet Services (find it in trinity/wallet directory)

  • Mainnet Wallet
python3.6 prompt.py -m #mainnet wallet
  • Testnet Wallet
python3.6 prompt.py #testnet wallet

To detach or resume the wallet session, please refer to the section of running gateways.

Channel Nodes Interworking

After the running of Trinity CLI wallet, the subsequent wallet and channel operations can be performed on the console. Input ‘help’ to the wallet console to view all trinity CLI wallet commands. Here are a few channel-related commands:

1.Use create wallet command to set up an address before using the channel.

trinity> create wallet <your wallet file name> 

2.Open the existing wallet. Note: The wallet to be opened should have state-channel functions, otherwise the function will be limited.

trinity> open wallet <your wallet file name>
Note: after creating or re-opening a wallet, the wallet will automatically connect to the gateway and enable channel function. If channel function was not enabled within 30s, please call channel function to open it manually.*

3.Use channel enable command to enable channel function before operating on state channels.

trinity> channel enable 

4.View the wallet uir through channel show uri command

trinity> channel show uri

5.Create channel

trinity> channel create xxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 80000 # create parameters:peer node uri(PublicKey@ip_address:port), asset_type, deposit*

6.Call channel tx to execute off-chain transactions. Use paymentlink code, or uri + asset + value as tx parameters.

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # payment link 

Or

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 10

7.Call channel payment to generate payment code

trinity> channel payment TNC 10 "mytest" # payment parameters: asset type, value,comments, comments can be empty

8.Call channel close to complete settlement and close the channel

trinity> channel close xxxxxxxxxxxxxxx #close parameters: channel name

9.Call channel peer to check peer nodes in the current channel

trinity> channel peer

Trinity中文文档

Trinity Network部署帮助文档

[TOC]

注意: Trinity 路由节点部署对python3.6有环境依赖,要求部署环境的python版本不低于python3.6。 随着Trinity项目的不断演进,本文档有可能不适用未来发布的Trinity版本;本文档使用Ubuntu16.04桌面版进行测试验证。

Trinity 运行环境准备工作

安装系统库及系统工具

sudo apt-get install screen git libleveldb-dev libssl-dev g++

安装mongodb并启动服务

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

sudo apt-get update

sudo apt-get install mongodb-org

sudo service mongod start

参考:mongodb部署相关细节请访问 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

安装python3.6

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:jonathonf/python-3.6

sudo apt-get update

sudo apt-get install python3.6 python3.6-dev

安装pip3.6

sudo wget https://bootstrap.pypa.io/get-pip.py

sudo python3.6 get-pip.py

安装virtualenv

sudo pip3.6 install virtualenv

Trinity 源码包获取

git clone https://github.com/trinity-project/trinity.git /home

进入trinity源码目录

cd /home/trinity

创建及激活虚拟环境

virtualenv -p /usr/bin/python3.6 venv

source venv/bin/activate

安装trinity节点依赖包

pip install -r requirements

Trinity 路由节点网关部署

打开gateway配置文件

vi gateway/config.py

cg_public_ip_port = "localhost:8089"中的localhost配置为用户自己的公网ip地址。

如:cg_public_ip_port = “8.8.8.8:8089”

新建会话窗口

screen -S TrinityGateway #TrinityGateway: 用户可替换该名称

进入虚拟环境

source venv/bin/activate

运行网关服务

python start.py

控制台输出如下消息启动成功

###### Trinity Gateway Start Successfully! ######

使用ctrl+a+d键盘按键退出当前TrinityGateway会话窗口

注:若需要重连已创建的名为TrinityGateway的会话窗口,可使用如下命令

screen -r TrinityGateway

Trinity 路由节点钱包部署

修改配置文件

vi wallet/configure.py 

默认configure文件为测试网配置文件,同时在wallet目录下有configure_testnet.py和configure_mainnet.py两个配置文件,如果部署主网可简单将configure_mainnet.py的内容复制到configure.py中。 具体配置信息请参考配置文件注释说明。

创建新窗口会话

    screen -S TrinityWallet #TrinityWallet: 用户可替换该名称

激活python3.6 virtualenv(进入到venv所在的文件夹目录)

   source venv/bin/activate

运行钱包服务(进入trinity/wallet源码目录)

  • 主链钱包
    python3.6 prompt.py -m #主链钱包
  • 测试网钱包
   python3.6 prompt.py #测试网钱包

退出或重连网关会话请参考网关运行章节中的内容。

Channel节点交互

trinity CLI钱包运行之后,即可在钱包控制台进行钱包及通道的相关操作了。

钱包控制台输入help查看所有trinity CLI钱包命令。

这里仅介绍几个和通道相关的命令:

1.使用状态通道前,需要先使用create wallet 命令创建一个地址。

trinity> create wallet /root/test/test.json # /root/test/test.json 为钱包文件路径

2.open wallet 打开已有钱包,注意:这里应该打开带有通道功能的钱包,否则通能功能将被限制。

trinity> open wallet /root/test/test.json

注: 新建钱包或打开钱包以后,wallet会主动连接gateway并打开channel功能,如果30s内没有自动打开channel功能,请使用以下命令手动打开channel功能.

3.channel enable命令进行channel功能的使能,只有使能channel功能之后才能进行状态通道相关的其他操作。

trinity> channel enable 

4.channel show uri 查看钱包uri

trinity> channel show uri

5.channel create创建通道。

trinity> channel create xxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 80000 
# create 后的参数:peer节点uri(PublicKey@ip_address:port), asset_type, depoist

注: TNC押金数量是以800美金的价格计算。假设当前TNC价值1美金,那最低需要800个TNC才能保障通道建立成功,可以通过如下命令获取当前时间所需要的TNC押金,目前这条规则仅对TNC通道有效

6.channel depoist_limit查看当前TNC押金最小值。

trinity> channel depoist_limit

7.channel tx命令进行状态通道的链下交易操作,tx后的参数可以支持paymentlink码,也可以是uri + asset + value。

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # payment link 码

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 10

8.channel payment生成付款码。

trinity> channel payment TNC 10 "mytest" # payment 后面的参数是 asset type, value,comments, comments可以为空

9.channel close命令进行状态通道的结算并关闭通道。

trinity> channel close xxxxxxxxxxxxxxx #close后的参数为 channel name

10.channel peer查看当前channel的peer节点

trinity> channel peer

Trinity-Eth Network部署帮助文档

注意: Trinity 路由节点部署对python3.6有环境依赖,要求部署环境的python版本不低于python3.6。 随着Trinity项目的不断演进,本文档有可能不适用未来发布的Trinity版本;本文档使用Ubuntu16.04桌面版进行测试验证。

Trinity 运行环境准备工作

说明:Trinity采用python3.6开发,在python开发中一个非常有用的工具virtualenv是用来建立一个虚拟的python环境,一个专属于项目的python环境。用virtualenv来保持一个干净的环境非常有用, 本文档也推荐在搭建节点的过程中使用virtaulenv创建一个虚拟环境,更多virtualenv的文档请参阅:https://virtualenv.pypa.io/en/stable/, 同时,python中pip是python的包管理工具可以方便的安装和管理项目所需要的依赖库,更多关于pip的资料请参阅: https://pip.pypa.io/en/stable/
Trinity中使用了mongodb作为本地数据,mongodb是一款著名的开源no-sql数据库,有着高性能、易部署、易使用,存储数据非常方便的显著特点,更多关于mongodb的资料请参阅:https://www.mongodb.com/
Trinity节点在对外通信过程中需要指定您可达的公网ip以及您在接下来配置中用的端口,请确保防火墙没有将其关闭,如果您是购买的云服务器请参阅您的服务商文档,如果您使用的是本地服务器,请详细咨询你的网络服务商。
本文使用screen作为会话窗口,更多screen的使用请参考:http://man7.org/linux/man-pages/man1/screen.1.html
安装依赖工具

安装系统库及系统工具

sudo apt-get install screen git libleveldb-dev libssl-dev g++

安装mongodb并启动服务

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sourcves.list.d/mongodb-org-3.6.list

sudo apt-get update

sudo apt-get install mongodb-org

sudo service mongod start

参考:mongodb部署相关细节请访问 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

安装python3.6

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:jonathonf/python-3.6

sudo apt-get update

sudo apt-get install python3.6 python3.6-dev

安装pip3.6

sudo wget https://bootstrap.pypa.io/get-pip.py

sudo python3.6 get-pip.py

安装virtualenv

sudo pip3.6 install virtualenv

Trinity 源码包获取

git clone https://github.com/trinity-project/trinity-eth.git <your dictionary> ##获取wallet代码
git clone https://github.com/trinity-project/trinity-gateway.git <your dictionary> ##获取gateway代码

进入trinity-eth源码目录

cd <your dictionary>/trinity-eth

创建及激活虚拟环境

virtualenv -p /usr/bin/python3.6 venv

source venv/bin/activate

安装trinity节点依赖包

pip install -r requirements

Trinity 路由节点网关部署

打开gateway配置文件

vi gateway/config.py

cg_public_ip_port = "localhost:8189"中的localhost配置为用户自己的公网ip地址。

如:cg_public_ip_port = “8.8.8.8:8189”

新建会话窗口

screen -S TrinityGateway #TrinityGateway: 用户可替换该名称

进入虚拟环境

source venv/bin/activate

运行网关服务

python start.py

控制台输出如下消息启动成功

###### Trinity Gateway Start Successfully! ######

使用ctrl+a+d键盘按键退出当前TrinityGateway会话窗口

注:若需要重连已创建的名为TrinityGateway的会话窗口,可使用如下命令

screen -r TrinityGateway

Trinity 路由节点钱包部署

修改配置文件

cd <your dictionary>/trinity-eth/wallet

进入到trinity-eth的wallet路径下,在该路径下默认trinity.py文件为测试网配置文件,同时在wallet目录下有trinity.py和trinity_mainnet.py两个配置文件,如果部署主网可简单将trinity_mainnet.py的内容复制到trinity.py中。 具体配置信息请参考配置文件注释说明。

创建新窗口会话

    screen -S TrinityWallet #TrinityWallet: 用户可替换该名称

激活python3.6 virtualenv(进入到venv所在的文件夹目录)

   source venv/bin/activate

运行钱包服务(进入trinity/wallet源码目录)

  • 主链钱包
    python3.6 prompt.py -m #主链钱包
  • 测试网钱包
   python3.6 prompt.py #测试网钱包

退出或重连钱包会话请参考网关运行章节中的内容。

Channel节点交互

trinity CLI钱包运行之后,即可在钱包控制台进行钱包及通道的相关操作了。

钱包控制台输入help查看所有trinity CLI钱包命令。

这里仅介绍几个和通道相关的命令:

1.使用状态通道前,需要先使用create wallet 命令创建一个地址。

trinity> create wallet <your wallet file name>

2.open wallet 打开已有钱包,注意:这里应该打开带有通道功能的钱包,否则通道功能将被限制。

trinity> open wallet <your wallet file name>

注: 新建钱包或打开钱包以后,wallet会主动连接gateway并打开channel功能,如果30s内没有自动打开channel功能,请使用以下命令手动打开channel功能.

3.channel enable命令进行channel功能的使能,只有使能channel功能之后才能进行状态通道相关的其他操作。

trinity> channel enable 

4.channel show uri 查看钱包uri

trinity> channel show uri

5.channel create创建通道。

trinity> channel create xxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 80000 
# create 后的参数:peer节点uri(PublicKey@ip_address:port), asset_type, depoist

注: TNC押金数量是以800美金的价格计算。假设当前TNC价值1美金,那最低需要800个TNC才能保障通道建立成功,可以通过如下命令获取当前时间所需要的TNC押金,目前这条规则仅对TNC通道有效

6.channel depoist_limit查看当前TNC押金最小值。

trinity> channel deposit_limit

7.channel tx命令进行状态通道的链下交易操作,tx后的参数可以支持paymentlink码,也可以是uri + asset + value。

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # payment link 码

trinity> channel tx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@xx.xx.xx.xx:xxxx TNC 10

8.channel payment生成付款码。

trinity> channel payment TNC 10 "mytest" # payment 后面的参数是 asset type, value,comments, comments可以为空

9.channel close命令进行状态通道的结算并关闭通道。

trinity> channel close xxxxxxxxxxxxxxx #close后的参数为 channel name

10.channel peer查看当前channel的peer节点

trinity> channel peer