-
Notifications
You must be signed in to change notification settings - Fork 178
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
Create CPID classes and clean up CPID code #1477
Conversation
By the way, we can ignore most of the changes to |
return m_bytes == Cpid::Hash(internal, email).m_bytes; | ||
} | ||
|
||
const std::array<unsigned char, 16>& Cpid::Raw() const |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyrossignol Sure :)
There was a problem hiding this comment.
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_map
s (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 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! utACK.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
Yep. That makes sense.
…Sent from my iPhone
On Jun 10, 2019, at 2:33 AM, Cy Rossignol ***@***.***> wrote:
@cyrossignol commented on this pull request.
In src/neuralnet/cpid.cpp:
> + return m_bytes != other.m_bytes;
+}
+
+bool Cpid::IsZero() const
+{
+ const auto zero = [](const unsigned char& i) { return i == 0; };
+
+ return std::all_of(m_bytes.begin(), m_bytes.end(), zero);
+}
+
+bool Cpid::Matches(const std::string& internal, const std::string& email) const
+{
+ return m_bytes == Cpid::Hash(internal, email).m_bytes;
+}
+
+const std::array<unsigned char, 16>& Cpid::Raw() const
@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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@cyrossignol have you tested this on testnet for compatibility? |
I am running this PR on my Windows test node on testnet. Looks good so far. |
@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. |
I am merging this one. It is running fine on my Windows testnet node. |
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)
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 aMiningId
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.