danicoin/src/Miner/Miner.h

68 lines
1.9 KiB
C
Raw Normal View History

2015-12-09 13:19:03 +00:00
// 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 <http://www.gnu.org/licenses/>.
#pragma once
#include <atomic>
#include <thread>
#include <System/Dispatcher.h>
#include <System/Event.h>
#include <System/RemoteContext.h>
#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<MiningState> m_state;
std::vector<std::unique_ptr<System::RemoteContext<void>>> 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