mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 14:35:53 +00:00
Avoid locking consensus twice in the common case of adding block with updateVirtual=true
This commit is contained in:
commit
b2b79e9b0a
@ -196,11 +196,26 @@ func (s *consensus) BuildBlockTemplate(coinbaseData *externalapi.DomainCoinbaseD
|
||||
func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updateVirtual bool) error {
|
||||
|
||||
if updateVirtual {
|
||||
// Make sure virtual is resolved before adding the new block
|
||||
err := s.ResolveVirtual(nil)
|
||||
s.lock.Lock()
|
||||
// Make sure virtual is resolved correctly before adding the new block
|
||||
isCompletelyResolved, err := s.resolveVirtualNoLock(100)
|
||||
if err != nil {
|
||||
s.lock.Unlock()
|
||||
return err
|
||||
}
|
||||
if isCompletelyResolved {
|
||||
defer s.lock.Unlock()
|
||||
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
s.lock.Unlock()
|
||||
|
||||
for !isCompletelyResolved {
|
||||
isCompletelyResolved, err = s.resolveVirtualChunkWithLock(100)
|
||||
}
|
||||
}
|
||||
|
||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user