Skip to content

Commit

Permalink
Merge pull request #331 from fireice-uk/cache-backup
Browse files Browse the repository at this point in the history
Implement cache file backup
  • Loading branch information
AxVultis authored Mar 19, 2024
2 parents 5a3d815 + 4591c72 commit b1af6ff
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/CryptoNoteCore/Blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,19 @@ namespace cn
{
logger(INFO) << "Loading blockchain";
BlockCacheSerializer loader(*this, get_block_hash(m_blocks.back().bl), logger.getLogger());
loader.load(appendPath(config_folder, m_currency.blocksCacheFileName()));
const std::string &blocksCacheFileName = m_currency.blocksCacheFileName();
loader.load(appendPath(config_folder, blocksCacheFileName));

if (!loader.loaded())
{
logger(WARNING, BRIGHT_YELLOW) << " No actual blockchain cache found, rebuilding internal structures";
rebuildCache();
std::string blockCacheBkpFileName = blocksCacheFileName + ".bkp";
loader.load(appendPath(config_folder, blockCacheBkpFileName));

if (!loader.loaded())
{
logger(WARNING, BRIGHT_YELLOW) << " No actual blockchain cache found, rebuilding internal structures";
rebuildCache();
}
}
uint64_t checkBlockHeight = 24732;
uint64_t checkMinimum = 13000000000000;
Expand Down Expand Up @@ -736,7 +743,13 @@ namespace cn

logger(INFO, BRIGHT_WHITE) << "Saving blockchain...";
BlockCacheSerializer ser(*this, getTailId(), logger.getLogger());
if (!ser.save(appendPath(m_config_folder, m_currency.blocksCacheFileName())))

const std::string &blocksCacheFileName = m_currency.blocksCacheFileName();
std::string blockCacheBkpFileName = blocksCacheFileName + ".bkp";

std::rename(blocksCacheFileName.c_str(), blockCacheBkpFileName.c_str()); // fail here can be ignored

if (!ser.save(appendPath(m_config_folder, blocksCacheFileName)))
{
logger(ERROR, BRIGHT_RED) << "Failed to save blockchain cache";
return false;
Expand Down Expand Up @@ -3287,4 +3300,4 @@ namespace cn
return m_checkpoints.is_in_checkpoint_zone(height);
}

} // namespace cn
} // namespace cn

0 comments on commit b1af6ff

Please sign in to comment.