feat: FastSync now stops on failure instead of falling back to FullSync (#974)

* feat: FastSync now stops on failure instead of falling back to FullSync

* feat: exiting on FastSync failed

* feat: FastSync continues on FullSync when no errors happened

Signed-off-by: Alexandre PARIS-VERGNE <alexpv14@gmail.com>
pull/1049/head
br0tchain 5 years ago committed by GitHub
parent c570c05a02
commit 3c2ef2b1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java
  2. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncException.java
  3. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetriever.java

@ -126,7 +126,17 @@ public class DefaultSynchronizer<C> implements Synchronizer {
LOG.info("Starting synchronizer.");
blockPropagationManager.start();
if (fastSyncDownloader.isPresent()) {
fastSyncDownloader.get().start().whenComplete(this::handleFastSyncResult);
fastSyncDownloader
.get()
.start()
.whenComplete(this::handleFastSyncResult)
.exceptionally(
ex -> {
LOG.warn("Exiting FastSync process");
System.exit(0);
return null;
});
} else {
startFullSync();
}
@ -157,20 +167,20 @@ public class DefaultSynchronizer<C> implements Synchronizer {
// We've been shutdown which will have triggered the fast sync future to complete
return;
}
fastSyncDownloader.ifPresent(FastSyncDownloader::deleteFastSyncState);
final Throwable rootCause = ExceptionUtils.rootCause(error);
if (rootCause instanceof FastSyncException) {
LOG.error(
"Fast sync failed ({}), switching to full sync.",
((FastSyncException) rootCause).getError());
"Fast sync failed ({}), please try again.", ((FastSyncException) rootCause).getError());
throw new FastSyncException(rootCause);
} else if (error != null) {
LOG.error("Fast sync failed, switching to full sync.", error);
LOG.error("Fast sync failed, please try again.", error);
throw new FastSyncException(error);
} else {
LOG.info(
"Fast sync completed successfully with pivot block {}",
result.getPivotBlockNumber().getAsLong());
}
fastSyncDownloader.ifPresent(FastSyncDownloader::deleteFastSyncState);
startFullSync();
}

@ -26,4 +26,9 @@ public class FastSyncException extends RuntimeException {
public FastSyncError getError() {
return error;
}
public FastSyncException(final Throwable error) {
super(error);
this.error = FastSyncError.UNEXPECTED_ERROR;
}
}

@ -42,7 +42,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 = 50;
private static final int DEFAULT_MAX_PIVOT_BLOCK_RESETS = 250;
private static final int SUSPICIOUS_NUMBER_OF_RETRIES = 5;
private final EthContext ethContext;

Loading…
Cancel
Save