mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
Keep the flag for tracking virtual state, since tip sorting perf is high with many tips
This commit is contained in:
parent
c93f310d20
commit
b1bf8ff259
@ -61,6 +61,7 @@ type consensus struct {
|
|||||||
blocksWithTrustedDataDAAWindowStore model.BlocksWithTrustedDataDAAWindowStore
|
blocksWithTrustedDataDAAWindowStore model.BlocksWithTrustedDataDAAWindowStore
|
||||||
|
|
||||||
consensusEventsChan chan externalapi.ConsensusEvent
|
consensusEventsChan chan externalapi.ConsensusEvent
|
||||||
|
virtualNotUpdated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *consensus) ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData, validateUTXO bool) error {
|
func (s *consensus) ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData, validateUTXO bool) error {
|
||||||
@ -194,31 +195,22 @@ func (s *consensus) BuildBlockTemplate(coinbaseData *externalapi.DomainCoinbaseD
|
|||||||
// ValidateAndInsertBlock validates the given block and, if valid, applies it
|
// ValidateAndInsertBlock validates the given block and, if valid, applies it
|
||||||
// to the current state
|
// to the current state
|
||||||
func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updateVirtual bool) error {
|
func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updateVirtual bool) error {
|
||||||
|
|
||||||
if updateVirtual {
|
if updateVirtual {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
// Make sure virtual is resolved correctly before adding the new block
|
if s.virtualNotUpdated {
|
||||||
isCompletelyResolved, err := s.resolveVirtualNoLock(100)
|
|
||||||
if err != nil {
|
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
|
err := s.ResolveVirtual(nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||||
|
}
|
||||||
|
defer s.lock.Unlock()
|
||||||
|
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if isCompletelyResolved {
|
return nil
|
||||||
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)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||||
@ -241,6 +233,11 @@ func (s *consensus) validateAndInsertBlockNoLock(block *externalapi.DomainBlock,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If block has a body, and yet virtual was not updated -- signify that virtual is in non-updated state
|
||||||
|
if !updateVirtual && blockStatus != externalapi.StatusHeaderOnly {
|
||||||
|
s.virtualNotUpdated = true
|
||||||
|
}
|
||||||
|
|
||||||
err = s.sendBlockAddedEvent(block, blockStatus)
|
err = s.sendBlockAddedEvent(block, blockStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -943,6 +940,7 @@ func (s *consensus) resolveVirtualNoLock(maxBlocksToResolve uint64) (bool, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
s.virtualNotUpdated = !isCompletelyResolved
|
||||||
|
|
||||||
stagingArea := model.NewStagingArea()
|
stagingArea := model.NewStagingArea()
|
||||||
err = s.pruningManager.UpdatePruningPointByVirtual(stagingArea)
|
err = s.pruningManager.UpdatePruningPointByVirtual(stagingArea)
|
||||||
|
|||||||
@ -515,6 +515,7 @@ func (f *factory) NewConsensus(config *Config, db infrastructuredatabase.Databas
|
|||||||
blocksWithTrustedDataDAAWindowStore: daaWindowStore,
|
blocksWithTrustedDataDAAWindowStore: daaWindowStore,
|
||||||
|
|
||||||
consensusEventsChan: consensusEventsChan,
|
consensusEventsChan: consensusEventsChan,
|
||||||
|
virtualNotUpdated: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if isOldReachabilityInitialized {
|
if isOldReachabilityInitialized {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user