mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-26 23:46:08 +00:00
Merge branch 'utxo-child-bug' into bump_v0.12.4-rc1
This commit is contained in:
commit
5b78323d7a
@ -61,6 +61,7 @@ type consensus struct {
|
||||
blocksWithTrustedDataDAAWindowStore model.BlocksWithTrustedDataDAAWindowStore
|
||||
|
||||
consensusEventsChan chan externalapi.ConsensusEvent
|
||||
virtualNotUpdated bool
|
||||
}
|
||||
|
||||
func (s *consensus) ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData, validateUTXO bool) error {
|
||||
@ -194,28 +195,22 @@ func (s *consensus) BuildBlockTemplate(coinbaseData *externalapi.DomainCoinbaseD
|
||||
// ValidateAndInsertBlock validates the given block and, if valid, applies it
|
||||
// to the current state
|
||||
func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updateVirtual bool) error {
|
||||
|
||||
if updateVirtual {
|
||||
s.lock.Lock()
|
||||
// Make sure virtual is resolved correctly before adding the new block
|
||||
isCompletelyResolved, err := s.resolveVirtualNoLock(100)
|
||||
if err != nil {
|
||||
if s.virtualNotUpdated {
|
||||
s.lock.Unlock()
|
||||
return err
|
||||
}
|
||||
if isCompletelyResolved {
|
||||
defer s.lock.Unlock()
|
||||
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
||||
err := s.ResolveVirtual(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||
}
|
||||
s.lock.Unlock()
|
||||
|
||||
for !isCompletelyResolved {
|
||||
isCompletelyResolved, err = s.resolveVirtualChunkWithLock(100)
|
||||
defer s.lock.Unlock()
|
||||
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||
@ -238,6 +233,11 @@ func (s *consensus) validateAndInsertBlockNoLock(block *externalapi.DomainBlock,
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -940,6 +940,7 @@ func (s *consensus) resolveVirtualNoLock(maxBlocksToResolve uint64) (bool, error
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
s.virtualNotUpdated = !isCompletelyResolved
|
||||
|
||||
stagingArea := model.NewStagingArea()
|
||||
err = s.pruningManager.UpdatePruningPointByVirtual(stagingArea)
|
||||
|
||||
@ -515,6 +515,7 @@ func (f *factory) NewConsensus(config *Config, db infrastructuredatabase.Databas
|
||||
blocksWithTrustedDataDAAWindowStore: daaWindowStore,
|
||||
|
||||
consensusEventsChan: consensusEventsChan,
|
||||
virtualNotUpdated: true,
|
||||
}
|
||||
|
||||
if isOldReachabilityInitialized {
|
||||
|
||||
@ -168,10 +168,17 @@ func (csm *consensusStateManager) ResolveVirtual(maxBlocksToResolve uint64) (*ex
|
||||
// If `isCompletelyResolved`, set virtual correctly with all tips which have less blue work than pending
|
||||
virtualTipCandidates := []*externalapi.DomainHash{intermediateTip}
|
||||
if isCompletelyResolved {
|
||||
virtualTipCandidates, err = csm.getLowerTips(readStagingArea, pendingTip)
|
||||
lowerTips, err := csm.getLowerTips(readStagingArea, pendingTip)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
log.Debugf("Picking virtual parents from relevant tips len: %d", len(lowerTips))
|
||||
virtualTipCandidates, err = csm.pickVirtualParents(readStagingArea, lowerTips)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
log.Debugf("Picked virtual parents: %s", virtualTipCandidates)
|
||||
}
|
||||
virtualUTXODiff, err := csm.updateVirtualWithParents(updateVirtualStagingArea, virtualTipCandidates)
|
||||
if err != nil {
|
||||
@ -183,7 +190,6 @@ func (csm *consensusStateManager) ResolveVirtual(maxBlocksToResolve uint64) (*ex
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// TODO: why was `readStagingArea` used here ?
|
||||
selectedParentChainChanges, err := csm.dagTraversalManager.
|
||||
CalculateChainPath(updateVirtualStagingArea, prevVirtualSelectedParent, pendingTip)
|
||||
if err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user