Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize pivot block selector on PoS networks #4488

Merged
merged 25 commits into from
Oct 6, 2022

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Oct 6, 2022

PR description

This PR is built on top of #4487 so check it first

This is the 3rd PR of a series to optimize the initial sync on PoS networks, that is ongoing here #4462, but since it is quite big, I am splitting it in smaller PRs to simplify the code review.

On PoS network we use as pivot block, the last finalized block sent by the Consensus Layer, so we do
not need peers, and so all the logic for selecting the pivot block from peers
has been moved from FastSyncActions to PivotSelectorFromPeers.
We do not need anymore the TransictionPeerSelector, and the --fast-sync-min-peers
applies only to PoW networks.

Fixed Issue(s)

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Changelog

Renaming to make clear everywhere that the forkchoice is not verified, so
it will be clear in case there will be a future event for a verified forkchoice.
Finalized block hash no more optional.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
On PoS network we use a pivot block sent by the Consensus Layer, so we do
not need peers, and so all the logic for selecting the pivot block from peers
has been moved from FastSyncActions to PivotSelectorFromPeers.
We do not need anymore the TransictionPeerSelector, and the --fast-sync-min-peers
applies only to PoW networks.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 changed the title Optimize snap sync3 Optimize pivot block selector on PoS networks Oct 6, 2022
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 added mainnet syncing doc-change-required Indicates an issue or PR that requires doc to be updated labels Oct 6, 2022
@fab-10 fab-10 marked this pull request as ready for review October 6, 2022 13:37
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
# Conflicts:
#	CHANGELOG.md
#	besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
@fab-10 fab-10 mentioned this pull request Oct 6, 2022
2 tasks
fab-10 and others added 13 commits October 6, 2022 19:02
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
# Conflicts:
#	besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
Renaming to make clear everywhere that the forkchoice is not verified, so
it will be clear in case there will be a future event for a verified forkchoice.
Finalized block hash no more optional.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
…ze-snap-sync3

Signed-off-by: garyschulte <garyschulte@gmail.com>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
Signed-off-by: Justin Florentine <justin+github@florentine.us>
@jflo jflo enabled auto-merge (squash) October 6, 2022 20:19
@jflo jflo disabled auto-merge October 6, 2022 20:19
Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

non-blocking feedback, in light of the fact that this PR fixes the mostly broken post-merge fast sync behavior

Comment on lines -72 to 73
.waitForSuitablePeers(FastSyncState.EMPTY_SYNC_STATE)
CompletableFuture.completedFuture(FastSyncState.EMPTY_SYNC_STATE)
.thenCompose(syncActions::selectPivotBlock)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, but rather than composing a static completed future, couldn't this be reduced to
fastSyncActions.selectPivotBlock(fastSyncState)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this way to avoid that an exception threw from fastSyncActions.selectPivotBlock(fastSyncState) escape the future chain, so I can handle all the exception in the same place, instead of putting an extra try...catch around fastSyncActions.selectPivotBlock(fastSyncState), do you have another idea on how to improve this?

Comment on lines -97 to +96
.waitForSuitablePeers(fastSyncState)
CompletableFuture.completedFuture(fastSyncState)
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment about unnecessary compose

.whenComplete(
(blockHeader, throwable) -> {
if (throwable != null) {
LOG.debug("Error downloading block header by hash {}", hash);
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be useful to log the throwable too

ethContext,
metricsSystem,
currentState.getPivotBlockNumber().getAsLong(),
syncConfig.getFastSyncMinimumPeerCount(),
Copy link
Contributor

Choose a reason for hiding this comment

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

this is going to default to 5 since we no longer override this value to 1 for PoS networks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on PoS this is never called, since we always have the pivot block hash

@garyschulte garyschulte enabled auto-merge (squash) October 6, 2022 20:38
@garyschulte garyschulte merged commit 839f39d into hyperledger:main Oct 6, 2022
@rolandtyler rolandtyler removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Oct 11, 2022
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* Refactor to optimize pivot block selector on PoS networks

On PoS network we use a pivot block sent by the Consensus Layer, so we do
not need peers, and so all the logic for selecting the pivot block from peers
has been moved from FastSyncActions to PivotSelectorFromPeers.
We do not need anymore the TransictionPeerSelector, and the --fast-sync-min-peers
applies only to PoW networks.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants