-
Notifications
You must be signed in to change notification settings - Fork 38.7k
refactor: Avoid locking tx pool cs thrice #13786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note to reviewers: This pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
faf2eca to
fa6b4b5
Compare
|
Tested ACK fa6b4b5. Verified all OP claims.
Line 173 in ef4fac0
Line 26 in ef4fac0
Line 680 in ef4fac0
which already have the annotation. |
fa6b4b5 to
fa5ed4f
Compare
|
Rebased |
|
|
||
|
|
||
| CTxMemPool testPool; | ||
| LOCK(testPool.cs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could move to 65 since removeRecursive locks separately
| { | ||
| CBlockPolicyEstimator feeEst; | ||
| CTxMemPool mpool(&feeEst); | ||
| LOCK(mpool.cs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could move to 55
|
utACK fa5ed4f |
kallewoof
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK fa5ed4f
fa5ed4f refactor: Avoid locking tx pool cs thrice (MarcoFalke) Pull request description: `addUnchecked` is (outside the tests) only called by ATMP, which already takes the tx pool read lock. So locking it twice more in both `addUnchecked` methods seems redundant. Similarly `CalculateMemPoolAncestors` is (beside once in the wallet) only called in contexts, where the tx pool lock is already taken. So remove the lock there as well. Tree-SHA512: fcf603b570da0fc529fe6db8add218663eae52845510732bee0d4611263d2429d3d3c9c8ae68493d67287d13504500ed51905ccbe711eb15a0af3b019edad543
Summary: `addUnchecked` is (outside the tests) only called by ATMP, which already takes the tx pool read lock. So locking it twice more in both `addUnchecked` methods seems redundant. Backport of Bitcoin Core PR13786 bitcoin/bitcoin#13786 Test Plan: 1. Build with Clang in Debug mode: ``` CXX=clang++ CC=clang cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug ninja check ``` 2. Verify that the compiler has not emitted a `thread-safety` warning. 3. Run the node: `./src/bitcoind -regtest` 4. Verify that text similar to `"Assertion failed: lock ... not held ..."` is not printed on `stderr`. Reviewers: Fabien, #bitcoin_abc, deadalnix Reviewed By: Fabien, #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D4186
fa5ed4f refactor: Avoid locking tx pool cs thrice (MarcoFalke) Pull request description: `addUnchecked` is (outside the tests) only called by ATMP, which already takes the tx pool read lock. So locking it twice more in both `addUnchecked` methods seems redundant. Similarly `CalculateMemPoolAncestors` is (beside once in the wallet) only called in contexts, where the tx pool lock is already taken. So remove the lock there as well. Tree-SHA512: fcf603b570da0fc529fe6db8add218663eae52845510732bee0d4611263d2429d3d3c9c8ae68493d67287d13504500ed51905ccbe711eb15a0af3b019edad543
addUncheckedis (outside the tests) only called by ATMP, which already takes the tx pool read lock. So locking it twice more in bothaddUncheckedmethods seems redundant.Similarly
CalculateMemPoolAncestorsis (beside once in the wallet) only called in contexts, where the tx pool lock is already taken. So remove the lock there as well.