Hello OT-DKG
Hello OriginTrail#1 — Cost-Effective Cloud Deployment of a DKG V6 Node
Setting up a Distributed Knowledge Graph V6 Node for the OriginTrail Network using Ansible Playbook automation
Introduction
In 2018 I decided to deep dive into the Web3 world and started my personal research work (backed by producing a lot of technical hands-on tutorials) in the area of Polkadot- and Kyber Network.
As part of my education journey, I wrote several Medium articles for Kyber Network and especially a Polkadot Hello World series, centered around their beta test phase of Validator nodes. Which got acknowledged by the Web3 foundation at that point in time by some small DOT donations for educating the community.
Fast-forwarding 4 years and we are in the extremely interesting launch time of the first set of Polkadot Parachains. The parachain slot auctions were kicked off in November 2021 accompanied by a lot of project community activities by the various Parachain contenders. It allowed me to get a lot of insights into what’s going on by some of the top-notch Web-3 projects.
At that point in time, I got known of OriginTrail with its Decentralized Knowledge Graph (DKG) vision. What strikes me besides their chosen approach, was the availability of a vast set of real-life industry use cases, which helps to map the sometimes digital abstract world back to the real one. That helps to gain a better understanding of the future potential also in a less non-tech manner.
As a parachain auction supporter of the Accala Parachain — the so-called DeFi Hub of Polkadot — I was more than pleased that OriginTrail went into a partnership with Accala in December 2021, so we can expect OriginTrail DKG in the Polkadot ecosystem in the near future. (taking also into consideration that a future OT own parachain may be a further option).
This convinced me to kick off a new educational deep-dive series — the main purpose is to educate myself but share the findings with the community as well— around OriginTrail Decentralized Knowledge Graph.
So let’s kickstart the
Hello OriginTrail Medium Article Series, which introduces major DKG concepts and technology from a high-level point of view.
The first article of the series will explain to you how to set up the brand new OriginTrail Decentralized Knowledge Graph Node Version 6 with the help of an Ansible Playbook.

Minimal Linux system know-how should be enough for this exercise, so let’s jump over to the necessary setup activities.
Prerequisite
Configure your Metamask Wallet for the Polygon (Matic) Network
Polygon (Matic Network) is the network to which the Origin Trail (OT) test node will connect. Polygon is a protocol and framework for building and connecting Ethereum-compatible Blockchain networks.
Polygon can be described as a layer-2 network and acts as an add-on layer to Ethereum that doesn't change the original blockchain layer. It provides a solution to Ethereum scalability problems in the context of gas feed and transaction speed and is known for its extremely low gas fees and transaction speed.
What you need for this exercise is a Polygon wallet on the Mumbai testnet. We will use the well-known Metamask wallet. Just head over to https://metamask.io/ in case you don't have it already as a browser extension.
The Medium article Guide — Accessing Polygon Testnet explains a nifty, easy way to connect your wallet to EVM powered network, which we will use below.
Open https://chainlist.org in the browser and enter the search keyword "mumbai" (1), which shows, as a result, the info tile for the Polygon test network. Click Connect Wallet (2).

Connect to chainlist with one of your accounts. It's advisable to have a dedicated MetaMask account with no economic value for testing purposes. (1).

Pressing the Next Button will be the standard confirmation form to allow the chainlist to view your Metamask address.

Pressing "Connect" redirects you back to the chainlist app.

Pressing the "Add To Metamask" button (1) pops up the Meta Mask approval dialog, showing the network configuration details.

The approval adds the network to Metamask, and you may now switch immediately to the network.

There you are. Pretty straightforward, and you can use this approach for any other EVM base project.

Get Test Tokens into your Wallet
Having Metamask configured for the Mumbai Polygon Test network, you now can request some test tokens.
You can request the tokens via the Polygon Mumbai MATIC test faucet. Just copy your Meta Mask Test account address as Wallet Address, and press submit.

Within some minutes, you have 0.5 MATIC test tokens for your exercise.

Short Intro to Polygon and MATIC
As already explained above, Polygon is a laver-2 solution for Ethereum used to build and connect Ethereum-compatible blockchains, for example, the OT Network. MATIC is the underlying crypto network token used as the currency for payments and settlements.

It's important to realize that for phase-1 of OT v6 node deployment, the OT-native token TRAC is not required.
Ok, you are done now with the prerequisites; let's head over and set up your cloud instance.
Setup a Test Environment on the Jelastic Multi-Cloud Platform as a Service
What means Multi-Cloud PAAS
I'm a big fan of the Jelastic Multi-Cloud Platform, which is available as a public, hybrid, or private cloud in over 100 data centers worldwide. There are multiple independent Service providers available in numerous jurisdictions, resulting in no vendor-lockin (or, better said, service-provider-lockin), which is quite a solid non-functional requirement in decentralized blockchain solutions.

In this example, I'm using Hidora as a service provider, which is a Swiss cloud provider, with all data centers in the Swiss jurisdictions (outside of the US- or Europe regulatory influence area). Deploying production nodes in the future in multiple jurisdictions and with numerous service providers may increase your censorship resistance and service availability (outages of regions or providers) quite dramatically.

Cloudlets the base for the Pay-as-you-use pricing model
This section is a take over of my 2018 "Hello World Polkadot" Medium series, where I described the setup of a Polkadot Validator on Hidoras using Docker.
Jelastic PaaS prices are flexible and scalable. They are based on actual consumption, so your bill reflects exactly what you use per hour.
This pricing model is based on resource units called "cloudlets." Each cloudlet accounts for 400 MHz of processor speed and 128 MB of RAM.


Jelastic PaaS offers you two types of cloudlets:
- Reserved Cloudlets are a type of cloudlets that allow getting significant automatic discount rates. A number of resources you reserve beforehand and pay for it whether you spent all resources or not.
- Dynamic Cloudlets — a type of cloudlets that allows you to pay based on your actual resource usage. Set your maximum resource consumption, and the Dynamic cloudlets will add and remove automatically depending on your site load.
So after deployment of an application, you have to do some fine-tuning in the reserved cloudlets to get an optimal price. This can be quickly done via the Dashboard in real-time without restarting any instance.
For this initial setup, i.e., running an Origin Trail node that is just consuming (and not producing) Distributed Knowledge Graph entries (DKG) of other nodes, we go with around 2.5 GB RAM. That will not be enough for later stress testing. But my tests have shown that such a constellation is running smoothly in this initial phase, below the dashboard view of a node running for 24 hours which consumed around 10'000 DKG entries. The memory is almost peaking but just enough for some first tests.

Create an Elastic VPS Node
We are setting up a System Container in Hidora, which provides us the most flexibility for the testing purpose.
It is an operating system (OS) centric solution that behaves like a standalone system, which does not require specialized software or custom images such as Docker. System containers are quite similar to virtual machines (VMs) but with very low overhead and easy management.
System containers run full-featured init systems (systemd, SysVinit, Upstart, OpenRC, etc.), which allows spawning multiple processes (e.g. OpenSSH, crond, or syslogd) inside a single container under the same OS. System containers are most suitable for traditional or legacy monolithic applications, as they allow reusing architectures, tools, and configurations implemented for VMs.

For our OT Node, we will run
- A Node.js Service
- A MySQL Service, as well as
- a GraphDB Service
Within the Jelastic Dashboard, we configure just an Elastic VPS node with Ubuntu 20.04 (1) and define as well as a Public IP Address (2). We name our environment clb-ot-v6-mumbai (3)and configure it for at least 20 cloudlets (2.5 GiB RAM and 6.4 GHz Processor Spec) (4). The estimated cost can be seen on the right. (5).

After creating the environment, it will be started and be ready in the Dashboard.

Import your public ssh key and login
As always copy, your public ssh key to the environment so that you can log in. Select the "Settings" feature (1) Which opens the Settings menu. From there, select "SSH Access" (2)and upload your public key (3), which then will be registered (4).

2) Now, to determine the connection string, switch over the "SSH Connection Tab." (1)

To connect to this dedicated machine, you have to determine the node id 1096 (2)and add it to the SSH gate URL [email protected] (3), i.e.
ssh [email protected] -p 3022

Ok, now we have an elastic VPS node running with a minimized Ubuntu 20.04. footprint.

Final step: Open the Firewall Ports
One final configuration is necessary; you have to open the firewall ports, which also can be done via the Settings.
- Open Port 7200, 8900, 9000 to access the GraphDB frontend and enable OT Node interaction with the blockchain.

You are done with the Jelastic PAAS configuration; as the next step, get ready for Ansible Playbook execution.
Ansible Playbook Preparation
What is Ansible
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems and can configure both Unix-like systems and Microsoft Windows.
You define the software installation and configuration aspects in so-called Ansible Playbooks which will be transferred to the target node via SSH and executed there. No heavyweight deployment infrastructure is required (just SSH), and its flexibility allows you to configure even the most complex node infrastructure environment ecosystems.
Obviously, you could configure, package and deploy your nodes in Docker. Still, I prefer this approach, which reduces the footprint quite dramatically (no docker runtime environment on top of a VM required) and reduces the operational complexity as well, i.e., Docker comes with its security- and configuration challenges on top of the underlying VM. With Ansible, I can fine-tune on Unix level directly.
Install Ansible Control Node
The first thing you have to do is establish an Ansible Control Node. It's the machine that runs the Ansible playbook and manages the installation of your Ansible Managed Nodes (i.e., our clb-ot-v6-mumbai ) via SSH-based interactions.
You can find the straightforward installation guide here;
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
Being based on SSH interactions, the prerequisite for a managed node is minimal, i.e., you have to enable the node for SSH interactions which we did beforehand.
I run the Ansible Control Noderun on my Windows 10 Development laptop. An Ansible Control Node doesn't run natively in Windows. Still, you can use the Windows Linux Subsystem (i.e., Ubuntu) for kicking off Ansible playbook execution and managing the playbooks itself via your Windows IDE. Installation procedure consists of just some apt commands:$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
That's it; your machine is ready to act as an Ansible Control Node and be prepared to manage any local- and cloud-based machines when it comes to installation and configuration.
Installing Ansible Galaxy Packages
For the installation of MySQLand node.js We use Ansible galaxy packages, pre-configured roles for our Playbook to automate the installation.
Roles let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure. After you group your content in roles, you can easily reuse them and share them with other users.
Execute on the Ansible Managed Node the following commands
ansible-galaxy install geerlingguy.mysql
ansible-galaxy install geerlingguy.nodejsWe have to write our roles for the other installation steps — i.e., the ot-node setup; they are part of my OT-v6 Ansible Playbook. It's time to clone the Playbook to your Ansible Managing Node.
Get the Ansible OT-v6 Ansible Playbook
You can find the Playbook on my GitHub account; clone the below repository to your Ansible Managing Node. The Playbook automates all the steps described in the Origin Trail document "Setup instruction dockerless."
The Playbook already adjusts the first configuration steps, which bring the installation closer to a production setup, i.e.
- graphdb and ot-node (node.js) runtime control will be done with the same process control system "supervisord," removing "forever" dependency, which isn't as flexible and have certain shortcomings
- introduction of dedicated Linux users which control graphdb or the ot-node, removing the dependency to run them as root, which would be bad in a production system (some work here is outstanding)
- standardization of the log writing, MySQL, graphdb, ot-node logs are directed to
/var/logwhich helps afterward in setting up a central monitoring component
We will not get into more detail about the playbook setup; this will be presented in a subsequent article.

Having cloned the repository to your local system, change it into the local repository directory in your Unix shell (i.e., from your Windows Unix Subsystem if you use a Windows machine). You will find the below directory structure.

Check out the README.md file, the package is under development, and the latest state, issues, etc., will be described there.
We are almost there to run the fully automated setup, but we have to provide some runtime environment information for the first run.
Ansible Playbook Initial Configuration
One thing to note: The Playbook is agnostic if it's used to configure a public, hybrid- or private cloud node or if it's just used to configure your machine running in your local network. As already mentioned, the only dependency is to have an Ubuntu node that allows to root-ssh from the Ansible Control node.
Configuration: Add the machine to the inventory
In the hosts.yml you define all nodes which you want to configure. There are various possibilities to group machines; in our case, we have defined a group ot_v6_mumbai with one machine ot_v6_mumbai-1. You have to adjust the ansible_host, ansible_user` (requires root rights) and potentially the ansible_port . Ansible also depends on pyhton3, which must be installed (a pretty standard that this is pre-installed).cd ./clb-origin-trail-v6-node/inventory
more hosts.yml
---ot_v6_mumbai:
hosts:I
ot_v6_mumba1_1:
ansible_host: gate.hidora.com
ansible_python_interpreter: /usr/bin/python3
ansible_user: 109622-2082
ansible_port: 3022
BTW, you can add as many machines as you want below the hosts section, which would be configured.
Configuration: Get the graphdb package distribution zip
Unfortunately graphdb isn't available as an apt package, and you have to download the distribution zip manually after registering on their site. They are also offering Unix packages, which I tried to use first. Still, specific files are missing in the packages available in the distribution zip and are required according to the OT installation guide.
Please visit their official website and fill out a form, and after having downloaded, the distribution.zip move it into the download folder.cd ./clb-origin-trail-v6-node/roles/graphdb/download
ls
graphdb-free-9.10.1-dist.zip
Configuration: Adjust the Ansible Variables
Change to the vars directory and check that the graphdb_versionattribute value reflects the downloaded file name above (excluding the -dist.zip postfix). The other parameters are fine for the first testing phase OT-v6cd ./clb-origin-trail-v6-node/vars
more main.yml
graphdb_version: graphdb-free-9.10.1
mysql_databases:
- name: operationaldb
encoding: utf8
ot_env: "testnet"
ot_blockchain_title: "Polygon"
ot_network_id: "polygon::testnet"
ot_rpcEndpoints: "https://rpc-mumbai.maticvigil.com/"
Configuration: Adjust the Ansible Secret Variables
Finally switch to vars_secret directory where you will find a template file, which you have to copy over to a file in the same directory with the name main-template.yml and insert sensitive information, like passwords, private keys, etc.cd ./clb-origin-trail-v6-node/secret_vars
more main.yml
mysql_root_password: ""
wallet_public_key: ""
wallet_private_key: ""
graph_db_pwd: ""
Apart from the wallet_public_key the data should never be shared with anybody or checked in a public repository. Git-wise, the directory is configured that it main.yml will never be checked in.
The wallet_private_key you can extract from Metamask via the Account Details menu.

That's it; you should now be ready to run a fully automated installation, which you can easily repeat at any time or introduce new machines to be set up from scratch.
As already mentioned, we will deep dive in a subsequent article into the Ansible playbook and explain its configuration, roles, assets in detail. For today just some information where you can find the playbook configurationcd ./clb-origin-trail-v6-node
more inventory.yml
---
# Origin Trail Version 6 Node Setup Playbook
# Works on Ubuntu System with Architecture x86_64
# By: [email protected]
# References:
# https://docs.origintrail.io/dkg-v6-upcoming-version/setup-instructions-dockerless
# https://severalnines.com/database-blog/introduction-mysql-deployment-using-ansible-role
- name: Installation of Origin Trail V6 Node
become: yes
hosts: ot_v6_mumbai
remote_user: root
vars:
nodejs_install_npm_user: root
vars_files:
- vars/main.yml
- vars_secret/main.yml
roles:
- common
- graphdb
- { role: geerlingguy.mysql }
- { role: geerlingguy.nodejs }
- origintrail
The roles section is referencing the installation roles, which can be found in the ./roles directory, mysql and nodejs are installed via standard Ansible Galaxy packages (see the section above).
Ansible Playbook Execution
Finger crossed, let's run the Playbookcd ./clb-origin-trail-v6-node
./run.sh
Ansible will log the installation progress and provide the status for each task. I.e., when you run the command multiple times, Ansible will report back if the task was necessary or skipped because the configuration was already there. So the playbook run command is idempotent and can run as many times as required. I.e., you can change a configuration file and re-run the Playbook; it will detect the delta changes and run only the subset of tasks. After completion, there is PLAY RECAP gives you a general overview, you should have only "ok" or "changed" states.

Ansible Managed Node Verification
If the Playbook terminated successfully, it's time to log in to your brand new Origin Trail Node V6 node via SSH as root.
Step 1: Verify runtime status of otnode and graphdbroot@node
-clb-ot-v6-mumbai:~# supervisorctl status
graphdb RUNNING pid 205323, uptime 0:30:54
otnode RUNNING pid 205428, uptime 0:26:54
graphdb and otnode should be both running.
Step 2: Checking the MySQL runtime status
The running of MySQL can be checked via the following commands. operationaldb is instance created by the ot-node installation script

Step 3: Check the otnode logs
Change to the /var/log/otnode folder and check the supervisor-out.log. You should see entries like the one below, which states the processing of DKG events and their insertion into the graphdb.root@node1:~# cd /var/log/otnode/
root@node1:/var/log/otnode# ls -lrt
total 27988
-rw-r--r-- 1 root root 6865 Jan 8 19:13 supervisor-err.log
-rw-r--r-- 1 root root 28646396 Jan 9 07:52 supervisor-out.log
root@node1:/var/log/otnode# tail -f supervisor-out.log
[2022-01-09 07:52:36] INFO: Sending response from QmU5Yqpot.....
[2022-01-09 07:52:41] INFO: Receiving message from QmPLnFc82
[2022-01-09 07:52:41] INFO: Assertion 8e2a52ca0f7..... inserted
[2022-01-09 07:52:41] INFO: Sending response from QmU5Yq.....
When bootstrapping a system newly or after a reboot of it, often you will have errors in the otnode log, like the one belowroot@node1:/var/log/otnode# tail -f supervisor-out.log
at async /home/otnode/node/external/libp2p-service.js:171:36
[2022-01-09 16:40:09] ERROR: Data received:
[2022-01-09 16:40:18] INFO: Receiving message from QmYfVTsGmHFkwvuxtKWS3Abf5CpP85NeaR1LrgqFBnyjzB to QmXJJ9j5KC4ZJBoT7KLHg11hjA8ZFwxeBZN2t7WV6Q5vRX: event=/store;
[2022-01-09 16:40:18] ERROR: TypeError: Cannot read property 'overwrite' of undefined
at GraphdbService.insert (/home/otnode/node/external/....
at DataService.insert (/home/otnode/node/modules/service/....
at PublishService.handleStore (/home/otnode/node/modules/service/publish-service.js:23:36)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async /home/otnode/node/external/libp2p-service.js:171:36root@node1:/var/log/otnode# supervisorctl restart otnode
otnode: stopped
otnode: started
This seems to be a race condition during system startup, that the graphdb wasn’t ready yet when the otnode wanted to connect to the db.
At the time being a restart of the otnode should just fix it:root@node1:~# supervisorctl stop otnode
root@node1:~# supervisorctl start otnode
By the way supervisorctl will ensure that the logs will not grow indefinitely and rolled over after some time. This definition can be found in the playbook in the following file./clb-origin-trail-v6-node/roles/origintrail/files/otnode.conf
Currently, a log file will be rolled over after reaching 5 MB and 10 files are kept. As an exercise, you could change the value and rerun the playbook. You would see that most of the steps would now be skipped apart from the supervisorctl step for the node (as well as some other steps, where Ansible cannot determine accurately if the installation was done).
Step 4: Check some DKG entries
Finally, you can also check the GraphDB entries themselves by opening the dashboard http://<yourNodeIPAddress>:7200. Login with the password you have set in the playbook configuration and select node0 (2) . Select in the left-hand menu “Explore — Graphs Overview”. This should open the below overview, (3) is listing the numbers of entries.
An ideal starting point to explore DKG entries and graphdb functionality itself. In an upcoming “Hello Origin Trail” article I will provide a high-level overview of DKG entries and how to assess them in the graphdb (just learning it now)

Wrapping up — The Cost’s
That’s it for the moment, I shifted some Ansible playbook explanation sections to an upcoming article in order to keep the article around 20 minutes ’ reading time. So just watch out for new articles.
A final note about the costs of running this node in the Swiss-based Jelastic Cloud of Hidora. I use here the Starbucks analogy which I used when setting up a Polkadot Validator in 2018.

Just to be clear, this cost figure is no indication about the costs of running a node in production. It just gives some minimal cost projections for participating in this early phase of the OT-Node Version 6 testing phase. I will readjust it in line with test phase progress, which will result in additional resource requirements on a node.
All in all, a node running for 24 hours is charged 0.83 CHF per day (= 0.9 USD), which results in monthly costs of around the price of 3 Starbuck coffees in Switzerland or 6 in Tokyo. So dependent on your global location you have to adjust your coffee consumption slightly that you can run your own Origin Trail test node.

