v29.4-roots.3 · Commit 7: [PATCH 07/30] release: establish Roots maintenance and assurance
src/txmempool.cpp
Before: src/txmempool.cpp · After: src/txmempool.cpp
File metadata
index dd76521e4e288b6aa428a29c64f021d9b2ef13fd..46bee48c6a2c6808b119f46326a5cfc9a224b5eb 100644
Download original patch · Release notes
Diff rows 1–49 of 49. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/txmempool.cpp
CHANGED
|
@@ -42,6 +42,49 @@
|
|
|
42
42
|
TRACEPOINT_SEMAPHORE(mempool, added);
|
|
43
43
|
TRACEPOINT_SEMAPHORE(mempool, removed);
|
|
44
44
|
|
|
45
|
+
void CTxMemPoolEntry::UpdateCachedPriority(unsigned int current_height, CAmount value_in_current_block)
|
|
46
|
+
{
|
|
47
|
+
const int height_diff{int(current_height) - int(cachedHeight)};
|
|
48
|
+
cachedPriority += (double(height_diff) * inChainInputValue) / nModSize;
|
|
49
|
+
cachedHeight = current_height;
|
|
50
|
+
inChainInputValue += value_in_current_block;
|
|
51
|
+
assert(MoneyRange(inChainInputValue));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
double CTxMemPoolEntry::GetPriority(unsigned int current_height) const
|
|
55
|
+
{
|
|
56
|
+
// This is accurate when the height range does not cross a block containing
|
|
57
|
+
// one of the transaction's inputs.
|
|
58
|
+
const int height_diff{int(current_height) - int(cachedHeight)};
|
|
59
|
+
const double priority{cachedPriority + (double(height_diff) * inChainInputValue) / nModSize};
|
|
60
|
+
return std::max(priority, 0.0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
namespace {
|
|
64
|
+
struct UpdatePriority {
|
|
65
|
+
unsigned int height;
|
|
66
|
+
CAmount value;
|
|
67
|
+
|
|
68
|
+
void operator()(CTxMemPoolEntry& entry) const
|
|
69
|
+
{
|
|
70
|
+
entry.UpdateCachedPriority(height, value);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
} // namespace
|
|
74
|
+
|
|
75
|
+
void CTxMemPool::UpdateDependentPriorities(const CTransaction& tx, unsigned int block_height, bool add_to_chain)
|
|
76
|
+
{
|
|
77
|
+
LOCK(cs);
|
|
78
|
+
for (unsigned int i{0}; i < tx.vout.size(); ++i) {
|
|
79
|
+
const auto next_tx{mapNextTx.find(COutPoint{tx.GetHash(), i})};
|
|
80
|
+
if (next_tx == mapNextTx.end()) continue;
|
|
81
|
+
|
|
82
|
+
const txiter entry{mapTx.find(next_tx->second->GetHash())};
|
|
83
|
+
const CAmount value{add_to_chain ? tx.vout[i].nValue : -tx.vout[i].nValue};
|
|
84
|
+
mapTx.modify(entry, UpdatePriority{block_height, value});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
45
88
|
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
|
|
46
89
|
{
|
|
47
90
|
AssertLockHeld(cs_main);
|