-
Notifications
You must be signed in to change notification settings - Fork 36.1k
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
Index for BIP 157 block filters #14121
Conversation
1eeef83
to
1c20791
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
src/index/blockfilter.cpp
Outdated
std::make_pair(pindex->GetBlockHash(), filter.GetHash())); | ||
batch.Write(std::make_pair(DB_FILTER_HEADER, height_key), | ||
std::make_pair(pindex->GetBlockHash(), filter.ComputeHeader(prev_header))); | ||
return m_db->WriteBatch(batch); |
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.
Out of scope for this PR, but is there a reason we can't write a batch of entries for more than a single block? Could we write 100 - 1000 blocks worth of entries in each batch write to speed up the migrations? This introduces some complexity, but perhaps it's worth 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.
Could be worth looking into during ThreadSync. As you note though, it's a fairly independent change.
Storing large records in leveldb is generally a bad idea. Is there a particular reason this doesn't work like the undo data? |
@gmaxwell If by that you mean writing the filters sequentially in flat files then indexing the disk positions in LevelDB, I hadn't considered that, but it may be worthwhile. The downside of course is additional complexity. What are you mostly concerned about, read or write performance? I'd want to benchmark reads and writes to determine if the DB value sizes are problematic before making the change. With filters on average being 2% of block size and a LevelDB file size limit of 2 MiB, each file could still store ~200 filters (ignoring keys and overhead and such). |
@gmaxwell I put together a (not-production-ready) branch to test your suggestion of writing filters to flat files. In sample size n=1 experiments, I measured that the time to write the entire block index was <1% faster using flat files, and reading 5,000 sequential filters (starting at height 500,000) was 11% slower. The total storage space consumed is nearly the same (3.4 GiB total). Happy to provide the log files/iPython notebooks I used if you'd like. Given the additional complexity and absence of significantly improved performance, I think writing filters directly into LevelDB is the way to go. |
5aebbb9
to
9b1e7a6
Compare
src/blockfilter.h
Outdated
@@ -44,19 +54,16 @@ class GCSFilter | |||
public: | |||
|
|||
/** Constructs an empty filter. */ | |||
GCSFilter(uint64_t siphash_k0 = 0, uint64_t siphash_k1 = 0, uint8_t P = 0, uint32_t M = 0); | |||
GCSFilter(const Params& params = Params()); |
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.
Please make explicit
:-)
src/index/blockfilter.cpp
Outdated
|
||
bool BlockFilterIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip) | ||
{ | ||
assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip); |
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.
Assertions should not have side effects. Please move GetAncestor
outside of assertion :-)
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.
What is the side effect? GetAncestor
is a const
method.
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.
@jimpo You're right! Forget my comment :-)
src/blockfilter.h
Outdated
uint32_t GetN() const { return m_N; } | ||
uint32_t GetM() const { return m_M; } | ||
const Params& GetParams() const { return m_params; } |
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.
Remove GetParams()
? Not used?
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.
No, it's not used, but it feels like there should be a getter.
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.
Unused code is untested code, so I suggest removing it or adding a test for it :-)
self.num_nodes = 2 | ||
self.extra_args = [["-blockfilterindex"], []] | ||
|
||
def run_test (self): |
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.
./test/functional/rpc_getblockfilter.py:21:17: E211 whitespace before '('
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.
Can you mention -blockfilterindex
and getblockfilter
in the PR description, as well as perhaps add a release note?
It's nice to be able to quickly delete an index, so having a separate file for each type makes sense to me (as is the case now: indexes/blockindex/basic/...
).
Lightly tested on macOS. I get a few mismatching headers compared to the test vectors:
src/bitcoin-cli getblockfilter 00000000fd3ceb2404ff07a785c7fdcc76619edc8ed61bd25134eaa22084366a "basic"
{
"filter": "0db414c859a07e8205876354a210a75042d0463404913d61a8e068e58a3ae2aa080026",
"header": "c582d51c0ca365e3fcf36c51cb646d7f83a67e867cb4743fd2128e3e022b700c"
}
000000000000015d6077a411a8f5cc95caf775ccf11c54e27df75ce58d187313
-> "header": "546c574a0472144bcaf9b6aeabf26372ad87c7af7d1ee0dbfae5e099abeae49c"
0000000000000c00901f2049055e2a437c819d79a3d54fd63e6af796cd7b8a79
-> "header": "0965a544743bbfa36f254446e75630c09404b3d164a261892372977538928ed5
The filters do match.
We should probably include those test vectors. In addition, it would be nice to have script to compare every single block with the btcd RPC, testnet and mainnet.
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.
good idea
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@4368384 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6332
Summary: This is partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@62b7a4f Depends on D6332 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6333
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@ba6ff9a Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6335
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@75a76e3 Depends on D6335 and D6333 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6337
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@b5e8200 Depends on D6338 and D6337 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D6339
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@6bcf099 Depends on D6339 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D6340
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@2bc90e4 Depends on D6340 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D6341
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@accc8b8 Depends on D6341 and D6344 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6345
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@ff35105 Depends on D6345 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6346
Summary: Retrieves and returns block filter and header from index. This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@19308c9 Depends on D6346 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Subscribers: jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6349
Summary: New tests for the case of non-standard OP_RETURN outputs. This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@c7efb65 Depends on D6349 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6351
Summary: This is a partial backport of Core [[bitcoin/bitcoin#14121 | PR14121]] : bitcoin/bitcoin@4368384 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D6332
Summary: This is a partial backport of Core [PR14121](bitcoin/bitcoin#14121) - `ba6ff9a6f70139594362b4b4a6b816707bb165c8` Test Plan: ``` ninja all check-all ``` Differential Revision: https://reviews.bitcoinabc.org/D6335
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
merge bitcoin#15118, bitcoin#14172, bitcoin#15623, bitcoin#14121, partial bitcoin#13743, partial bitcoin#15280: block filters
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
…_tests 89e8df1 tests: fix outdate include in blockfilter_index_tests (James O'Beirne) Pull request description: Build is currently failing due to bad merge of bitcoin#15788 and bitcoin#14121. ACKs for commit 89e8df: fanquake: tACK 89e8df1 Tree-SHA512: d3fea861f80d660b4a2827ca7241237311b68de4175d3db938a9a1d538e1325822410c98d84ba0734208af8163fbcc42cf2732788311ea22f3834c95eeb330b8
This introduces a new BlockFilterIndex class, which is required for BIP 157 support.
The index is uses the asynchronous BaseIndex infrastructure driven by the ValidationInterface callbacks. Filters are stored sequentially in flat files and the disk location of each filter is indexed in LevelDB along with the filter hash and header. The index is designed to ensure persistence of filters reorganized out of the main chain to simplify the BIP 157 net implementation.
Stats (block height = 565500):