mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
Added an option to disable RandomX for the build
This commit is contained in:
parent
52050bbcfb
commit
62b1690780
10 changed files with 74 additions and 11 deletions
9
.github/workflows/c-cpp.yml
vendored
9
.github/workflows/c-cpp.yml
vendored
|
@ -106,8 +106,9 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
config:
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\"}
|
||||
- {vs: Visual Studio 17 2022, os: 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\"}
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "ON"}
|
||||
- {vs: Visual Studio 17 2022, os: 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\", rx: "ON"}
|
||||
- {vs: Visual Studio 17 2022, os: 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\", rx: "OFF"}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
|
@ -122,7 +123,7 @@ jobs:
|
|||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -G "${{ matrix.config.vs }}"
|
||||
cmake .. -G "${{ matrix.config.vs }}" -DWITH_RANDOMX=${{ matrix.config.rx }}
|
||||
& "${{ matrix.config.msbuild }}msbuild" /m /p:Configuration=Release p2pool.vcxproj
|
||||
|
||||
- name: Build tests
|
||||
|
@ -141,7 +142,7 @@ jobs:
|
|||
- name: Archive binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: p2pool-msbuild-${{ matrix.config.os }}.exe
|
||||
name: p2pool-msbuild-${{ matrix.config.os }}-randomx-${{ matrix.config.rx }}.exe
|
||||
path: build/Release/p2pool.exe
|
||||
|
||||
build-macos:
|
||||
|
|
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
|
|||
project(p2pool)
|
||||
|
||||
option(STATIC_BINARY "Build static binary" OFF)
|
||||
option(WITH_RANDOMX "Include the RandomX library in the build. If this is turned off, p2pool will rely on monerod for verifying RandomX hashes" ON)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||
|
||||
|
@ -9,8 +10,11 @@ if (${CMAKE_VERSION} VERSION_GREATER "3.5.2")
|
|||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT p2pool)
|
||||
endif()
|
||||
|
||||
if (WITH_RANDOMX)
|
||||
add_definitions(-DWITH_RANDOMX)
|
||||
add_subdirectory(external/src/RandomX)
|
||||
set(LIBS randomx)
|
||||
endif()
|
||||
|
||||
include(cmake/flags.cmake)
|
||||
|
||||
|
@ -27,7 +31,6 @@ set(HEADERS
|
|||
src/keccak.h
|
||||
src/log.h
|
||||
src/mempool.h
|
||||
src/miner.h
|
||||
src/p2p_server.h
|
||||
src/p2pool.h
|
||||
src/p2pool_api.h
|
||||
|
@ -61,7 +64,6 @@ set(SOURCES
|
|||
src/main.cpp
|
||||
src/memory_leak_debug.cpp
|
||||
src/mempool.cpp
|
||||
src/miner.cpp
|
||||
src/p2p_server.cpp
|
||||
src/p2pool.cpp
|
||||
src/p2pool_api.cpp
|
||||
|
@ -75,6 +77,11 @@ set(SOURCES
|
|||
src/zmq_reader.cpp
|
||||
)
|
||||
|
||||
if (WITH_RANDOMX)
|
||||
set(HEADERS ${HEADERS} src/miner.h)
|
||||
set(SOURCES ${SOURCES} src/miner.cpp)
|
||||
endif()
|
||||
|
||||
include_directories(src)
|
||||
include_directories(external/src)
|
||||
include_directories(external/src/cryptonote)
|
||||
|
@ -82,7 +89,9 @@ include_directories(external/src/libuv/include)
|
|||
include_directories(external/src/cppzmq)
|
||||
include_directories(external/src/libzmq/include)
|
||||
include_directories(external/src/llhttp)
|
||||
if (WITH_RANDOMX)
|
||||
include_directories(external/src/RandomX/src)
|
||||
endif()
|
||||
include_directories(external/src/rapidjson/include)
|
||||
include_directories(external/src/robin-hood-hashing/src/include)
|
||||
|
||||
|
@ -127,7 +136,10 @@ add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES})
|
|||
if (STATIC_BINARY)
|
||||
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} ${CMAKE_PROJECT_NAME})
|
||||
|
||||
if (WITH_RANDOMX)
|
||||
set(STATIC_LIBS randomx)
|
||||
endif()
|
||||
|
||||
if (NOT APPLE)
|
||||
set(STATIC_LIBS ${STATIC_LIBS} pthread dl)
|
||||
endif()
|
||||
|
|
|
@ -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 */)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -19,6 +19,7 @@ set(LIBS gtest)
|
|||
|
||||
add_subdirectory(../external/src/RandomX RandomX)
|
||||
set(LIBS ${LIBS} randomx)
|
||||
add_definitions(-DWITH_RANDOMX)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
set(WARNING_FLAGS "")
|
||||
|
|
Loading…
Reference in a new issue