From 068b286a888582f8dd1468ba8a8236f5e240c194 Mon Sep 17 00:00:00 2001 From: gavinbarnard Date: Sat, 6 Sep 2025 06:17:36 +0000 Subject: [PATCH] full share validation via cmdline option --- docs/COMMAND_LINE.MD | 9 +++++++++ src/main.cpp | 1 + src/params.cpp | 5 +++++ src/params.h | 1 + src/stratum_server.cpp | 10 +++++----- src/stratum_server.h | 2 +- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/COMMAND_LINE.MD b/docs/COMMAND_LINE.MD index eda2d88..279dc5d 100644 --- a/docs/COMMAND_LINE.MD +++ b/docs/COMMAND_LINE.MD @@ -39,6 +39,7 @@ --rpc-ssl Enable SSL on RPC connections to the Monero node --rpc-ssl-fingerprint base64-encoded fingerprint of the Monero node's certificate (optional, use it for certificate pinning) --no-stratum-http Disable HTTP on Stratum ports +--full-validation Enables full share validation / increases CPU usage ``` ### Example command line @@ -116,3 +117,11 @@ openssl x509 -in rpc_ssl.crt -pubkey -noout -inform pem | openssl pkey -pubin -o ``` By default, `rpc_ssl.crt` can be found in Monero data directory: `/home/username/.bitmonero/rpc_ssl.crt` on Linux and `C:\ProgramData\bitmonero\rpc_ssl.crt` on Windows. + + +### Full validation + +`--full-validation` is a boolean flag and will set the value to true; by default it is false to reduce CPU usage + +Enable this if untrusted sources can submit shares to your p2pool server and you want to verify the validity of the shares PoW. Increases CPU usage. +This option is for shared mining services, and not neccessary in local setups. \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 61f1bb1..0efee4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,6 +100,7 @@ void p2pool_usage() "--rpc-ssl-fingerprint base64-encoded fingerprint of the Monero node's certificate (optional, use it for certificate pinning)\n" #endif "--no-stratum-http Disable HTTP on Stratum ports\n" + "--full-validation Enables full share validation / increases CPU usage\n" "--help Show this help message\n\n" "Example command line:\n\n" "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n", diff --git a/src/params.cpp b/src/params.cpp index 02d83d2..77953ed 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -258,6 +258,11 @@ Params::Params(int argc, char* const argv[]) } #endif + if (strcmp(argv[i], "--full-validation") == 0) { + m_enableFullValidation = true; + ok = true; + } + if (!ok) { // Wait to avoid log messages overlapping with printf() calls and making a mess on screen std::this_thread::sleep_for(std::chrono::milliseconds(10)); diff --git a/src/params.h b/src/params.h index 46de756..df8a8c9 100644 --- a/src/params.h +++ b/src/params.h @@ -116,6 +116,7 @@ struct Params uint8_t priv_key[64]; }; #endif + bool m_enableFullValidation = false; }; } // namespace p2pool diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index 208b265..5bc2324 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -47,6 +47,7 @@ StratumServer::StratumServer(p2pool* pool) : TCPServer(DEFAULT_BACKLOG, StratumClient::allocate, std::string()) , m_pool(pool) , m_autoDiff(pool->params().m_autoDiff) + , m_enableFullValidation(pool->params().m_enableFullValidation) , m_rng(RandomDeviceSeed::instance) , m_cumulativeHashes(0) , m_cumulativeHashesAtLastShare(0) @@ -480,7 +481,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo update_auto_diff(client, share.m_timestamp, share.m_hashes); // If this share is below sidechain difficulty, process it in this thread because it'll be quick - if (!share.m_highEnoughDifficulty) { + if (!share.m_highEnoughDifficulty && !m_enableFullValidation) { on_share_found(&share.m_req); on_after_share_found(&share.m_req, 0); return true; @@ -951,7 +952,7 @@ void StratumServer::on_share_found(uv_work_t* req) return; } - if (share->m_highEnoughDifficulty) { + if (share->m_highEnoughDifficulty || server->m_enableFullValidation) { BACKGROUND_JOB_START(StratumServer::on_share_found); } @@ -960,7 +961,7 @@ void StratumServer::on_share_found(uv_work_t* req) const uint64_t target = share->m_target; const uint64_t hashes = share->m_hashes; - if (share->m_highEnoughDifficulty) { + if (share->m_highEnoughDifficulty || server->m_enableFullValidation) { if (pool->stopped()) { LOGWARN(0, "p2pool is shutting down, but a share was found. Trying to process it anyway!"); } @@ -1024,8 +1025,7 @@ void StratumServer::on_share_found(uv_work_t* req) prev_time = server->m_lastSidechainShareFoundTime; server->m_lastSidechainShareFoundTime = cur_time; } - - if (!pool->submit_sidechain_block(share->m_templateId, share->m_nonce, share->m_extraNonce)) { + if (share->m_highEnoughDifficulty && !pool->submit_sidechain_block(share->m_templateId, share->m_nonce, share->m_extraNonce)) { WriteLock lock(server->m_hashrateDataLock); if (server->m_totalFoundSidechainShares > 0) { diff --git a/src/stratum_server.h b/src/stratum_server.h index 6d3a0b9..fc097e2 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -115,7 +115,7 @@ private: p2pool* m_pool; bool m_autoDiff; - + bool m_enableFullValidation; struct BlobsData { uint32_t m_extraNonceStart;