Bitcoin Core  0.20.99
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
CTxMemPool::EpochGuard Class Reference

EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms. More...

#include <txmempool.h>

Collaboration diagram for CTxMemPool::EpochGuard:
[legend]

Public Member Functions

 EpochGuard (const CTxMemPool &in)
 
 ~EpochGuard ()
 

Private Attributes

const CTxMemPoolpool
 

Detailed Description

EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms.

When walking ancestors or descendants, we generally want to avoid visiting the same transactions twice. Some traversal algorithms use std::set (or setEntries) to deduplicate the transaction we visit. However, use of std::set is algorithmically undesirable because it both adds an asymptotic factor of O(log n) to traverals cost and triggers O(n) more dynamic memory allocations. In many algorithms we can replace std::set with an internal mempool counter to track the time (or, "epoch") that we began a traversal, and check + update a per-transaction epoch for each transaction we look at to determine if that transaction has not yet been visited during the current traversal's epoch. Algorithms using std::set can be replaced on a one by one basis. Both techniques are not fundamentally incompatible across the codebase. Generally speaking, however, the remaining use of std::set for mempool traversal should be viewed as a TODO for replacement with an epoch based traversal, rather than a preference for std::set over epochs in that algorithm.

Definition at line 785 of file txmempool.h.

Constructor & Destructor Documentation

◆ EpochGuard()

CTxMemPool::EpochGuard::EpochGuard ( const CTxMemPool in)

Definition at line 1127 of file txmempool.cpp.

◆ ~EpochGuard()

CTxMemPool::EpochGuard::~EpochGuard ( )

Definition at line 1134 of file txmempool.cpp.

Member Data Documentation

◆ pool

const CTxMemPool& CTxMemPool::EpochGuard::pool
private

Definition at line 786 of file txmempool.h.


The documentation for this class was generated from the following files: