Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
DisconnectedBlockTransactions Class Reference

DisconnectedBlockTransactions. More...

#include <disconnected_transactions.h>

Public Member Functions

 DisconnectedBlockTransactions (size_t max_mem_usage)
 
 ~DisconnectedBlockTransactions ()
 
size_t DynamicMemoryUsage () const
 
std::vector< CTransactionRefAddTransactionsFromBlock (const std::vector< CTransactionRef > &vtx)
 Add transactions from the block, iterating through vtx in reverse order. More...
 
void removeForBlock (const std::vector< CTransactionRef > &vtx)
 Remove any entries that are in this block. More...
 
size_t size () const
 
void clear ()
 
std::list< CTransactionReftake ()
 Clear all data structures and return the list of transactions. More...
 

Private Types

using TxList = decltype(queuedTx)
 

Private Member Functions

std::vector< CTransactionRefLimitMemoryUsage ()
 Trim the earliest-added entries until we are within memory bounds. More...
 

Private Attributes

uint64_t cachedInnerUsage = 0
 Cached dynamic memory usage for the CTransactionRefs. More...
 
const size_t m_max_mem_usage
 
std::list< CTransactionRefqueuedTx
 
std::unordered_map< uint256, TxList::iterator, SaltedTxidHasheriters_by_txid
 

Detailed Description

DisconnectedBlockTransactions.

During the reorg, it's desirable to re-add previously confirmed transactions to the mempool, so that anything not re-confirmed in the new chain is available to be mined. However, it's more efficient to wait until the reorg is complete and process all still-unconfirmed transactions at that time, since we expect most confirmed transactions to (typically) still be confirmed in the new chain, and re-accepting to the memory pool is expensive (and therefore better to not do in the middle of reorg-processing). Instead, store the disconnected transactions (in order!) as we go, remove any that are included in blocks in the new chain, and then process the remaining still-unconfirmed transactions at the end.

Order of queuedTx: The front of the list should be the most recently-confirmed transactions (transactions at the end of vtx of blocks closer to the tip). If memory usage grows too large, we trim from the front of the list. After trimming, transactions can be re-added to the mempool from the back of the list to the front without running into missing inputs.

Definition at line 37 of file disconnected_transactions.h.

Member Typedef Documentation

◆ TxList

Definition at line 43 of file disconnected_transactions.h.

Constructor & Destructor Documentation

◆ DisconnectedBlockTransactions()

DisconnectedBlockTransactions::DisconnectedBlockTransactions ( size_t  max_mem_usage)
inline

Definition at line 50 of file disconnected_transactions.h.

◆ ~DisconnectedBlockTransactions()

DisconnectedBlockTransactions::~DisconnectedBlockTransactions ( )

Definition at line 24 of file disconnected_transactions.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ AddTransactionsFromBlock()

std::vector< CTransactionRef > DisconnectedBlockTransactions::AddTransactionsFromBlock ( const std::vector< CTransactionRef > &  vtx)

Add transactions from the block, iterating through vtx in reverse order.

Callers should call this function for blocks in descending order by block height. We assume that callers never pass multiple transactions with the same txid, otherwise things can go very wrong in removeForBlock due to queuedTx containing an item without a corresponding entry in iters_by_txid.

Returns
vector of transactions that were evicted for size-limiting.

Definition at line 49 of file disconnected_transactions.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void DisconnectedBlockTransactions::clear ( )

Definition at line 78 of file disconnected_transactions.cpp.

Here is the caller graph for this function:

◆ DynamicMemoryUsage()

size_t DisconnectedBlockTransactions::DynamicMemoryUsage ( ) const

Definition at line 44 of file disconnected_transactions.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LimitMemoryUsage()

std::vector< CTransactionRef > DisconnectedBlockTransactions::LimitMemoryUsage ( )
private

Trim the earliest-added entries until we are within memory bounds.

Definition at line 31 of file disconnected_transactions.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeForBlock()

void DisconnectedBlockTransactions::removeForBlock ( const std::vector< CTransactionRef > &  vtx)

Remove any entries that are in this block.

Definition at line 61 of file disconnected_transactions.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t DisconnectedBlockTransactions::size ( ) const
inline

Definition at line 69 of file disconnected_transactions.h.

◆ take()

std::list< CTransactionRef > DisconnectedBlockTransactions::take ( )

Clear all data structures and return the list of transactions.

Definition at line 85 of file disconnected_transactions.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cachedInnerUsage

uint64_t DisconnectedBlockTransactions::cachedInnerUsage = 0
private

Cached dynamic memory usage for the CTransactionRefs.

Definition at line 40 of file disconnected_transactions.h.

◆ iters_by_txid

std::unordered_map<uint256, TxList::iterator, SaltedTxidHasher> DisconnectedBlockTransactions::iters_by_txid
private

Definition at line 44 of file disconnected_transactions.h.

◆ m_max_mem_usage

const size_t DisconnectedBlockTransactions::m_max_mem_usage
private

Definition at line 41 of file disconnected_transactions.h.

◆ queuedTx

std::list<CTransactionRef> DisconnectedBlockTransactions::queuedTx
private

Definition at line 42 of file disconnected_transactions.h.


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