// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers // // This file is part of Bytecoin. // // Bytecoin is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Bytecoin is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with Bytecoin. If not, see . #pragma once #include #include #include #include #include #include "CryptoNote.h" #include "CryptoNoteCore/Difficulty.h" #include "Logging/LoggerRef.h" namespace CryptoNote { struct BlockMiningParameters { Block blockTemplate; difficulty_type difficulty; }; class Miner { public: Miner(System::Dispatcher& dispatcher, Logging::ILogger& logger); ~Miner(); Block mine(const BlockMiningParameters& blockMiningParameters, size_t threadCount); //NOTE! this is blocking method void stop(); private: System::Dispatcher& m_dispatcher; System::Event m_miningStopped; enum class MiningState : uint8_t { MINING_STOPPED, BLOCK_FOUND, MINING_IN_PROGRESS}; std::atomic m_state; std::vector>> m_workers; Block m_block; Logging::LoggerRef m_logger; void runWorkers(BlockMiningParameters blockMiningParameters, size_t threadCount); void workerFunc(const Block& blockTemplate, difficulty_type difficulty, uint32_t nonceStep); bool setStateBlockFound(); }; } //namespace CryptoNote