Skip to content

Commit

Permalink
Merge xmrig-proxy v6.19.2 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MoneroOcean committed May 31, 2023
2 parents 12c79c0 + d6ce28a commit 3f66272
Show file tree
Hide file tree
Showing 31 changed files with 263 additions and 90 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v6.19.2
- [#532](https://github.com/xmrig/xmrig-proxy/pull/532) Added view tag calculation (fixes Wownero solo mining issue).
- Sync with latest XMRig.

# v6.19.0
- [#530](https://github.com/xmrig/xmrig-proxy/pull/530) Sync with latest XMRig.

# v6.18.0
- Sync changes with XMRig v6.18.0
- [#499](https://github.com/xmrig/xmrig-proxy/pull/499) Fixed socket and memory leak.
Expand Down
2 changes: 1 addition & 1 deletion cmake/os.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else()
set(XMRIG_OS_ANDROID ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(XMRIG_OS_LINUX ON)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL DragonFly)
set(XMRIG_OS_FREEBSD ON)
endif()
endif()
Expand Down
10 changes: 6 additions & 4 deletions src/base/kernel/Platform.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "base/kernel/Platform.h"


Expand All @@ -42,9 +41,12 @@ void xmrig::Platform::init(const char *userAgent)
# ifdef XMRIG_FEATURE_TLS
SSL_library_init();
SSL_load_error_strings();

# if OPENSSL_VERSION_NUMBER < 0x30000000L || defined(LIBRESSL_VERSION_NUMBER)
ERR_load_BIO_strings();
ERR_load_crypto_strings();
SSL_load_error_strings();
# endif

OpenSSL_add_all_digests();
# endif

Expand Down
28 changes: 20 additions & 8 deletions src/base/kernel/Platform_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef __FreeBSD__
#ifdef XMRIG_OS_FREEBSD
# include <sys/types.h>
# include <sys/param.h>
# include <sys/cpuset.h>
# ifndef __DragonFly__
# include <sys/cpuset.h>
# endif
# include <pthread_np.h>
#endif

Expand All @@ -41,11 +43,6 @@
#include "version.h"


#ifdef __FreeBSD__
typedef cpuset_t cpu_set_t;
#endif


char *xmrig::Platform::createUserAgent()
{
constexpr const size_t max = 256;
Expand Down Expand Up @@ -74,6 +71,19 @@ char *xmrig::Platform::createUserAgent()


#ifndef XMRIG_FEATURE_HWLOC
#ifdef __DragonFly__

bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
return true;
}

#else

#ifdef XMRIG_OS_FREEBSD
typedef cpuset_t cpu_set_t;
#endif

bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
{
cpu_set_t mn;
Expand All @@ -89,7 +99,9 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
return result;
}
#endif

#endif // __DragonFly__
#endif // XMRIG_FEATURE_HWLOC


void xmrig::Platform::setProcessPriority(int)
Expand Down
4 changes: 4 additions & 0 deletions src/base/kernel/config/BaseTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
case IConfig::HttpPort: /* --http-port */
case IConfig::DonateLevelKey: /* --donate-level */
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
case IConfig::DaemonJobTimeoutKey: /* --daemon-job-timeout */
case IConfig::DnsTtlKey: /* --dns-ttl */
case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return transformUint64(doc, key, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
Expand Down Expand Up @@ -360,6 +361,9 @@ void xmrig::BaseTransform::transformUint64(rapidjson::Document &doc, int key, ui
case IConfig::DaemonPollKey: /* --daemon-poll-interval */
return add(doc, Pools::kPools, Pool::kDaemonPollInterval, arg);

case IConfig::DaemonJobTimeoutKey: /* --daemon-job-timeout */
return add(doc, Pools::kPools, Pool::kDaemonJobTimeout, arg);

case IConfig::DaemonZMQPortKey: /* --daemon-zmq-port */
return add(doc, Pools::kPools, Pool::kDaemonZMQPort, arg);
# endif
Expand Down
1 change: 1 addition & 0 deletions src/base/kernel/interfaces/IConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class IConfig
DaemonZMQPortKey = 1056,
HugePagesJitKey = 1057,
RotationKey = 1058,
DaemonJobTimeoutKey = 1059,

// xmrig common
CPUPriorityKey = 1021,
Expand Down
8 changes: 4 additions & 4 deletions src/base/net/dns/DnsRecord.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -46,11 +46,11 @@ xmrig::String xmrig::DnsRecord::ip() const

if (m_type == AAAA) {
buf = new char[45]();
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(m_data), buf, 45);
uv_ip6_name(reinterpret_cast<const sockaddr_in6*>(m_data), buf, 45);
}
else {
buf = new char[16]();
uv_ip4_name(reinterpret_cast<sockaddr_in*>(m_data), buf, 16);
uv_ip4_name(reinterpret_cast<const sockaddr_in*>(m_data), buf, 16);
}

return buf;
Expand Down
29 changes: 18 additions & 11 deletions src/base/net/dns/DnsUvBackend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2023 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2023 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -28,18 +28,19 @@

namespace xmrig {

static Storage<DnsUvBackend>* storage = nullptr;

Storage<DnsUvBackend>& DnsUvBackend::getStorage()
static Storage<DnsUvBackend> *storage = nullptr;


Storage<DnsUvBackend> &DnsUvBackend::getStorage()
{
if (storage == nullptr) storage = new Storage<DnsUvBackend>();
if (storage == nullptr) {
storage = new Storage<DnsUvBackend>();
}

return *storage;
}

void DnsUvBackend::releaseStorage()
{
delete storage;
}

static addrinfo hints{};

Expand All @@ -61,8 +62,14 @@ xmrig::DnsUvBackend::DnsUvBackend()

xmrig::DnsUvBackend::~DnsUvBackend()
{
getStorage().release(m_key);
releaseStorage();
assert(storage);

storage->release(m_key);

if (storage->isEmpty()) {
delete storage;
storage = nullptr;
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/base/net/stratum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)

if (status < 0) {
if (!client->isQuiet()) {
LOG_ERR("%s " RED("connect error: ") RED_BOLD("\"%s\""), client->tag(), uv_strerror(status));
LOG_ERR("%s %s " RED("connect error: ") RED_BOLD("\"%s\""), client->tag(), client->ip().data(), uv_strerror(status));
}

if (client->state() == ReconnectingState || client->state() == ClosingState) {
Expand Down
46 changes: 40 additions & 6 deletions src/base/net/stratum/DaemonClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Storage<DaemonClient> DaemonClient::m_storage;

static const char* kBlocktemplateBlob = "blocktemplate_blob";
static const char* kBlockhashingBlob = "blockhashing_blob";
static const char* kLastError = "lasterror";
static const char *kGetHeight = "/getheight";
static const char *kGetInfo = "/getinfo";
static const char *kHash = "hash";
Expand Down Expand Up @@ -149,6 +148,11 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
memcpy(data + sig_offset * 2, result.sig, 64 * 2);
memcpy(data + m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) * 2, result.sig_data, 32 * 2);
memcpy(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2, result.sig_data + 32 * 2, 32 * 2);

// Handle view tag for txout_to_tagged_key outputs
if (m_blocktemplate.outputType() == 3) {
Cvt::toHex(data + m_blocktemplate.offset(BlockTemplate::EPH_PUBLIC_KEY_OFFSET) * 2 + 32 * 2, 2, &result.view_tag, 1);
}
}

if (result.extra_nonce >= 0) {
Expand Down Expand Up @@ -179,7 +183,10 @@ int64_t xmrig::DaemonClient::submit(const JobResult &result)
m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), 0, result.backend);
# endif

return rpcSend(doc);
std::map<std::string, std::string> headers;
headers.insert({"X-Hash-Difficulty", std::to_string(result.actualDiff())});

return rpcSend(doc, headers);
}


Expand Down Expand Up @@ -304,6 +311,18 @@ void xmrig::DaemonClient::onHttpData(const HttpData &data)

void xmrig::DaemonClient::onTimer(const Timer *)
{
if (m_pool.zmq_port() >= 0) {
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
send(kGetHeight);
return;
}

if (Chrono::steadyMSecs() >= m_jobSteadyMs + m_pool.jobTimeout()) {
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
}

if (m_state == ConnectingState) {
connect();
}
Expand Down Expand Up @@ -353,7 +372,7 @@ void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, cons

bool xmrig::DaemonClient::isOutdated(uint64_t height, const char *hash) const
{
return m_job.height() != height || m_prevHash != hash;
return m_job.height() != height || m_prevHash != hash || Chrono::steadyMSecs() >= m_jobSteadyMs + m_pool.jobTimeout();
}


Expand Down Expand Up @@ -390,7 +409,8 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
m_blocktemplate.offset(BlockTemplate::TX_PUBKEY_OFFSET) - k,
m_blocktemplate.offset(BlockTemplate::TX_EXTRA_NONCE_OFFSET) - k,
m_blocktemplate.txExtraNonce().size(),
m_blocktemplate.minerTxMerkleTreeBranch()
m_blocktemplate.minerTxMerkleTreeBranch(),
m_blocktemplate.outputType() == 3
);
# endif

Expand Down Expand Up @@ -427,7 +447,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
}

uint8_t derivation[32];
if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation)) {
if (!generate_key_derivation(m_blocktemplate.blob(BlockTemplate::TX_PUBKEY_OFFSET), secret_viewkey, derivation, nullptr)) {
return jobError("Failed to generate key derivation for miner signature.");
}

Expand Down Expand Up @@ -469,6 +489,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
m_job = std::move(job);
m_blocktemplateStr = std::move(blocktemplate);
m_prevHash = Json::getString(params, "prev_hash");
m_jobSteadyMs = Chrono::steadyMSecs();

if (m_state == ConnectingState) {
setState(ConnectedState);
Expand Down Expand Up @@ -541,9 +562,13 @@ int64_t xmrig::DaemonClient::getBlockTemplate()
}


int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc)
int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc, const std::map<std::string, std::string> &headers)
{
FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet());
for (const auto &header : headers) {
req.headers.insert(header);
}

fetch(tag(), std::move(req), m_httpListener);

return m_sequence++;
Expand Down Expand Up @@ -597,6 +622,10 @@ void xmrig::DaemonClient::setState(SocketState state)
const uint64_t interval = std::max<uint64_t>(20, m_pool.pollInterval());
m_timer->start(interval, interval);
}
else {
const uint64_t t = m_pool.jobTimeout();
m_timer->start(t, t);
}
}
break;

Expand Down Expand Up @@ -866,7 +895,12 @@ void xmrig::DaemonClient::ZMQParse()
// Clear previous hash and check daemon height to guarantee that xmrig will call get_block_template RPC later
// We can't call get_block_template directly because daemon is not ready yet
m_prevHash = nullptr;
m_blocktemplateRequestHash = nullptr;
send(kGetHeight);

const uint64_t t = m_pool.jobTimeout();
m_timer->stop();
m_timer->start(t, t);
}


Expand Down
3 changes: 2 additions & 1 deletion src/base/net/stratum/DaemonClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DaemonClient : public BaseClient, public IDnsListener, public ITimerListen
bool parseJob(const rapidjson::Value &params, int *code);
bool parseResponse(int64_t id, const rapidjson::Value &result, const rapidjson::Value &error);
int64_t getBlockTemplate();
int64_t rpcSend(const rapidjson::Document &doc);
int64_t rpcSend(const rapidjson::Document &doc, const std::map<std::string, std::string> &headers = {});
void retry();
void send(const char *path);
void setState(SocketState state);
Expand All @@ -104,6 +104,7 @@ class DaemonClient : public BaseClient, public IDnsListener, public ITimerListen
String m_blocktemplateStr;
String m_currentJobId;
String m_prevHash;
uint64_t m_jobSteadyMs = 0;
String m_tlsFingerprint;
String m_tlsVersion;
Timer *m_timer;
Expand Down
Loading

0 comments on commit 3f66272

Please sign in to comment.