Browse Source

Retry the entire bootstrap import process on failure, rather than just the download.

bootstrap
CalDescent 3 years ago
parent
commit
47b1b6daba
  1. 9
      src/main/java/org/qortal/block/BlockChain.java
  2. 45
      src/main/java/org/qortal/repository/Bootstrap.java

9
src/main/java/org/qortal/block/BlockChain.java

@ -517,7 +517,12 @@ public class BlockChain {
} else {
// Check first block is Genesis Block
if (!isGenesisBlockValid()) {
rebuildBlockchain();
try {
rebuildBlockchain();
} catch (InterruptedException e) {
throw new DataException(String.format("Interrupted when trying to rebuild blockchain: %s", e.getMessage()));
}
}
}
@ -600,7 +605,7 @@ public class BlockChain {
}
}
private static void rebuildBlockchain() throws DataException {
private static void rebuildBlockchain() throws DataException, InterruptedException {
boolean shouldBootstrap = Settings.getInstance().getBootstrap();
if (shouldBootstrap) {
// Settings indicate that we should apply a bootstrap rather than rebuilding and syncing from genesis

45
src/main/java/org/qortal/repository/Bootstrap.java

@ -27,7 +27,7 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
public class Bootstrap {
private Repository repository;
private final Repository repository;
private static final Logger LOGGER = LogManager.getLogger(Bootstrap.class);
@ -286,7 +286,22 @@ public class Bootstrap {
}
}
public void startImport() throws DataException {
public void startImport() throws InterruptedException {
while (!Controller.isStopping()) {
try {
LOGGER.info("Starting import of bootstrap...");
this.doImport();
} catch (DataException e) {
LOGGER.info("Bootstrap import failed: {}", e.getMessage());
LOGGER.info("Retrying in 5 minutes");
Thread.sleep(5 * 60 * 1000L);
}
}
}
private void doImport() throws DataException {
Path path = null;
try {
Path tempDir = Files.createTempDirectory("qortal-bootstrap");
@ -313,28 +328,14 @@ public class Bootstrap {
private void downloadToPath(Path path) throws DataException {
String bootstrapUrl = "http://bootstrap.qortal.org/bootstrap.7z";
while (!Controller.isStopping()) {
try {
LOGGER.info("Downloading bootstrap...");
InputStream in = new URL(bootstrapUrl).openStream();
Files.copy(in, path, REPLACE_EXISTING);
break;
} catch (IOException e) {
LOGGER.info("Unable to download bootstrap: {}", e.getMessage());
LOGGER.info("Retrying in 5 minutes");
try {
LOGGER.info("Downloading bootstrap...");
InputStream in = new URL(bootstrapUrl).openStream();
Files.copy(in, path, REPLACE_EXISTING);
try {
repository.discardChanges();
Thread.sleep(5 * 60 * 1000L);
} catch (InterruptedException e2) {
break;
}
}
} catch (IOException e) {
throw new DataException(String.format("Unable to download bootstrap: {}", e.getMessage()));
}
// It's best to throw an exception on all failures, even though we're most likely just stopping
throw new DataException("Unable to download bootstrap");
}
public void importFromPath(Path path) throws InterruptedException, DataException, IOException {

Loading…
Cancel
Save