Skip to content

Commit

Permalink
[MOVE-ONLY] Init: move -resync interaction out of init-wallet (step 5)
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 7, 2021
1 parent 1270ef8 commit 4dfc8e0
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,53 +1299,50 @@ bool AppInitMain()
return UIError(_("Unable to start HTTP server. See debug log for details."));
}

// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
#ifdef ENABLE_WALLET
if (!InitAutoBackupWallet()) {
return false;
}

// not fixing indentation as this block of code will be moved away from here in the following commits

if (gArgs.GetBoolArg("-resync", false)) {
uiInterface.InitMessage(_("Preparing for resync..."));
// Delete the local blockchain folders to force a resync from scratch to get a consitent blockchain-state
fs::path blocksDir = GetBlocksDir();
fs::path chainstateDir = GetDataDir() / "chainstate";
fs::path sporksDir = GetDataDir() / "sporks";
fs::path zerocoinDir = GetDataDir() / "zerocoin";

LogPrintf("Deleting blockchain folders blocks, chainstate, sporks and zerocoin\n");
// We delete in 4 individual steps in case one of the folder is missing already
try {
if (fs::exists(blocksDir)){
fs::remove_all(blocksDir);
LogPrintf("-resync: folder deleted: %s\n", blocksDir.string().c_str());
}
if (gArgs.GetBoolArg("-resync", false)) {
uiInterface.InitMessage(_("Preparing for resync..."));
// Delete the local blockchain folders to force a resync from scratch to get a consitent blockchain-state
fs::path blocksDir = GetBlocksDir();
fs::path chainstateDir = GetDataDir() / "chainstate";
fs::path sporksDir = GetDataDir() / "sporks";
fs::path zerocoinDir = GetDataDir() / "zerocoin";

LogPrintf("Deleting blockchain folders blocks, chainstate, sporks and zerocoin\n");
// We delete in 4 individual steps in case one of the folder is missing already
try {
if (fs::exists(blocksDir)){
fs::remove_all(blocksDir);
LogPrintf("-resync: folder deleted: %s\n", blocksDir.string().c_str());
}

if (fs::exists(chainstateDir)){
fs::remove_all(chainstateDir);
LogPrintf("-resync: folder deleted: %s\n", chainstateDir.string().c_str());
}
if (fs::exists(chainstateDir)){
fs::remove_all(chainstateDir);
LogPrintf("-resync: folder deleted: %s\n", chainstateDir.string().c_str());
}

if (fs::exists(sporksDir)){
fs::remove_all(sporksDir);
LogPrintf("-resync: folder deleted: %s\n", sporksDir.string().c_str());
}
if (fs::exists(sporksDir)){
fs::remove_all(sporksDir);
LogPrintf("-resync: folder deleted: %s\n", sporksDir.string().c_str());
}

if (fs::exists(zerocoinDir)){
fs::remove_all(zerocoinDir);
LogPrintf("-resync: folder deleted: %s\n", zerocoinDir.string().c_str());
}
} catch (const fs::filesystem_error& error) {
LogPrintf("Failed to delete blockchain folders %s\n", error.what());
if (fs::exists(zerocoinDir)){
fs::remove_all(zerocoinDir);
LogPrintf("-resync: folder deleted: %s\n", zerocoinDir.string().c_str());
}
} catch (const fs::filesystem_error& error) {
LogPrintf("Failed to delete blockchain folders %s\n", error.what());
}
}

if (!CWallet::Verify())
return false;

#endif // ENABLE_WALLET
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
#ifdef ENABLE_WALLET
if (!InitAutoBackupWallet()) {
return false;
}
if (!CWallet::Verify()) {
return false;
}
#endif

// ********************************************************* Step 6: network initialization
// Note that we absolutely cannot open any actual connections
Expand Down

0 comments on commit 4dfc8e0

Please sign in to comment.