Changeset View
Changeset View
Standalone View
Standalone View
src/index/base.cpp
// Copyright (c) 2017-2018 The Bitcoin Core developers | // Copyright (c) 2017-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <chain.h> | |||||
#include <config.h> | #include <config.h> | ||||
#include <index/base.h> | #include <index/base.h> | ||||
#include <init.h> | #include <init.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
constexpr char DB_BEST_BLOCK = 'B'; | |||||
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds | constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds | ||||
constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds | constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds | ||||
template <typename... Args> | template <typename... Args> | ||||
static void FatalError(const char *fmt, const Args &... args) { | static void FatalError(const char *fmt, const Args &... args) { | ||||
std::string strMessage = tfm::format(fmt, args...); | std::string strMessage = tfm::format(fmt, args...); | ||||
SetMiscWarning(strMessage); | SetMiscWarning(strMessage); | ||||
LogPrintf("*** %s\n", strMessage); | LogPrintf("*** %s\n", strMessage); | ||||
uiInterface.ThreadSafeMessageBox( | uiInterface.ThreadSafeMessageBox( | ||||
"Error: A fatal internal error occurred, see debug.log for details", "", | "Error: A fatal internal error occurred, see debug.log for details", "", | ||||
CClientUIInterface::MSG_ERROR); | CClientUIInterface::MSG_ERROR); | ||||
StartShutdown(); | StartShutdown(); | ||||
} | } | ||||
BaseIndex::DB::DB(const fs::path &path, size_t n_cache_size, bool f_memory, | |||||
bool f_wipe, bool f_obfuscate) | |||||
: CDBWrapper(path, n_cache_size, f_memory, f_wipe, f_obfuscate) {} | |||||
bool BaseIndex::DB::ReadBestBlock(CBlockLocator &locator) const { | |||||
bool success = Read(DB_BEST_BLOCK, locator); | |||||
if (!success) { | |||||
locator.SetNull(); | |||||
} | |||||
return success; | |||||
} | |||||
bool BaseIndex::DB::WriteBestBlock(const CBlockLocator &locator) { | |||||
return Write(DB_BEST_BLOCK, locator); | |||||
} | |||||
BaseIndex::~BaseIndex() { | BaseIndex::~BaseIndex() { | ||||
Interrupt(); | Interrupt(); | ||||
Stop(); | Stop(); | ||||
} | } | ||||
bool BaseIndex::Init() { | bool BaseIndex::Init() { | ||||
CBlockLocator locator; | CBlockLocator locator; | ||||
if (!GetDB().ReadBestBlock(locator)) { | if (!GetDB().ReadBestBlock(locator)) { | ||||
▲ Show 20 Lines • Show All 220 Lines • Show Last 20 Lines |