-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Move SaltedHashers to separate file and add some new ones #19935
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
Conversation
a2b50c9
to
7e755b7
Compare
7e755b7
to
3f6e8ec
Compare
src/Makefile.am
Outdated
@@ -193,6 +193,7 @@ BITCOIN_CORE_H = \ | |||
rpc/request.h \ | |||
rpc/server.h \ | |||
rpc/util.h \ | |||
saltedhash.h \ |
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.
Maybe place these in util
or crypto
? I'd prefer not to add files to the source root anymore when possible.
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.
Moved to util.
Concept ACK |
3f6e8ec
to
b645eff
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
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.
Concept ACK.
Maybe name the file hashers.{h,cpp}? Would be nice to see SaltedScriptHasher
and SaltedPubkeyHasher
being used - didn't find them in #19602 either.
Verified moved code in ea4c980 and 8ab5135 with git show --color-moved=dimmed_zebra
.
BTW, should include util/saltedhash.h explicitly - it's indirectly included in coins.h.
Concept ACK +1 on @promag's feedback regarding |
b645eff
to
4e0ce3e
Compare
Done.
I'm using them in another branch that I haven't opened a PR for yet. |
4e0ce3e
to
97fde1a
Compare
For the non-optimized ones, it may be better to have a single |
97fde1a
to
4ed62a4
Compare
Good idea. Done. Apparently we have other Hashers too, so I've added those to |
4ed62a4
to
2d5c130
Compare
2d5c130
to
134a904
Compare
Move the hashers that we use for hash tables to a common place. Moved hashers: - SaltedTxidHasher - SaltedOutpointHasher - FilterHeaderHasher - SignatureCacheHasher - BlockHasher
SaltedSipHasher is a generic hasher that can be used with most things we would hash in an unordered container.
134a904
to
281fd1a
Compare
Code review ACK 281fd1a I must say that in general I think throwing all hashers of all kinds of different data structures into one grabbag header is not a great subdivision criterion. However in this case it's all consensus transaction/block related things so I think it's fine! But I wouldn't want to say, add P2P, wallet or mempool specific data structure hashers to this file. |
Right. What I had really needed was |
* This *must* return size_t. With Boost 1.46 on 32-bit systems the | ||
* unordered_map will behave unpredictably if the custom hasher returns a | ||
* uint64_t, resulting in failures when syncing the chain (#4634). | ||
* |
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.
Our minimum boost version is now 1.58, and has been higher than 1.46 since #8920. According to this comment: #4635 (comment), boost versions higher than 1.54 are fine.
I think we can just delete this part of the comment rather than retaining 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.
Will remove if I have to push again
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.
@@ -303,7 +303,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv | |||
|
|||
/* the HD chain data model (external chain counters) */ | |||
CHDChain m_hd_chain; | |||
std::unordered_map<CKeyID, CHDChain, KeyIDHasher> m_inactive_hd_chains; | |||
std::unordered_map<CKeyID, CHDChain, SaltedSipHasher> m_inactive_hd_chains; |
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 like KeyIDHasher
could be removed since it's no longer used after this this change.
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.
Will remove if I have to push again.
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.
utACK 281fd1a
I agree with @mzumsande that KeyIDHasher
seems not longer used and could be removed unless I am missing something.
#include <crypto/siphash.h> | ||
#include <primitives/transaction.h> | ||
#include <uint256.h> | ||
|
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.
I think it would be great if there was a small comment here explaining what belongs into this file and what doesn't to help future contributors so they don't have to go back in git history to understand 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.
Will add if I have to push again.
@@ -0,0 +1,87 @@ | |||
// Copyright (c) 2019 The Bitcoin Core developers |
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.
nit: 2020
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.
Will fix if I have to push again.
… new ones 281fd1a Replace KeyIDHasher with SaltedSipHasher (Andrew Chow) 210b693 Add generic SaltedSipHasher (Andrew Chow) 95e61c1 Move Hashers to util/hasher.{cpp/h} (Andrew Chow) Pull request description: There are existing `SaltedOutPointHasher` and `SaltedTxidHasher` classes used for `std::unordered_map` and `std::unordered_set` that could be useful in other places in the codebase. So we these to their own `saltedhash.{cpp/h}` file. An existing `KeyIDHasher` is moved there too. Additionally, `ScriptIDHasher`, `SaltedPubkeyHasher`, and `SaltedScriptHasher` are added so that they can be used in future work. `KeyIDHasher` and `ScriptIDHasher` are not salted so that equality comparisons of maps and sets keyed by `CKeyID` and `CScriptID` will actually work. Split from bitcoin#19602 (and a few other PRs/branches I have). ACKs for top commit: laanwj: Code review ACK 281fd1a jonatack: ACK 281fd1a, code review, debug build and ran bitcoind after rebasing to master @ dff0f6f fjahr: utACK 281fd1a Tree-SHA512: bb03b231ccf3c9ecefc997b8da9c3770af4819f9be5b0a72997a103864e84046a2ac39b8eadf0dc9247bdccd53f86f433642e3a098882e6748341a9e7736271b
… new ones 281fd1a Replace KeyIDHasher with SaltedSipHasher (Andrew Chow) 210b693 Add generic SaltedSipHasher (Andrew Chow) 95e61c1 Move Hashers to util/hasher.{cpp/h} (Andrew Chow) Pull request description: There are existing `SaltedOutPointHasher` and `SaltedTxidHasher` classes used for `std::unordered_map` and `std::unordered_set` that could be useful in other places in the codebase. So we these to their own `saltedhash.{cpp/h}` file. An existing `KeyIDHasher` is moved there too. Additionally, `ScriptIDHasher`, `SaltedPubkeyHasher`, and `SaltedScriptHasher` are added so that they can be used in future work. `KeyIDHasher` and `ScriptIDHasher` are not salted so that equality comparisons of maps and sets keyed by `CKeyID` and `CScriptID` will actually work. Split from bitcoin#19602 (and a few other PRs/branches I have). ACKs for top commit: laanwj: Code review ACK 281fd1a jonatack: ACK 281fd1a, code review, debug build and ran bitcoind after rebasing to master @ dff0f6f fjahr: utACK 281fd1a Tree-SHA512: bb03b231ccf3c9ecefc997b8da9c3770af4819f9be5b0a72997a103864e84046a2ac39b8eadf0dc9247bdccd53f86f433642e3a098882e6748341a9e7736271b
…add some new ones" This reverts commit 6c60aa4.
…9935) 4c69571 doc: remove outdated comment (Martin Zumsande) 16652a9 refactor: Remove unused KeyIDHasher (Martin Zumsande) Pull request description: Small follow-ups to #19935: - Removal of unused `KeyIDHasher` class ([comment in 19935](bitcoin/bitcoin#19935 (comment))) - Removal of an outdated comment, which referred to an old problem with the no longer supported Boost 1.46 and `boost::unordered_map`, now replaced by `std::unordered_map`. ([comment in 19935](bitcoin/bitcoin#19935 (comment))) ACKs for top commit: Saviour1001: Tested ACK <code>[4c69571](https://github.com/bitcoin/bitcoin/commit/4c69571e6eeae2c03d59045ea102baa5fd1c3816)</code> Zero-1729: ACK 4c69571 theStack: ACK 4c69571 🆗 Tree-SHA512: 243fda2120bfac6c40a268ca2c0f34482ce27e71fbc50005c0d13c2ad5db9ee72a037f9937c37cc50ed0f9f6f11ee6afee4ac50e5031d6876ec942f41f38dadf
4c69571 doc: remove outdated comment (Martin Zumsande) 16652a9 refactor: Remove unused KeyIDHasher (Martin Zumsande) Pull request description: Small follow-ups to bitcoin#19935: - Removal of unused `KeyIDHasher` class ([comment in 19935](bitcoin#19935 (comment))) - Removal of an outdated comment, which referred to an old problem with the no longer supported Boost 1.46 and `boost::unordered_map`, now replaced by `std::unordered_map`. ([comment in 19935](bitcoin#19935 (comment))) ACKs for top commit: Saviour1001: Tested ACK <code>[4c69571](https://github.com/bitcoin/bitcoin/commit/4c69571e6eeae2c03d59045ea102baa5fd1c3816)</code> Zero-1729: ACK 4c69571 theStack: ACK 4c69571 🆗 Tree-SHA512: 243fda2120bfac6c40a268ca2c0f34482ce27e71fbc50005c0d13c2ad5db9ee72a037f9937c37cc50ed0f9f6f11ee6afee4ac50e5031d6876ec942f41f38dadf
There are existing
SaltedOutPointHasher
andSaltedTxidHasher
classes used forstd::unordered_map
andstd::unordered_set
that could be useful in other places in the codebase. So we these to their ownsaltedhash.{cpp/h}
file. An existingKeyIDHasher
is moved there too. Additionally,ScriptIDHasher
,SaltedPubkeyHasher
, andSaltedScriptHasher
are added so that they can be used in future work.KeyIDHasher
andScriptIDHasher
are not salted so that equality comparisons of maps and sets keyed byCKeyID
andCScriptID
will actually work.Split from #19602 (and a few other PRs/branches I have).