Cache the pruning point anticone (#2002)

This commit is contained in:
Michael Sutton 2022-04-03 14:44:42 +03:00 committed by GitHub
parent 3f840233d8
commit ab73def07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -44,6 +44,9 @@ type pruningManager struct {
shouldSanityCheckPruningUTXOSet bool
k externalapi.KType
difficultyAdjustmentWindowSize int
cachedPruningPoint *externalapi.DomainHash
cachedPruningPointAnticone []*externalapi.DomainHash
}
// New instantiates a new PruningManager
@ -932,6 +935,12 @@ func (pm *pruningManager) PruningPointAndItsAnticone() ([]*externalapi.DomainHas
return nil, err
}
// By the Prunality proof, The pruning point anticone is a closed set (i.e., guaranteed not to change) ,
// so we can safely cache it.
if pm.cachedPruningPoint != nil && pm.cachedPruningPoint.Equal(pruningPoint) {
return append([]*externalapi.DomainHash{pruningPoint}, pm.cachedPruningPointAnticone...), nil
}
pruningPointAnticone, err := pm.dagTraversalManager.AnticoneFromVirtualPOV(stagingArea, pruningPoint)
if err != nil {
return nil, err
@ -958,6 +967,9 @@ func (pm *pruningManager) PruningPointAndItsAnticone() ([]*externalapi.DomainHas
return nil, sortErr
}
pm.cachedPruningPoint = pruningPoint
pm.cachedPruningPointAnticone = pruningPointAnticone
// The pruning point should always come first
return append([]*externalapi.DomainHash{pruningPoint}, pruningPointAnticone...), nil
}

View File

@ -11,6 +11,7 @@ func (d *domain) migrate() error {
if err != nil {
return err
}
log.Infof("Current pruning point: %s", pruningPoint)
if d.consensusConfig.Params.GenesisHash.Equal(pruningPoint) {
err = d.initStagingConsensus(d.consensusConfig)