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
|
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,16 +195,16 @@ 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 err
|
||||||
}
|
}
|
||||||
if isCompletelyResolved {
|
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||||
|
}
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
_, err := s.validateAndInsertBlockNoLock(block, updateVirtual)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -211,12 +212,6 @@ func (s *consensus) ValidateAndInsertBlock(block *externalapi.DomainBlock, updat
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.lock.Unlock()
|
|
||||||
|
|
||||||
for !isCompletelyResolved {
|
|
||||||
isCompletelyResolved, err = s.resolveVirtualChunkWithLock(100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
return s.validateAndInsertBlockWithLock(block, updateVirtual)
|
||||||
}
|
}
|
||||||
@ -238,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
|
||||||
@ -940,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 {
|
||||||
|
|||||||
@ -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
|
// If `isCompletelyResolved`, set virtual correctly with all tips which have less blue work than pending
|
||||||
virtualTipCandidates := []*externalapi.DomainHash{intermediateTip}
|
virtualTipCandidates := []*externalapi.DomainHash{intermediateTip}
|
||||||
if isCompletelyResolved {
|
if isCompletelyResolved {
|
||||||
virtualTipCandidates, err = csm.getLowerTips(readStagingArea, pendingTip)
|
lowerTips, err := csm.getLowerTips(readStagingArea, pendingTip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
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)
|
virtualUTXODiff, err := csm.updateVirtualWithParents(updateVirtualStagingArea, virtualTipCandidates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -183,7 +190,6 @@ func (csm *consensusStateManager) ResolveVirtual(maxBlocksToResolve uint64) (*ex
|
|||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: why was `readStagingArea` used here ?
|
|
||||||
selectedParentChainChanges, err := csm.dagTraversalManager.
|
selectedParentChainChanges, err := csm.dagTraversalManager.
|
||||||
CalculateChainPath(updateVirtualStagingArea, prevVirtualSelectedParent, pendingTip)
|
CalculateChainPath(updateVirtualStagingArea, prevVirtualSelectedParent, pendingTip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user