21 #include <validation.h> 41 explicit DB(
size_t n_cache_size,
bool f_memory =
false,
bool f_wipe =
false);
48 void WriteTxs(
const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos);
52 BaseIndex::
DB(
gArgs.GetDataDirNet() /
"indexes" /
"txindex", n_cache_size, f_memory, f_wipe)
63 for (
const auto& [txid, pos] : v_pos) {
69 TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain,
size_t n_cache_size,
bool f_memory,
bool f_wipe)
78 if (block.
height == 0)
return true;
82 std::vector<std::pair<Txid, CDiskTxPos>> vPos;
83 vPos.reserve(block.
data->
vtx.size());
84 for (
const auto& tx : block.
data->
vtx) {
85 vPos.emplace_back(tx->GetHash(), pos);
97 if (!
m_db->ReadTxPos(tx_hash, postx)) {
111 }
catch (
const std::exception& e) {
112 LogError(
"Deserialize or I/O error - %s", e.what());
115 if (tx->GetHash() != tx_hash) {
std::shared_ptr< const CTransaction > CTransactionRef
constexpr uint8_t DB_TXINDEX
Batch of changes queued to be written to a CDBWrapper.
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances...
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) const
Check whether the block associated with this index entry is pruned or not.
const std::unique_ptr< DB > m_db
Non-refcounted RAII wrapper for FILE*.
Access to the txindex database (indexes/txindex/)
The database stores a block locator of the chain the database is synced to so that the index can effi...
Block data sent with blockConnected, blockDisconnected notifications.
Base class for indices of blockchain data.
bool ReadTxPos(const Txid &txid, CDiskTxPos &pos) const
Read the disk location of the transaction data with the given hash.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
uint64_t GetSerializeSize(const T &t)
void Write(const K &key, const V &value)
BaseIndex::DB & GetDB() const override
virtual ~TxIndex() override
std::vector< CTransactionRef > vtx
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
bool FindTx(const Txid &tx_hash, uint256 &block_hash, CTransactionRef &tx) const
Look up a transaction by hash.
Chainstate * m_chainstate
DB(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
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.
void WriteTxs(const std::vector< std::pair< Txid, CDiskTxPos >> &v_pos)
Write a batch of transaction positions to the DB.
const uint256 & ToUint256() const LIFETIMEBOUND
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 ...
TxIndex is used to look up transactions included in the blockchain by hash.
static constexpr TransactionSerParams TX_WITH_WITNESS