Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
99eeebc
first commit
dogecoindev May 14, 2021
ee8a79e
Fix TestGetFullHeader
trinhdn97 May 18, 2021
70fc265
fix get full header
dogecoindev May 20, 2021
3608c4d
Implement kaiclient
trinhdn97 May 27, 2021
5a09b80
update readme
dogecoindev May 27, 2021
bcd645d
fix import kai pkg
dogecoindev May 27, 2021
cc601c2
update import kai pkg
dogecoindev May 27, 2021
ed6274a
add WaitTransactionConfirm
dogecoindev May 27, 2021
2fde8b2
update WaitTransactionConfirm
dogecoindev May 27, 2021
bc1790a
add blocknumber
dogecoindev May 27, 2021
946553d
Fix uint64 result of kaiclient methods
trinhdn97 May 27, 2021
ea39b16
Fix gasPrice method
trinhdn97 May 27, 2021
93c0f6f
Fix TransactionByHash method in KaiClient
trinhdn97 May 27, 2021
5402c9e
Rework WaitTransactionConfirm method
trinhdn97 May 27, 2021
bc3e37f
Fix CallArgs
trinhdn97 May 27, 2021
4524a99
Update client
trinhdn97 May 28, 2021
52a9067
Add config.json to git
trinhdn97 May 28, 2021
5f34179
fix findLastestHeight
dogecoindev May 29, 2021
740266a
fix get node height
dogecoindev May 31, 2021
1ae441f
update log message
dogecoindev May 31, 2021
b8e69cd
update kai manager
dogecoindev May 31, 2021
c9ae7e3
update handleBlockHeader
dogecoindev Jun 1, 2021
0aa6e6b
Fix value type of toCallArgs method
trinhdn97 Jun 2, 2021
c6aba2d
Merge remote-tracking branch 'origin/master'
trinhdn97 Jun 2, 2021
c1c2c1f
Add blockHeight for EstimateGas call
trinhdn97 Jun 2, 2021
0c7827a
update commit Proof
dogecoindev Jun 2, 2021
7996784
update relayer
dogecoindev Jun 8, 2021
f091fa6
update relayer
dogecoindev Jun 8, 2021
b0714d1
remove unused code
dogecoindev Jun 8, 2021
34bf794
fix kai manager
dogecoindev Jun 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/
.idea/workspace.xml
capital*
db/bolt.bin
wallet.dat
config-debug.json
log/20*
UTC--*
Log
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,70 @@
# kai-relayer
<h1 align=center> Kai Relayer </h1>

Kai(Kardiachain) Relayer is an important character of Poly cross-chain interactive protocol which is responsible for relaying cross-chain transaction from and to Kardiachain.

## Build From Source

### Prerequisites

- [Golang](https://golang.org/doc/install) version 1.14 or later

### Build

```shell
git clone https://github.com/polynetwork/kai-relayer.git
cd kai_relayer
go build -o kai_relayer main.go
```

After building the source code successfully, you should see the executable program `kai_relayer`.

### Build Docker Image

```
docker build -t polynetwork/kai_relayer -f Dockerfile ./
```

This command will copy ./config.json to /app/config.json in the image. So you need to prepare config.json before running this command and you should start the kai-relayer in container basing on the configuration in /app/config.json.

## Run Relayer

Before you can run the relayer you will need to create a wallet file of PolyNetwork. 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.

Before running, you need feed the configuration file `config.json`.

```
{
"MultiChainConfig":{
"RestURL":"http://poly_ip:20336", // address of Poly
"EntranceContractAddress":"0300000000000000000000000000000000000000", // CrossChainManagerContractAddress on Poly. No need to change
"WalletFile":"./wallet.dat", // your poly wallet
"WalletPwd":"pwd" //password
},
"KaiConfig":{
"SideChainId": 2, // kai side chainID registered on poly
"RestURL":"https://dev-1@kardiachain.io", // your kai node
"ECCMContractAddress":"kai_cross_chain_contract",
"ECCDContractAddress":"kai_cross_chain_data_contract",
"KeyStorePath": "./keystore", // path to store your kai(ethereum) wallet
"KeyStorePwdSet": { // password to protect your kai(ethereum) wallet
"0xd12e...54ccacf91ca364d": "pwd1", // password for address "0xd12e...54ccacf91ca364d"
"0xabb4...0aba7cf3ee3b953": "pwd2" // password for address "0xabb4...0aba7cf3ee3b953"
},
"BlockConfig": 20, // blocks to confirm a kai tx
"HeadersPerBatch": 500, // number of kai headers commited to poly in one transaction at most
"MonitorInterval": 3, // seconds of ticker to monitor kai chain
"EnableChangeBookKeeper": false // normally speaking, set this value as false
},
"BoltDbPath": "./db", // DB path
"RoutineNum": 64,
"TargetContracts": [
{
"0xD8aE73e06552E...bcAbf9277a1aac99": { // your lockproxy hash on kai chain
"inbound": [6], // from which chain allowed
"outbound": [6] // to which chain allowed
}
}
]
}
```

95 changes: 95 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2020 The poly network Authors
* This file is part of The poly network library.
*
* The poly network is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The poly network 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 Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with The poly network . If not, see <http://www.gnu.org/licenses/>.
*/
package cmd

import (
"strings"

"github.com/polynetwork/kai-relayer/config"
"github.com/urfave/cli"
)

var (
LogLevelFlag = cli.UintFlag{
Name: "loglevel",
Usage: "Set the log level to `<level>` (0~6). 0:Trace 1:Debug 2:Info 3:Warn 4:Error 5:Fatal 6:MaxLevel",
Value: config.DEFAULT_LOG_LEVEL,
}

//CliWalletDirFlag = cli.StringFlag{
// Name: "walletdir",
// Usage: "Wallet data `<path>`",
// Value: config.DEFAULT_WALLET_PATH,
//}

//CliAddressFlag = cli.StringFlag{
// Name: "cliaddress",
// Usage: "Rpc bind `<address>`",
// Value: config.DEFUALT_CLI_RPC_ADDRESS,
//}

//CliRpcPortFlag = cli.UintFlag{
// Name: "cliport",
// Usage: "Rpc bind port `<number>`",
// Value: config.DEFAULT_CLI_RPC_PORT,
//}

ConfigPathFlag = cli.StringFlag{
Name: "cliconfig",
Usage: "Server config file `<path>`",
Value: config.DEFAULT_CONFIG_FILE_NAME,
}

KaiStartFlag = cli.Uint64Flag{
Name: "kardiachain",
Usage: "kai start block height ",
Value: uint64(0),
}

KaiStartForceFlag = cli.Uint64Flag{
Name: "kardiachainforce",
Usage: "kai start block height ",
Value: uint64(0),
}

PolyStartFlag = cli.Uint64Flag{
Name: "poly",
Usage: "poly start block height ",
Value: uint64(0),
}

LogDir = cli.StringFlag{
Name: "logdir",
Usage: "log directory",
Value: "./Log/",
}

//EncryptFlag = cli.StringFlag{
// Name: "encrypt",
// Usage: "encrypt string `pwd`",
// Value: "",
//}
)

//GetFlagName deal with short flag, and return the flag name whether flag name have short name
func GetFlagName(flag cli.Flag) string {
name := flag.GetName()
if name == "" {
return ""
}
return strings.TrimSpace(strings.Split(name, ",")[0])
}
26 changes: 26 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"PolyConfig":{
"RestURL":"http://138.91.6.226:40336",
"EntranceContractAddress":"0300000000000000000000000000000000000000",
"WalletFile":"/home/thangn/go/pkg/github.com/polynetwork/poly/wallet.dat",
"WalletPwd":"123456"
},
"KaiConfig":{
"SideChainId": 141,
"RestURL":"https://dev-1.kardiachain.io",
"ECCMContractAddress":"0x14E8226B63C77c6fdCB3830e1bde2b6981F01AAe",
"ECCDContractAddress":"0xad8673ba653c75494EF43F3431b67aD597B21314",
"KeyStorePath": "/home/thangn/snap/geth/477/.ethereum/keystore",
"KeyStorePwdSet": {
"0x2290ddc3874523ffd48c948c8b9379425bDe8BeC": "123456"
},
"BlockConfig": 2,
"HeadersPerBatch": 500,
"MonitorInterval": 3,
"EnableChangeBookKeeper": false
},
"BoltDbPath": "./db",
"RoutineNum": 64,
"TargetContracts": [
]
}
113 changes: 113 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (C) 2020 The poly network Authors
* This file is part of The poly network library.
*
* The poly network is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The poly network 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 Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with The poly network . If not, see <http://www.gnu.org/licenses/>.
*/
package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"time"

"github.com/polynetwork/kai-relayer/log"
)

const (
KAI_MONITOR_INTERVAL = 3 * time.Second
ONT_MONITOR_INTERVAL = 3 * time.Second
KEY_UNLOCK_TIME = 30 * time.Second

KAI_USEFUL_BLOCK_NUM = 3
KAI_PROOF_USERFUL_BLOCK = 12
ONT_USEFUL_BLOCK_NUM = 1
DEFAULT_CONFIG_FILE_NAME = "./config.json"
Version = "1.0"

DEFAULT_LOG_LEVEL = log.InfoLog
)

//type ETH struct {
// Chain string // eth or etc
// ChainId uint64
// RpcAddress string
// ConfirmedBlockNum uint
// //Tokens []*Token
//}

type ServiceConfig struct {
PolyConfig *PolyConfig
KAIConfig *KAIConfig
BoltDbPath string
RoutineNum int64
}

type PolyConfig struct {
RestURL string
EntranceContractAddress string
WalletFile string
WalletPwd string
}

type KAIConfig struct {
RestURL string
ECCMContractAddress string
ECCDContractAddress string
KeyStorePath string
KeyStorePwdSet map[string]string
BlockConfig uint64
SideChainId uint64
}

func ReadFile(fileName string) ([]byte, error) {
file, err := os.OpenFile(fileName, os.O_RDONLY, 0666)
if err != nil {
return nil, fmt.Errorf("ReadFile: open file %s error %s", fileName, err)
}
defer func() {
err := file.Close()
if err != nil {
log.Errorf("ReadFile: File %s close error %s", fileName, err)
}
}()
data, err := ioutil.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("ReadFile: ioutil.ReadAll %s error %s", fileName, err)
}
return data, nil
}

func NewServiceConfig(configFilePath string) *ServiceConfig {
fileContent, err := ReadFile(configFilePath)
if err != nil {
log.Errorf("NewServiceConfig: failed, err: %s", err)
return nil
}
servConfig := &ServiceConfig{}
err = json.Unmarshal(fileContent, servConfig)
if err != nil {
log.Errorf("NewServiceConfig: failed, err: %s", err)
return nil
}

for k, v := range servConfig.KAIConfig.KeyStorePwdSet {
delete(servConfig.KAIConfig.KeyStorePwdSet, k)
servConfig.KAIConfig.KeyStorePwdSet[strings.ToLower(k)] = v
}

return servConfig
}
Loading