Skip to content

Commit

Permalink
KNC ETH stratum support
Browse files Browse the repository at this point in the history
  • Loading branch information
MoneroOcean committed Jun 5, 2024
1 parent 2215ab1 commit 90a7e11
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
54 changes: 42 additions & 12 deletions src/base/net/stratum/EthStratumClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#ifdef XMRIG_ALGO_GHOSTRIDER
#include <cmath>
#include "base/crypto/sha3.h"

extern "C" {
#include "crypto/ghostrider/sph_sha2.h"
Expand Down Expand Up @@ -307,18 +308,47 @@ void xmrig::EthStratumClient::parseNotification(const char *method, const rapidj
}
}

sha256d(merkle_root, buf.data(), static_cast<int>(buf.size()));

auto merkle_branches = arr[4].GetArray();
for (int i = 0, n = merkle_branches.Size(); i < n; ++i) {
auto& b = merkle_branches[i];
buf = b.IsString() ? Cvt::fromHex(b.GetString(), b.GetStringLength()) : Buffer();
if (buf.size() != 32) {
LOG_ERR("%s " RED("invalid mining.notify notification: param 4 is invalid"), tag());
return;
}
memcpy(merkle_root + 32, buf.data(), 32);
sha256d(merkle_root, merkle_root, 64);
if (algo.id() == Algorithm::GHOSTRIDER_RTM) {
sha256d(merkle_root, buf.data(), static_cast<int>(buf.size()));
auto merkle_branches = arr[4].GetArray();
for (int i = 0, n = merkle_branches.Size(); i < n; ++i) {
auto& b = merkle_branches[i];
buf = b.IsString() ? Cvt::fromHex(b.GetString(), b.GetStringLength()) : Buffer();
if (buf.size() != 32) {
LOG_ERR("%s " RED("invalid mining.notify notification: param 4 is invalid"), tag());
return;
}
memcpy(merkle_root + 32, buf.data(), 32);
sha256d(merkle_root, merkle_root, 64);
}
} else {
#define SHA3_256(a, b, c) sha3_HashBuffer(256, SHA3_FLAGS_NONE, b, c, a, 32)
auto merkle_branches = arr[4].GetArray();
int length = merkle_branches.Size() + 1;
uint8_t* merkle_tree = new uint8_t[32*length];
SHA3_256(merkle_tree, buf.data(), static_cast<int>(buf.size()));
SHA3_256(merkle_tree, merkle_tree, 32);
for (int i = 1; i < length; ++i) {
auto& b = merkle_branches[i-1];
buf = b.IsString() ? Cvt::fromHex(b.GetString(), b.GetStringLength()) : Buffer();
if (buf.size() != 32) {
LOG_ERR("%s " RED("invalid mining.notify notification: param 4 is invalid"), tag());
delete [] merkle_tree;
return;
}
memcpy(merkle_tree + 32*i, buf.data(), 32);
}
while (length > 1) {
int j = 0;
for (int i = 0; i < length; i += 2, ++j) {
memcpy(merkle_root, merkle_tree + 32*i, 32);
memcpy(merkle_root + 32, merkle_tree + 32*(i + 1 == length ? i : i+1), 32);
sha256d(merkle_tree + 32*j, merkle_root, 64);
}
length = j;
}
memcpy(merkle_root, merkle_tree, 32);
delete [] merkle_tree;
}

s << Cvt::toHex(merkle_root, 32);
Expand Down
7 changes: 5 additions & 2 deletions src/base/net/stratum/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,14 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
if ((f == Algorithm::KAWPOW) || (f == Algorithm::GHOSTRIDER) || (m_coin == Coin::RAVEN)) {
client = new EthStratumClient(id, Platform::userAgent(), listener);
}
else
# endif
else {
client = new AutoClient(id, Platform::userAgent(), listener);
}
#else
{
client = new Client(id, Platform::userAgent(), listener);
}
# endif
}
# ifdef XMRIG_FEATURE_HTTP
else if (m_mode == MODE_DAEMON) {
Expand Down
4 changes: 0 additions & 4 deletions src/base/net/stratum/Pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ class Pool
bool m_submitToOrigin = false;
Coin m_coin;
int m_keepAlive = 0;
# if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER
Mode m_mode = MODE_AUTO_ETH;
# else
Mode m_mode = MODE_POOL;
# endif
ProxyUrl m_proxy;
std::bitset<FLAG_MAX> m_flags = 0;
String m_fingerprint;
Expand Down

0 comments on commit 90a7e11

Please sign in to comment.