Optimise lock behaviour for GuessVerificationProgress()#12287
Optimise lock behaviour for GuessVerificationProgress()#12287jonasschnelli merged 1 commit intobitcoin:masterfrom
Conversation
|
Not meant for 0.16. |
|
Related:
|
src/qt/clientmodel.cpp
Outdated
| LOCK(cs_main); | ||
| tip = chainActive.Tip(); | ||
| } | ||
| LOCK(cs_main); |
There was a problem hiding this comment.
Just move the above lock up?
src/validation.cpp
Outdated
| //! Guess how far we are in the verification process at the given block index | ||
| //! needs cs_main due to access of pindex->nChainTx (mutable) | ||
| double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pindex) { | ||
| AssertLockHeld(cs_main); |
There was a problem hiding this comment.
I think maybe the new lock and assert here could be dropped and comment above could be changed to: "require cs_main if pindex has not been validated yet (because nChainTx might be unset)."
If we're calling this on blocks from chainActive, it seems like locking should be unnecessary.
There was a problem hiding this comment.
After 3d40869, ClientModel::getVerificationProgress is the only caller without the lock, so AssertLockHeld seems fine to me.
There was a problem hiding this comment.
AssertLockHeld seems fine to me
Getting rid of this could avoid a new lock in Rescan, and remove an existing lock. It also seems not ideal if code and documentation implies locking is required when it isn't.
src/validation.cpp
Outdated
| DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), | ||
| GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); | ||
| { | ||
| LOCK(cs_main); |
src/validation.cpp
Outdated
| //! Guess how far we are in the verification process at the given block index | ||
| //! needs cs_main due to access of pindex->nChainTx (mutable) | ||
| double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pindex) { | ||
| AssertLockHeld(cs_main); |
There was a problem hiding this comment.
After 3d40869, ClientModel::getVerificationProgress is the only caller without the lock, so AssertLockHeld seems fine to me.
|
@jonasschnelli please see 6e36821 which came after discussing with @ryanofsky on IRC. |
5b790b8 to
2ceb308
Compare
2ceb308 to
90ba2df
Compare
|
Changed my mind. Included 6e36821.
|
|
Thread #12287 (comment) In this case, where Other than that, utACK 90ba2df. |
ryanofsky
left a comment
There was a problem hiding this comment.
Nice code simplifications and comments.
Conditional utACK 90ba2df if PR title ("Fix missing cs_main lock for GuessVerificationProgress") is updated, because the added locking is just defensive, not because locks are missing. Also think adding the assert would be misleading for the same reason.
|
Changed the PR title. |
|
Tested ACK 90ba2df. Let's get this merged? 🙄 |
90ba2df Fix missing cs_main lock for GuessVerificationProgress() (Jonas Schnelli) Pull request description: `GuessVerificationProgress()` needs `cs_main` due to accessing the `pindex->nChainTx`. This adds a `AssertLockHeld` in `GuessVerificationProgress()` and adds the missing locks in... * `LoadChainTip()` * `ScanForWalletTransactions()` (got missed in #11281) * GUI, `ClientModel::getVerificationProgress()` <--- **this may have GUI performance impacts**, but could be relaxed later with a cache or something more efficient. Tree-SHA512: 13302946571422375f32af8e396b9d2c1180f2693ea363aeba9e98c8266ddec64fe7862bfdcbb5a93a4b12165a61eec1e51e4e7d7a8515fa50879095dc163412
…gress() 90ba2df Fix missing cs_main lock for GuessVerificationProgress() (Jonas Schnelli) Pull request description: `GuessVerificationProgress()` needs `cs_main` due to accessing the `pindex->nChainTx`. This adds a `AssertLockHeld` in `GuessVerificationProgress()` and adds the missing locks in... * `LoadChainTip()` * `ScanForWalletTransactions()` (got missed in bitcoin#11281) * GUI, `ClientModel::getVerificationProgress()` <--- **this may have GUI performance impacts**, but could be relaxed later with a cache or something more efficient. Tree-SHA512: 13302946571422375f32af8e396b9d2c1180f2693ea363aeba9e98c8266ddec64fe7862bfdcbb5a93a4b12165a61eec1e51e4e7d7a8515fa50879095dc163412
GuessVerificationProgress()needscs_maindue to accessing thepindex->nChainTx.This adds a
AssertLockHeldinGuessVerificationProgress()and adds the missing locks in...LoadChainTip()ScanForWalletTransactions()(got missed in Avoid permanent cs_main/cs_wallet lock during RescanFromTime #11281)ClientModel::getVerificationProgress()<--- this may have GUI performance impacts, but could be relaxed later with a cache or something more efficient.