Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Synchroniser to wait for new peer if best is up to date #1161

Merged
merged 5 commits into from
Mar 26, 2019

Conversation

rain-on
Copy link
Contributor

@rain-on rain-on commented Mar 25, 2019

When chain downloading, the SyncTargetManager continues to
attempt to download headers/blocks from the current syncTarget,
even if the system is "insync". This is due to the fact that
the "insync" check is only performed at initial peer selection,
rather than on each loop of the chain downloader.

When chain downloading, the SyncTargetManager continues to
attempt to download headers/blocks from the current syncTarget,
even if the system is "insync". This is due to the fact that
the "insync" check is only performed at initial peer selection,
rather than on each loop of the chain downloader.
@rain-on rain-on requested a review from ajsutton March 25, 2019 06:20
.map(CompletableFuture::completedFuture) // Return an existing sync target if present
.orElseGet(this::selectNewSyncTarget);
if (syncState.syncTarget().isPresent() && !syncState.isInSync()) {
return CompletableFuture.completedFuture(syncState.syncTarget().get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks like the right direction.

The isInSync check has a small tolerance to avoid rapidly toggling between inSync/outOfSync when a new block is first published but we don't want that behaviour here. It's common to want different tolerances in different situations so we probably should introduce a isInSync(long tolerance) variant and use isInSync(0) here.

We could also remove the syncState.syncTarget().isPresent() condition because isInSync will always be true if there is no sync target.


@Override
public boolean isCaughtUpWithPeer(final EthPeer peer) {
return peer.chainState().getEstimatedHeight() < pivotBlockHeader.getNumber();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right thing to extract here. It is the right condition for where it was (when fast syncing we can select any peer as our target as long as their chain height is above the pivot block). We've caught up with that peer when our chain height >= pivotBlockHeader.getNumber().

@@ -144,4 +144,15 @@ public void clearSyncTarget(final SyncTarget syncTarget) {
public abstract boolean shouldSwitchSyncTarget(final SyncTarget currentTarget);

public abstract boolean shouldContinueDownloading();

public abstract boolean isCaughtUpWithPeer(final EthPeer peer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and implementations) could probably be protected.

Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rain-on rain-on merged commit 142d7b3 into PegaSysEng:master Mar 26, 2019
@rain-on rain-on deleted the uptodate branch March 26, 2019 04:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants