99#include < net_processing.h>
1010#include < pow.h>
1111#include < protocol.h>
12+ #include < random.h>
1213#include < script/script.h>
1314#include < streams.h>
1415#include < sync.h>
2324#include < test/util/txmempool.h>
2425#include < test/util/validation.h>
2526#include < util/fs_helpers.h>
27+ #include < util/strencodings.h>
2628#include < util/time.h>
2729#include < validationinterface.h>
2830
3234#include < utility>
3335#include < vector>
3436
37+ using namespace util ::hex_literals;
38+
3539namespace {
3640
3741// ! Fee each created tx will pay.
@@ -64,12 +68,29 @@ class FuzzedCBlockHeaderAndShortTxIDs : public CBlockHeaderAndShortTxIDs
6468 shorttxids.erase (shorttxids.begin () + index);
6569 }
6670};
71+ // ! Class to delete the statically-named datadir at the end of a fuzzing run.
72+ class FuzzedDirectoryWrapper
73+ {
74+ private:
75+ fs::path staticdir;
76+
77+ public:
78+ FuzzedDirectoryWrapper (fs::path name) : staticdir(name) {}
79+
80+ ~FuzzedDirectoryWrapper ()
81+ {
82+ fs::remove_all (staticdir);
83+ }
84+ };
6785
6886} // namespace
6987
7088void initialize_cmpctblock () {
89+ FastRandomContext ctx;
90+
7191 std::string testdatadir = " -testdatadir=" ;
72- g_cached_path = fs::temp_directory_path () / " cmpctblock_cached" ;
92+ std::string staticdir = " cmpctblock_cached" + HexStr (ctx.randbytes (10 ));
93+ g_cached_path = fs::temp_directory_path () / staticdir;
7394 auto cached_datadir_arg = testdatadir + g_cached_path.string ();
7495
7596 const auto initial_setup = MakeNoLogFileContext<const TestingSetup>(
@@ -78,6 +99,8 @@ void initialize_cmpctblock() {
7899 .coins_db_in_memory = false ,
79100 .block_tree_db_in_memory = false });
80101
102+ static const FuzzedDirectoryWrapper wrapper (g_cached_path);
103+
81104 SetMockTime (Params ().GenesisBlock ().Time ());
82105
83106 node::BlockAssembler::Options options;
0 commit comments