Skip to content

Commit 7003559

Browse files
committed
Merge branch 'feature-cryptonight-heavy' into dev
2 parents 44d5639 + 6b710ff commit 7003559

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1182
-377
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# v2.6.0-beta1
2+
- [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.**
23
- HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization.
34
- Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested.
45
- Added API endpoint `PUT /1/config` to update current config.
56
- Added API endpoint `GET /1/config` to get current active config.
7+
- Added API endpoint `GET /1/threads` to get current active threads configuration.
68
- API endpoint `GET /` now deprecated, use `GET /1/summary` instead.
79
- Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API.
810
- Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified.

CMakeLists.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(xmrig)
33

44
option(WITH_LIBCPUID "Use Libcpuid" ON)
55
option(WITH_AEON "CryptoNight-Lite support" ON)
6+
option(WITH_SUMO "CryptoNight-Heavy support" ON)
67
option(WITH_HTTPD "HTTP REST API" ON)
78
option(BUILD_STATIC "Build static binary" OFF)
89

@@ -32,6 +33,7 @@ set(HEADERS
3233
src/interfaces/ILogBackend.h
3334
src/interfaces/IStrategy.h
3435
src/interfaces/IStrategyListener.h
36+
src/interfaces/IThread.h
3537
src/interfaces/IWatcherListener.h
3638
src/interfaces/IWorker.h
3739
src/log/ConsoleLog.h
@@ -52,6 +54,7 @@ set(HEADERS
5254
src/Platform.h
5355
src/Summary.h
5456
src/version.h
57+
src/workers/CpuThread.h
5558
src/workers/DoubleWorker.h
5659
src/workers/Handle.h
5760
src/workers/Hashrate.h
@@ -68,6 +71,7 @@ set(HEADERS_CRYPTO
6871
src/crypto/c_keccak.h
6972
src/crypto/c_skein.h
7073
src/crypto/CryptoNight.h
74+
src/crypto/CryptoNight_constants.h
7175
src/crypto/CryptoNight_monero.h
7276
src/crypto/CryptoNight_test.h
7377
src/crypto/groestl_tables.h
@@ -106,6 +110,7 @@ set(SOURCES
106110
src/net/Url.cpp
107111
src/Platform.cpp
108112
src/Summary.cpp
113+
src/workers/CpuThread.cpp
109114
src/workers/DoubleWorker.cpp
110115
src/workers/Handle.cpp
111116
src/workers/Hashrate.cpp
@@ -121,7 +126,6 @@ set(SOURCES_CRYPTO
121126
src/crypto/c_blake256.c
122127
src/crypto/c_jh.c
123128
src/crypto/c_skein.c
124-
src/crypto/CryptoNight.cpp
125129
)
126130

127131
if (WIN32)
@@ -200,6 +204,10 @@ if (NOT WITH_AEON)
200204
add_definitions(/DXMRIG_NO_AEON)
201205
endif()
202206

207+
if (NOT WITH_SUMO)
208+
add_definitions(/DXMRIG_NO_SUMO)
209+
endif()
210+
203211
if (WITH_HTTPD)
204212
find_package(MHD)
205213

src/App.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,8 @@ int App::exec()
101101

102102
background();
103103

104-
if (!CryptoNight::init(m_controller->config()->algorithm(), m_controller->config()->algoVariant(), m_controller->config()->isDoubleHash())) {
105-
LOG_ERR("\"%s\" hash self-test failed.", m_controller->config()->algoName());
106-
return 1;
107-
}
108-
109104
Mem::allocate(m_controller->config()->algorithm(),
110-
m_controller->config()->threads(),
105+
m_controller->config()->threadsCount(),
111106
m_controller->config()->isDoubleHash(),
112107
m_controller->config()->isHugePages()
113108
);
@@ -136,7 +131,7 @@ int App::exec()
136131
m_httpd->start();
137132
# endif
138133

139-
Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller);
134+
Workers::start(m_controller);
140135

141136
m_controller->network()->connect();
142137

src/Cpu.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
55
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
66
* Copyright 2016 Jay D Dee <[email protected]>
7-
* Copyright 2016-2017 XMRig <support@xmrig.com>
8-
*
7+
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
8+
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
99
*
1010
* This program is free software: you can redistribute it and/or modify
1111
* it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0;
3939
int Cpu::m_totalThreads = 0;
4040

4141

42-
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
42+
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
4343
{
4444
if (m_totalThreads == 1) {
4545
return 1;
@@ -54,7 +54,18 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
5454
}
5555

5656
int count = 0;
57-
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
57+
int size = 2048;
58+
59+
if (algo == xmrig::CRYPTONIGHT_LITE) {
60+
size = 1024;
61+
}
62+
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
63+
size = 4096;
64+
}
65+
66+
if (doubleHash) {
67+
size *= 2;
68+
}
5869

5970
if (cache) {
6071
count = cache / size;

src/Cpu.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
55
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
66
* Copyright 2016 Jay D Dee <[email protected]>
7-
* Copyright 2016-2017 XMRig <support@xmrig.com>
8-
*
7+
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
8+
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <[email protected]>
99
*
1010
* This program is free software: you can redistribute it and/or modify
1111
* it under the terms of the GNU General Public License as published by
@@ -28,6 +28,9 @@
2828
#include <stdint.h>
2929

3030

31+
#include "xmrig.h"
32+
33+
3134
class Cpu
3235
{
3336
public:
@@ -37,7 +40,7 @@ class Cpu
3740
BMI2 = 4
3841
};
3942

40-
static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
43+
static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage);
4144
static void init();
4245
static void setAffinity(int id, uint64_t mask);
4346

src/Cpu_arm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int Cpu::m_totalCores = 0;
3737
int Cpu::m_totalThreads = 0;
3838

3939

40-
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
40+
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
4141
{
4242
return m_totalThreads;
4343
}

src/Mem.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828

2929
#include "crypto/CryptoNight.h"
30+
#include "crypto/CryptoNight_constants.h"
3031
#include "Mem.h"
31-
#include "xmrig.h"
3232

3333

3434
bool Mem::m_doubleHash = false;
@@ -43,15 +43,18 @@ alignas(16) uint8_t *Mem::m_memory = nullptr;
4343
cryptonight_ctx *Mem::create(int threadId)
4444
{
4545
# ifndef XMRIG_NO_AEON
46-
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
46+
if (m_algo == xmrig::CRYPTONIGHT_LITE) {
4747
return createLite(threadId);
4848
}
4949
# endif
5050

51-
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
51+
const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory<xmrig::CRYPTONIGHT_HEAVY>()
52+
: xmrig::cn_select_memory<xmrig::CRYPTONIGHT>();
53+
54+
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]);
5255

5356
const int ratio = m_doubleHash ? 2 : 1;
54-
ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
57+
ctx->memory = &m_memory[size * (threadId * ratio + 1)];
5558

5659
return ctx;
5760
}

src/Mem.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include <stdint.h>
3131

3232

33+
#include "xmrig.h"
34+
35+
3336
struct cryptonight_ctx;
3437

3538

@@ -42,7 +45,7 @@ class Mem
4245
Lock = 4
4346
};
4447

45-
static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
48+
static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled);
4649
static cryptonight_ctx *create(int threadId);
4750
static void *calloc(size_t num, size_t size);
4851
static void release();

src/Mem_unix.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@
4040
#include "xmrig.h"
4141

4242

43-
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
43+
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
4444
{
4545
m_algo = algo;
4646
m_threads = threads;
4747
m_doubleHash = doubleHash;
4848

49-
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
49+
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
5050
m_size = MONERO_MEMORY * (threads * ratio + 1);
5151

52+
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
53+
m_size *= 2;
54+
}
55+
5256
if (!enabled) {
5357
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
5458
return true;

src/Mem_win.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,19 @@ static BOOL TrySetLockPagesPrivilege() {
145145
}
146146

147147

148-
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
148+
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
149149
{
150150
m_algo = algo;
151151
m_threads = threads;
152152
m_doubleHash = doubleHash;
153153

154-
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
154+
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
155155
m_size = MONERO_MEMORY * (threads * ratio + 1);
156156

157+
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
158+
m_size *= 2;
159+
}
160+
157161
if (!enabled) {
158162
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
159163
return true;

src/Summary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void print_threads(xmrig::Config *config)
101101
}
102102

103103
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",
104-
config->threads(),
104+
config->threadsCount(),
105105
config->algoName(),
106106
config->algoVariant(),
107107
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "",

src/api/ApiRouter.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "core/Config.h"
3939
#include "core/Controller.h"
4040
#include "Cpu.h"
41+
#include "interfaces/IThread.h"
4142
#include "Mem.h"
4243
#include "net/Job.h"
4344
#include "Platform.h"
@@ -67,7 +68,7 @@ static inline double normalize(double d)
6768
ApiRouter::ApiRouter(xmrig::Controller *controller) :
6869
m_controller(controller)
6970
{
70-
m_threads = controller->config()->threads();
71+
m_threads = controller->config()->threadsCount();
7172
m_hashrate = new double[m_threads * 3]();
7273

7374
memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
@@ -87,7 +88,6 @@ ApiRouter::~ApiRouter()
8788
void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const
8889
{
8990
rapidjson::Document doc;
90-
doc.SetObject();
9191

9292
if (req.match("/1/config")) {
9393
if (req.isRestricted()) {
@@ -100,6 +100,14 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
100100
return finalize(reply, doc);
101101
}
102102

103+
if (req.match("/1/threads")) {
104+
getThreads(doc);
105+
106+
return finalize(reply, doc);
107+
}
108+
109+
doc.SetObject();
110+
103111
getIdentify(doc);
104112
getMiner(doc);
105113
getHashrate(doc);
@@ -144,7 +152,7 @@ void ApiRouter::tick(const NetworkState &network)
144152

145153
void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig)
146154
{
147-
// updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
155+
updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
148156
}
149157

150158

@@ -288,6 +296,18 @@ void ApiRouter::getResults(rapidjson::Document &doc) const
288296
}
289297

290298

299+
void ApiRouter::getThreads(rapidjson::Document &doc) const
300+
{
301+
doc.SetArray();
302+
303+
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
304+
305+
for (const xmrig::IThread *thread : threads) {
306+
doc.PushBack(thread->toAPI(doc), doc.GetAllocator());
307+
}
308+
}
309+
310+
291311
void ApiRouter::setWorkerId(const char *id)
292312
{
293313
memset(m_workerId, 0, sizeof(m_workerId));

src/api/ApiRouter.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ApiRouter : public xmrig::IControllerListener
6363
void getIdentify(rapidjson::Document &doc) const;
6464
void getMiner(rapidjson::Document &doc) const;
6565
void getResults(rapidjson::Document &doc) const;
66+
void getThreads(rapidjson::Document &doc) const;
6667
void setWorkerId(const char *id);
6768
void updateWorkerId(const char *id, const char *previousId);
6869

src/core/CommonConfig.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static const char *algoNames[] = {
5151

5252

5353
xmrig::CommonConfig::CommonConfig() :
54+
m_algorithm(CRYPTONIGHT),
5455
m_adjusted(false),
5556
m_apiIPv6(true),
5657
m_apiRestricted(true),
@@ -63,7 +64,6 @@ xmrig::CommonConfig::CommonConfig() :
6364
m_fileName(nullptr),
6465
m_logFile(nullptr),
6566
m_userAgent(nullptr),
66-
m_algorithm(ALGO_CRYPTONIGHT),
6767
m_apiPort(0),
6868
m_donateLevel(kDefaultDonateLevel),
6969
m_printTime(60),
@@ -95,9 +95,9 @@ xmrig::CommonConfig::~CommonConfig()
9595
}
9696

9797

98-
const char *xmrig::CommonConfig::algoName() const
98+
const char *xmrig::CommonConfig::algoName(Algo algorithm)
9999
{
100-
return algoNames[m_algorithm];
100+
return algoNames[algorithm];
101101
}
102102

103103

@@ -367,15 +367,15 @@ void xmrig::CommonConfig::setAlgo(const char *algo)
367367
if (strcasecmp(algo, "cryptonight-light") == 0) {
368368
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
369369

370-
m_algorithm = ALGO_CRYPTONIGHT_LITE;
370+
m_algorithm = CRYPTONIGHT_LITE;
371371
return;
372372
}
373373

374374
const size_t size = sizeof(algoNames) / sizeof((algoNames)[0]);
375375

376376
for (size_t i = 0; i < size; i++) {
377377
if (algoNames[i] && strcasecmp(algo, algoNames[i]) == 0) {
378-
m_algorithm = (int) i;
378+
m_algorithm = static_cast<Algo>(i);
379379
break;
380380
}
381381
}

0 commit comments

Comments
 (0)