v29.4-roots.1 · Commit 3: [PATCH 03/13] policy: restore conservative relay and network controls
src/txmempool.cpp
Before: src/txmempool.cpp · After: src/txmempool.cpp
File metadata
index 3a5a3fb306d38669600ac395c58c68c10f27f787..dd76521e4e288b6aa428a29c64f021d9b2ef13fd 100644
Download original patch · Release notes
Diff rows 1–290 of 290. 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.cpp
CHANGED
|
@@ -11,11 +11,16 @@
|
|
| 11 |
#include <consensus/consensus.h>
|
| 12 |
#include <consensus/tx_verify.h>
|
| 13 |
#include <consensus/validation.h>
|
|
|
|
| 14 |
#include <logging.h>
|
|
|
|
|
|
|
| 15 |
#include <policy/policy.h>
|
| 16 |
#include <policy/settings.h>
|
| 17 |
#include <random.h>
|
|
|
|
| 18 |
#include <tinyformat.h>
|
|
|
|
| 19 |
#include <util/check.h>
|
| 20 |
#include <util/feefrac.h>
|
| 21 |
#include <util/moneystr.h>
|
|
@@ -54,6 +59,13 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
|
|
| 54 |
return true;
|
| 55 |
}
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
| 58 |
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
|
| 59 |
{
|
|
@@ -404,7 +416,7 @@ void CTxMemPoolEntry::UpdateAncestorState(int32_t modifySize, CAmount modifyFee,
|
|
| 404 |
static CTxMemPool::Options&& Flatten(CTxMemPool::Options&& opts, bilingual_str& error)
|
| 405 |
{
|
| 406 |
opts.check_ratio = std::clamp<int>(opts.check_ratio, 0, 1'000'000);
|
| 407 |
-
int64_t descendant_limit_bytes = opts.limits.descendant_size_vbytes * 40;
|
| 408 |
if (opts.max_size_bytes < 0 || opts.max_size_bytes < descendant_limit_bytes) {
|
| 409 |
error = strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0));
|
| 410 |
}
|
|
@@ -414,6 +426,17 @@ static CTxMemPool::Options&& Flatten(CTxMemPool::Options&& opts, bilingual_str&
|
|
| 414 |
CTxMemPool::CTxMemPool(Options opts, bilingual_str& error)
|
| 415 |
: m_opts{Flatten(std::move(opts), error)}
|
| 416 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
}
|
| 418 |
|
| 419 |
bool CTxMemPool::isSpent(const COutPoint& outpoint) const
|
|
@@ -453,11 +476,20 @@ void CTxMemPool::Apply(ChangeSet* changeset)
|
|
| 453 |
ancestors = *Assume(changeset->CalculateMemPoolAncestors(tx_entry, Limits::NoLimits()));
|
| 454 |
}
|
| 455 |
// First splice this entry into mapTx.
|
|
|
|
| 456 |
auto node_handle = changeset->m_to_add.extract(tx_entry);
|
| 457 |
auto result = mapTx.insert(std::move(node_handle));
|
| 458 |
|
| 459 |
Assume(result.inserted);
|
| 460 |
txiter it = result.position;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
// Now update the entry for ancestors/descendants.
|
| 463 |
if (ancestors.has_value()) {
|
|
@@ -510,6 +542,17 @@ void CTxMemPool::addNewTransaction(CTxMemPool::txiter newit, CTxMemPool::setEntr
|
|
| 510 |
txns_randomized.emplace_back(newit->GetSharedTx());
|
| 511 |
newit->idx_randomized = txns_randomized.size() - 1;
|
| 512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
TRACEPOINT(mempool, added,
|
| 514 |
entry.GetTx().GetHash().data(),
|
| 515 |
entry.GetTxSize(),
|
|
@@ -538,6 +581,7 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
|
| 538 |
std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(it->GetTime()).count()
|
| 539 |
);
|
| 540 |
|
|
|
|
| 541 |
for (const CTxIn& txin : it->GetTx().vin)
|
| 542 |
mapNextTx.erase(txin.prevout);
|
| 543 |
|
|
@@ -554,6 +598,19 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason)
|
|
| 554 |
} else
|
| 555 |
txns_randomized.clear();
|
| 556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
totalTxSize -= it->GetTxSize();
|
| 558 |
m_total_fee -= it->GetFee();
|
| 559 |
cachedInnerUsage -= it->DynamicMemoryUsage();
|
|
@@ -669,9 +726,11 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
|
| 669 |
AssertLockHeld(cs);
|
| 670 |
Assume(!m_have_changeset);
|
| 671 |
std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
|
|
|
|
| 672 |
txs_removed_for_block.reserve(vtx.size());
|
| 673 |
for (const auto& tx : vtx)
|
| 674 |
{
|
|
|
|
| 675 |
txiter it = mapTx.find(tx->GetHash());
|
| 676 |
if (it != mapTx.end()) {
|
| 677 |
setEntries stage;
|
|
@@ -682,6 +741,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
|
| 682 |
removeConflicts(*tx);
|
| 683 |
ClearPrioritisation(tx->GetHash());
|
| 684 |
}
|
|
|
|
| 685 |
if (m_opts.signals) {
|
| 686 |
m_opts.signals->MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);
|
| 687 |
}
|
|
@@ -689,6 +749,38 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
|
| 689 |
blockSinceLastRollingFeeBump = true;
|
| 690 |
}
|
| 691 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
|
| 693 |
{
|
| 694 |
if (m_opts.check_ratio == 0) return;
|
|
@@ -708,6 +800,14 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
|
|
| 708 |
|
| 709 |
for (const auto& it : GetSortedDepthAndScore()) {
|
| 710 |
checkTotal += it->GetTxSize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
check_total_fee += it->GetFee();
|
| 712 |
innerUsage += it->DynamicMemoryUsage();
|
| 713 |
const CTransaction& tx = it->GetTx();
|
|
@@ -844,6 +944,21 @@ std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::Get
|
|
| 844 |
return iters;
|
| 845 |
}
|
| 846 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
|
| 848 |
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
|
| 849 |
}
|
|
@@ -910,15 +1025,17 @@ TxMempoolInfo CTxMemPool::info_for_relay(const GenTxid& gtxid, uint64_t last_seq
|
|
| 910 |
}
|
| 911 |
}
|
| 912 |
|
| 913 |
-
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
|
| 914 |
{
|
| 915 |
{
|
| 916 |
LOCK(cs);
|
| 917 |
-
CAmount &delta = mapDeltas[hash];
|
| 918 |
-
delta = SaturatingAdd(delta, nFeeDelta);
|
|
|
|
| 919 |
txiter it = mapTx.find(hash);
|
| 920 |
if (it != mapTx.end()) {
|
| 921 |
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
|
|
|
|
| 922 |
// Now update all ancestors' modified fees with descendants
|
| 923 |
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, *it, Limits::NoLimits(), /*fSearchForParents=*/false)};
|
| 924 |
for (txiter ancestorIt : ancestors) {
|
|
@@ -933,27 +1050,29 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
|
|
| 933 |
}
|
| 934 |
++nTransactionsUpdated;
|
| 935 |
}
|
| 936 |
-
if (delta == 0) {
|
| 937 |
mapDeltas.erase(hash);
|
| 938 |
LogPrintf("PrioritiseTransaction: %s (%sin mempool) delta cleared\n", hash.ToString(), it == mapTx.end() ? "not " : "");
|
| 939 |
} else {
|
| 940 |
-
LogPrintf("PrioritiseTransaction: %s (%sin mempool) fee += %s, new delta=%s\n",
|
| 941 |
hash.ToString(),
|
| 942 |
it == mapTx.end() ? "not " : "",
|
|
|
|
| 943 |
FormatMoney(nFeeDelta),
|
| 944 |
-
FormatMoney(delta));
|
| 945 |
}
|
| 946 |
}
|
| 947 |
}
|
| 948 |
|
| 949 |
-
void CTxMemPool::ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const
|
| 950 |
{
|
| 951 |
AssertLockHeld(cs);
|
| 952 |
-
std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
|
| 953 |
if (pos == mapDeltas.end())
|
| 954 |
return;
|
| 955 |
-
const CAmount &delta = pos->second;
|
| 956 |
-
nFeeDelta += delta;
|
|
|
|
| 957 |
}
|
| 958 |
|
| 959 |
void CTxMemPool::ClearPrioritisation(const uint256& hash)
|
|
@@ -973,7 +1092,7 @@ std::vector<CTxMemPool::delta_info> CTxMemPool::GetPrioritisedTransactions() con
|
|
| 973 |
const bool in_mempool{iter != mapTx.end()};
|
| 974 |
std::optional<CAmount> modified_fee;
|
| 975 |
if (in_mempool) modified_fee = iter->GetModifiedFee();
|
| 976 |
-
result.emplace_back(delta_info{in_mempool, delta, modified_fee, txid});
|
| 977 |
}
|
| 978 |
return result;
|
| 979 |
}
|
|
@@ -1403,13 +1522,15 @@ util::Result<std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>>> CTxMemPool::
|
|
| 1403 |
return std::make_pair(old_chunks, new_chunks);
|
| 1404 |
}
|
| 1405 |
|
| 1406 |
-
CTxMemPool::ChangeSet::TxHandle CTxMemPool::ChangeSet::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)
|
| 1407 |
{
|
| 1408 |
LOCK(m_pool->cs);
|
| 1409 |
Assume(m_to_add.find(tx->GetHash()) == m_to_add.end());
|
| 1410 |
-
auto newit = m_to_add.emplace(tx, fee, time, entry_height, entry_sequence, spends_coinbase, sigops_cost, lp).first;
|
|
|
|
| 1411 |
CAmount delta{0};
|
| 1412 |
-
m_pool->ApplyDelta(tx->GetHash(), delta);
|
|
|
|
| 1413 |
if (delta) m_to_add.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
|
| 1414 |
|
| 1415 |
m_entry_vec.push_back(newit);
|
|
|
|
| 11 |
#include <consensus/consensus.h>
|
| 12 |
#include <consensus/tx_verify.h>
|
| 13 |
#include <consensus/validation.h>
|
| 14 |
+
#include <crypto/ripemd160.h>
|
| 15 |
#include <logging.h>
|
| 16 |
+
#include <policy/coin_age_priority.h>
|
| 17 |
+
#include <policy/fees.h>
|
| 18 |
#include <policy/policy.h>
|
| 19 |
#include <policy/settings.h>
|
| 20 |
#include <random.h>
|
| 21 |
+
#include <scheduler.h>
|
| 22 |
#include <tinyformat.h>
|
| 23 |
+
#include <script/script.h>
|
| 24 |
#include <util/check.h>
|
| 25 |
#include <util/feefrac.h>
|
| 26 |
#include <util/moneystr.h>
|
|
|
|
| 59 |
return true;
|
| 60 |
}
|
| 61 |
|
| 62 |
+
uint160 ScriptHashkey(const CScript& script)
|
| 63 |
+
{
|
| 64 |
+
uint160 hash;
|
| 65 |
+
CRIPEMD160().Write(script.data(), script.size()).Finalize(hash.begin());
|
| 66 |
+
return hash;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap& cachedDescendants,
|
| 70 |
const std::set<uint256>& setExclude, std::set<uint256>& descendants_to_remove)
|
| 71 |
{
|
|
|
|
| 416 |
static CTxMemPool::Options&& Flatten(CTxMemPool::Options&& opts, bilingual_str& error)
|
| 417 |
{
|
| 418 |
opts.check_ratio = std::clamp<int>(opts.check_ratio, 0, 1'000'000);
|
| 419 |
+
int64_t descendant_limit_bytes = maxmempoolMinimumBytes(opts.limits.descendant_size_vbytes);
|
| 420 |
if (opts.max_size_bytes < 0 || opts.max_size_bytes < descendant_limit_bytes) {
|
| 421 |
error = strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0));
|
| 422 |
}
|
|
|
|
| 426 |
CTxMemPool::CTxMemPool(Options opts, bilingual_str& error)
|
| 427 |
: m_opts{Flatten(std::move(opts), error)}
|
| 428 |
{
|
| 429 |
+
Assert(m_opts.scheduler || !m_opts.dust_relay_target);
|
| 430 |
+
m_opts.dust_relay_feerate_floor = m_opts.dust_relay_feerate;
|
| 431 |
+
#ifdef BUILDING_FOR_LIBBITCOINKERNEL
|
| 432 |
+
assert(!m_opts.scheduler);
|
| 433 |
+
#else
|
| 434 |
+
if (m_opts.scheduler) {
|
| 435 |
+
m_opts.scheduler->scheduleEvery([this]{
|
| 436 |
+
UpdateDynamicDustFeerate();
|
| 437 |
+
}, DYNAMIC_DUST_FEERATE_UPDATE_INTERVAL);
|
| 438 |
+
}
|
| 439 |
+
#endif
|
| 440 |
}
|
| 441 |
|
| 442 |
bool CTxMemPool::isSpent(const COutPoint& outpoint) const
|
|
|
|
| 476 |
ancestors = *Assume(changeset->CalculateMemPoolAncestors(tx_entry, Limits::NoLimits()));
|
| 477 |
}
|
| 478 |
// First splice this entry into mapTx.
|
| 479 |
+
#if BOOST_VERSION >= 107400
|
| 480 |
auto node_handle = changeset->m_to_add.extract(tx_entry);
|
| 481 |
auto result = mapTx.insert(std::move(node_handle));
|
| 482 |
|
| 483 |
Assume(result.inserted);
|
| 484 |
txiter it = result.position;
|
| 485 |
+
#else
|
| 486 |
+
// Boost 1.73 didn't support node extraction, so we have to copy
|
| 487 |
+
auto result = mapTx.emplace(CTxMemPoolEntry::ExplicitCopy, *tx_entry);
|
| 488 |
+
changeset->m_to_add.erase(tx_entry);
|
| 489 |
+
|
| 490 |
+
Assume(result.second);
|
| 491 |
+
txiter it = result.first;
|
| 492 |
+
#endif
|
| 493 |
|
| 494 |
// Now update the entry for ancestors/descendants.
|
| 495 |
if (ancestors.has_value()) {
|
|
|
|
| 542 |
txns_randomized.emplace_back(newit->GetSharedTx());
|
| 543 |
newit->idx_randomized = txns_randomized.size() - 1;
|
| 544 |
|
| 545 |
+
for (auto& vSPK : entry.mapSPK) {
|
| 546 |
+
const uint160& SPKKey = vSPK.first;
|
| 547 |
+
const MemPool_SPK_State& claims = vSPK.second;
|
| 548 |
+
if (claims & MSS_CREATED) {
|
| 549 |
+
mapUsedSPK[SPKKey].first = &tx;
|
| 550 |
+
}
|
| 551 |
+
if (claims & MSS_SPENT) {
|
| 552 |
+
mapUsedSPK[SPKKey].second = &tx;
|
| 553 |
+
}
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
TRACEPOINT(mempool, added,
|
| 557 |
entry.GetTx().GetHash().data(),
|
| 558 |
entry.GetTxSize(),
|
|
|
|
| 581 |
std::chrono::duration_cast<std::chrono::duration<std::uint64_t>>(it->GetTime()).count()
|
| 582 |
);
|
| 583 |
|
| 584 |
+
const CTransaction& tx = it->GetTx();
|
| 585 |
for (const CTxIn& txin : it->GetTx().vin)
|
| 586 |
mapNextTx.erase(txin.prevout);
|
| 587 |
|
|
|
|
| 598 |
} else
|
| 599 |
txns_randomized.clear();
|
| 600 |
|
| 601 |
+
for (auto& vSPK : it->mapSPK) {
|
| 602 |
+
const uint160& SPKKey = vSPK.first;
|
| 603 |
+
if (mapUsedSPK[SPKKey].first == &tx) {
|
| 604 |
+
mapUsedSPK[SPKKey].first = NULL;
|
| 605 |
+
}
|
| 606 |
+
if (mapUsedSPK[SPKKey].second == &tx) {
|
| 607 |
+
mapUsedSPK[SPKKey].second = NULL;
|
| 608 |
+
}
|
| 609 |
+
if (!(mapUsedSPK[SPKKey].first || mapUsedSPK[SPKKey].second)) {
|
| 610 |
+
mapUsedSPK.erase(SPKKey);
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
totalTxSize -= it->GetTxSize();
|
| 615 |
m_total_fee -= it->GetFee();
|
| 616 |
cachedInnerUsage -= it->DynamicMemoryUsage();
|
|
|
|
| 726 |
AssertLockHeld(cs);
|
| 727 |
Assume(!m_have_changeset);
|
| 728 |
std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
|
| 729 |
+
if (mapTx.size() || mapNextTx.size() || mapDeltas.size()) {
|
| 730 |
txs_removed_for_block.reserve(vtx.size());
|
| 731 |
for (const auto& tx : vtx)
|
| 732 |
{
|
| 733 |
+
UpdateDependentPriorities(*tx, nBlockHeight, true);
|
| 734 |
txiter it = mapTx.find(tx->GetHash());
|
| 735 |
if (it != mapTx.end()) {
|
| 736 |
setEntries stage;
|
|
|
|
| 741 |
removeConflicts(*tx);
|
| 742 |
ClearPrioritisation(tx->GetHash());
|
| 743 |
}
|
| 744 |
+
}
|
| 745 |
if (m_opts.signals) {
|
| 746 |
m_opts.signals->MempoolTransactionsRemovedForBlock(txs_removed_for_block, nBlockHeight);
|
| 747 |
}
|
|
|
|
| 749 |
blockSinceLastRollingFeeBump = true;
|
| 750 |
}
|
| 751 |
|
| 752 |
+
#ifndef BUILDING_FOR_LIBBITCOINKERNEL
|
| 753 |
+
void CTxMemPool::UpdateDynamicDustFeerate()
|
| 754 |
+
{
|
| 755 |
+
CFeeRate est_feerate{0};
|
| 756 |
+
if (m_opts.dust_relay_target < 0 && m_opts.estimator) {
|
| 757 |
+
static constexpr double target_success_threshold{0.8};
|
| 758 |
+
est_feerate = m_opts.estimator->estimateRawFee(-m_opts.dust_relay_target, target_success_threshold, FeeEstimateHorizon::LONG_HALFLIFE, nullptr);
|
| 759 |
+
} else if (m_opts.dust_relay_target > 0) {
|
| 760 |
+
auto bytes_remaining = int64_t{m_opts.dust_relay_target} * 1'000;
|
| 761 |
+
LOCK(cs);
|
| 762 |
+
for (auto mi = mapTx.get<ancestor_score>().begin(); mi != mapTx.get<ancestor_score>().end(); ++mi) {
|
| 763 |
+
bytes_remaining -= mi->GetTxSize();
|
| 764 |
+
if (bytes_remaining <= 0) {
|
| 765 |
+
est_feerate = CFeeRate(mi->GetFee(), mi->GetTxSize());
|
| 766 |
+
break;
|
| 767 |
+
}
|
| 768 |
+
}
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
est_feerate = (est_feerate * m_opts.dust_relay_multiplier) / 1'000;
|
| 772 |
+
|
| 773 |
+
if (est_feerate < m_opts.dust_relay_feerate_floor) {
|
| 774 |
+
est_feerate = m_opts.dust_relay_feerate_floor;
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
if (m_opts.dust_relay_feerate != est_feerate) {
|
| 778 |
+
LogDebug(BCLog::MEMPOOL, "Updating dust feerate to %s\n", est_feerate.ToString(FeeEstimateMode::SAT_VB));
|
| 779 |
+
m_opts.dust_relay_feerate = est_feerate;
|
| 780 |
+
}
|
| 781 |
+
}
|
| 782 |
+
#endif
|
| 783 |
+
|
| 784 |
void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const
|
| 785 |
{
|
| 786 |
if (m_opts.check_ratio == 0) return;
|
|
|
|
| 800 |
|
| 801 |
for (const auto& it : GetSortedDepthAndScore()) {
|
| 802 |
checkTotal += it->GetTxSize();
|
| 803 |
+
const auto fresh_coin_age = GetCoinAge(it->GetTx(), active_coins_tip, spendheight);
|
| 804 |
+
const auto fresh_mod_vsize = CalculateModifiedSize(it->GetTx(), it->GetTxSize());
|
| 805 |
+
const double freshPriority = ComputePriority2(fresh_coin_age.inputs_coin_age, fresh_mod_vsize);
|
| 806 |
+
double cachePriority = it->GetPriority(spendheight);
|
| 807 |
+
double priDiff = cachePriority > freshPriority ? cachePriority - freshPriority : freshPriority - cachePriority;
|
| 808 |
+
// Verify that the difference between the on the fly calculation and a fresh calculation
|
| 809 |
+
// is small enough to be a result of double imprecision.
|
| 810 |
+
assert(priDiff < .0001 * freshPriority + 1);
|
| 811 |
check_total_fee += it->GetFee();
|
| 812 |
innerUsage += it->DynamicMemoryUsage();
|
| 813 |
const CTransaction& tx = it->GetTx();
|
|
|
|
| 944 |
return iters;
|
| 945 |
}
|
| 946 |
|
| 947 |
+
void CTxMemPool::FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results) {
|
| 948 |
+
LOCK(cs);
|
| 949 |
+
for (const CTxMemPoolEntry& entry : mapTx) {
|
| 950 |
+
const CTransaction& tx = entry.GetTx();
|
| 951 |
+
const Txid& hash = tx.GetHash();
|
| 952 |
+
for (size_t txo_index = tx.vout.size(); txo_index > 0; ) {
|
| 953 |
+
--txo_index;
|
| 954 |
+
const CTxOut& txo = tx.vout[txo_index];
|
| 955 |
+
if (needles.count(txo.scriptPubKey)) {
|
| 956 |
+
out_results.emplace(COutPoint(hash, txo_index), Coin(txo, MEMPOOL_HEIGHT, false));
|
| 957 |
+
}
|
| 958 |
+
}
|
| 959 |
+
}
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
|
| 963 |
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
|
| 964 |
}
|
|
|
|
| 1025 |
}
|
| 1026 |
}
|
| 1027 |
|
| 1028 |
+
void CTxMemPool::PrioritiseTransaction(const uint256& hash, double dPriorityDelta, const CAmount& nFeeDelta)
|
| 1029 |
{
|
| 1030 |
{
|
| 1031 |
LOCK(cs);
|
| 1032 |
+
std::pair<double, CAmount> &deltas = mapDeltas[hash];
|
| 1033 |
+
deltas.first += dPriorityDelta;
|
| 1034 |
+
deltas.second = SaturatingAdd(deltas.second, nFeeDelta);
|
| 1035 |
txiter it = mapTx.find(hash);
|
| 1036 |
if (it != mapTx.end()) {
|
| 1037 |
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
|
| 1038 |
+
|
| 1039 |
// Now update all ancestors' modified fees with descendants
|
| 1040 |
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, *it, Limits::NoLimits(), /*fSearchForParents=*/false)};
|
| 1041 |
for (txiter ancestorIt : ancestors) {
|
|
|
|
| 1050 |
}
|
| 1051 |
++nTransactionsUpdated;
|
| 1052 |
}
|
| 1053 |
+
if (deltas.first == 0. && deltas.second == 0) {
|
| 1054 |
mapDeltas.erase(hash);
|
| 1055 |
LogPrintf("PrioritiseTransaction: %s (%sin mempool) delta cleared\n", hash.ToString(), it == mapTx.end() ? "not " : "");
|
| 1056 |
} else {
|
| 1057 |
+
LogPrintf("PrioritiseTransaction: %s (%sin mempool) priority += %f, fee += %s, new delta=%s\n",
|
| 1058 |
hash.ToString(),
|
| 1059 |
it == mapTx.end() ? "not " : "",
|
| 1060 |
+
dPriorityDelta,
|
| 1061 |
FormatMoney(nFeeDelta),
|
| 1062 |
+
FormatMoney(deltas.second));
|
| 1063 |
}
|
| 1064 |
}
|
| 1065 |
}
|
| 1066 |
|
| 1067 |
+
void CTxMemPool::ApplyDeltas(const uint256& hash, double &dPriorityDelta, CAmount &nFeeDelta) const
|
| 1068 |
{
|
| 1069 |
AssertLockHeld(cs);
|
| 1070 |
+
std::map<uint256, std::pair<double, CAmount> >::const_iterator pos = mapDeltas.find(hash);
|
| 1071 |
if (pos == mapDeltas.end())
|
| 1072 |
return;
|
| 1073 |
+
const std::pair<double, CAmount> &deltas = pos->second;
|
| 1074 |
+
dPriorityDelta += deltas.first;
|
| 1075 |
+
nFeeDelta += deltas.second;
|
| 1076 |
}
|
| 1077 |
|
| 1078 |
void CTxMemPool::ClearPrioritisation(const uint256& hash)
|
|
|
|
| 1092 |
const bool in_mempool{iter != mapTx.end()};
|
| 1093 |
std::optional<CAmount> modified_fee;
|
| 1094 |
if (in_mempool) modified_fee = iter->GetModifiedFee();
|
| 1095 |
+
result.emplace_back(delta_info{in_mempool, delta.second, delta.first, modified_fee, txid});
|
| 1096 |
}
|
| 1097 |
return result;
|
| 1098 |
}
|
|
|
|
| 1522 |
return std::make_pair(old_chunks, new_chunks);
|
| 1523 |
}
|
| 1524 |
|
| 1525 |
+
CTxMemPool::ChangeSet::TxHandle CTxMemPool::ChangeSet::StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, const CoinAgeCache coin_age_cache, bool spends_coinbase, int32_t extra_weight, int64_t sigops_cost, LockPoints lp)
|
| 1526 |
{
|
| 1527 |
LOCK(m_pool->cs);
|
| 1528 |
Assume(m_to_add.find(tx->GetHash()) == m_to_add.end());
|
| 1529 |
+
auto newit = m_to_add.emplace(tx, fee, time, entry_height, entry_sequence, coin_age_cache, spends_coinbase, /*extra_weight=*/ extra_weight, /*sigops_cost=*/ sigops_cost, lp).first;
|
| 1530 |
+
double priority_delta{0.};
|
| 1531 |
CAmount delta{0};
|
| 1532 |
+
m_pool->ApplyDeltas(tx->GetHash(), priority_delta, delta);
|
| 1533 |
+
// NOTE: priority_delta is handled in addPriorityTxs
|
| 1534 |
if (delta) m_to_add.modify(newit, [&delta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(delta); });
|
| 1535 |
|
| 1536 |
m_entry_vec.push_back(newit);
|