Merge branch 'master' into mo
This commit is contained in:
commit
91bd1cf8ce
9 changed files with 130 additions and 7 deletions
107
mt.js
Executable file
107
mt.js
Executable file
|
@ -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();
|
||||||
|
});
|
|
@ -42,7 +42,7 @@ static inline char *createUserAgent()
|
||||||
{
|
{
|
||||||
const size_t max = 160;
|
const size_t max = 160;
|
||||||
|
|
||||||
char *buf = new char[max];
|
char *buf = static_cast<char *>(malloc(max));
|
||||||
|
|
||||||
# ifdef XMRIG_NVIDIA_PROJECT
|
# ifdef XMRIG_NVIDIA_PROJECT
|
||||||
const int cudaVersion = cuda_get_runtime_version();
|
const int cudaVersion = cuda_get_runtime_version();
|
||||||
|
|
|
@ -56,7 +56,7 @@ static inline char *createUserAgent()
|
||||||
{
|
{
|
||||||
const size_t max = 160;
|
const size_t max = 160;
|
||||||
|
|
||||||
char *buf = new char[max];
|
char *buf = static_cast<char *>(malloc(max));
|
||||||
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
||||||
|
|
||||||
# if defined(__x86_64__)
|
# if defined(__x86_64__)
|
||||||
|
|
|
@ -60,7 +60,7 @@ static inline char *createUserAgent()
|
||||||
const auto osver = winOsVersion();
|
const auto osver = winOsVersion();
|
||||||
const size_t max = 160;
|
const size_t max = 160;
|
||||||
|
|
||||||
char *buf = new char[max];
|
char *buf = static_cast<char *>(malloc(max));
|
||||||
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
|
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)
|
# if defined(__x86_64__) || defined(_M_AMD64)
|
||||||
|
|
|
@ -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;
|
const size_t size = m_host.size() + 8;
|
||||||
assert(size > 8);
|
assert(size > 8);
|
||||||
|
|
||||||
char *url = new char[size]();
|
char *url = static_cast<char *>(malloc(size));
|
||||||
snprintf(url, size - 1, "%s:%d", m_host.data(), m_port);
|
snprintf(url, size - 1, "%s:%d", m_host.data(), m_port);
|
||||||
|
|
||||||
m_url = url;
|
m_url = url;
|
||||||
|
@ -171,8 +171,9 @@ bool Pool::parse(const char *url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t size = port++ - base + 1;
|
const size_t size = port++ - base + 1;
|
||||||
char *host = new char[size]();
|
char *host = static_cast<char *>(malloc(size));
|
||||||
memcpy(host, base, size - 1);
|
memcpy(host, base, size - 1);
|
||||||
|
host[size - 1] = 0;
|
||||||
|
|
||||||
m_host = host;
|
m_host = host;
|
||||||
m_port = static_cast<uint16_t>(strtol(port, nullptr, 10));
|
m_port = static_cast<uint16_t>(strtol(port, nullptr, 10));
|
||||||
|
@ -188,7 +189,7 @@ bool Pool::setUserpass(const char *userpass)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *user = new char[p - userpass + 1]();
|
char *user = static_cast<char *>(malloc(p - userpass + 1));
|
||||||
strncpy(user, userpass, p - userpass);
|
strncpy(user, userpass, p - userpass);
|
||||||
|
|
||||||
m_user = user;
|
m_user = user;
|
||||||
|
@ -279,7 +280,7 @@ bool Pool::parseIPv6(const char *addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t size = end - addr;
|
const size_t size = end - addr;
|
||||||
char *host = new char[size]();
|
char *host = static_cast<char *>(malloc(size));
|
||||||
memcpy(host, addr + 1, size - 1);
|
memcpy(host, addr + 1, size - 1);
|
||||||
|
|
||||||
m_host = host;
|
m_host = host;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "workers/Handle.h"
|
#include "workers/Handle.h"
|
||||||
|
#include "interfaces/IWorker.h"
|
||||||
|
|
||||||
|
|
||||||
Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) :
|
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()
|
void Handle::join()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ class Handle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays);
|
Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays);
|
||||||
|
~Handle();
|
||||||
void join();
|
void join();
|
||||||
void start(void (*callback) (void *));
|
void start(void (*callback) (void *));
|
||||||
|
|
||||||
|
|
|
@ -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
|
double Hashrate::calc(size_t ms) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Hashrate(size_t threads, xmrig::Controller *controller);
|
Hashrate(size_t threads, xmrig::Controller *controller);
|
||||||
|
~Hashrate();
|
||||||
double calc(size_t ms) const;
|
double calc(size_t ms) const;
|
||||||
double calc(size_t threadId, size_t ms) const;
|
double calc(size_t threadId, size_t ms) const;
|
||||||
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
void add(size_t threadId, uint64_t count, uint64_t timestamp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue