-
Notifications
You must be signed in to change notification settings - Fork 38.6k
fuzz: a target for the block index database #28209
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
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
maflcko
left a comment
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, left two nits
8f26ab2 to
8a0cb8b
Compare
|
Thanks, addressed your comments. |
|
Concept ACK |
1 similar comment
|
Concept ACK |
65a107e to
c3f6289
Compare
c3f6289 to
7f6ff2f
Compare
7f6ff2f to
e626f35
Compare
|
Rebased on master to fix the macOS CI. |
|
Needs rebase if still relevant |
e626f35 to
f0ca012
Compare
|
Ok @DrahtBot. Done. |
f0ca012 to
1847309
Compare
1847309 to
1c95882
Compare
|
Added a |
1c95882 to
8083aa2
Compare
sedited
left a comment
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.
ACK ffee43efe845cbbfbf16d5e61a1d541cb316ef56
| const std::string flag_name = fuzzed_data_provider.ConsumeBytesAsString(flag_size); | ||
| bool flag_value; | ||
| block_index.WriteFlag(flag_name, true); | ||
| block_index.ReadFlag(flag_name, flag_value); |
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.
Adding something to exercise Erase would also be nice.
ffee43e to
86b3852
Compare
|
Thanks for the review, i've also rebased on top of master for fresh CI. |
sedited
left a comment
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.
Re-ACK 86b3852
|
|
||
| const BasicTestingSetup* g_setup; | ||
|
|
||
| // Hardcoded block hash and nBits to make sure the blocks we store pass the pow check. |
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.
In 86b3852: nBits is not hardcoded anymore.
| // Hardcoded block hash and nBits to make sure the blocks we store pass the pow check. | |
| // Hardcoded block hash to make sure the blocks we store pass the pow check. |
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 is. (At least the code I reviewed locally)
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.
Yes, but not here as done before.
before:
// Hardcoded block hash and nBits to make sure the blocks we store pass the pow check.
const uint256 g_block_hash{uint256S("000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9")};
uint32_t g_bits{0x1d00ffff};anyway, feel free to ignore it.
maflcko
left a comment
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.
left some style-nits, feel free to ignore. lgtm
review ACK 86b3852 🥒
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 86b38529d5014612c3e7bb59fdc4dad3bff2aa64 🥒
cjVCcUx/BhmdYxcriNMuwwyayOaGH23QYrgOlQYTjyrvNxUXvUDplvgUguxjMPrdahNSoffgh3ITZYRvtcHNCg==
| #include <test/fuzz/fuzz.h> | ||
| #include <test/fuzz/util.h> | ||
| #include <test/util/setup_common.h> | ||
| #include <txdb.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.
style-nit: txdb.h is CCoinsViewDB (chainstate/), but you are fuzzing BlockTreeDB (blocks/index/).
Maybe just:
test/fuzz/block_index.cpp should add these lines:
#include <cassert> // for assert
#include <functional> // for function
#include <memory> // for unique_ptr, make_unique
#include <optional> // for optional
#include <string> // for string
#include <utility> // for pair, move
#include <vector> // for vector
#include "consensus/params.h" // for Params
#include "dbwrapper.h" // for DBParams
#include "primitives/block.h" // for CBlockHeader, CBlock
#include "sync.h" // for MaybeCheckNotHeld, UniqueLock, WITH_LOCK
#include "uint256.h" // for uint256
#include "util/fs.h" // for path
test/fuzz/block_index.cpp should remove these lines:
- #include <txdb.h> // lines 12-12
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.
Not sure why i have this include here, i'll just copy what you suggest.
| @@ -0,0 +1,133 @@ | |||
| // Copyright (c) 2023 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.
style-nit, to pre-empt touching this file on (or after) future changes.
| // Copyright (c) 2023 The Bitcoin Core developers | |
| // Copyright (c) 2023-present The Bitcoin Core developers |
|
|
||
| void init_block_index() | ||
| { | ||
| static const auto testing_setup = MakeNoLogFileContext<>(ChainType::MAIN); |
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.
q/nit: Any reason to use MAIN here, instead of the default, or a test-net?
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 don't think there is any difference, i just default to test against mainnet when possible. On the other hand it sometimes makes sense to default to regtest instead (for instance in the context of a fuzz target touching validation it would enable the codepaths for all soft forks). So, yeah, 🤷.
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.
Actually i think i can get rid of this now, and just disable logging like i do like in #29158.
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 just default to test against mainnet when possible.
I do the opposite 😅 , so that a corrupt test is less likely to corrupt a developers (default) main datadir for their testing by accident, but no strong opinion. Just a style-nit in any case.
(Even if you disable the logging manually, I presume you'll have to select a network) But if it works without, then it is fine as well.
|
Thanks for the review everyone. Maintainers: there is still a determinism issue here as per Niklas, which i have yet to re-reproduce.
…-------- Original Message --------
On 8/7/24 4:16 PM, Bruno Garcia wrote:
@brunoerg commented on this pull request.
---------------------------------------------------------------
In [src/test/fuzz/block_index.cpp](#28209 (comment)):
> +
+#include <chain.h>
+#include <chainparams.h>
+#include <node/blockstorage.h>
+#include <test/fuzz/FuzzedDataProvider.h>
+#include <test/fuzz/fuzz.h>
+#include <test/fuzz/util.h>
+#include <test/util/setup_common.h>
+#include <txdb.h>
+#include <validation.h>
+
+namespace {
+
+const BasicTestingSetup* g_setup;
+
+// Hardcoded block hash and nBits to make sure the blocks we store pass the pow check.
Yes, but not here as done before.
before:
//
Hardcoded block hash and nBits to make sure the blocks we store pass the pow check.
const
uint256 g_block_hash{
uint256S
(
"
000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9
"
)};
uint32_t
g_bits{
0x1d00ffff
};
anyway, feel free to ignore it.
—
Reply to this email directly, [view it on GitHub](#28209 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AFLK3F74IQUKD7UY52RWYFTZQIT5VAVCNFSM6AAAAAA3CSR3DWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMRVGMZTOMJYGU).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Are you sure? I think may be confused with #28216 (comment) ? Even if not, I wonder if stability is a hard blocker for a fuzz target. Obviously, it should be fixed, but this can be done in a follow-up, if the fuzz target otherwise makes sense to merge. |
Iirc, I pinged Antoine for both PRs on irc. I also don't think the stability needs to be a blocker. |
brunoerg
left a comment
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 86b3852
|
ACK 86b3852 |
|
Ported to the CMake-based build system in hebasto#334. |
86b3852 qa: a fuzz target for the block index database (Antoine Poinsot) Pull request description: This introduces a small fuzz target for `CBlockTreeDB` which asserts a few invariants by using an in-memory LevelDb. ACKs for top commit: achow101: ACK 86b3852 TheCharlatan: Re-ACK 86b3852 maflcko: review ACK 86b3852 🥒 brunoerg: utACK 86b3852 Tree-SHA512: ab75b4ae1c7e0a4b15f8a6ceffdf509fbc79833e6ea073ecef68558d53b83663d1b30362aaa2d77c22b8890a572f5b1d4b1c5abbca483c8c8f9b1fb5b276a59a
This introduces a small fuzz target for
CBlockTreeDBwhich asserts a few invariants by using an in-memory LevelDb.