12#include <validation.h>
23 explicit DB(
size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
30 [[nodiscard]]
bool WriteTxs(
const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
34 BaseIndex::
DB(
gArgs.GetDataDirNet() /
"indexes" /
"txindex", n_cache_size, f_memory, f_wipe)
39 return Read(std::make_pair(
DB_TXINDEX, txid), pos);
45 for (
const auto& tuple : v_pos) {
48 return WriteBatch(batch);
51TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain,
size_t n_cache_size,
bool f_memory,
bool f_wipe)
60 if (block.
height == 0)
return true;
64 std::vector<std::pair<uint256, CDiskTxPos>> vPos;
65 vPos.reserve(block.
data->
vtx.size());
66 for (
const auto& tx : block.
data->
vtx) {
67 vPos.emplace_back(tx->GetHash(), pos);
70 return m_db->WriteTxs(vPos);
78 if (!
m_db->ReadTxPos(tx_hash, postx)) {
84 LogError(
"%s: OpenBlockFile failed\n", __func__);
92 }
catch (
const std::exception& e) {
93 LogError(
"%s: Deserialize or I/O error - %s\n", __func__, e.what());
96 if (tx->GetHash() != tx_hash) {
97 LogError(
"%s: txid mismatch\n", __func__);
Non-refcounted RAII wrapper for FILE*.
The database stores a block locator of the chain the database is synced to so that the index can effi...
Base class for indices of blockchain data.
Chainstate * m_chainstate
std::vector< CTransactionRef > vtx
Batch of changes queued to be written to a CDBWrapper.
void Write(const K &key, const V &value)
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Access to the txindex database (indexes/txindex/)
DB(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
bool WriteTxs(const std::vector< std::pair< uint256, CDiskTxPos > > &v_pos)
Write a batch of transaction positions to the DB.
bool ReadTxPos(const uint256 &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given hash.
TxIndex is used to look up transactions included in the blockchain by hash.
bool FindTx(const uint256 &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
BaseIndex::DB & GetDB() const override
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
TxIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Constructs the index, which becomes available to be queried.
virtual ~TxIndex() override
const std::unique_ptr< DB > m_db
bool IsBlockPruned(const CBlockIndex &block) const EXCLUSIVE_LOCKS_REQUIRED(void UpdatePruneLock(const std::string &name, const PruneLockInfo &lock_info) EXCLUSIVE_LOCKS_REQUIRED(AutoFile OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false) const
Check whether the block associated with this index entry is pruned or not.
static constexpr TransactionSerParams TX_WITH_WITNESS
std::shared_ptr< const CTransaction > CTransactionRef
size_t GetSerializeSize(const T &t)
constexpr unsigned int GetSizeOfCompactSize(uint64_t nSize)
Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 byt...
Block data sent with blockConnected, blockDisconnected notifications.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
constexpr uint8_t DB_TXINDEX