From 143bd192a2aa73c1ad85936d49c53a7075e211e6 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 8 Aug 2018 21:55:51 +0200 Subject: [PATCH 1/6] Allow integer algo-perf values --- src/core/Config.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index d72ae86f..32a7322b 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -345,7 +345,9 @@ void xmrig::Config::parseJSON(const rapidjson::Document &doc) const xmrig::PerfAlgo pa = static_cast(a); const rapidjson::Value &key = algo_perf[xmrig::Algorithm::perfAlgoName(pa)]; if (key.IsDouble()) { - m_algo_perf[pa] = key.GetDouble(); + m_algo_perf[pa] = static_cast(key.GetDouble()); + } else if (key.IsInt()) { + m_algo_perf[pa] = static_cast(key.GetInt()); } } } From cff4757a965bf0c732dd1a743b60127133be759d Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Mon, 20 Aug 2018 17:23:17 +0200 Subject: [PATCH 2/6] Fixed repo location --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 6054b9f8..06b39843 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # XMRig -:warning: **If you mine Monero, Aeon, Sumokoin, Turtlecoin, Stellite, GRAFT, Haven Protocol, IPBC, [PLEASE READ](https://github.com/xmrig/xmrig/issues/482)!** :warning: +:warning: **If you mine Monero, Aeon, Sumokoin, Turtlecoin, Stellite, GRAFT, Haven Protocol, IPBC, [PLEASE READ](https://github.com/MoneroOcean/xmrig/issues/482)!** :warning: -[![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/xmrig/xmrig/releases) -[![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/xmrig/xmrig/releases) -[![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/releases) -[![GitHub license](https://img.shields.io/github/license/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/blob/master/LICENSE) -[![GitHub stars](https://img.shields.io/github/stars/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/stargazers) -[![GitHub forks](https://img.shields.io/github/forks/xmrig/xmrig.svg)](https://github.com/xmrig/xmrig/network) +[![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig/total.svg)](https://github.com/MoneroOcean/xmrig/releases) +[![GitHub release](https://img.shields.io/github/release/xmrig/xmrig/all.svg)](https://github.com/MoneroOcean/xmrig/releases) +[![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig.svg)](https://github.com/MoneroOcean/xmrig/releases) +[![GitHub license](https://img.shields.io/github/license/xmrig/xmrig.svg)](https://github.com/MoneroOcean/xmrig/blob/master/LICENSE) +[![GitHub stars](https://img.shields.io/github/stars/xmrig/xmrig.svg)](https://github.com/MoneroOcean/xmrig/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/xmrig/xmrig.svg)](https://github.com/MoneroOcean/xmrig/network) XMRig is a high performance Monero (XMR) CPU miner, with official support for Windows. Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 completely rewritten from scratch on C++. -* This is the **CPU-mining** version, there is also a [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia) and [AMD GPU version]( https://github.com/xmrig/xmrig-amd). -* [Roadmap](https://github.com/xmrig/xmrig/issues/106) for next releases. +* This is the **CPU-mining** version, there is also a [NVIDIA GPU version](https://github.com/MoneroOcean/xmrig-nvidia) and [AMD GPU version]( https://github.com/MoneroOcean/xmrig-amd). +* [Roadmap](https://github.com/MoneroOcean/xmrig/issues/106) for next releases. @@ -22,7 +22,7 @@ Originally based on cpuminer-multi with heavy optimizations/rewrites and removin * [Download](#download) * [Usage](#usage) * [Algorithm variations](#algorithm-variations) -* [Build](https://github.com/xmrig/xmrig/wiki/Build) +* [Build](https://github.com/MoneroOcean/xmrig/wiki/Build) * [Common Issues](#common-issues) * [Other information](#other-information) * [Donations](#donations) @@ -38,14 +38,14 @@ Originally based on cpuminer-multi with heavy optimizations/rewrites and removin * keepalived support. * Command line options compatible with cpuminer. * CryptoNight-Lite support for AEON. -* Smart automatic [CPU configuration](https://github.com/xmrig/xmrig/wiki/Threads). +* Smart automatic [CPU configuration](https://github.com/MoneroOcean/xmrig/wiki/Threads). * Nicehash support * It's open source software. ## Download -* Binary releases: https://github.com/xmrig/xmrig/releases -* Git tree: https://github.com/xmrig/xmrig.git - * Clone with `git clone https://github.com/xmrig/xmrig.git` :hammer: [Build instructions](https://github.com/xmrig/xmrig/wiki/Build). +* Binary releases: https://github.com/MoneroOcean/xmrig/releases +* Git tree: https://github.com/MoneroOcean/xmrig.git + * Clone with `git clone https://github.com/MoneroOcean/xmrig.git` :hammer: [Build instructions](https://github.com/MoneroOcean/xmrig/wiki/Build). ## Usage Use [config.xmrig.com](https://config.xmrig.com/xmrig) to generate, edit or share configurations. From a671cdcadfeb240bed467ce3a8560f4934f3ff68 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 22 Aug 2018 21:46:49 +0200 Subject: [PATCH 3/6] Added helper script for pool algo switch emulation --- mt.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 mt.js diff --git a/mt.js b/mt.js new file mode 100644 index 00000000..d621b010 --- /dev/null +++ b/mt.js @@ -0,0 +1,107 @@ +#!/usr/bin/env node + +// Miner Tester: testing miner algo switch stability + +"use strict"; + +// ***************************************************************************** +// *** DEPENDECIES *** +// ***************************************************************************** + +const net = require('net'); + +// ***************************************************************************** +// *** CONSTS *** +// ***************************************************************************** + +const algos = [ "cn/1", "cn/xtl", "cn/msr", "cn/xao", "cn/rto", "cn-heavy/0", "cn-heavy/tube", "cn-heavy/xhv", "cn-lite/1" ]; + +// ***************************************************************************** +// *** WORKING STATE *** +// ***************************************************************************** + +let curr_miner_socket = null; + +// ***************************************************************************** +// *** FUNCTIONS *** +// ***************************************************************************** + +// *** Console/log output + +function log(msg) { + console.log(">>> " + msg); +} + +function err(msg) { + console.error("!!! " + msg); +} + +// *** Miner socket processing + +const test_blob_str = "7f7ffeeaa0db054f15eca39c843cb82c15e5c5a7743e06536cb541d4e96e90ffd31120b7703aa90000000076a6f6e34a9977c982629d8fe6c8b45024cafca109eef92198784891e0df41bc03"; + +let miner_server = net.createServer(function (miner_socket) { + if (curr_miner_socket) { + err("Miner server on localhost:3333 port is already connected (please make sure you do not have other miner running)"); + return; + } + log("Miner server on localhost:3333 port connected from " + miner_socket.remoteAddress); + + let miner_data_buff = ""; + + miner_socket.on('data', function (msg) { + miner_data_buff += msg; + if (miner_data_buff.indexOf('\n') === -1) return; + let messages = miner_data_buff.split('\n'); + let incomplete_line = miner_data_buff.slice(-1) === '\n' ? '' : messages.pop(); + for (let i = 0; i < messages.length; i++) { + let message = messages[i]; + if (message.trim() === '') continue; + let json; + try { + json = JSON.parse(message); + } catch (e) { + err("Can't parse message from the miner: " + message); + continue; + } + const is_keepalived = "method" in json && json.method === "keepalived"; + if ("method" in json && json.method === "login") { + miner_socket.write( + '{"id":1,"jsonrpc":"2.0","error":null,"result":{"id":"benchmark","job":{"blob":"' + test_blob_str + + '","algo":"cn/1","job_id":"benchmark1","target":"10000000","id":"benchmark"},"status":"OK"}}\n' + ); + curr_miner_socket = miner_socket; + } + } + miner_data_buff = incomplete_line; + }); + miner_socket.on('end', function() { + log("Miner socket was closed"); + curr_miner_socket = null; + }); + miner_socket.on('error', function() { + err("Miner socket error"); + miner_socket.destroy(); + curr_miner_socket = null; + }); +}); + +let job_num = 1; +function change_algo() { + if (curr_miner_socket) { + const algo = algos[Math.floor(Math.random() * algos.length)]; + log("Switching to " + algo); + curr_miner_socket.write( + '{"jsonrpc":"2.0","method":"job","params":{"blob":"' + test_blob_str + '","algo":"' + algo + + '","job_id":"benchmark' + ++job_num + '","target":"10000000","id":"benchmark"}}\n' + ); + } + const sleep = Math.floor(Math.random() * 5); + log("Waiting " + sleep + "s"); + setTimeout(change_algo, sleep * 1000); +} + +miner_server.listen(3333, "localhost", function() { + log("Local miner server on localhost:3333 port started"); + change_algo(); +}); From 541ecc4e4b5e153ccc5b0fb65981dbb4eab3bfd3 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 22 Aug 2018 21:48:22 +0200 Subject: [PATCH 4/6] Fixed memory leak --- mt.js | 0 src/workers/Handle.cpp | 2 ++ src/workers/Handle.h | 1 + 3 files changed, 3 insertions(+) mode change 100644 => 100755 mt.js diff --git a/mt.js b/mt.js old mode 100644 new mode 100755 diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index d42ea368..a7a06c79 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -23,6 +23,7 @@ #include "workers/Handle.h" +#include "interfaces/IWorker.h" Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : @@ -33,6 +34,7 @@ Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : { } +Handle::~Handle() { if (m_worker) delete m_worker; } void Handle::join() { diff --git a/src/workers/Handle.h b/src/workers/Handle.h index 4bb899f9..40df51f2 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -40,6 +40,7 @@ class Handle { public: Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays); + ~Handle(); void join(); void start(void (*callback) (void *)); From 1a819c61890ad940edf3d5f4cb1abb893d4e3e69 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 22 Aug 2018 21:49:57 +0200 Subject: [PATCH 5/6] Fixed memory leak --- src/workers/Hashrate.cpp | 11 +++++++++++ src/workers/Hashrate.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 2a750318..10fd8279 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -71,6 +71,17 @@ Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) : } } +Hashrate::~Hashrate() +{ + for (size_t i = 0; i < m_threads; i++) { + delete [] m_counts[i]; + delete [] m_timestamps[i]; + } + delete [] m_counts; + delete [] m_timestamps; + delete [] m_top; +} + double Hashrate::calc(size_t ms) const { diff --git a/src/workers/Hashrate.h b/src/workers/Hashrate.h index e766f117..8b323a80 100644 --- a/src/workers/Hashrate.h +++ b/src/workers/Hashrate.h @@ -44,6 +44,7 @@ public: }; Hashrate(size_t threads, xmrig::Controller *controller); + ~Hashrate(); double calc(size_t ms) const; double calc(size_t threadId, size_t ms) const; void add(size_t threadId, uint64_t count, uint64_t timestamp); From 87eb62b4eb01c8bfcf3d2194d3b60fe82fc5c09a Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Wed, 22 Aug 2018 21:52:56 +0200 Subject: [PATCH 6/6] Fixed new/free mismatch and uninit memory usage --- src/common/Platform_mac.cpp | 2 +- src/common/Platform_unix.cpp | 2 +- src/common/Platform_win.cpp | 2 +- src/common/net/Pool.cpp | 9 +++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/Platform_mac.cpp b/src/common/Platform_mac.cpp index b8181cc4..7a2849b0 100644 --- a/src/common/Platform_mac.cpp +++ b/src/common/Platform_mac.cpp @@ -42,7 +42,7 @@ static inline char *createUserAgent() { const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); # ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); diff --git a/src/common/Platform_unix.cpp b/src/common/Platform_unix.cpp index 97b32ee8..15be0f5f 100644 --- a/src/common/Platform_unix.cpp +++ b/src/common/Platform_unix.cpp @@ -56,7 +56,7 @@ static inline char *createUserAgent() { const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); # if defined(__x86_64__) diff --git a/src/common/Platform_win.cpp b/src/common/Platform_win.cpp index 47f41867..7026fd17 100644 --- a/src/common/Platform_win.cpp +++ b/src/common/Platform_win.cpp @@ -60,7 +60,7 @@ static inline char *createUserAgent() const auto osver = winOsVersion(); const size_t max = 160; - char *buf = new char[max]; + char *buf = static_cast(malloc(max)); int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); # if defined(__x86_64__) || defined(_M_AMD64) diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index bfe42b51..aa9c943e 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -97,7 +97,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo const size_t size = m_host.size() + 8; assert(size > 8); - char *url = new char[size](); + char *url = static_cast(malloc(size)); snprintf(url, size - 1, "%s:%d", m_host.data(), m_port); m_url = url; @@ -171,8 +171,9 @@ bool Pool::parse(const char *url) } const size_t size = port++ - base + 1; - char *host = new char[size](); + char *host = static_cast(malloc(size)); memcpy(host, base, size - 1); + host[size - 1] = 0; m_host = host; m_port = static_cast(strtol(port, nullptr, 10)); @@ -188,7 +189,7 @@ bool Pool::setUserpass(const char *userpass) return false; } - char *user = new char[p - userpass + 1](); + char *user = static_cast(malloc(p - userpass + 1)); strncpy(user, userpass, p - userpass); m_user = user; @@ -279,7 +280,7 @@ bool Pool::parseIPv6(const char *addr) } const size_t size = end - addr; - char *host = new char[size](); + char *host = static_cast(malloc(size)); memcpy(host, addr + 1, size - 1); m_host = host;