Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ private TrailingPeerRequirements calculateTrailingPeerRequirements() {
public void start() {
if (running.compareAndSet(false, true)) {
LOG.info("Starting synchronizer.");
blockPropagationManager.start();
try {
blockPropagationManager.start();
} catch (IllegalStateException e) {
LOG.info("Attempt to start an already started block propagation manager");
}
if (fastSyncDownloader.isPresent()) {
fastSyncDownloader.get().start().whenComplete(this::handleFastSyncResult);
} else {
Expand Down Expand Up @@ -162,16 +166,23 @@ private void handleFastSyncResult(final FastSyncState result, final Throwable er
LOG.error(
"Fast sync failed ({}), switching to full sync.",
((FastSyncException) rootCause).getError());
fastSyncDownloader.ifPresent(FastSyncDownloader::deleteFastSyncState);
startFullSync();
} else if (error != null) {
LOG.error("Fast sync failed, switching to full sync.", error);
LOG.error("Fast sync failed, trying to restart.", error);
restartFastSync();
} else {
LOG.info(
"Fast sync completed successfully with pivot block {}",
result.getPivotBlockNumber().getAsLong());
fastSyncDownloader.ifPresent(FastSyncDownloader::deleteFastSyncState);
startFullSync();
}
fastSyncDownloader.ifPresent(FastSyncDownloader::deleteFastSyncState);
}

startFullSync();
private void restartFastSync() {
stop();
start();
}

private void startFullSync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class PivotBlockRetriever<C> {
private static final Logger LOG = LogManager.getLogger();
public static final int MAX_QUERY_RETRIES_PER_PEER = 3;
private static final int DEFAULT_MAX_PIVOT_BLOCK_RESETS = 5;
private static final int SUSPICIOUS_NUMBER_OF_RETRIES = 5;

private final EthContext ethContext;
private final MetricsSystem metricsSystem;
Expand Down Expand Up @@ -148,6 +149,11 @@ private void handleContestedPivotBlock(final long contestedBlockNumber) {
LOG.info("Received conflicting pivot blocks for {}.", contestedBlockNumber);

final int retryCount = confirmationTasks.size();

if ((retryCount % SUSPICIOUS_NUMBER_OF_RETRIES) == 0) {
LOG.warn("Several attempts have been made without finding a pivot block");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd print a warning periodically (every SUSPICIOUS_NUMBER_OF_PIVOT_BLOCK_RESETS retries?) rather than on every individual retry. Also, confirmationTasks can now grow very large, so we'll probably need to rework how we track tasks so we don't hold onto every confirmation task we created.

Alternatively, I wonder if we could alleviate the problem of prematurely switching to full sync by just increasing DEFAULT_MAX_PIVOT_BLOCK_RESETS and making sure we retry fast sync here: https://github.com/hyperledger/besu/blob/7fe1d4796e52fa1ce6099f402cc05f1165607335/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java#L166 ...

Comment thread
matkt marked this conversation as resolved.
Outdated
}

if (retryCount > maxPivotBlockResets
|| pivotBlockNumber.get() <= BlockHeader.GENESIS_BLOCK_NUMBER) {
LOG.info("Max retries reached, cancel pivot block download.");
Comment thread
matkt marked this conversation as resolved.
Expand Down