From ae2f32f9d8b4b6e740d33e19c104fbdcd00c363a Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Tue, 24 Nov 2020 21:51:30 +0800 Subject: [PATCH] func name --- statediff/service.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/statediff/service.go b/statediff/service.go index b29afc993..0bd31fdde 100644 --- a/statediff/service.go +++ b/statediff/service.go @@ -200,8 +200,9 @@ func (sds *Service) APIs() []rpc.API { } } -// Return the parent block of currentBlock, using the cached block if available -func (lbc *blockCache) replace(currentBlock *types.Block, bc blockChain) *types.Block { +// Return the parent block of currentBlock, using the cached block if available; +// and cache the passed block +func (lbc *blockCache) getParentBlock(currentBlock *types.Block, bc blockChain) *types.Block { lbc.Lock() parentHash := currentBlock.ParentHash() var parentBlock *types.Block @@ -248,7 +249,7 @@ func (sds *Service) writeLoopWorker(params workerParams) { log.Debug("WriteLoop(): chain event received", "event", chainEvent) currentBlock := chainEvent.Block statediffMetrics.lastEventHeight.Update(int64(currentBlock.Number().Uint64())) - parentBlock := sds.BlockCache.replace(currentBlock, sds.BlockChain) + parentBlock := sds.BlockCache.getParentBlock(currentBlock, sds.BlockChain) if parentBlock == nil { log.Error("Parent block is nil, skipping this block", "block height", currentBlock.Number()) continue @@ -290,7 +291,7 @@ func (sds *Service) Loop(chainEventCh chan core.ChainEvent) { continue } currentBlock := chainEvent.Block - parentBlock := sds.BlockCache.replace(currentBlock, sds.BlockChain) + parentBlock := sds.BlockCache.getParentBlock(currentBlock, sds.BlockChain) if parentBlock == nil { log.Error("Parent block is nil, skipping this block", "block height", currentBlock.Number()) continue