Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Jul 28, 2018

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 28, 2018

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.

@promag
Copy link
Contributor

promag commented Jul 28, 2018

Tested ACK fa6b4b5. Verified all OP claims.

CalculateMemPoolAncestors is called in:

void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);

RBFTransactionState IsRBFOptIn(const CTransaction &tx, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);

void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs);

which already have the annotation.

@maflcko maflcko force-pushed the Mf1807-txPoolCsThrice branch from fa6b4b5 to fa5ed4f Compare July 29, 2018 12:04
@maflcko
Copy link
Member Author

maflcko commented Jul 29, 2018

Rebased



CTxMemPool testPool;
LOCK(testPool.cs);
Copy link
Contributor

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);
Copy link
Contributor

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

@Empact
Copy link
Contributor

Empact commented Jul 30, 2018

utACK fa5ed4f

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK fa5ed4f

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Jul 30, 2018
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
@maflcko maflcko merged commit fa5ed4f into bitcoin:master Jul 30, 2018
@maflcko maflcko deleted the Mf1807-txPoolCsThrice branch July 30, 2018 20:23
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 11, 2019
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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 4, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants