mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +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 {
|
func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updateVirtual bool) error {
|
||||||
|
|
||||||
if updateVirtual {
|
if updateVirtual {
|
||||||
// Make sure virtual is resolved before adding the new block
|
s.lock.Lock()
|
||||||
err := s.ResolveVirtual(nil)
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
s.lock.Unlock()
|
||||||
|
|
||||||
|
for !isCompletelyResolved {
|
||||||
|
isCompletelyResolved, err = s.resolveVirtualChunkWithLock(100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user