Commit c071ed4d authored by mdj33's avatar mdj33 Committed by vipwzw

adjust fork height init

parent 4440a138
...@@ -47,8 +47,9 @@ var ( ...@@ -47,8 +47,9 @@ var (
zeroHash [32]byte zeroHash [32]byte
grpcRecSize = 30 * 1024 * 1024 //the size should be limited in server grpcRecSize = 30 * 1024 * 1024 //the size should be limited in server
//current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free //current miner tx take any privatekey for unify all nodes sign purpose, and para chain is free
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b" minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth int32 = 100 searchHashMatchDepth int32 = 100
mainBlockHashForkHeight int64 = types.MaxHeight //calc block hash fork height in main chain
) )
func init() { func init() {
...@@ -203,6 +204,14 @@ func (client *client) GetStartSeq(height int64) int64 { ...@@ -203,6 +204,14 @@ func (client *client) GetStartSeq(height int64) int64 {
if height == 0 { if height == 0 {
return 0 return 0
} }
ret, err := client.grpcClient.GetFork(context.Background(), &types.ReqKey{Key: []byte("ForkBlockHash")})
if err != nil {
plog.Error("para get rpc ForkBlockHash fail", "err", err.Error())
panic(err)
}
mainBlockHashForkHeight = ret.Data
lastHeight, err := client.GetLastHeightOnMainChain() lastHeight, err := client.GetLastHeightOnMainChain()
if err != nil { if err != nil {
panic(err) panic(err)
...@@ -422,15 +431,10 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) { ...@@ -422,15 +431,10 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) {
return nil, err return nil, err
} }
height, err := client.grpcClient.GetFork(context.Background(), &types.ReqKey{Key: []byte("ForkBlockHash")}) hash := blockSeq.Detail.Block.HashByForkHeight(mainBlockHashForkHeight)
if err != nil {
plog.Error("para get rpc ForkBlockHash fail", "err", err.Error())
return nil, err
}
hash := blockSeq.Detail.Block.HashByForkHeight(height.Data)
if !bytes.Equal(blockSeq.Seq.Hash, hash) { if !bytes.Equal(blockSeq.Seq.Hash, hash) {
plog.Error("para compare ForkBlockHash fail", "height", height, "seqHash", common.Bytes2Hex(blockSeq.Seq.Hash), plog.Error("para compare ForkBlockHash fail", "forkHeight", mainBlockHashForkHeight,
"calcHash", common.Bytes2Hex(hash)) "seqHash", common.Bytes2Hex(blockSeq.Seq.Hash), "calcHash", common.Bytes2Hex(hash))
return nil, types.ErrBlockHashNoMatch return nil, types.ErrBlockHashNoMatch
} }
......
...@@ -75,6 +75,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu ...@@ -75,6 +75,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client) s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
s.grpcCli = &typesmocks.Chain33Client{} s.grpcCli = &typesmocks.Chain33Client{}
s.grpcCli.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, nil)
// GetBlockBySeq return error to stop create's for cycle to request tx // GetBlockBySeq return error to stop create's for cycle to request tx
s.grpcCli.On("GetBlockBySeq", mock.Anything, mock.Anything).Return(nil, errors.New("quit create")) s.grpcCli.On("GetBlockBySeq", mock.Anything, mock.Anything).Return(nil, errors.New("quit create"))
//data := &types.Int64{1} //data := &types.Int64{1}
......
...@@ -66,6 +66,7 @@ func (s *suiteParaClient) initEnv(cfg *types.Config, sub *types.ConfigSubModule) ...@@ -66,6 +66,7 @@ func (s *suiteParaClient) initEnv(cfg *types.Config, sub *types.ConfigSubModule)
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client) s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
s.grpcCli = &typesmocks.Chain33Client{} s.grpcCli = &typesmocks.Chain33Client{}
s.grpcCli.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, nil)
s.createBlockMock() s.createBlockMock()
reply := &types.Reply{IsOk: true} reply := &types.Reply{IsOk: true}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment