mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
[refactor] txmempool: split epoch logic into class
This commit is contained in:
@@ -23,7 +23,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFe
|
||||
int64_t _nTime, unsigned int _entryHeight,
|
||||
bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp)
|
||||
: tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
|
||||
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp), m_epoch(0)
|
||||
spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
|
||||
{
|
||||
nCountWithDescendants = 1;
|
||||
nSizeWithDescendants = GetTxSize();
|
||||
@@ -132,7 +132,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
|
||||
// include them, and update their CTxMemPoolEntry::m_parents to include this tx.
|
||||
// we cache the in-mempool children to avoid duplicate updates
|
||||
{
|
||||
const auto epoch = GetFreshEpoch();
|
||||
WITH_FRESH_EPOCH(m_epoch);
|
||||
for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
|
||||
const uint256 &childHash = iter->second->GetHash();
|
||||
txiter childIter = mapTx.find(childHash);
|
||||
@@ -1117,22 +1117,3 @@ void CTxMemPool::SetIsLoaded(bool loaded)
|
||||
LOCK(cs);
|
||||
m_is_loaded = loaded;
|
||||
}
|
||||
|
||||
|
||||
CTxMemPool::EpochGuard CTxMemPool::GetFreshEpoch() const
|
||||
{
|
||||
return EpochGuard(*this);
|
||||
}
|
||||
CTxMemPool::EpochGuard::EpochGuard(const CTxMemPool& in) : pool(in)
|
||||
{
|
||||
assert(!pool.m_has_epoch_guard);
|
||||
++pool.m_epoch;
|
||||
pool.m_has_epoch_guard = true;
|
||||
}
|
||||
|
||||
CTxMemPool::EpochGuard::~EpochGuard()
|
||||
{
|
||||
// prevents stale results being used
|
||||
++pool.m_epoch;
|
||||
pool.m_has_epoch_guard = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user