Skip to content

Commit f131c97

Browse files
zhangbinzhangbin
zhangbin
authored and
zhangbin
committedJun 24, 2022
add chainbridge.json.sample
1 parent c377eb3 commit f131c97

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed
 

‎chainbridge-core/chainbridge.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/elastos/Elastos.ELA.SideChain.ESC/crypto"
2727
"github.com/elastos/Elastos.ELA.SideChain.ESC/dpos"
2828
"github.com/elastos/Elastos.ELA.SideChain.ESC/log"
29+
"github.com/elastos/Elastos.ELA.SideChain.ESC/node"
2930
"github.com/elastos/Elastos.ELA.SideChain.ESC/rpc"
3031
"github.com/elastos/Elastos.ELA.SideChain.ESC/spv"
3132

@@ -85,13 +86,13 @@ func APIs(engine *pbft.Pbft) []rpc.API {
8586
}}
8687
}
8788

88-
func Init(engine *pbft.Pbft, accountPath, accountPassword string) {
89+
func Init(engine *pbft.Pbft, stack *node.Node, accountPath, accountPassword string) {
8990
pbftEngine = engine
9091
if MsgReleayer != nil {
9192
log.Warn("chain bridge is started")
9293
return
9394
}
94-
err := initRelayer(engine, accountPath, accountPassword)
95+
err := initRelayer(engine, stack, accountPath, accountPassword)
9596
if err != nil {
9697
bridgelog.Error("chain bridge started error", "error", err)
9798
return
@@ -645,13 +646,14 @@ func onProducersChanged(e *events.Event) {
645646
bridgelog.Info("SetManualArbiters", "total", total, "error", err, "arbiterCount", len(addresses))
646647
}
647648

648-
func initRelayer(engine *pbft.Pbft, accountPath, accountPassword string) error {
649+
func initRelayer(engine *pbft.Pbft, stack *node.Node, accountPath, accountPassword string) error {
649650
if MsgReleayer != nil {
650651
return nil
651652
}
652653
cfg, err := config.GetConfig(config.DefaultConfigDir)
653654
if err != nil {
654655
log.Info("engine.GetBlockChain().Config().BridgeContractAddr", "address", engine.GetBlockChain().Config().BridgeContractAddr)
656+
err = createSelfChain(engine, stack)
655657
return err
656658
}
657659
db, err := lvldb.NewLvlDB(config.BlockstoreFlagName)
@@ -675,6 +677,24 @@ func initRelayer(engine *pbft.Pbft, accountPath, accountPassword string) error {
675677
return nil
676678
}
677679

680+
func createSelfChain(engine *pbft.Pbft, stack *node.Node) error {
681+
escChainID = engine.GetBlockChain().Config().ChainID.Uint64()
682+
rpc := fmt.Sprintf("http://localhost:%d", stack.Config().HTTPPort)
683+
generalConfig := config.GeneralChainConfig{
684+
Name: "ESC",
685+
Id: escChainID,
686+
Endpoint: rpc,
687+
}
688+
layer, errMsg := createChain(&generalConfig, nil, engine, "", "")
689+
if errMsg != nil {
690+
return errors.New(fmt.Sprintf("evm createSelfChain is error:%s, chainid:%d", errMsg.Error(), escChainID))
691+
}
692+
chains := make([]relayer.RelayedChain, 1)
693+
chains[0] = layer
694+
MsgReleayer = relayer.NewRelayer(chains, escChainID)
695+
return nil
696+
}
697+
678698
func Stop(msg string) {
679699
if isRequireArbiter {
680700
errChn <- fmt.Errorf(msg)

‎cmd/geth/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func initChainBridge(ctx *cli.Context, stack *node.Node, blockChain *core.BlockC
653653
log.Info("is common sync node, no password")
654654
}
655655
engine := blockChain.GetDposEngine().(*pbft.Pbft)
656-
chainbridge_core.Init(engine, accPath, password)
656+
chainbridge_core.Init(engine, stack, accPath, password)
657657
}
658658

659659
func startLayer2(blockChain *core.BlockChain) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"chains":[
3+
{
4+
"name": "layer1",
5+
"type": "ethereum",
6+
"id": 80,
7+
"endpoint": "http://127.0.0.1:1111",
8+
"freshstart": true,
9+
"opts": {
10+
"bridge": "0xd68251F74a6C1E502653A505cd0cF7072e66981D",
11+
"gasLimit": 8000000,
12+
"maxGasPrice": 10000000000,
13+
"blockConfirmations": 1,
14+
"gasMultiplier": 1.2,
15+
"startBlock": 5
16+
}
17+
},
18+
{
19+
"name": "layer2",
20+
"type": "ethereum",
21+
"id": 83,
22+
"endpoint": "http://127.0.0.1:6111",
23+
"freshstart": false,
24+
"opts": {
25+
"bridge": "0xd68251F74a6C1E502653A505cd0cF7072e66981D",
26+
"gasLimit": 8000000,
27+
"maxGasPrice": 10000000000,
28+
"blockConfirmations": 1,
29+
"gasMultiplier": 1.2,
30+
"startBlock": 5
31+
}
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)
Please sign in to comment.