Skip to content

Commit 359e8a0

Browse files
committed
[cleanup] Remove coin age priority completely.
Remove GetPriority and ComputePriority. Remove internal machinery for tracking priority in CTxMemPoolEntry.
1 parent f9b9371 commit 359e8a0

File tree

11 files changed

+11
-97
lines changed

11 files changed

+11
-97
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
1313
{
1414
int64_t nTime = 0;
15-
double dPriority = 10.0;
1615
unsigned int nHeight = 1;
1716
bool spendsCoinbase = false;
1817
unsigned int sigOpCost = 4;
1918
LockPoints lp;
2019
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
21-
MakeTransactionRef(tx), nFee, nTime, dPriority, nHeight,
22-
tx.GetValueOut(), spendsCoinbase, sigOpCost, lp));
20+
MakeTransactionRef(tx), nFee, nTime, nHeight,
21+
spendsCoinbase, sigOpCost, lp));
2322
}
2423

2524
// Right now this is only testing eviction performance in an extremely small

src/coins.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,6 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const
295295
return true;
296296
}
297297

298-
double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const
299-
{
300-
inChainInputValue = 0;
301-
if (tx.IsCoinBase())
302-
return 0.0;
303-
double dResult = 0.0;
304-
BOOST_FOREACH(const CTxIn& txin, tx.vin)
305-
{
306-
const CCoins* coins = AccessCoins(txin.prevout.hash);
307-
assert(coins);
308-
if (!coins->IsAvailable(txin.prevout.n)) continue;
309-
if (coins->nHeight <= nHeight) {
310-
dResult += (double)(coins->vout[txin.prevout.n].nValue) * (nHeight-coins->nHeight);
311-
inChainInputValue += coins->vout[txin.prevout.n].nValue;
312-
}
313-
}
314-
return tx.ComputePriority(dResult);
315-
}
316-
317298
CCoinsModifier::CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_, size_t usage) : cache(cache_), it(it_), cachedCoinUsage(usage) {
318299
assert(!cache.hasModifier);
319300
cache.hasModifier = true;

src/coins.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,6 @@ class CCoinsViewCache : public CCoinsViewBacked
460460
//! Check whether all prevouts of the transaction are present in the UTXO set represented by this view
461461
bool HaveInputs(const CTransaction& tx) const;
462462

463-
/**
464-
* Return priority of tx at height nHeight. Also calculate the sum of the values of the inputs
465-
* that are already in the chain. These are the inputs that will age and increase priority as
466-
* new blocks are added to the chain.
467-
*/
468-
double GetPriority(const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const;
469-
470463
const CTxOut &GetOutputFor(const CTxIn& input) const;
471464

472465
friend class CCoinsModifier;

src/primitives/transaction.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,6 @@ CAmount CTransaction::GetValueOut() const
8989
return nValueOut;
9090
}
9191

92-
double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const
93-
{
94-
nTxSize = CalculateModifiedSize(nTxSize);
95-
if (nTxSize == 0) return 0.0;
96-
97-
return dPriorityInputs / nTxSize;
98-
}
99-
100-
unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
101-
{
102-
// In order to avoid disincentivizing cleaning up the UTXO set we don't count
103-
// the constant overhead for each txin and up to 110 bytes of scriptSig (which
104-
// is enough to cover a compressed pubkey p2sh redemption) for priority.
105-
// Providing any more cleanup incentive than making additional inputs free would
106-
// risk encouraging people to create junk outputs to redeem later.
107-
if (nTxSize == 0)
108-
nTxSize = (GetTransactionWeight(*this) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
109-
for (std::vector<CTxIn>::const_iterator it(vin.begin()); it != vin.end(); ++it)
110-
{
111-
unsigned int offset = 41U + std::min(110U, (unsigned int)it->scriptSig.size());
112-
if (nTxSize > offset)
113-
nTxSize -= offset;
114-
}
115-
return nTxSize;
116-
}
117-
11892
unsigned int CTransaction::GetTotalSize() const
11993
{
12094
return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);

src/primitives/transaction.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,6 @@ class CTransaction
361361
// GetValueIn() is a method on CCoinsViewCache, because
362362
// inputs must be known to compute value in.
363363

364-
// Compute priority, given priority of inputs and (optionally) tx size
365-
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
366-
367-
// Compute modified tx size for priority calculation (optionally given tx size)
368-
unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
369-
370364
/**
371365
* Get the total transaction size in bytes, including witness data.
372366
* "Total Size" defined in BIP141 and BIP144.

src/test/mempool_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
407407
/* set the fee to just below tx2's feerate when including ancestor */
408408
CAmount fee = (20000/tx2Size)*(tx7Size + tx6Size) - 1;
409409

410-
//CTxMemPoolEntry entry7(tx7, fee, 2, 10.0, 1, true);
411410
pool.addUnchecked(tx7.GetHash(), entry.Fee(fee).FromTx(tx7));
412411
BOOST_CHECK_EQUAL(pool.size(), 7);
413412
sortedOrder.insert(sortedOrder.begin()+1, tx7.GetHash().ToString());

src/test/test_bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) {
147147
}
148148

149149
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransaction &txn) {
150-
return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, 0.0, nHeight,
151-
0, spendsCoinbase, sigOpCost, lp);
150+
return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, nHeight,
151+
spendsCoinbase, sigOpCost, lp);
152152
}
153153

154154
void Shutdown(void* parg)

src/txmempool.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@
1919
#include "version.h"
2020

2121
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
22-
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
23-
CAmount _inChainInputValue,
22+
int64_t _nTime, unsigned int _entryHeight,
2423
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
25-
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
26-
inChainInputValue(_inChainInputValue),
24+
tx(_tx), nFee(_nFee), nTime(_nTime), entryHeight(_entryHeight),
2725
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
2826
{
2927
nTxWeight = GetTransactionWeight(*tx);
30-
nModSize = tx->CalculateModifiedSize(GetTxSize());
3128
nUsageSize = RecursiveDynamicUsage(*tx) + memusage::DynamicUsage(tx);
3229

3330
nCountWithDescendants = 1;
3431
nSizeWithDescendants = GetTxSize();
3532
nModFeesWithDescendants = nFee;
36-
CAmount nValueIn = tx->GetValueOut()+nFee;
37-
assert(inChainInputValue <= nValueIn);
3833

3934
feeDelta = 0;
4035

@@ -49,16 +44,6 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry& other)
4944
*this = other;
5045
}
5146

52-
double
53-
CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
54-
{
55-
double deltaPriority = ((double)(currentHeight-entryHeight)*inChainInputValue)/nModSize;
56-
double dResult = entryPriority + deltaPriority;
57-
if (dResult < 0) // This should only happen if it was called with a height below entry height
58-
dResult = 0;
59-
return dResult;
60-
}
61-
6247
void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
6348
{
6449
nModFeesWithDescendants += newFeeDelta - feeDelta;

src/txmempool.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ class CTxMemPoolEntry
7373
CTransactionRef tx;
7474
CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
7575
size_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
76-
size_t nModSize; //!< ... and modified size for priority
7776
size_t nUsageSize; //!< ... and total memory usage
7877
int64_t nTime; //!< Local time when entering the mempool
79-
double entryPriority; //!< Priority when entering the mempool
8078
unsigned int entryHeight; //!< Chain height when entering the mempool
81-
CAmount inChainInputValue; //!< Sum of all txin values that are already in blockchain
8279
bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
8380
int64_t sigOpCost; //!< Total sigop cost
8481
int64_t feeDelta; //!< Used for determining the priority of the transaction for mining in a block
@@ -101,19 +98,14 @@ class CTxMemPoolEntry
10198

10299
public:
103100
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
104-
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
105-
CAmount _inChainInputValue, bool spendsCoinbase,
101+
int64_t _nTime, unsigned int _entryHeight,
102+
bool spendsCoinbase,
106103
int64_t nSigOpsCost, LockPoints lp);
107104

108105
CTxMemPoolEntry(const CTxMemPoolEntry& other);
109106

110107
const CTransaction& GetTx() const { return *this->tx; }
111108
CTransactionRef GetSharedTx() const { return this->tx; }
112-
/**
113-
* Fast calculation of lower bound of current priority as update
114-
* from entry priority. Only inputs that were originally in-chain will age.
115-
*/
116-
double GetPriority(unsigned int currentHeight) const;
117109
const CAmount& GetFee() const { return nFee; }
118110
size_t GetTxSize() const;
119111
size_t GetTxWeight() const { return nTxWeight; }

src/validation.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,6 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
722722
CAmount nModifiedFees = nFees;
723723
pool.ApplyDelta(hash, nModifiedFees);
724724

725-
CAmount inChainInputValue;
726-
double dPriority = view.GetPriority(tx, chainActive.Height(), inChainInputValue);
727-
728725
// Keep track of transactions that spend a coinbase, which we re-scan
729726
// during reorgs to ensure COINBASE_MATURITY is still met.
730727
bool fSpendsCoinbase = false;
@@ -736,8 +733,8 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
736733
}
737734
}
738735

739-
CTxMemPoolEntry entry(ptx, nFees, nAcceptTime, dPriority, chainActive.Height(),
740-
inChainInputValue, fSpendsCoinbase, nSigOpsCost, lp);
736+
CTxMemPoolEntry entry(ptx, nFees, nAcceptTime, chainActive.Height(),
737+
fSpendsCoinbase, nSigOpsCost, lp);
741738
unsigned int nSize = entry.GetTxSize();
742739

743740
// Check that the transaction doesn't have an excessive number of

0 commit comments

Comments
 (0)