mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
bc45a2f87a
* Merge #8068: Compact Blocks48efec8
Fix some minor compact block issues that came up in review (Matt Corallo)ccd06b9
Elaborate bucket size math (Pieter Wuille)0d4cb48
Use vTxHashes to optimize InitData significantly (Matt Corallo)8119026
Provide a flat list of txid/terators to txn in CTxMemPool (Matt Corallo)678ee97
Add BIP 152 to implemented BIPs list (Matt Corallo)56ba516
Add reconstruction debug logging (Matt Corallo)2f34a2e
Get our "best three" peers to announce blocks using cmpctblocks (Matt Corallo)927f8ee
Add ability to fetch CNode by NodeId (Matt Corallo)d25cd3e
Add receiver-side protocol implementation for CMPCTBLOCK stuff (Matt Corallo)9c837d5
Add sender-side protocol implementation for CMPCTBLOCK stuff (Matt Corallo)00c4078
Add protocol messages for short-ids blocks (Matt Corallo)e3b2222
Add some blockencodings tests (Matt Corallo)f4f8f14
Add TestMemPoolEntryHelper::FromTx version for CTransaction (Matt Corallo)85ad31e
Add partial-block block encodings API (Matt Corallo)5249dac
Add COMPACTSIZE wrapper similar to VARINT for serialization (Matt Corallo)cbda71c
Move context-required checks from CheckBlockHeader to Contextual... (Matt Corallo)7c29ec9
If AcceptBlockHeader returns true, pindex will be set. (Matt Corallo)96806c3
Stop trimming when mapTx is empty (Pieter Wuille) * Merge #8408: Prevent fingerprinting, disk-DoS with compact blocks1d06e49
Ignore CMPCTBLOCK messages for pruned blocks (Suhas Daftuar)1de2a46
Ignore GETBLOCKTXN requests for unknown blocks (Suhas Daftuar) * Merge #8418: Add tests for compact blocks45c7ddd
Add p2p test for BIP 152 (compact blocks) (Suhas Daftuar)9a22a6c
Add support for compactblocks to mininode (Suhas Daftuar)a8689fd
Tests: refactor compact size serialization in mininode (Suhas Daftuar)9c8593d
Implement SipHash in Python (Pieter Wuille)56c87e9
Allow changing BIP9 parameters on regtest (Suhas Daftuar) * Merge #8505: Trivial: Fix typos in various files1aacfc2
various typos (leijurv) * Merge #8449: [Trivial] Do not shadow local variable, cleanupa159f25
Remove redundand (and shadowing) declaration (Pavel Janík)cce3024
Do not shadow local variable, cleanup (Pavel Janík) * Merge #8739: [qa] Fix broken sendcmpct test in p2p-compactblocks.py157254a
Fix broken sendcmpct test in p2p-compactblocks.py (Suhas Daftuar) * Merge #8854: [qa] Fix race condition in p2p-compactblocks testb5fd666
[qa] Fix race condition in p2p-compactblocks test (Suhas Daftuar) * Merge #8393: Support for compact blocks together with segwit27acfc1
[qa] Update p2p-compactblocks.py for compactblocks v2 (Suhas Daftuar)422fac6
[qa] Add support for compactblocks v2 to mininode (Suhas Daftuar)f5b9b8f
[qa] Fix bug in mininode witness deserialization (Suhas Daftuar)6aa28ab
Use cmpctblock type 2 for segwit-enabled transfer (Pieter Wuille)be7555f
Fix overly-prescriptive p2p-segwit test for new fetch logic (Matt Corallo)06128da
Make GetFetchFlags always request witness objects from witness peers (Matt Corallo) * Merge #8882: [qa] Fix race conditions in p2p-compactblocks.py and sendheaders.pyb55d941
[qa] Fix race condition in sendheaders.py (Suhas Daftuar)6976db2
[qa] Another attempt to fix race condition in p2p-compactblocks.py (Suhas Daftuar) * Merge #8904: [qa] Fix compact block shortids for a test case4cdece4
[qa] Fix compact block shortids for a test case (Dagur Valberg Johannsson) * Merge #8637: Compact Block Tweaks (rebase of #8235)3ac6de0
Align constant names for maximum compact block / blocktxn depth (Pieter Wuille)b2e93a3
Add cmpctblock to debug help list (instagibbs)fe998e9
More agressively filter compact block requests (Matt Corallo)02a337d
Dont remove a "preferred" cmpctblock peer if they provide a block (Matt Corallo) * Merge #8975: Chainparams: Trivial: In AppInit2(), s/Params()/chainparams/6f2f639
Chainparams: Trivial: In AppInit2(), s/Params()/chainparams/ (Jorge Timón) * Merge #8968: Don't hold cs_main when calling ProcessNewBlock from a cmpctblock72ca7d9
Don't hold cs_main when calling ProcessNewBlock from a cmpctblock (Matt Corallo) * Merge #8995: Add missing cs_main lock to ::GETBLOCKTXN processingdfe7906
Add missing cs_main lock to ::GETBLOCKTXN processing (Matt Corallo) * Merge #8515: A few mempool removal optimizations0334430
Add some missing includes (Pieter Wuille)4100499
Return shared_ptr<CTransaction> from mempool removes (Pieter Wuille)51f2783
Make removed and conflicted arguments optional to remove (Pieter Wuille)f48211b
Bypass removeRecursive in removeForReorg (Pieter Wuille) * Merge #9026: Fix handling of invalid compact blocksd4833ff
Bump the protocol version to distinguish new banning behavior. (Suhas Daftuar)88c3549
Fix compact block handling to not ban if block is invalid (Suhas Daftuar)c93beac
[qa] Test that invalid compactblocks don't result in ban (Suhas Daftuar) * Merge #9039: Various serialization simplifcations and optimizationsd59a518
Use fixed preallocation instead of costly GetSerializeSize (Pieter Wuille)25a211a
Add optimized CSizeComputer serializers (Pieter Wuille)a2929a2
Make CSerAction's ForRead() constexpr (Pieter Wuille)a603925
Avoid -Wshadow errors (Pieter Wuille)5284721
Get rid of nType and nVersion (Pieter Wuille)657e05a
Make GetSerializeSize a wrapper on top of CSizeComputer (Pieter Wuille)fad9b66
Make nType and nVersion private and sometimes const (Pieter Wuille)c2c5d42
Make streams' read and write return void (Pieter Wuille)50e8a9c
Remove unused ReadVersion and WriteVersion (Pieter Wuille) * Merge #9058: Fixes for p2p-compactblocks.py test timeouts on travis (#8842)dac53b5
Modify getblocktxn handler not to drop requests for old blocks (Russell Yanofsky)55bfddc
[qa] Fix stale data bug in test_compactblocks_not_at_tip (Russell Yanofsky)47e9659
[qa] Fix bug in compactblocks v2 merge (Russell Yanofsky) * Merge #9160: [trivial] Fix hungarian variable nameec34648
[trivial] Fix hungarian variable name (Russell Yanofsky) * Merge #9159: [qa] Wait for specific block announcement in p2p-compactblocksdfa44d1
[qa] Wait for specific block announcement in p2p-compactblocks (Russell Yanofsky) * Merge #9125: Make CBlock a vector of shared_ptr of CTransactionsb4e4ba4
Introduce convenience type CTransactionRef (Pieter Wuille)1662b43
Make CBlock::vtx a vector of shared_ptr<CTransaction> (Pieter Wuille)da60506
Add deserializing constructors to CTransaction and CMutableTransaction (Pieter Wuille)0e85204
Add serialization for unique_ptr and shared_ptr (Pieter Wuille) * Merge #8872: Remove block-request logic from INV message processing037159c
Remove block-request logic from INV message processing (Matt Corallo)3451203
[qa] Respond to getheaders and do not assume a getdata on inv (Matt Corallo)d768f15
[qa] Make comptool push blocks instead of relying on inv-fetch (mrbandrews) * Merge #9199: Always drop the least preferred HB peer when adding a new one.ca8549d
Always drop the least preferred HB peer when adding a new one. (Gregory Maxwell) * Merge #9233: Fix some typos15fa95d
Fix some typos (fsb4000) * Merge #9260: Mrs Peacock in The Library with The Candlestick (killed main.{h,cpp})76faa3c
Rename the remaining main.{h,cpp} to validation.{h,cpp} (Matt Corallo)e736772
Move network-msg-processing code out of main to its own file (Matt Corallo)87c35f5
Remove orphan state wipe from UnloadBlockIndex. (Matt Corallo) * Merge #9014: Fix block-connection performance regressiondd0df81
Document ConnectBlock connectTrace postconditions (Matt Corallo)2d6e561
Switch pblock in ProcessNewBlock to a shared_ptr (Matt Corallo)2736c44
Make the optional pblock in ActivateBestChain a shared_ptr (Matt Corallo)ae4db44
Create a shared_ptr for the block we're connecting in ActivateBCS (Matt Corallo)fd9d890
Keep blocks as shared_ptrs, instead of copying txn in ConnectTip (Matt Corallo)6fdd43b
Add struct to track block-connect-time-generated info for callbacks (Matt Corallo) * Merge #9240: Remove txConflicteda874ab5
remove internal tracking of mempool conflicts for reporting to wallet (Alex Morcos)bf663f8
remove external usage of mempool conflict tracking (Alex Morcos) * Merge #9344: Do not run functions with necessary side-effects in assert()da9cdd2
Do not run functions with necessary side-effects in assert() (Gregory Maxwell) * Merge #9273: Remove unused CDiskBlockPos* argument from ProcessNewBlocka13fa4c
Remove unused CDiskBlockPos* argument from ProcessNewBlock (Matt Corallo) * Merge #9352: Attempt reconstruction from all compact block announcements813ede9
[qa] Update compactblocks test for multi-peer reconstruction (Suhas Daftuar)7017298
Allow compactblock reconstruction when block is in flight (Suhas Daftuar) * Merge #9252: Release cs_main before calling ProcessNewBlock, or processing headers (cmpctblock handling)bd02bdd
Release cs_main before processing cmpctblock as header (Suhas Daftuar)680b0c0
Release cs_main before calling ProcessNewBlock (cmpctblock handling) (Suhas Daftuar) * Merge #9283: A few more CTransactionRef optimizations91335ba
Remove unused MakeTransactionRef overloads (Pieter Wuille)6713f0f
Make FillBlock consume txn_available to avoid shared_ptr copies (Pieter Wuille)62607d7
Convert COrphanTx to keep a CTransactionRef (Pieter Wuille)c44e4c4
Make AcceptToMemoryPool take CTransactionRef (Pieter Wuille) * Merge #9375: Relay compact block messages prior to full block connection02ee4eb
Make most_recent_compact_block a pointer to a const (Matt Corallo)73666ad
Add comment to describe callers to ActivateBestChain (Matt Corallo)962f7f0
Call ActivateBestChain without cs_main/with most_recent_block (Matt Corallo)0df777d
Use a temp pindex to avoid a const_cast in ProcessNewBlockHeaders (Matt Corallo)c1ae4fc
Avoid holding cs_most_recent_block while calling ReadBlockFromDisk (Matt Corallo)9eb67f5
Ensure we meet the BIP 152 old-relay-types response requirements (Matt Corallo)5749a85
Cache most-recently-connected compact block (Matt Corallo)9eaec08
Cache most-recently-announced block's shared_ptr (Matt Corallo)c802092
Relay compact block messages prior to full block connection (Matt Corallo)6987219
Add a CValidationInterface::NewPoWValidBlock callback (Matt Corallo)180586f
Call AcceptBlock with the block's shared_ptr instead of CBlock& (Matt Corallo)8baaba6
[qa] Avoid race in preciousblock test. (Matt Corallo)9a0b2f4
[qa] Make compact blocks test construction using fetch methods (Matt Corallo)8017547
Make CBlockIndex*es in net_processing const (Matt Corallo) * Merge #9486: Make peer=%d log prints consistente6111b2
Make peer id logging consistent ("peer=%d" instead of "peer %d") (Matt Corallo) * Merge #9400: Set peers as HB peers upon full block validationd4781ac
Set peers as HB peers upon full block validation (Gregory Sanders) * Merge #9499: Use recent-rejects, orphans, and recently-replaced txn for compact-block-reconstructionc594580
Add braces around AddToCompactExtraTransactions (Matt Corallo)1ccfe9b
Clarify comment about mempool/extra conflicts (Matt Corallo)fac4c78
Make PartiallyDownloadedBlock::InitData's second param const (Matt Corallo)b55b416
Add extra_count lower bound to compact reconstruction debug print (Matt Corallo)863edb4
Consider all (<100k memusage) txn for compact-block-extra-txn cache (Matt Corallo)7f8c8ca
Consider all orphan txn for compact-block-extra-txn cache (Matt Corallo)93380c5
Use replaced transactions in compact block reconstruction (Matt Corallo)1531652
Keep shared_ptrs to recently-replaced txn for compact blocks (Matt Corallo)edded80
Make ATMP optionally return the CTransactionRefs it replaced (Matt Corallo)c735540
Move ORPHAN constants from validation.h to net_processing.h (Matt Corallo) * Merge #9587: Do not shadow local variable named `tx`.44f2baa
Do not shadow local variable named `tx`. (Pavel Janík) * Merge #9510: [trivial] Fix typos in commentscc16d99
[trivial] Fix typos in comments (practicalswift) * Merge #9604: [Trivial] add comment about setting peer as HB peer.dd5b011
[Trivial] add comment about setting peer as HB peer. (John Newbery) * Fix using of AcceptToMemoryPool in PrivateSend code * add `override` * fSupportsDesiredCmpctVersion * bring back tx ressurection in DisconnectTip * Fix delayed headers * Remove unused CConnman::FindNode overload * Fix typos and comments * Fix minor code differences * Don't use rejection cache for corrupted transactions Partly based on https://github.com/bitcoin/bitcoin/pull/8525 * Backport missed cs_main locking changes Missed from58a215ce8c
* Backport missed comments and mapBlockSource.emplace call Missed from two commits:88c35491ab
7c98ce584e
* Add CheckPeerHeaders() helper and check in (nCount == 0) too
781 lines
31 KiB
C++
781 lines
31 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_TXMEMPOOL_H
|
|
#define BITCOIN_TXMEMPOOL_H
|
|
|
|
#include <memory>
|
|
#include <set>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include <string>
|
|
|
|
#include "addressindex.h"
|
|
#include "spentindex.h"
|
|
#include "amount.h"
|
|
#include "coins.h"
|
|
#include "indirectmap.h"
|
|
#include "primitives/transaction.h"
|
|
#include "sync.h"
|
|
#include "random.h"
|
|
|
|
#undef foreach
|
|
#include "boost/multi_index_container.hpp"
|
|
#include "boost/multi_index/ordered_index.hpp"
|
|
#include "boost/multi_index/hashed_index.hpp"
|
|
|
|
#include <boost/signals2/signal.hpp>
|
|
|
|
class CAutoFile;
|
|
class CBlockIndex;
|
|
|
|
inline double AllowFreeThreshold()
|
|
{
|
|
return COIN * 144 / 250;
|
|
}
|
|
|
|
inline bool AllowFree(double dPriority)
|
|
{
|
|
// Large (in bytes) low-priority (new, small-coin) transactions
|
|
// need a fee.
|
|
return dPriority > AllowFreeThreshold();
|
|
}
|
|
|
|
|
|
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
|
|
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
|
|
|
struct LockPoints
|
|
{
|
|
// Will be set to the blockchain height and median time past
|
|
// values that would be necessary to satisfy all relative locktime
|
|
// constraints (BIP68) of this tx given our view of block chain history
|
|
int height;
|
|
int64_t time;
|
|
// As long as the current chain descends from the highest height block
|
|
// containing one of the inputs used in the calculation, then the cached
|
|
// values are still valid even after a reorg.
|
|
CBlockIndex* maxInputBlock;
|
|
|
|
LockPoints() : height(0), time(0), maxInputBlock(NULL) { }
|
|
};
|
|
|
|
class CTxMemPool;
|
|
|
|
/** \class CTxMemPoolEntry
|
|
*
|
|
* CTxMemPoolEntry stores data about the corresponding transaction, as well
|
|
* as data about all in-mempool transactions that depend on the transaction
|
|
* ("descendant" transactions).
|
|
*
|
|
* When a new entry is added to the mempool, we update the descendant state
|
|
* (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) for
|
|
* all ancestors of the newly added transaction.
|
|
*
|
|
* If updating the descendant state is skipped, we can mark the entry as
|
|
* "dirty", and set nSizeWithDescendants/nModFeesWithDescendants to equal nTxSize/
|
|
* nFee+feeDelta. (This can potentially happen during a reorg, where we limit the
|
|
* amount of work we're willing to do to avoid consuming too much CPU.)
|
|
*
|
|
*/
|
|
|
|
class CTxMemPoolEntry
|
|
{
|
|
private:
|
|
CTransactionRef tx;
|
|
CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
|
|
size_t nTxSize; //!< ... and avoid recomputing tx size
|
|
size_t nModSize; //!< ... and modified size for priority
|
|
size_t nUsageSize; //!< ... and total memory usage
|
|
int64_t nTime; //!< Local time when entering the mempool
|
|
double entryPriority; //!< Priority when entering the mempool
|
|
unsigned int entryHeight; //!< Chain height when entering the mempool
|
|
CAmount inChainInputValue; //!< Sum of all txin values that are already in blockchain
|
|
bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
|
|
unsigned int sigOpCount; //!< Legacy sig ops plus P2SH sig op count
|
|
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
|
|
LockPoints lockPoints; //!< Track the height and time at which tx was final
|
|
|
|
// Information about descendants of this transaction that are in the
|
|
// mempool; if we remove this transaction we must remove all of these
|
|
// descendants as well. if nCountWithDescendants is 0, treat this entry as
|
|
// dirty, and nSizeWithDescendants and nModFeesWithDescendants will not be
|
|
// correct.
|
|
uint64_t nCountWithDescendants; //!< number of descendant transactions
|
|
uint64_t nSizeWithDescendants; //!< ... and size
|
|
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
|
|
|
|
// Analogous statistics for ancestor transactions
|
|
uint64_t nCountWithAncestors;
|
|
uint64_t nSizeWithAncestors;
|
|
CAmount nModFeesWithAncestors;
|
|
unsigned int nSigOpCountWithAncestors;
|
|
|
|
public:
|
|
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
|
|
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
|
|
CAmount _inChainInputValue, bool spendsCoinbase,
|
|
unsigned int nSigOps, LockPoints lp);
|
|
|
|
CTxMemPoolEntry(const CTxMemPoolEntry& other);
|
|
|
|
const CTransaction& GetTx() const { return *this->tx; }
|
|
CTransactionRef GetSharedTx() const { return this->tx; }
|
|
/**
|
|
* Fast calculation of lower bound of current priority as update
|
|
* from entry priority. Only inputs that were originally in-chain will age.
|
|
*/
|
|
double GetPriority(unsigned int currentHeight) const;
|
|
const CAmount& GetFee() const { return nFee; }
|
|
size_t GetTxSize() const { return nTxSize; }
|
|
int64_t GetTime() const { return nTime; }
|
|
unsigned int GetHeight() const { return entryHeight; }
|
|
unsigned int GetSigOpCount() const { return sigOpCount; }
|
|
int64_t GetModifiedFee() const { return nFee + feeDelta; }
|
|
size_t DynamicMemoryUsage() const { return nUsageSize; }
|
|
const LockPoints& GetLockPoints() const { return lockPoints; }
|
|
|
|
// Adjusts the descendant state, if this entry is not dirty.
|
|
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
|
|
// Adjusts the ancestor state
|
|
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps);
|
|
// Updates the fee delta used for mining priority score, and the
|
|
// modified fees with descendants.
|
|
void UpdateFeeDelta(int64_t feeDelta);
|
|
// Update the LockPoints after a reorg
|
|
void UpdateLockPoints(const LockPoints& lp);
|
|
|
|
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
|
|
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
|
|
CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
|
|
|
|
bool GetSpendsCoinbase() const { return spendsCoinbase; }
|
|
|
|
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
|
|
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
|
|
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
|
|
unsigned int GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; }
|
|
|
|
mutable size_t vTxHashesIdx; //!< Index in mempool's vTxHashes
|
|
};
|
|
|
|
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
|
|
struct update_descendant_state
|
|
{
|
|
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
|
|
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
|
|
{}
|
|
|
|
void operator() (CTxMemPoolEntry &e)
|
|
{ e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
|
|
|
|
private:
|
|
int64_t modifySize;
|
|
CAmount modifyFee;
|
|
int64_t modifyCount;
|
|
};
|
|
|
|
struct update_ancestor_state
|
|
{
|
|
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int _modifySigOps) :
|
|
modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOps(_modifySigOps)
|
|
{}
|
|
|
|
void operator() (CTxMemPoolEntry &e)
|
|
{ e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOps); }
|
|
|
|
private:
|
|
int64_t modifySize;
|
|
CAmount modifyFee;
|
|
int64_t modifyCount;
|
|
int modifySigOps;
|
|
};
|
|
|
|
struct update_fee_delta
|
|
{
|
|
update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
|
|
|
|
void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
|
|
|
|
private:
|
|
int64_t feeDelta;
|
|
};
|
|
|
|
struct update_lock_points
|
|
{
|
|
update_lock_points(const LockPoints& _lp) : lp(_lp) { }
|
|
|
|
void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
|
|
|
|
private:
|
|
const LockPoints& lp;
|
|
};
|
|
|
|
// extracts a TxMemPoolEntry's transaction hash
|
|
struct mempoolentry_txid
|
|
{
|
|
typedef uint256 result_type;
|
|
result_type operator() (const CTxMemPoolEntry &entry) const
|
|
{
|
|
return entry.GetTx().GetHash();
|
|
}
|
|
};
|
|
|
|
/** \class CompareTxMemPoolEntryByDescendantScore
|
|
*
|
|
* Sort an entry by max(score/size of entry's tx, score/size with all descendants).
|
|
*/
|
|
class CompareTxMemPoolEntryByDescendantScore
|
|
{
|
|
public:
|
|
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
|
|
{
|
|
bool fUseADescendants = UseDescendantScore(a);
|
|
bool fUseBDescendants = UseDescendantScore(b);
|
|
|
|
double aModFee = fUseADescendants ? a.GetModFeesWithDescendants() : a.GetModifiedFee();
|
|
double aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize();
|
|
|
|
double bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() : b.GetModifiedFee();
|
|
double bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize();
|
|
|
|
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
|
|
double f1 = aModFee * bSize;
|
|
double f2 = aSize * bModFee;
|
|
|
|
if (f1 == f2) {
|
|
return a.GetTime() >= b.GetTime();
|
|
}
|
|
return f1 < f2;
|
|
}
|
|
|
|
// Calculate which score to use for an entry (avoiding division).
|
|
bool UseDescendantScore(const CTxMemPoolEntry &a) const
|
|
{
|
|
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
|
|
double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
|
|
return f2 > f1;
|
|
}
|
|
};
|
|
|
|
/** \class CompareTxMemPoolEntryByScore
|
|
*
|
|
* Sort by score of entry ((fee+delta)/size) in descending order
|
|
*/
|
|
class CompareTxMemPoolEntryByScore
|
|
{
|
|
public:
|
|
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
|
|
{
|
|
double f1 = (double)a.GetModifiedFee() * b.GetTxSize();
|
|
double f2 = (double)b.GetModifiedFee() * a.GetTxSize();
|
|
if (f1 == f2) {
|
|
return b.GetTx().GetHash() < a.GetTx().GetHash();
|
|
}
|
|
return f1 > f2;
|
|
}
|
|
};
|
|
|
|
class CompareTxMemPoolEntryByEntryTime
|
|
{
|
|
public:
|
|
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
|
|
{
|
|
return a.GetTime() < b.GetTime();
|
|
}
|
|
};
|
|
|
|
class CompareTxMemPoolEntryByAncestorFee
|
|
{
|
|
public:
|
|
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
|
|
{
|
|
double aFees = a.GetModFeesWithAncestors();
|
|
double aSize = a.GetSizeWithAncestors();
|
|
|
|
double bFees = b.GetModFeesWithAncestors();
|
|
double bSize = b.GetSizeWithAncestors();
|
|
|
|
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
|
|
double f1 = aFees * bSize;
|
|
double f2 = aSize * bFees;
|
|
|
|
if (f1 == f2) {
|
|
return a.GetTx().GetHash() < b.GetTx().GetHash();
|
|
}
|
|
|
|
return f1 > f2;
|
|
}
|
|
};
|
|
|
|
// Multi_index tag names
|
|
struct descendant_score {};
|
|
struct entry_time {};
|
|
struct mining_score {};
|
|
struct ancestor_score {};
|
|
|
|
class CBlockPolicyEstimator;
|
|
|
|
/**
|
|
* Information about a mempool transaction.
|
|
*/
|
|
struct TxMempoolInfo
|
|
{
|
|
/** The transaction itself */
|
|
CTransactionRef tx;
|
|
|
|
/** Time the transaction entered the mempool. */
|
|
int64_t nTime;
|
|
|
|
/** Feerate of the transaction. */
|
|
CFeeRate feeRate;
|
|
|
|
/** The fee delta. */
|
|
int64_t nFeeDelta;
|
|
};
|
|
|
|
/** Reason why a transaction was removed from the mempool,
|
|
* this is passed to the notification signal.
|
|
*/
|
|
enum class MemPoolRemovalReason {
|
|
UNKNOWN = 0, //! Manually removed or unknown reason
|
|
EXPIRY, //! Expired from mempool
|
|
SIZELIMIT, //! Removed in size limiting
|
|
REORG, //! Removed for reorganization
|
|
BLOCK, //! Removed for block
|
|
CONFLICT, //! Removed for conflict with in-block transaction
|
|
REPLACED //! Removed for replacement
|
|
};
|
|
|
|
class SaltedTxidHasher
|
|
{
|
|
private:
|
|
/** Salt */
|
|
const uint64_t k0, k1;
|
|
|
|
public:
|
|
SaltedTxidHasher();
|
|
|
|
size_t operator()(const uint256& txid) const {
|
|
return SipHashUint256(k0, k1, txid);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* CTxMemPool stores valid-according-to-the-current-best-chain transactions
|
|
* that may be included in the next block.
|
|
*
|
|
* 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
|
|
* example, the following new transactions will not be added to the mempool:
|
|
* - a transaction which doesn't meet the minimum fee requirements.
|
|
* - a new transaction that double-spends an input of a transaction already in
|
|
* the pool where the new transaction does not meet the Replace-By-Fee
|
|
* requirements as defined in BIP 125.
|
|
* - a non-standard transaction.
|
|
*
|
|
* CTxMemPool::mapTx, and CTxMemPoolEntry bookkeeping:
|
|
*
|
|
* mapTx is a boost::multi_index that sorts the mempool on 4 criteria:
|
|
* - transaction hash
|
|
* - feerate [we use max(feerate of tx, feerate of tx with all descendants)]
|
|
* - time in mempool
|
|
* - mining score (feerate modified by any fee deltas from PrioritiseTransaction)
|
|
*
|
|
* Note: the term "descendant" refers to in-mempool transactions that depend on
|
|
* this one, while "ancestor" refers to in-mempool transactions that a given
|
|
* transaction depends on.
|
|
*
|
|
* In order for the feerate sort to remain correct, we must update transactions
|
|
* in the mempool when new descendants arrive. To facilitate this, we track
|
|
* the set of in-mempool direct parents and direct children in mapLinks. Within
|
|
* each CTxMemPoolEntry, we track the size and fees of all descendants.
|
|
*
|
|
* Usually when a new transaction is added to the mempool, it has no in-mempool
|
|
* children (because any such children would be an orphan). So in
|
|
* addUnchecked(), we:
|
|
* - update a new entry's setMemPoolParents to include all in-mempool parents
|
|
* - update the new entry's direct parents to include the new tx as a child
|
|
* - update all ancestors of the transaction to include the new tx's size/fee
|
|
*
|
|
* When a transaction is removed from the mempool, we must:
|
|
* - update all in-mempool parents to not track the tx in setMemPoolChildren
|
|
* - update all ancestors to not include the tx's size/fees in descendant state
|
|
* - update all in-mempool children to not include it as a parent
|
|
*
|
|
* These happen in UpdateForRemoveFromMempool(). (Note that when removing a
|
|
* transaction along with its descendants, we must calculate that set of
|
|
* transactions to be removed before doing the removal, or else the mempool can
|
|
* be in an inconsistent state where it's impossible to walk the ancestors of
|
|
* a transaction.)
|
|
*
|
|
* In the event of a reorg, the assumption that a newly added tx has no
|
|
* in-mempool children is false. In particular, the mempool is in an
|
|
* inconsistent state while new transactions are being added, because there may
|
|
* be descendant transactions of a tx coming from a disconnected block that are
|
|
* unreachable from just looking at transactions in the mempool (the linking
|
|
* transactions may also be in the disconnected block, waiting to be added).
|
|
* Because of this, there's not much benefit in trying to search for in-mempool
|
|
* children in addUnchecked(). Instead, in the special case of transactions
|
|
* being added from a disconnected block, we require the caller to clean up the
|
|
* state, to account for in-mempool, out-of-block descendants for all the
|
|
* in-block transactions by calling UpdateTransactionsFromBlock(). Note that
|
|
* until this is called, the mempool state is not consistent, and in particular
|
|
* mapLinks may not be correct (and therefore functions like
|
|
* CalculateMemPoolAncestors() and CalculateDescendants() that rely
|
|
* on them to walk the mempool are not generally safe to use).
|
|
*
|
|
* Computational limits:
|
|
*
|
|
* Updating all in-mempool ancestors of a newly added transaction can be slow,
|
|
* if no bound exists on how many in-mempool ancestors there may be.
|
|
* CalculateMemPoolAncestors() takes configurable limits that are designed to
|
|
* prevent these calculations from being too CPU intensive.
|
|
*
|
|
* Adding transactions from a disconnected block can be very time consuming,
|
|
* because we don't have a way to limit the number of in-mempool descendants.
|
|
* To bound CPU processing, we limit the amount of work we're willing to do
|
|
* to properly update the descendant information for a tx being added from
|
|
* a disconnected block. If we would exceed the limit, then we instead mark
|
|
* the entry as "dirty", and set the feerate for sorting purposes to be equal
|
|
* the feerate of the transaction without any descendants.
|
|
*
|
|
*/
|
|
class CTxMemPool
|
|
{
|
|
private:
|
|
uint32_t nCheckFrequency; //!< Value n means that n times in 2^32 we check.
|
|
unsigned int nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
|
|
CBlockPolicyEstimator* minerPolicyEstimator;
|
|
|
|
uint64_t totalTxSize; //!< sum of all mempool tx' byte sizes
|
|
uint64_t cachedInnerUsage; //!< sum of dynamic memory usage of all the map elements (NOT the maps themselves)
|
|
|
|
mutable int64_t lastRollingFeeUpdate;
|
|
mutable bool blockSinceLastRollingFeeBump;
|
|
mutable double rollingMinimumFeeRate; //!< minimum fee to get into the pool, decreases exponentially
|
|
|
|
void trackPackageRemoved(const CFeeRate& rate);
|
|
|
|
public:
|
|
|
|
static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
|
|
|
|
typedef boost::multi_index_container<
|
|
CTxMemPoolEntry,
|
|
boost::multi_index::indexed_by<
|
|
// sorted by txid
|
|
boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
|
|
// sorted by fee rate
|
|
boost::multi_index::ordered_non_unique<
|
|
boost::multi_index::tag<descendant_score>,
|
|
boost::multi_index::identity<CTxMemPoolEntry>,
|
|
CompareTxMemPoolEntryByDescendantScore
|
|
>,
|
|
// sorted by entry time
|
|
boost::multi_index::ordered_non_unique<
|
|
boost::multi_index::tag<entry_time>,
|
|
boost::multi_index::identity<CTxMemPoolEntry>,
|
|
CompareTxMemPoolEntryByEntryTime
|
|
>,
|
|
// sorted by score (for mining prioritization)
|
|
boost::multi_index::ordered_unique<
|
|
boost::multi_index::tag<mining_score>,
|
|
boost::multi_index::identity<CTxMemPoolEntry>,
|
|
CompareTxMemPoolEntryByScore
|
|
>,
|
|
// sorted by fee rate with ancestors
|
|
boost::multi_index::ordered_non_unique<
|
|
boost::multi_index::tag<ancestor_score>,
|
|
boost::multi_index::identity<CTxMemPoolEntry>,
|
|
CompareTxMemPoolEntryByAncestorFee
|
|
>
|
|
>
|
|
> indexed_transaction_set;
|
|
|
|
mutable CCriticalSection cs;
|
|
indexed_transaction_set mapTx;
|
|
|
|
typedef indexed_transaction_set::nth_index<0>::type::iterator txiter;
|
|
std::vector<std::pair<uint256, txiter> > vTxHashes; //!< All tx hashes/entries in mapTx, in random order
|
|
|
|
struct CompareIteratorByHash {
|
|
bool operator()(const txiter &a, const txiter &b) const {
|
|
return a->GetTx().GetHash() < b->GetTx().GetHash();
|
|
}
|
|
};
|
|
typedef std::set<txiter, CompareIteratorByHash> setEntries;
|
|
|
|
const setEntries & GetMemPoolParents(txiter entry) const;
|
|
const setEntries & GetMemPoolChildren(txiter entry) const;
|
|
private:
|
|
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
|
|
|
struct TxLinks {
|
|
setEntries parents;
|
|
setEntries children;
|
|
};
|
|
|
|
typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
|
|
txlinksMap mapLinks;
|
|
|
|
typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> addressDeltaMap;
|
|
addressDeltaMap mapAddress;
|
|
|
|
typedef std::map<uint256, std::vector<CMempoolAddressDeltaKey> > addressDeltaMapInserted;
|
|
addressDeltaMapInserted mapAddressInserted;
|
|
|
|
typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mapSpentIndex;
|
|
mapSpentIndex mapSpent;
|
|
|
|
typedef std::map<uint256, std::vector<CSpentIndexKey> > mapSpentIndexInserted;
|
|
mapSpentIndexInserted mapSpentInserted;
|
|
|
|
void UpdateParent(txiter entry, txiter parent, bool add);
|
|
void UpdateChild(txiter entry, txiter child, bool add);
|
|
|
|
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const;
|
|
|
|
public:
|
|
indirectmap<COutPoint, const CTransaction*> mapNextTx;
|
|
std::map<uint256, std::pair<double, CAmount> > mapDeltas;
|
|
|
|
/** Create a new CTxMemPool.
|
|
*/
|
|
CTxMemPool(const CFeeRate& _minReasonableRelayFee);
|
|
~CTxMemPool();
|
|
|
|
/**
|
|
* If sanity-checking is turned on, check makes sure the pool is
|
|
* consistent (does not contain two transactions that spend the same inputs,
|
|
* all inputs are in the mapNextTx array). If sanity-checking is turned off,
|
|
* check does nothing.
|
|
*/
|
|
void check(const CCoinsViewCache *pcoins) const;
|
|
void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967295.0; }
|
|
|
|
// addUnchecked must updated state for all ancestors of a given transaction,
|
|
// to track size/count of descendant transactions. First version of
|
|
// addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
|
|
// then invoke the second version.
|
|
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
|
|
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
|
|
|
|
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
|
|
bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses,
|
|
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
|
|
bool removeAddressIndex(const uint256 txhash);
|
|
|
|
void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
|
|
bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
|
|
bool removeSpentIndex(const uint256 txhash);
|
|
|
|
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
|
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
|
|
void removeConflicts(const CTransaction &tx);
|
|
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
|
|
|
|
void clear();
|
|
void _clear(); //lock free
|
|
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
|
|
void queryHashes(std::vector<uint256>& vtxid);
|
|
bool isSpent(const COutPoint& outpoint);
|
|
unsigned int GetTransactionsUpdated() const;
|
|
void AddTransactionsUpdated(unsigned int n);
|
|
/**
|
|
* Check that none of this transactions inputs are in the mempool, and thus
|
|
* the tx is not dependent on other mempool transactions to be included in a block.
|
|
*/
|
|
bool HasNoInputsOf(const CTransaction& tx) const;
|
|
|
|
/** Affect CreateNewBlock prioritisation of transactions */
|
|
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount& nFeeDelta);
|
|
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta) const;
|
|
void ClearPrioritisation(const uint256 hash);
|
|
|
|
public:
|
|
/** Remove a set of transactions from the mempool.
|
|
* If a transaction is in this set, then all in-mempool descendants must
|
|
* also be in the set, unless this transaction is being removed for being
|
|
* in a block.
|
|
* Set updateDescendants to true when removing a tx that was in a block, so
|
|
* that any in-mempool descendants have their ancestor state updated.
|
|
*/
|
|
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
|
|
|
/** When adding transactions from a disconnected block back to the mempool,
|
|
* new mempool entries may have children in the mempool (which is generally
|
|
* not the case when otherwise adding transactions).
|
|
* UpdateTransactionsFromBlock() will find child transactions and update the
|
|
* descendant state for each transaction in hashesToUpdate (excluding any
|
|
* child transactions present in hashesToUpdate, which are already accounted
|
|
* for). Note: hashesToUpdate should be the set of transactions from the
|
|
* disconnected block that have been accepted back into the mempool.
|
|
*/
|
|
void UpdateTransactionsFromBlock(const std::vector<uint256> &hashesToUpdate);
|
|
|
|
/** Try to calculate all in-mempool ancestors of entry.
|
|
* (these are all calculated including the tx itself)
|
|
* limitAncestorCount = max number of ancestors
|
|
* limitAncestorSize = max size of ancestors
|
|
* limitDescendantCount = max number of descendants any ancestor can have
|
|
* limitDescendantSize = max size of descendants any ancestor can have
|
|
* errString = populated with error reason if any limits are hit
|
|
* fSearchForParents = whether to search a tx's vin for in-mempool parents, or
|
|
* look up parents from mapLinks. Must be true for entries not in the mempool
|
|
*/
|
|
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents = true) const;
|
|
|
|
/** Populate setDescendants with all in-mempool descendants of hash.
|
|
* Assumes that setDescendants includes all in-mempool descendants of anything
|
|
* already in it. */
|
|
void CalculateDescendants(txiter it, setEntries &setDescendants);
|
|
|
|
/** The minimum fee to get into the mempool, which may itself not be enough
|
|
* for larger-sized transactions.
|
|
* The incrementalRelayFee policy variable is used to bound the time it
|
|
* takes the fee rate to go back down all the way to 0. When the feerate
|
|
* would otherwise be half of this, it is set to 0 instead.
|
|
*/
|
|
CFeeRate GetMinFee(size_t sizelimit) const;
|
|
void UpdateMinFee(const CFeeRate& _minReasonableRelayFee);
|
|
|
|
/** Remove transactions from the mempool until its dynamic size is <= sizelimit.
|
|
* pvNoSpendsRemaining, if set, will be populated with the list of outpoints
|
|
* which are not in mempool which no longer have any spends in this mempool.
|
|
*/
|
|
void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=NULL);
|
|
|
|
/** Expire all transaction (and their dependencies) in the mempool older than time. Return the number of removed transactions. */
|
|
int Expire(int64_t time);
|
|
|
|
/** Returns false if the transaction is in the mempool and not within the chain limit specified. */
|
|
bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const;
|
|
|
|
unsigned long size()
|
|
{
|
|
LOCK(cs);
|
|
return mapTx.size();
|
|
}
|
|
|
|
uint64_t GetTotalTxSize()
|
|
{
|
|
LOCK(cs);
|
|
return totalTxSize;
|
|
}
|
|
|
|
bool exists(uint256 hash) const
|
|
{
|
|
LOCK(cs);
|
|
return (mapTx.count(hash) != 0);
|
|
}
|
|
|
|
bool exists(const COutPoint& outpoint) const
|
|
{
|
|
LOCK(cs);
|
|
auto it = mapTx.find(outpoint.hash);
|
|
return (it != mapTx.end() && outpoint.n < it->GetTx().vout.size());
|
|
}
|
|
|
|
CTransactionRef get(const uint256& hash) const;
|
|
TxMempoolInfo info(const uint256& hash) const;
|
|
std::vector<TxMempoolInfo> infoAll() const;
|
|
|
|
/** Estimate fee rate needed to get into the next nBlocks
|
|
* If no answer can be given at nBlocks, return an estimate
|
|
* at the lowest number of blocks where one can be given
|
|
*/
|
|
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks = NULL) const;
|
|
|
|
/** Estimate fee rate needed to get into the next nBlocks */
|
|
CFeeRate estimateFee(int nBlocks) const;
|
|
|
|
/** Estimate priority needed to get into the next nBlocks
|
|
* If no answer can be given at nBlocks, return an estimate
|
|
* at the lowest number of blocks where one can be given
|
|
*/
|
|
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks = NULL) const;
|
|
|
|
/** Estimate priority needed to get into the next nBlocks */
|
|
double estimatePriority(int nBlocks) const;
|
|
|
|
/** Write/Read estimates to disk */
|
|
bool WriteFeeEstimates(CAutoFile& fileout) const;
|
|
bool ReadFeeEstimates(CAutoFile& filein);
|
|
|
|
size_t DynamicMemoryUsage() const;
|
|
|
|
boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
|
|
boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
|
|
|
|
private:
|
|
/** UpdateForDescendants is used by UpdateTransactionsFromBlock to update
|
|
* the descendants for a single transaction that has been added to the
|
|
* mempool but may have child transactions in the mempool, eg during a
|
|
* chain reorg. setExclude is the set of descendant transactions in the
|
|
* mempool that must not be accounted for (because any descendants in
|
|
* setExclude were added to the mempool after the transaction being
|
|
* updated and hence their state is already reflected in the parent
|
|
* state).
|
|
*
|
|
* cachedDescendants will be updated with the descendants of the transaction
|
|
* being updated, so that future invocations don't need to walk the
|
|
* same transaction again, if encountered in another transaction chain.
|
|
*/
|
|
void UpdateForDescendants(txiter updateIt,
|
|
cacheMap &cachedDescendants,
|
|
const std::set<uint256> &setExclude);
|
|
/** Update ancestors of hash to add/remove it as a descendant transaction. */
|
|
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors);
|
|
/** Set ancestor state for an entry */
|
|
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors);
|
|
/** For each transaction being removed, update ancestors and any direct children.
|
|
* If updateDescendants is true, then also update in-mempool descendants'
|
|
* ancestor state. */
|
|
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants);
|
|
/** Sever link between specified transaction and direct children. */
|
|
void UpdateChildrenForRemoval(txiter entry);
|
|
|
|
/** Before calling removeUnchecked for a given transaction,
|
|
* UpdateForRemoveFromMempool must be called on the entire (dependent) set
|
|
* of transactions being removed at the same time. We use each
|
|
* CTxMemPoolEntry's setMemPoolParents in order to walk ancestors of a
|
|
* given transaction that is removed, so we can't remove intermediate
|
|
* transactions in a chain before we've updated all the state for the
|
|
* removal.
|
|
*/
|
|
void removeUnchecked(txiter entry, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
|
|
};
|
|
|
|
/**
|
|
* CCoinsView that brings transactions from a memorypool into view.
|
|
* It does not check for spendings by memory pool transactions.
|
|
*/
|
|
class CCoinsViewMemPool : public CCoinsViewBacked
|
|
{
|
|
protected:
|
|
const CTxMemPool& mempool;
|
|
|
|
public:
|
|
CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
|
|
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
|
|
};
|
|
|
|
// We want to sort transactions by coin age priority
|
|
typedef std::pair<double, CTxMemPool::txiter> TxCoinAgePriority;
|
|
|
|
struct TxCoinAgePriorityCompare
|
|
{
|
|
bool operator()(const TxCoinAgePriority& a, const TxCoinAgePriority& b)
|
|
{
|
|
if (a.first == b.first)
|
|
return CompareTxMemPoolEntryByScore()(*(b.second), *(a.second)); //Reverse order to make sort less than
|
|
return a.first < b.first;
|
|
}
|
|
};
|
|
|
|
#endif // BITCOIN_TXMEMPOOL_H
|