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
[Qt] Reduce a significant cs_main lock freeze #10231
Conversation
Can the GUI instead cache the current best tip? This may help with @ryanofsky's process split as well. |
@TheBlueMatt: Yes. @theuni recommended this on IRC and I'm currently changing it. |
737adc1
to
745a27f
Compare
Moved the cache from the core validation logic to the GUI. |
src/qt/clientmodel.cpp
Outdated
if (!pindexBestHeader) | ||
return 0; | ||
return pindexBestHeader->nHeight; | ||
if (cachedBestHeaderHeight == 0) { |
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.
Where is this initialized? -- these don't have static duration AFAICT.
Also is zero really the best value to use? -- it's in range, so it'll keep relocking again while there is no data there.
What does the GUI use the header time/height for as opposed to the tip? |
745a27f
to
42e30f4
Compare
42e30f4
to
7148f5e
Compare
Thanks @gmaxwell. Added the missing initialisation and switched to
The only use case is to calculate the remaining blocks to download/validate (modal sync progress overlay). |
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
src/qt/clientmodel.cpp
Outdated
@@ -72,20 +74,28 @@ int ClientModel::getNumBlocks() const | |||
return chainActive.Height(); | |||
} | |||
|
|||
int ClientModel::getHeaderTipHeight() const | |||
int ClientModel::getHeaderTipHeight() |
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.
Maybe this should remain const, and declare the caches mutable?
// otherwise we need to wait for a tip update | ||
LOCK(cs_main); | ||
if (pindexBestHeader) { | ||
cachedBestHeaderHeight = pindexBestHeader->nHeight; |
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.
Would it make sense to populate both caches at once perhaps?
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.
Good idea.
utACK |
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
Followed @luke-jr's advice and re-set the method to @gmaxwell, @TheBlueMatt: thanks for a re-ack. :) |
Less blocking of the gui on cs_main is always a good thing, thanks! |
4082fb0 Add missing <atomic> header in clientmodel.h (Jonas Schnelli) 928d4a9 Set both time/height header caches at the same time (Jonas Schnelli) 610a917 Declare headers height/time cache mutable, re-set the methods const (Jonas Schnelli) cf92bce Update the remaining blocks left in modaloverlay at init. (Jonas Schnelli) 7148f5e Reduce cs_main locks during modal overlay by adding an atomic cache (Jonas Schnelli) Tree-SHA512: a92ca22f90b8b2a5e8eb94fdce531ef44542e21a8dbbb0693f7723d7018592cb68de687a2a0aac91d31cbf019793f8e922550656d2b130ed3d854d60630341db
Github-Pull: bitcoin#10231 Rebased-From: 7148f5e
Github-Pull: bitcoin#10231 Rebased-From: cf92bce
Github-Pull: bitcoin#10231 Rebased-From: 610a917
Github-Pull: bitcoin#10231 Rebased-From: 928d4a9
Github-Pull: bitcoin#10231 Rebased-From: 4082fb0
4082fb0 Add missing <atomic> header in clientmodel.h (Jonas Schnelli) 928d4a9 Set both time/height header caches at the same time (Jonas Schnelli) 610a917 Declare headers height/time cache mutable, re-set the methods const (Jonas Schnelli) cf92bce Update the remaining blocks left in modaloverlay at init. (Jonas Schnelli) 7148f5e Reduce cs_main locks during modal overlay by adding an atomic cache (Jonas Schnelli) Tree-SHA512: a92ca22f90b8b2a5e8eb94fdce531ef44542e21a8dbbb0693f7723d7018592cb68de687a2a0aac91d31cbf019793f8e922550656d2b130ed3d854d60630341db
…1704) 4082fb0 Add missing <atomic> header in clientmodel.h (Jonas Schnelli) 928d4a9 Set both time/height header caches at the same time (Jonas Schnelli) 610a917 Declare headers height/time cache mutable, re-set the methods const (Jonas Schnelli) cf92bce Update the remaining blocks left in modaloverlay at init. (Jonas Schnelli) 7148f5e Reduce cs_main locks during modal overlay by adding an atomic cache (Jonas Schnelli) Tree-SHA512: a92ca22f90b8b2a5e8eb94fdce531ef44542e21a8dbbb0693f7723d7018592cb68de687a2a0aac91d31cbf019793f8e922550656d2b130ed3d854d60630341db
I can't remember why we added this in the first place: but in current master, we request a
cs_main
lock (not a try lock) every block tip update in order to get the best headers height / time.This results in significant freezes in the GUI during IBD/catch-up.
This PR adds two atomic caches for the best headers height and time.
If we do a 0.14.1rc3, we should consider adding this.