From 94b7e1688aa8ab6728dbc39a61305c5d8f34ecc4 Mon Sep 17 00:00:00 2001 From: dCorral <55594560+dcorral@users.noreply.github.com> Date: Fri, 13 Jan 2023 10:18:12 +0100 Subject: [PATCH] Adds -leveldebchecksum argument (#1669) * Adds -leveldebchecksum argument * Use level DB checksum global bool Co-authored-by: Peter Bushnell --- src/dbwrapper.cpp | 8 +++++++- src/dbwrapper.h | 3 +++ src/init.cpp | 15 +++++++++++++++ test/lint/check-doc.py | 15 ++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index a3a770e2978..f8bc56a1482 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -14,6 +14,8 @@ #include #include +bool levelDBChecksum{true}; + class CDefiLevelDBLogger : public leveldb::Logger { public: // This code is adapted from posix_logger.h, which is why it is using vsprintf. @@ -105,7 +107,7 @@ static leveldb::Options GetOptions(size_t nCacheSize) v++; return v; }; - + leveldb::Options options; options.block_cache = leveldb::NewLRUCache(nCacheSize / 2); options.write_buffer_size = ceil_power_of_two(std::min(static_cast(64) @@ -132,6 +134,10 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo syncoptions.sync = true; options = GetOptions(nCacheSize); options.create_if_missing = true; + + readoptions.verify_checksums = levelDBChecksum; + iteroptions.verify_checksums = levelDBChecksum; + if (fMemory) { penv = leveldb::NewMemEnv(leveldb::Env::Default()); options.env = penv; diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 8cb4ef56da8..9823603c238 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -18,6 +18,9 @@ static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64; static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024; +static const std::string DEFAULT_LEVELDB_CHECKSUM = "auto"; + +extern bool levelDBChecksum; class dbwrapper_error : public std::runtime_error { diff --git a/src/init.cpp b/src/init.cpp index 12aaca3120c..f27be70b625 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -944,6 +944,21 @@ void InitParameterInteraction() if (gArgs.SoftSetBoolArg("-whitelistrelay", true)) LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__); } + + // Parse leveldb checksum + const auto checksumArg = gArgs.GetArg("-leveldbchecksum", DEFAULT_LEVELDB_CHECKSUM); + if (checksumArg == "true"){ + levelDBChecksum = true; + } else if (checksumArg == "false") { + levelDBChecksum = false; + } else { + if (checksumArg != "auto"){ + InitWarning("Invalid value for -leveldbchecksum, setting default value -> 'auto'"); + } + if (levelDBChecksum = gArgs.IsArgSet("-masternode_operator"); levelDBChecksum) { + LogPrintf("%s: parameter interaction: -masternode_operator -> setting -leveldbchecksum='true'\n", __func__); + } + } } /** diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py index 7e9e150c6b6..bbf57f706bd 100755 --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -23,7 +23,20 @@ CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR) CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR) # list unsupported, deprecated and duplicate args as they need no documentation -SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb', '-interrupt-block', '-stop-block', '-mocknet', '-mocknet-key', '-mocknet-blocktime', '-checkpoints-file', '-negativeinterest']) +SET_DOC_OPTIONAL = set([ + '-h', + '-help', + '-dbcrashratio', + '-forcecompactdb', + '-leveldbchecksum', + '-interrupt-block', + '-stop-block', + '-mocknet', + '-mocknet-key', + '-mocknet-blocktime', + '-checkpoints-file', + '-negativeinterest', + ]) def lint_missing_argument_documentation():