// 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 "cryptonote_core/cryptonote_basic.h" #include "cryptonote_core/Currency.h" #include "cryptonote_core/difficulty.h" #include "cryptonote_core/i_miner_handler.h" #include "cryptonote_core/MinerConfig.h" #include "cryptonote_core/OnceInInterval.h" #include #include "serialization/ISerializer.h" namespace CryptoNote { class miner { public: miner(const Currency& currency, i_miner_handler& handler, Logging::ILogger& log); ~miner(); bool init(const MinerConfig& config); bool set_block_template(const Block& bl, const difficulty_type& diffic); bool on_block_chain_update(); bool start(const AccountPublicAddress& adr, size_t threads_count, const boost::thread::attributes& attrs); uint64_t get_speed(); void send_stop_signal(); bool stop(); bool is_mining(); bool on_idle(); void on_synchronized(); //synchronous analog (for fast calls) static bool find_nonce_for_given_block(crypto::cn_context &context, Block& bl, const difficulty_type& diffic); void pause(); void resume(); void do_print_hashrate(bool do_hr); private: bool worker_thread(uint32_t th_local_index); bool request_block_template(); void merge_hr(); struct miner_config { uint64_t current_extra_message_index; void serialize(ISerializer& s) { KV_MEMBER(current_extra_message_index) } }; const Currency& m_currency; Logging::LoggerRef logger; std::atomic m_stop; std::mutex m_template_lock; Block m_template; std::atomic m_template_no; std::atomic m_starter_nonce; difficulty_type m_diffic; std::atomic m_threads_total; std::atomic m_pausers_count; std::mutex m_miners_count_lock; std::list m_threads; std::mutex m_threads_lock; i_miner_handler& m_handler; AccountPublicAddress m_mine_address; OnceInInterval m_update_block_template_interval; OnceInInterval m_update_merge_hr_interval; std::vector m_extra_messages; miner_config m_config; std::string m_config_folder_path; std::atomic m_last_hr_merge_time; std::atomic m_hashes; std::atomic m_current_hash_rate; std::mutex m_last_hash_rates_lock; std::list m_last_hash_rates; bool m_do_print_hashrate; bool m_do_mining; }; }