diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index fa28889..a8c1a0b 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -760,6 +760,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) { diff --git a/src/pool_block.h b/src/pool_block.h index b95a283..4b538ed 100644 --- a/src/pool_block.h +++ b/src/pool_block.h @@ -54,6 +54,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 dd44e73..29eee72 100644 --- a/src/pool_block_parser.inl +++ b/src/pool_block_parser.inl @@ -326,12 +326,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__; + } + uint8_t merkle_proof_size; READ_BYTE(merkle_proof_size);