Similar to what #32421 did for CTransaction
instances, this PR aims to improve the block hash determination of CBlockHeader
/CBlock
(the latter is a subclass of the former) instances by removing the block header caching mechanism and introducing consistent naming. Without the statefulness, sneaky testing bugs like #32742 and #32823 are less likely to happen in the future. Note that performance is even less of an issue here compared to CTransaction
, as we only need to hash 80 bytes, which is less than typical standard transaction sizes [2].
The only instance where the testing logic was relying on caching (i.e. we want to return an outdated value) is tackled in the second commit, the rest should be straight-forward to review, especially for contributors who already reviewed #32421.
Summary table showing block hash determaination before/after this PR:
Task | master | PR |
---|---|---|
get block header hash (hex string) | .hash [1] |
.hash_hex |
get block header hash (integer) | rehash() , .sha256 [1] |
.hash_int |
[1] = returned value might be None
or out-of-date, if rehashing function wasn’t called after modification
[2] = the only exception I could think of are transaction with pay-to-anchor (P2A) outputs