Commit c9ffd835 authored by mdj33's avatar mdj33 Committed by 33cn

add lock to isCaughtup

parent fa8b1676
...@@ -68,6 +68,7 @@ type client struct { ...@@ -68,6 +68,7 @@ type client struct {
privateKey crypto.PrivKey privateKey crypto.PrivKey
wg sync.WaitGroup wg sync.WaitGroup
subCfg *subConfig subCfg *subConfig
mtx sync.Mutex
} }
type subConfig struct { type subConfig struct {
...@@ -139,7 +140,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -139,7 +140,6 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
grpcClient: grpcCli, grpcClient: grpcCli,
authAccount: subcfg.AuthAccount, authAccount: subcfg.AuthAccount,
privateKey: priKey, privateKey: priKey,
isCaughtUp: false,
subCfg: &subcfg, subCfg: &subcfg,
} }
if subcfg.WaitBlocks4CommitMsg < 2 { if subcfg.WaitBlocks4CommitMsg < 2 {
...@@ -473,11 +473,13 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type ...@@ -473,11 +473,13 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
txs := client.FilterTxsForPara(blockSeq.Detail) txs := client.FilterTxsForPara(blockSeq.Detail)
plog.Info("GetCurrentSeq", "Len of txs", len(txs), "seqTy", blockSeq.Seq.Type) plog.Info("GetCurrentSeq", "Len of txs", len(txs), "seqTy", blockSeq.Seq.Type)
client.mtx.Lock()
if lastSeq-currSeq > emptyBlockInterval { if lastSeq-currSeq > emptyBlockInterval {
client.isCaughtUp = false client.isCaughtUp = false
} else { } else {
client.isCaughtUp = true client.isCaughtUp = true
} }
client.mtx.Unlock()
if client.authAccount != "" { if client.authAccount != "" {
client.commitMsgClient.onMainBlockAdded(blockSeq.Detail) client.commitMsgClient.onMainBlockAdded(blockSeq.Detail)
...@@ -808,7 +810,11 @@ func (client *client) Query_IsCaughtUp(req *types.ReqNil) (types.Message, error) ...@@ -808,7 +810,11 @@ func (client *client) Query_IsCaughtUp(req *types.ReqNil) (types.Message, error)
if client == nil { if client == nil {
return nil, fmt.Errorf("%s", "client not bind message queue.") return nil, fmt.Errorf("%s", "client not bind message queue.")
} }
return &types.IsCaughtUp{Iscaughtup: client.isCaughtUp}, nil client.mtx.Lock()
caughtUp := client.isCaughtUp
client.mtx.Unlock()
return &types.IsCaughtUp{Iscaughtup: caughtUp}, nil
} }
func checkMinerTx(current *types.BlockDetail) error { func checkMinerTx(current *types.BlockDetail) error {
......
...@@ -97,7 +97,10 @@ out: ...@@ -97,7 +97,10 @@ out:
plog.Debug("para del block", "delHeight", height) plog.Debug("para del block", "delHeight", height)
case block := <-client.mainBlockAdd: case block := <-client.mainBlockAdd:
if client.currentTx != nil && client.paraClient.isCaughtUp { client.paraClient.mtx.Lock()
isCaughtUp := client.paraClient.isCaughtUp
client.paraClient.mtx.Unlock()
if client.currentTx != nil && isCaughtUp {
exist := checkTxInMainBlock(client.currentTx, block) exist := checkTxInMainBlock(client.currentTx, block)
if exist { if exist {
finishHeight = sendingHeight finishHeight = sendingHeight
...@@ -487,6 +490,7 @@ func (client *commitMsgClient) mainSync() error { ...@@ -487,6 +490,7 @@ func (client *commitMsgClient) mainSync() error {
func (client *commitMsgClient) getConsensusHeight(consensusRst chan *pt.ParacrossStatus) { func (client *commitMsgClient) getConsensusHeight(consensusRst chan *pt.ParacrossStatus) {
ticker := time.NewTicker(time.Second * time.Duration(consensusInterval)) ticker := time.NewTicker(time.Second * time.Duration(consensusInterval))
isSync := false isSync := false
isCaughtUp := false
defer ticker.Stop() defer ticker.Stop()
out: out:
...@@ -503,7 +507,10 @@ out: ...@@ -503,7 +507,10 @@ out:
isSync = true isSync = true
} }
if !client.paraClient.isCaughtUp { client.paraClient.mtx.Lock()
isCaughtUp = client.paraClient.isCaughtUp
client.paraClient.mtx.Unlock()
if !isCaughtUp {
plog.Debug("getConsensusHeight para is CatchingUp") plog.Debug("getConsensusHeight para is CatchingUp")
continue continue
} }
......
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