Skip to content

Commit cac69c7

Browse files
authored
Merge pull request #1161 from zhengjunhe/improve_cross2eth_stability_0224
Improve cross2eth stability 0224
2 parents 8b20a36 + 0ebe48b commit cac69c7

File tree

18 files changed

+5170
-2535
lines changed

18 files changed

+5170
-2535
lines changed

plugin/dapp/cross2eth/boss4x/ethereum/offline/safeTransferCmd.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
"strings"
1111

12+
"github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/utils"
13+
1214
erc20 "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/erc20/generated"
1315
gnosis "github.com/33cn/plugin/plugin/dapp/cross2eth/contracts/gnosis/generated"
1416
ebTypes "github.com/33cn/plugin/plugin/dapp/cross2eth/ebrelayer/types"
@@ -63,7 +65,7 @@ func addPrepareCreateMultisignTransferTxFlags(cmd *cobra.Command) {
6365
_ = cmd.MarkFlagRequired("contract")
6466
cmd.Flags().StringP("receiver", "r", "", "receive address")
6567
_ = cmd.MarkFlagRequired("receiver")
66-
cmd.Flags().Float64P("amount", "a", 0, "amount to transfer")
68+
cmd.Flags().StringP("amount", "a", "0", "amount to transfer")
6769
_ = cmd.MarkFlagRequired("amount")
6870
cmd.Flags().StringP("token", "t", "", "erc20 address,not need to set for ETH(optional)")
6971
}
@@ -72,7 +74,7 @@ func prepareCreateMultisignTransferTx(cmd *cobra.Command, _ []string) {
7274
url, _ := cmd.Flags().GetString("rpc_laddr_ethereum")
7375
receiver, _ := cmd.Flags().GetString("receiver")
7476
tokenAddr, _ := cmd.Flags().GetString("token")
75-
amount, _ := cmd.Flags().GetFloat64("amount")
77+
amount, _ := cmd.Flags().GetString("amount")
7678
sendAddr, _ := cmd.Flags().GetString("sendAddr")
7779
multiSignAddrstr, _ := cmd.Flags().GetString("contract")
7880

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

110-
gasPrice, err := client.SuggestGasPrice(context.Background())
111-
if err != nil {
112-
fmt.Println("SuggestGasPrice Err:", err)
113-
return
114-
}
112+
gasPrice := big.NewInt(0)
113+
//gasPrice, err := client.SuggestGasPrice(context.Background())
114+
//if err != nil {
115+
// fmt.Println("SuggestGasPrice Err:", err)
116+
// return
117+
//}
115118

119+
bn := big.NewInt(1)
120+
bn, _ = bn.SetString(utils.TrimZeroAndDot(amount), 10)
116121
if tokenAddr == "" {
117-
value.Mul(big.NewInt(int64(amount)), big.NewInt(int64(1e18)))
122+
value.Mul(bn, big.NewInt(int64(1e18)))
118123
} else {
119124
toAddr = common.HexToAddress(tokenAddr)
120125
erc20Abi, err := abi.JSON(strings.NewReader(erc20.ERC20ABI))
@@ -133,13 +138,14 @@ func prepareCreateMultisignTransferTx(cmd *cobra.Command, _ []string) {
133138
fmt.Println("Decimals Err:", err)
134139
return
135140
}
141+
136142
dec, ok := ebTypes.DecimalsPrefix[decimals]
137143
if !ok {
138144
fmt.Println("dec Err:")
139145
return
140146
}
141147

142-
value.Mul(big.NewInt(int64(amount)), big.NewInt(dec))
148+
value.Mul(bn, big.NewInt(dec))
143149

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

351-
gasPrice, err := client.SuggestGasPrice(context.Background())
352-
if err != nil {
353-
fmt.Println("SuggestGasPrice Err:", err)
354-
return
355-
}
356-
357357
gnoAbi, err := abi.JSON(strings.NewReader(gnosis.GnosisSafeABI))
358358
if err != nil {
359359
fmt.Println("JSON Err:", err)
@@ -363,7 +363,7 @@ func SendMultisignTransferTx(cmd *cobra.Command, _ []string) {
363363
safeTxGas := big.NewInt(10 * 10000)
364364

365365
gnoData, err := gnoAbi.Pack("execTransaction", txinfo.To, txinfo.Value, txinfo.TransferData, uint8(0),
366-
safeTxGas, big.NewInt(0), gasPrice, zeroAddr, zeroAddr, txinfo.Content)
366+
safeTxGas, big.NewInt(0), big.NewInt(0), zeroAddr, zeroAddr, txinfo.Content)
367367
if err != nil {
368368
fmt.Println("Pack execTransaction Err:", err)
369369
return

plugin/dapp/cross2eth/ebrelayer/doc/start_ebrelayer.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99

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

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

3031
#### 首次启动 relayer 进行设置
3132
```shell

plugin/dapp/cross2eth/ebrelayer/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ func main() {
7373
ethRelayerCnt := len(cfg.EthRelayerCfg)
7474
chain33MsgChan2Eths := make(map[string]chan<- *events.Chain33Msg)
7575
ethBridgeClaimChan := make(chan *ebrelayerTypes.EthBridgeClaim, 100)
76+
txRelayAckChan2Chain33 := make(chan *ebrelayerTypes.TxRelayAck, 100)
77+
txRelayAckChan2Eth := make(map[string]chan<- *ebrelayerTypes.TxRelayAck)
7678

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

85+
txRelayAckRecvChan := make(chan *ebrelayerTypes.TxRelayAck, 100)
86+
txRelayAckChan2Eth[cfg.EthRelayerCfg[i].EthChainName] = txRelayAckRecvChan
87+
8388
ethStartPara := &ethRelayer.EthereumStartPara{
8489
DbHandle: db,
8590
EthProvider: cfg.EthRelayerCfg[i].EthProvider,
@@ -88,6 +93,8 @@ func main() {
8893
Degree: cfg.EthRelayerCfg[i].EthMaturityDegree,
8994
BlockInterval: cfg.EthRelayerCfg[i].EthBlockFetchPeriod,
9095
EthBridgeClaimChan: ethBridgeClaimChan,
96+
TxRelayAckSendChan: txRelayAckChan2Chain33,
97+
TxRelayAckRecvChan: txRelayAckRecvChan,
9198
Chain33MsgChan: chain33MsgChan,
9299
ProcessWithDraw: cfg.ProcessWithDraw,
93100
Name: cfg.EthRelayerCfg[i].EthChainName,
@@ -106,6 +113,8 @@ func main() {
106113
BridgeRegistryAddr: cfg.Chain33RelayerCfg.BridgeRegistryOnChain33,
107114
DBHandle: db,
108115
EthBridgeClaimChan: ethBridgeClaimChan,
116+
TxRelayAckRecvChan: txRelayAckChan2Chain33,
117+
TxRelayAckSendChan: txRelayAckChan2Eth,
109118
Chain33MsgChan: chain33MsgChan2Eths,
110119
ChainID: cfg.Chain33RelayerCfg.ChainID4Chain33,
111120
ProcessWithDraw: cfg.ProcessWithDraw,

plugin/dapp/cross2eth/ebrelayer/proto/config.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ message SyncTxConfig {
1313
int64 startSyncHeight = 10;
1414
int64 startSyncSequence = 11;
1515
string startSyncHash = 12;
16+
int64 keepAliveDuration = 13;
1617
}
1718

1819
message Log {
@@ -66,4 +67,5 @@ message SyncTxReceiptConfig {
6667
int64 startSyncSequence = 6;
6768
string startSyncHash = 7;
6869
repeated string contracts = 8;
70+
int64 keepAliveDuration = 9;
6971
}

plugin/dapp/cross2eth/ebrelayer/proto/relayer.proto

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ message EthBridgeClaim {
5353
string chainName = 11;
5454
int64 decimal = 12;
5555
string ethTxHash = 13;
56+
int32 forwardTimes = 14;
57+
int64 forwardIndex = 15;
5658
}
5759

5860
message ImportKeyReq {
@@ -340,10 +342,42 @@ message CreateLockEventReq {
340342
string chainName = 7;
341343
}
342344

345+
message TxRelayConfirm4Chain33 {
346+
int32 eventType = 1;
347+
bytes data = 2;
348+
int32 fdTimes = 3;
349+
int64 fdIndex = 4;
350+
string toChainName = 5;
351+
bytes txHash = 6;
352+
bool resend = 7;
353+
}
354+
355+
message TxRelayConfirm4Ethereum {
356+
int32 eventType = 1;
357+
bytes data = 2;
358+
int32 fdTimes = 3;
359+
int64 fdIndex = 4;
360+
string txHash = 5;
361+
bool resend = 6;
362+
}
363+
364+
message TxRelayAck {
365+
string txHash = 1;
366+
int64 fdIndex = 2;
367+
}
368+
369+
message relayTxDetail {
370+
int32 claimType = 1;
371+
int64 txIndexRelayed = 2; //已经发送的中继交易的index
372+
//中继交易,不是源交易
373+
string txhash = 3;
374+
}
375+
343376
message QueryReq {
344377
string param = 1;
345378
string abiData = 2;
346379
string contractAddr = 3;
347380
string owner = 4;
348381
string chainName = 5;
349-
}
382+
}
383+

plugin/dapp/cross2eth/ebrelayer/relayer.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pushName="x2eth"
3636
pushBind="0.0.0.0:20000"
3737
maturityDegree=10
3838
fetchHeightPeriodMs=5000
39+
keepAliveDuration=600000 #10分钟之内未收到信息,通过重新订阅,确保订阅可用
3940
#如果需要配置起始的块的信息,则为了保持一致性,三项缺一不可,或者都不配置
4041
startSyncHeight=0
4142
startSyncSequence=0

0 commit comments

Comments
 (0)