Skip to content

[Refactoring] Remove BaseOutPoint::GetHash#2180

Merged
furszy merged 4 commits into
PIVX-Project:masterfrom
random-zebra:202102_prevout-hash
Feb 19, 2021
Merged

[Refactoring] Remove BaseOutPoint::GetHash#2180
furszy merged 4 commits into
PIVX-Project:masterfrom
random-zebra:202102_prevout-hash

Conversation

@random-zebra
Copy link
Copy Markdown

BaseOutPoint has a member variable named hash, but GetHash() does not return its value.
It returns the hash of the serialized class (hash and n) instead.
This is confusing and might lead to sneaky bugs (in fact, it already did in the past: #1963 (comment))

Further, the implementation of GetHash() is rather ugly, as it accesses the singleton pointer &this->n as an array (with BEGIN()/END()), which could result in misinterpretation or corruption of adjacent memory locations.

This function is used only in two places:

  • in the RPC getbudgetvotes for the key "nHash". This is wrong, as nHash is supposed to be the vote hash (as described in the help), and not the collateral outpoint hash.
  • to index mapVotes inside budgets and proposal objects. Here we can just index directly by collateral outpoint (instead of its hash).

With these two changes, we can get rid of BaseOutPoint::GetHash.
This also fixes another bug fund along the way: CBP/CFB::GetVotesHashes should return the vote hashes, not the masternode collateral hash.

Note: mapVotes is not directly sent on the network, it is only stored locally for each proposal.

- nHash is supposed to be the vote hash, not the outpoint hash
- mnId is the collateral outpoint (not just the outpoint.hash)
These functions are supposed to return a vector of vote-hashes.
They instead return a vector of mnIds(collateral)-hashes.
instead of using the hash of the whole outpoint object.
@furszy
Copy link
Copy Markdown

furszy commented Feb 2, 2021

Concept ACK 👌

@furszy furszy added the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Feb 10, 2021
Copy link
Copy Markdown

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Code review ACK 1192272.

Copy link
Copy Markdown
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

utACK 1192272

@furszy furszy merged commit cc9a7da into PIVX-Project:master Feb 19, 2021
@random-zebra random-zebra removed the Needs Release Notes Placeholder tag for anything needing mention in the "Notable Changes" section of release notes label Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants