Skip to content

Commit fad00fb

Browse files
committed
Remove priority index.
1 parent 55bb08e commit fad00fb

File tree

4 files changed

+17
-77
lines changed

4 files changed

+17
-77
lines changed

src/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,8 +2024,6 @@ bool static DisconnectTip(CValidationState &state) {
20242024
mempool.check(pcoinsTip);
20252025
// Update chainActive and related variables.
20262026
UpdateTip(pindexDelete->pprev);
2027-
// Recalculate priorities of mempool transactions
2028-
mempool.recalcPriorities(pindexDelete->nHeight);
20292027
// Let wallets know transactions went from 1-confirmed to
20302028
// 0-confirmed or conflicted:
20312029
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
@@ -2087,8 +2085,6 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
20872085
mempool.check(pcoinsTip);
20882086
// Update chainActive & related variables.
20892087
UpdateTip(pindexNew);
2090-
// Recalculate priorities of mempool transactions
2091-
mempool.recalcPriorities(pindexNew->nHeight+1);
20922088
// Tell wallet about transactions that went from mempool
20932089
// to conflicted:
20942090
BOOST_FOREACH(const CTransaction &tx, txConflicted) {

src/test/mempool_tests.cpp

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,63 +105,52 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
105105
{
106106
CTxMemPool pool(CFeeRate(0));
107107

108-
/* 3rd highest fee, 2nd highest priority */
108+
/* 3rd highest fee */
109109
CMutableTransaction tx1 = CMutableTransaction();
110110
tx1.vout.resize(1);
111111
tx1.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
112112
tx1.vout[0].nValue = 10 * COIN;
113113
pool.addUnchecked(tx1.GetHash(), CTxMemPoolEntry(tx1, 10000LL, 0, 10.0, 1, true));
114114

115-
/* highest fee, 3rd highest priority */
115+
/* highest fee */
116116
CMutableTransaction tx2 = CMutableTransaction();
117117
tx2.vout.resize(1);
118118
tx2.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
119119
tx2.vout[0].nValue = 2 * COIN;
120120
pool.addUnchecked(tx2.GetHash(), CTxMemPoolEntry(tx2, 20000LL, 0, 9.0, 1, true));
121121

122-
/* lowest fee, highest priority */
122+
/* lowest fee */
123123
CMutableTransaction tx3 = CMutableTransaction();
124124
tx3.vout.resize(1);
125125
tx3.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
126126
tx3.vout[0].nValue = 5 * COIN;
127127
pool.addUnchecked(tx3.GetHash(), CTxMemPoolEntry(tx3, 0LL, 0, 100.0, 1, true));
128128

129-
/* 2nd highest fee, lowest priority */
129+
/* 2nd highest fee */
130130
CMutableTransaction tx4 = CMutableTransaction();
131131
tx4.vout.resize(1);
132132
tx4.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
133133
tx4.vout[0].nValue = 6 * COIN;
134134
pool.addUnchecked(tx4.GetHash(), CTxMemPoolEntry(tx4, 15000LL, 0, 1.0, 1, true));
135135

136+
/* equal fee rate to tx1, but newer */
137+
CMutableTransaction tx5 = CMutableTransaction();
138+
tx5.vout.resize(1);
139+
tx5.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
140+
tx5.vout[0].nValue = 11 * COIN;
141+
pool.addUnchecked(tx5.GetHash(), CTxMemPoolEntry(tx5, 10000LL, 1, 10.0, 1, true));
142+
136143
// there should be 4 transactions in the mempool
137-
BOOST_CHECK_EQUAL(pool.size(), 4);
144+
BOOST_CHECK_EQUAL(pool.size(), 5);
138145

139-
// Check the fee-rate index is in order, should be tx2, tx4, tx1, tx3
146+
// Check the fee-rate index is in order, should be tx2, tx4, tx1, tx5, tx3
140147
CTxMemPool::indexed_transaction_set::nth_index<1>::type::iterator it = pool.mapTx.get<1>().begin();
141148
BOOST_CHECK_EQUAL(it++->GetTx().GetHash().ToString(), tx2.GetHash().ToString());
142149
BOOST_CHECK_EQUAL(it++->GetTx().GetHash().ToString(), tx4.GetHash().ToString());
143150
BOOST_CHECK_EQUAL(it++->GetTx().GetHash().ToString(), tx1.GetHash().ToString());
151+
BOOST_CHECK_EQUAL(it++->GetTx().GetHash().ToString(), tx5.GetHash().ToString());
144152
BOOST_CHECK_EQUAL(it++->GetTx().GetHash().ToString(), tx3.GetHash().ToString());
145153
BOOST_CHECK(it == pool.mapTx.get<1>().end());
146-
147-
// Check the priority index is in order, should be tx3, tx1, tx2, tx4
148-
CTxMemPool::indexed_transaction_set::nth_index<2>::type::iterator it2 = pool.mapTx.get<2>().begin();
149-
BOOST_CHECK_EQUAL(it2++->GetTx().GetHash().ToString(), tx3.GetHash().ToString());
150-
BOOST_CHECK_EQUAL(it2++->GetTx().GetHash().ToString(), tx1.GetHash().ToString());
151-
BOOST_CHECK_EQUAL(it2++->GetTx().GetHash().ToString(), tx2.GetHash().ToString());
152-
BOOST_CHECK_EQUAL(it2++->GetTx().GetHash().ToString(), tx4.GetHash().ToString());
153-
BOOST_CHECK(it2 == pool.mapTx.get<2>().end());
154-
155-
// Now advance the height of the mempool by 1 block
156-
pool.recalcPriorities(2);
157-
158-
// Check the priority index has been adjusted. Should be tx1, tx4, tx3, tx2
159-
CTxMemPool::indexed_transaction_set::nth_index<2>::type::iterator it3 = pool.mapTx.get<2>().begin();
160-
BOOST_CHECK_EQUAL(it3++->GetTx().GetHash().ToString(), tx1.GetHash().ToString());
161-
BOOST_CHECK_EQUAL(it3++->GetTx().GetHash().ToString(), tx4.GetHash().ToString());
162-
BOOST_CHECK_EQUAL(it3++->GetTx().GetHash().ToString(), tx3.GetHash().ToString());
163-
BOOST_CHECK_EQUAL(it3++->GetTx().GetHash().ToString(), tx2.GetHash().ToString());
164-
BOOST_CHECK(it3 == pool.mapTx.get<2>().end());
165154
}
166155

167156
BOOST_AUTO_TEST_SUITE_END()

src/txmempool.cpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
using namespace std;
1919

2020
CTxMemPoolEntry::CTxMemPoolEntry():
21-
nFee(0), nTxSize(0), nModSize(0), nTime(0), dPriority(0.0),
22-
dCurrentPriority(0.0), hadNoDependencies(false)
21+
nFee(0), nTxSize(0), nModSize(0), nTime(0), dPriority(0.0), hadNoDependencies(false)
2322
{
2423
nHeight = MEMPOOL_HEIGHT;
2524
}
2625

2726
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
2827
int64_t _nTime, double _dPriority,
2928
unsigned int _nHeight, bool poolHasNoInputsOf):
30-
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority),
31-
dCurrentPriority(_dPriority), nHeight(_nHeight),
29+
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight),
3230
hadNoDependencies(poolHasNoInputsOf)
3331
{
3432
nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
@@ -110,29 +108,6 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
110108
}
111109

112110

113-
struct update_priority
114-
{
115-
update_priority (unsigned int h) : height(h) {}
116-
117-
void operator() (CTxMemPoolEntry &e)
118-
{
119-
e.recalcCurrentPriority(height);
120-
}
121-
private:
122-
unsigned int height;
123-
};
124-
125-
void CTxMemPool::recalcPriorities(unsigned int nBlockHeight)
126-
{
127-
LOCK(cs);
128-
for (indexed_transaction_set::nth_index<0>::type::iterator it = mapTx.begin();
129-
it != mapTx.end(); it++)
130-
{
131-
mapTx.modify(it, update_priority(nBlockHeight));
132-
}
133-
}
134-
135-
136111
void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive)
137112
{
138113
// Remove transaction from memory pool

src/txmempool.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class CTxMemPoolEntry
4545
CFeeRate feeRate; //! ... and fee per kB
4646
int64_t nTime; //! Local time when entering the mempool
4747
double dPriority; //! Priority when entering the mempool
48-
double dCurrentPriority; //! Priority at next block height
4948
unsigned int nHeight; //! Chain height when entering the mempool
5049
bool hadNoDependencies; //! Not dependent on any other txs when it entered the mempool
5150

@@ -57,14 +56,12 @@ class CTxMemPoolEntry
5756

5857
const CTransaction& GetTx() const { return this->tx; }
5958
double GetPriority(unsigned int currentHeight) const;
60-
double GetCurrentPriority() const { return dCurrentPriority; }
6159
CAmount GetFee() const { return nFee; }
6260
CFeeRate GetFeeRate() const { return feeRate; }
6361
size_t GetTxSize() const { return nTxSize; }
6462
int64_t GetTime() const { return nTime; }
6563
unsigned int GetHeight() const { return nHeight; }
6664
bool WasClearAtEntry() const { return hadNoDependencies; }
67-
void recalcCurrentPriority (unsigned int height) { dCurrentPriority = GetPriority(height); }
6865
};
6966

7067
// extracts a TxMemPoolEntry's transaction hash
@@ -77,24 +74,13 @@ struct mempoolentry_txid
7774
}
7875
};
7976

80-
class CompareTxMemPoolEntryByPriority
81-
{
82-
public:
83-
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b)
84-
{
85-
if (a.GetCurrentPriority() == b.GetCurrentPriority())
86-
return a.GetFeeRate() > b.GetFeeRate();
87-
return a.GetCurrentPriority() > b.GetCurrentPriority();
88-
}
89-
};
90-
9177
class CompareTxMemPoolEntryByFee
9278
{
9379
public:
9480
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b)
9581
{
9682
if (a.GetFeeRate() == b.GetFeeRate())
97-
return a.GetCurrentPriority() > b.GetCurrentPriority();
83+
return a.GetTime() < b.GetTime();
9884
return a.GetFeeRate() > b.GetFeeRate();
9985
}
10086
};
@@ -143,11 +129,6 @@ class CTxMemPool
143129
boost::multi_index::ordered_non_unique<
144130
boost::multi_index::identity<CTxMemPoolEntry>,
145131
CompareTxMemPoolEntryByFee
146-
>,
147-
// sorted by priority
148-
boost::multi_index::ordered_non_unique<
149-
boost::multi_index::identity<CTxMemPoolEntry>,
150-
CompareTxMemPoolEntryByPriority
151132
>
152133
>
153134
> indexed_transaction_set;
@@ -178,7 +159,6 @@ class CTxMemPool
178159
void clear();
179160
void queryHashes(std::vector<uint256>& vtxid);
180161
void pruneSpent(const uint256& hash, CCoins &coins);
181-
void recalcPriorities(unsigned int nBlockHeight);
182162
unsigned int GetTransactionsUpdated() const;
183163
void AddTransactionsUpdated(unsigned int n);
184164
/**

0 commit comments

Comments
 (0)