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 <crypto/siphash.h> | |||||
#include <indirectmap.h> | #include <indirectmap.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <salteduint256hasher.h> | ||||
#include <sync.h> | #include <sync.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> | ||||
#include <boost/multi_index_container.hpp> | #include <boost/multi_index_container.hpp> | ||||
#include <boost/signals2/signal.hpp> | #include <boost/signals2/signal.hpp> | ||||
▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | enum class MemPoolRemovalReason { | ||||
//! Removed for block | //! Removed for block | ||||
BLOCK, | BLOCK, | ||||
//! Removed for conflict with in-block transaction | //! Removed for conflict with in-block transaction | ||||
CONFLICT, | CONFLICT, | ||||
//! Removed for replacement | //! Removed for replacement | ||||
REPLACED | REPLACED | ||||
}; | }; | ||||
class SaltedTxidHasher { | class SaltedTxIdHasher : private SaltedUint256Hasher { | ||||
private: | |||||
/** Salt */ | |||||
const uint64_t k0, k1; | |||||
public: | public: | ||||
SaltedTxidHasher(); | SaltedTxIdHasher() : SaltedUint256Hasher() {} | ||||
size_t operator()(const TxId &txid) const { | size_t operator()(const TxId &txid) const { return hash(txid); } | ||||
return SipHashUint256(k0, k1, txid); | |||||
} | |||||
}; | }; | ||||
/** | /** | ||||
* CTxMemPool stores valid-according-to-the-current-best-chain transactions that | * CTxMemPool stores valid-according-to-the-current-best-chain transactions that | ||||
* may be included in the next block. | * may be included in the next block. | ||||
* | * | ||||
* Transactions are added when they are seen on the network (or created by the | * Transactions are added when they are seen on the network (or created by the | ||||
* local node), but not all transactions seen are added to the pool. For | * local node), but not all transactions seen are added to the pool. For | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
// public only for testing | // public only for testing | ||||
static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; | static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; | ||||
typedef boost::multi_index_container< | typedef boost::multi_index_container< | ||||
CTxMemPoolEntry, boost::multi_index::indexed_by< | CTxMemPoolEntry, boost::multi_index::indexed_by< | ||||
// sorted by txid | // sorted by txid | ||||
boost::multi_index::hashed_unique< | boost::multi_index::hashed_unique< | ||||
mempoolentry_txid, SaltedTxidHasher>, | mempoolentry_txid, SaltedTxIdHasher>, | ||||
// sorted by fee rate | // sorted by fee rate | ||||
boost::multi_index::ordered_non_unique< | boost::multi_index::ordered_non_unique< | ||||
boost::multi_index::tag<descendant_score>, | boost::multi_index::tag<descendant_score>, | ||||
boost::multi_index::identity<CTxMemPoolEntry>, | boost::multi_index::identity<CTxMemPoolEntry>, | ||||
CompareTxMemPoolEntryByDescendantScore>, | CompareTxMemPoolEntryByDescendantScore>, | ||||
// sorted by entry time | // sorted by entry time | ||||
boost::multi_index::ordered_non_unique< | boost::multi_index::ordered_non_unique< | ||||
boost::multi_index::tag<entry_time>, | boost::multi_index::tag<entry_time>, | ||||
▲ Show 20 Lines • Show All 370 Lines • ▼ Show 20 Lines | |||||
class DisconnectedBlockTransactions { | class DisconnectedBlockTransactions { | ||||
private: | private: | ||||
typedef boost::multi_index_container< | typedef boost::multi_index_container< | ||||
CTransactionRef, boost::multi_index::indexed_by< | CTransactionRef, boost::multi_index::indexed_by< | ||||
// sorted by txid | // sorted by txid | ||||
boost::multi_index::hashed_unique< | boost::multi_index::hashed_unique< | ||||
boost::multi_index::tag<txid_index>, | boost::multi_index::tag<txid_index>, | ||||
mempoolentry_txid, SaltedTxidHasher>, | mempoolentry_txid, SaltedTxIdHasher>, | ||||
// sorted by order in the blockchain | // sorted by order in the blockchain | ||||
boost::multi_index::sequenced< | boost::multi_index::sequenced< | ||||
boost::multi_index::tag<insertion_order>>>> | boost::multi_index::tag<insertion_order>>>> | ||||
indexed_disconnected_transactions; | indexed_disconnected_transactions; | ||||
indexed_disconnected_transactions queuedTx; | indexed_disconnected_transactions queuedTx; | ||||
uint64_t cachedInnerUsage = 0; | uint64_t cachedInnerUsage = 0; | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |