Skip to content

Commit

Permalink
Adds -leveldebchecksum argument (#1669)
Browse files Browse the repository at this point in the history
* Adds -leveldebchecksum argument

* Use level DB checksum global bool

Co-authored-by: Peter Bushnell <[email protected]>
  • Loading branch information
dcorral and Bushstar authored Jan 13, 2023
1 parent 26f8834 commit 94b7e16
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <stdint.h>
#include <algorithm>

bool levelDBChecksum{true};

class CDefiLevelDBLogger : public leveldb::Logger {
public:
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
Expand Down Expand Up @@ -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<size_t>(64)
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
15 changes: 15 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}
}
}

/**
Expand Down
15 changes: 14 additions & 1 deletion test/lint/check-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 94b7e16

Please sign in to comment.