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

adjust fork height init

parent 4440a138
......@@ -47,8 +47,9 @@ var (
zeroHash [32]byte
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
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth int32 = 100
minerPrivateKey = "6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
searchHashMatchDepth int32 = 100
mainBlockHashForkHeight int64 = types.MaxHeight //calc block hash fork height in main chain
)
func init() {
......@@ -203,6 +204,14 @@ func (client *client) GetStartSeq(height int64) int64 {
if height == 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()
if err != nil {
panic(err)
......@@ -422,15 +431,10 @@ func (client *client) GetBlockOnMainBySeq(seq int64) (*types.BlockSeq, error) {
return nil, err
}
height, err := client.grpcClient.GetFork(context.Background(), &types.ReqKey{Key: []byte("ForkBlockHash")})
if err != nil {
plog.Error("para get rpc ForkBlockHash fail", "err", err.Error())
return nil, err
}
hash := blockSeq.Detail.Block.HashByForkHeight(height.Data)
hash := blockSeq.Detail.Block.HashByForkHeight(mainBlockHashForkHeight)
if !bytes.Equal(blockSeq.Seq.Hash, hash) {
plog.Error("para compare ForkBlockHash fail", "height", height, "seqHash", common.Bytes2Hex(blockSeq.Seq.Hash),
"calcHash", common.Bytes2Hex(hash))
plog.Error("para compare ForkBlockHash fail", "forkHeight", mainBlockHashForkHeight,
"seqHash", common.Bytes2Hex(blockSeq.Seq.Hash), "calcHash", common.Bytes2Hex(hash))
return nil, types.ErrBlockHashNoMatch
}
......
......@@ -75,6 +75,7 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
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
s.grpcCli.On("GetBlockBySeq", mock.Anything, mock.Anything).Return(nil, errors.New("quit create"))
//data := &types.Int64{1}
......
......@@ -66,6 +66,7 @@ func (s *suiteParaClient) initEnv(cfg *types.Config, sub *types.ConfigSubModule)
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
s.grpcCli = &typesmocks.Chain33Client{}
s.grpcCli.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, nil)
s.createBlockMock()
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