Setting up a 4-node Service Chain
Last updated
Last updated
This section covers how to set up a multi-node ServiceChain. We will set up a 4-consensus-node ServiceChain with chainID
1002, as you can see in the blue border box in the figure below.
Download packages for kscn
, homi
binary from Download.
4 Linux or MacOS servers
Minimum hardware requirements
CPU: 4-core (Intel Xeon or equivalent), RAM: 16GB, HDD: 50GB
Please refer to System Requirements for more explanation.
The installation is the uncompression of the downloaded package. Extract the SCN archive on each server.
For the convenience, we will add the binary path to $PATH. Use the actual path on your node.
SCN also provides various RPM distributions like RHEL, CentOS, and Fedora. For more information, please refer to Installation.
We will use homi utility to generate the needful files. homi
is a utility that automatically generates scripts, configuration files, and private keys necessary to configure the Klaytn blockchain. You can execute homi from any Linux/Mac PC.
First, extract the homi archive you downloaded.
Go to the bin
folder and execute homi
with following options to generate the files. homi setup --gen-type local --cn-num 4 --test-num 1 --servicechain --chainID 1002 --p2p-port 22323 -o homi-output
Since Baobab's chainID
is 1001, for convenience, the chainID
of the ServiceChain constructed in this example is set to 1002. When operating a blockchain by launching an actual service, it is recommended to use it after registering a new chainID value at https://chainlist.defillama.com/ so that chainID does not overlap with other ServiceChains. The ServiceChain port is set to 22323, which is the default port.
Among the outputs, we will use nodekey*
, genesis.json
and static-nodes.json
in the subsequent steps.
Open homi-output/scripts/static-nodes.json
in a text editor then update the IP addresses and ports with the actual values of your nodes. In this example, it is assumed that the IP of each SCN node in the ServiceChain is as shown in the figure below. Remember the port you assigned here, as it will be used later in step 4.
After you update static-nodes.json
, upload the output folders(homi-output
) to all SCNs, i.e. SCN-L2-01, SCN-L2-02, SCN-L2-03, SCN-L2-04 nodes in this example.
Now, we will initialize each node using the genesis file. On each node, execute the following command. It will create the data folder storing the chain data and logs on your home directory. You can change the data folder using the --datadir
directive. In this example, we set the data folder to \~/data
.
nodekey
and static-nodes.json
On every SCNs, copy static-nodes.json
to the data folder.
In step 1, we generated 4 nodekeys. Assign each node key to the SCN and copy the matching nodekey
to each SCN's data folder. For example, use nodekey1
for SCN-L2-01(192.168.0.1) node and use nodekey2
, nodekey3
and nodekey4
for SCN-L2-02(192.168.0.2), SCN-L2-03(192.168.0.3) and SCN-L2-04(192.168.0.4) respectively.
On every SCNs, go to the kscn installation folder and edit conf/kscnd.conf
as follows. PORT
is the port used to set up homi
, and SC_SUB_BRIDGE
is required for connecting bridges in the next section. For now, just set it to 0. In DATA_DIR
, enter the data folder used in step 3.
Execute the following command on all SCN nodes.
You can check block generation status by watching klay.blockNumber
. If this number is not 0, the node is working fine.
If you want to stop a node, you can use the command kscnd stop
Now the 4-node ServiceChain is up and running. We will execute a value transfer transaction in the ServiceChain to confirm the installation.
testkey1
was automatically generated by homi
in step 1. KLAY is allocated to the test account as described in the genesis.json
which was also generated by homi
.
Unlocking the account is possible only through the console of the SCN node that imported testkey1
.
The simplest form of ServiceChain is having one SCN. The ServiceChain illustrated in this tutorial is a 4-node ServiceChain. You can, however, set up a single-node ServiceChain if you wish. Simply pass --cn-num 1
instead of --cn-num 4
to homi in 'Step 1:Create genesis.json and nodekeys'.
At least 4 nodes are required to tolerate byzantine faults. Therefore, the minimum number of SCNs to achieve high availability under the BFT algorithm is 4. Having 2 SCN nodes is not enough, because if one SCN fails, the other one cannot reach a consensus on its own.