From edf48b6c46610b2b826ab241c7bb4e85d1cd054f Mon Sep 17 00:00:00 2001 From: capt4ce Date: Tue, 5 May 2020 15:23:03 +0800 Subject: [PATCH] fix the status for easier debug --- common/constant/statuses.go | 6 ++++-- core/blockchainsync/blockchainSync.go | 4 ++-- core/service/blockMainService.go | 12 ++++++------ core/service/blockSpineService.go | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/constant/statuses.go b/common/constant/statuses.go index eb1de1946..90259ede1 100644 --- a/common/constant/statuses.go +++ b/common/constant/statuses.go @@ -6,6 +6,8 @@ var ( BlockchainStatusReceivingBlock = 3 BlockchainStatusSyncingBlock = 4 // BlockchainSendingBlockTransactions needs blockchain lock because transactions are tightly coupled of what blocks the node has - BlockchainSendingBlockTransactions = 5 - BlockchainSendingBlocks = 6 + BlockchainSendingBlockTransactions = 5 + BlockchainSendingBlocks = 6 + BlockchainStatusReceivingBlockScanBlockPool = 7 + BlockchainStatusReceivingBlockProcessCompletedBlock = 8 ) diff --git a/core/blockchainsync/blockchainSync.go b/core/blockchainsync/blockchainSync.go index cabab5709..6c61fdbfc 100644 --- a/core/blockchainsync/blockchainSync.go +++ b/core/blockchainsync/blockchainSync.go @@ -138,7 +138,7 @@ func (bss *BlockchainSyncService) getMoreBlocks() { errCasted.Message) default: monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 7) - bss.Logger.Infof("failed to getPeerBlockchainInfo: %v", err) + bss.Logger.Infof("ChainSync: failed to getPeerBlockchainInfo: %v", err) } } @@ -151,7 +151,7 @@ func (bss *BlockchainSyncService) getMoreBlocks() { monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 10) if err != nil { monitoring.IncrementMainchainDownloadCycleDebugger(bss.ChainType, 11) - bss.Logger.Warnf("\nfailed to DownloadFromPeer: %v\n\n", err) + bss.Logger.Warnf("ChainSync: failed to DownloadFromPeer: %v\n\n", err) break } diff --git a/core/service/blockMainService.go b/core/service/blockMainService.go index a201b4a54..0dbb95a27 100644 --- a/core/service/blockMainService.go +++ b/core/service/blockMainService.go @@ -217,9 +217,9 @@ func (bs *BlockService) ChainWriteLock(actionType int) { // ChainWriteUnlock unlocks the chain func (bs *BlockService) ChainWriteUnlock(actionType int) { - monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle) - monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType) bs.Unlock() + monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType) + monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle) } // NewGenesisBlock create new block that is fixed in the value of cumulative difficulty, smith scale, and the block signature @@ -638,8 +638,8 @@ func (bs *BlockService) PushBlock(previousBlock, block *model.Block, broadcast, // ScanBlockPool scan the whole block pool to check if there are any block that's legal to be pushed yet func (bs *BlockService) ScanBlockPool() error { - bs.ChainWriteLock(constant.BlockchainStatusReceivingBlock) - defer bs.ChainWriteUnlock(constant.BlockchainStatusReceivingBlock) + bs.ChainWriteLock(constant.BlockchainStatusReceivingBlockScanBlockPool) + defer bs.ChainWriteUnlock(constant.BlockchainStatusReceivingBlockScanBlockPool) previousBlock, err := bs.GetLastBlock() if err != nil { return err @@ -1478,8 +1478,8 @@ func (bs *BlockService) WillSmith( // ProcessCompletedBlock to process block that already having all needed transactions func (bs *BlockService) ProcessCompletedBlock(block *model.Block) error { - bs.ChainWriteLock(constant.BlockchainStatusReceivingBlock) - defer bs.ChainWriteUnlock(constant.BlockchainStatusReceivingBlock) + bs.ChainWriteLock(constant.BlockchainStatusReceivingBlockProcessCompletedBlock) + defer bs.ChainWriteUnlock(constant.BlockchainStatusReceivingBlockProcessCompletedBlock) lastBlock, err := bs.GetLastBlock() if err != nil { return err diff --git a/core/service/blockSpineService.go b/core/service/blockSpineService.go index 85fb95043..eda944322 100644 --- a/core/service/blockSpineService.go +++ b/core/service/blockSpineService.go @@ -150,9 +150,9 @@ func (bs *BlockSpineService) ChainWriteLock(actionType int) { // ChainWriteUnlock unlocks the chain func (bs *BlockSpineService) ChainWriteUnlock(actionType int) { - monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle) - monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType) bs.Unlock() + monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType) + monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle) } // NewGenesisBlock create new block that is fixed in the value of cumulative difficulty, smith scale, and the block signature