Implemented VM mode for OpenCL RandomX.
This commit is contained in:
parent
4c90f9960e
commit
95daab4bc0
42 changed files with 450 additions and 165 deletions
|
@ -25,32 +25,18 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
#include "base/net/stratum/Job.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
|
||||
|
||||
xmrig::Job::Job() :
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job::Job(bool nicehash, const Algorithm &algorithm, const String &clientId) :
|
||||
m_algorithm(algorithm),
|
||||
m_nicehash(nicehash),
|
||||
m_clientId(clientId),
|
||||
m_blob(),
|
||||
m_seedHash()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Job::~Job()
|
||||
m_clientId(clientId)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -96,7 +82,7 @@ bool xmrig::Job::setBlob(const char *blob)
|
|||
|
||||
bool xmrig::Job::setSeedHash(const char *hash)
|
||||
{
|
||||
if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) {
|
||||
if (!hash || (strlen(hash) != kMaxSeedSize * 2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -104,7 +90,9 @@ bool xmrig::Job::setSeedHash(const char *hash)
|
|||
m_rawSeedHash = hash;
|
||||
# endif
|
||||
|
||||
return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash);
|
||||
m_seed = Buffer::fromHex(hash, kMaxSeedSize * 2);
|
||||
|
||||
return !m_seed.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,9 +161,9 @@ void xmrig::Job::copy(const Job &other)
|
|||
m_height = other.m_height;
|
||||
m_target = other.m_target;
|
||||
m_index = other.m_index;
|
||||
m_seed = other.m_seed;
|
||||
|
||||
memcpy(m_blob, other.m_blob, sizeof(m_blob));
|
||||
memcpy(m_seedHash, other.m_seedHash, sizeof(m_seedHash));
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
m_rawSeedHash = other.m_rawSeedHash;
|
||||
|
|
|
@ -28,10 +28,11 @@
|
|||
#define XMRIG_JOB_H
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "crypto/common/Algorithm.h"
|
||||
|
||||
|
@ -45,10 +46,11 @@ public:
|
|||
// Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
// SECOR increase requirements for blob size: https://github.com/xmrig/xmrig/issues/913
|
||||
static constexpr const size_t kMaxBlobSize = 128;
|
||||
static constexpr const size_t kMaxSeedSize = 32;
|
||||
|
||||
Job();
|
||||
Job() = default;
|
||||
Job(bool nicehash, const Algorithm &algorithm, const String &clientId);
|
||||
~Job();
|
||||
~Job() = default;
|
||||
|
||||
bool isEqual(const Job &other) const;
|
||||
bool setBlob(const char *blob);
|
||||
|
@ -60,11 +62,11 @@ public:
|
|||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
inline bool setId(const char *id) { return m_id = id; }
|
||||
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const Buffer &seed() const { return m_seed; }
|
||||
inline const String &clientId() const { return m_clientId; }
|
||||
inline const String &id() const { return m_id; }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline const uint8_t *seedHash() const { return m_seedHash; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint64_t diff() const { return m_diff; }
|
||||
|
@ -97,15 +99,15 @@ private:
|
|||
|
||||
Algorithm m_algorithm;
|
||||
bool m_nicehash = false;
|
||||
Buffer m_seed;
|
||||
size_t m_size = 0;
|
||||
String m_clientId;
|
||||
String m_id;
|
||||
uint64_t m_diff = 0;
|
||||
uint64_t m_height = 0;
|
||||
uint64_t m_target = 0;
|
||||
uint8_t m_blob[kMaxBlobSize];
|
||||
uint8_t m_blob[kMaxBlobSize]{ 0 };
|
||||
uint8_t m_index = 0;
|
||||
uint8_t m_seedHash[32];
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
char m_rawBlob[kMaxBlobSize * 2 + 8];
|
||||
|
|
|
@ -53,14 +53,7 @@ static inline uint8_t hf_bin2hex(uint8_t c)
|
|||
}
|
||||
|
||||
|
||||
xmrig::Buffer::Buffer() :
|
||||
m_data(nullptr),
|
||||
m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::Buffer::Buffer(Buffer &&other) :
|
||||
xmrig::Buffer::Buffer(Buffer &&other) noexcept :
|
||||
m_data(other.m_data),
|
||||
m_size(other.m_size)
|
||||
{
|
||||
|
@ -138,11 +131,13 @@ bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out)
|
|||
xmrig::Buffer xmrig::Buffer::fromHex(const char *data, size_t size)
|
||||
{
|
||||
if (data == nullptr || size % 2 != 0) {
|
||||
return Buffer();
|
||||
return {};
|
||||
}
|
||||
|
||||
Buffer buf(size / 2);
|
||||
fromHex(data, size, buf.data());
|
||||
if (!fromHex(data, size, buf.data())) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -157,12 +152,6 @@ void xmrig::Buffer::toHex(const uint8_t *in, size_t size, uint8_t *out)
|
|||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Buffer::toHex(const uint8_t *in, size_t size)
|
||||
{
|
||||
return Buffer(reinterpret_cast<const char *>(in), size).toHex();
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Buffer::toHex() const
|
||||
{
|
||||
if (m_size == 0) {
|
||||
|
|
|
@ -35,14 +35,15 @@ namespace xmrig {
|
|||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer();
|
||||
Buffer(Buffer &&other);
|
||||
Buffer() = default;
|
||||
Buffer(Buffer &&other) noexcept;
|
||||
Buffer(const Buffer &other);
|
||||
Buffer(const char *data, size_t size);
|
||||
Buffer(size_t size);
|
||||
~Buffer();
|
||||
|
||||
|
||||
inline bool isEmpty() const { return size() == 0; }
|
||||
inline bool isEqual(const Buffer &other) const { return m_size == other.m_size && (m_size == 0 || memcmp(m_data, other.m_data, m_size) == 0); }
|
||||
inline char *data() { return m_data; }
|
||||
inline const char *data() const { return m_data; }
|
||||
|
@ -55,7 +56,7 @@ public:
|
|||
|
||||
inline bool operator!=(const Buffer &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Buffer &other) const { return isEqual(other); }
|
||||
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
|
||||
inline Buffer &operator=(Buffer &&other) noexcept { move(std::move(other)); return *this; }
|
||||
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
|
||||
|
||||
|
||||
|
@ -67,12 +68,13 @@ public:
|
|||
inline static bool fromHex(const char *in, size_t size, uint8_t *out) { return fromHex(reinterpret_cast<const uint8_t *>(in), size, out); }
|
||||
inline static Buffer fromHex(const char *data) { return fromHex(data, strlen(data)); }
|
||||
inline static Buffer fromHex(const String &str) { return fromHex(str.data(), str.size()); }
|
||||
inline static String toHex(const char *in, size_t size) { return Buffer(in, size).toHex(); }
|
||||
inline static String toHex(const uint8_t *in, size_t size) { return Buffer(reinterpret_cast<const char *>(in), size).toHex(); }
|
||||
inline static void toHex(const char *in, size_t size, char *out) { return toHex(reinterpret_cast<const uint8_t *>(in), size, reinterpret_cast<uint8_t *>(out)); }
|
||||
inline static void toHex(const uint8_t *in, size_t size, char *out) { return toHex(in, size, reinterpret_cast<uint8_t *>(out)); }
|
||||
|
||||
static bool fromHex(const uint8_t *in, size_t size, uint8_t *out);
|
||||
static Buffer fromHex(const char *data, size_t size);
|
||||
static String toHex(const uint8_t *in, size_t size);
|
||||
static void toHex(const uint8_t *in, size_t size, uint8_t *out);
|
||||
String toHex() const;
|
||||
|
||||
|
@ -80,8 +82,8 @@ private:
|
|||
void copy(const char *data, size_t size);
|
||||
void move(Buffer &&other);
|
||||
|
||||
char *m_data;
|
||||
size_t m_size;
|
||||
char *m_data = nullptr;
|
||||
size_t m_size = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue