Commit 14ddd950 authored by yukang's avatar yukang Committed by vipwzw

Optimize some sync code for review

parent 0e0bc545
...@@ -192,8 +192,8 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -192,8 +192,8 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
paraClient: para, paraClient: para,
notifyChan: make(chan bool), notifyChan: make(chan bool),
quitChan: make(chan struct{}), quitChan: make(chan struct{}),
maxCacheCount: 1000, maxCacheCount: DefaultMaxCacheCount,
maxSyncErrCount: 100, maxSyncErrCount: DefaultMaxSyncErrCount,
isPrintDebugInfo: false, isPrintDebugInfo: false,
} }
if subcfg.MaxCacheCount > 0 { if subcfg.MaxCacheCount > 0 {
......
...@@ -15,6 +15,13 @@ import ( ...@@ -15,6 +15,13 @@ import (
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
) )
const (
//DefaultMaxCacheCount 默认local最大缓冲数
DefaultMaxCacheCount = int64(1000)
//DefaultMaxSyncErrCount 默认连续错误最大数量
DefaultMaxSyncErrCount = int32(100)
)
//BlockSyncClient 区块同步控制和状态变量 //BlockSyncClient 区块同步控制和状态变量
type BlockSyncClient struct { type BlockSyncClient struct {
paraClient *client paraClient *client
...@@ -298,6 +305,11 @@ func (client *BlockSyncClient) getFirstLocalHeight() (int64, error) { ...@@ -298,6 +305,11 @@ func (client *BlockSyncClient) getFirstLocalHeight() (int64, error) {
if err != nil { if err != nil {
return -1, err return -1, err
} }
if len(value) == 0 {
return -1, types.ErrNotFound
}
if value[0] == nil { if value[0] == nil {
return -1, types.ErrNotFound return -1, types.ErrNotFound
} }
...@@ -403,6 +415,10 @@ func (client *BlockSyncClient) rollbackBlock(block *types.Block) error { ...@@ -403,6 +415,10 @@ func (client *BlockSyncClient) rollbackBlock(block *types.Block) error {
} }
blocks := resp.GetData().(*types.BlockDetails) blocks := resp.GetData().(*types.BlockDetails)
if len(blocks.Items) == 0 {
return errors.New("para sync -blocks Items len = 0 ")
}
parablockDetail := &types.ParaChainBlockDetail{Blockdetail: blocks.Items[0]} parablockDetail := &types.ParaChainBlockDetail{Blockdetail: blocks.Items[0]}
msg = client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventDelParaChainBlockDetail, parablockDetail) msg = client.paraClient.GetQueueClient().NewMessage("blockchain", types.EventDelParaChainBlockDetail, parablockDetail)
err = client.paraClient.GetQueueClient().Send(msg, true) err = client.paraClient.GetQueueClient().Send(msg, 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