From 8253b1c4f3778511d09de96cce87d135dd463cd5 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Fri, 26 Jul 2019 11:22:49 -0700 Subject: [PATCH] Added RX switch tester --- build.bat => misc/build.bat | 0 build_rh6.sh => misc/build_rh6.sh | 0 misc/switch_test.js | 107 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) rename build.bat => misc/build.bat (100%) rename build_rh6.sh => misc/build_rh6.sh (100%) create mode 100644 misc/switch_test.js diff --git a/build.bat b/misc/build.bat similarity index 100% rename from build.bat rename to misc/build.bat diff --git a/build_rh6.sh b/misc/build_rh6.sh similarity index 100% rename from build_rh6.sh rename to misc/build_rh6.sh diff --git a/misc/switch_test.js b/misc/switch_test.js new file mode 100644 index 00000000..bba34709 --- /dev/null +++ b/misc/switch_test.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 = [ "rx/wow", "rx/loki" ]; + +// ***************************************************************************** +// *** 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","seed_hash":"0000000000000000000000000000000000000000000000000000000000000001","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 + '","height":0,"seed_hash":"0000000000000000000000000000000000000000000000000000000000000000","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(); +}); \ No newline at end of file