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

Store pivot block header #836

Merged

Conversation

ajsutton
Copy link
Contributor

PR description

When the pivot block header has been downloaded, store it to disk. Currently this is always removed on shutdown because the world state downloader can't currently handle resuming. However, once that is complete and we stop deleting the stored header on shutdown:

  • Fast sync is enabled when requested if a fast sync is still in progress, even if the chain head is no longer genesis
  • FastSyncActions will use that same pivot block when restarting

Note that the validation which disabled fast sync when the chain wasn't empty has been moved out of SynchronizerConfiguration into the new FastSynchronizer. The validation therefore happens later than previously and the EthProtocolManager will require Eth63 if fast sync is requested, even if it is disallowed due to the chain not being empty. Given how rare Eth62-only clients are these days and that we expect to be able to find Eth63 clients on the first run when fast sync is used this seems like a reasonable trade off. The code is now simpler and the decision to use fast sync is all in one place now.

The introduction of FastSynchronizer moves a lot of fast-sync specific code out of DefaultSynchronizer, keeping it simple and providing better isolation of concerns.

Allow fast sync to resume if chain head is not genesis but a fast sync is still in progress.
If present, use the stored pivot block header when restarting.
Extract the fast sync logic out of DefaultSynchronizer into it's own class.
Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

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

Looks good! Just left one optional comment.

@@ -126,6 +131,19 @@ private void waitForAnyPeer(final CompletableFuture<Void> result) {
}

public CompletableFuture<FastSyncState> selectPivotBlock() {
return loadPivotBlockFromStorage().orElseGet(this::selectPivotBlockFromPeers);
Copy link
Contributor

Choose a reason for hiding this comment

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

(optional / discussion) What about loading this from storage in the constructor? Otherwise, successive calls to this method may always return the same value, which you may not want or may be unexpected. Also thinking it might be nice to move the reading / writing of this to the FastSyncState class with something like FastSyncState.create(dataDir) that loads or creates a new state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think there are definitely some improvements along these lines. The changes have wound up being reasonable large though so I'm going to merge this and put up a follow-up PR so we can review them and discuss more clearly.

@ajsutton ajsutton merged commit 1ed7136 into PegaSysEng:master Feb 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants