Commit 2a47c254 authored by mdj33's avatar mdj33 Committed by vipwzw

add search depth config

parent 2632b315
...@@ -46,8 +46,8 @@ var ( ...@@ -46,8 +46,8 @@ 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"
searchHashMatchBlockDepth int64 = 100 searchHashMatchDepth int32 = 100
) )
func init() { func init() {
...@@ -84,9 +84,9 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -84,9 +84,9 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
emptyBlockInterval = cfg.EmptyBlockInterval emptyBlockInterval = cfg.EmptyBlockInterval
} }
//if cfg.searchHashMatchBlockDepth > 0 { if cfg.SearchHashMatchedBlockDepth > 0 {
// searchHashMatchBlockDepth = cfg.searchHashMatchBlockDepth searchHashMatchDepth = cfg.SearchHashMatchedBlockDepth
//} }
pk, err := hex.DecodeString(minerPrivateKey) pk, err := hex.DecodeString(minerPrivateKey)
if err != nil { if err != nil {
...@@ -508,8 +508,8 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -508,8 +508,8 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
return return
} }
findDepth := searchHashMatchBlockDepth depth := searchHashMatchDepth
for height := lastBlock.Height; height > 0 && findDepth > 0; height-- { for height := lastBlock.Height; height > 0 && depth > 0; height-- {
block, err := client.GetBlockByHeight(height) block, err := client.GetBlockByHeight(height)
if err != nil { if err != nil {
return return
...@@ -522,11 +522,12 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[ ...@@ -522,11 +522,12 @@ func (client *client) switchHashMatchedBlock(currSeq *int64, preMainBlockHash *[
miner.MainBlockHeight, "mainHash", common.Bytes2Hex(miner.MainBlockHash)) miner.MainBlockHeight, "mainHash", common.Bytes2Hex(miner.MainBlockHash))
mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash) mainSeq, err := client.GetSeqByHashOnMainChain(miner.MainBlockHash)
if err != nil { if err != nil {
findDepth-- depth--
if findDepth == 0 { if depth == 0 {
plog.Error("switchHashMatchedBlock depth overflow", "last info:mainHeight", miner.MainBlockHeight, plog.Error("switchHashMatchedBlock depth overflow", "last info:mainHeight", miner.MainBlockHeight,
"mainHash", common.Bytes2Hex(miner.MainBlockHash), "search depth", searchHashMatchBlockDepth) "mainHash", common.Bytes2Hex(miner.MainBlockHash), "search startHeight",lastBlock.Height,"curHeight",miner.Height,
panic("switchHashMatchedBlock depth overflow, restart and re-connect main node") "search depth", searchHashMatchDepth)
panic("search HashMatchedBlock overflow, re-setting search depth and restart to try")
} }
if height == 1 { if height == 1 {
plog.Error("switchHashMatchedBlock search to height=1 not found", "lastBlockHeight", lastBlock.Height, plog.Error("switchHashMatchedBlock search to height=1 not found", "lastBlockHeight", lastBlock.Height,
......
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