Commit 16b9b452 authored by harrylee2015's avatar harrylee2015 Committed by vipwzw

add feature for parachain check is sync..

parent 69aba101
......@@ -60,7 +60,7 @@ type client struct {
conn *grpc.ClientConn
grpcClient types.Chain33Client
paraClient paracross.ParacrossClient
isCatchingUp bool
iscaughtup bool
commitMsgClient *commitMsgClient
authAccount string
privateKey crypto.PrivKey
......@@ -119,6 +119,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
paraClient: paraCli,
authAccount: cfg.AuthAccount,
privateKey: priKey,
iscaughtup: false,
}
if cfg.WaitBlocks4CommitMsg < 2 {
......@@ -444,9 +445,9 @@ func (client *client) RequestTx(currSeq int64, preMainBlockHash []byte) ([]*type
plog.Info("GetCurrentSeq", "Len of txs", len(txs), "seqTy", seqTy)
if lastSeq-currSeq > emptyBlockInterval {
client.isCatchingUp = true
client.iscaughtup = false
} else {
client.isCatchingUp = false
client.iscaughtup = true
}
if client.authAccount != "" {
......@@ -654,7 +655,7 @@ func (client *client) CreateBlock() {
plog.Error("Incorrect sequence type")
incSeqFlag = false
}
if !client.isCatchingUp {
if client.iscaughtup {
time.Sleep(time.Second * time.Duration(blockSec))
}
}
......@@ -766,6 +767,14 @@ func (client *client) DelBlock(block *types.Block, seq int64) error {
return nil
}
//IsCaughtUp 是否追上最新高度,
func (client *client) Query_IsCaughtUp(req *types.ReqNil) (types.Message, error) {
if client == nil {
return nil, fmt.Errorf("client not bind message queue.")
}
return &types.IsCaughtUp{Iscaughtup: client.iscaughtup}, nil
}
func checkMinerTx(current *types.BlockDetail) error {
//检查第一个笔交易的execs, 以及执行状态
if len(current.Block.Txs) == 0 {
......
......@@ -83,7 +83,7 @@ out:
}
case block := <-client.mainBlockAdd:
if client.currentTx != nil && !client.paraClient.isCatchingUp {
if client.currentTx != nil && client.paraClient.iscaughtup {
exist := checkTxInMainBlock(client.currentTx, block)
if exist {
finishHeight = sendingHeight
......
......@@ -678,7 +678,13 @@ func (q *QueueProtocol) DumpPrivkey(param *types.ReqString) (*types.ReplyString,
// IsSync query the blockchain sync state
func (q *QueueProtocol) IsSync() (*types.Reply, error) {
msg, err := q.query(blockchainKey, types.EventIsSync, &types.ReqNil{})
var msg queue.Message
var err error
if types.IsPara() {
msg, err = q.query(consensusKey, types.EventIsSync, &types.ReqNil{})
} else {
msg, err = q.query(blockchainKey, types.EventIsSync, &types.ReqNil{})
}
if err != nil {
log.Error("IsSync", "Error", err.Error())
return nil, err
......
......@@ -216,6 +216,23 @@ func (bc *BaseClient) EventLoop() {
block := msg.GetData().(*types.BlockDetail)
err := bc.CheckBlock(block)
msg.ReplyErr("EventCheckBlock", err)
} else if msg.Ty == types.EventIsSync {
if types.IsPara() {
reply, err := QueryData.Call("para", "IsCaughtUp", &types.ReqNil{})
if err != nil {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, err))
} else {
if isCaughtUp, ok := reply.(*types.IsCaughtUp); ok {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, isCaughtUp))
} else {
err = types.ErrTypeAsset
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, err))
}
}
} else {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, &types.IsCaughtUp{Iscaughtup: bc.IsCaughtUp()}))
}
} else if msg.Ty == types.EventMinerStart {
if !atomic.CompareAndSwapInt32(&bc.minerStart, 0, 1) {
msg.ReplyErr("EventMinerStart", types.ErrMinerIsStared)
......
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