danicoin/src/cryptonote_core/miner.h

100 lines
3.3 KiB
C
Raw Normal View History

2014-08-13 10:38:35 +00:00
// Copyright (c) 2012-2014, 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/>.
2014-03-03 22:07:58 +00:00
2014-06-25 17:21:42 +00:00
#pragma once
2014-03-03 22:07:58 +00:00
#include <atomic>
2014-08-13 10:51:37 +00:00
#include <boost/program_options.hpp>
2014-03-03 22:07:58 +00:00
2014-08-13 10:51:37 +00:00
// epee
#include "serialization/keyvalue_serialization.h"
#include "math_helper.h"
2014-03-03 22:07:58 +00:00
2014-08-13 10:51:37 +00:00
#include "cryptonote_core/cryptonote_basic.h"
#include "cryptonote_core/Currency.h"
#include "cryptonote_core/difficulty.h"
#include "cryptonote_core/i_miner_handler.h"
2014-03-03 22:07:58 +00:00
2014-08-13 10:51:37 +00:00
namespace cryptonote {
class miner {
2014-06-25 17:21:42 +00:00
public:
2014-08-13 10:51:37 +00:00
miner(const Currency& currency, i_miner_handler* phandler);
2014-03-03 22:07:58 +00:00
~miner();
bool init(const boost::program_options::variables_map& vm);
static void init_options(boost::program_options::options_description& desc);
2014-08-13 10:51:37 +00:00
bool set_block_template(const Block& bl, const difficulty_type& diffic);
2014-03-03 22:07:58 +00:00
bool on_block_chain_update();
2014-08-13 10:51:37 +00:00
bool start(const AccountPublicAddress& adr, size_t threads_count, const boost::thread::attributes& attrs);
2014-03-03 22:07:58 +00:00
uint64_t get_speed();
void send_stop_signal();
bool stop();
bool is_mining();
bool on_idle();
void on_synchronized();
//synchronous analog (for fast calls)
2014-08-13 10:51:37 +00:00
static bool find_nonce_for_given_block(crypto::cn_context &context, Block& bl, const difficulty_type& diffic);
2014-03-03 22:07:58 +00:00
void pause();
void resume();
void do_print_hashrate(bool do_hr);
private:
bool worker_thread();
bool request_block_template();
void merge_hr();
2014-06-25 17:21:42 +00:00
2014-03-03 22:07:58 +00:00
struct miner_config
{
uint64_t current_extra_message_index;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(current_extra_message_index)
END_KV_SERIALIZE_MAP()
};
2014-08-13 10:51:37 +00:00
const Currency& m_currency;
2014-03-03 22:07:58 +00:00
volatile uint32_t m_stop;
epee::critical_section m_template_lock;
2014-08-13 10:51:37 +00:00
Block m_template;
2014-03-03 22:07:58 +00:00
std::atomic<uint32_t> m_template_no;
std::atomic<uint32_t> m_starter_nonce;
difficulty_type m_diffic;
2014-06-25 17:21:42 +00:00
volatile uint32_t m_thread_index;
2014-03-03 22:07:58 +00:00
volatile uint32_t m_threads_total;
std::atomic<int32_t> m_pausers_count;
epee::critical_section m_miners_count_lock;
2014-03-03 22:07:58 +00:00
std::list<boost::thread> m_threads;
epee::critical_section m_threads_lock;
2014-03-03 22:07:58 +00:00
i_miner_handler* m_phandler;
2014-08-13 10:51:37 +00:00
AccountPublicAddress m_mine_address;
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
2014-03-03 22:07:58 +00:00
std::vector<blobdata> m_extra_messages;
miner_config m_config;
2014-06-25 17:21:42 +00:00
std::string m_config_folder_path;
2014-03-03 22:07:58 +00:00
std::atomic<uint64_t> m_last_hr_merge_time;
std::atomic<uint64_t> m_hashes;
std::atomic<uint64_t> m_current_hash_rate;
epee::critical_section m_last_hash_rates_lock;
2014-03-03 22:07:58 +00:00
std::list<uint64_t> m_last_hash_rates;
bool m_do_print_hashrate;
bool m_do_mining;
};
}