mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-04 00:12:33 +02:00
init: Sanity check LevelDB build/runtime versions
This commit is contained in:
parent
2080d467fa
commit
2e6765cd35
@ -6,18 +6,21 @@
|
||||
|
||||
#include <logging.h>
|
||||
#include <random.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <serialize.h>
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <util/fs.h>
|
||||
#include <util/fs_helpers.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <leveldb/c.h>
|
||||
#include <leveldb/cache.h>
|
||||
#include <leveldb/db.h>
|
||||
#include <leveldb/env.h>
|
||||
@ -51,6 +54,22 @@ static void HandleError(const leveldb::Status& status)
|
||||
throw dbwrapper_error(errmsg);
|
||||
}
|
||||
|
||||
bool dbwrapper_SanityCheck()
|
||||
{
|
||||
unsigned long header_version = (leveldb::kMajorVersion << 16) | leveldb::kMinorVersion;
|
||||
unsigned long library_version = (leveldb_major_version() << 16) | leveldb_minor_version();
|
||||
|
||||
if (header_version != library_version) {
|
||||
InitError(Untranslated(strprintf("Compiled with LevelDB %d.%d, but linked with LevelDB %d.%d (incompatible).",
|
||||
leveldb::kMajorVersion, leveldb::kMinorVersion,
|
||||
leveldb_major_version(), leveldb_minor_version()
|
||||
)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class CBitcoinLevelDBLogger : public leveldb::Logger {
|
||||
public:
|
||||
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
bool dbwrapper_SanityCheck();
|
||||
|
||||
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
|
||||
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <kernel/checks.h>
|
||||
|
||||
#include <dbwrapper.h>
|
||||
#include <random.h>
|
||||
#include <util/result.h>
|
||||
#include <util/translation.h>
|
||||
@ -14,6 +15,10 @@ namespace kernel {
|
||||
|
||||
util::Result<void> SanityChecks(const Context&)
|
||||
{
|
||||
if (!dbwrapper_SanityCheck()) {
|
||||
return util::Error{Untranslated("Database sanity check failure. Aborting.")};
|
||||
}
|
||||
|
||||
if (!Random_SanityCheck()) {
|
||||
return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user