Merge branch 'dev'

This commit is contained in:
XMRig 2018-06-11 16:05:57 +07:00
commit 7f169e391d
59 changed files with 669 additions and 390 deletions

View file

@ -1,3 +1,13 @@
# v2.6.3
- **Added support for new cryptonight-heavy variant xhv** (`cn-heavy/xhv`) for upcoming Haven Protocol fork.
- **Added support for new cryptonight variant msr** (`cn/msr`) also known as `cryptonight-fast` for upcoming Masari fork.
- [#446](https://github.com/xmrig/xmrig/issues/446) Likely fixed SIGBUS error on 32 bit ARM CPUs.
- [#551](https://github.com/xmrig/xmrig/issues/551) Fixed `cn-heavy` algorithm on ARMv8.
- [#614](https://github.com/xmrig/xmrig/issues/614) Fixed display issue with huge pages percentage when colors disabled.
- [#615](https://github.com/xmrig/xmrig/issues/615) Fixed build without libcpuid.
- [#629](https://github.com/xmrig/xmrig/pull/629) Fixed file logging with non-seekable files.
- [#672](https://github.com/xmrig/xmrig/pull/672) Reverted back `cryptonight-light` and exit if no valid algorithm specified.
# v2.6.2 # v2.6.2
- [#607](https://github.com/xmrig/xmrig/issues/607) Fixed donation bug. - [#607](https://github.com/xmrig/xmrig/issues/607) Fixed donation bug.
- [#610](https://github.com/xmrig/xmrig/issues/610) Fixed ARM build. - [#610](https://github.com/xmrig/xmrig/issues/610) Fixed ARM build.

View file

@ -4,7 +4,6 @@ project(xmrig)
option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_AEON "CryptoNight-Lite support" ON)
option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_SUMO "CryptoNight-Heavy support" ON)
option(WITH_IPBC "CryptoNight-IPBC support" ON)
option(WITH_HTTPD "HTTP REST API" ON) option(WITH_HTTPD "HTTP REST API" ON)
option(BUILD_STATIC "Build static binary" OFF) option(BUILD_STATIC "Build static binary" OFF)
@ -21,6 +20,15 @@ set(HEADERS
src/common/Console.h src/common/Console.h
src/common/crypto/Algorithm.h src/common/crypto/Algorithm.h
src/common/crypto/keccak.h src/common/crypto/keccak.h
src/common/interfaces/IClientListener.h
src/common/interfaces/IConfig.h
src/common/interfaces/IConfigCreator.h
src/common/interfaces/IConsoleListener.h
src/common/interfaces/IControllerListener.h
src/common/interfaces/ILogBackend.h
src/common/interfaces/IStrategy.h
src/common/interfaces/IStrategyListener.h
src/common/interfaces/IWatcherListener.h
src/common/log/ConsoleLog.h src/common/log/ConsoleLog.h
src/common/log/FileLog.h src/common/log/FileLog.h
src/common/log/Log.h src/common/log/Log.h
@ -36,21 +44,11 @@ set(HEADERS
src/common/utils/c_str.h src/common/utils/c_str.h
src/common/utils/mm_malloc.h src/common/utils/mm_malloc.h
src/common/xmrig.h src/common/xmrig.h
src/core/Config.cpp
src/core/ConfigLoader_platform.h src/core/ConfigLoader_platform.h
src/core/Controller.h src/core/Controller.h
src/Cpu.h src/Cpu.h
src/interfaces/IClientListener.h
src/interfaces/IConfig.h
src/interfaces/IConfigCreator.h
src/interfaces/IConsoleListener.h
src/interfaces/IControllerListener.h
src/interfaces/IJobResultListener.h src/interfaces/IJobResultListener.h
src/interfaces/ILogBackend.h
src/interfaces/IStrategy.h
src/interfaces/IStrategyListener.h
src/interfaces/IThread.h src/interfaces/IThread.h
src/interfaces/IWatcherListener.h
src/interfaces/IWorker.h src/interfaces/IWorker.h
src/Mem.h src/Mem.h
src/net/JobResult.h src/net/JobResult.h
@ -246,5 +244,5 @@ if (BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS " -static") set(CMAKE_EXE_LINKER_FLAGS " -static")
endif() endif()
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES}) add_executable(${PROJECT_NAME} ${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}) target_link_libraries(${PROJECT_NAME} ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})

View file

@ -28,7 +28,7 @@
#include <uv.h> #include <uv.h>
#include "interfaces/IConsoleListener.h" #include "common/interfaces/IConsoleListener.h"
class Console; class Console;

View file

@ -47,8 +47,11 @@ void Cpu::initCommon()
{ {
memcpy(m_brand, "Unknown", 7); memcpy(m_brand, "Unknown", 7);
# if defined(XMRIG_ARMv8) # if defined (__arm64__) || defined (__aarch64__)
m_flags |= X86_64; m_flags |= X86_64;
# endif
# if __ARM_FEATURE_CRYPTO
m_flags |= AES; m_flags |= AES;
# endif # endif
} }

View file

@ -39,7 +39,7 @@
static void print_versions(xmrig::Config *config) static void print_versions(xmrig::Config *config)
{ {
char buf[16]; char buf[16] = { 0 };
# if defined(__clang__) # if defined(__clang__)
snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); 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__); snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
snprintf(buf, 16, " MSVC/%d", MSVC_VERSION); snprintf(buf, 16, " MSVC/%d", MSVC_VERSION);
# else
buf[0] = '\0';
# endif # endif
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" libuv/%s%s")
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", : " * %-13s%s/%s libuv/%s%s",
APP_VERSION, uv_version_string(), buf); "VERSIONS", APP_NAME, APP_VERSION, uv_version_string(), buf);
} }
static void print_memory(xmrig::Config *config) { static void print_memory(xmrig::Config *config) {
# ifdef _WIN32 # ifdef _WIN32
if (config->isColors()) { if (config->isColors()) {
Log::i()->text("\x1B[01;32m * \x1B[01;37mHUGE PAGES: %s", Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
Mem::isHugepagesAvailable() ? "\x1B[01;32mavailable" : "\x1B[01;31munavailable"); "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable");
} }
else { else {
Log::i()->text(" * HUGE PAGES: %s", Mem::isHugepagesAvailable() ? "available" : "unavailable"); Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable");
} }
# endif # endif
} }
@ -73,19 +71,20 @@ static void print_memory(xmrig::Config *config) {
static void print_cpu(xmrig::Config *config) static void print_cpu(xmrig::Config *config)
{ {
if (config->isColors()) { 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::brand(),
Cpu::sockets(), Cpu::sockets(),
Cpu::isX64() ? "\x1B[01;32m" : "\x1B[01;31m-", Cpu::isX64() ? "\x1B[1;32m" : "\x1B[1;31m-",
Cpu::hasAES() ? "\x1B[01;32m" : "\x1B[01;31m-"); Cpu::hasAES() ? "\x1B[1;32m" : "\x1B[1;31m-");
# ifndef XMRIG_NO_LIBCPUID # 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 # endif
} }
else { 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 # 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 # endif
} }
} }
@ -94,27 +93,28 @@ static void print_cpu(xmrig::Config *config)
static void print_threads(xmrig::Config *config) static void print_threads(xmrig::Config *config)
{ {
if (config->threadsMode() != xmrig::Config::Advanced) { if (config->threadsMode() != xmrig::Config::Advanced) {
char buf[32]; char buf[32] = { 0 };
if (config->affinity() != -1L) { if (config->affinity() != -1L) {
snprintf(buf, 32, ", affinity=0x%" PRIX64, config->affinity()); snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity());
}
else {
buf[0] = '\0';
} }
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->threadsCount(),
config->algorithm().name(), config->algorithm().name(),
config->algoVariant(), config->algoVariant(),
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
config->donateLevel(), config->donateLevel(),
buf); buf);
} }
else { 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->threadsCount(),
config->algorithm().name(), config->algorithm().name(),
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "", config->isColors() && config->donateLevel() == 0 ? "\x1B[1;31m" : "",
config->donateLevel()); config->donateLevel());
} }
} }
@ -125,9 +125,11 @@ static void print_pools(xmrig::Config *config)
const std::vector<Pool> &pools = config->pools(); const std::vector<Pool> &pools = config->pools();
for (size_t i = 0; i < pools.size(); ++i) { 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, i + 1,
pools[i].url() pools[i].url(),
pools[i].algorithm().variantName()
); );
} }
@ -147,8 +149,9 @@ static void print_api(xmrig::Config *config)
return; return;
} }
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mAPI BIND: \x1B[01;36m%s:%d" : " * API BIND: %s:%d", Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN("%s:") CYAN_BOLD("%d")
config->isApiIPv6() ? "[::]" : "0.0.0.0", port); : " * %-13s%s:%d",
"API BIND", config->isApiIPv6() ? "[::]" : "0.0.0.0", port);
} }
#endif #endif
@ -156,10 +159,12 @@ static void print_api(xmrig::Config *config)
static void print_commands(xmrig::Config *config) static void print_commands(xmrig::Config *config)
{ {
if (config->isColors()) { 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 { else {
Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume"); Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
} }
} }

View file

@ -26,7 +26,7 @@
#include "api/NetworkState.h" #include "api/NetworkState.h"
#include "interfaces/IControllerListener.h" #include "common/interfaces/IControllerListener.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"

View file

@ -38,11 +38,13 @@
xmrig::CommonConfig::CommonConfig() : xmrig::CommonConfig::CommonConfig() :
m_algorithm(CRYPTONIGHT, VARIANT_AUTO),
m_adjusted(false), m_adjusted(false),
m_apiIPv6(false), m_apiIPv6(false),
m_apiRestricted(true), m_apiRestricted(true),
m_background(false), m_background(false),
m_colors(true), m_colors(true),
m_dryRun(false),
m_syslog(false), m_syslog(false),
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
@ -72,6 +74,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<rapidjson::FileWriteStream> 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() bool xmrig::CommonConfig::finalize()
{ {
if (m_state == ReadyState) { if (m_state == ReadyState) {
@ -83,7 +119,7 @@ bool xmrig::CommonConfig::finalize()
} }
if (!m_algorithm.isValid()) { if (!m_algorithm.isValid()) {
m_algorithm.setAlgo(CRYPTONIGHT); return false;
} }
for (Pool &pool : m_pools) { for (Pool &pool : m_pools) {
@ -137,9 +173,15 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable)
case ApiIPv6Key: /* ipv6 */ case ApiIPv6Key: /* ipv6 */
m_apiIPv6 = enable; m_apiIPv6 = enable;
break;
case ApiRestrictedKey: /* restricted */ case ApiRestrictedKey: /* restricted */
m_apiRestricted = enable; m_apiRestricted = enable;
break;
case IConfig::DryRunKey: /* --dry-run */
m_dryRun = enable;
break;
default: default:
break; break;
@ -224,6 +266,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
case KeepAliveKey: /* --keepalive */ case KeepAliveKey: /* --keepalive */
case NicehashKey: /* --nicehash */ case NicehashKey: /* --nicehash */
case ApiIPv6Key: /* --api-ipv6 */ case ApiIPv6Key: /* --api-ipv6 */
case DryRunKey: /* --dry-run */
return parseBoolean(key, true); return parseBoolean(key, true);
case ColorKey: /* --no-color */ case ColorKey: /* --no-color */
@ -254,40 +297,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<rapidjson::FileWriteStream> 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) void xmrig::CommonConfig::setFileName(const char *fileName)
{ {
m_fileName = fileName; m_fileName = fileName;

View file

@ -28,10 +28,10 @@
#include <vector> #include <vector>
#include "common/interfaces/IConfig.h"
#include "common/net/Pool.h" #include "common/net/Pool.h"
#include "common/utils/c_str.h" #include "common/utils/c_str.h"
#include "common/xmrig.h" #include "common/xmrig.h"
#include "interfaces/IConfig.h"
namespace xmrig { namespace xmrig {
@ -47,8 +47,8 @@ public:
inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isApiRestricted() const { return m_apiRestricted; }
inline bool isBackground() const { return m_background; } inline bool isBackground() const { return m_background; }
inline bool isColors() const { return m_colors; } inline bool isColors() const { return m_colors; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isSyslog() const { return m_syslog; } inline bool isSyslog() const { return m_syslog; }
inline const Algorithm &algorithm() const { return m_algorithm; }
inline const char *apiToken() const { return m_apiToken.data(); } inline const char *apiToken() const { return m_apiToken.data(); }
inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *apiWorkerId() const { return m_apiWorkerId.data(); }
inline const char *logFile() const { return m_logFile.data(); } inline const char *logFile() const { return m_logFile.data(); }
@ -62,8 +62,11 @@ public:
inline void setColors(bool colors) { m_colors = colors; } inline void setColors(bool colors) { m_colors = colors; }
inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); }
inline const Algorithm &algorithm() const override { return m_algorithm; }
inline const char *fileName() const override { return m_fileName.data(); } inline const char *fileName() const override { return m_fileName.data(); }
bool save() override;
protected: protected:
enum State { enum State {
NoneState, NoneState,
@ -75,7 +78,6 @@ protected:
bool parseBoolean(int key, bool enable) override; bool parseBoolean(int key, bool enable) override;
bool parseString(int key, const char *arg) override; bool parseString(int key, const char *arg) override;
bool parseUint64(int key, uint64_t arg) override; bool parseUint64(int key, uint64_t arg) override;
bool save() override;
void setFileName(const char *fileName) override; void setFileName(const char *fileName) override;
Algorithm m_algorithm; Algorithm m_algorithm;
@ -84,6 +86,7 @@ protected:
bool m_apiRestricted; bool m_apiRestricted;
bool m_background; bool m_background;
bool m_colors; bool m_colors;
bool m_dryRun;
bool m_syslog; bool m_syslog;
bool m_watch; bool m_watch;
int m_apiPort; int m_apiPort;

View file

@ -34,12 +34,12 @@
#include "common/config/ConfigLoader.h" #include "common/config/ConfigLoader.h"
#include "common/config/ConfigWatcher.h" #include "common/config/ConfigWatcher.h"
#include "common/interfaces/IConfig.h"
#include "common/interfaces/IWatcherListener.h"
#include "common/net/Pool.h" #include "common/net/Pool.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "core/ConfigCreator.h" #include "core/ConfigCreator.h"
#include "core/ConfigLoader_platform.h" #include "core/ConfigLoader_platform.h"
#include "interfaces/IConfig.h"
#include "interfaces/IWatcherListener.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
#include "rapidjson/filereadstream.h" #include "rapidjson/filereadstream.h"
@ -170,7 +170,13 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator
} }
if (!config->finalize()) { if (!config->finalize()) {
if (!config->algorithm().isValid()) {
fprintf(stderr, "No valid algorithm specified. Exiting.\n");
}
else {
fprintf(stderr, "No valid configuration found. Exiting.\n"); fprintf(stderr, "No valid configuration found. Exiting.\n");
}
delete config; delete config;
return nullptr; return nullptr;
} }

View file

@ -27,9 +27,9 @@
#include "common/config/ConfigLoader.h" #include "common/config/ConfigLoader.h"
#include "common/config/ConfigWatcher.h" #include "common/config/ConfigWatcher.h"
#include "common/interfaces/IWatcherListener.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/ConfigCreator.h" #include "core/ConfigCreator.h"
#include "interfaces/IWatcherListener.h"
xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) :

View file

@ -57,9 +57,11 @@ static AlgoData const algorithms[] = {
{ "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 }, { "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 },
{ "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 }, { "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
{ "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL }, { "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
{ "cryptonight/msr", "cn/msr", xmrig::CRYPTONIGHT, xmrig::VARIANT_MSR },
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
{ "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
{ "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
{ "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
{ "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC }, { "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IPBC },
@ -67,6 +69,8 @@ static AlgoData const algorithms[] = {
# ifndef XMRIG_NO_SUMO # ifndef XMRIG_NO_SUMO
{ "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
{ "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
{ "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV },
# endif # endif
}; };
@ -88,7 +92,9 @@ static const char *variants[] = {
"0", "0",
"1", "1",
"ipbc", "ipbc",
"xtl" "xtl",
"msr",
"xhv"
}; };
@ -144,11 +150,6 @@ void xmrig::Algorithm::parseAlgorithm(const char *algo)
void xmrig::Algorithm::parseVariant(const char *variant) void xmrig::Algorithm::parseVariant(const char *variant)
{ {
if (m_algo == CRYPTONIGHT_HEAVY) {
m_variant = VARIANT_0;
return;
}
m_variant = VARIANT_AUTO; m_variant = VARIANT_AUTO;
for (size_t i = 0; i < ARRAY_SIZE(variants); i++) { for (size_t i = 0; i < ARRAY_SIZE(variants); i++) {
@ -162,7 +163,7 @@ void xmrig::Algorithm::parseVariant(const char *variant)
void xmrig::Algorithm::parseVariant(int variant) void xmrig::Algorithm::parseVariant(int variant)
{ {
if (variant >= VARIANT_AUTO && variant <= VARIANT_XTL) { if (variant >= VARIANT_AUTO && variant < VARIANT_MAX) {
m_variant = static_cast<Variant>(variant); m_variant = static_cast<Variant>(variant);
} }
else { else {
@ -174,10 +175,6 @@ void xmrig::Algorithm::parseVariant(int variant)
void xmrig::Algorithm::setAlgo(Algo algo) void xmrig::Algorithm::setAlgo(Algo algo)
{ {
m_algo = algo; m_algo = algo;
if (m_algo == CRYPTONIGHT_HEAVY) {
m_variant = VARIANT_0;
}
} }

View file

@ -24,6 +24,7 @@
#define __ICONFIG_H__ #define __ICONFIG_H__
#include "common/crypto/Algorithm.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
@ -77,6 +78,12 @@ public:
ThreadsKey = 't', ThreadsKey = 't',
HardwareAESKey = 1011, HardwareAESKey = 1011,
// xmrig amd
OclPlatform = 1400,
OclAffinity = 1401,
OclDevices = 1402,
OclLaunch = 1403,
// xmrig-proxy // xmrig-proxy
AccessLogFileKey = 'A', AccessLogFileKey = 'A',
BindKey = 'b', BindKey = 'b',
@ -97,6 +104,7 @@ public:
virtual bool parseString(int key, const char *arg) = 0; virtual bool parseString(int key, const char *arg) = 0;
virtual bool parseUint64(int key, uint64_t arg) = 0; virtual bool parseUint64(int key, uint64_t arg) = 0;
virtual bool save() = 0; virtual bool save() = 0;
virtual const Algorithm &algorithm() const = 0;
virtual const char *fileName() const = 0; virtual const char *fileName() const = 0;
virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void getJSON(rapidjson::Document &doc) const = 0;
virtual void parseJSON(const rapidjson::Document &doc) = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0;

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -26,14 +26,29 @@
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
class ILogBackend class ILogBackend
{ {
public: public:
enum Level {
ERR,
WARNING,
NOTICE,
INFO,
DEBUG
};
# ifdef APP_DEBUG
constexpr static const size_t kBufferSize = 1024;
# else
constexpr static const size_t kBufferSize = 512;
# endif
virtual ~ILogBackend() {} virtual ~ILogBackend() {}
virtual void message(int level, const char* fmt, va_list args) = 0; virtual void message(Level level, const char* fmt, va_list args) = 0;
virtual void text(const char* fmt, va_list args) = 0; virtual void text(const char* fmt, va_list args) = 0;
}; };

View file

@ -66,7 +66,7 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) :
} }
void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::message(Level level, const char* fmt, va_list args)
{ {
time_t now = time(nullptr); time_t now = time(nullptr);
tm stime; tm stime;
@ -77,43 +77,18 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
localtime_r(&now, &stime); localtime_r(&now, &stime);
# endif # endif
const char* color = nullptr; const bool isColors = m_controller->config()->isColors();
const bool colors = m_controller->config()->isColors();
if (colors) { snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
switch (level) {
case Log::ERR:
color = Log::kCL_RED;
break;
case Log::WARNING:
color = Log::kCL_YELLOW;
break;
case Log::NOTICE:
color = Log::kCL_WHITE;
break;
case Log::DEBUG:
color = Log::kCL_GRAY;
break;
default:
color = "";
break;
}
}
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
stime.tm_year + 1900, stime.tm_year + 1900,
stime.tm_mon + 1, stime.tm_mon + 1,
stime.tm_mday, stime.tm_mday,
stime.tm_hour, stime.tm_hour,
stime.tm_min, stime.tm_min,
stime.tm_sec, stime.tm_sec,
colors ? color : "", Log::colorByLevel(level, isColors),
fmt, fmt,
colors ? Log::kCL_N : "" Log::endl(isColors)
); );
print(args); print(args);
@ -122,7 +97,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
void ConsoleLog::text(const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args)
{ {
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_controller->config()->isColors() ? Log::kCL_N : ""); snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(m_controller->config()->isColors()));
print(args); print(args);
} }

View file

@ -28,7 +28,7 @@
#include <uv.h> #include <uv.h>
#include "interfaces/ILogBackend.h" #include "common/interfaces/ILogBackend.h"
namespace xmrig { namespace xmrig {
@ -41,14 +41,14 @@ class ConsoleLog : public ILogBackend
public: public:
ConsoleLog(xmrig::Controller *controller); ConsoleLog(xmrig::Controller *controller);
void message(int level, const char *fmt, va_list args) override; void message(Level level, const char *fmt, va_list args) override;
void text(const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override;
private: private:
bool isWritable() const; bool isWritable() const;
void print(va_list args); void print(va_list args);
char m_buf[512]; char m_buf[kBufferSize];
char m_fmt[256]; char m_fmt[256];
uv_buf_t m_uvBuf; uv_buf_t m_uvBuf;
uv_stream_t *m_stream; uv_stream_t *m_stream;

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -30,9 +30,13 @@
#include "common/log/FileLog.h" #include "common/log/FileLog.h"
#include "common/log/Log.h"
#include "core/Config.h"
#include "core/Controller.h"
FileLog::FileLog(const char *fileName) FileLog::FileLog(xmrig::Controller *controller, const char *fileName) :
m_controller(controller)
{ {
uv_fs_t req; uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr); m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
@ -40,7 +44,7 @@ FileLog::FileLog(const char *fileName)
} }
void FileLog::message(int level, const char* fmt, va_list args) void FileLog::message(Level level, const char* fmt, va_list args)
{ {
if (m_file < 0) { if (m_file < 0) {
return; return;
@ -55,29 +59,33 @@ void FileLog::message(int level, const char* fmt, va_list args)
localtime_r(&now, &stime); localtime_r(&now, &stime);
# endif # endif
char *buf = new char[512]; const bool isColors = m_controller->config()->isColors();
int size = snprintf(buf, 23, "[%d-%02d-%02d %02d:%02d:%02d] ",
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
stime.tm_year + 1900, stime.tm_year + 1900,
stime.tm_mon + 1, stime.tm_mon + 1,
stime.tm_mday, stime.tm_mday,
stime.tm_hour, stime.tm_hour,
stime.tm_min, stime.tm_min,
stime.tm_sec); stime.tm_sec,
Log::colorByLevel(level, isColors),
fmt,
Log::endl(isColors)
);
size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size; char *buf = new char[kBufferSize];
buf[size] = '\n'; const int size = vsnprintf(buf, kBufferSize - 1, m_fmt, args);
write(buf, size + 1); write(buf, size);
} }
void FileLog::text(const char* fmt, va_list args) void FileLog::text(const char* fmt, va_list args)
{ {
message(0, fmt, args); message(INFO, fmt, args);
} }
void FileLog::onWrite(uv_fs_t *req) void FileLog::onWrite(uv_fs_t *req)
{ {
delete [] static_cast<char *>(req->data); delete [] static_cast<char *>(req->data);

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,15 +28,20 @@
#include <uv.h> #include <uv.h>
#include "interfaces/ILogBackend.h" #include "common/interfaces/ILogBackend.h"
namespace xmrig {
class Controller;
}
class FileLog : public ILogBackend class FileLog : public ILogBackend
{ {
public: public:
FileLog(const char *fileName); FileLog(xmrig::Controller *controller, const char *fileName);
void message(int level, const char* fmt, va_list args) override; void message(Level level, const char* fmt, va_list args) override;
void text(const char* fmt, va_list args) override; void text(const char* fmt, va_list args) override;
private: private:
@ -44,7 +49,9 @@ private:
void write(char *data, size_t size); void write(char *data, size_t size);
char m_fmt[256];
int m_file; int m_file;
xmrig::Controller *m_controller;
}; };
#endif /* __FILELOG_H__ */ #endif /* __FILELOG_H__ */

View file

@ -29,14 +29,27 @@
#include <time.h> #include <time.h>
#include "common/interfaces/ILogBackend.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "interfaces/ILogBackend.h"
Log *Log::m_self = nullptr; Log *Log::m_self = nullptr;
void Log::message(Log::Level level, const char* fmt, ...) static const char *colors[5] = {
"\x1B[0;31m", /* ERR */
"\x1B[0;33m", /* WARNING */
"\x1B[1;37m", /* NOTICE */
"", /* INFO */
# ifdef WIN32
"\x1B[1;30m" /* DEBUG */
# else
"\x1B[90m" /* DEBUG */
# endif
};
void Log::message(ILogBackend::Level level, const char* fmt, ...)
{ {
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
@ -76,6 +89,26 @@ void Log::text(const char* fmt, ...)
} }
const char *Log::colorByLevel(ILogBackend::Level level, bool isColors)
{
if (!isColors) {
return "";
}
return colors[level];
}
const char *Log::endl(bool isColors)
{
# ifdef _WIN32
return isColors ? "\x1B[0m\r\n" : "\r\n";
# else
return isColors ? "\x1B[0m\n" : "\n";
# endif
}
Log::~Log() Log::~Log()
{ {
for (auto backend : m_backends) { for (auto backend : m_backends) {

View file

@ -30,39 +30,23 @@
#include <vector> #include <vector>
class ILogBackend; #include "common/interfaces/ILogBackend.h"
class Log class Log
{ {
public: public:
enum Level {
ERR,
WARNING,
NOTICE,
INFO,
DEBUG
};
constexpr static const char* kCL_N = "\x1B[0m";
constexpr static const char* kCL_RED = "\x1B[31m";
constexpr static const char* kCL_YELLOW = "\x1B[33m";
constexpr static const char* kCL_WHITE = "\x1B[01;37m";
# ifdef WIN32
constexpr static const char* kCL_GRAY = "\x1B[01;30m";
# else
constexpr static const char* kCL_GRAY = "\x1B[90m";
# endif
static inline Log* i() { assert(m_self != nullptr); return m_self; } static inline Log* i() { assert(m_self != nullptr); return m_self; }
static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); }
static inline void init() { if (!m_self) { new Log(); } } static inline void init() { if (!m_self) { new Log(); } }
static inline void release() { assert(m_self != nullptr); delete m_self; } static inline void release() { assert(m_self != nullptr); delete m_self; }
void message(Level level, const char* fmt, ...); void message(ILogBackend::Level level, const char* fmt, ...);
void text(const char* fmt, ...); void text(const char* fmt, ...);
static const char *colorByLevel(ILogBackend::Level level, bool isColors = true);
static const char *endl(bool isColors = true);
private: private:
inline Log() { inline Log() {
assert(m_self == nullptr); assert(m_self == nullptr);
@ -92,20 +76,20 @@ private:
#define WHITE(x) "\x1B[0;37m" x "\x1B[0m" #define WHITE(x) "\x1B[0;37m" x "\x1B[0m"
#define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) #define LOG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__)
#define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) #define LOG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) Log::i()->message(ILogBackend::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) Log::i()->message(Log::INFO, x, ##__VA_ARGS__) #define LOG_INFO(x, ...) Log::i()->message(ILogBackend::INFO, x, ##__VA_ARGS__)
#ifdef APP_DEBUG #ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) Log::i()->message(Log::DEBUG, x, ##__VA_ARGS__) # define LOG_DEBUG(x, ...) Log::i()->message(ILogBackend::DEBUG, x, ##__VA_ARGS__)
#else #else
# define LOG_DEBUG(x, ...) # define LOG_DEBUG(x, ...)
#endif #endif
#if defined(APP_DEBUG) || defined(APP_DEVEL) #if defined(APP_DEBUG) || defined(APP_DEVEL)
# define LOG_DEBUG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) # define LOG_DEBUG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__)
# define LOG_DEBUG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) # define LOG_DEBUG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__)
#else #else
# define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_ERR(x, ...)
# define LOG_DEBUG_WARN(x, ...) # define LOG_DEBUG_WARN(x, ...)

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,13 +35,13 @@ SysLog::SysLog()
} }
void SysLog::message(int level, const char *fmt, va_list args) void SysLog::message(Level level, const char *fmt, va_list args)
{ {
vsyslog(level, fmt, args); vsyslog(static_cast<int>(level), fmt, args);
} }
void SysLog::text(const char *fmt, va_list args) void SysLog::text(const char *fmt, va_list args)
{ {
message(LOG_INFO, fmt, args); vsyslog(LOG_INFO, fmt, args);
} }

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
#define __SYSLOG_H__ #define __SYSLOG_H__
#include "interfaces/ILogBackend.h" #include "common/interfaces/ILogBackend.h"
class SysLog : public ILogBackend class SysLog : public ILogBackend
@ -33,7 +33,7 @@ class SysLog : public ILogBackend
public: public:
SysLog(); SysLog();
void message(int level, const char *fmt, va_list args) override; void message(Level level, const char *fmt, va_list args) override;
void text(const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override;
}; };

View file

@ -29,9 +29,9 @@
#include <utility> #include <utility>
#include "common/interfaces/IClientListener.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "common/net/Client.h" #include "common/net/Client.h"
#include "interfaces/IClientListener.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"

View file

@ -30,6 +30,7 @@
#include <vector> #include <vector>
#include "common/crypto/Algorithm.h"
#include "common/net/Id.h" #include "common/net/Id.h"
#include "common/net/Job.h" #include "common/net/Job.h"
#include "common/net/Pool.h" #include "common/net/Pool.h"
@ -73,6 +74,7 @@ public:
inline int id() const { return m_id; } inline int id() const { return m_id; }
inline SocketState state() const { return m_state; } inline SocketState state() const { return m_state; }
inline uint16_t port() const { return m_pool.port(); } inline uint16_t port() const { return m_pool.port(); }
inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); }
inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setQuiet(bool quiet) { m_quiet = quiet; }
inline void setRetries(int retries) { m_retries = retries; } inline void setRetries(int retries) { m_retries = retries; }
inline void setRetryPause(int ms) { m_retryPause = ms; } inline void setRetryPause(int ms) { m_retryPause = ms; }

View file

@ -165,20 +165,20 @@ bool Job::setTarget(const char *target)
xmrig::Variant Job::variant() const xmrig::Variant Job::variant() const
{ {
if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) {
return xmrig::VARIANT_0;
}
if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) { if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] < 4) {
return xmrig::VARIANT_1; return xmrig::VARIANT_1;
} }
if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] < 7) {
if (m_algorithm.algo() == xmrig::CRYPTONIGHT) {
return xmrig::VARIANT_1; return xmrig::VARIANT_1;
} }
return (m_blob[0] > 6 ? xmrig::VARIANT_1 : xmrig::VARIANT_0); if (m_algorithm.variant() == xmrig::VARIANT_XHV && m_blob[0] < 3) {
return xmrig::VARIANT_0;
}
if (m_algorithm.variant() == xmrig::VARIANT_AUTO) {
return m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY ? xmrig::VARIANT_0 : xmrig::VARIANT_1;
} }
return m_algorithm.variant(); return m_algorithm.variant();

View file

@ -101,6 +101,12 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const
} }
} }
# ifdef XMRIG_PROXY_PROJECT
if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT && m_algorithm.variant() == xmrig::VARIANT_XTL) {
return true;
}
# endif
return false; return false;
} }
@ -227,7 +233,10 @@ void Pool::adjust(xmrig::Algo algorithm)
m_algorithm.setAlgo(algorithm); m_algorithm.setAlgo(algorithm);
if (m_algorithm.variant() == xmrig::VARIANT_AUTO) { if (m_algorithm.variant() == xmrig::VARIANT_AUTO) {
if (algorithm == xmrig::CRYPTONIGHT) { if (algorithm == xmrig::CRYPTONIGHT_HEAVY) {
m_algorithm.setVariant(xmrig::VARIANT_0);
}
else {
m_algorithm.setVariant(xmrig::VARIANT_1); m_algorithm.setVariant(xmrig::VARIANT_1);
} }
} }
@ -247,17 +256,15 @@ void Pool::adjust(xmrig::Algo algorithm)
m_algorithm.setVariant(xmrig::VARIANT_1); m_algorithm.setVariant(xmrig::VARIANT_1);
} }
m_algorithms.push_back(m_algorithm); rebuild();
}
# ifndef XMRIG_PROXY_PROJECT
if (m_algorithm.algo() != xmrig::CRYPTONIGHT_HEAVY) { void Pool::setAlgo(const xmrig::Algorithm &algorithm)
addVariant(xmrig::VARIANT_1); {
addVariant(xmrig::VARIANT_0); m_algorithm = algorithm;
addVariant(xmrig::VARIANT_XTL);
addVariant(xmrig::VARIANT_IPBC); rebuild();
addVariant(xmrig::VARIANT_AUTO);
}
# endif
} }
@ -309,3 +316,20 @@ void Pool::addVariant(xmrig::Variant variant)
m_algorithms.push_back(algorithm); m_algorithms.push_back(algorithm);
} }
void Pool::rebuild()
{
m_algorithms.clear();
m_algorithms.push_back(m_algorithm);
# ifndef XMRIG_PROXY_PROJECT
addVariant(xmrig::VARIANT_1);
addVariant(xmrig::VARIANT_0);
addVariant(xmrig::VARIANT_XTL);
addVariant(xmrig::VARIANT_IPBC);
addVariant(xmrig::VARIANT_MSR);
addVariant(xmrig::VARIANT_XHV);
addVariant(xmrig::VARIANT_AUTO);
# endif
}

View file

@ -78,6 +78,7 @@ public:
bool setUserpass(const char *userpass); bool setUserpass(const char *userpass);
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
void adjust(xmrig::Algo algorithm); void adjust(xmrig::Algo algorithm);
void setAlgo(const xmrig::Algorithm &algorithm);
# ifdef APP_DEBUG # ifdef APP_DEBUG
void print() const; void print() const;
@ -86,6 +87,7 @@ public:
private: private:
bool parseIPv6(const char *addr); bool parseIPv6(const char *addr);
void addVariant(xmrig::Variant variant); void addVariant(xmrig::Variant variant);
void rebuild();
bool m_nicehash; bool m_nicehash;
int m_keepAlive; int m_keepAlive;

View file

@ -22,10 +22,10 @@
*/ */
#include "common/interfaces/IStrategyListener.h"
#include "common/net/Client.h" #include "common/net/Client.h"
#include "common/net/strategies/FailoverStrategy.h" #include "common/net/strategies/FailoverStrategy.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "interfaces/IStrategyListener.h"
FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : FailoverStrategy::FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) :

View file

@ -28,9 +28,9 @@
#include <vector> #include <vector>
#include "common/interfaces/IClientListener.h"
#include "common/interfaces/IStrategy.h"
#include "common/net/Pool.h" #include "common/net/Pool.h"
#include "interfaces/IClientListener.h"
#include "interfaces/IStrategy.h"
class Client; class Client;

View file

@ -22,10 +22,10 @@
*/ */
#include "common/interfaces/IStrategyListener.h"
#include "common/net/Client.h" #include "common/net/Client.h"
#include "common/net/strategies/SinglePoolStrategy.h" #include "common/net/strategies/SinglePoolStrategy.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "interfaces/IStrategyListener.h"
SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) :

View file

@ -25,8 +25,8 @@
#define __SINGLEPOOLSTRATEGY_H__ #define __SINGLEPOOLSTRATEGY_H__
#include "interfaces/IClientListener.h" #include "common/interfaces/IClientListener.h"
#include "interfaces/IStrategy.h" #include "common/interfaces/IStrategy.h"
class Client; class Client;

View file

@ -61,8 +61,17 @@ enum Variant {
VARIANT_AUTO = -1, // Autodetect VARIANT_AUTO = -1, // Autodetect
VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy
VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7
VARIANT_IPBC = 2, // CryptoNight Lite variant 1 with XOR (IPBC only) VARIANT_IPBC = 2, // Modified CryptoNight Lite variant 1 with XOR (IPBC/TUBE only)
VARIANT_XTL = 3 // CryptoNight variant 1 (Stellite only) VARIANT_XTL = 3, // Modified CryptoNight variant 1 (Stellite only)
VARIANT_MSR = 4, // Modified CryptoNight variant 1 (Masari only)
VARIANT_XHV = 5, // Modified CryptoNight-Heavy (Haven Protocol only)
VARIANT_MAX
};
enum AlgoVerify {
VERIFY_HW_AES = 1,
VERIFY_SOFT_AES = 2
}; };

View file

@ -43,7 +43,6 @@ static char affinity_tmp[20] = { 0 };
xmrig::Config::Config() : xmrig::CommonConfig(), xmrig::Config::Config() : xmrig::CommonConfig(),
m_aesMode(AES_AUTO), m_aesMode(AES_AUTO),
m_algoVariant(AV_AUTO), m_algoVariant(AV_AUTO),
m_dryRun(false),
m_hugePages(true), m_hugePages(true),
m_safe(false), m_safe(false),
m_maxCpuUsage(75), m_maxCpuUsage(75),
@ -116,7 +115,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
Value threads(kArrayType); Value threads(kArrayType);
for (const IThread *thread : m_threads.list) { 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); doc.AddMember("threads", threads, allocator);
@ -192,19 +191,15 @@ bool xmrig::Config::parseBoolean(int key, bool enable)
} }
switch (key) { switch (key) {
case IConfig::SafeKey: /* --safe */ case SafeKey: /* --safe */
m_safe = enable; m_safe = enable;
break; break;
case IConfig::HugePagesKey: /* --no-huge-pages */ case HugePagesKey: /* --no-huge-pages */
m_hugePages = enable; m_hugePages = enable;
break; break;
case IConfig::DryRunKey: /* --dry-run */ case HardwareAESKey: /* hw-aes config only */
m_dryRun = enable;
break;
case IConfig::HardwareAESKey: /* hw-aes config only */
m_aesMode = enable ? AES_HW : AES_SOFT; m_aesMode = enable ? AES_HW : AES_SOFT;
break; break;
@ -223,19 +218,18 @@ bool xmrig::Config::parseString(int key, const char *arg)
} }
switch (key) { switch (key) {
case xmrig::IConfig::AVKey: /* --av */ case AVKey: /* --av */
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ case MaxCPUUsageKey: /* --max-cpu-usage */
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ case CPUPriorityKey: /* --cpu-priority */
return parseUint64(key, strtol(arg, nullptr, 10)); return parseUint64(key, strtol(arg, nullptr, 10));
case xmrig::IConfig::SafeKey: /* --safe */ case SafeKey: /* --safe */
case xmrig::IConfig::DryRunKey: /* --dry-run */
return parseBoolean(key, true); return parseBoolean(key, true);
case xmrig::IConfig::HugePagesKey: /* --no-huge-pages */ case HugePagesKey: /* --no-huge-pages */
return parseBoolean(key, false); return parseBoolean(key, false);
case xmrig::IConfig::ThreadsKey: /* --threads */ case ThreadsKey: /* --threads */
if (strncmp(arg, "all", 3) == 0) { if (strncmp(arg, "all", 3) == 0) {
m_threads.count = Cpu::threads(); m_threads.count = Cpu::threads();
return true; return true;
@ -243,7 +237,7 @@ bool xmrig::Config::parseString(int key, const char *arg)
return parseUint64(key, strtol(arg, nullptr, 10)); return parseUint64(key, strtol(arg, nullptr, 10));
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ case CPUAffinityKey: /* --cpu-affinity */
{ {
const char *p = strstr(arg, "0x"); const char *p = strstr(arg, "0x");
return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); return parseUint64(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10));
@ -264,7 +258,7 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg)
} }
switch (key) { switch (key) {
case xmrig::IConfig::CPUAffinityKey: /* --cpu-affinity */ case CPUAffinityKey: /* --cpu-affinity */
if (arg) { if (arg) {
m_threads.mask = arg; m_threads.mask = arg;
} }
@ -303,25 +297,25 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc)
bool xmrig::Config::parseInt(int key, int arg) bool xmrig::Config::parseInt(int key, int arg)
{ {
switch (key) { switch (key) {
case xmrig::IConfig::ThreadsKey: /* --threads */ case ThreadsKey: /* --threads */
if (arg >= 0 && arg < 1024) { if (arg >= 0 && arg < 1024) {
m_threads.count = arg; m_threads.count = arg;
} }
break; break;
case xmrig::IConfig::AVKey: /* --av */ case AVKey: /* --av */
if (arg >= AV_AUTO && arg < AV_MAX) { if (arg >= AV_AUTO && arg < AV_MAX) {
m_algoVariant = static_cast<AlgoVariant>(arg); m_algoVariant = static_cast<AlgoVariant>(arg);
} }
break; break;
case xmrig::IConfig::MaxCPUUsageKey: /* --max-cpu-usage */ case MaxCPUUsageKey: /* --max-cpu-usage */
if (m_maxCpuUsage > 0 && arg <= 100) { if (m_maxCpuUsage > 0 && arg <= 100) {
m_maxCpuUsage = arg; m_maxCpuUsage = arg;
} }
break; break;
case xmrig::IConfig::CPUPriorityKey: /* --cpu-priority */ case CPUPriorityKey: /* --cpu-priority */
if (arg >= 0 && arg <= 5) { if (arg >= 0 && arg <= 5) {
m_priority = arg; m_priority = arg;
} }

View file

@ -77,7 +77,6 @@ public:
inline AesMode aesMode() const { return m_aesMode; } inline AesMode aesMode() const { return m_aesMode; }
inline AlgoVariant algoVariant() const { return m_algoVariant; } inline AlgoVariant algoVariant() const { return m_algoVariant; }
inline bool isDryRun() const { return m_dryRun; }
inline bool isHugePages() const { return m_hugePages; } inline bool isHugePages() const { return m_hugePages; }
inline const std::vector<IThread *> &threads() const { return m_threads.list; } inline const std::vector<IThread *> &threads() const { return m_threads.list; }
inline int priority() const { return m_priority; } inline int priority() const { return m_priority; }
@ -117,7 +116,6 @@ private:
AesMode m_aesMode; AesMode m_aesMode;
AlgoVariant m_algoVariant; AlgoVariant m_algoVariant;
bool m_dryRun;
bool m_hugePages; bool m_hugePages;
bool m_safe; bool m_safe;
int m_maxCpuUsage; int m_maxCpuUsage;

View file

@ -24,8 +24,8 @@
#define __CONFIGCREATOR_H__ #define __CONFIGCREATOR_H__
#include "common/interfaces/IConfigCreator.h"
#include "core/Config.h" #include "core/Config.h"
#include "interfaces/IConfigCreator.h"
namespace xmrig { namespace xmrig {

View file

@ -33,8 +33,8 @@
#endif #endif
#include "common/interfaces/IConfig.h"
#include "version.h" #include "version.h"
#include "interfaces/IConfig.h"
namespace xmrig { namespace xmrig {

View file

@ -26,6 +26,7 @@
#include "common/config/ConfigLoader.h" #include "common/config/ConfigLoader.h"
#include "common/interfaces/IControllerListener.h"
#include "common/log/ConsoleLog.h" #include "common/log/ConsoleLog.h"
#include "common/log/FileLog.h" #include "common/log/FileLog.h"
#include "common/log/Log.h" #include "common/log/Log.h"
@ -33,7 +34,6 @@
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "Cpu.h" #include "Cpu.h"
#include "interfaces/IControllerListener.h"
#include "net/Network.h" #include "net/Network.h"
@ -110,7 +110,7 @@ int xmrig::Controller::init(int argc, char **argv)
} }
if (config()->logFile()) { if (config()->logFile()) {
Log::add(new FileLog(config()->logFile())); Log::add(new FileLog(this, config()->logFile()));
} }
# ifdef HAVE_SYSLOG_H # ifdef HAVE_SYSLOG_H

View file

@ -25,7 +25,7 @@
#define __CONTROLLER_H__ #define __CONTROLLER_H__
#include "interfaces/IWatcherListener.h" #include "common/interfaces/IWatcherListener.h"
class Network; class Network;

View file

@ -73,7 +73,7 @@ static inline __attribute__((always_inline)) __m128i _mm_set_epi64x(const uint64
} }
#ifdef XMRIG_ARMv8 #if __ARM_FEATURE_CRYPTO
static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey)
{ {
alignas(16) const __m128i zero = { 0 }; alignas(16) const __m128i zero = { 0 };
@ -82,6 +82,8 @@ static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v,
#else #else
static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey) static inline __attribute__((always_inline)) __m128i _mm_aesenc_si128(__m128i v, __m128i rkey)
{ {
alignas(16) const __m128i zero = { 0 };
return zero;
} }
#endif #endif
@ -96,7 +98,7 @@ static inline __attribute__((always_inline)) uint64_t _mm_cvtsi128_si64(__m128i
#define EXTRACT64(X) _mm_cvtsi128_si64(X) #define EXTRACT64(X) _mm_cvtsi128_si64(X)
#if defined(XMRIG_ARMv8) #if defined (__arm64__) || defined (__aarch64__)
static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi) static inline uint64_t __umul128(uint64_t a, uint64_t b, uint64_t* hi)
{ {
unsigned __int128 r = (unsigned __int128) a * (unsigned __int128) b; unsigned __int128 r = (unsigned __int128) a * (unsigned __int128) b;
@ -396,14 +398,15 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp)
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 32); memset(output, 0, 32);
return; return;
} }
@ -434,7 +437,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
} }
if (VARIANT > 0) { if (IS_MONERO) {
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
} else { } else {
_mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
@ -453,7 +456,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0;
} }
@ -470,14 +473,21 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
idx0 = al0; idx0 = al0;
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; const int64x2_t x = vld1q_s64(reinterpret_cast<const int64_t *>(&l0[idx0 & MASK]));
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; const int64_t n = vgetq_lane_s64(x, 0);
int64_t q = n / (d | 0x5); const int32_t d = vgetq_lane_s32(x, 2);
const int64_t q = n / (d | 0x5);
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx0 = (~d) ^ q;
}
else {
idx0 = d ^ q; idx0 = d ^ q;
} }
} }
}
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state);
@ -486,14 +496,15 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 64); memset(output, 0, 64);
return; return;
} }
@ -537,7 +548,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1));
} }
if (VARIANT > 0) { if (IS_MONERO) {
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
} else { } else {
@ -561,7 +572,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0;
} }
@ -578,13 +589,20 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
idx0 = al0; idx0 = al0;
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0]; const int64x2_t x = vld1q_s64(reinterpret_cast<const int64_t *>(&l0[idx0 & MASK]));
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2]; const int64_t n = vgetq_lane_s64(x, 0);
int64_t q = n / (d | 0x5); const int32_t d = vgetq_lane_s32(x, 2);
const int64_t q = n / (d | 0x5);
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx0 = (~d) ^ q;
}
else {
idx0 = d ^ q; idx0 = d ^ q;
} }
}
cl = ((uint64_t*) &l1[idx1 & MASK])[0]; cl = ((uint64_t*) &l1[idx1 & MASK])[0];
ch = ((uint64_t*) &l1[idx1 & MASK])[1]; ch = ((uint64_t*) &l1[idx1 & MASK])[1];
@ -595,7 +613,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l1[idx1 & MASK])[0] = al1; ((uint64_t*)&l1[idx1 & MASK])[0] = al1;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1;
} }
@ -612,14 +630,21 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
idx1 = al1; idx1 = al1;
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) { if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
int64_t n = ((int64_t*)&l1[idx1 & MASK])[0]; const int64x2_t x = vld1q_s64(reinterpret_cast<const int64_t *>(&l1[idx1 & MASK]));
int32_t d = ((int32_t*)&l1[idx1 & MASK])[2]; const int64_t n = vgetq_lane_s64(x, 0);
int64_t q = n / (d | 0x5); const int32_t d = vgetq_lane_s32(x, 2);
const int64_t q = n / (d | 0x5);
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx1 = (~d) ^ q;
}
else {
idx1 = d ^ q; idx1 = d ^ q;
} }
} }
}
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
@ -632,19 +657,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx)
{ {
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx)
{ {
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx) inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx **__restrict__ ctx)
{ {
} }

View file

@ -38,6 +38,7 @@ namespace xmrig
constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024; constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024;
constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0; constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0;
constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000; constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000;
constexpr const uint32_t CRYPTONIGHT_MSR_ITER = 0x40000;
constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024; constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024;
constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0; constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0;
@ -102,18 +103,24 @@ inline uint32_t cn_select_mask(Algo algorithm)
} }
template<Algo ALGO> inline constexpr uint32_t cn_select_iter() { return 0; } template<Algo ALGO, Variant variant> inline constexpr uint32_t cn_select_iter() { return 0; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT>() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT, VARIANT_0>() { return CRYPTONIGHT_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_ITER; } template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT, VARIANT_1>() { return CRYPTONIGHT_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_ITER; } template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT, VARIANT_XTL>() { return CRYPTONIGHT_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT, VARIANT_MSR>() { return CRYPTONIGHT_MSR_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE, VARIANT_0>() { return CRYPTONIGHT_LITE_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE, VARIANT_1>() { return CRYPTONIGHT_LITE_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE, VARIANT_IPBC>() { return CRYPTONIGHT_LITE_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_HEAVY, VARIANT_0>() { return CRYPTONIGHT_HEAVY_ITER; }
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_HEAVY, VARIANT_XHV>() { return CRYPTONIGHT_HEAVY_ITER; }
inline uint32_t cn_select_iter(Algo algorithm) inline uint32_t cn_select_iter(Algo algorithm, Variant variant)
{ {
switch(algorithm) switch(algorithm)
{ {
case CRYPTONIGHT: case CRYPTONIGHT:
return CRYPTONIGHT_ITER; return variant == VARIANT_MSR ? CRYPTONIGHT_MSR_ITER : CRYPTONIGHT_ITER;
case CRYPTONIGHT_LITE: case CRYPTONIGHT_LITE:
return CRYPTONIGHT_LITE_ITER; return CRYPTONIGHT_LITE_ITER;
@ -129,6 +136,21 @@ inline uint32_t cn_select_iter(Algo algorithm)
} }
template<Variant variant> inline constexpr bool cn_is_monero() { return false; }
template<> inline constexpr bool cn_is_monero<VARIANT_0>() { return false; }
template<> inline constexpr bool cn_is_monero<VARIANT_1>() { return true; }
template<> inline constexpr bool cn_is_monero<VARIANT_IPBC>() { return true; }
template<> inline constexpr bool cn_is_monero<VARIANT_XTL>() { return true; }
template<> inline constexpr bool cn_is_monero<VARIANT_MSR>() { return true; }
template<> inline constexpr bool cn_is_monero<VARIANT_XHV>() { return false; }
inline bool cn_is_monero(Variant variant)
{
return variant > VARIANT_0 && variant < VARIANT_XHV;
}
} /* namespace xmrig */ } /* namespace xmrig */

View file

@ -30,22 +30,21 @@
#ifndef XMRIG_ARM #ifndef XMRIG_ARM
# define VARIANT1_INIT(part) \ # define VARIANT1_INIT(part) \
uint64_t tweak1_2_##part = 0; \ uint64_t tweak1_2_##part = 0; \
if (VARIANT > 0) { \ if (IS_MONERO) { \
tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(input + 35 + part * size) ^ \ tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(input + 35 + part * size) ^ \
*(reinterpret_cast<const uint64_t*>(ctx[part]->state) + 24)); \ *(reinterpret_cast<const uint64_t*>(ctx[part]->state) + 24)); \
} }
#else #else
# define VARIANT1_INIT(part) \ # define VARIANT1_INIT(part) \
uint64_t tweak1_2_##part = 0; \ uint64_t tweak1_2_##part = 0; \
if (VARIANT > 0) { \ if (IS_MONERO) { \
volatile const uint64_t a = *reinterpret_cast<const uint64_t*>(input + 35 + part * size); \ memcpy(&tweak1_2_##part, input + 35 + part * size, sizeof tweak1_2_##part); \
volatile const uint64_t b = *(reinterpret_cast<const uint64_t*>(ctx[part]->state) + 24); \ tweak1_2_##part ^= *(reinterpret_cast<const uint64_t*>(ctx[part]->state) + 24); \
tweak1_2_##part = a ^ b; \
} }
#endif #endif
#define VARIANT1_1(p) \ #define VARIANT1_1(p) \
if (VARIANT > 0) { \ if (IS_MONERO) { \
const uint8_t tmp = reinterpret_cast<const uint8_t*>(p)[11]; \ const uint8_t tmp = reinterpret_cast<const uint8_t*>(p)[11]; \
static const uint32_t table = 0x75310; \ static const uint32_t table = 0x75310; \
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \ const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
@ -53,7 +52,7 @@
} }
#define VARIANT1_2(p, part) \ #define VARIANT1_2(p, part) \
if (VARIANT > 0) { \ if (IS_MONERO) { \
(p) ^= tweak1_2_##part; \ (p) ^= tweak1_2_##part; \
} }

View file

@ -99,6 +99,21 @@ const static uint8_t test_output_xtl[160] = {
}; };
// Masari (MSR)
const static uint8_t test_output_msr[160] = {
0x3C, 0x7A, 0x61, 0x08, 0x4C, 0x5E, 0xB8, 0x65, 0xB4, 0x98, 0xAB, 0x2F, 0x5A, 0x1A, 0xC5, 0x2C,
0x49, 0xC1, 0x77, 0xC2, 0xD0, 0x13, 0x34, 0x42, 0xD6, 0x5E, 0xD5, 0x14, 0x33, 0x5C, 0x82, 0xC5,
0x69, 0xDF, 0x38, 0x51, 0x1B, 0xB3, 0xEB, 0x7D, 0xE7, 0x6B, 0x08, 0x8E, 0xB6, 0x7E, 0xB7, 0x1C,
0x5F, 0x3C, 0x81, 0xC9, 0xF7, 0xCE, 0xAE, 0x28, 0xC0, 0xFE, 0xEB, 0xBA, 0x0B, 0x40, 0x38, 0x1D,
0x44, 0xD0, 0xD5, 0xD3, 0x98, 0x1F, 0xA3, 0x0E, 0xE9, 0x89, 0x1A, 0xD7, 0x88, 0xCC, 0x25, 0x76,
0x9C, 0xFF, 0x4D, 0x7F, 0x9C, 0xCF, 0x48, 0x07, 0x91, 0xF9, 0x82, 0xF5, 0x4C, 0xE9, 0xBD, 0x82,
0x36, 0x36, 0x64, 0x14, 0xED, 0xB8, 0x54, 0xEE, 0x22, 0xA1, 0x66, 0xA3, 0x87, 0x10, 0x76, 0x1F,
0x5A, 0xCD, 0x4C, 0x31, 0x4C, 0xBA, 0x41, 0xD2, 0xDB, 0x6C, 0x31, 0x2E, 0x7A, 0x64, 0x15, 0xFF,
0xA6, 0xD9, 0xB9, 0x7D, 0x1C, 0x3C, 0x98, 0xDD, 0x16, 0xE6, 0xD3, 0xAA, 0xEF, 0xB6, 0xB3, 0x53,
0x74, 0xD1, 0xAC, 0x5C, 0x04, 0x26, 0x7D, 0x71, 0xDE, 0xAB, 0x66, 0x28, 0x91, 0x3A, 0x6F, 0x4F
};
#ifndef XMRIG_NO_AEON #ifndef XMRIG_NO_AEON
const static uint8_t test_output_v0_lite[160] = { const static uint8_t test_output_v0_lite[160] = {
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E,
@ -146,7 +161,7 @@ const static uint8_t test_output_ipbc_lite[160] = {
#ifndef XMRIG_NO_SUMO #ifndef XMRIG_NO_SUMO
const static uint8_t test_output_heavy[160] = { const static uint8_t test_output_v0_heavy[160] = {
0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64,
0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2, 0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2,
0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A, 0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A,
@ -158,6 +173,19 @@ const static uint8_t test_output_heavy[160] = {
0x53, 0x62, 0x0A, 0x54, 0x7D, 0x43, 0xEA, 0x18, 0x94, 0xED, 0xD8, 0x92, 0x06, 0x6A, 0xA1, 0x51, 0x53, 0x62, 0x0A, 0x54, 0x7D, 0x43, 0xEA, 0x18, 0x94, 0xED, 0xD8, 0x92, 0x06, 0x6A, 0xA1, 0x51,
0xAD, 0xB1, 0xFD, 0x89, 0xFB, 0x5C, 0xB4, 0x25, 0x6A, 0xDD, 0xB0, 0x09, 0xC5, 0x72, 0x87, 0xEB 0xAD, 0xB1, 0xFD, 0x89, 0xFB, 0x5C, 0xB4, 0x25, 0x6A, 0xDD, 0xB0, 0x09, 0xC5, 0x72, 0x87, 0xEB
}; };
const static uint8_t test_output_xhv_heavy[160] = {
0x5A, 0xC3, 0xF7, 0x85, 0xC4, 0x90, 0xC5, 0x85, 0x50, 0xEC, 0x95, 0xD2, 0x72, 0x65, 0x63, 0x57,
0x7E, 0x7C, 0x1C, 0x21, 0x2D, 0x0C, 0xDE, 0x59, 0x12, 0x73, 0x20, 0x1E, 0x44, 0xFD, 0xD5, 0xB6,
0x1F, 0x4E, 0xB2, 0x0A, 0x36, 0x51, 0x4B, 0xF5, 0x4D, 0xC9, 0xE0, 0x90, 0x2C, 0x16, 0x47, 0x3F,
0xDE, 0x18, 0x29, 0x8E, 0xBB, 0x34, 0x2B, 0xEF, 0x7A, 0x04, 0x22, 0xD1, 0xB1, 0xF2, 0x48, 0xDA,
0xE3, 0x7F, 0x4B, 0x4C, 0xB4, 0xDF, 0xE8, 0xD3, 0x70, 0xE2, 0xE7, 0x44, 0x25, 0x87, 0x12, 0xF9,
0x8F, 0x28, 0x0B, 0xCE, 0x2C, 0xEE, 0xDD, 0x88, 0x94, 0x35, 0x48, 0x51, 0xAE, 0xC8, 0x9C, 0x0B,
0xED, 0x2F, 0xE6, 0x0F, 0x39, 0x05, 0xB4, 0x4A, 0x8F, 0x38, 0x44, 0x2D, 0x4B, 0xE9, 0x7B, 0x81,
0xC6, 0xB0, 0xE0, 0x0A, 0x39, 0x8C, 0x38, 0xFE, 0x63, 0x31, 0x47, 0x65, 0x0D, 0x2B, 0xF4, 0x96,
0x13, 0x91, 0x89, 0xB4, 0x5B, 0xA9, 0x2A, 0x7A, 0x09, 0x65, 0x14, 0x20, 0x76, 0x24, 0x6C, 0x80,
0x1D, 0x3F, 0x9F, 0xCD, 0x68, 0x39, 0xA9, 0x42, 0x27, 0xC1, 0x0C, 0x53, 0x98, 0x35, 0x60, 0x7A
};
#endif #endif

View file

@ -403,14 +403,15 @@ static inline void cryptonight_monero_tweak(uint64_t* mem_out, __m128i tmp)
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 32); memset(output, 0, 32);
return; return;
} }
@ -441,7 +442,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
} }
if (VARIANT > 0) { if (IS_MONERO) {
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
} else { } else {
_mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx)); _mm_store_si128((__m128i *)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
@ -460,7 +461,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0;
} }
@ -482,9 +483,15 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
int64_t q = n / (d | 0x5); int64_t q = n / (d | 0x5);
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx0 = (~d) ^ q;
}
else {
idx0 = d ^ q; idx0 = d ^ q;
} }
} }
}
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx[0]->memory, (__m128i*) ctx[0]->state);
@ -493,14 +500,15 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 64); memset(output, 0, 64);
return; return;
} }
@ -544,7 +552,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1)); cx1 = _mm_aesenc_si128(cx1, _mm_set_epi64x(ah1, al1));
} }
if (VARIANT > 0) { if (IS_MONERO) {
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1)); cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>((uint64_t*)&l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
} else { } else {
@ -568,7 +576,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l0[idx0 & MASK])[0] = al0; ((uint64_t*)&l0[idx0 & MASK])[0] = al0;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0; ((uint64_t*)&l0[idx0 & MASK])[1] = ah0 ^ tweak1_2_0 ^ al0;
} }
@ -590,8 +598,14 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
int64_t q = n / (d | 0x5); int64_t q = n / (d | 0x5);
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q; ((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx0 = (~d) ^ q;
}
else {
idx0 = d ^ q; idx0 = d ^ q;
} }
}
cl = ((uint64_t*) &l1[idx1 & MASK])[0]; cl = ((uint64_t*) &l1[idx1 & MASK])[0];
ch = ((uint64_t*) &l1[idx1 & MASK])[1]; ch = ((uint64_t*) &l1[idx1 & MASK])[1];
@ -602,7 +616,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
((uint64_t*)&l1[idx1 & MASK])[0] = al1; ((uint64_t*)&l1[idx1 & MASK])[0] = al1;
if (VARIANT > 0) { if (IS_MONERO) {
if (VARIANT == xmrig::VARIANT_IPBC) { if (VARIANT == xmrig::VARIANT_IPBC) {
((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1; ((uint64_t*)&l1[idx1 & MASK])[1] = ah1 ^ tweak1_2_1 ^ al1;
} }
@ -624,9 +638,15 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
int64_t q = n / (d | 0x5); int64_t q = n / (d | 0x5);
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q; ((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
if (VARIANT == xmrig::VARIANT_XHV) {
idx1 = (~d) ^ q;
}
else {
idx1 = d ^ q; idx1 = d ^ q;
} }
} }
}
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1); cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
@ -653,7 +673,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
\ \
b = _mm_xor_si128(b, c); \ b = _mm_xor_si128(b, c); \
\ \
if (VARIANT > 0) { \ if (IS_MONERO) { \
cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>(reinterpret_cast<uint64_t*>(ptr), b); \ cryptonight_monero_tweak<VARIANT == xmrig::VARIANT_XTL ? 4 : 3>(reinterpret_cast<uint64_t*>(ptr), b); \
} else { \ } else { \
_mm_store_si128(ptr, b); \ _mm_store_si128(ptr, b); \
@ -670,7 +690,7 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
lo = __umul128(idx, EXTRACT64(b), &hi); \ lo = __umul128(idx, EXTRACT64(b), &hi); \
a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \
\ \
if (VARIANT > 0) { \ if (IS_MONERO) { \
_mm_store_si128(ptr, _mm_xor_si128(a, mc)); \ _mm_store_si128(ptr, _mm_xor_si128(a, mc)); \
\ \
if (VARIANT == xmrig::VARIANT_IPBC) { \ if (VARIANT == xmrig::VARIANT_IPBC) { \
@ -688,26 +708,32 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
int32_t d = ((int32_t*)&l[idx & MASK])[2]; \ int32_t d = ((int32_t*)&l[idx & MASK])[2]; \
int64_t q = n / (d | 0x5); \ int64_t q = n / (d | 0x5); \
((int64_t*)&l[idx & MASK])[0] = n ^ q; \ ((int64_t*)&l[idx & MASK])[0] = n ^ q; \
if (VARIANT == xmrig::VARIANT_XHV) { \
idx = (~d) ^ q; \
} \
else { \
idx = d ^ q; \ idx = d ^ q; \
} \
} }
#define CONST_INIT(ctx, n) \ #define CONST_INIT(ctx, n) \
__m128i mc##n; \ __m128i mc##n; \
if (VARIANT > 0) { \ if (IS_MONERO) { \
mc##n = _mm_set_epi64x(*reinterpret_cast<const uint64_t*>(input + n * size + 35) ^ \ mc##n = _mm_set_epi64x(*reinterpret_cast<const uint64_t*>(input + n * size + 35) ^ \
*(reinterpret_cast<const uint64_t*>((ctx)->state) + 24), 0); \ *(reinterpret_cast<const uint64_t*>((ctx)->state) + 24), 0); \
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 32 * 3); memset(output, 0, 32 * 3);
return; return;
} }
@ -790,14 +816,15 @@ inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t si
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 32 * 4); memset(output, 0, 32 * 4);
return; return;
} }
@ -896,14 +923,15 @@ inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size
} }
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT> template<xmrig::Algo ALGO, bool SOFT_AES, xmrig::Variant VARIANT>
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx) inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx)
{ {
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>(); constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>(); constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO, VARIANT>();
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
constexpr bool IS_MONERO = xmrig::cn_is_monero<VARIANT>();
if (VARIANT > 0 && size < 43) { if (IS_MONERO && size < 43) {
memset(output, 0, 32 * 5); memset(output, 0, 32 * 5);
return; return;
} }

View file

@ -30,8 +30,8 @@
#include "api/NetworkState.h" #include "api/NetworkState.h"
#include "common/interfaces/IStrategyListener.h"
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
#include "interfaces/IStrategyListener.h"
class IStrategy; class IStrategy;

View file

@ -23,13 +23,13 @@
#include "common/crypto/keccak.h" #include "common/crypto/keccak.h"
#include "common/interfaces/IStrategyListener.h"
#include "common/net/Client.h" #include "common/net/Client.h"
#include "common/net/Job.h" #include "common/net/Job.h"
#include "common/net/strategies/FailoverStrategy.h" #include "common/net/strategies/FailoverStrategy.h"
#include "common/net/strategies/SinglePoolStrategy.h" #include "common/net/strategies/SinglePoolStrategy.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "common/xmrig.h" #include "common/xmrig.h"
#include "interfaces/IStrategyListener.h"
#include "net/strategies/DonateStrategy.h" #include "net/strategies/DonateStrategy.h"

View file

@ -30,9 +30,9 @@
#include "common/net/Pool.h" #include "common/net/Pool.h"
#include "interfaces/IClientListener.h" #include "common/interfaces/IClientListener.h"
#include "interfaces/IStrategy.h" #include "common/interfaces/IStrategy.h"
#include "interfaces/IStrategyListener.h" #include "common/interfaces/IStrategyListener.h"
class Client; class Client;

View file

@ -62,9 +62,15 @@ bool xmrig::CpuThread::isSoftAES(AlgoVariant av)
xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant) xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant)
{ {
assert(variant == VARIANT_0 || variant == VARIANT_1 || variant == VARIANT_IPBC || variant == VARIANT_XTL); assert(variant == VARIANT_0 ||
variant == VARIANT_1 ||
variant == VARIANT_IPBC ||
variant == VARIANT_XTL ||
variant == VARIANT_MSR ||
variant == VARIANT_XHV
);
static const cn_hash_fun func_table[90] = { static const cn_hash_fun func_table[180] = {
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_0>,
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_0>, cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_0>,
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_0>,
@ -87,7 +93,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_1>, cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_1>,
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_1>, cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_1>,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_XTL>, cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_XTL>,
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_XTL>, cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_XTL>,
@ -100,6 +106,19 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_XTL>, cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_XTL>,
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_XTL>, cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_XTL>,
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_MSR>,
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_MSR>,
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_MSR>,
cryptonight_double_hash<CRYPTONIGHT, true, VARIANT_MSR>,
cryptonight_triple_hash<CRYPTONIGHT, false, VARIANT_MSR>,
cryptonight_quad_hash<CRYPTONIGHT, false, VARIANT_MSR>,
cryptonight_penta_hash<CRYPTONIGHT, false, VARIANT_MSR>,
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_MSR>,
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_MSR>,
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_MSR>,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_0>,
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_0>, cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_0>,
@ -134,12 +153,16 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_IPBC>, cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_IPBC>,
cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_IPBC>, cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_IPBC>,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV
# else # else
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
# endif # endif
# ifndef XMRIG_NO_SUMO # ifndef XMRIG_NO_SUMO
@ -153,18 +176,33 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>, cryptonight_triple_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>,
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>, cryptonight_quad_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>,
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>, cryptonight_penta_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_IPBC
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR
cryptonight_single_hash<CRYPTONIGHT_HEAVY, false, VARIANT_XHV>,
cryptonight_double_hash<CRYPTONIGHT_HEAVY, false, VARIANT_XHV>,
cryptonight_single_hash<CRYPTONIGHT_HEAVY, true, VARIANT_XHV>,
cryptonight_double_hash<CRYPTONIGHT_HEAVY, true, VARIANT_XHV>,
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, false, VARIANT_XHV>,
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, false, VARIANT_XHV>,
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, false, VARIANT_XHV>,
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, true, VARIANT_XHV>,
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, true, VARIANT_XHV>,
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, true, VARIANT_XHV>,
# else # else
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
# endif # endif
}; };
# ifndef XMRIG_NO_SUMO const size_t index = VARIANT_MAX * 10 * algorithm + 10 * variant + av - 1;
if (algorithm == CRYPTONIGHT_HEAVY) {
variant = VARIANT_0;
}
# endif
const size_t index = 40 * algorithm + 10 * variant + av - 1;
# ifndef NDEBUG # ifndef NDEBUG
cn_hash_fun func = func_table[index]; cn_hash_fun func = func_table[index];

View file

@ -35,7 +35,7 @@
#include "workers/Hashrate.h" #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)) { if (isnormal(h)) {
snprintf(buf, size, "%03.1f", 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 double Hashrate::calc(size_t threadId, size_t ms) const
{ {
assert(threadId < m_threads); assert(threadId < m_threads);
if (threadId >= m_threads) {
return nan("");
}
using namespace std::chrono; using namespace std::chrono;
const uint64_t now = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count(); const uint64_t now = time_point_cast<milliseconds>(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 num1[8] = { 0 };
char num2[8] = { 0 }; char num2[8] = { 0 };
char num3[8] = { 0 }; char num3[8] = { 0 };
char num4[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(ShortInterval), num1, sizeof(num1)),
format(calc(MediumInterval), num2, sizeof(num2)), format(calc(MediumInterval), num2, sizeof(num2)),
format(calc(LargeInterval), num3, sizeof(num3)), 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) void Hashrate::onReport(uv_timer_t *handle)
{ {
static_cast<Hashrate*>(handle->data)->print(); static_cast<Hashrate*>(handle->data)->print();

View file

@ -38,7 +38,7 @@ class Hashrate
{ {
public: public:
enum Intervals { enum Intervals {
ShortInterval = 2500, ShortInterval = 10000,
MediumInterval = 60000, MediumInterval = 60000,
LargeInterval = 900000 LargeInterval = 900000
}; };
@ -47,13 +47,15 @@ public:
double calc(size_t ms) const; double calc(size_t ms) const;
double calc(size_t threadId, 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 add(size_t threadId, uint64_t count, uint64_t timestamp);
void print(); void print() const;
void stop(); void stop();
void updateHighest(); void updateHighest();
inline double highest() const { return m_highest; } inline double highest() const { return m_highest; }
inline size_t threads() const { return m_threads; } inline size_t threads() const { return m_threads; }
static const char *format(double h, char *buf, size_t size);
private: private:
static void onReport(uv_timer_t *handle); static void onReport(uv_timer_t *handle);

View file

@ -50,39 +50,29 @@ MultiWorker<N>::~MultiWorker()
template<size_t N> template<size_t N>
bool MultiWorker<N>::selfTest() bool MultiWorker<N>::selfTest()
{ {
if (m_thread->fn(xmrig::VARIANT_0) == nullptr) { if (m_thread->algorithm() == xmrig::CRYPTONIGHT) {
return false; return verify(xmrig::VARIANT_0, test_output_v0) &&
} verify(xmrig::VARIANT_1, test_output_v1) &&
verify(xmrig::VARIANT_XTL, test_output_xtl) &&
m_thread->fn(xmrig::VARIANT_0)(test_input, 76, m_hash, m_ctx); verify(xmrig::VARIANT_MSR, test_output_msr);
if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, sizeof m_hash) == 0) {
m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx);
if (memcmp(m_hash, test_output_v1, sizeof m_hash) != 0) {
return false;
}
m_thread->fn(xmrig::VARIANT_XTL)(test_input, 76, m_hash, m_ctx);
return memcmp(m_hash, test_output_xtl, sizeof m_hash) == 0;
} }
# ifndef XMRIG_NO_AEON # ifndef XMRIG_NO_AEON
if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, sizeof m_hash) == 0) { if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE) {
m_thread->fn(xmrig::VARIANT_1)(test_input, 76, m_hash, m_ctx); return verify(xmrig::VARIANT_0, test_output_v0_lite) &&
if (memcmp(m_hash, test_output_v1_lite, sizeof m_hash) != 0) { verify(xmrig::VARIANT_1, test_output_v1_lite) &&
return false; verify(xmrig::VARIANT_IPBC, test_output_ipbc_lite);
}
m_thread->fn(xmrig::VARIANT_IPBC)(test_input, 76, m_hash, m_ctx);
return memcmp(m_hash, test_output_ipbc_lite, sizeof m_hash) == 0;
} }
# endif # endif
# ifndef XMRIG_NO_SUMO # ifndef XMRIG_NO_SUMO
return m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY && memcmp(m_hash, test_output_heavy, sizeof m_hash) == 0; if (m_thread->algorithm() == xmrig::CRYPTONIGHT_HEAVY) {
# else return verify(xmrig::VARIANT_0, test_output_v0_heavy) &&
return false; verify(xmrig::VARIANT_XHV, test_output_xhv_heavy);
}
# endif # endif
return false;
} }
@ -140,6 +130,20 @@ bool MultiWorker<N>::resume(const Job &job)
} }
template<size_t N>
bool MultiWorker<N>::verify(xmrig::Variant variant, const uint8_t *referenceValue)
{
xmrig::CpuThread::cn_hash_fun func = m_thread->fn(variant);
if (!func) {
return false;
}
func(test_input, 76, m_hash, m_ctx);
return memcmp(m_hash, referenceValue, sizeof m_hash) == 0;
}
template<size_t N> template<size_t N>
void MultiWorker<N>::consumeJob() void MultiWorker<N>::consumeJob()
{ {

View file

@ -48,6 +48,7 @@ protected:
private: private:
bool resume(const Job &job); bool resume(const Job &job);
bool verify(xmrig::Variant variant, const uint8_t *referenceValue);
void consumeJob(); void consumeJob();
void save(const Job &job); void save(const Job &job);

View file

@ -22,6 +22,7 @@
*/ */
#include <cmath> #include <cmath>
#include <inttypes.h>
#include <thread> #include <thread>
@ -55,6 +56,7 @@ uv_async_t Workers::m_async;
uv_mutex_t Workers::m_mutex; uv_mutex_t Workers::m_mutex;
uv_rwlock_t Workers::m_rwlock; uv_rwlock_t Workers::m_rwlock;
uv_timer_t Workers::m_timer; uv_timer_t Workers::m_timer;
xmrig::Controller *Workers::m_controller = nullptr;
Job Workers::job() Job Workers::job()
@ -89,6 +91,33 @@ size_t Workers::threads()
void Workers::printHashrate(bool detail) void Workers::printHashrate(bool detail)
{ {
assert(m_controller != nullptr);
if (!m_controller) {
return;
}
if (detail) {
const bool isColors = m_controller->config()->isColors();
char num1[8] = { 0 };
char num2[8] = { 0 };
char num3[8] = { 0 };
Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : "");
size_t i = 0;
for (const xmrig::IThread *thread : m_controller->config()->threads()) {
Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |",
thread->index(),
thread->affinity(),
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::MediumInterval), num2, sizeof num2),
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::LargeInterval), num3, sizeof num3)
);
i++;
}
}
m_hashrate->print(); m_hashrate->print();
} }
@ -131,6 +160,8 @@ void Workers::setJob(const Job &job, bool donate)
void Workers::start(xmrig::Controller *controller) void Workers::start(xmrig::Controller *controller)
{ {
m_controller = controller;
const std::vector<xmrig::IThread *> &threads = controller->config()->threads(); const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
m_status.algo = controller->config()->algorithm().algo(); m_status.algo = controller->config()->algorithm().algo();
m_status.colors = controller->config()->isColors(); m_status.colors = controller->config()->isColors();

View file

@ -114,6 +114,7 @@ private:
static uv_mutex_t m_mutex; static uv_mutex_t m_mutex;
static uv_rwlock_t m_rwlock; static uv_rwlock_t m_rwlock;
static uv_timer_t m_timer; static uv_timer_t m_timer;
static xmrig::Controller *m_controller;
}; };