This proof of concept PR (leveraging work done by Cory Fields & Jeremy Rubin, see #16834) replaces the rolling bloom filter used for m_addr_known
with a Cuckoo Filter written in Rust. I’ve have made some minor build related adjustments to the Rust code, which can be seen here: https://github.com/fanquake/rust-cuckoofilter/tree/cabi_build_adjustments.
See “Cuckoo Filter: Practically Better Than Bloom”:
In many networking systems, Bloom filters are used for high-speed set membership tests. They permit a small fraction of false positive answers with very good space efficiency. However, they do not permit deletion of items from the set, and previous attempts to extend “standard” Bloom filters to support deletion all degrade either space or performance.
We propose a new data structure called the cuckoo filter that can replace Bloom filters for approximate set member- ship tests. Cuckoo filters support adding and removing items dynamically while achieving even higher performance than Bloom filters.
For applications that store many items and target moderately low false positive rates, cuckoo filters have lower space overhead than space-optimized Bloom filters. Our experimental results also show that cuckoo filters out-perform previous data structures that extend Bloom filters to support deletions substantially in both time and space.
Using this is a matter of:
0./autogen.sh
1./configure --enable-experimental-rust
2make
3make -C src rusty-check
4src/bitcoind
Note that sometimes compilation will finish (i.e due to ccache
) before cargo
has finished generating the header and Rust lib, which will result in a compile error:
0./net.h:43:10: fatal error: rusty/out/rcf_cuckoofilter.h: No such file or directory
1 43 | #include <rusty/out/rcf_cuckoofilter.h>
In this case you can just re-run make
. Has been tested on macOS and Linux. Sometimes p2p_getaddr_caching.py
fails, because the number of records returned falls a few short of MAX_ADDR_TO_SEND
. Need investigating.
I’m not suggesting that this be merged as-is, or that this is the ideal way of integrating Rust code (i.e copying sources in tree, using cbindgen
), into Bitcoin Core. What I am suggesting is that the Rust discussion should continue, particularly in regards to integrations that can be done in a very non-invasive / modular fashion.
Doesn’t crash, but may catch your machine on fire 🔥, use with caution. More Rust related discussion available in #17090.