-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Use std::unordered_set instead of set in blockfilter interface #14074
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // Copyright (c) 2016-2018 The Bitcoin Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <crypto/siphash.h> | ||
|
|
||
| #define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) | ||
|
|
||
| #define SIPROUND do { \ | ||
| v0 += v1; v1 = ROTL(v1, 13); v1 ^= v0; \ | ||
| v0 = ROTL(v0, 32); \ | ||
| v2 += v3; v3 = ROTL(v3, 16); v3 ^= v2; \ | ||
| v0 += v3; v3 = ROTL(v3, 21); v3 ^= v0; \ | ||
| v2 += v1; v1 = ROTL(v1, 17); v1 ^= v2; \ | ||
| v2 = ROTL(v2, 32); \ | ||
| } while (0) | ||
|
|
||
| CSipHasher::CSipHasher(uint64_t k0, uint64_t k1) | ||
| { | ||
| v[0] = 0x736f6d6570736575ULL ^ k0; | ||
| v[1] = 0x646f72616e646f6dULL ^ k1; | ||
| v[2] = 0x6c7967656e657261ULL ^ k0; | ||
| v[3] = 0x7465646279746573ULL ^ k1; | ||
| count = 0; | ||
| tmp = 0; | ||
| } | ||
|
|
||
| CSipHasher& CSipHasher::Write(uint64_t data) | ||
| { | ||
| uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3]; | ||
|
|
||
| assert(count % 8 == 0); | ||
|
|
||
| v3 ^= data; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= data; | ||
|
|
||
| v[0] = v0; | ||
| v[1] = v1; | ||
| v[2] = v2; | ||
| v[3] = v3; | ||
|
|
||
| count += 8; | ||
| return *this; | ||
| } | ||
|
|
||
| CSipHasher& CSipHasher::Write(const unsigned char* data, size_t size) | ||
| { | ||
| uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3]; | ||
| uint64_t t = tmp; | ||
| int c = count; | ||
|
|
||
| while (size--) { | ||
| t |= ((uint64_t)(*(data++))) << (8 * (c % 8)); | ||
| c++; | ||
| if ((c & 7) == 0) { | ||
| v3 ^= t; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= t; | ||
| t = 0; | ||
| } | ||
| } | ||
|
|
||
| v[0] = v0; | ||
| v[1] = v1; | ||
| v[2] = v2; | ||
| v[3] = v3; | ||
| count = c; | ||
| tmp = t; | ||
|
|
||
| return *this; | ||
| } | ||
|
|
||
| uint64_t CSipHasher::Finalize() const | ||
| { | ||
| uint64_t v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3]; | ||
|
|
||
| uint64_t t = tmp | (((uint64_t)count) << 56); | ||
|
|
||
| v3 ^= t; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= t; | ||
| v2 ^= 0xFF; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| return v0 ^ v1 ^ v2 ^ v3; | ||
| } | ||
|
|
||
| uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val) | ||
| { | ||
| /* Specialized implementation for efficiency */ | ||
| uint64_t d = val.GetUint64(0); | ||
|
|
||
| uint64_t v0 = 0x736f6d6570736575ULL ^ k0; | ||
| uint64_t v1 = 0x646f72616e646f6dULL ^ k1; | ||
| uint64_t v2 = 0x6c7967656e657261ULL ^ k0; | ||
| uint64_t v3 = 0x7465646279746573ULL ^ k1 ^ d; | ||
|
|
||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(1); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(2); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(3); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| v3 ^= ((uint64_t)4) << 59; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= ((uint64_t)4) << 59; | ||
| v2 ^= 0xFF; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| return v0 ^ v1 ^ v2 ^ v3; | ||
| } | ||
|
|
||
| uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256& val, uint32_t extra) | ||
| { | ||
| /* Specialized implementation for efficiency */ | ||
| uint64_t d = val.GetUint64(0); | ||
|
|
||
| uint64_t v0 = 0x736f6d6570736575ULL ^ k0; | ||
| uint64_t v1 = 0x646f72616e646f6dULL ^ k1; | ||
| uint64_t v2 = 0x6c7967656e657261ULL ^ k0; | ||
| uint64_t v3 = 0x7465646279746573ULL ^ k1 ^ d; | ||
|
|
||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(1); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(2); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = val.GetUint64(3); | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| d = (((uint64_t)36) << 56) | extra; | ||
| v3 ^= d; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| v0 ^= d; | ||
| v2 ^= 0xFF; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| SIPROUND; | ||
| return v0 ^ v1 ^ v2 ^ v3; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright (c) 2016-2018 The Bitcoin Core developers | ||
|
||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #ifndef BITCOIN_CRYPTO_SIPHASH_H | ||
| #define BITCOIN_CRYPTO_SIPHASH_H | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include <uint256.h> | ||
|
|
||
| /** SipHash-2-4 */ | ||
| class CSipHasher | ||
| { | ||
| private: | ||
| uint64_t v[4]; | ||
| uint64_t tmp; | ||
| int count; | ||
|
|
||
| public: | ||
| /** Construct a SipHash calculator initialized with 128-bit key (k0, k1) */ | ||
| CSipHasher(uint64_t k0, uint64_t k1); | ||
| /** Hash a 64-bit integer worth of data | ||
| * It is treated as if this was the little-endian interpretation of 8 bytes. | ||
| * This function can only be used when a multiple of 8 bytes have been written so far. | ||
| */ | ||
| CSipHasher& Write(uint64_t data); | ||
| /** Hash arbitrary bytes. */ | ||
| CSipHasher& Write(const unsigned char* data, size_t size); | ||
| /** Compute the 64-bit SipHash-2-4 of the data written so far. The object remains untouched. */ | ||
| uint64_t Finalize() const; | ||
| }; | ||
|
|
||
| /** Optimized SipHash-2-4 implementation for uint256. | ||
| * | ||
| * It is identical to: | ||
| * SipHasher(k0, k1) | ||
| * .Write(val.GetUint64(0)) | ||
| * .Write(val.GetUint64(1)) | ||
| * .Write(val.GetUint64(2)) | ||
| * .Write(val.GetUint64(3)) | ||
| * .Finalize() | ||
| */ | ||
| uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256& val); | ||
| uint64_t SipHashUint256Extra(uint64_t k0, uint64_t k1, const uint256& val, uint32_t extra); | ||
|
|
||
| #endif // BITCOIN_CRYPTO_SIPHASH_H | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Initialize
countandtmpusing default member initializers or in the member initializer list of the constructor?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.
This is a move-only commit. I'd rather not modify the contents of the code here.
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.
Makes sense!