v29.4-roots.2 · Commit 3: [PATCH 03/21] policy: restore conservative relay and network controls
src/txmempool.h
Before: src/txmempool.h · After: src/txmempool.h
File metadata
index acc52aef1d9543f1e582aecaca049612dbd155dc..4acb5f626fc7e1611caf8c44bb2c44f05986d24b 100644
Download original patch · Release notes
Diff rows 1–136 of 136. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/txmempool.h
CHANGED
|
@@ -17,6 +17,7 @@
|
|
| 17 |
#include <policy/feerate.h>
|
| 18 |
#include <policy/packages.h>
|
| 19 |
#include <primitives/transaction.h>
|
|
|
|
| 20 |
#include <sync.h>
|
| 21 |
#include <util/epochguard.h>
|
| 22 |
#include <util/hasher.h>
|
|
@@ -41,13 +42,23 @@
|
|
| 41 |
#include <vector>
|
| 42 |
|
| 43 |
class CChain;
|
|
|
|
| 44 |
class ValidationSignals;
|
| 45 |
|
| 46 |
struct bilingual_str;
|
| 47 |
|
|
|
|
|
|
|
| 48 |
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
|
| 49 |
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
/**
|
| 52 |
* Test whether the LockPoints height and time are still valid on the current chain
|
| 53 |
*/
|
|
@@ -200,12 +211,16 @@ public:
|
|
| 200 |
}
|
| 201 |
};
|
| 202 |
|
|
|
|
|
|
|
| 203 |
// Multi_index tag names
|
| 204 |
struct descendant_score {};
|
| 205 |
struct entry_time {};
|
| 206 |
struct ancestor_score {};
|
| 207 |
struct index_by_wtxid {};
|
| 208 |
|
|
|
|
|
|
|
| 209 |
/**
|
| 210 |
* Information about a mempool transaction.
|
| 211 |
*/
|
|
@@ -396,6 +411,9 @@ public:
|
|
| 396 |
using Limits = kernel::MemPoolLimits;
|
| 397 |
|
| 398 |
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
|
|
|
|
|
|
|
|
|
| 399 |
private:
|
| 400 |
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
| 401 |
|
|
@@ -430,11 +448,11 @@ private:
|
|
| 430 |
|
| 431 |
public:
|
| 432 |
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
| 433 |
-
std::map<uint256, CAmount> mapDeltas GUARDED_BY(cs);
|
| 434 |
|
| 435 |
using Options = kernel::MemPoolOptions;
|
| 436 |
|
| 437 |
-
const Options m_opts;
|
| 438 |
|
| 439 |
/** Create a new CTxMemPool.
|
| 440 |
* Sanity checks will be off by default for performance, because otherwise
|
|
@@ -473,10 +491,19 @@ public:
|
|
| 473 |
* the tx is not dependent on other mempool transactions to be included in a block.
|
| 474 |
*/
|
| 475 |
bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
|
| 477 |
/** Affect CreateNewBlock prioritisation of transactions */
|
| 478 |
-
void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
|
| 479 |
-
void ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
|
|
|
| 480 |
void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 481 |
|
| 482 |
struct delta_info {
|
|
@@ -484,6 +511,7 @@ public:
|
|
| 484 |
const bool in_mempool;
|
| 485 |
/** The fee delta added using PrioritiseTransaction(). */
|
| 486 |
const CAmount delta;
|
|
|
|
| 487 |
/** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
|
| 488 |
std::optional<CAmount> modified_fee;
|
| 489 |
/** The prioritised transaction's txid. */
|
|
@@ -667,6 +695,8 @@ public:
|
|
| 667 |
std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 668 |
std::vector<TxMempoolInfo> infoAll() const;
|
| 669 |
|
|
|
|
|
|
|
| 670 |
size_t DynamicMemoryUsage() const;
|
| 671 |
|
| 672 |
/** Adds a transaction to the unbroadcast set */
|
|
@@ -827,7 +857,12 @@ public:
|
|
| 827 |
|
| 828 |
using TxHandle = CTxMemPool::txiter;
|
| 829 |
|
| 830 |
-
TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 831 |
void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
|
| 832 |
|
| 833 |
const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
|
|
@@ -868,9 +903,9 @@ public:
|
|
| 868 |
|
| 869 |
void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
| 870 |
|
| 871 |
-
private:
|
| 872 |
CTxMemPool* m_pool;
|
| 873 |
CTxMemPool::indexed_transaction_set m_to_add;
|
|
|
|
| 874 |
std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
|
| 875 |
// map from the m_to_add index to the ancestors for the transaction
|
| 876 |
std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
|
|
@@ -918,6 +953,9 @@ private:
|
|
| 918 |
* It also allows you to sign a double-spend directly in
|
| 919 |
* signrawtransactionwithkey and signrawtransactionwithwallet,
|
| 920 |
* as long as the conflicting transaction is not yet confirmed.
|
|
|
|
|
|
|
|
|
|
| 921 |
*/
|
| 922 |
class CCoinsViewMemPool : public CCoinsViewBacked
|
| 923 |
{
|
|
|
|
| 17 |
#include <policy/feerate.h>
|
| 18 |
#include <policy/packages.h>
|
| 19 |
#include <primitives/transaction.h>
|
| 20 |
+
#include <script/script.h>
|
| 21 |
#include <sync.h>
|
| 22 |
#include <util/epochguard.h>
|
| 23 |
#include <util/hasher.h>
|
|
|
|
| 42 |
#include <vector>
|
| 43 |
|
| 44 |
class CChain;
|
| 45 |
+
class CScript;
|
| 46 |
class ValidationSignals;
|
| 47 |
|
| 48 |
struct bilingual_str;
|
| 49 |
|
| 50 |
+
static constexpr std::chrono::minutes DYNAMIC_DUST_FEERATE_UPDATE_INTERVAL{15};
|
| 51 |
+
|
| 52 |
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
|
| 53 |
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
| 54 |
|
| 55 |
+
inline int64_t maxmempoolMinimumBytes(const int64_t descendant_size_vbytes) {
|
| 56 |
+
return descendant_size_vbytes * 40;
|
| 57 |
+
}
|
| 58 |
+
inline int64_t limitdescendantsizeMaximumVBytes(const int64_t maxmempool) {
|
| 59 |
+
return maxmempool / 40;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
/**
|
| 63 |
* Test whether the LockPoints height and time are still valid on the current chain
|
| 64 |
*/
|
|
|
|
| 211 |
}
|
| 212 |
};
|
| 213 |
|
| 214 |
+
uint160 ScriptHashkey(const CScript& script);
|
| 215 |
+
|
| 216 |
// Multi_index tag names
|
| 217 |
struct descendant_score {};
|
| 218 |
struct entry_time {};
|
| 219 |
struct ancestor_score {};
|
| 220 |
struct index_by_wtxid {};
|
| 221 |
|
| 222 |
+
class CBlockPolicyEstimator;
|
| 223 |
+
|
| 224 |
/**
|
| 225 |
* Information about a mempool transaction.
|
| 226 |
*/
|
|
|
|
| 411 |
using Limits = kernel::MemPoolLimits;
|
| 412 |
|
| 413 |
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 414 |
+
|
| 415 |
+
std::map<uint160, std::pair<const CTransaction *, const CTransaction *>> mapUsedSPK;
|
| 416 |
+
|
| 417 |
private:
|
| 418 |
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
| 419 |
|
|
|
|
| 448 |
|
| 449 |
public:
|
| 450 |
indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
|
| 451 |
+
std::map<uint256, std::pair<double, CAmount> > mapDeltas GUARDED_BY(cs);
|
| 452 |
|
| 453 |
using Options = kernel::MemPoolOptions;
|
| 454 |
|
| 455 |
+
Options m_opts;
|
| 456 |
|
| 457 |
/** Create a new CTxMemPool.
|
| 458 |
* Sanity checks will be off by default for performance, because otherwise
|
|
|
|
| 491 |
* the tx is not dependent on other mempool transactions to be included in a block.
|
| 492 |
*/
|
| 493 |
bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 494 |
+
/**
|
| 495 |
+
* Update all transactions in the mempool which depend on tx to recalculate their priority
|
| 496 |
+
* and adjust the input value that will age to reflect that the inputs from this transaction have
|
| 497 |
+
* either just been added to the chain or just been removed.
|
| 498 |
+
*/
|
| 499 |
+
void UpdateDependentPriorities(const CTransaction &tx, unsigned int nBlockHeight, bool addToChain);
|
| 500 |
+
|
| 501 |
+
void UpdateDynamicDustFeerate();
|
| 502 |
|
| 503 |
/** Affect CreateNewBlock prioritisation of transactions */
|
| 504 |
+
void PrioritiseTransaction(const uint256& hash, double dPriorityDelta, const CAmount& nFeeDelta);
|
| 505 |
+
void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta) { PrioritiseTransaction(hash, 0., nFeeDelta); }
|
| 506 |
+
void ApplyDeltas(const uint256& hash, double &dPriorityDelta, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 507 |
void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 508 |
|
| 509 |
struct delta_info {
|
|
|
|
| 511 |
const bool in_mempool;
|
| 512 |
/** The fee delta added using PrioritiseTransaction(). */
|
| 513 |
const CAmount delta;
|
| 514 |
+
const double priority_delta;
|
| 515 |
/** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
|
| 516 |
std::optional<CAmount> modified_fee;
|
| 517 |
/** The prioritised transaction's txid. */
|
|
|
|
| 695 |
std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
| 696 |
std::vector<TxMempoolInfo> infoAll() const;
|
| 697 |
|
| 698 |
+
void FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results);
|
| 699 |
+
|
| 700 |
size_t DynamicMemoryUsage() const;
|
| 701 |
|
| 702 |
/** Adds a transaction to the unbroadcast set */
|
|
|
|
| 857 |
|
| 858 |
using TxHandle = CTxMemPool::txiter;
|
| 859 |
|
| 860 |
+
TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, CoinAgeCache coin_age_cache, bool spends_coinbase, int32_t extra_weight, int64_t sigops_cost, LockPoints lp);
|
| 861 |
+
TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
|
| 862 |
+
{
|
| 863 |
+
return StageAddition(tx, fee, time, entry_height, entry_sequence, COIN_AGE_CACHE_ZERO,
|
| 864 |
+
spends_coinbase, /*extra_weight=*/0, sigops_cost, lp);
|
| 865 |
+
}
|
| 866 |
void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
|
| 867 |
|
| 868 |
const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
|
|
|
|
| 903 |
|
| 904 |
void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
| 905 |
|
|
|
|
| 906 |
CTxMemPool* m_pool;
|
| 907 |
CTxMemPool::indexed_transaction_set m_to_add;
|
| 908 |
+
private:
|
| 909 |
std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
|
| 910 |
// map from the m_to_add index to the ancestors for the transaction
|
| 911 |
std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
|
|
|
|
| 953 |
* It also allows you to sign a double-spend directly in
|
| 954 |
* signrawtransactionwithkey and signrawtransactionwithwallet,
|
| 955 |
* as long as the conflicting transaction is not yet confirmed.
|
| 956 |
+
*
|
| 957 |
+
* Its Cursor also doesn't work. In general, it is broken as a CCoinsView
|
| 958 |
+
* implementation outside of a few use cases.
|
| 959 |
*/
|
| 960 |
class CCoinsViewMemPool : public CCoinsViewBacked
|
| 961 |
{
|