Extract virtualResolveChunk constant

This commit is contained in:
msutton 2022-08-01 23:52:23 +03:00
parent a5be6afd9c
commit 4d3dce456c

View File

@ -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
}