Commit 32d57ba1 authored by yukang's avatar yukang Committed by vipwzw

Don't print some debug info for performance

parent fd136884
...@@ -190,6 +190,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -190,6 +190,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
quitChan: make(chan struct{}), quitChan: make(chan struct{}),
maxCacheCount: 1000, maxCacheCount: 1000,
maxSyncErrCount: 100, maxSyncErrCount: 100,
isPrintDebugInfo: false,
} }
if subcfg.MaxCacheCount > 0 { if subcfg.MaxCacheCount > 0 {
para.blockSyncClient.maxCacheCount = subcfg.MaxCacheCount para.blockSyncClient.maxCacheCount = subcfg.MaxCacheCount
......
...@@ -30,6 +30,8 @@ type BlockSyncClient struct { ...@@ -30,6 +30,8 @@ type BlockSyncClient struct {
maxCacheCount int64 maxCacheCount int64
//isSyncCaughtUp 是否追赶上 //isSyncCaughtUp 是否追赶上
isSyncCaughtUpAtom int32 isSyncCaughtUpAtom int32
//printDebugInfo 打印Debug信息
isPrintDebugInfo bool
} }
//NextActionType 定义每一轮可执行操作 //NextActionType 定义每一轮可执行操作
...@@ -63,9 +65,9 @@ func (client *BlockSyncClient) SyncHasCaughtUp() bool { ...@@ -63,9 +65,9 @@ func (client *BlockSyncClient) SyncHasCaughtUp() bool {
//NotifyLocalChange 下载状态通知,供下载层调用 //NotifyLocalChange 下载状态通知,供下载层调用
func (client *BlockSyncClient) NotifyLocalChange() { func (client *BlockSyncClient) NotifyLocalChange() {
plog.Info("Para sync - notify change") client.printDebugInfo("Para sync - notify change")
if client.getBlockSyncState() != BlockSyncStateSyncing { if client.getBlockSyncState() != BlockSyncStateSyncing {
plog.Info("Para sync - notified change") client.printDebugInfo("Para sync - notified change")
client.notifyChan <- true client.notifyChan <- true
} }
} }
...@@ -95,14 +97,14 @@ out: ...@@ -95,14 +97,14 @@ out:
} }
} }
plog.Info("Para sync - quit block sync goroutine") client.printDebugInfo("Para sync - quit block sync goroutine")
client.paraClient.wg.Done() client.paraClient.wg.Done()
} }
//批量执行同步区块 //批量执行同步区块
func (client *BlockSyncClient) batchSyncBlocks() { func (client *BlockSyncClient) batchSyncBlocks() {
client.setBlockSyncState(BlockSyncStateSyncing) client.setBlockSyncState(BlockSyncStateSyncing)
plog.Info("Para sync - syncing") client.printDebugInfo("Para sync - syncing")
errCount := int32(0) errCount := int32(0)
for { for {
...@@ -131,7 +133,7 @@ func (client *BlockSyncClient) batchSyncBlocks() { ...@@ -131,7 +133,7 @@ func (client *BlockSyncClient) batchSyncBlocks() {
} }
client.setBlockSyncState(BlockSyncStateFinished) client.setBlockSyncState(BlockSyncStateFinished)
plog.Info("Para sync - finished") client.printDebugInfo("Para sync - finished")
return return
} }
} }
...@@ -211,7 +213,7 @@ func (client *BlockSyncClient) syncBlocksIfNeed() (bool, error) { ...@@ -211,7 +213,7 @@ func (client *BlockSyncClient) syncBlocksIfNeed() (bool, error) {
isSyncCaughtUp := lastBlock.Height+1 == lastLocalHeight isSyncCaughtUp := lastBlock.Height+1 == lastLocalHeight
client.setSyncCaughtUp(isSyncCaughtUp) client.setSyncCaughtUp(isSyncCaughtUp)
if client.paraClient.authAccount != "" { if client.paraClient.authAccount != "" {
plog.Info("Para sync - add block commit", "isSyncCaughtUp", isSyncCaughtUp) client.printDebugInfo("Para sync - add block commit", "isSyncCaughtUp", isSyncCaughtUp)
client.paraClient.commitMsgClient.updateChainHeight(lastBlock.Height+1, false) client.paraClient.commitMsgClient.updateChainHeight(lastBlock.Height+1, false)
} }
} }
...@@ -230,7 +232,7 @@ func (client *BlockSyncClient) syncBlocksIfNeed() (bool, error) { ...@@ -230,7 +232,7 @@ func (client *BlockSyncClient) syncBlocksIfNeed() (bool, error) {
if err == nil { if err == nil {
client.setSyncCaughtUp(false) client.setSyncCaughtUp(false)
if client.paraClient.authAccount != "" { if client.paraClient.authAccount != "" {
plog.Info("Para sync - rollback block commit", "isSyncCaughtUp", false) client.printDebugInfo("Para sync - rollback block commit", "isSyncCaughtUp", false)
client.paraClient.commitMsgClient.updateChainHeight(lastBlock.Height-1, true) client.paraClient.commitMsgClient.updateChainHeight(lastBlock.Height-1, true)
} }
} }
...@@ -267,7 +269,7 @@ func (client *BlockSyncClient) delLocalBlocks(startHeight int64, endHeight int64 ...@@ -267,7 +269,7 @@ func (client *BlockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
kv := &types.KeyValue{Key: key, Value: types.Encode(&types.Int64{Data: endHeight + 1})} kv := &types.KeyValue{Key: key, Value: types.Encode(&types.Int64{Data: endHeight + 1})}
set.KV = append(set.KV, kv) set.KV = append(set.KV, kv)
plog.Info("Para sync - clear local blocks", "startHeight:", startHeight, "endHeight:", endHeight) client.printDebugInfo("Para sync - clear local blocks", "startHeight:", startHeight, "endHeight:", endHeight)
return client.paraClient.setLocalDb(set) return client.paraClient.setLocalDb(set)
} }
...@@ -356,7 +358,7 @@ func (client *BlockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc ...@@ -356,7 +358,7 @@ func (client *BlockSyncClient) addMinerTx(preStateHash []byte, block *types.Bloc
//添加一个区块 //添加一个区块
func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.ParaLocalDbBlock) error { func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.ParaLocalDbBlock) error {
var newBlock types.Block var newBlock types.Block
plog.Debug(fmt.Sprintf("Para sync - the len txs is: %v", len(localBlock.Txs))) client.printDebugInfo(fmt.Sprintf("Para sync - the len txs is: %v", len(localBlock.Txs)))
newBlock.ParentHash = lastBlock.Hash() newBlock.ParentHash = lastBlock.Hash()
newBlock.Height = lastBlock.Height + 1 newBlock.Height = lastBlock.Height + 1
...@@ -374,7 +376,7 @@ func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P ...@@ -374,7 +376,7 @@ func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P
err = client.writeBlock(lastBlock.StateHash, &newBlock) err = client.writeBlock(lastBlock.StateHash, &newBlock)
plog.Debug("Para sync - para create new Block", "newblock.ParentHash", common.ToHex(newBlock.ParentHash), client.printDebugInfo("Para sync - para create new Block", "newblock.ParentHash", common.ToHex(newBlock.ParentHash),
"newblock.Height", newBlock.Height, "newblock.TxHash", common.ToHex(newBlock.TxHash), "newblock.Height", newBlock.Height, "newblock.TxHash", common.ToHex(newBlock.TxHash),
"newblock.BlockTime", newBlock.BlockTime) "newblock.BlockTime", newBlock.BlockTime)
...@@ -383,7 +385,7 @@ func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P ...@@ -383,7 +385,7 @@ func (client *BlockSyncClient) addBlock(lastBlock *types.Block, localBlock *pt.P
// 向blockchain删区块 // 向blockchain删区块
func (client *BlockSyncClient) rollbackBlock(block *types.Block) error { func (client *BlockSyncClient) rollbackBlock(block *types.Block) error {
plog.Debug("Para sync - delete block in parachain") client.printDebugInfo("Para sync - delete block in parachain")
start := block.Height start := block.Height
if start == 0 { if start == 0 {
...@@ -469,9 +471,16 @@ func (client *BlockSyncClient) printError(err error) { ...@@ -469,9 +471,16 @@ func (client *BlockSyncClient) printError(err error) {
plog.Error(fmt.Sprintf("Para sync - sync block error:%v", err.Error())) plog.Error(fmt.Sprintf("Para sync - sync block error:%v", err.Error()))
} }
//打印调试信息
func (client *BlockSyncClient) printDebugInfo(msg string, ctx ...interface{}) {
if client.isPrintDebugInfo {
plog.Info(msg, ctx...)
}
}
//初始化 //初始化
func (client *BlockSyncClient) syncInit() { func (client *BlockSyncClient) syncInit() {
plog.Info("Para sync - init") client.printDebugInfo("Para sync - init")
client.setBlockSyncState(BlockSyncStateNone) client.setBlockSyncState(BlockSyncStateNone)
client.setSyncCaughtUp(false) client.setSyncCaughtUp(false)
err := client.initFirstLocalHeightIfNeed() err := client.initFirstLocalHeightIfNeed()
......
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