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