Skip to content

Commit 84f7ab0

Browse files
committed
Remove member variable hadNoDependencies from CTxMemPoolEntry
Fee estimation can just check its own mapMemPoolTxs to determine the same information. Note that now fee estimation for block processing must happen before those transactions are removed, but this shoudl be a speedup.
1 parent 60ac00d commit 84f7ab0

File tree

9 files changed

+19
-32
lines changed

9 files changed

+19
-32
lines changed

src/bench/mempool_eviction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void AddTx(const CTransaction& tx, const CAmount& nFee, CTxMemPool& pool)
1818
unsigned int sigOpCost = 4;
1919
LockPoints lp;
2020
pool.addUnchecked(tx.GetHash(), CTxMemPoolEntry(
21-
MakeTransactionRef(tx), nFee, nTime, dPriority, nHeight, pool.HasNoInputsOf(tx),
21+
MakeTransactionRef(tx), nFee, nTime, dPriority, nHeight,
2222
tx.GetValueOut(), spendsCoinbase, sigOpCost, lp));
2323
}
2424

src/policy/fees.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,6 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
327327
if (!fCurrentEstimate)
328328
return;
329329

330-
if (!entry.WasClearAtEntry()) {
331-
// This transaction depends on other transactions in the mempool to
332-
// be included in a block before it will be able to be included, so
333-
// we shouldn't include it in our calculations
334-
return;
335-
}
336-
337330
// Feerates are stored and reported as BTC-per-kb:
338331
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
339332

@@ -343,10 +336,8 @@ void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, boo
343336

344337
void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry)
345338
{
346-
if (!entry.WasClearAtEntry()) {
347-
// This transaction depended on other transactions in the mempool to
348-
// be included in a block before it was able to be included, so
349-
// we shouldn't include it in our calculations
339+
if (!removeTx(entry.GetTx().GetHash())) {
340+
// This transaction wasn't being tracked for fee estimation
350341
return;
351342
}
352343

@@ -378,14 +369,18 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
378369
// transaction fees."
379370
return;
380371
}
381-
nBestSeenHeight = nBlockHeight;
382372

383373
// Only want to be updating estimates when our blockchain is synced,
384374
// otherwise we'll miscalculate how many blocks its taking to get included.
385375
if (!fCurrentEstimate)
386376
return;
387377

388-
// Clear the current block state
378+
// Must update nBestSeenHeight in sync with ClearCurrent so that
379+
// calls to removeTx (via processBlockTx) correctly calculate age
380+
// of unconfirmed txs to remove from tracking.
381+
nBestSeenHeight = nBlockHeight;
382+
383+
// Clear the current block state and update unconfirmed circular buffer
389384
feeStats.ClearCurrent(nBlockHeight);
390385

391386
// Repopulate the current block states

src/test/mempool_tests.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
120120
{
121121
CTxMemPool pool(CFeeRate(0));
122122
TestMemPoolEntryHelper entry;
123-
entry.hadNoDependencies = true;
124123

125124
/* 3rd highest fee */
126125
CMutableTransaction tx1 = CMutableTransaction();
@@ -323,7 +322,6 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
323322
{
324323
CTxMemPool pool(CFeeRate(0));
325324
TestMemPoolEntryHelper entry;
326-
entry.hadNoDependencies = true;
327325

328326
/* 3rd highest fee */
329327
CMutableTransaction tx1 = CMutableTransaction();

src/test/test_bitcoin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,11 @@ CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx, CT
147147
}
148148

149149
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransaction &txn, CTxMemPool *pool) {
150-
bool hasNoDependencies = pool ? pool->HasNoInputsOf(txn) : hadNoDependencies;
151150
// Hack to assume either its completely dependent on other mempool txs or not at all
152-
CAmount inChainValue = hasNoDependencies ? txn.GetValueOut() : 0;
151+
CAmount inChainValue = pool && pool->HasNoInputsOf(txn) ? txn.GetValueOut() : 0;
153152

154153
return CTxMemPoolEntry(MakeTransactionRef(txn), nFee, nTime, dPriority, nHeight,
155-
hasNoDependencies, inChainValue, spendsCoinbase, sigOpCost, lp);
154+
inChainValue, spendsCoinbase, sigOpCost, lp);
156155
}
157156

158157
void Shutdown(void* parg)

src/test/test_bitcoin.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ struct TestMemPoolEntryHelper
7070
int64_t nTime;
7171
double dPriority;
7272
unsigned int nHeight;
73-
bool hadNoDependencies;
7473
bool spendsCoinbase;
7574
unsigned int sigOpCost;
7675
LockPoints lp;
7776

7877
TestMemPoolEntryHelper() :
7978
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
80-
hadNoDependencies(false), spendsCoinbase(false), sigOpCost(4) { }
79+
spendsCoinbase(false), sigOpCost(4) { }
8180

8281
CTxMemPoolEntry FromTx(const CMutableTransaction &tx, CTxMemPool *pool = NULL);
8382
CTxMemPoolEntry FromTx(const CTransaction &tx, CTxMemPool *pool = NULL);
@@ -87,7 +86,6 @@ struct TestMemPoolEntryHelper
8786
TestMemPoolEntryHelper &Time(int64_t _time) { nTime = _time; return *this; }
8887
TestMemPoolEntryHelper &Priority(double _priority) { dPriority = _priority; return *this; }
8988
TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
90-
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
9189
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
9290
TestMemPoolEntryHelper &SigOpsCost(unsigned int _sigopsCost) { sigOpCost = _sigopsCost; return *this; }
9391
};

src/txmempool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ using namespace std;
2222

2323
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
2424
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
25-
bool poolHasNoInputsOf, CAmount _inChainInputValue,
25+
CAmount _inChainInputValue,
2626
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp):
2727
tx(_tx), nFee(_nFee), nTime(_nTime), entryPriority(_entryPriority), entryHeight(_entryHeight),
28-
hadNoDependencies(poolHasNoInputsOf), inChainInputValue(_inChainInputValue),
28+
inChainInputValue(_inChainInputValue),
2929
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
3030
{
3131
nTxWeight = GetTransactionWeight(*tx);
@@ -604,6 +604,8 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
604604
if (i != mapTx.end())
605605
entries.push_back(*i);
606606
}
607+
// Before the txs in the new block have been removed from the mempool, update policy estimates
608+
minerPolicyEstimator->processBlock(nBlockHeight, entries, fCurrentEstimate);
607609
for (const auto& tx : vtx)
608610
{
609611
txiter it = mapTx.find(tx->GetHash());
@@ -615,8 +617,6 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
615617
removeConflicts(*tx);
616618
ClearPrioritisation(tx->GetHash());
617619
}
618-
// After the txs in the new block have been removed from the mempool, update policy estimates
619-
minerPolicyEstimator->processBlock(nBlockHeight, entries, fCurrentEstimate);
620620
lastRollingFeeUpdate = GetTime();
621621
blockSinceLastRollingFeeBump = true;
622622
}

src/txmempool.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class CTxMemPoolEntry
8888
int64_t nTime; //!< Local time when entering the mempool
8989
double entryPriority; //!< Priority when entering the mempool
9090
unsigned int entryHeight; //!< Chain height when entering the mempool
91-
bool hadNoDependencies; //!< Not dependent on any other txs when it entered the mempool
9291
CAmount inChainInputValue; //!< Sum of all txin values that are already in blockchain
9392
bool spendsCoinbase; //!< keep track of transactions that spend a coinbase
9493
int64_t sigOpCost; //!< Total sigop cost
@@ -113,7 +112,7 @@ class CTxMemPoolEntry
113112
public:
114113
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
115114
int64_t _nTime, double _entryPriority, unsigned int _entryHeight,
116-
bool poolHasNoInputsOf, CAmount _inChainInputValue, bool spendsCoinbase,
115+
CAmount _inChainInputValue, bool spendsCoinbase,
117116
int64_t nSigOpsCost, LockPoints lp);
118117

119118
CTxMemPoolEntry(const CTxMemPoolEntry& other);
@@ -130,7 +129,6 @@ class CTxMemPoolEntry
130129
size_t GetTxWeight() const { return nTxWeight; }
131130
int64_t GetTime() const { return nTime; }
132131
unsigned int GetHeight() const { return entryHeight; }
133-
bool WasClearAtEntry() const { return hadNoDependencies; }
134132
int64_t GetSigOpCost() const { return sigOpCost; }
135133
int64_t GetModifiedFee() const { return nFee + feeDelta; }
136134
size_t DynamicMemoryUsage() const { return nUsageSize; }

src/validation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
693693
}
694694

695695
CTxMemPoolEntry entry(ptx, nFees, nAcceptTime, dPriority, chainActive.Height(),
696-
!IsInitialBlockDownload() && pool.HasNoInputsOf(tx),
697696
inChainInputValue, fSpendsCoinbase, nSigOpsCost, lp);
698697
unsigned int nSize = entry.GetTxSize();
699698

@@ -943,7 +942,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
943942
pool.RemoveStaged(allConflicting, false);
944943

945944
// Store transaction in memory
946-
pool.addUnchecked(hash, entry, setAncestors, !IsInitialBlockDownload());
945+
pool.addUnchecked(hash, entry, setAncestors, !IsInitialBlockDownload() && pool.HasNoInputsOf(tx));
947946

948947
// trim mempool and check if tx was trimmed
949948
if (!fOverrideMempoolLimit) {

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
25632563
if (GetBoolArg("-walletrejectlongchains", DEFAULT_WALLET_REJECT_LONG_CHAINS)) {
25642564
// Lastly, ensure this tx will pass the mempool's chain limits
25652565
LockPoints lp;
2566-
CTxMemPoolEntry entry(wtxNew.tx, 0, 0, 0, 0, false, 0, false, 0, lp);
2566+
CTxMemPoolEntry entry(wtxNew.tx, 0, 0, 0, 0, 0, false, 0, lp);
25672567
CTxMemPool::setEntries setAncestors;
25682568
size_t nLimitAncestors = GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT);
25692569
size_t nLimitAncestorSize = GetArg("-limitancestorsize", DEFAULT_ANCESTOR_SIZE_LIMIT)*1000;

0 commit comments

Comments
 (0)