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

Backport bloom filter improvements #5026

Merged
merged 17 commits into from Apr 15, 2021
Merged

Conversation

@str4d str4d added C-upstream-port Category: Changes that are ported from the Bitcoin Core codebase. I-dos Problems and improvements with respect to Denial-of-Service. labels Mar 5, 2021
@str4d str4d added this to the Core Sprint 2021-08 milestone Mar 5, 2021
@str4d
Copy link
Contributor Author

str4d commented Mar 5, 2021

@zkbot try

@zkbot
Copy link
Contributor

zkbot commented Mar 5, 2021

⌛ Trying commit bb2463a with merge be45961...

zkbot added a commit that referenced this pull request Mar 5, 2021
Backport bloom filter improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7113
- bitcoin/bitcoin#7818
  - Only the second commit (to resolve conflicts).
- bitcoin/bitcoin#7934
- bitcoin/bitcoin#8655
  - Partial backport to help resolve conflicts.
- bitcoin/bitcoin#9060
- bitcoin/bitcoin#9223
- bitcoin/bitcoin#9644
  - Partial backport to help resolve conflicts.
- bitcoin/bitcoin#9916
- bitcoin/bitcoin#9750
- bitcoin/bitcoin#13176
- bitcoin/bitcoin#13948
- bitcoin/bitcoin#16073
- bitcoin/bitcoin#18670
- bitcoin/bitcoin#18806
  - Reveals upstream's covert fix for CVE-2013-5700.
- bitcoin/bitcoin#19968
src/init.cpp Outdated Show resolved Hide resolved
@zkbot
Copy link
Contributor

zkbot commented Mar 5, 2021

☀️ Test successful - pr-try
State: approved= try=True

@daira daira self-requested a review March 6, 2021 01:47
@mdr0id mdr0id added the safe-to-build Used to send PR to prod CI environment label Mar 31, 2021
@zkbot
Copy link
Contributor

zkbot commented Apr 2, 2021

☔ The latest upstream changes (presumably #5009) made this pull request unmergeable. Please resolve the merge conflicts.

sipa and others added 14 commits April 2, 2021 16:04
For each 'bit' in the filter we really maintain 2 bits, which store either:
0: not set
1-3: set in generation N

After (nElements / 2) insertions, we switch to a new generation, and wipe
entries which already had the new generation number, effectively switching
from the last 1.5 * nElements set to the last 1.0 * nElements set.

This is 25% more space efficient than the previous implementation, and can
(at peak) store 1.5 times the requested amount of history (though only
1.0 times the requested history is guaranteed).

The existing unit tests should be sufficient.

(cherry picked from commit 086ee67)
This patch changes the implementation from one that stores 16 2-bit integers
in one uint32_t's, to one that stores the first bit of 64 2-bit integers in
one uint64_t and the second bit in another. This allows for 450x faster
refreshing and 2.2x faster average speed.

(cherry picked from commit 1953c40)
(cherry picked from commit 4731cab)

Zcash: Excluding changes to code we haven't backported.
Fixes newly initialized bloom filters being
constructed with isEmpty(false), which still
works but loses the possible speedup when
checking for key membership in an empty filter.

(cherry picked from commit cccf73d)
Output instances of "BloomFilter" changed to "Bloom filter", in accordance with Wikipedia standard notation:

https://en.wikipedia.org/wiki/Bloom_filter

also to sync with the majority of cases in the self-same file

(cherry picked from commit b7aa290)
(cherry picked from commit b7b48c8)

Zcash: Excluding changes to code we haven't backported yet that cause
too many conflicts.
On msvc14, the compiler error C4146 (unary minus operator applied to unsigned type, result still unsigned) had been occured.
Use '0 - x' styled formula instead of '-x' so as to fix the error.

(cherry picked from commit 292112f)
…ed type)

On msvc14, int literal '-2147483648' is invalid, because '2147483648' is unsigned type and cant't apply minus operator to unsigned type.
To define the int literal correctly, use '-2147483647 - 1' formula that is also used to define INT_MIN in limits.h.

(cherry picked from commit 8e0720b)
(cherry picked from commit 64aa36e)
Replaces the slow modulo operation with a much faster 32bit multiplication & shift. This works
because the hash should be uniformly distributed between 0 and 2^32-1. This speeds up the benchmark
by a factor of about 1.3:

RollingBloom, 5, 1500000, 3.73733, 4.97569e-07, 4.99002e-07, 4.98372e-07 # before
RollingBloom, 5, 1500000, 2.86842, 3.81630e-07, 3.83730e-07, 3.82473e-07 # FastMod

Be aware that this changes the position of the bits that are toggled, so this should probably
not be used for CBloomFilter which is serialized.

(cherry picked from commit 9aac9f9)
This commit removes the `CBloomFilter::CBloomFilter(const unsigned int, const double, const unsigned int)` constructor, which became obsolete with 086ee67.

(cherry picked from commit 265bd50)
theStack and others added 3 commits April 2, 2021 16:04
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
(cherry picked from commit 69ffddc)

Zcash: Excluding change to src/test/fuzz/bloom_filter.cpp which we
don't have (we haven't backported upstream's fuzzing framework).
(cherry picked from commit 1ad8ea2)

Zcash: Excluding change to src/test/fuzz/bloom_filter.cpp which we
don't have (we haven't backported upstream's fuzzing framework).
(cherry picked from commit d9141a0002bb508b2e94e206a1bd28ef8f97ffde)
Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

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

utACK + @daira and @therealyingtong

@str4d
Copy link
Contributor Author

str4d commented Apr 15, 2021

@zkbot r+

@zkbot
Copy link
Contributor

zkbot commented Apr 15, 2021

📌 Commit 1dd379a has been approved by str4d

@zkbot
Copy link
Contributor

zkbot commented Apr 15, 2021

⌛ Testing commit 1dd379a with merge 78de0cd...

@zkbot
Copy link
Contributor

zkbot commented Apr 15, 2021

☀️ Test successful - pr-merge
Approved by: str4d
Pushing 78de0cd to master...

@zkbot zkbot merged commit 78de0cd into zcash:master Apr 15, 2021
@str4d str4d deleted the bloom-filter-backports branch April 16, 2021 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-upstream-port Category: Changes that are ported from the Bitcoin Core codebase. I-dos Problems and improvements with respect to Denial-of-Service. safe-to-build Used to send PR to prod CI environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet