mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 989 forks source link

TUI Freeze Fix - Add manually maintained hash to difficulty iterator #3684

Closed yeastplume closed 2 years ago

yeastplume commented 2 years ago

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 the prev_header field in the Headers themselves. This optionally keeps hashes available in the HeaderDifficultyInfo 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.