Browse Source

Force a bootstrap if the block archive isn't intact on launch

This allows the topOnly setting to be disabled and the node will automatically bootstrap to the archive version. A rebuild isn't attempted if bootstrapping is disabled, in order to reduce risk.
bootstrap
CalDescent 3 years ago
parent
commit
dc876d9c96
  1. 15
      src/main/java/org/qortal/block/BlockChain.java

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

@ -502,13 +502,22 @@ public class BlockChain {
*/
public static void validate() throws DataException {
boolean isTopOnly = Settings.getInstance().isTopOnly();
boolean archiveEnabled = Settings.getInstance().isArchiveEnabled();
boolean canBootstrap = Settings.getInstance().getBootstrap();
boolean needsArchiveRebuild = false;
BlockData chainTip;
try (final Repository repository = RepositoryManager.getRepository()) {
chainTip = repository.getBlockRepository().getLastBlock();
// Ensure archive is (at least partially) intact, and force a bootstrap if it isn't
if (!isTopOnly && archiveEnabled && canBootstrap) {
needsArchiveRebuild = (repository.getBlockArchiveRepository().fromHeight(2) == null);
LOGGER.info("Couldn't retrieve block 2 from archive. Bootstrapping...");
}
}
boolean isTopOnly = Settings.getInstance().isTopOnly();
boolean archiveEnabled = Settings.getInstance().isArchiveEnabled();
boolean hasBlocks = (chainTip != null && chainTip.getHeight() > 1);
if (isTopOnly && hasBlocks) {
@ -516,7 +525,7 @@ public class BlockChain {
// It's best not to validate it, and there's no real need to
} else {
// Check first block is Genesis Block
if (!isGenesisBlockValid()) {
if (!isGenesisBlockValid() || needsArchiveRebuild) {
try {
rebuildBlockchain();

Loading…
Cancel
Save