From 4d3dce456cd2d31c58cc798b23c90d5951de1a0e Mon Sep 17 00:00:00 2001 From: msutton Date: Mon, 1 Aug 2022 23:52:23 +0300 Subject: [PATCH] Extract virtualResolveChunk constant --- domain/consensus/consensus.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/domain/consensus/consensus.go b/domain/consensus/consensus.go index f96015679..20d02be9c 100644 --- a/domain/consensus/consensus.go +++ b/domain/consensus/consensus.go @@ -64,6 +64,12 @@ type consensus struct { virtualNotUpdated bool } +// In order to prevent a situation that the consensus lock is held for too much time, we +// release the lock each time we resolve 100 blocks. +// Note: `virtualResolveChunk` should be smaller than `params.FinalityDuration` in order to avoid a situation +// where UpdatePruningPointByVirtual skips a pruning point. +const virtualResolveChunk = 100 + func (s *consensus) ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData, validateUTXO bool) error { s.lock.Lock() defer s.lock.Unlock() @@ -200,8 +206,7 @@ func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updat if s.virtualNotUpdated { // We enter the loop in locked state for { - // See comment about the const used at `ResolveVirtual` - _, isCompletelyResolved, err := s.resolveVirtualChunkNoLock(100) + _, isCompletelyResolved, err := s.resolveVirtualChunkNoLock(virtualResolveChunk) if err != nil { s.lock.Unlock() return err @@ -930,11 +935,7 @@ func (s *consensus) ResolveVirtual(progressReportCallback func(uint64, uint64)) progressReportCallback(virtualDAAScoreStart, virtualDAAScore) } - // In order to prevent a situation that the consensus lock is held for too much time, we - // release the lock each time we resolve 100 blocks. - // Note: maxBlocksToResolve should be smaller than `params.FinalityDuration` in order to avoid a situation - // where UpdatePruningPointByVirtual skips a pruning point. - _, isCompletelyResolved, err := s.resolveVirtualChunkWithLock(100) + _, isCompletelyResolved, err := s.resolveVirtualChunkWithLock(virtualResolveChunk) if err != nil { return err }