Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 5, 2021

Conversation

Zannick
Copy link
Collaborator

@Zannick Zannick commented Jul 26, 2021

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.

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.
@codeofalltrades codeofalltrades added Tag: Waiting For Code Review Waiting for code review from a core developer Tag: Chainstate Related to blockindexes and the state of the chain. Tag: PoS Related to Proof of Stake Tag: PoW Related to Proof of Work consensus labels Jul 26, 2021
Copy link
Collaborator

@CaveSpectre11 CaveSpectre11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a7941b8

Copy link
Collaborator

@CaveSpectre11 CaveSpectre11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a7941b8

Copy link
Collaborator

@codeofalltrades codeofalltrades left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a7941b8

@codeofalltrades codeofalltrades added Code Review: Passed and removed Tag: Waiting For Code Review Waiting for code review from a core developer labels Aug 2, 2021
@CaveSpectre11 CaveSpectre11 merged commit 0cfd270 into Veil-Project:master Sep 5, 2021
@CaveSpectre11 CaveSpectre11 added the Dev Status: Merged Issue is completely finished. label Sep 5, 2021
@Zannick Zannick deleted the hash branch October 22, 2021 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Review: Passed Dev Status: Merged Issue is completely finished. Tag: Chainstate Related to blockindexes and the state of the chain. Tag: PoS Related to Proof of Stake Tag: PoW Related to Proof of Work consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants