You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The TokenBridge is deployed on specified validator nodes (only nodes whose private keys correspond to addresses specified in the smart contracts) in the network. It connects to two chains via a Remote Procedure Call (RPC) and is responsible for:
8
+
- listening to events related to bridge contracts
9
+
- sending transactions to authorize asset transfers
10
+
11
+
Following is an overview of the TokenBridge and [instructions for getting started](#how-to-use).
8
12
9
-
The POA Bridge allows users to transfer assets between two chains in the Ethereum ecosystem. It is composed of several elements which are located in different POA Network repositories:
13
+
## POA General Bridge Overview
14
+
15
+
A POA Bridge allows users to transfer assets between two chains in the Ethereum ecosystem. It is composed of several elements located in different POA Network repositories:
10
16
11
17
**Bridge Elements**
12
-
1.An oracle written in NodeJS, contained in this repository.
18
+
1.The TokenBridge contained in this repository.
13
19
2.[Solidity smart contracts](https://github.com/poanetwork/poa-bridge-contracts). Used to manage bridge validators, collect signatures, and confirm asset relay and disposal.
14
20
3.[Bridge UI Application](https://github.com/poanetwork/bridge-ui). A DApp interface to transfer tokens and coins between chains.
15
21
4.[Bridge Monitor](https://github.com/poanetwork/bridge-monitor). A tool for checking balances and unprocessed events in bridged networks.
16
22
5.[Bridge Deployment Playbooks](https://github.com/poanetwork/deployment-bridge). Manages configuration instructions for remote deployments.
17
23
18
-
The bridge oracle is deployed on specified validator nodes (only nodes whose private keys correspond to addresses specified in the smart contracts) in the network. The oracle connects to two chains via a Remote Procedure Call (RPC). It is responsible for:
19
-
- listening to events related to bridge contracts
20
-
- sending transactions to authorize asset transfers
21
-
22
-
Following is an overview of the NodeJS bridge oracle and [instructions for getting started](#how-to-use) with the POA Bridge.
23
-
24
-
## Interoperability
25
-
26
-
Interoperability is the ability to share resources between networks. The POA Bridge is an interoperability protocol where users can transfer value (ERC20 compatible tokens and network coins) between chains in the Ethereum ecosystem. This creates opportunities to use different chains for different purposes. For example, smart contracts can allocate resource intensive operations to a sidechain where transactions are fast and inexpensive.
27
-
28
-
## Network Processes
29
-
30
-
### Network Definitions
24
+
## Network Definitions
31
25
32
26
Bridging occurs between two networks.
33
27
34
-
***Home** - or Native - is a network with fast and inexpensive operations. All bridge operations to collect validator confirmations are performed on this side of the bridge.
28
+
***Home** - or **Native** - is a network with fast and inexpensive operations. All bridge operations to collect validator confirmations are performed on this side of the bridge.
35
29
36
-
***Foreign** can be any chain, but generally refers to the Ethereum mainnet.
30
+
***Foreign** can be any chain; generally it refers to the Ethereum mainnet.
37
31
38
-
###Operational Modes
32
+
## Operational Modes
39
33
40
-
The POA bridge currently provides two operational modes, with a 3rd mode in development.
41
-
42
-
-[x]`Native-to-ERC20`**Coins** on a Home network can be converted to ERC20-compatible **tokens** on a Foreign network. Coins are locked on the Home side and the corresponding amount of ERC20 tokens are minted on the Foreign side. When the operation is reversed, tokens are burnt on the Foreign side and unlocked in the Home network.
43
-
-[x]`ERC20-to-ERC20` ERC20-compatible tokens on the Foreign network are locked and minted as ERC20-compatible tokens (ERC677 tokens) on the Home network. When transferred from Home to Foreign, they are burnt on the Home side and unlocked in the Foreign network. This can be considered a form of atomic swap when a user swaps the token "X" in network "A" to the token "Y" in network "B".
44
-
-[ ]`ERC20-to-Native`: Currently in development. Pre-existing tokens in the Foreign network are locked and coins are minted in the `Home` network. The Home network consensus engine in this case should support invocation of Parity's Block Reward contract (https://wiki.parity.io/Block-Reward-Contract.html) to mint coins per the bridge contract request.
34
+
The POA TokenBridge provides three operational modes:
45
35
36
+
-[x]`Native-to-ERC20`**Coins** on a Home network can be converted to ERC20-compatible **tokens** on a Foreign network. Coins are locked on the Home side and the corresponding amount of ERC20 tokens are minted on the Foreign side. When the operation is reversed, tokens are burnt on the Foreign side and unlocked in the Home network. **More Information: [POA-to-POA20 Bridge](https://medium.com/poa-network/introducing-poa-bridge-and-poa20-55d8b78058ac)**
37
+
-[x]`ERC20-to-ERC20` ERC20-compatible tokens on the Foreign network are locked and minted as ERC20-compatible tokens (ERC677 tokens) on the Home network. When transferred from Home to Foreign, they are burnt on the Home side and unlocked in the Foreign network. This can be considered a form of atomic swap when a user swaps the token "X" in network "A" to the token "Y" in network "B". **More Information: [ERC20-to-ERC20](https://medium.com/poa-network/introducing-the-erc20-to-erc20-tokenbridge-ce266cc1a2d0)**
38
+
-[x]`ERC20-to-Native`: Pre-existing **tokens** in the Foreign network are locked and **coins** are minted in the `Home` network. In this mode, the Home network consensus engine invokes [Parity's Block Reward contract](https://wiki.parity.io/Block-Reward-Contract.html) to mint coins per the bridge contract request. **More Information: [xDai Chain](https://medium.com/poa-network/poa-network-partners-with-makerdao-on-xdai-chain-the-first-ever-usd-stable-blockchain-65a078c41e6a)**
46
39
47
40
## Architecture
48
41
49
42
### Native-to-ERC20
50
43
51
44

52
45
53
-
### ERC20-to-ERC20
46
+
### ERC20-to-ERC20 and ERC20-to-Native
54
47
55
48

56
49
57
-
58
50
### Watcher
59
51
A watcher listens for a certain event and creates proper jobs in the queue. These jobs contain the transaction data (without the nonce) and the transaction hash for the related event. The watcher runs on a given frequency, keeping track of the last processed block.
60
52
61
53
If the watcher observes that the transaction data cannot be prepared, which generally means that the corresponding method of the bridge contract cannot be invoked, it inspects the contract state to identify the potential reason for failure and records this in the logs.
62
54
63
-
64
55
There are three Watchers:
65
56
-**Signature Request Watcher**: Listens to `UserRequestForSignature` events on the Home network.
66
57
-**Collected Signatures Watcher**: Listens to `CollectedSignatures` events on the Home network.
67
58
-**Affirmation Request Watcher**: Depends on the bridge mode.
68
59
-`Native-to-ERC20`: Listens to `UserRequestForAffirmation` raised by the bridge contract.
69
60
-`ERC20-to-ERC20` and `ERC20-to-Native`: Listens to `Transfer` events raised by the token contract.
70
61
71
-
72
62
### Sender
73
63
A sender subscribes to the queue and keeps track of the nonce. It takes jobs from the queue, extracts transaction data, adds the proper nonce, and sends it to the network.
74
64
75
65
There are two Senders:
76
-
-**Home Sender**: Sends transaction to the `Home` network.
77
-
-**Foreign Sender**: Sends transaction to the `Foreign` network.
66
+
-**Home Sender**: Sends a transaction to the `Home` network.
67
+
-**Foreign Sender**: Sends a transaction to the `Foreign` network.
78
68
79
69
### RabbitMQ
80
70
81
-
[RabbitMQ](https://www.rabbitmq.com/) is used to send jobs from watchers to senders.
71
+
[RabbitMQ](https://www.rabbitmq.com/) is used to transmit jobs from watchers to senders.
82
72
83
73
### Redis DB
84
74
85
-
Redis is used to store the number of blocks that were already inspected by watchers, and the NOnce (Number of Operation) which was used by the sender last time to send a transaction.
75
+
Redis is used to store the number of blocks that were already inspected by watchers, and the NOnce (Number of Operation) which was used previously by the sender to send a transaction.
86
76
87
-
For more information on the Redis/RabbitMQ requirements, see [#90](/../../issues/90)
77
+
For more information on the Redis/RabbitMQ requirements, see [#90](/../../issues/90). We also provide [useful commands for development](#useful-commands-for-development).
88
78
89
79
# How to Use
90
80
91
81
## Installation and Deployment
92
82
83
+
**Note:** The following steps detail the bridge deployment process for development and testing. For deployment in a production environment we recommend using the [Bridge Deployment Playbooks](https://github.com/poanetwork/deployment-bridge/tree/master/bridge-nodejs).
84
+
93
85
#### Deploy the Bridge Contracts
94
86
95
87
1.[Deploy the bridge contracts](https://github.com/poanetwork/poa-bridge-contracts/blob/master/deploy/README.md)
96
88
97
-
2. Open `bridgeDeploymentResults.json` generated by the bridge contract deployment process.
89
+
2. Open `bridgeDeploymentResults.json`or copy the JSON output generated by the bridge contract deployment process.
98
90
99
91
`Native-to-ERC20` mode example:
100
92
```json
@@ -134,19 +126,25 @@ For more information on the Redis/RabbitMQ requirements, see [#90](/../../issues
134
126
135
127
1. Create a `.env` file: `cp .env.example .env`
136
128
137
-
2. Fill in the required information using the output data from `bridgeDeploymentResults.json`. Check the tables with the [set of parameters](#configuration-parameters) below to see their explanation.
129
+
2. Fill in the required information using the JSON output data. Check the tables with the [set of parameters](#configuration-parameters) below to see their explanation.
138
130
139
131
## Run the Processes
140
132
141
-
There are two options to run the nodejs oracle:
142
-
1. Docker containers. This requires [Docker](https://docs.docker.com/install/) and [Docker Compose](https://docs.docker.com/compose/install/) installed. If you are on Linux, it's also recommended that you [create a docker group and add your user to it](https://docs.docker.com/install/linux/linux-postinstall/), so that you can use the CLI without sudo.
133
+
There are two options to run the TokenBridge processes:
134
+
1. Docker containers. This requires [Docker](https://docs.docker.com/install/) and [Docker Compose](https://docs.docker.com/compose/install/). If you are on Linux, it's also recommended that you [create a docker group and add your user to it](https://docs.docker.com/install/linux/linux-postinstall/), so that you can use the CLI without sudo.
143
135
2. NodeJs Package Manager (NPM).
144
136
145
-
### Docker
137
+
### Docker
146
138
147
139
- While running the bridge containers for the first time use `VALIDATOR_ADDRESS=<validator address> VALIDATOR_ADDRESS_PRIVATE_KEY=<validator address private key> docker-compose up -d --build`
148
140
- For further launches use `VALIDATOR_ADDRESS=<validator address> VALIDATOR_ADDRESS_PRIVATE_KEY=<validator address private key> docker-compose up --detach`
149
-
- If you want to use any command from this document, prefix it with `docker-compose exec bridge_affirmation`, if not already prefixed, to execute command inside on of the running docker containers. Make sure bridge service is started before using the commands.
141
+
142
+
All [watcher](#watcher) & [sender](#sender) services launch when `docker-compose` is called.
143
+
144
+
**Note**: To view the Docker logs:
145
+
*`chdir` to the directory containing the `docker-compose.yml` file used to run the bridge instance
146
+
*[View the logs](https://docs.docker.com/v17.09/compose/reference/logs/) : `docker-compose logs`
147
+
150
148
151
149
### NPM
152
150
@@ -168,20 +166,21 @@ If the bridge does not handle an event properly (i.e. a transaction stalls due t
168
166
169
167
Execute this command in the bridge root directory:
@@ -211,17 +210,17 @@ for docker installation respectively, where the _watcher_ could be one of:
211
210
|`LOG_LEVEL`| Set the level of details in the logs. |`trace` / `debug` / `info` / `warn` / `error` / `fatal`|
212
211
|`MAX_PROCESSING_TIME`| The workers processes will be killed if this amount of time (in milliseconds) is ellapsed before they finish processing. It is recommended to set this value to 4 times the value of the longest polling time (set with the `HOME_POLLING_INTERVAL` and `FOREIGN_POLLING_INTERVAL` variables). To disable this, set the time to 0. | integer |
213
212
214
-
###Useful Commands for Development
213
+
## Useful Commands for Development
215
214
216
-
####RabbitMQ
215
+
### RabbitMQ
217
216
Command | Description
218
217
--- | ---
219
218
`rabbitmqctl list_queues` | List all queues
220
219
`rabbitmqctl purge_queue home` | Remove all messages from `home` queue
221
220
`rabbitmqctl status` | check if rabbitmq server is currently running
222
221
`rabbitmq-server` | start rabbitMQ server
223
222
224
-
####Redis
223
+
### Redis
225
224
Use `redis-cli`
226
225
227
226
Command | Description
@@ -293,4 +292,6 @@ This project is licensed under the GNU Lesser General Public License v3.0. See t
0 commit comments