diff --git a/CMakeLists.txt b/CMakeLists.txt index c71309c3..a242970b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ project(xmrig) option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON) -option(WITH_IPBC "CryptoNight-IPBC support" ON) option(WITH_HTTPD "HTTP REST API" ON) option(BUILD_STATIC "Build static binary" OFF) @@ -245,5 +244,5 @@ if (BUILD_STATIC) set(CMAKE_EXE_LINKER_FLAGS " -static") endif() -add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) -target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) +add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) +target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB}) diff --git a/src/Summary.cpp b/src/Summary.cpp index e960dd8d..fe538fda 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -39,7 +39,7 @@ static void print_versions(xmrig::Config *config) { - char buf[16]; + char buf[16] = { 0 }; # if defined(__clang__) snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); @@ -47,24 +47,22 @@ static void print_versions(xmrig::Config *config) snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # elif defined(_MSC_VER) snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); -# else - buf[0] = '\0'; # endif - - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s", - APP_VERSION, uv_version_string(), buf); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" libuv/%s%s") + : " * %-13s%s/%s libuv/%s%s", + "VERSIONS", APP_NAME, APP_VERSION, uv_version_string(), buf); } static void print_memory(xmrig::Config *config) { # ifdef _WIN32 if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s", - Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", + "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); } else { - Log::i()->text(" * HUGE PAGES: %s", Mem::isHugepagesAvailable() ? "available" : "unavailable"); + Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); } # endif } @@ -73,19 +71,20 @@ static void print_memory(xmrig::Config *config) { static void print_cpu(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU: %s (%d) %sx64 %sAES-NI", + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s (%d) %sx64 %sAES-NI", + "CPU", Cpu::brand(), Cpu::sockets(), - Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", - Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); + Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-", + Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text("\x1B[01;32m * \x1B[01;37mCPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } else { - Log::i()->text(" * CPU: %s (%d) %sx64 %sAES-NI", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); + Log::i()->text(" * %-13s%s (%d) %sx64 %sAES-NI", "CPU", Cpu::brand(), Cpu::sockets(), Cpu::isX64() ? "" : "-", Cpu::hasAES() ? "" : "-"); # ifndef XMRIG_NO_LIBCPUID - Log::i()->text(" * CPU L2/L3: %.1f MB/%.1f MB", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); + Log::i()->text(" * %-13s%.1f MB/%.1f MB", "CPU L2/L3", Cpu::l2() / 1024.0, Cpu::l3() / 1024.0); # endif } } @@ -94,27 +93,28 @@ static void print_cpu(xmrig::Config *config) static void print_threads(xmrig::Config *config) { if (config->threadsMode() != xmrig::Config::Advanced) { - char buf[32]; + char buf[32] = { 0 }; if (config->affinity() != -1L) { - snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity()); - } - else { - buf[0] = '\0'; + snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") + : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", + "THREADS", config->threadsCount(), config->algorithm().name(), config->algoVariant(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel(), buf); } else { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, %sdonate=%d%%" : " * THREADS: %d, %s, %sdonate=%d%%", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") + : " * %-13s%d, %s, %sdonate=%d%%", + "THREADS", config->threadsCount(), config->algorithm().name(), - config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", + config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "", config->donateLevel()); } } @@ -125,9 +125,11 @@ static void print_pools(xmrig::Config *config) const std::vector &pools = config->pools(); for (size_t i = 0; i < pools.size(); ++i) { - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mPOOL #%d: \x1B[01;36m%s" : " * POOL #%d: %s", + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") CYAN_BOLD("%s") " variant " WHITE_BOLD("%s") + : " * POOL #%-7d%s variant %s", i + 1, - pools[i].url() + pools[i].url(), + pools[i].algorithm().variantName() ); } @@ -147,8 +149,9 @@ static void print_api(xmrig::Config *config) return; } - Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI BIND: \x1B[01;36m%s:%d" : " * API BIND: %s:%d", - config->isApiIPv6() ? "[::]" : "0.0.0.0", port); + Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d") + : " * %-13s%s:%d", + "API BIND", config->isApiIPv6() ? "[::]" : "0.0.0.0", port); } #endif @@ -156,10 +159,12 @@ static void print_api(xmrig::Config *config) static void print_commands(xmrig::Config *config) { if (config->isColors()) { - Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume"); + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") + MAGENTA_BOLD("p") WHITE_BOLD("ause, ") + MAGENTA_BOLD("r") WHITE_BOLD("esume")); } else { - Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume"); + Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); } } diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 5eaf68fd..155485d2 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -72,6 +72,40 @@ xmrig::CommonConfig::~CommonConfig() } +bool xmrig::CommonConfig::save() +{ + if (m_fileName.isNull()) { + return false; + } + + uv_fs_t req; + const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); + if (fd < 0) { + return false; + } + + uv_fs_req_cleanup(&req); + + rapidjson::Document doc; + getJSON(doc); + + FILE *fp = fdopen(fd, "w"); + + char buf[4096]; + rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); + rapidjson::PrettyWriter writer(os); + doc.Accept(writer); + + fclose(fp); + + uv_fs_close(uv_default_loop(), &req, fd, nullptr); + uv_fs_req_cleanup(&req); + + LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); + return true; +} + + bool xmrig::CommonConfig::finalize() { if (m_state == ReadyState) { @@ -254,40 +288,6 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) } -bool xmrig::CommonConfig::save() -{ - if (m_fileName.isNull()) { - return false; - } - - uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); - if (fd < 0) { - return false; - } - - uv_fs_req_cleanup(&req); - - rapidjson::Document doc; - getJSON(doc); - - FILE *fp = fdopen(fd, "w"); - - char buf[4096]; - rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); - rapidjson::PrettyWriter writer(os); - doc.Accept(writer); - - fclose(fp); - - uv_fs_close(uv_default_loop(), &req, fd, nullptr); - uv_fs_req_cleanup(&req); - - LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); - return true; -} - - void xmrig::CommonConfig::setFileName(const char *fileName) { m_fileName = fileName; diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index d54afe3a..356f550d 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -64,6 +64,8 @@ public: inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const char *fileName() const override { return m_fileName.data(); } + bool save() override; + protected: enum State { NoneState, @@ -75,7 +77,6 @@ protected: bool parseBoolean(int key, bool enable) override; bool parseString(int key, const char *arg) override; bool parseUint64(int key, uint64_t arg) override; - bool save() override; void setFileName(const char *fileName) override; Algorithm m_algorithm; diff --git a/src/common/xmrig.h b/src/common/xmrig.h index a6fda9fc..43a2a252 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -66,6 +66,12 @@ enum Variant { }; +enum AlgoVerify { + VERIFY_HW_AES = 1, + VERIFY_SOFT_AES = 2 +}; + + enum AesMode { AES_AUTO, AES_HW, diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 4c283164..232e7024 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -116,7 +116,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value threads(kArrayType); for (const IThread *thread : m_threads.list) { - threads.PushBack(thread->toConfig(doc), doc.GetAllocator()); + threads.PushBack(thread->toConfig(doc), allocator); } doc.AddMember("threads", threads, allocator); diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 42068eb7..2a750318 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -35,7 +35,7 @@ #include "workers/Hashrate.h" -inline const char *format(double h, char* buf, size_t size) +inline static const char *format(double h, char *buf, size_t size) { if (isnormal(h)) { snprintf(buf, size, "%03.1f", h); @@ -91,6 +91,9 @@ double Hashrate::calc(size_t ms) const double Hashrate::calc(size_t threadId, size_t ms) const { assert(threadId < m_threads); + if (threadId >= m_threads) { + return nan(""); + } using namespace std::chrono; const uint64_t now = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); @@ -149,14 +152,15 @@ void Hashrate::add(size_t threadId, uint64_t count, uint64_t timestamp) } -void Hashrate::print() +void Hashrate::print() const { char num1[8] = { 0 }; char num2[8] = { 0 }; char num3[8] = { 0 }; char num4[8] = { 0 }; - LOG_INFO(m_controller->config()->isColors() ? "\x1B[01;37mspeed\x1B[0m 2.5s/60s/15m \x1B[01;36m%s \x1B[22;36m%s %s \x1B[01;36mH/s\x1B[0m max: \x1B[01;36m%s H/s" : "speed 2.5s/60s/15m %s %s %s H/s max: %s H/s", + LOG_INFO(m_controller->config()->isColors() ? WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s") + : "speed 10s/60s/15m %s %s %s H/s max %s H/s", format(calc(ShortInterval), num1, sizeof(num1)), format(calc(MediumInterval), num2, sizeof(num2)), format(calc(LargeInterval), num3, sizeof(num3)), @@ -180,6 +184,12 @@ void Hashrate::updateHighest() } +const char *Hashrate::format(double h, char *buf, size_t size) +{ + return ::format(h, buf, size); +} + + void Hashrate::onReport(uv_timer_t *handle) { static_cast(handle->data)->print(); diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index e79c757a..e766f117 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -38,7 +38,7 @@ class Hashrate { public: enum Intervals { - ShortInterval = 2500, + ShortInterval = 10000, MediumInterval = 60000, LargeInterval = 900000 }; @@ -47,13 +47,15 @@ public: double calc(size_t ms) const; double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); - void print(); + void print() const; void stop(); void updateHighest(); inline double highest() const { return m_highest; } inline size_t threads() const { return m_threads; } + static const char *format(double h, char *buf, size_t size); + private: static void onReport(uv_timer_t *handle);