Skip to content

Commit 24122ef

Browse files
authoredJan 28, 2019
Merge pull request #130 from andogro/ag-README-update
minor README updates

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed
 

‎README.md

+48-47
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,92 @@
11

2-
# POA Bridge - NodeJS Oracle
2+
# POA TokenBridge
33

4-
[![Build Status](https://travis-ci.org/poanetwork/bridge-nodejs.svg?branch=develop)](https://travis-ci.org/poanetwork/bridge-nodejs)
4+
[![Build Status](https://travis-ci.org/poanetwork/token-bridge.svg)](https://travis-ci.org/poanetwork/token-bridge)
55
[![Gitter](https://badges.gitter.im/poanetwork/poa-bridge.svg)](https://gitter.im/poanetwork/poa-bridge?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

7-
## Bridge Overview
7+
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).
812

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:
1016

1117
**Bridge Elements**
12-
1. An oracle written in NodeJS, contained in this repository.
18+
1. The TokenBridge contained in this repository.
1319
2. [Solidity smart contracts](https://github.com/poanetwork/poa-bridge-contracts). Used to manage bridge validators, collect signatures, and confirm asset relay and disposal.
1420
3. [Bridge UI Application](https://github.com/poanetwork/bridge-ui). A DApp interface to transfer tokens and coins between chains.
1521
4. [Bridge Monitor](https://github.com/poanetwork/bridge-monitor). A tool for checking balances and unprocessed events in bridged networks.
1622
5. [Bridge Deployment Playbooks](https://github.com/poanetwork/deployment-bridge). Manages configuration instructions for remote deployments.
1723

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
3125

3226
Bridging occurs between two networks.
3327

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.
3529

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.
3731

38-
### Operational Modes
32+
## Operational Modes
3933

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:
4535

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)**
4639

4740
## Architecture
4841

4942
### Native-to-ERC20
5043

5144
![Native-to-ERC](Native-to-ERC.png)
5245

53-
### ERC20-to-ERC20
46+
### ERC20-to-ERC20 and ERC20-to-Native
5447

5548
![ERC-to-ERC](ERC-to-ERC.png)
5649

57-
5850
### Watcher
5951
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.
6052

6153
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.
6254

63-
6455
There are three Watchers:
6556
- **Signature Request Watcher**: Listens to `UserRequestForSignature` events on the Home network.
6657
- **Collected Signatures Watcher**: Listens to `CollectedSignatures` events on the Home network.
6758
- **Affirmation Request Watcher**: Depends on the bridge mode.
6859
- `Native-to-ERC20`: Listens to `UserRequestForAffirmation` raised by the bridge contract.
6960
- `ERC20-to-ERC20` and `ERC20-to-Native`: Listens to `Transfer` events raised by the token contract.
7061

71-
7262
### Sender
7363
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.
7464

7565
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.
7868

7969
### RabbitMQ
8070

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.
8272

8373
### Redis DB
8474

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.
8676

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).
8878

8979
# How to Use
9080

9181
## Installation and Deployment
9282

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+
9385
#### Deploy the Bridge Contracts
9486

9587
1. [Deploy the bridge contracts](https://github.com/poanetwork/poa-bridge-contracts/blob/master/deploy/README.md)
9688

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.
9890

9991
`Native-to-ERC20` mode example:
10092
```json
@@ -134,19 +126,25 @@ For more information on the Redis/RabbitMQ requirements, see [#90](/../../issues
134126

135127
1. Create a `.env` file: `cp .env.example .env`
136128

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.
138130

139131
## Run the Processes
140132

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.
143135
2. NodeJs Package Manager (NPM).
144136

145-
### Docker
137+
### Docker
146138

147139
- 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`
148140
- 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+
150148

151149
### NPM
152150

@@ -168,20 +166,21 @@ If the bridge does not handle an event properly (i.e. a transaction stalls due t
168166

169167
Execute this command in the bridge root directory:
170168

169+
for NPM installation:
171170
```shell
172171
bash ./reset-lastBlock.sh <watcher> <block num>
173172
```
174-
for NPM installation or
173+
for Docker installation:
175174
```shell
176175
docker-compose exec bridge_affirmation bash ./reset-lastBlock.sh <watcher> <block num>
177176
```
178-
for docker installation respectively, where the _watcher_ could be one of:
177+
where the _watcher_ could be one of:
179178

180179
- `signature-request`
181180
- `collected-signatures`
182181
- `affirmation-request`
183182

184-
### Configuration parameters
183+
## Configuration parameters
185184

186185
| Variable | Description | Values |
187186
|-------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------|
@@ -211,17 +210,17 @@ for docker installation respectively, where the _watcher_ could be one of:
211210
| `LOG_LEVEL` | Set the level of details in the logs. | `trace` / `debug` / `info` / `warn` / `error` / `fatal` |
212211
| `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 |
213212

214-
### Useful Commands for Development
213+
## Useful Commands for Development
215214

216-
#### RabbitMQ
215+
### RabbitMQ
217216
Command | Description
218217
--- | ---
219218
`rabbitmqctl list_queues` | List all queues
220219
`rabbitmqctl purge_queue home` | Remove all messages from `home` queue
221220
`rabbitmqctl status` | check if rabbitmq server is currently running
222221
`rabbitmq-server` | start rabbitMQ server
223222

224-
#### Redis
223+
### Redis
225224
Use `redis-cli`
226225

227226
Command | Description
@@ -293,4 +292,6 @@ This project is licensed under the GNU Lesser General Public License v3.0. See t
293292

294293
## References
295294

295+
* [Additional Documentation](https://forum.poa.network/c/tokenbridge)
296296
* [POA Bridge FAQ](https://poanet.zendesk.com/hc/en-us/categories/360000349273-POA-Bridge)
297+

0 commit comments

Comments
 (0)
Please sign in to comment.