You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fa2b083 [test] Add test to check mempool consistency in case of reorgs (MarcoFalke)
fabeb1f validation: Add missing mempool locks (MarcoFalke)
fa0c9db txpool: Make nTransactionsUpdated atomic (MarcoFalke)
Pull request description:
Take the mempool read lock during reorgs, so that we don't accidentally read an inconsistent mempool.
ACKs for top commit:
laanwj:
code review ACK fa2b083
ryanofsky:
utACK fa2b083 [EDIT: was ~e284e422e75189794e24fe482819d8b1407857c3~, from bad copy and paste]. Changes since last review: rebase after #15976, adding vTxHashes lock annotation, adding new commit dropping mempool lock for nTransactionsUpdated and making it atomic to avoid deadlock between mempool lock and g_best_block_mutex
Tree-SHA512: cfe7777993589087753e000e3736d79d320dca412383fb77b56bef8946a04049722bf888c11b6f722adf677165185c7e58b4a269f7c5fa25e84dda375f6c8a7d
Copy file name to clipboardExpand all lines: src/txmempool.h
+14-22Lines changed: 14 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,13 @@
6
6
#ifndef BITCOIN_TXMEMPOOL_H
7
7
#defineBITCOIN_TXMEMPOOL_H
8
8
9
+
#include<atomic>
10
+
#include<map>
9
11
#include<memory>
10
12
#include<set>
11
-
#include<map>
12
-
#include<vector>
13
-
#include<utility>
14
13
#include<string>
14
+
#include<utility>
15
+
#include<vector>
15
16
16
17
#include<amount.h>
17
18
#include<coins.h>
@@ -443,7 +444,7 @@ class CTxMemPool
443
444
{
444
445
private:
445
446
uint32_t nCheckFrequency GUARDED_BY(cs); //!< Value n means that n times in 2^32 we check.
446
-
unsignedint nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
447
+
std::atomic<unsignedint> nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
447
448
CBlockPolicyEstimator* minerPolicyEstimator;
448
449
449
450
uint64_t totalTxSize; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
@@ -513,21 +514,12 @@ class CTxMemPool
513
514
* `mempool.cs` whenever adding transactions to the mempool and whenever
514
515
* changing the chain tip. It's necessary to keep both mutexes locked until
515
516
* the mempool is consistent with the new chain tip and fully populated.
516
-
*
517
-
* @par Consistency bug
518
-
*
519
-
* The second guarantee above is not currently enforced, but
520
-
* https://github.com/bitcoin/bitcoin/pull/14193 will fix it. No known code
521
-
* in bitcoin currently depends on second guarantee, but it is important to
522
-
* fix for third party code that needs be able to frequently poll the
523
-
* mempool without locking `cs_main` and without encountering missing
524
-
* transactions during reorgs.
525
517
*/
526
518
mutable RecursiveMutex cs;
527
519
indexed_transaction_set mapTx GUARDED_BY(cs);
528
520
529
521
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
530
-
std::vector<std::pair<uint256, txiter>> vTxHashes; //!< All tx witness hashes/entries in mapTx, in random order
522
+
std::vector<std::pair<uint256, txiter>> vTxHashesGUARDED_BY(cs); //!< All tx witness hashes/entries in mapTx, in random order
0 commit comments