Skip to main content

Configure high availability

If only one bridge is used in the ServiceChain, that bridge can become a single point of failure. To solve this, we describe how you can build an HA system with two or more bridges. As shown in the figure below, configure the bridges to be connected in at least two pairs, so that even if there is a problem in one bridge connection, data anchoring and value transfer between chains can still work normally through the other bridge.

Prerequisites ​

  • The main bridge of the EN and the sub bridge of the SCN are connected. If it's not, please refer to Kairos connection to establish the connection.
  • This section describes how to add an extra bridge between Kairos and a ServiceChain. In the same way, you can also set up HA by adding another bridge.

Step 1: Adding another Bridge between EN-SCN ​

In Connecting to Kairos, we assume that the EN and the SCN connected by a bridge as EN-01 and SCN-L2-01, respectively. In this section, we will add another bridge between EN-02 and SCN-L2-02. Since it follows the same procedure, we will briefly explain.

After building EN-02, set SC_MAIN_BRIDGE to 1 in conf/kend.conf and restart ken on EN-02.


SC_MAIN_BRIDGE=1

Check the KNI information of EN-02 by the following command:


EN-02$ ken attach --datadir ~/data
> mainbridge.nodeInfo.kni
"kni://eb8f21df10c6562...25bae@[::]:50505?discport=0"

Log in to SCN-L2-02, and create main-bridges.json with the KNI of EN-02. Please make sure that it should be in the JSON array format with a square bracket.


SCN-L2-02$ echo '["kni://eb8f21df10c6562...25bae@192.168.0.5:50505?discport=0"]' > ~/data/main-bridges.json

On the shell of SCN-L2-02, edit kscn-XXXXX-amd64/conf/kscnd.conf as described below. To connect a bridge, set SC_SUB_BRIDGE to 1. SC_PARENT_CHAIN_ID is set to Kairos's chainID 1001. SC_ANCHORING_PERIOD is the parameter that decides the period to send an anchoring transaction to the parent chain. In this example, an anchor transaction is submitted to the parent chain (Kairos) for every 10 child blocks.


...
SC_SUB_BRIDGE=1
...
SC_PARENT_CHAIN_ID=1001
...
SC_ANCHORING_PERIOD=10
...

If you restart ken on EN-02, a bridge will be connected automatically between the EN-02 and the SCN-L2-02 and data anchoring will start from the point where the connection is made as shown in the figure below.

After adding the bridge between EN-02 and SCN-L2-02, you can now see the connection between the nodes are established as shown in below.

Step 2: Registering and Subscribing the Bridge Contract ​

As shown in the figure above, the bridge contract is registered only in EN-01 and SCN-L2-01.

Connect to the SCN-L2-02 console and run the APIs for bridge registration, bridge subscription, and token registration. The bridge and token contract were created while deploying the bridge contract with EN-01 and SCN-L2-01 in step 2 of Cross-Chain Value Transfer.


$ kscn attach --datadir ~/data
> subbridge.registerBridge("0xCHILD_BRIDGE_ADDR", "0xPARENT_BRIDGE_ADDR")
null
> subbridge.subscribeBridge("0xCHILD_BRIDGE_ADDR", "0xPARENT_BRIDGE_ADDR")
null
> subbridge.registerToken("0xCHILD_BRIDGE_ADDR", "0xPARENT_BRIDGE_ADDR", "0xCHILD_TOKEN_ADDR", "0XPARENT_TOKEN_ADDR")
null

In the bridge contract, information about adding an extra bridge should be updated. The erc20/erc20-addOperator4HA.js script of service-chain/value-transfer registers the operators of the extra bridge in the bridge contracts deployed in Cross-Chain Value Transfer.

First, check the operator addresses of the extra bridge on SCN-L2-02 and add them to bridges in common/bridge_info.json.


$ kscn attach --datadir ~/data
> subbridge.childOperator
"0x2ed72a9d7fe5da7672fd21567e07302431649b0b"
> subbridge.parentOperator
"0x5f4d5ac6da5d2d1f0af0e1bd8bc85a43a0ba41c5"


"bridges": [
{
"child": { "operator": "0x10221f7f9355017cd0c11444e7eecb99621bacce" },
"parent": { "operator": "0x3ce216beeafc62d20547376396e89528e1d778ca" }
},
{
"child": { "operator": "0x2ed72a9d7fe5da7672fd21567e07302431649b0b" },
"parent": { "operator": "0x5f4d5ac6da5d2d1f0af0e1bd8bc85a43a0ba41c5" }
}
]

Only the owner of a bridge contract can register operators. erc20-deploy.js transferred the ownership of the bridge contracts to the operators of SCN-L2-01, so the script has to be signed with their keys. SCN-L2-01 keeps them in ~/data/child_bridge_account and ~/data/parent_bridge_account, each with the keystore file and its password file. Copy these two directories to the machine running the script and pass their paths to it. Run the script in the erc20 directory, where transfer_conf.json was created by erc20-deploy.js.


$ cd erc20
$ CHILD_OWNER_KEYSTORE=/path/to/child_bridge_account \
PARENT_OWNER_KEYSTORE=/path/to/parent_bridge_account \
node erc20-addOperator4HA.js

warning

The bridge account directories contain the operator keystores together with their plaintext passwords, which give full control of the operator accounts. Delete the copies after running the script.

When there are multiple bridges, value transfer can be provided more safely by setting a threshold. Value transfer can be enabled only when an operator above the threshold normally requests value transfer. For example, as in the current example, if there are two bridge pairs and the threshold is set to 2, value transfer can be provided only when both are normally requested. That is, even if one bridge is attacked and sends an abnormal request, it can be prevented. The script sets the threshold to the number of bridges in bridge_info.json. To use a different value, set THRESHOLD when running it, e.g. THRESHOLD=1 node erc20-addOperator4HA.js.

The script sends transactions from the operator accounts of SCN-L2-01 outside of the node. After it completes, restart kscn on SCN-L2-01 so that its sub-bridge reloads the nonce of the operator accounts.


SCN-L2-01$ kscnd stop
SCN-L2-01$ kscnd start

When registration is completed, a bridge contract is registered in both EN-02 and SCN-L2-02 as shown in the figure below to configure HA.

When two or more bridge pairs are connected for HA, data anchoring transactions for the same block occur more than once, and value transfer transactions can also occur multiple times. That is, additional fees are required.

Make this page better