Veil-Project / veil

Veil-Project
MIT License
118 stars 91 forks source link

[Chain] Keep hashAccumulators more up-to-date. #963

Closed Zannick closed 3 years ago

Zannick commented 3 years ago

Problem

Issue #942: Orphaned blocks sometimes had inconsistent hashes between block index hash (generally the cached value) and the disk index hash (produced by taking a new hash of the data). On closer inspection, hashAccumulators was the only differing value.

Solution

Make sure hashAccumulators is set or copied appropriately where relevant, particularly when mapAccumulatorHashes is set but not changed. The main culprit is likely LoadBlockIndexGuts, since it would be very easy to forget to update hashAccumulators before writing it out again.

Plus we use hashAccumulators instead of recalculating the map's hash as described in #942.

Testing

On regtest, with lots of extra debug warnings in WriteBatchSync about bad hashes, minted zerocoins in forks, confirmed this makes the debug warnings go away.