mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Merge #19854: Avoid locking CTxMemPool::cs recursively in simple cases
020f0519ec
refactor: CTxMemPool::IsUnbroadcastTx() requires CTxMemPool::cs lock (Hennadii Stepanov)7c4bd0387a
refactor: CTxMemPool::GetTotalTxSize() requires CTxMemPool::cs lock (Hennadii Stepanov)fa5fcb032b
refactor: CTxMemPool::ClearPrioritisation() requires CTxMemPool::cs lock (Hennadii Stepanov)7140b31b90
refactor: CTxMemPool::ApplyDelta() requires CTxMemPool::cs lock (Hennadii Stepanov)66e47e5e50
refactor: CTxMemPool::UpdateChild() requires CTxMemPool::cs lock (Hennadii Stepanov)939807768a
refactor: CTxMemPool::UpdateParent() requires CTxMemPool::cs lock (Hennadii Stepanov) Pull request description: This is another step to transit `CTxMemPool::cs` from `RecursiveMutex` to `Mutex`. Split out from #19306. Only trivial thread safety annotations and lock assertions added. No new locks. No behavior change. Refactoring `const uint256` to `const uint256&` was [requested](https://github.com/bitcoin/bitcoin/pull/19647#discussion_r468471022) by **promag**. Please note that now, since #19668 has been merged, it is safe to apply `AssertLockHeld()` macros as they do not swallow compile time Thread Safety Analysis warnings. ACKs for top commit: promag: Core review ACK020f0519ec
. jnewbery: Code review ACK020f0519ec
vasild: ACK020f0519e
Tree-SHA512: a31e389142d5a19b25fef0aaf1072a337278564528b5cc9209df88ae548a31440e1b8dd9bae0169fd7aa59ea06e22fe5e0413955386512b83ef1f3e7d941e890
This commit is contained in:
commit
99a8eb6051
2 changed files with 16 additions and 13 deletions
|
@ -852,9 +852,9 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
|
|||
LogPrintf("PrioritiseTransaction: %s feerate += %s\n", hash.ToString(), FormatMoney(nFeeDelta));
|
||||
}
|
||||
|
||||
void CTxMemPool::ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const
|
||||
void CTxMemPool::ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const
|
||||
{
|
||||
LOCK(cs);
|
||||
AssertLockHeld(cs);
|
||||
std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
|
||||
if (pos == mapDeltas.end())
|
||||
return;
|
||||
|
@ -862,9 +862,9 @@ void CTxMemPool::ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const
|
|||
nFeeDelta += delta;
|
||||
}
|
||||
|
||||
void CTxMemPool::ClearPrioritisation(const uint256 hash)
|
||||
void CTxMemPool::ClearPrioritisation(const uint256& hash)
|
||||
{
|
||||
LOCK(cs);
|
||||
AssertLockHeld(cs);
|
||||
mapDeltas.erase(hash);
|
||||
}
|
||||
|
||||
|
@ -968,6 +968,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimat
|
|||
|
||||
void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
setEntries s;
|
||||
if (add && mapLinks[entry].children.insert(child).second) {
|
||||
cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
|
||||
|
@ -978,6 +979,7 @@ void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add)
|
|||
|
||||
void CTxMemPool::UpdateParent(txiter entry, txiter parent, bool add)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
setEntries s;
|
||||
if (add && mapLinks[entry].parents.insert(parent).second) {
|
||||
cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
|
||||
|
|
|
@ -568,8 +568,8 @@ private:
|
|||
typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
|
||||
txlinksMap mapLinks;
|
||||
|
||||
void UpdateParent(txiter entry, txiter parent, bool add);
|
||||
void UpdateChild(txiter entry, txiter child, bool add);
|
||||
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
|
@ -626,8 +626,8 @@ public:
|
|||
|
||||
/** Affect CreateNewBlock prioritisation of transactions */
|
||||
void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
|
||||
void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
|
||||
void ClearPrioritisation(const uint256 hash);
|
||||
void ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
/** Get the transaction in the pool that spends the same prevout */
|
||||
const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
@ -710,9 +710,9 @@ public:
|
|||
return mapTx.size();
|
||||
}
|
||||
|
||||
uint64_t GetTotalTxSize() const
|
||||
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||
{
|
||||
LOCK(cs);
|
||||
AssertLockHeld(cs);
|
||||
return totalTxSize;
|
||||
}
|
||||
|
||||
|
@ -757,9 +757,10 @@ public:
|
|||
}
|
||||
|
||||
/** Returns whether a txid is in the unbroadcast set */
|
||||
bool IsUnbroadcastTx(const uint256& txid) const {
|
||||
LOCK(cs);
|
||||
return (m_unbroadcast_txids.count(txid) != 0);
|
||||
bool IsUnbroadcastTx(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
return m_unbroadcast_txids.count(txid) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue