Added an option to disable RandomX for the build

This commit is contained in:
SChernykh
2022-03-15 16:56:37 +01:00
parent 52050bbcfb
commit 62b1690780
10 changed files with 74 additions and 11 deletions
+13 -1
View File
@@ -21,7 +21,9 @@
#include "p2pool.h"
#include "stratum_server.h"
#include "p2p_server.h"
#ifdef WITH_RANDOMX
#include "miner.h"
#endif
#include "side_chain.h"
#include <iostream>
@@ -70,7 +72,11 @@ typedef struct cmd {
cmdfunc *func;
} cmd;
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showbans, do_outpeers, do_inpeers, do_start_mining, do_stop_mining, do_exit;
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showbans, do_outpeers, do_inpeers, do_exit;
#ifdef WITH_RANDOMX
static cmdfunc do_start_mining, do_stop_mining;
#endif
static cmd cmds[] = {
{ STRCONST("help"), "", "display list of commands", do_help },
@@ -82,8 +88,10 @@ static cmd cmds[] = {
{ STRCONST("bans"), "", "show all banned IPs", do_showbans },
{ STRCONST("outpeers"), "", "set maximum number of outgoing connections", do_outpeers },
{ STRCONST("inpeers"), "", "set maximum number of incoming connections", do_inpeers },
#ifdef WITH_RANDOMX
{ STRCONST("start_mining"), "<threads>", "start mining", do_start_mining },
{ STRCONST("stop_mining"), "", "stop mining", do_stop_mining },
#endif
{ STRCONST("exit"), "", "terminate p2pool", do_exit },
{ STRCNULL, NULL, NULL, NULL }
};
@@ -106,9 +114,11 @@ static int do_status(p2pool *m_pool, const char * /* args */)
if (m_pool->p2p_server()) {
m_pool->p2p_server()->print_status();
}
#ifdef WITH_RANDOMX
if (m_pool->miner()) {
m_pool->miner()->print_status();
}
#endif
bkg_jobs_tracker.print_status();
return 0;
}
@@ -175,6 +185,7 @@ static int do_inpeers(p2pool* m_pool, const char* args)
return 0;
}
#ifdef WITH_RANDOMX
static int do_start_mining(p2pool* m_pool, const char* args)
{
uint32_t threads = strtoul(args, nullptr, 10);
@@ -188,6 +199,7 @@ static int do_stop_mining(p2pool* m_pool, const char* /*args*/)
m_pool->stop_mining();
return 0;
}
#endif
static int do_exit(p2pool *m_pool, const char * /* args */)
{
+14
View File
@@ -27,7 +27,9 @@
#include "side_chain.h"
#include "stratum_server.h"
#include "p2p_server.h"
#ifdef WITH_RANDOMX
#include "miner.h"
#endif
#include "params.h"
#include "console_commands.h"
#include "crypto.h"
@@ -128,12 +130,16 @@ p2pool::p2pool(int argc, char* argv[])
m_params->m_p2pAddresses = buf;
}
#ifdef WITH_RANDOMX
if (m_params->m_disableRandomX) {
m_hasher = new RandomX_Hasher_RPC(this);
}
else {
m_hasher = new RandomX_Hasher(this);
}
#else
m_hasher = new RandomX_Hasher_RPC(this);
#endif
m_blockTemplate = new BlockTemplate(this);
m_mempool = new Mempool();
@@ -602,9 +608,11 @@ void p2pool::download_block_headers(uint64_t current_height)
m_ZMQReader = new ZMQReader(m_params->m_host.c_str(), m_params->m_zmqPort, this);
m_stratumServer = new StratumServer(this);
m_p2pServer = new P2PServer(this);
#ifdef WITH_RANDOMX
if (m_params->m_minerThreads) {
start_mining(m_params->m_minerThreads);
}
#endif
api_update_network_stats();
}
}
@@ -671,9 +679,11 @@ void p2pool::update_median_timestamp()
void p2pool::stratum_on_block()
{
#ifdef WITH_RANDOMX
if (m_miner) {
m_miner->on_block(*m_blockTemplate);
}
#endif
if (m_stratumServer) {
m_stratumServer->on_block(*m_blockTemplate);
}
@@ -1219,6 +1229,7 @@ bool p2pool::get_difficulty_at_height(uint64_t height, difficulty_type& diff)
return true;
}
#ifdef WITH_RANDOMX
void p2pool::start_mining(uint32_t threads)
{
stop_mining();
@@ -1233,6 +1244,7 @@ void p2pool::stop_mining()
delete miner;
}
}
#endif
static void on_signal(uv_signal_t* handle, int signum)
{
@@ -1342,7 +1354,9 @@ int p2pool::run()
bkg_jobs_tracker.wait();
#ifdef WITH_RANDOMX
delete m_miner;
#endif
delete m_stratumServer;
delete m_p2pServer;
+6
View File
@@ -59,7 +59,9 @@ public:
StratumServer* stratum_server() const { return m_stratumServer; }
P2PServer* p2p_server() const { return m_p2pServer; }
#ifdef WITH_RANDOMX
Miner* miner() const { return m_miner; }
#endif
virtual void handle_tx(TxMempoolData& tx) override;
virtual void handle_miner_data(MinerData& data) override;
@@ -80,8 +82,10 @@ public:
bool get_difficulty_at_height(uint64_t height, difficulty_type& diff);
#ifdef WITH_RANDOMX
void start_mining(uint32_t threads);
void stop_mining();
#endif
time_t zmq_last_active() const { return m_zmqLastActive; }
time_t start_time() const { return m_startTime; }
@@ -160,7 +164,9 @@ private:
std::atomic<uint32_t> m_serversStarted{ 0 };
StratumServer* m_stratumServer = nullptr;
P2PServer* m_p2pServer = nullptr;
#ifdef WITH_RANDOMX
Miner* m_miner = nullptr;
#endif
ConsoleCommands* m_consoleCommands;
+4
View File
@@ -39,7 +39,11 @@ struct Params
std::string m_apiPath;
bool m_localStats = false;
bool m_blockCache = true;
#ifdef WITH_RANDOMX
bool m_disableRandomX = false;
#else
bool m_disableRandomX = true;
#endif
uint32_t m_maxOutgoingPeers = 10;
uint32_t m_maxIncomingPeers = 1000;
uint32_t m_minerThreads = 0;
+4
View File
@@ -19,9 +19,11 @@
#include "pow_hash.h"
#include "p2pool.h"
#include "params.h"
#ifdef WITH_RANDOMX
#include "randomx.h"
#include "configuration.h"
#include "virtual_machine.hpp"
#endif
#include "json_rpc_request.h"
#include "json_parsers.h"
#include <rapidjson/document.h>
@@ -31,6 +33,7 @@ static constexpr char log_category_prefix[] = "RandomX_Hasher ";
namespace p2pool {
#ifdef WITH_RANDOMX
RandomX_Hasher::RandomX_Hasher(p2pool* pool)
: m_pool(pool)
, m_cache{}
@@ -357,6 +360,7 @@ bool RandomX_Hasher::calculate(const void* data, size_t size, uint64_t /*height*
return false;
}
#endif
RandomX_Hasher_RPC::RandomX_Hasher_RPC(p2pool* pool)
: m_pool(pool)
+2
View File
@@ -43,6 +43,7 @@ public:
virtual bool calculate(const void* data, size_t size, uint64_t height, const hash& seed, hash& result) = 0;
};
#ifdef WITH_RANDOMX
class RandomX_Hasher : public RandomX_Hasher_Base
{
public:
@@ -90,6 +91,7 @@ private:
std::atomic<uint32_t> m_seedCounter;
};
#endif
class RandomX_Hasher_RPC : public RandomX_Hasher_Base
{
+7
View File
@@ -21,10 +21,12 @@
#include "pool_block.h"
#include "wallet.h"
#include "block_template.h"
#ifdef WITH_RANDOMX
#include "randomx.h"
#include "dataset.hpp"
#include "configuration.h"
#include "intrin_portable.h"
#endif
#include "keccak.h"
#include "p2p_server.h"
#include "stratum_server.h"
@@ -108,6 +110,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
m_consensusId.assign(mini_consensus_id, mini_consensus_id + HASH_SIZE);
}
else {
#ifdef WITH_RANDOMX
const randomx_flags flags = randomx_get_flags();
randomx_cache* cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
if (!cache) {
@@ -142,6 +145,10 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
keccak(reinterpret_cast<uint8_t*>(scratchpad), static_cast<int>(scratchpad_size * sizeof(rx_vec_i128)), id.h, HASH_SIZE);
randomx_release_cache(cache);
m_consensusId.assign(id.h, id.h + HASH_SIZE);
#else
LOGERR(1, "Can't calculate consensus ID without RandomX library");
panic();
#endif
}
s.m_pos = 0;