TUI Freeze Fix - Add manually maintained hash to difficulty iterator #3684
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to recent performance optimisations to the difficulty iterator, a call to the chain's
get_header_by_height
needed to be added. Unfortunately, this function relies on a read lock on the txhashset. A write lock is held unyielded for a very long time by validation code after the txhashset is downloaded, leading to a TUI freeze when calling this method.Fix is to avoid that call by re-adding a hash to the
HeaderDifficultyInfo
struct, populated by maintaining hashes as provided in theprev_header
field in the Headers themselves. This optionally keeps hashes available in theHeaderDifficultyInfo
struct while still avoiding the need to deserialize the entire header to derive the hash.Note this point in the TUI code is the only place where a block's hash is needed from the DifficultyIterator, so impact should be minimal.