mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 03:59:41 +00:00
Code cleanup.
This commit is contained in:
parent
4326ba3c38
commit
c828e6b793
7 changed files with 61 additions and 69 deletions
|
@ -1,5 +1,6 @@
|
||||||
if (WITH_RANDOMX)
|
if (WITH_RANDOMX)
|
||||||
add_definitions(/DXMRIG_ALGO_RANDOMX)
|
add_definitions(/DXMRIG_ALGO_RANDOMX)
|
||||||
|
set(WITH_ARGON2 ON)
|
||||||
|
|
||||||
list(APPEND HEADERS_CRYPTO
|
list(APPEND HEADERS_CRYPTO
|
||||||
src/crypto/rx/Rx.h
|
src/crypto/rx/Rx.h
|
||||||
|
|
|
@ -89,13 +89,13 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName)
|
||||||
m_watch = reader.getBool(kWatch, m_watch);
|
m_watch = reader.getBool(kWatch, m_watch);
|
||||||
m_logFile = reader.getString(kLogFile);
|
m_logFile = reader.getString(kLogFile);
|
||||||
m_userAgent = reader.getString(kUserAgent);
|
m_userAgent = reader.getString(kUserAgent);
|
||||||
|
m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U);
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_TLS
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
m_tls = reader.getValue(kTls);
|
m_tls = reader.getValue(kTls);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
Log::setColors(reader.getBool(kColors, Log::isColors()));
|
Log::setColors(reader.getBool(kColors, Log::isColors()));
|
||||||
setPrintTime(reader.getUint(kPrintTime, 60));
|
|
||||||
setVerbose(reader.getValue(kVerbose));
|
setVerbose(reader.getValue(kVerbose));
|
||||||
|
|
||||||
const auto &api = reader.getObject(kApi);
|
const auto &api = reader.getObject(kApi);
|
||||||
|
|
|
@ -112,8 +112,6 @@ protected:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } }
|
|
||||||
|
|
||||||
void setVerbose(const rapidjson::Value &value);
|
void setVerbose(const rapidjson::Value &value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include "base/tools/Timer.h"
|
#include "base/tools/Timer.h"
|
||||||
#include "core/config/Config.h"
|
#include "core/config/Config.h"
|
||||||
#include "core/Controller.h"
|
#include "core/Controller.h"
|
||||||
#include "crypto/astrobwt/AstroBWT.h"
|
|
||||||
#include "crypto/common/Nonce.h"
|
#include "crypto/common/Nonce.h"
|
||||||
#include "crypto/rx/Rx.h"
|
#include "crypto/rx/Rx.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
@ -67,6 +66,11 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_ALGO_ASTROBWT
|
||||||
|
# include "crypto/astrobwt/AstroBWT.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,15 +242,36 @@ public:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
|
void printHashrate(bool details)
|
||||||
|
{
|
||||||
|
char num[8 * 4] = { 0 };
|
||||||
|
double speed[3] = { 0.0 };
|
||||||
|
|
||||||
|
for (auto backend : backends) {
|
||||||
|
const auto hashrate = backend->hashrate();
|
||||||
|
if (hashrate) {
|
||||||
|
speed[0] += hashrate->calc(Hashrate::ShortInterval);
|
||||||
|
speed[1] += hashrate->calc(Hashrate::MediumInterval);
|
||||||
|
speed[2] += hashrate->calc(Hashrate::LargeInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
backend->printHashrate(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"),
|
||||||
|
Hashrate::format(speed[0], num, sizeof(num) / 4),
|
||||||
|
Hashrate::format(speed[1], num + 8, sizeof(num) / 4),
|
||||||
|
Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ),
|
||||||
|
Hashrate::format(maxHashrate[algorithm], num + 8 * 3, sizeof(num) / 4)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
inline bool initRX() { return Rx::init(job, controller->config()->rx(), controller->config()->cpu()); }
|
inline bool initRX() { return Rx::init(job, controller->config()->rx(), controller->config()->cpu()); }
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_ASTROBWT
|
|
||||||
inline bool initAstroBWT() { return astrobwt::init(job); }
|
|
||||||
# endif
|
|
||||||
|
|
||||||
Algorithm algorithm;
|
Algorithm algorithm;
|
||||||
Algorithms algorithms;
|
Algorithms algorithms;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
@ -279,6 +304,10 @@ xmrig::Miner::Miner(Controller *controller)
|
||||||
Rx::init(this);
|
Rx::init(this);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef XMRIG_ALGO_ASTROBWT
|
||||||
|
astrobwt::init();
|
||||||
|
# endif
|
||||||
|
|
||||||
controller->addListener(this);
|
controller->addListener(this);
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_API
|
# ifdef XMRIG_FEATURE_API
|
||||||
|
@ -345,7 +374,7 @@ void xmrig::Miner::execCommand(char command)
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'H':
|
case 'H':
|
||||||
printHashrate(true);
|
d_ptr->printHashrate(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
|
@ -384,31 +413,6 @@ void xmrig::Miner::pause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Miner::printHashrate(bool details)
|
|
||||||
{
|
|
||||||
char num[8 * 4] = { 0 };
|
|
||||||
double speed[3] = { 0.0 };
|
|
||||||
|
|
||||||
for (IBackend *backend : d_ptr->backends) {
|
|
||||||
const Hashrate *hashrate = backend->hashrate();
|
|
||||||
if (hashrate) {
|
|
||||||
speed[0] += hashrate->calc(Hashrate::ShortInterval);
|
|
||||||
speed[1] += hashrate->calc(Hashrate::MediumInterval);
|
|
||||||
speed[2] += hashrate->calc(Hashrate::LargeInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
backend->printHashrate(details);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"),
|
|
||||||
Hashrate::format(speed[0], num, sizeof(num) / 4),
|
|
||||||
Hashrate::format(speed[1], num + 8, sizeof(num) / 4),
|
|
||||||
Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ),
|
|
||||||
Hashrate::format(d_ptr->maxHashrate[d_ptr->algorithm], num + 8 * 3, sizeof(num) / 4)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Miner::setEnabled(bool enabled)
|
void xmrig::Miner::setEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (d_ptr->enabled == enabled) {
|
if (d_ptr->enabled == enabled) {
|
||||||
|
@ -459,14 +463,10 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
|
||||||
d_ptr->userJobId = job.id();
|
d_ptr->userJobId = job.id();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ready = true;
|
|
||||||
|
|
||||||
# ifdef XMRIG_ALGO_RANDOMX
|
# ifdef XMRIG_ALGO_RANDOMX
|
||||||
ready &= d_ptr->initRX();
|
const bool ready = d_ptr->initRX();
|
||||||
# endif
|
# else
|
||||||
|
constexpr const bool ready = true;
|
||||||
# ifdef XMRIG_ALGO_ASTROBWT
|
|
||||||
ready &= d_ptr->initAstroBWT();
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
@ -524,7 +524,7 @@ void xmrig::Miner::onTimer(const Timer *)
|
||||||
|
|
||||||
const auto printTime = d_ptr->controller->config()->printTime();
|
const auto printTime = d_ptr->controller->config()->printTime();
|
||||||
if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) {
|
if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) {
|
||||||
printHashrate(false);
|
d_ptr->printHashrate(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
d_ptr->ticks++;
|
d_ptr->ticks++;
|
||||||
|
|
|
@ -61,7 +61,6 @@ public:
|
||||||
Job job() const;
|
Job job() const;
|
||||||
void execCommand(char command);
|
void execCommand(char command);
|
||||||
void pause();
|
void pause();
|
||||||
void printHashrate(bool details);
|
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
void setJob(const Job &job, bool donate);
|
void setJob(const Job &job, bool donate);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
|
@ -27,15 +27,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "AstroBWT.h"
|
#include "crypto/astrobwt/AstroBWT.h"
|
||||||
#include "sha3.h"
|
|
||||||
#include "crypto/cn/CryptoNight.h"
|
|
||||||
#include "base/net/stratum/Job.h"
|
|
||||||
#include "base/crypto/Algorithm.h"
|
|
||||||
#include "base/io/log/Log.h"
|
|
||||||
#include "backend/cpu/Cpu.h"
|
#include "backend/cpu/Cpu.h"
|
||||||
|
#include "crypto/astrobwt/sha3.h"
|
||||||
|
#include "crypto/cn/CryptoNight.h"
|
||||||
|
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
|
||||||
constexpr int STAGE1_SIZE = 147253;
|
constexpr int STAGE1_SIZE = 147253;
|
||||||
constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63));
|
constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63));
|
||||||
|
|
||||||
|
@ -171,24 +171,6 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool xmrig::astrobwt::init(const xmrig::Job& job)
|
|
||||||
{
|
|
||||||
if (job.algorithm().family() != xmrig::Algorithm::ASTROBWT)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (astrobwtInitialized)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
#ifdef ASTROBWT_AVX2
|
|
||||||
if (xmrig::Cpu::info()->hasAVX2()) {
|
|
||||||
hasAVX2 = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
astrobwtInitialized = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2)
|
bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2)
|
||||||
{
|
{
|
||||||
uint8_t key[32];
|
uint8_t key[32];
|
||||||
|
@ -257,6 +239,19 @@ bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::astrobwt::init()
|
||||||
|
{
|
||||||
|
if (!astrobwtInitialized) {
|
||||||
|
# ifdef ASTROBWT_AVX2
|
||||||
|
hasAVX2 = Cpu::info()->hasAVX2();
|
||||||
|
# endif
|
||||||
|
|
||||||
|
astrobwtInitialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void xmrig::astrobwt::single_hash<xmrig::Algorithm::ASTROBWT_DERO>(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t)
|
void xmrig::astrobwt::single_hash<xmrig::Algorithm::ASTROBWT_DERO>(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,12 +35,11 @@ struct cryptonight_ctx;
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
class Job;
|
|
||||||
|
|
||||||
namespace astrobwt {
|
namespace astrobwt {
|
||||||
|
|
||||||
bool init(const Job&);
|
|
||||||
bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2);
|
bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2);
|
||||||
|
void init();
|
||||||
|
|
||||||
template<Algorithm::Id ALGO>
|
template<Algorithm::Id ALGO>
|
||||||
void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t);
|
void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t);
|
||||||
|
|
Loading…
Reference in a new issue