Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 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. | ||||
#ifndef BITCOIN_TXMEMPOOL_H | #ifndef BITCOIN_TXMEMPOOL_H | ||||
#define BITCOIN_TXMEMPOOL_H | #define BITCOIN_TXMEMPOOL_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <core_memusage.h> | #include <core_memusage.h> | ||||
#include <indirectmap.h> | #include <indirectmap.h> | ||||
#include <policy/packages.h> | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <util/epochguard.h> | #include <util/epochguard.h> | ||||
#include <util/hasher.h> | #include <util/hasher.h> | ||||
#include <boost/multi_index/hashed_index.hpp> | #include <boost/multi_index/hashed_index.hpp> | ||||
#include <boost/multi_index/ordered_index.hpp> | #include <boost/multi_index/ordered_index.hpp> | ||||
#include <boost/multi_index/sequenced_index.hpp> | #include <boost/multi_index/sequenced_index.hpp> | ||||
▲ Show 20 Lines • Show All 572 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* Track locally submitted transactions to periodically retry initial | * Track locally submitted transactions to periodically retry initial | ||||
* broadcast | * broadcast | ||||
*/ | */ | ||||
std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs); | std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs); | ||||
/** | /** | ||||
* Helper function to populate setAncestors with all the ancestors of entry | * Helper function to calculate all in-mempool ancestors of staged_ancestors | ||||
* and apply ancestor and descendant limits. | * and apply ancestor and descendant limits (including staged_ancestors | ||||
* themselves, entry_size and entry_count). | |||||
* param@[in] entry_size Virtual size to include in the limits. | |||||
* param@[in] entry_count How many entries to include in the | |||||
* limits. | |||||
* param@[in] staged_ancestors Should contain entries in the mempool. | |||||
* param@[out] setAncestors Will be populated with all mempool | * param@[out] setAncestors Will be populated with all mempool | ||||
* ancestors of entry. | * ancestors. | ||||
* param@[in] staged_ancestors Should contain mempool parents of entry. | |||||
*/ | */ | ||||
bool CalculateAncestorsAndCheckLimits( | bool CalculateAncestorsAndCheckLimits( | ||||
const CTxMemPoolEntry &entry, setEntries &setAncestors, | size_t entry_size, size_t entry_count, setEntries &setAncestors, | ||||
CTxMemPoolEntry::Parents &staged_ancestors, uint64_t limitAncestorCount, | CTxMemPoolEntry::Parents &staged_ancestors, uint64_t limitAncestorCount, | ||||
uint64_t limitAncestorSize, uint64_t limitDescendantCount, | uint64_t limitAncestorSize, uint64_t limitDescendantCount, | ||||
uint64_t limitDescendantSize, std::string &errString) const | uint64_t limitDescendantSize, std::string &errString) const | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
public: | public: | ||||
indirectmap<COutPoint, const CTransaction *> mapNextTx GUARDED_BY(cs); | indirectmap<COutPoint, const CTransaction *> mapNextTx GUARDED_BY(cs); | ||||
std::map<TxId, Amount> mapDeltas GUARDED_BY(cs); | std::map<TxId, Amount> mapDeltas GUARDED_BY(cs); | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | public: | ||||
bool CalculateMemPoolAncestors( | bool CalculateMemPoolAncestors( | ||||
const CTxMemPoolEntry &entry, setEntries &setAncestors, | const CTxMemPoolEntry &entry, setEntries &setAncestors, | ||||
uint64_t limitAncestorCount, uint64_t limitAncestorSize, | uint64_t limitAncestorCount, uint64_t limitAncestorSize, | ||||
uint64_t limitDescendantCount, uint64_t limitDescendantSize, | uint64_t limitDescendantCount, uint64_t limitDescendantSize, | ||||
std::string &errString, bool fSearchForParents = true) const | std::string &errString, bool fSearchForParents = true) const | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
/** | /** | ||||
* Calculate all in-mempool ancestors of a set of transactions not already | |||||
* in the mempool and check ancestor and descendant limits. Heuristics are | |||||
* used to estimate the ancestor and descendant count of all entries if the | |||||
* package were to be added to the mempool. The limits are applied to the | |||||
* union of all package transactions. For example, if the package has 3 | |||||
* transactions and limitAncestorCount = 50, the union of all 3 sets of | |||||
* ancestors (including the transactions themselves) must be <= 47. | |||||
* @param[in] package Transaction package being | |||||
* evaluated for acceptance to mempool. The transactions need not be | |||||
* direct ancestors/descendants of each other. | |||||
* @param[in] limitAncestorCount Max number of txns including | |||||
* ancestors. | |||||
* @param[in] limitAncestorSize Max size including ancestors. | |||||
* @param[in] limitDescendantCount Max number of txns including | |||||
* descendants. | |||||
* @param[in] limitDescendantSize Max size including descendants. | |||||
* @param[out] errString Populated with error reason if | |||||
* a limit is hit. | |||||
*/ | |||||
bool CheckPackageLimits(const Package &package, uint64_t limitAncestorCount, | |||||
uint64_t limitAncestorSize, | |||||
uint64_t limitDescendantCount, | |||||
uint64_t limitDescendantSize, | |||||
std::string &errString) const | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | |||||
/** | |||||
* Populate setDescendants with all in-mempool descendants of hash. | * Populate setDescendants with all in-mempool descendants of hash. | ||||
* Assumes that setDescendants includes all in-mempool descendants of | * Assumes that setDescendants includes all in-mempool descendants of | ||||
* anything already in it. | * anything already in it. | ||||
*/ | */ | ||||
void CalculateDescendants(txiter it, setEntries &setDescendants) const | void CalculateDescendants(txiter it, setEntries &setDescendants) const | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs); | EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 341 Lines • Show Last 20 Lines |