[Chain] Keep hashAccumulators more up-to-date.#963
Merged
CaveSpectre11 merged 1 commit intoVeil-Project:masterfrom Sep 5, 2021
Merged
[Chain] Keep hashAccumulators more up-to-date.#963CaveSpectre11 merged 1 commit intoVeil-Project:masterfrom
CaveSpectre11 merged 1 commit intoVeil-Project:masterfrom
Conversation
Use hashAccumulators instead of re-hashing mapAccumulatorHashes, as sometimes the map is not used but the cached hash value it had is (e.g. constructing the CBlockIndex from a CBlockHeader). Update hashAccumulators on any calls to AddAccumulators. Copy it when copying mapBlockIndex. Finally, copy it on loading from the diskindex--I believe this is the cause of some indexes (particularly orphans) having inconsistent hashes. Fixes Veil-Project#942.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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,
hashAccumulatorswas the only differing value.Solution
Make sure
hashAccumulatorsis set or copied appropriately where relevant, particularly whenmapAccumulatorHashesis set but not changed. The main culprit is likelyLoadBlockIndexGuts, since it would be very easy to forget to updatehashAccumulatorsbefore writing it out again.Plus we use
hashAccumulatorsinstead of recalculating the map's hash as described in #942.Testing
On regtest, with lots of extra debug warnings in
WriteBatchSyncabout bad hashes, minted zerocoins in forks, confirmed this makes the debug warnings go away.