Changeset View
Changeset View
Standalone View
Standalone View
src/index/txindex.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 <config.h> | #include <config.h> | ||||
#include <index/txindex.h> | #include <index/txindex.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 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 | ||||
std::unique_ptr<TxIndex> g_txindex; | |||||
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); | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | if (!m_synced) { | ||||
} | } | ||||
} | } | ||||
LogPrintf("%s: txindex is catching up on block notifications\n", __func__); | LogPrintf("%s: txindex is catching up on block notifications\n", __func__); | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
return true; | return true; | ||||
} | } | ||||
bool TxIndex::FindTx(const uint256 &txid, CDiskTxPos &pos) const { | bool TxIndex::FindTx(const uint256 &tx_hash, uint256 &block_hash, | ||||
return m_db->ReadTxPos(txid, pos); | CTransactionRef &tx) const { | ||||
CDiskTxPos postx; | |||||
if (!m_db->ReadTxPos(tx_hash, postx)) { | |||||
return false; | |||||
} | |||||
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); | |||||
if (file.IsNull()) { | |||||
return error("%s: OpenBlockFile failed", __func__); | |||||
} | |||||
CBlockHeader header; | |||||
try { | |||||
file >> header; | |||||
fseek(file.Get(), postx.nTxOffset, SEEK_CUR); | |||||
file >> tx; | |||||
} catch (const std::exception &e) { | |||||
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); | |||||
} | |||||
if (tx->GetHash() != tx_hash) { | |||||
return error("%s: txid mismatch", __func__); | |||||
} | |||||
block_hash = header.GetHash(); | |||||
return true; | |||||
} | } | ||||
void TxIndex::Interrupt() { | void TxIndex::Interrupt() { | ||||
m_interrupt(); | m_interrupt(); | ||||
} | } | ||||
void TxIndex::Start() { | void TxIndex::Start() { | ||||
// Need to register this ValidationInterface before running Init(), so that | // Need to register this ValidationInterface before running Init(), so that | ||||
Show All 18 Lines |