Fix IBD sync conditions (#2174)

* Fix IBD sync conditions

* Fix syntax

* Fix Sprintf

* Bump version

* On negotiation check only blocks in future of PP

* Only log error and add comment

* Fix comment
This commit is contained in:
Ori Newman 2022-11-29 17:18:07 +02:00 committed by GitHub
parent d4a27bf1c1
commit beee947dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View File

@ -175,6 +175,11 @@ func (flow *handleIBDFlow) negotiateMissingSyncerChainSegment() (*externalapi.Do
chainNegotiationRestartCounter := 0 chainNegotiationRestartCounter := 0
chainNegotiationZoomCounts := 0 chainNegotiationZoomCounts := 0
initialLocatorLen := len(locatorHashes) initialLocatorLen := len(locatorHashes)
pruningPoint, err := flow.Domain().Consensus().PruningPoint()
if err != nil {
return nil, nil, err
}
for { for {
var lowestUnknownSyncerChainHash, currentHighestKnownSyncerChainHash *externalapi.DomainHash var lowestUnknownSyncerChainHash, currentHighestKnownSyncerChainHash *externalapi.DomainHash
for _, syncerChainHash := range locatorHashes { for _, syncerChainHash := range locatorHashes {
@ -187,9 +192,22 @@ func (flow *handleIBDFlow) negotiateMissingSyncerChainSegment() (*externalapi.Do
return nil, nil, protocolerrors.Errorf(true, "Sent invalid chain block %s", syncerChainHash) return nil, nil, protocolerrors.Errorf(true, "Sent invalid chain block %s", syncerChainHash)
} }
isPruningPointOnSyncerChain, err := flow.Domain().Consensus().IsInSelectedParentChainOf(pruningPoint, syncerChainHash)
if err != nil {
log.Errorf("Error checking isPruningPointOnSyncerChain: %s", err)
}
// We're only interested in syncer chain blocks that have our pruning
// point in their selected chain. Otherwise, it means one of the following:
// 1) We will not switch the virtual selected chain to the syncers chain since it will violate finality
// (hence we can ignore it unless merged by others).
// 2) syncerChainHash is actually in the past of our pruning point so there's no
// point in syncing from it.
if err == nil && isPruningPointOnSyncerChain {
currentHighestKnownSyncerChainHash = syncerChainHash currentHighestKnownSyncerChainHash = syncerChainHash
break break
} }
}
lowestUnknownSyncerChainHash = syncerChainHash lowestUnknownSyncerChainHash = syncerChainHash
} }
// No unknown blocks, break. Note this can only happen in the first iteration // No unknown blocks, break. Note this can only happen in the first iteration
@ -285,7 +303,11 @@ func (flow *handleIBDFlow) isGenesisVirtualSelectedParent() (bool, error) {
func (flow *handleIBDFlow) logIBDFinished(isFinishedSuccessfully bool, err error) { func (flow *handleIBDFlow) logIBDFinished(isFinishedSuccessfully bool, err error) {
successString := "successfully" successString := "successfully"
if !isFinishedSuccessfully { if !isFinishedSuccessfully {
if err != nil {
successString = fmt.Sprintf("(interrupted: %s)", err) successString = fmt.Sprintf("(interrupted: %s)", err)
} else {
successString = fmt.Sprintf("(interrupted)")
}
} }
log.Infof("IBD with peer %s finished %s", flow.peer, successString) log.Infof("IBD with peer %s finished %s", flow.peer, successString)
} }

View File

@ -85,9 +85,14 @@ func (flow *handleIBDFlow) shouldSyncAndShouldDownloadHeadersProof(
return true, true, nil return true, true, nil
} }
if highestKnownSyncerChainHash == nil {
log.Infof("Stopping IBD since IBD from this node will cause a finality conflict")
return false, false, nil return false, false, nil
} }
return false, true, nil
}
return false, true, nil return false, true, nil
} }

View File

@ -11,7 +11,7 @@ const validCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs
const ( const (
appMajor uint = 0 appMajor uint = 0
appMinor uint = 12 appMinor uint = 12
appPatch uint = 10 appPatch uint = 11
) )
// appBuild is defined as a variable so it can be overridden during the build // appBuild is defined as a variable so it can be overridden during the build