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

Create CPID classes and clean up CPID code #1477

Merged
merged 3 commits into from
Jun 11, 2019

Conversation

cyrossignol
Copy link
Member

@cyrossignol cyrossignol commented Jun 8, 2019

Part 1 of some changes that clean up CPID handling. To make this easier to review, I'm splitting it up into two PRs and pulling it out of the contract/beacon updates.

These changes add a dedicated Cpid structure and a MiningId class that describes the identity of a miner (researcher or investor, for future serialization or potential support for surrogate ID to multiple CPIDs). It removes some legacy CPID handling code and the "boinckey" import mechanism. We can discuss a better way to implement that later.

The classes help with upcoming beacon format changes and move a bit more Gridcoin-specific code out of main.cpp.

@cyrossignol cyrossignol marked this pull request as ready for review June 8, 2019 18:12
@jamescowens jamescowens added this to the Elizabeth milestone Jun 9, 2019
@cyrossignol
Copy link
Member Author

By the way, we can ignore most of the changes to HarvestCPIDs() and GetNextProject()...those have been rewritten in part 2.

return m_bytes == Cpid::Hash(internal, email).m_bytes;
}

const std::array<unsigned char, 16>& Cpid::Raw() const
Copy link
Member

Choose a reason for hiding this comment

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

Consider returning a copy here unless we want to use a reference for performance reason. It looks like the class is immutable so this should be safe, but the reference will be dangling if this object is used in a container which is then reorganized.

Copy link
Member

Choose a reason for hiding this comment

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

Should we also change from an MD5 to sha256 hash for the CPID::Hash? Is it necessary for security? How much would it break things? Also, would have to be coded as a mandatory I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

@denravonska Ah, good point--let's use a copy. Only the tests use this method right now, so the overhead should be fine. Can I change that in the part 2 PR?

@jamescowens The Hash() method is used to generate an external CPID from an internal CPID and email address so that the wallet can validate the CPIDs loaded from client_state.xml locally to avoid running with a corrupt CPID. It replaces the obfuscated MD5 algorithm from the cpid.cpp class that I removed. BOINC's external CPIDs are MD5 hashes, so we can't change the format, but we won't use it in the protocol.

Copy link
Member

Choose a reason for hiding this comment

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

@cyrossignol Sure :)

Copy link
Member Author

@cyrossignol cyrossignol Jun 10, 2019

Choose a reason for hiding this comment

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

@denravonska I remember why this returns a reference now--in the upcoming PR, I specialized std::hash<T> so that we can use Cpid objects as keys in unordered_maps (for lookup by CPID--beacons for example). A copy would happen there every time we access the maps by key if we go that route because it's calling this method to get the data to hash.

I'll do some reading about dangling references. In this case, Raw() is provided for low-level access which should happen only sparingly outside of the interface provided by the rest of the class. We can review in the next PR to determine how we want to keep it 🙂

Copy link
Member

@denravonska denravonska left a comment

Choose a reason for hiding this comment

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

Looks great! utACK.

Copy link
Member

@jamescowens jamescowens left a comment

Choose a reason for hiding this comment

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

Really nice work IMHO.

return m_bytes == Cpid::Hash(internal, email).m_bytes;
}

const std::array<unsigned char, 16>& Cpid::Raw() const
Copy link
Member

Choose a reason for hiding this comment

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

Should we also change from an MD5 to sha256 hash for the CPID::Hash? Is it necessary for security? How much would it break things? Also, would have to be coded as a mandatory I think.

@jamescowens
Copy link
Member

jamescowens commented Jun 10, 2019 via email

@jamescowens
Copy link
Member

@cyrossignol have you tested this on testnet for compatibility?

@jamescowens
Copy link
Member

I am running this PR on my Windows test node on testnet. Looks good so far.

@cyrossignol
Copy link
Member Author

@jamescowens I synced testnet from 0 and staked a couple blocks...no issues so far that I can tell. I'll do mainnet in the next PR.

@jamescowens
Copy link
Member

I am merging this one. It is running fine on my Windows testnet node.

@jamescowens jamescowens merged commit d1d4910 into gridcoin-community:development Jun 11, 2019
jamescowens added a commit that referenced this pull request Aug 20, 2019
Added:
 - Add freedesktop.org desktop file and icon set #1438 (@a123b)
 - Add warning in help for blockchain scan for importprivkey #1469 (@jamescowens)
 - Consolidateunspent rpc function #1472 (@jamescowens)
 - Scraper 2.0 improvements #1481, #1488, #1509, and #1514 (@jamescowens, @cyrossignol)
   - explorer mode operation
   - simplified explainmagnitude output
   - improved convergence reporting, including scraper information in the tooltip when fDebug3 is set
   - improved statistics and SB contract core caching based on a bClean flag in the cache global
   - new SB format and packing for bv11
   - new SB contract hashing (native) for bv11
   - changes to accomodate new beacon approach
   - Implement in memory versioning for team file ETags
 - Implement local dynamic team requirement removal and whitelist #1502 (@cyrossignol)

Changed:
 - Quiet logging for getmininginfo and scraper INFO logging level #1460 (@jamescowens)
 - Spelling corrections #1461, #1462 (@caraka)
 - Update crypto module #1453 (@denravonska)
 - Update .travis.yml for Bionic #1475 (@jamescowens)
 - Create CPID classes and clean up CPID code #1477 (@cyrossignol)
 - Refactor researcher context and CPID harvesting #1480 (@cyrossignol)
   - Remove boinckey export RPC method and import handler
 - Notify when wallet locked in advertisebeacon RPC method #1504 (@cyrossignol)
 - Notify when wallet locked in beaconstatus RPC method #1506 (@cyrossignol)
 - Change spacer minimum height hint #1511 (@jamescowens)

Removed:
 - Remove safe mode #1434 (@denravonska)
 - Remove bitcoin.moc in Makefile.qt.include #1444 (@RoboticMind)
 - Clean up legacy Proof-of-Work functions #1497 (@cyrossignol)

Fixed:
 - Constrain walletpassphrase to 10000000 seconds #1459 (@jamescowens)
 - Straighten out localization in the scraper. #1471 (@jamescowens)
 - Quick fix for rainbymagnitude #1473 (@jamescowens)
 - Correct negation error in scraper tooltip for vScrapersNotPublishing #1484 (@jamescowens)
 - Fix staked block rejection when active researcher #1485 (@cyrossignol)
 - Add back informational magnitude to generated blocks #1489 (@cyrossignol)
 - Add back in the in sync check in ScraperGetNeuralContract #1492 (@jamescowens)
 - Scraper correct team file processing. #1501 (@jamescowens)
 - Have importwallet file path default to datadir #1508 (@jamescowens)
 - Scraper add Beacon Map size check to ensure convergence #1515 (@jamescowens)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants