Skip to content

Commit

Permalink
Port block storage
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Jun 19, 2024
1 parent e13a643 commit 1202459
Show file tree
Hide file tree
Showing 14 changed files with 542 additions and 18 deletions.
48 changes: 41 additions & 7 deletions src/common/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <utility>
#include <variant>

const char * const BITCOIN_CONF_FILENAME = "bitcoin.conf";
const char * const BITCOIN_CONF_FILENAME = "qtum.conf";
const char * const BITCOIN_SETTINGS_FILENAME = "settings.json";

ArgsManager gArgs;
Expand Down Expand Up @@ -684,12 +684,12 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message

fs::path GetDefaultDataDir()
{
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
// macOS: ~/Library/Application Support/Bitcoin
// Unix-like: ~/.bitcoin
// Windows: C:\Users\Username\AppData\Roaming\Qtum
// macOS: ~/Library/Application Support/Qtum
// Unix-like: ~/.qtum
#ifdef WIN32
// Windows
return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
return GetSpecialFolderPath(CSIDL_APPDATA) / "Qtum";
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
Expand All @@ -699,10 +699,10 @@ fs::path GetDefaultDataDir()
pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// macOS
return pathRet / "Library/Application Support/Bitcoin";
return pathRet / "Library/Application Support/Qtum";
#else
// Unix-like
return pathRet / ".bitcoin";
return pathRet / ".qtum";
#endif
#endif
}
Expand Down Expand Up @@ -818,6 +818,40 @@ void ArgsManager::LogArgs() const
logArgsPrefix("Command-line arg:", "", m_settings.command_line_options);
}

std::map<std::string, std::vector<std::string>> ArgsManager::getArgsList(const std::vector<std::string>& paramListType) const
{
LOCK(cs_args);
// Get argument list
std::map<std::string, bool> args;
for (const auto& arg : m_settings.forced_settings) {
args[arg.first] = true;
}
for (const auto& arg : m_settings.command_line_options) {
args[arg.first] = true;
}
for (const auto& arg : m_settings.ro_config) {
for(const auto& confArg : arg.second)
args[confArg.first] = true;
}

// Fill argument list with values
std::map<std::string, std::vector<std::string>> ret;
for (const auto& arg : args) {
std::string paramName = '-' + arg.first;
std::vector<std::string> paramValue;
bool isList = std::find(std::begin(paramListType), std::end(paramListType), paramName) != std::end(paramListType);
if(isList) {
paramValue = GetArgs(paramName);
}
else {
paramValue.push_back(GetArg(paramName, ""));
}
ret[arg.first] = paramValue;
}

return ret;
}

namespace common {
#ifdef WIN32
WinCmdLineArgs::WinCmdLineArgs()
Expand Down
5 changes: 5 additions & 0 deletions src/common/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ class ArgsManager
*/
void LogArgs() const;

/**
* Return config arguments
*/
std::map<std::string, std::vector<std::string>> getArgsList(const std::vector<std::string>& paramListType) const;

private:
/**
* Get data directory path
Expand Down
9 changes: 9 additions & 0 deletions src/common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <compat/compat.h>
#include <codecvt>
#endif
#include <iomanip>

#ifdef HAVE_MALLOPT_ARENA_MAX
#include <malloc.h>
Expand Down Expand Up @@ -105,6 +106,14 @@ int GetNumCores()
return std::thread::hardware_concurrency();
}

bool CheckHex(const std::string& str) {
size_t data=0;
if(str.size() > 2 && (str.compare(0, 2, "0x") == 0 || str.compare(0, 2, "0X") == 0)){
data=2;
}
return str.size() > data && str.find_first_not_of("0123456789abcdefABCDEF", data) == std::string::npos;
}

// Obtain the application startup time (used for uptime calculation)
int64_t GetStartupTime()
{
Expand Down
32 changes: 32 additions & 0 deletions src/common/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#include <cstdint>
#include <string>

#ifndef WIN32
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#endif

// Application startup time (used for uptime calculation)
int64_t GetStartupTime();

Expand All @@ -31,4 +37,30 @@ void runCommand(const std::string& strCommand);
*/
int GetNumCores();

#ifdef WIN32
inline void SetThreadPriority(int nPriority)
{
SetThreadPriority(GetCurrentThread(), nPriority);
}
#else

#define THREAD_PRIORITY_LOWEST PRIO_MAX
#define THREAD_PRIORITY_BELOW_NORMAL 2
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_ABOVE_NORMAL 0

inline void SetThreadPriority(int nPriority)
{
// It's unclear if it's even possible to change thread priorities on Linux,
// but we really and truly need it for the generation threads.
#ifdef PRIO_THREAD
setpriority(PRIO_THREAD, 0, nPriority);
#else
setpriority(PRIO_PROCESS, 0, nPriority);
#endif
}
#endif

bool CheckHex(const std::string& str);

#endif // BITCOIN_COMMON_SYSTEM_H
8 changes: 4 additions & 4 deletions src/crypto/muhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void Num3072::Divide(const Num3072& a)
if (this->IsOverflow()) this->FullReduce();
}

Num3072::Num3072(const unsigned char (&data)[BYTE_SIZE]) {
Num3072::Num3072(const unsigned char (&data)[DATA_BYTE_SIZE]) {
for (int i = 0; i < LIMBS; ++i) {
if (sizeof(limb_t) == 4) {
this->limbs[i] = ReadLE32(data + 4 * i);
Expand All @@ -285,7 +285,7 @@ Num3072::Num3072(const unsigned char (&data)[BYTE_SIZE]) {
}
}

void Num3072::ToBytes(unsigned char (&out)[BYTE_SIZE]) {
void Num3072::ToBytes(unsigned char (&out)[DATA_BYTE_SIZE]) {
for (int i = 0; i < LIMBS; ++i) {
if (sizeof(limb_t) == 4) {
WriteLE32(out + i * 4, this->limbs[i]);
Expand All @@ -296,7 +296,7 @@ void Num3072::ToBytes(unsigned char (&out)[BYTE_SIZE]) {
}

Num3072 MuHash3072::ToNum3072(Span<const unsigned char> in) {
unsigned char tmp[Num3072::BYTE_SIZE];
unsigned char tmp[Num3072::DATA_BYTE_SIZE];

uint256 hashed_in{(HashWriter{} << in).GetSHA256()};
static_assert(sizeof(tmp) % ChaCha20Aligned::BLOCKLEN == 0);
Expand All @@ -316,7 +316,7 @@ void MuHash3072::Finalize(uint256& out) noexcept
m_numerator.Divide(m_denominator);
m_denominator.SetToOne(); // Needed to keep the MuHash object valid

unsigned char data[Num3072::BYTE_SIZE];
unsigned char data[Num3072::DATA_BYTE_SIZE];
m_numerator.ToBytes(data);

out = (HashWriter{} << data).GetSHA256();
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/muhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Num3072
Num3072 GetInverse() const;

public:
static constexpr size_t BYTE_SIZE = 384;
static constexpr size_t DATA_BYTE_SIZE = 384;

#ifdef __SIZEOF_INT128__
typedef unsigned __int128 double_limb_t;
Expand All @@ -45,10 +45,10 @@ class Num3072
void Divide(const Num3072& a);
void SetToOne();
void Square();
void ToBytes(unsigned char (&out)[BYTE_SIZE]);
void ToBytes(unsigned char (&out)[DATA_BYTE_SIZE]);

Num3072() { this->SetToOne(); };
Num3072(const unsigned char (&data)[BYTE_SIZE]);
Num3072(const unsigned char (&data)[DATA_BYTE_SIZE]);

SERIALIZE_METHODS(Num3072, obj)
{
Expand Down
2 changes: 1 addition & 1 deletion src/init/bitcoin-gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace init {
namespace {
const char* EXE_NAME = "bitcoin-gui";
const char* EXE_NAME = "qtum-gui";

class BitcoinGuiInit : public interfaces::Init
{
Expand Down
2 changes: 1 addition & 1 deletion src/init/bitcoin-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace init {
namespace {
const char* EXE_NAME = "bitcoin-node";
const char* EXE_NAME = "qtum-node";

class BitcoinNodeInit : public interfaces::Init
{
Expand Down
8 changes: 8 additions & 0 deletions src/init/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <util/string.h>
#include <util/time.h>
#include <util/translation.h>
#include <libdevcore/Log.h>

#include <algorithm>
#include <string>
Expand Down Expand Up @@ -48,6 +49,7 @@ void AddLoggingArgs(ArgsManager& argsman)
void SetLoggingOptions(const ArgsManager& args)
{
LogInstance().m_print_to_file = !args.IsArgNegated("-debuglogfile");
LogInstance().m_file_pathVM = AbsPathForConfigVal(args, args.GetPathArg("-debugvmlogfile", DEFAULT_DEBUGVMLOGFILE));
LogInstance().m_file_path = AbsPathForConfigVal(args, args.GetPathArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", !args.GetBoolArg("-daemon", false));
LogInstance().m_log_timestamps = args.GetBoolArg("-logtimestamps", DEFAULT_LOGTIMESTAMPS);
Expand All @@ -57,6 +59,8 @@ void SetLoggingOptions(const ArgsManager& args)
#endif
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
LogInstance().m_always_print_category_level = args.GetBoolArg("-loglevelalways", DEFAULT_LOGLEVELALWAYS);
LogInstance().m_show_evm_logs = args.GetBoolArg("-showevmlogs", DEFAULT_SHOWEVMLOGS);
dev::g_logPost = [&](std::string const& s, char const* c){ LogInstance().LogPrintStr(s + '\n', c ? c : "", "", 0, BCLog::ALL, BCLog::Level::Debug, true); };

fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
}
Expand Down Expand Up @@ -121,6 +125,10 @@ bool StartLogging(const ArgsManager& args)
fs::PathToString(LogInstance().m_file_path)));
}

////////////////////////////////////////////////////////////////////// // qtum
dev::g_logPost(std::string("\n\n\n\n\n\n\n\n\n\n"), NULL);
//////////////////////////////////////////////////////////////////////

if (!LogInstance().m_log_timestamps)
LogPrintf("Startup time: %s\n", FormatISO8601DateTime(GetTime()));
LogPrintf("Default data directory %s\n", fs::PathToString(GetDefaultDataDir()));
Expand Down
3 changes: 2 additions & 1 deletion src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <optional>

const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
const char * const DEFAULT_DEBUGVMLOGFILE = "vm.log";
constexpr auto MAX_USER_SETABLE_SEVERITY_LEVEL{BCLog::Level::Info};

BCLog::Logger& LogInstance()
Expand Down Expand Up @@ -414,7 +415,7 @@ std::string BCLog::Logger::GetLogPrefix(BCLog::LogFlags category, BCLog::Level l
return s;
}

void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level)
void BCLog::Logger::LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level, bool useVMLog)
{
StdLockGuard scoped_lock(m_cs);
std::string str_prefixed = LogEscapeMessage(str);
Expand Down
4 changes: 3 additions & 1 deletion src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ namespace BCLog {
bool m_log_threadnames = DEFAULT_LOGTHREADNAMES;
bool m_log_sourcelocations = DEFAULT_LOGSOURCELOCATIONS;
bool m_always_print_category_level = DEFAULT_LOGLEVELALWAYS;
bool m_show_evm_logs = DEFAULT_SHOWEVMLOGS;

fs::path m_file_path;
fs::path m_file_pathVM;
std::atomic<bool> m_reopen_file{false};

std::string GetLogPrefix(LogFlags category, Level level) const;

/** Send a string to the log output */
void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level);
void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level, bool useVMLog = false);

/** Returns whether logs will be written to any output */
bool Enabled() const
Expand Down
Loading

0 comments on commit 1202459

Please sign in to comment.