Skip to content
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

Improve cross2eth stability 0224 #1161

Merged
merged 21 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 16 additions & 16 deletions plugin/dapp/cross2eth/boss4x/ethereum/offline/safeTransferCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"strings"

"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/utils"

erc20 "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/erc20/generated"
gnosis "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/gnosis/generated"
ebTypes "github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/types"
Expand Down Expand Up @@ -63,7 +65,7 @@ func addPrepareCreateMultisignTransferTxFlags(cmd *cobra.Command) {
_ = cmd.MarkFlagRequired("contract")
cmd.Flags().StringP("receiver", "r", "", "receive address")
_ = cmd.MarkFlagRequired("receiver")
cmd.Flags().Float64P("amount", "a", 0, "amount to transfer")
cmd.Flags().StringP("amount", "a", "0", "amount to transfer")
_ = cmd.MarkFlagRequired("amount")
cmd.Flags().StringP("token", "t", "", "erc20 address,not need to set for ETH(optional)")
}
Expand All @@ -72,7 +74,7 @@ func prepareCreateMultisignTransferTx(cmd *cobra.Command, _ []string) {
url, _ := cmd.Flags().GetString("rpc_laddr_ethereum")
receiver, _ := cmd.Flags().GetString("receiver")
tokenAddr, _ := cmd.Flags().GetString("token")
amount, _ := cmd.Flags().GetFloat64("amount")
amount, _ := cmd.Flags().GetString("amount")
sendAddr, _ := cmd.Flags().GetString("sendAddr")
multiSignAddrstr, _ := cmd.Flags().GetString("contract")

Expand Down Expand Up @@ -107,14 +109,17 @@ func prepareCreateMultisignTransferTx(cmd *cobra.Command, _ []string) {
return
}

gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
fmt.Println("SuggestGasPrice Err:", err)
return
}
gasPrice := big.NewInt(0)
//gasPrice, err := client.SuggestGasPrice(context.Background())
//if err != nil {
// fmt.Println("SuggestGasPrice Err:", err)
// return
//}

bn := big.NewInt(1)
bn, _ = bn.SetString(utils.TrimZeroAndDot(amount), 10)
if tokenAddr == "" {
value.Mul(big.NewInt(int64(amount)), big.NewInt(int64(1e18)))
value.Mul(bn, big.NewInt(int64(1e18)))
} else {
toAddr = common.HexToAddress(tokenAddr)
erc20Abi, err := abi.JSON(strings.NewReader(erc20.ERC20ABI))
Expand All @@ -133,13 +138,14 @@ func prepareCreateMultisignTransferTx(cmd *cobra.Command, _ []string) {
fmt.Println("Decimals Err:", err)
return
}

dec, ok := ebTypes.DecimalsPrefix[decimals]
if !ok {
fmt.Println("dec Err:")
return
}

value.Mul(big.NewInt(int64(amount)), big.NewInt(dec))
value.Mul(bn, big.NewInt(dec))

sendData, err = erc20Abi.Pack("transfer", common.HexToAddress(receiver), value)
if err != nil {
Expand Down Expand Up @@ -348,12 +354,6 @@ func SendMultisignTransferTx(cmd *cobra.Command, _ []string) {
return
}

gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
fmt.Println("SuggestGasPrice Err:", err)
return
}

gnoAbi, err := abi.JSON(strings.NewReader(gnosis.GnosisSafeABI))
if err != nil {
fmt.Println("JSON Err:", err)
Expand All @@ -363,7 +363,7 @@ func SendMultisignTransferTx(cmd *cobra.Command, _ []string) {
safeTxGas := big.NewInt(10 * 10000)

gnoData, err := gnoAbi.Pack("execTransaction", txinfo.To, txinfo.Value, txinfo.TransferData, uint8(0),
safeTxGas, big.NewInt(0), gasPrice, zeroAddr, zeroAddr, txinfo.Content)
safeTxGas, big.NewInt(0), big.NewInt(0), zeroAddr, zeroAddr, txinfo.Content)
if err != nil {
fmt.Println("Pack execTransaction Err:", err)
return
Expand Down
7 changes: 4 additions & 3 deletions plugin/dapp/cross2eth/ebrelayer/doc/start_ebrelayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@

./ebcli_A --node_addr http://182.160.7.143:8545 --eth_chain_name Binance
```
--eth_chain_name string eth chain name (default "Ethereum") 根据 relayer.toml 配置文件中的 EthChainName 字段区分, 目前支持两条链的配置
--eth_chain_name string eth chain name (default "Binance") 根据 relayer.toml 配置文件中的 EthChainName 字段区分, 目前支持两条链的配置
--node_addr string eth node url (default "http://182.160.7.143:8545")
```

#### 修改 relayer.toml 配置文件
|字段|说明|
|----|----|
|pushName|4 个 relayer 不同相同, `sed -i 's/^pushName=.*/pushName="XXX"/g' relayer.toml`|
|ethProvider|ethereum 的 socket 通信地址, 例如: wss://rinkeby.infura.io/ws/v3/404eb4acc421426ebeb6e92c7ce9a270, 如果有多个就根据 EthChainName 分别配置|
|EthProviderCli|ethereum 的 http url 地址, 例如: https://rinkeby.infura.io/ws/v3/404eb4acc421426ebeb6e92c7ce9a270, 如果有多个就根据 EthChainName 分别配置|
|ethProvider|ethereum 的 socket 通信地址, 例如: ["ws://43.130.113.145:9545/","ws://43.130.113.145:9545/"], 如果有多个就根据 EthChainName 分别配置, 提高通信的稳定性, 支持多个配置, 用逗号分隔|
|EthProviderCli|ethereum 的 http url 地址, 例如: ["http://43.130.113.145:9545","http://43.130.113.145:9545"], 如果有多个就根据 EthChainName 分别配置, 提高通信的稳定性, 支持多个配置, 用逗号分隔|
|BridgeRegistry|部署在 ethereum 的 BridgeRegistry 地址, 如果有多个就根据 EthChainName 分别配置|
|chain33BridgeRegistry|部署在 chain33 的 BridgeRegistry 地址|
|ChainID4Chain33|chain33 链的 ID, 默认为 0|
|ChainName|链的名称, 用来区分主链和平行链, 如user.p.xxx., 必须包含最后一个点|
|chain33Host|平行链的 host 地址, 默认: http://localhost:8801|
|pushHost|relayer 的 host 地址, 默认: http://localhost:20000|
|pushBind|relayer 的 bind 端口, 默认: 0.0.0.0:20000|
|keepAliveDuration|单位毫秒, 默认 600000, 表示 10 分钟之内未收到信息, 通过重新订阅, 确保订阅可用, 提高稳定性|

#### 首次启动 relayer 进行设置
```shell
Expand Down
9 changes: 9 additions & 0 deletions plugin/dapp/cross2eth/ebrelayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ func main() {
ethRelayerCnt := len(cfg.EthRelayerCfg)
chain33MsgChan2Eths := make(map[string]chan<- *events.Chain33Msg)
ethBridgeClaimChan := make(chan *ebrelayerTypes.EthBridgeClaim, 100)
txRelayAckChan2Chain33 := make(chan *ebrelayerTypes.TxRelayAck, 100)
txRelayAckChan2Eth := make(map[string]chan<- *ebrelayerTypes.TxRelayAck)

//启动多个以太坊系中继器
ethRelayerServices := make(map[string]*ethRelayer.Relayer4Ethereum)
for i := 0; i < ethRelayerCnt; i++ {
chain33MsgChan := make(chan *events.Chain33Msg, 100)
chain33MsgChan2Eths[cfg.EthRelayerCfg[i].EthChainName] = chain33MsgChan

txRelayAckRecvChan := make(chan *ebrelayerTypes.TxRelayAck, 100)
txRelayAckChan2Eth[cfg.EthRelayerCfg[i].EthChainName] = txRelayAckRecvChan

ethStartPara := &ethRelayer.EthereumStartPara{
DbHandle: db,
EthProvider: cfg.EthRelayerCfg[i].EthProvider,
Expand All @@ -88,6 +93,8 @@ func main() {
Degree: cfg.EthRelayerCfg[i].EthMaturityDegree,
BlockInterval: cfg.EthRelayerCfg[i].EthBlockFetchPeriod,
EthBridgeClaimChan: ethBridgeClaimChan,
TxRelayAckSendChan: txRelayAckChan2Chain33,
TxRelayAckRecvChan: txRelayAckRecvChan,
Chain33MsgChan: chain33MsgChan,
ProcessWithDraw: cfg.ProcessWithDraw,
Name: cfg.EthRelayerCfg[i].EthChainName,
Expand All @@ -106,6 +113,8 @@ func main() {
BridgeRegistryAddr: cfg.Chain33RelayerCfg.BridgeRegistryOnChain33,
DBHandle: db,
EthBridgeClaimChan: ethBridgeClaimChan,
TxRelayAckRecvChan: txRelayAckChan2Chain33,
TxRelayAckSendChan: txRelayAckChan2Eth,
Chain33MsgChan: chain33MsgChan2Eths,
ChainID: cfg.Chain33RelayerCfg.ChainID4Chain33,
ProcessWithDraw: cfg.ProcessWithDraw,
Expand Down
2 changes: 2 additions & 0 deletions plugin/dapp/cross2eth/ebrelayer/proto/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message SyncTxConfig {
int64 startSyncHeight = 10;
int64 startSyncSequence = 11;
string startSyncHash = 12;
int64 keepAliveDuration = 13;
}

message Log {
Expand Down Expand Up @@ -66,4 +67,5 @@ message SyncTxReceiptConfig {
int64 startSyncSequence = 6;
string startSyncHash = 7;
repeated string contracts = 8;
int64 keepAliveDuration = 9;
}
36 changes: 35 additions & 1 deletion plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ message EthBridgeClaim {
string chainName = 11;
int64 decimal = 12;
string ethTxHash = 13;
int32 forwardTimes = 14;
int64 forwardIndex = 15;
}

message ImportKeyReq {
Expand Down Expand Up @@ -340,10 +342,42 @@ message CreateLockEventReq {
string chainName = 7;
}

message TxRelayConfirm4Chain33 {
int32 eventType = 1;
bytes data = 2;
int32 fdTimes = 3;
int64 fdIndex = 4;
string toChainName = 5;
bytes txHash = 6;
bool resend = 7;
}

message TxRelayConfirm4Ethereum {
int32 eventType = 1;
bytes data = 2;
int32 fdTimes = 3;
int64 fdIndex = 4;
string txHash = 5;
bool resend = 6;
}

message TxRelayAck {
string txHash = 1;
int64 fdIndex = 2;
}

message relayTxDetail {
int32 claimType = 1;
int64 txIndexRelayed = 2; //已经发送的中继交易的index
//中继交易,不是源交易
string txhash = 3;
}

message QueryReq {
string param = 1;
string abiData = 2;
string contractAddr = 3;
string owner = 4;
string chainName = 5;
}
}

1 change: 1 addition & 0 deletions plugin/dapp/cross2eth/ebrelayer/relayer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pushName="x2eth"
pushBind="0.0.0.0:20000"
maturityDegree=10
fetchHeightPeriodMs=5000
keepAliveDuration=600000 #10分钟之内未收到信息,通过重新订阅,确保订阅可用
#如果需要配置起始的块的信息,则为了保持一致性,三项缺一不可,或者都不配置
startSyncHeight=0
startSyncSequence=0
Expand Down
Loading