-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Zilliqa relayer implementation #1
base: main
Are you sure you want to change the base?
Changes from 85 commits
5396a9e
f5d508b
cfccd10
9d9cb37
63d470e
94be137
bbf073c
f814d43
8d614a6
90abef4
f3f9b1d
31586f7
accbbff
67f2d6a
44c4d2d
06882c1
47f6fdc
d4ab90e
efc4109
98e7b0e
8008ee7
53b6aca
68221c3
43f6cce
7c12929
6437260
d901574
5542053
d337d8f
bb964da
4ffdaa9
094ce41
bad0a21
e1b4b3f
979a2fc
2e9867a
94253f2
ea8562e
8200580
83a149e
4fa85b3
a21bdff
616b0b8
12f0f5c
3fcbc27
70a7803
54e404a
1b40f14
c9bc96a
dcb9243
316c42a
4cd70db
df1eace
6718e14
c58e826
fe9c704
d6a6e60
8d72826
33b103a
63f895c
9bd13f7
a36f6f5
f9bebfd
83240c9
ac50ba9
f82f5d4
daa2eda
8220c03
8fe2da6
64d4693
a3e2a03
f06a017
02d09cf
11be2f6
10395dc
34713a3
5747433
e591df7
326f41b
884f277
9e72572
6577db8
fed17de
447ea9e
fc38bbb
b60f292
a977fe2
c58370e
0f7f18d
600516e
0ce01c9
e0ed0b5
4356c6e
6fa2043
db02563
c162de1
8f4c3bf
cc2528a
8432bf5
894e9aa
d30ded0
ac5dec1
6b3ddac
de2d5b0
85b85da
65c23dc
efd966c
5c81aae
73f7cf3
844f457
88594be
13d0a28
6666992
e0050b8
23118e2
63fd1ca
baf74b1
c31613e
2d061c8
da42edb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
zilliqa-relayer | ||
.idea | ||
bolt.bin | ||
config.local.yaml | ||
constants.xml | ||
cross_chain_manager_admin.json | ||
xiaohuo.wallet | ||
zilliqa.wallet | ||
poly.wallet | ||
relayer.wallet | ||
secrets | ||
config.devnet.yaml | ||
config.testnet.yaml | ||
target_contracts_devnet.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.15 AS build | ||
WORKDIR /app/zilliqa-relayer | ||
COPY . ./ | ||
RUN go build | ||
#RUN git clone https://github.com/Zilliqa/zilliqa-relayer.git && \ | ||
# cd zilliqa-relayer && \ | ||
# go build | ||
|
||
FROM ubuntu:18.04 | ||
RUN apt-get update && apt-get install -y ca-certificates | ||
WORKDIR /app | ||
COPY run.sh run.sh | ||
COPY --from=build /app/zilliqa-relayer/zilliqa-relayer zilliqa-relayer | ||
ENTRYPOINT ["/bin/bash", "run.sh"] |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1 +1,130 @@ | ||||||||
# zilliqa-relayer | ||||||||
# zilliqa-relayer | ||||||||
|
||||||||
*This program is still under developing!* | ||||||||
|
||||||||
Zilliqa Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Zilliqa. | ||||||||
|
||||||||
## Build From Source | ||||||||
|
||||||||
### Prerequisites | ||||||||
|
||||||||
- [Golang](https://golang.org/doc/install) version 1.14 or later | ||||||||
|
||||||||
### Build | ||||||||
|
||||||||
```shell | ||||||||
git clone https://github.com/polynetwork/zil-relayer.git | ||||||||
cd zil-relayer | ||||||||
./build.sh | ||||||||
``` | ||||||||
|
||||||||
After building the source code successfully, you should see the executable program `zilliqa-relayer`. | ||||||||
|
||||||||
### Build Docker Image | ||||||||
|
||||||||
``` | ||||||||
docker build -t polynetwork/zilliqa-relayer . | ||||||||
``` | ||||||||
|
||||||||
This command will copy config.yaml to /app/config.yaml in the image. So you need to prepare config.yaml before running this command and you should start the zilliqa-relayer in container basing on the configuration in /app/config.yaml. | ||||||||
|
||||||||
|
||||||||
## Run Relayer | ||||||||
Before you can run the relayer you will need to create a wallet file of PolyNetwork by running(build Poly CLI first): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
```shell | ||||||||
./poly account add -d | ||||||||
``` | ||||||||
|
||||||||
After creation, you need to register it as a Relayer to Poly net and get consensus nodes approving your registeration. And then you can send transaction to Poly net and start relaying. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
Before running, you need feed the configuration file `config.yaml`. | ||||||||
|
||||||||
```yaml | ||||||||
zil_config: | ||||||||
zil_api: https://api.zilliqa.com | ||||||||
zil_chain_id: 111 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be chain_id 1 |
||||||||
zil_message_version: 1 | ||||||||
zil_force_height: 0 | ||||||||
zil_monitor_interval: 10 | ||||||||
zil_headers_per_batch: 2 | ||||||||
corss_chain_manager_address: zil1tjru7m5zdn3x6k0t72nzmmpz62e5qds62nte9t | ||||||||
cross_chain_manager_proxy_address: zil1n7wkwr0xxslwsrhnqtjrwlus80dp5ncnlpaw93 | ||||||||
side_chain_id: 85 | ||||||||
key_store_path: zilliqa.wallet | ||||||||
key_store_pwd_set: | ||||||||
6c89b62d65dc632e259b96f7ae2f1d68a27e3383: "" | ||||||||
poly_config: | ||||||||
poly_wallet_file: poly.wallet | ||||||||
poly_wallet_pwd: | ||||||||
poly_start_height: 0 | ||||||||
poly_monitor_interval: 2 | ||||||||
entrance_contract_address: "0300000000000000000000000000000000000000" | ||||||||
rest_url: http://poly.com | ||||||||
target_contracts: target_contracts.json | ||||||||
db_path: persistence | ||||||||
``` | ||||||||
|
||||||||
A sample keystore file could be: | ||||||||
|
||||||||
```text | ||||||||
{"address":"7d48043742a1103042d327111746531ca26be9be","id":"6cd445ed-8f5f-4565-af2a-cc2306a82b73","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"d136660a4e5664709031ebc162616556e8c812ab37d0157ea3276aa08d0a6c2d","kdf":"pbkdf2","mac":"b30dd459f1fd9d99c0b2f3452ccd2bf11414ad92d32ac70d1d7b52f17281b4e5","cipherparams":{"iv":"6a14f95c8cbafe7d1f317bec88e9d1b8"},"kdfparams":{"n":8192,"c":262144,"r":8,"p":1,"dklen":32,"salt":"c4939e7cead32935d1972a2cd06d249dd501181e6ad2d1872fa0eb397d7fea20"}}} | ||||||||
``` | ||||||||
# Relayer Container Administration | ||||||||
## Running the Relayer Container | ||||||||
### Prerequisites: | ||||||||
If you are running via docker-compose, you'll need to install docker-compose first via the following guide: | ||||||||
``` | ||||||||
https://docs.docker.com/compose/install/ | ||||||||
``` | ||||||||
|
||||||||
You need the following files and folders created: <br /> | ||||||||
If persistence is already created: | ||||||||
``` | ||||||||
./persistence/bolt.bin | ||||||||
``` | ||||||||
If persistence folder is not created: | ||||||||
``` | ||||||||
create a folder named 'persistence'. The container will use that folder to store the bolt.bin file. | ||||||||
``` | ||||||||
Configuration Files: | ||||||||
``` | ||||||||
secrets/config.local.yaml | ||||||||
secrets/target_contracts.json | ||||||||
secrets/poly.wallet | ||||||||
secrets/zilliqa.wallet | ||||||||
``` | ||||||||
### Running Relayer via Docker Container | ||||||||
``` | ||||||||
./docker-run | ||||||||
``` | ||||||||
|
||||||||
### Running Relayer via Docker Compose | ||||||||
``` | ||||||||
docker-compose up -d | ||||||||
``` | ||||||||
## Stopping the Relayer | ||||||||
### Stopping Relayer via Docker Container | ||||||||
``` | ||||||||
docker stop zilliqa-relayer && docker rm zilliqa-relayer | ||||||||
``` | ||||||||
### Stopping Relayer via Docker Compose | ||||||||
``` | ||||||||
docker-compose down | ||||||||
``` | ||||||||
## Getting logs | ||||||||
``` | ||||||||
docker logs -f zilliqa-relayer | ||||||||
``` | ||||||||
|
||||||||
|
||||||||
## Other Resources | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the resource to the latest repo |
||||||||
|
||||||||
- [zilliqa cross chain manager proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManagerProxy.scilla) | ||||||||
- [zilliqa cross chain manager](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/ZilCrossChainManager.scilla) | ||||||||
- [zilliqa lock proxy](https://github.com/Zilliqa/zilliqa-contracts/blob/main/contracts/LockProxy.scilla) | ||||||||
- [polynetwork](https://github.com/polynetwork/poly) | ||||||||
|
||||||||
|
||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
docker build -t polynetwork/zilliqa-relayer . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
go build |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||
/* | ||||||
* Copyright (C) 2021 Zilliqa | ||||||
* | ||||||
* This program is free software: you can redistribute it and/or modify | ||||||
* it under the terms of the GNU General Public License as published by | ||||||
* the Free Software Foundation, either version 3 of the License, or | ||||||
* (at your option) any later version. | ||||||
* | ||||||
* This program is distributed in the hope that it will be useful, | ||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
* GNU General Public License for more details. | ||||||
* | ||||||
* You should have received a copy of the GNU General Public License | ||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
*/ | ||||||
|
||||||
package cmd | ||||||
|
||||||
import ( | ||||||
log "github.com/sirupsen/logrus" | ||||||
"github.com/spf13/cobra" | ||||||
|
||||||
"os" | ||||||
) | ||||||
|
||||||
var RootCmd = &cobra.Command{ | ||||||
Use: "zilliqa-relayer", | ||||||
Short: "To run zilliqa relayer for poly network", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Long: `To run zilliqa relayer for poly network`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Run: func(cmd *cobra.Command, args []string) { | ||||||
}, | ||||||
} | ||||||
|
||||||
func Execute() { | ||||||
if err := RootCmd.Execute(); err != nil { | ||||||
log.Error(err) | ||||||
os.Exit(1) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* Copyright (C) 2021 Zilliqa | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package cmd | ||
renlulu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"encoding/json" | ||
"github.com/Zilliqa/gozilliqa-sdk/provider" | ||
poly_go_sdk "github.com/polynetwork/poly-go-sdk" | ||
"github.com/polynetwork/zilliqa-relayer/config" | ||
"github.com/polynetwork/zilliqa-relayer/db" | ||
"github.com/polynetwork/zilliqa-relayer/service" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
) | ||
|
||
var cfgFile string | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)") | ||
|
||
RootCmd.AddCommand(runCmd) | ||
log.SetFormatter(&log.TextFormatter{ | ||
FullTimestamp: true, | ||
}) | ||
} | ||
|
||
func initConfig() { | ||
if cfgFile != "" { | ||
// Use config file from the flag. | ||
viper.SetConfigFile(cfgFile) | ||
} else { | ||
viper.AddConfigPath("./") | ||
viper.SetConfigName("config.local") | ||
} | ||
|
||
viper.AutomaticEnv() | ||
|
||
err := viper.ReadInConfig() | ||
if err == nil { | ||
log.Info("Using config file:", viper.ConfigFileUsed()) | ||
} else { | ||
log.Error(err.Error()) | ||
} | ||
} | ||
|
||
func setUpPoly(poly *poly_go_sdk.PolySdk, RpcAddr string) error { | ||
poly.NewRpcClient().SetAddress(RpcAddr) | ||
hdr, err := poly.GetHeaderByHeight(0) | ||
if err != nil { | ||
return err | ||
} | ||
poly.SetChainId(hdr.ChainID) | ||
return nil | ||
} | ||
|
||
func checkIfExist(dir string) bool { | ||
_, err := os.Stat(dir) | ||
if err != nil && !os.IsExist(err) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
var runCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "Run zilliqa relayer", | ||
Long: `Run zilliqa relayer`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
zilConfigMap := viper.GetStringMap("zil_config") | ||
targetContractsPath := viper.GetString("target_contracts") | ||
dbPath := viper.GetString("db_path") | ||
removeDb := viper.GetBool("remove_db") | ||
bytes, e := ioutil.ReadFile(targetContractsPath) | ||
if e != nil { | ||
log.Errorf("read target contracts error: %s, path: %s\n", e.Error(), targetContractsPath) | ||
return | ||
} | ||
var targetContract []map[string]map[string][]uint64 | ||
e2 := json.Unmarshal(bytes, &targetContract) | ||
if e2 != nil { | ||
log.Errorf("unmarshal target contracts error: %s\n", e2.Error()) | ||
return | ||
} | ||
log.Info(targetContract) | ||
zilConfig := &config.ZILConfig{ | ||
ZilApiEndpoint: zilConfigMap["zil_api"].(string), | ||
ZilChainId: zilConfigMap["zil_chain_id"].(int), | ||
ZilMessageVersion: zilConfigMap["zil_message_version"].(int), | ||
ZilForceHeight: uint64(zilConfigMap["zil_force_height"].(int)), | ||
ZilMonitorInterval: uint32(zilConfigMap["zil_monitor_interval"].(int)), | ||
ZilHeadersPerBatch: uint32(zilConfigMap["zil_headers_per_batch"].(int)), | ||
SideChainId: uint64(zilConfigMap["side_chain_id"].(int)), | ||
CrossChainManagerContract: zilConfigMap["corss_chain_manager_address"].(string), | ||
CrossChainManagerProxyContract: zilConfigMap["cross_chain_manager_proxy_address"].(string), | ||
MaxExistTxEpoch: zilConfigMap["max_exist_tx_epoch"].(int), | ||
KeyStorePath: zilConfigMap["key_store_path"].(string), | ||
KeyStorePwdSet: zilConfigMap["key_store_pwd_set"].(map[string]interface{}), | ||
} | ||
|
||
polyConfigMap := viper.GetStringMap("poly_config") | ||
|
||
polyConfig := &config.POLYConfig{ | ||
PolyWalletFile: polyConfigMap["poly_wallet_file"].(string), | ||
PolyWalletPassword: polyConfigMap["poly_wallet_pwd"].(string), | ||
PolyStartHeight: uint32(polyConfigMap["poly_start_height"].(int)), | ||
PolyMonitorInterval: uint32(polyConfigMap["poly_monitor_interval"].(int)), | ||
EntranceContractAddress: polyConfigMap["entrance_contract_address"].(string), | ||
RestUrl: polyConfigMap["rest_url"].(string), | ||
} | ||
|
||
cfg := &config.Config{ | ||
ZilConfig: zilConfig, | ||
PolyConfig: polyConfig, | ||
TargetContracts: targetContract, | ||
Path: dbPath, | ||
RemoveDB: removeDb, | ||
} | ||
|
||
cfgStr, _ := json.Marshal(cfg) | ||
log.Infof("config file: %s\n", cfgStr) | ||
|
||
zilSdk := provider.NewProvider(cfg.ZilConfig.ZilApiEndpoint) | ||
polySdk := poly_go_sdk.NewPolySdk() | ||
err1 := setUpPoly(polySdk, cfg.PolyConfig.RestUrl) | ||
if err1 != nil { | ||
log.Errorf("init poly sdk error: %s\n", err1.Error()) | ||
return | ||
} | ||
|
||
if cfg.RemoveDB { | ||
os.Remove(path.Join(cfg.Path, "bolt.bin")) | ||
} | ||
|
||
if !checkIfExist(cfg.Path) { | ||
os.Mkdir(cfg.Path, os.ModePerm) | ||
} | ||
boltDB, err2 := db.NewBoltDB(cfg.Path) | ||
if err2 != nil { | ||
log.Errorf("cannot init bolt db: %s\n", err2.Error()) | ||
return | ||
} | ||
|
||
zilliqaManager, err := service.NewZilliqaSyncManager(cfg, zilSdk, polySdk, boltDB) | ||
if err != nil { | ||
log.Errorf("init zilliqamanger error: %s\n", err.Error()) | ||
return | ||
} | ||
polyManager, err1 := service.NewPolySyncManager(cfg, zilSdk, polySdk, boltDB, cfg.ZilConfig.CrossChainManagerContract, cfg.ZilConfig.CrossChainManagerProxyContract) | ||
if err1 != nil { | ||
log.Errorf("init polymanager error: %s\n", err1.Error()) | ||
return | ||
} | ||
|
||
zilliqaManager.Run(true) | ||
polyManager.Run(true) | ||
|
||
service.WaitToExit() | ||
|
||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.