Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from weichang-bianjie/develop
Browse files Browse the repository at this point in the history
migrate rainbow-sync to GitHub
  • Loading branch information
kaifei Hu authored Aug 13, 2019
2 parents ab98812 + b0811a2 commit 0c57026
Show file tree
Hide file tree
Showing 55 changed files with 6,136 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
vendor
*.log
rainbow-sync*
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
# rainbow-sync
A daemon that synchronizes IRIS hub data for the Rainbow wallet backend

## Run
- Cosmos
```bash
cd service/cosmos && make all
nohup ./rainbow-sync > debug.log 2>&1 &
```
- Iris
```bash
cd service/iris && make all
nohup ./rainbow-sync > debug.log 2>&1 &
```

## Run with docker
You can run application with docker.
### Iris
- Build Rainbow-sync Image
```$xslt
cd service/iris && docker build -t rainbow-sync:dev01 .
```

- Run Application
```$xslt
docker run --name rainbow-sync \&
-v /mnt/data/rainbow-sync/logs:/root/go/src/github.com/irisnet/rainbow-sync/logs \&
-e "DB_ADDR=127.0.0.1:27217" -e "DB_USER=user" \&
-e "DB_PASSWD=password" -e "DB_DATABASE=db_name" \&
-e "SER_BC_FULL_NODE=tcp://localhost:26657,..." rainbow-sync:dev01
```
### Cosmos
- Build Rainbow-sync Image
```$xslt
cd service/cosmos && docker build -t rainbow-sync:dev01 .
```
- Run Application
```$xslt
docker run --name rainbow-sync \&
-v /mnt/data/rainbow-sync/logs:/root/go/src/github.com/irisnet/rainbow-sync/logs \&
-e "DB_ADDR=127.0.0.1:27217" -e "DB_USER=user" \&
-e "DB_PASSWD=password" -e "DB_DATABASE=db_name" \&
-e "SER_BC_FULL_NODE_COSMOS=tcp://localhost:36657,..." rainbow-sync:dev01
```


## environment params

| param | type | default |description | example |
| :--- | :--- | :--- | :---: | :---: |
| DB_ADDR | string | "" | db addr | 127.0.0.1:27017,127.0.0.2:27017... |
| DB_USER | string | "" | db user | user |
| DB_PASSWD | string | "" |db passwd | password |
| DB_DATABASE | string | "" |database name | db_name |
| IRIS_NETWORK | string | "testnet" |irishub name | testnet or mainnet |
| SER_BC_FULL_NODE | string | tcp://localhost:26657 | iris full node rpc url | tcp://localhost:26657, tcp://127.0.0.2:26657 |
| WORKER_NUM_CREATE_TASK | string | 2 | 创建同步Iris的Tag任务的线程数 | 2 |
| WORKER_NUM_EXECUTE_TASK | string | 30 | 执行同步Iris的Tag任务的线程数 | 30 |
| WORKER_MAX_SLEEP_TIME | string | 120 | 允许同步Iris的Tag线程处于不工作状态的最大时长(单位为:秒) | 120 |
| BLOCK_NUM_PER_WORKER_HANDLE | string | 50 | 每个同步Iris的Tag任务所包含的Iris区块数 | 50 |
| SER_BC_FULL_NODE_COSMOS | string | tcp://localhost:36657 |cosmos full node rpc url | tcp://localhost:36657, tcp://127.0.0.2:36657 |
| WORKER_NUM_CREATE_TASK_COSMOS | string | 2 | 创建同步Cosmos的Tx任务的线程数 | 2 |
| WORKER_NUM_EXECUTE_TASK_COSMOS | string | 30 | 执行同步Cosmos的Tx任务的线程数 | 30 |
| WORKER_MAX_SLEEP_TIME_COSMOS | string | 120 | 允许同步Cosmos的Tx线程处于不工作状态的最大时长(单位为:秒) | 120 |
| BLOCK_NUM_PER_WORKER_HANDLE_COSMOS | string | 50 | 每个同步Cosmos的Tx任务所包含的Cosmos区块数 | 50 |


37 changes: 37 additions & 0 deletions script/mongodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// create table
db.createCollection("sync_iris_asset_detail");
db.sync_block.renameCollection("sync_iris_block");
db.sync_task.renameCollection("sync_iris_task");
db.createCollection("sync_iris_tx");
db.createCollection("sync_cosmos_tx");
db.createCollection("sync_cosmos_block");
db.createCollection("sync_cosmos_task");


// create index
db.sync_iris_task.createIndex({"status": 1}, {"background": true});
db.sync_iris_tx.createIndex({"to": -1, "height": -1});
db.sync_iris_asset_detail.createIndex({"to": -1, "height": -1});
db.sync_iris_asset_detail.createIndex({"to": -1, "subject": -1});
db.sync_iris_block.createIndex({"height": -1}, {"unique": true});
db.sync_iris_task.createIndex({"start_height": 1, "end_height": 1}, {"unique": true});

db.sync_cosmos_task.createIndex({"status": 1}, {"background": true});
db.sync_cosmos_tx.createIndex({"to": -1, "height": -1});
db.sync_cosmos_block.createIndex({"height": -1}, {"unique": true});
db.sync_cosmos_task.createIndex({"start_height": 1, "end_height": 1}, {"unique": true});

db.sync_cosmos_tx.createIndex({"status": 1}, {"background": true});
db.sync_cosmos_tx.createIndex({"type": 1}, {"background": true});
db.sync_cosmos_tx.createIndex({'from': 1}, {'background': true});
db.sync_cosmos_tx.createIndex({'initiator': 1}, {'background': true});

db.sync_iris_tx.createIndex({'from': 1}, {'background': true});
db.sync_iris_tx.createIndex({'initiator': 1}, {'background': true});
db.sync_iris_tx.createIndex({"type": 1}, {"background": true});
/*
* remove collection data
*/
// db.sync_iris_asset_detail.deleteMany({});
// db.sync_block.deleteMany({});
// db.sync_task.deleteMany({});
27 changes: 27 additions & 0 deletions service/cosmos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM alpine:3.8

# Set up dependencies
ENV PACKAGES go make git libc-dev bash

# Set up path
ENV BINARY_NAME rainbow-sync
ENV GOPATH /root/go
ENV REPO_PATH $GOPATH/src/github.com/irisnet/rainbow-sync/service/cosmos
ENV PATH $GOPATH/bin:$PATH

RUN mkdir -p $GOPATH $REPO_PATH

COPY . $REPO_PATH
WORKDIR $REPO_PATH

VOLUME $REPO_PATH/logs

# Install minimum necessary dependencies, build binary
RUN apk add --no-cache $PACKAGES && \
cd $REPO_PATH && make all && \
mv $REPO_PATH/$BINARY_NAME $GOPATH/bin && \
rm -rf $REPO_PATH/vendor && \
rm -rf $GOPATH/src/github.com/golang $GOPATH/bin/dep $GOPATH/pkg/* && \
apk del $PACKAGES

CMD $BINARY_NAME
Loading

0 comments on commit 0c57026

Please sign in to comment.