Slightly improve the performance of antiPastHashesBetween. (#1312)

This commit is contained in:
stasatdaglabs 2020-12-29 10:36:18 +02:00 committed by GitHub
parent d91afbfe3b
commit 48278bd1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -42,7 +42,7 @@ func (flow *handleRequestBlocksFlow) start() error {
// We expect that if the other peer did not receive all the headers
// they requested, they'd re-request a block locator and re-request
// headers with a higher lowHash
const maxBlueScoreDifference = 1 << 12
const maxBlueScoreDifference = 1 << 10
blockHashes, err := flow.Domain().Consensus().GetHashesBetween(lowHash, highHash, maxBlueScoreDifference)
if err != nil {
return err

View File

@ -35,13 +35,19 @@ func (sm *syncManager) antiPastHashesBetween(lowHash, highHash *externalapi.Doma
// Using blueScore as an approximation is considered to be
// fairly accurate because we presume that most DAG blocks are
// blue.
for highBlockGHOSTDAGData.BlueScore()-lowBlockGHOSTDAGData.BlueScore()+1 > maxBlueScoreDifference {
highHash = highBlockGHOSTDAGData.SelectedParent()
var err error
iterator, err := sm.dagTraversalManager.SelectedChildIterator(highHash, lowHash)
if err != nil {
return nil, err
}
for iterator.Next() {
highHash = iterator.Get()
highBlockGHOSTDAGData, err = sm.ghostdagDataStore.Get(sm.databaseContext, highHash)
if err != nil {
return nil, err
}
if highBlockGHOSTDAGData.BlueScore()-lowBlockGHOSTDAGData.BlueScore()+1 > maxBlueScoreDifference {
break
}
}
}