From 1b0103c119e436aac9f6eecb5d8c9fa464d0ff97 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Thu, 11 Apr 2024 20:41:20 +0200 Subject: [PATCH 1/4] Fixed include paths --- src/crypto.cpp | 2 +- src/miner.cpp | 2 +- src/p2pool.cpp | 2 +- src/side_chain.cpp | 2 +- src/util.h | 2 +- src/wallet.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/crypto.cpp b/src/crypto.cpp index 21b39ea..352cbb5 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -21,7 +21,7 @@ #include "uv_util.h" extern "C" { -#include "crypto-ops.h" +#include } // l = 2^252 + 27742317777372353535851937790883648493. diff --git a/src/miner.cpp b/src/miner.cpp index 0b8b299..d36bf7e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -21,7 +21,7 @@ #include "stratum_server.h" #include "block_template.h" #include "pow_hash.h" -#include "randomx.h" +#include #include "params.h" #include "p2pool_api.h" #include "side_chain.h" diff --git a/src/p2pool.cpp b/src/p2pool.cpp index 9084592..cbd0f56 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -20,7 +20,7 @@ #include "zmq_reader.h" #include "mempool.h" #include "json_rpc_request.h" -#include "rapidjson/document.h" +#include #include "json_parsers.h" #include "pow_hash.h" #include "block_template.h" diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 80e605b..7280852 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -33,7 +33,7 @@ #include "params.h" #include "json_parsers.h" #include "crypto.h" -#include "hardforks/hardforks.h" +#include #include #include #include diff --git a/src/util.h b/src/util.h index 8dfb79d..d69b4b4 100644 --- a/src/util.h +++ b/src/util.h @@ -26,7 +26,7 @@ #define ROBIN_HOOD_CALLOC(count, size) p2pool::calloc_hook((count), (size)) #define ROBIN_HOOD_FREE(ptr) p2pool::free_hook(ptr) -#include "robin_hood.h" +#include #ifdef _MSC_VER #pragma warning(pop) diff --git a/src/wallet.cpp b/src/wallet.cpp index 5110331..fe1db64 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -24,7 +24,7 @@ #include "crypto.h" extern "C" { -#include "crypto-ops.h" +#include } namespace { From a847baf33159ef125523843a44edd0e81ddb7919 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Tue, 23 Apr 2024 18:10:09 +0200 Subject: [PATCH 2/4] Revert "Fixed include paths" This reverts commit 1b0103c119e436aac9f6eecb5d8c9fa464d0ff97. --- src/crypto.cpp | 2 +- src/miner.cpp | 2 +- src/p2pool.cpp | 2 +- src/side_chain.cpp | 2 +- src/util.h | 2 +- src/wallet.cpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/crypto.cpp b/src/crypto.cpp index 352cbb5..21b39ea 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -21,7 +21,7 @@ #include "uv_util.h" extern "C" { -#include +#include "crypto-ops.h" } // l = 2^252 + 27742317777372353535851937790883648493. diff --git a/src/miner.cpp b/src/miner.cpp index d36bf7e..0b8b299 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -21,7 +21,7 @@ #include "stratum_server.h" #include "block_template.h" #include "pow_hash.h" -#include +#include "randomx.h" #include "params.h" #include "p2pool_api.h" #include "side_chain.h" diff --git a/src/p2pool.cpp b/src/p2pool.cpp index cbd0f56..9084592 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -20,7 +20,7 @@ #include "zmq_reader.h" #include "mempool.h" #include "json_rpc_request.h" -#include +#include "rapidjson/document.h" #include "json_parsers.h" #include "pow_hash.h" #include "block_template.h" diff --git a/src/side_chain.cpp b/src/side_chain.cpp index 7280852..80e605b 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -33,7 +33,7 @@ #include "params.h" #include "json_parsers.h" #include "crypto.h" -#include +#include "hardforks/hardforks.h" #include #include #include diff --git a/src/util.h b/src/util.h index d69b4b4..8dfb79d 100644 --- a/src/util.h +++ b/src/util.h @@ -26,7 +26,7 @@ #define ROBIN_HOOD_CALLOC(count, size) p2pool::calloc_hook((count), (size)) #define ROBIN_HOOD_FREE(ptr) p2pool::free_hook(ptr) -#include +#include "robin_hood.h" #ifdef _MSC_VER #pragma warning(pop) diff --git a/src/wallet.cpp b/src/wallet.cpp index fe1db64..5110331 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -24,7 +24,7 @@ #include "crypto.h" extern "C" { -#include +#include "crypto-ops.h" } namespace { From b3f562caab00be9c2c475636d386db669a58f86d Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Tue, 23 Apr 2024 18:29:19 +0200 Subject: [PATCH 3/4] Added sanity checks for height and difficulty --- src/pool_block.h | 6 ++++++ src/pool_block_parser.inl | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/pool_block.h b/src/pool_block.h index 947c50c..4281bd6 100644 --- a/src/pool_block.h +++ b/src/pool_block.h @@ -53,6 +53,12 @@ static constexpr uint64_t MAX_BLOCK_SIZE = 128 * 1024 - 5; // 0.6 XMR static constexpr uint64_t BASE_BLOCK_REWARD = 600000000000ULL; +// 1000 years at 1 TH/s. It should be enough for any normal use. +static constexpr difficulty_type MAX_CUMULATIVE_DIFFICULTY{ 13019633956666736640ULL, 1710ULL }; + +// 1000 years at 1 block/second. It should be enough for any normal use. +static constexpr uint64_t MAX_SIDECHAIN_HEIGHT = 31556952000ULL; + struct DifficultyData { FORCEINLINE DifficultyData(uint64_t t, const difficulty_type& d) : m_timestamp(t), m_cumulativeDifficulty(d) {} diff --git a/src/pool_block_parser.inl b/src/pool_block_parser.inl index 5ff85b5..d80048c 100644 --- a/src/pool_block_parser.inl +++ b/src/pool_block_parser.inl @@ -306,12 +306,20 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si READ_VARINT(m_sidechainHeight); + if (m_sidechainHeight > MAX_SIDECHAIN_HEIGHT) { + return __LINE__; + } + READ_VARINT(m_difficulty.lo); READ_VARINT(m_difficulty.hi); READ_VARINT(m_cumulativeDifficulty.lo); READ_VARINT(m_cumulativeDifficulty.hi); + if (m_cumulativeDifficulty > MAX_CUMULATIVE_DIFFICULTY) { + return __LINE__; + } + READ_BUF(m_sidechainExtraBuf, sizeof(m_sidechainExtraBuf)); #undef READ_BYTE From 6dd72dfcd5a3ff131fcccb3f11baa36fe22349bc Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Tue, 23 Apr 2024 18:40:15 +0200 Subject: [PATCH 4/4] Fixed a rare crash on shutdown --- src/p2p_server.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index d27d0db..9a66c24 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -771,6 +771,11 @@ void P2PServer::Peer::normalize() void P2PServer::broadcast(const PoolBlock& block, const PoolBlock* parent) { + // Don't broadcast blocks when shutting down + if (m_finished.load()) { + return; + } + MinerData miner_data = m_pool->miner_data(); if (block.m_txinGenHeight + 2 < miner_data.height) {