Rewrite automatic variant handling.

This commit is contained in:
XMRig 2018-09-03 15:39:55 +03:00
parent a27dfa8b70
commit bb3990a076
5 changed files with 41 additions and 28 deletions

View file

@ -270,17 +270,17 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
}
if (params.HasMember("algo")) {
job.algorithm().parseAlgorithm(params["algo"].GetString());
job.setAlgorithm(params["algo"].GetString());
}
if (params.HasMember("variant")) {
const rapidjson::Value &variant = params["variant"];
if (variant.IsInt()) {
job.algorithm().parseVariant(variant.GetInt());
job.setVariant(variant.GetInt());
}
else if (variant.IsString()){
job.algorithm().parseVariant(variant.GetString());
job.setVariant(variant.GetString());
}
}

View file

@ -59,6 +59,7 @@ static inline char hf_bin2hex(unsigned char c)
Job::Job() :
m_autoVariant(false),
m_nicehash(false),
m_poolId(-2),
m_threadId(-1),
@ -70,7 +71,8 @@ Job::Job() :
}
Job::Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId) :
Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) :
m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO),
m_nicehash(nicehash),
m_poolId(poolId),
m_threadId(-1),
@ -113,6 +115,10 @@ bool Job::setBlob(const char *blob)
m_nicehash = true;
}
if (m_autoVariant) {
m_algorithm.setVariant(variant());
}
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawBlob, 0, sizeof(m_rawBlob));
memcpy(m_rawBlob, blob, m_size * 2);
@ -164,22 +170,6 @@ bool Job::setTarget(const char *target)
}
xmrig::Variant Job::variant() const
{
if (m_algorithm.variant() == xmrig::VARIANT_AUTO) {
if (m_algorithm.algo() == xmrig::CRYPTONIGHT_HEAVY) {
return xmrig::VARIANT_0;
} else if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) {
return xmrig::VARIANT_1;
}
return (m_blob[0] >= 8) ? xmrig::VARIANT_2 : xmrig::VARIANT_1;
}
return m_algorithm.variant();
}
bool Job::fromHex(const char* in, unsigned int len, unsigned char* out)
{
bool error = false;
@ -224,3 +214,25 @@ bool Job::operator!=(const Job &other) const
{
return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
}
xmrig::Variant Job::variant() const
{
using namespace xmrig;
switch (m_algorithm.algo()) {
case CRYPTONIGHT:
return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1;
case CRYPTONIGHT_LITE:
return VARIANT_1;
case CRYPTONIGHT_HEAVY:
return VARIANT_0;
default:
break;
}
return m_algorithm.variant();
}

View file

@ -39,12 +39,11 @@ class Job
{
public:
Job();
Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId);
Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId);
~Job();
bool setBlob(const char *blob);
bool setTarget(const char *target);
xmrig::Variant variant() const;
inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
@ -61,10 +60,12 @@ public:
inline uint32_t diff() const { return static_cast<uint32_t>(m_diff); }
inline uint64_t target() const { return m_target; }
inline void reset() { m_size = 0; m_diff = 0; }
inline void setAlgorithm(const char *algo) { m_algorithm.parseAlgorithm(algo); }
inline void setClientId(const xmrig::Id &id) { m_clientId = id; }
inline void setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; }
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); }
inline void setVariant(int variant) { m_algorithm.parseVariant(variant); }
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
@ -84,6 +85,9 @@ public:
bool operator!=(const Job &other) const;
private:
xmrig::Variant variant() const;
bool m_autoVariant;
bool m_nicehash;
int m_poolId;
int m_threadId;

View file

@ -166,12 +166,9 @@ bool Network::isColors() const
void Network::setJob(Client *client, const Job &job, bool donate)
{
xmrig::Algorithm algorithm = job.algorithm();
algorithm.setVariant(job.variant());
LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s")
: "new job from %s:%d diff %d algo %s",
client->host(), client->port(), job.diff(), algorithm.shortName());
client->host(), client->port(), job.diff(), job.algorithm().shortName());
m_state.diff = job.diff();
Workers::setJob(job, donate);

View file

@ -104,7 +104,7 @@ void MultiWorker<N>::start()
storeStats();
}
m_thread->fn(m_state.job.variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx);
m_thread->fn(m_state.job.algorithm().variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx);
for (size_t i = 0; i < N; ++i) {
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) {