Electroneum
Loading...
Searching...
No Matches
miner.cpp
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, The Monero Project
3//
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without modification, are
7// permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this list of
10// conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13// of conditions and the following disclaimer in the documentation and/or other
14// materials provided with the distribution.
15//
16// 3. Neither the name of the copyright holder nor the names of its contributors may be
17// used to endorse or promote products derived from this software without specific
18// prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29//
30// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32#include <sstream>
33#include <numeric>
34#include <boost/utility/value_init.hpp>
35#include <boost/interprocess/detail/atomic.hpp>
36#include <boost/algorithm/string.hpp>
37#include <boost/filesystem.hpp>
38#include "misc_language.h"
39#include "syncobj.h"
42#include "file_io_utils.h"
43#include "common/command_line.h"
44#include "string_coding.h"
45#include "string_tools.h"
47#include "boost/logic/tribool.hpp"
48
49#ifdef __APPLE__
50 #include <sys/times.h>
51 #include <IOKit/IOKitLib.h>
52 #include <IOKit/ps/IOPSKeys.h>
53 #include <IOKit/ps/IOPowerSources.h>
54 #include <mach/mach_host.h>
55 #include <AvailabilityMacros.h>
56 #include <TargetConditionals.h>
57#elif defined(__linux__)
58 #include <unistd.h>
59 #include <sys/resource.h>
60 #include <sys/times.h>
61 #include <time.h>
62#elif defined(__FreeBSD__)
63 #include <devstat.h>
64 #include <errno.h>
65 #include <fcntl.h>
66 #include <machine/apm_bios.h>
67 #include <stdio.h>
68 #include <sys/resource.h>
69 #include <sys/sysctl.h>
70 #include <sys/times.h>
71 #include <sys/types.h>
72 #include <unistd.h>
73#endif
74
75#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
76#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "miner"
77
78#define AUTODETECT_WINDOW 10 // seconds
79#define AUTODETECT_GAIN_THRESHOLD 1.02f // 2%
80
81using namespace epee;
82
83#include "miner.h"
84
85
86extern "C" void slow_hash_allocate_state();
87extern "C" void slow_hash_free_state();
88namespace cryptonote
89{
90
91 namespace
92 {
93 const command_line::arg_descriptor<std::string> arg_extra_messages = {"extra-messages-file", "Specify file for extra messages to include into coinbase transactions", "", true};
94 const command_line::arg_descriptor<std::string> arg_start_mining = {"start-mining", "Specify wallet address to mining for", "", true};
95 const command_line::arg_descriptor<uint32_t> arg_mining_threads = {"mining-threads", "Specify mining threads count", 0, true};
96 const command_line::arg_descriptor<bool> arg_bg_mining_enable = {"bg-mining-enable", "enable/disable background mining", true, true};
97 const command_line::arg_descriptor<bool> arg_bg_mining_ignore_battery = {"bg-mining-ignore-battery", "if true, assumes plugged in when unable to query system power status", false, true};
98 const command_line::arg_descriptor<uint64_t> arg_bg_mining_min_idle_interval_seconds = {"bg-mining-min-idle-interval", "Specify min lookback interval in seconds for determining idle state", miner::BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS, true};
99 const command_line::arg_descriptor<uint16_t> arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true};
100 const command_line::arg_descriptor<uint16_t> arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true};
101 }
102
103
104 miner::miner(i_miner_handler* phandler):m_stop(1),
105 m_template(boost::value_initialized<block>()),
106 m_template_no(0),
107 m_diffic(0),
108 m_thread_index(0),
109 m_phandler(phandler),
110 m_height(0),
111 m_threads_active(0),
112 m_pausers_count(0),
113 m_threads_total(0),
114 m_starter_nonce(0),
115 m_last_hr_merge_time(0),
116 m_hashes(0),
117 m_total_hashes(0),
118 m_do_print_hashrate(false),
119 m_do_mining(false),
120 m_current_hash_rate(0),
121 m_is_background_mining_enabled(false),
126 m_block_reward(0)
127 {
128 m_attrs.set_stack_size(THREAD_STACK_SIZE);
129 }
130 //-----------------------------------------------------------------------------------------------------
132 {
133 try { stop(); }
134 catch (...) { /* ignore */ }
135 }
136 //-----------------------------------------------------------------------------------------------------
137 bool miner::set_block_template(const block& bl, const difficulty_type& di, uint64_t height, uint64_t block_reward)
138 {
139 CRITICAL_REGION_LOCAL(m_template_lock);
140 m_template = bl;
141 m_diffic = di;
142 m_height = height;
143 m_block_reward = block_reward;
144 ++m_template_no;
145 m_starter_nonce = crypto::rand<uint32_t>();
146 return true;
147 }
148 //-----------------------------------------------------------------------------------------------------
150 {
151 if(!is_mining())
152 return true;
153
154 return request_block_template();
155 }
156 //-----------------------------------------------------------------------------------------------------
157 bool miner::request_block_template()
158 {
159 block bl;
162 uint64_t expected_reward; //only used for RPC calls - could possibly be useful here too?
163
164 cryptonote::blobdata extra_nonce;
165 if(m_extra_messages.size() && m_config.current_extra_message_index < m_extra_messages.size())
166 {
167 extra_nonce = m_extra_messages[m_config.current_extra_message_index];
168 }
169
170 if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce))
171 {
172 LOG_ERROR("Failed to get_block_template(), stopping mining");
173 return false;
174 }
175 set_block_template(bl, di, height, expected_reward);
176 return true;
177 }
178 //-----------------------------------------------------------------------------------------------------
180 {
181 m_update_block_template_interval.do_call([&](){
182 if(is_mining())request_block_template();
183 return true;
184 });
185
186 m_update_merge_hr_interval.do_call([&](){
187 merge_hr();
188 return true;
189 });
190
191 m_autodetect_interval.do_call([&](){
192 update_autodetection();
193 return true;
194 });
195
196 return true;
197 }
198 //-----------------------------------------------------------------------------------------------------
200 {
201 m_do_print_hashrate = do_hr;
202 }
203 //-----------------------------------------------------------------------------------------------------
204 void miner::merge_hr()
205 {
206 if(m_last_hr_merge_time && is_mining())
207 {
208 m_current_hash_rate = m_hashes * 1000 / ((misc_utils::get_tick_count() - m_last_hr_merge_time + 1));
209 CRITICAL_REGION_LOCAL(m_last_hash_rates_lock);
210 m_last_hash_rates.push_back(m_current_hash_rate);
211 if(m_last_hash_rates.size() > 19)
212 m_last_hash_rates.pop_front();
213 if(m_do_print_hashrate)
214 {
215 uint64_t total_hr = std::accumulate(m_last_hash_rates.begin(), m_last_hash_rates.end(), 0);
216 float hr = static_cast<float>(total_hr)/static_cast<float>(m_last_hash_rates.size());
217 const auto flags = std::cout.flags();
218 const auto precision = std::cout.precision();
219 std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << std::setiosflags(flags) << std::setprecision(precision) << ENDL;
220 }
221 }
222 m_last_hr_merge_time = misc_utils::get_tick_count();
223 m_hashes = 0;
224 }
225 //-----------------------------------------------------------------------------------------------------
226 void miner::update_autodetection()
227 {
228 if (m_threads_autodetect.empty())
229 return;
230
232 uint64_t dt = now - m_threads_autodetect.back().first;
233 if (dt < AUTODETECT_WINDOW * 1000000000ull)
234 return;
235
236 // work out how many more hashes we got
237 m_threads_autodetect.back().first = dt;
238 uint64_t dh = m_total_hashes - m_threads_autodetect.back().second;
239 m_threads_autodetect.back().second = dh;
240 float hs = dh / (dt / (float)1000000000);
241 MGINFO("Mining autodetection: " << m_threads_autodetect.size() << " threads: " << hs << " H/s");
242
243 // when we don't increase by at least 2%, stop, otherwise check next
244 // if N and N+1 have mostly the same hash rate, we want to "lighter" one
245 bool found = false;
246 if (m_threads_autodetect.size() > 1)
247 {
248 int previdx = m_threads_autodetect.size() - 2;
249 float previous_hs = m_threads_autodetect[previdx].second / (m_threads_autodetect[previdx].first / (float)1000000000);
250 if (previous_hs > 0 && hs / previous_hs < AUTODETECT_GAIN_THRESHOLD)
251 {
252 m_threads_total = m_threads_autodetect.size() - 1;
253 m_threads_autodetect.clear();
254 MGINFO("Optimal number of threads seems to be " << m_threads_total);
255 found = true;
256 }
257 }
258
259 if (!found)
260 {
261 // setup one more thread
262 m_threads_autodetect.push_back({now, m_total_hashes});
263 m_threads_total = m_threads_autodetect.size();
264 }
265
266 // restart all threads
267 {
268 CRITICAL_REGION_LOCAL(m_threads_lock);
269 boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
270 while (m_threads_active > 0)
272 m_threads.clear();
273 }
274 boost::interprocess::ipcdetail::atomic_write32(&m_stop, 0);
275 boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0);
276 for(size_t i = 0; i != m_threads_total; i++)
277 m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
278 }
279 //-----------------------------------------------------------------------------------------------------
280 void miner::init_options(boost::program_options::options_description& desc)
281 {
282 command_line::add_arg(desc, arg_extra_messages);
283 command_line::add_arg(desc, arg_start_mining);
284 command_line::add_arg(desc, arg_mining_threads);
285 command_line::add_arg(desc, arg_bg_mining_enable);
286 command_line::add_arg(desc, arg_bg_mining_ignore_battery);
287 command_line::add_arg(desc, arg_bg_mining_min_idle_interval_seconds);
288 command_line::add_arg(desc, arg_bg_mining_idle_threshold_percentage);
289 command_line::add_arg(desc, arg_bg_mining_miner_target_percentage);
290 }
291 //-----------------------------------------------------------------------------------------------------
292 bool miner::init(const boost::program_options::variables_map& vm, network_type nettype, bool fallback_to_pow)
293 {
294 if(command_line::has_arg(vm, arg_extra_messages))
295 {
296 std::string buff;
297 bool r = file_io_utils::load_file_to_string(command_line::get_arg(vm, arg_extra_messages), buff);
298 CHECK_AND_ASSERT_MES(r, false, "Failed to load file with extra messages: " << command_line::get_arg(vm, arg_extra_messages));
299 std::vector<std::string> extra_vec;
300 boost::split(extra_vec, buff, boost::is_any_of("\n"), boost::token_compress_on );
301 m_extra_messages.resize(extra_vec.size());
302 for(size_t i = 0; i != extra_vec.size(); i++)
303 {
304 string_tools::trim(extra_vec[i]);
305 if(!extra_vec[i].size())
306 continue;
307 std::string buff = string_encoding::base64_decode(extra_vec[i]);
308 if(buff != "0")
309 m_extra_messages[i] = buff;
310 }
311 m_config_folder_path = boost::filesystem::path(command_line::get_arg(vm, arg_extra_messages)).parent_path().string();
312 m_config = AUTO_VAL_INIT(m_config);
313 const std::string filename = m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME;
314 CHECK_AND_ASSERT_MES(epee::serialization::load_t_from_json_file(m_config, filename), false, "Failed to load data from " << filename);
315 MINFO("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index);
316 }
317
318 if(command_line::has_arg(vm, arg_start_mining))
319 {
321 if(!cryptonote::get_account_address_from_str(info, nettype, command_line::get_arg(vm, arg_start_mining)) || info.is_subaddress)
322 {
323 LOG_ERROR("Target account address " << command_line::get_arg(vm, arg_start_mining) << " has wrong format, starting daemon canceled");
324 return false;
325 }
326 // just a safeguard for the legacy infrastructure
327 if(!(command_line::get_arg(vm, arg_start_mining) == "etnkCys4uGhSi9h48ajL9vBDJTcn2s2ttXtXq3SXWPAbiMHNhHitu5fJ8QgRfFWTzmJ8QgRfFWTzmJ8QgRfFWTzm4t51HTfCtK"))
328 {
329 LOG_ERROR("Target account address " << command_line::get_arg(vm, arg_start_mining) << " isn't equal to the Aurelius legacy mining burn address etnkCys4uGhSi9h48ajL9vBDJTcn2s2ttXtXq3SXWPAbiMHNhHitu5fJ8QgRfFWTzmJ8QgRfFWTzmJ8QgRfFWTzm4t51HTfCtK");
330 return false;
331 }
332 m_mine_address = info.address;
333 m_threads_total = 1;
334 m_do_mining = true;
335 if(command_line::has_arg(vm, arg_mining_threads))
336 {
337 m_threads_total = command_line::get_arg(vm, arg_mining_threads);
338 }
339 }
340
341 // Background mining parameters
342 // Let init set all parameters even if background mining is not enabled, they can start later with params set
343 if(command_line::has_arg(vm, arg_bg_mining_enable))
344 set_is_background_mining_enabled( command_line::get_arg(vm, arg_bg_mining_enable) );
345 if(command_line::has_arg(vm, arg_bg_mining_ignore_battery))
346 set_ignore_battery( command_line::get_arg(vm, arg_bg_mining_ignore_battery) );
347 if(command_line::has_arg(vm, arg_bg_mining_min_idle_interval_seconds))
348 set_min_idle_seconds( command_line::get_arg(vm, arg_bg_mining_min_idle_interval_seconds) );
349 if(command_line::has_arg(vm, arg_bg_mining_idle_threshold_percentage))
350 set_idle_threshold( command_line::get_arg(vm, arg_bg_mining_idle_threshold_percentage) );
351 if(command_line::has_arg(vm, arg_bg_mining_miner_target_percentage))
352 set_mining_target( command_line::get_arg(vm, arg_bg_mining_miner_target_percentage) );
353
354 m_fallback_to_pow = fallback_to_pow;
355
356 return true;
357 }
358 //-----------------------------------------------------------------------------------------------------
359 bool miner::is_mining() const
360 {
361 return !m_stop;
362 }
363 //-----------------------------------------------------------------------------------------------------
365 {
366 return m_mine_address;
367 }
368 //-----------------------------------------------------------------------------------------------------
370 return m_threads_total;
371 }
372 //-----------------------------------------------------------------------------------------------------
373 bool miner::start(const account_public_address& adr, size_t threads_count, bool do_background, bool ignore_battery)
374 {
375 m_block_reward = 0;
376 m_mine_address = adr;
377 m_threads_total = static_cast<uint32_t>(threads_count);
378 if (threads_count == 0)
379 {
380 m_threads_autodetect.clear();
381 m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
382 m_threads_total = 1;
383 }
384 m_starter_nonce = crypto::rand<uint32_t>();
385 CRITICAL_REGION_LOCAL(m_threads_lock);
386 if(is_mining())
387 {
388 LOG_ERROR("Starting miner but it's already started");
389 return false;
390 }
391
392 if(!m_threads.empty())
393 {
394 LOG_ERROR("Unable to start miner because there are active mining threads");
395 return false;
396 }
397
398 request_block_template();//lets update block template
399
400 boost::interprocess::ipcdetail::atomic_write32(&m_stop, 0);
401 boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0);
402 set_is_background_mining_enabled(do_background);
403 set_ignore_battery(ignore_battery);
404
405 for(size_t i = 0; i != m_threads_total; i++)
406 {
407 m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
408 }
409
410 if (threads_count == 0)
411 MINFO("Mining has started, autodetecting optimal number of threads, good luck!" );
412 else
413 MINFO("Mining has started with " << threads_count << " threads, good luck!" );
414
416 {
417 m_background_mining_thread = boost::thread(m_attrs, boost::bind(&miner::background_worker_thread, this));
418 LOG_PRINT_L0("Background mining controller thread started" );
419 }
420
422 {
423 MINFO("Ignoring battery");
424 }
425
426 return true;
427 }
428 //-----------------------------------------------------------------------------------------------------
430 {
431 if(is_mining()) {
432 return m_current_hash_rate;
433 }
434 else {
435 return 0;
436 }
437 }
438 //-----------------------------------------------------------------------------------------------------
440 {
441 boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
442 }
443 //-----------------------------------------------------------------------------------------------------
445 {
446 MTRACE("Miner has received stop signal");
447
448 CRITICAL_REGION_LOCAL(m_threads_lock);
449 bool mining = !m_threads.empty();
450 if (!mining)
451 {
452 MTRACE("Not mining - nothing to stop" );
453 return true;
454 }
455
457
458 // In case background mining was active and the miner threads are waiting
459 // on the background miner to signal start.
460 while (m_threads_active > 0)
461 {
462 m_is_background_mining_started_cond.notify_all();
464 }
465
466 // The background mining thread could be sleeping for a long time, so we
467 // interrupt it just in case
468 m_background_mining_thread.interrupt();
469 m_background_mining_thread.join();
470 m_is_background_mining_enabled = false;
471
472 MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
473 m_threads.clear();
474 m_threads_autodetect.clear();
475 return true;
476 }
477 //-----------------------------------------------------------------------------------------------------
479 {
480 for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
481 {
482 crypto::hash h;
484
485 if(check_hash(h, diffic))
486 {
488 return true;
489 }
490 }
492 return false;
493 }
494 //-----------------------------------------------------------------------------------------------------
496 {
497 if(m_do_mining)
498 {
499 start(m_mine_address, m_threads_total, get_is_background_mining_enabled(), get_ignore_battery());
500 }
501 }
502 //-----------------------------------------------------------------------------------------------------
504 {
505 CRITICAL_REGION_LOCAL(m_miners_count_lock);
506 MDEBUG("miner::pause: " << m_pausers_count << " -> " << (m_pausers_count + 1));
507 ++m_pausers_count;
508 if(m_pausers_count == 1 && is_mining())
509 MDEBUG("MINING PAUSED");
510 }
511 //-----------------------------------------------------------------------------------------------------
513 {
514 CRITICAL_REGION_LOCAL(m_miners_count_lock);
515 MDEBUG("miner::resume: " << m_pausers_count << " -> " << (m_pausers_count - 1));
516 --m_pausers_count;
517 if(m_pausers_count < 0)
518 {
519 m_pausers_count = 0;
520 }
521 if(!m_pausers_count && is_mining())
522 MDEBUG("MINING RESUMED");
523 }
524 //-----------------------------------------------------------------------------------------------------
525 bool miner::worker_thread()
526 {
527 uint32_t th_local_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
528 MLOG_SET_THREAD_NAME(std::string("[miner ") + std::to_string(th_local_index) + "]");
529 MGINFO("Miner thread was started ["<< th_local_index << "]");
530 uint32_t nonce = m_starter_nonce + th_local_index;
531 uint64_t height = 0;
532 difficulty_type local_diff = 0;
533 uint32_t local_template_ver = 0;
534 block b;
536 ++m_threads_active;
537 while(!m_stop)
538 {
539 if(m_pausers_count)//anti split workaround
540 {
542 continue;
543 }
544 else if( m_is_background_mining_enabled )
545 {
546 misc_utils::sleep_no_w(m_miner_extra_sleep);
547 while( !m_is_background_mining_started )
548 {
549 MGINFO("background mining is enabled, but not started, waiting until start triggers");
550 boost::unique_lock<boost::mutex> started_lock( m_is_background_mining_started_mutex );
551 m_is_background_mining_started_cond.wait( started_lock );
552 if( m_stop ) break;
553 }
554
555 if( m_stop ) continue;
556 }
557
558 if(local_template_ver != m_template_no)
559 {
560 CRITICAL_REGION_BEGIN(m_template_lock);
561 b = m_template;
562
563 if(!m_fallback_to_pow && b.major_version >= 8 && b.signature.empty()) {
564 continue;
565 }
566
567 local_diff = m_diffic;
568 height = m_height;
570 local_template_ver = m_template_no;
571 nonce = m_starter_nonce + th_local_index;
572 }
573
574 if(!local_template_ver)//no any set_block_template call
575 {
576 LOG_PRINT_L2("Block template not set yet");
578 continue;
579 }
580
581 b.nonce = nonce;
582 crypto::hash h;
584
585 if(check_hash(h, local_diff))
586 {
587 //we lucky!
588 ++m_config.current_extra_message_index;
589 MGINFO_GREEN("Found block " << get_block_hash(b) << " at height " << height << " for difficulty: " << local_diff);
590 cryptonote::block_verification_context bvc;
591 if(!m_phandler->handle_block_found(b, bvc) || !bvc.m_added_to_main_chain)
592 {
593 --m_config.current_extra_message_index;
594 }else
595 {
596 //success update, lets update config
597 if (!m_config_folder_path.empty())
598 epee::serialization::store_t_to_json_file(m_config, m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME);
599 }
600 }
601 nonce+=m_threads_total;
602 ++m_hashes;
603 ++m_total_hashes;
604 }
606 MGINFO("Miner thread stopped ["<< th_local_index << "]");
607 --m_threads_active;
608 return true;
609 }
610 //-----------------------------------------------------------------------------------------------------
612 {
613 return m_is_background_mining_enabled;
614 }
615 //-----------------------------------------------------------------------------------------------------
617 {
618 return m_ignore_battery;
619 }
620 //-----------------------------------------------------------------------------------------------------
625 bool miner::set_is_background_mining_enabled(bool is_background_mining_enabled)
626 {
627 m_is_background_mining_enabled = is_background_mining_enabled;
628 // Extra logic will be required if we make this function public in the future
629 // and allow toggling smart mining without start/stop
630 //m_is_background_mining_enabled_cond.notify_one();
631 return true;
632 }
633 //-----------------------------------------------------------------------------------------------------
634 void miner::set_ignore_battery(bool ignore_battery)
635 {
636 m_ignore_battery = ignore_battery;
637 }
638 //-----------------------------------------------------------------------------------------------------
640 {
641 return m_min_idle_seconds;
642 }
643 //-----------------------------------------------------------------------------------------------------
645 {
646 if(min_idle_seconds > BACKGROUND_MINING_MAX_MIN_IDLE_INTERVAL_IN_SECONDS) return false;
647 if(min_idle_seconds < BACKGROUND_MINING_MIN_MIN_IDLE_INTERVAL_IN_SECONDS) return false;
648 m_min_idle_seconds = min_idle_seconds;
649 return true;
650 }
651 //-----------------------------------------------------------------------------------------------------
653 {
654 return m_idle_threshold;
655 }
656 //-----------------------------------------------------------------------------------------------------
658 {
659 if(idle_threshold > BACKGROUND_MINING_MAX_IDLE_THRESHOLD_PERCENTAGE) return false;
660 if(idle_threshold < BACKGROUND_MINING_MIN_IDLE_THRESHOLD_PERCENTAGE) return false;
661 m_idle_threshold = idle_threshold;
662 return true;
663 }
664 //-----------------------------------------------------------------------------------------------------
666 {
667 return m_mining_target;
668 }
669 //-----------------------------------------------------------------------------------------------------
671 {
672 if(mining_target > BACKGROUND_MINING_MAX_MINING_TARGET_PERCENTAGE) return false;
673 if(mining_target < BACKGROUND_MINING_MIN_MINING_TARGET_PERCENTAGE) return false;
674 m_mining_target = mining_target;
675 return true;
676 }
677 //-----------------------------------------------------------------------------------------------------
678 bool miner::background_worker_thread()
679 {
680 uint64_t prev_total_time, current_total_time;
681 uint64_t prev_idle_time, current_idle_time;
682 uint64_t previous_process_time = 0, current_process_time = 0;
683 m_is_background_mining_started = false;
684
685 if(!get_system_times(prev_total_time, prev_idle_time))
686 {
687 LOG_ERROR("get_system_times call failed, background mining will NOT work!");
688 return false;
689 }
690
691 while(!m_stop)
692 {
693
694 try
695 {
696 // Commenting out the below since we're going with privatizing the bg mining enabled
697 // function, but I'll leave the code/comments here for anyone that wants to modify the
698 // patch in the future
699 // -------------------------------------------------------------------------------------
700 // All of this might be overkill if we just enforced some simple requirements
701 // about changing this variable before/after the miner starts, but I envision
702 // in the future a checkbox that you can tick on/off for background mining after
703 // you've clicked "start mining". There's still an issue here where if background
704 // mining is disabled when start is called, this thread is never created, and so
705 // enabling after does nothing, something I have to fix in the future. However,
706 // this should take care of the case where mining is started with bg-enabled,
707 // and then the user decides to un-check background mining, and just do
708 // regular full-speed mining. I might just be over-doing it and thinking up
709 // non-existant use-cases, so if the consensus is to simplify, we can remove all this fluff.
710 /*
711 while( !m_is_background_mining_enabled )
712 {
713 MGINFO("background mining is disabled, waiting until enabled!");
714 boost::unique_lock<boost::mutex> enabled_lock( m_is_background_mining_enabled_mutex );
715 m_is_background_mining_enabled_cond.wait( enabled_lock );
716 }
717 */
718
719 // If we're already mining, then sleep for the miner monitor interval.
720 // If we're NOT mining, then sleep for the idle monitor interval
722 if( !m_is_background_mining_started ) sleep_for_seconds = get_min_idle_seconds();
723 boost::this_thread::sleep_for(boost::chrono::seconds(sleep_for_seconds));
724 }
725 catch(const boost::thread_interrupted&)
726 {
727 MDEBUG("background miner thread interrupted ");
728 continue; // if interrupted because stop called, loop should end ..
729 }
730
731 bool on_ac_power = m_ignore_battery;
732 if(!m_ignore_battery)
733 {
734 boost::tribool battery_powered(on_battery_power());
735 if(!indeterminate( battery_powered ))
736 {
737 on_ac_power = !(bool)battery_powered;
738 }
739 }
740
741 if( m_is_background_mining_started )
742 {
743 // figure out if we need to stop, and monitor mining usage
744
745 // If we get here, then previous values are initialized.
746 // Let's get some current data for comparison.
747
748 if(!get_system_times(current_total_time, current_idle_time))
749 {
750 MERROR("get_system_times call failed");
751 continue;
752 }
753
754 if(!get_process_time(current_process_time))
755 {
756 MERROR("get_process_time call failed!");
757 continue;
758 }
759
760 uint64_t total_diff = (current_total_time - prev_total_time);
761 uint64_t idle_diff = (current_idle_time - prev_idle_time);
762 uint64_t process_diff = (current_process_time - previous_process_time);
763 uint8_t idle_percentage = get_percent_of_total(idle_diff, total_diff);
764 uint8_t process_percentage = get_percent_of_total(process_diff, total_diff);
765
766 MDEBUG("idle percentage is " << unsigned(idle_percentage) << "\%, miner percentage is " << unsigned(process_percentage) << "\%, ac power : " << on_ac_power);
767 if( idle_percentage + process_percentage < get_idle_threshold() || !on_ac_power )
768 {
769 MINFO("cpu is " << unsigned(idle_percentage) << "% idle, idle threshold is " << unsigned(get_idle_threshold()) << "\%, ac power : " << on_ac_power << ", background mining stopping, thanks for your contribution!");
770 m_is_background_mining_started = false;
771
772 // reset process times
773 previous_process_time = 0;
774 current_process_time = 0;
775 }
776 else
777 {
778 previous_process_time = current_process_time;
779
780 // adjust the miner extra sleep variable
781 int64_t miner_extra_sleep_change = (-1 * (get_mining_target() - process_percentage) );
782 int64_t new_miner_extra_sleep = m_miner_extra_sleep + miner_extra_sleep_change;
783 // if you start the miner with few threads on a multicore system, this could
784 // fall below zero because all the time functions aggregate across all processors.
785 // I'm just hard limiting to 5 millis min sleep here, other options?
786 m_miner_extra_sleep = std::max( new_miner_extra_sleep , (int64_t)5 );
787 MDEBUG("m_miner_extra_sleep " << m_miner_extra_sleep);
788 }
789
790 prev_total_time = current_total_time;
791 prev_idle_time = current_idle_time;
792 }
793 else if( on_ac_power )
794 {
795 // figure out if we need to start
796
797 if(!get_system_times(current_total_time, current_idle_time))
798 {
799 MERROR("get_system_times call failed");
800 continue;
801 }
802
803 uint64_t total_diff = (current_total_time - prev_total_time);
804 uint64_t idle_diff = (current_idle_time - prev_idle_time);
805 uint8_t idle_percentage = get_percent_of_total(idle_diff, total_diff);
806
807 MDEBUG("idle percentage is " << unsigned(idle_percentage));
808 if( idle_percentage >= get_idle_threshold() && on_ac_power )
809 {
810 MINFO("cpu is " << unsigned(idle_percentage) << "% idle, idle threshold is " << unsigned(get_idle_threshold()) << "\%, ac power : " << on_ac_power << ", background mining started, good luck!");
811 m_is_background_mining_started = true;
812 m_is_background_mining_started_cond.notify_all();
813
814 // Wait for a little mining to happen ..
815 boost::this_thread::sleep_for(boost::chrono::seconds( 1 ));
816
817 // Starting data ...
818 if(!get_process_time(previous_process_time))
819 {
820 m_is_background_mining_started = false;
821 MERROR("get_process_time call failed!");
822 }
823 }
824
825 prev_total_time = current_total_time;
826 prev_idle_time = current_idle_time;
827 }
828 }
829
830 return true;
831 }
832 //-----------------------------------------------------------------------------------------------------
833 bool miner::get_system_times(uint64_t& total_time, uint64_t& idle_time)
834 {
835 #ifdef _WIN32
836
837 FILETIME idleTime;
838 FILETIME kernelTime;
839 FILETIME userTime;
840 if ( GetSystemTimes( &idleTime, &kernelTime, &userTime ) != -1 )
841 {
842 total_time =
843 ( (((uint64_t)(kernelTime.dwHighDateTime)) << 32) | ((uint64_t)kernelTime.dwLowDateTime) )
844 + ( (((uint64_t)(userTime.dwHighDateTime)) << 32) | ((uint64_t)userTime.dwLowDateTime) );
845
846 idle_time = ( (((uint64_t)(idleTime.dwHighDateTime)) << 32) | ((uint64_t)idleTime.dwLowDateTime) );
847
848 return true;
849 }
850
851 #elif defined(__linux__)
852
853 const std::string STAT_FILE_PATH = "/proc/stat";
854
855 if( !epee::file_io_utils::is_file_exist(STAT_FILE_PATH) )
856 {
857 LOG_ERROR("'" << STAT_FILE_PATH << "' file does not exist");
858 return false;
859 }
860
861 std::ifstream stat_file_stream(STAT_FILE_PATH);
862 if( stat_file_stream.fail() )
863 {
864 LOG_ERROR("failed to open '" << STAT_FILE_PATH << "'");
865 return false;
866 }
867
868 std::string line;
869 std::getline(stat_file_stream, line);
870 std::istringstream stat_file_iss(line);
871 stat_file_iss.ignore(65536, ' '); // skip cpu label ...
872 uint64_t utime, ntime, stime, itime;
873 if( !(stat_file_iss >> utime && stat_file_iss >> ntime && stat_file_iss >> stime && stat_file_iss >> itime) )
874 {
875 LOG_ERROR("failed to read '" << STAT_FILE_PATH << "'");
876 return false;
877 }
878
879 idle_time = itime;
880 total_time = utime + ntime + stime + itime;
881
882 return true;
883
884 #elif defined(__APPLE__)
885
886 mach_msg_type_number_t count;
887 kern_return_t status;
888 host_cpu_load_info_data_t stats;
889 count = HOST_CPU_LOAD_INFO_COUNT;
890 status = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&stats, &count);
891 if(status != KERN_SUCCESS)
892 {
893 return false;
894 }
895
896 idle_time = stats.cpu_ticks[CPU_STATE_IDLE];
897 total_time = idle_time + stats.cpu_ticks[CPU_STATE_USER] + stats.cpu_ticks[CPU_STATE_SYSTEM];
898
899 return true;
900
901 #elif defined(__FreeBSD__)
902
903 struct statinfo s;
904 size_t n = sizeof(s.cp_time);
905 if( sysctlbyname("kern.cp_time", s.cp_time, &n, NULL, 0) == -1 )
906 {
907 LOG_ERROR("sysctlbyname(\"kern.cp_time\"): " << strerror(errno));
908 return false;
909 }
910 if( n != sizeof(s.cp_time) )
911 {
912 LOG_ERROR("sysctlbyname(\"kern.cp_time\") output is unexpectedly "
913 << n << " bytes instead of the expected " << sizeof(s.cp_time)
914 << " bytes.");
915 return false;
916 }
917
918 idle_time = s.cp_time[CP_IDLE];
919 total_time =
920 s.cp_time[CP_USER] +
921 s.cp_time[CP_NICE] +
922 s.cp_time[CP_SYS] +
923 s.cp_time[CP_INTR] +
924 s.cp_time[CP_IDLE];
925
926 return true;
927
928 #endif
929
930 return false; // unsupported system
931 }
932 //-----------------------------------------------------------------------------------------------------
933 bool miner::get_process_time(uint64_t& total_time)
934 {
935 #ifdef _WIN32
936
937 FILETIME createTime;
938 FILETIME exitTime;
939 FILETIME kernelTime;
940 FILETIME userTime;
941 if ( GetProcessTimes( GetCurrentProcess(), &createTime, &exitTime, &kernelTime, &userTime ) != -1 )
942 {
943 total_time =
944 ( (((uint64_t)(kernelTime.dwHighDateTime)) << 32) | ((uint64_t)kernelTime.dwLowDateTime) )
945 + ( (((uint64_t)(userTime.dwHighDateTime)) << 32) | ((uint64_t)userTime.dwLowDateTime) );
946
947 return true;
948 }
949
950 #elif (defined(__linux__) && defined(_SC_CLK_TCK)) || defined(__APPLE__) || defined(__FreeBSD__)
951
952 struct tms tms;
953 if ( times(&tms) != (clock_t)-1 )
954 {
955 total_time = tms.tms_utime + tms.tms_stime;
956 return true;
957 }
958
959 #endif
960
961 return false; // unsupported system
962 }
963 //-----------------------------------------------------------------------------------------------------
964 uint8_t miner::get_percent_of_total(uint64_t other, uint64_t total)
965 {
966 return (uint8_t)( ceil( (other * 1.f / total * 1.f) * 100) );
967 }
968 //-----------------------------------------------------------------------------------------------------
969 boost::logic::tribool miner::on_battery_power()
970 {
971 #ifdef _WIN32
972
973 SYSTEM_POWER_STATUS power_status;
974 if ( GetSystemPowerStatus( &power_status ) != 0 )
975 {
976 return boost::logic::tribool(power_status.ACLineStatus != 1);
977 }
978
979 #elif defined(__APPLE__)
980
981 #if TARGET_OS_MAC && (!defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7)
982 return boost::logic::tribool(IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited);
983 #else
984 // iOS or OSX <10.7
985 return boost::logic::tribool(boost::logic::indeterminate);
986 #endif
987
988 #elif defined(__linux__)
989
990 // Use the power_supply class http://lxr.linux.no/#linux+v4.10.1/Documentation/power/power_supply_class.txt
991 std::string power_supply_class_path = "/sys/class/power_supply";
992
993 boost::tribool on_battery = boost::logic::tribool(boost::logic::indeterminate);
994 if (boost::filesystem::is_directory(power_supply_class_path))
995 {
996 const boost::filesystem::directory_iterator end_itr;
997 for (boost::filesystem::directory_iterator iter(power_supply_class_path); iter != end_itr; ++iter)
998 {
999 const boost::filesystem::path& power_supply_path = iter->path();
1000 if (boost::filesystem::is_directory(power_supply_path))
1001 {
1002 boost::filesystem::path power_supply_type_path = power_supply_path / "type";
1003 if (boost::filesystem::is_regular_file(power_supply_type_path))
1004 {
1005 std::ifstream power_supply_type_stream(power_supply_type_path.string());
1006 if (power_supply_type_stream.fail())
1007 {
1008 LOG_PRINT_L0("Unable to read from " << power_supply_type_path << " to check power supply type");
1009 continue;
1010 }
1011
1012 std::string power_supply_type;
1013 std::getline(power_supply_type_stream, power_supply_type);
1014
1015 // If there is an AC adapter that's present and online we can break early
1016 if (boost::starts_with(power_supply_type, "Mains"))
1017 {
1018 boost::filesystem::path power_supply_online_path = power_supply_path / "online";
1019 if (boost::filesystem::is_regular_file(power_supply_online_path))
1020 {
1021 std::ifstream power_supply_online_stream(power_supply_online_path.string());
1022 if (power_supply_online_stream.fail())
1023 {
1024 LOG_PRINT_L0("Unable to read from " << power_supply_online_path << " to check ac power supply status");
1025 continue;
1026 }
1027
1028 if (power_supply_online_stream.get() == '1')
1029 {
1030 return boost::logic::tribool(false);
1031 }
1032 }
1033 }
1034 else if (boost::starts_with(power_supply_type, "Battery") && boost::logic::indeterminate(on_battery))
1035 {
1036 boost::filesystem::path power_supply_status_path = power_supply_path / "status";
1037 if (boost::filesystem::is_regular_file(power_supply_status_path))
1038 {
1039 std::ifstream power_supply_status_stream(power_supply_status_path.string());
1040 if (power_supply_status_stream.fail())
1041 {
1042 LOG_PRINT_L0("Unable to read from " << power_supply_status_path << " to check battery power supply status");
1043 continue;
1044 }
1045
1046 // Possible status are Charging, Full, Discharging, Not Charging, and Unknown
1047 // We are only need to handle negative states right now
1048 std::string power_supply_status;
1049 std::getline(power_supply_status_stream, power_supply_status);
1050 if (boost::starts_with(power_supply_status, "Charging") || boost::starts_with(power_supply_status, "Full"))
1051 {
1052 on_battery = boost::logic::tribool(false);
1053 }
1054
1055 if (boost::starts_with(power_supply_status, "Discharging"))
1056 {
1057 on_battery = boost::logic::tribool(true);
1058 }
1059 }
1060 }
1061 }
1062 }
1063 }
1064 }
1065
1066 if (boost::logic::indeterminate(on_battery))
1067 {
1068 static bool error_shown = false;
1069 if (!error_shown)
1070 {
1071 LOG_ERROR("couldn't query power status from " << power_supply_class_path);
1072 error_shown = true;
1073 }
1074 }
1075 return on_battery;
1076
1077 #elif defined(__FreeBSD__)
1078 int ac;
1079 size_t n = sizeof(ac);
1080 if( sysctlbyname("hw.acpi.acline", &ac, &n, NULL, 0) == -1 )
1081 {
1082 if( errno != ENOENT )
1083 {
1084 LOG_ERROR("Cannot query battery status: "
1085 << "sysctlbyname(\"hw.acpi.acline\"): " << strerror(errno));
1086 return boost::logic::tribool(boost::logic::indeterminate);
1087 }
1088
1089 // If sysctl fails with ENOENT, then try querying /dev/apm.
1090
1091 static const char* dev_apm = "/dev/apm";
1092 const int fd = open(dev_apm, O_RDONLY);
1093 if( fd == -1 ) {
1094 LOG_ERROR("Cannot query battery status: "
1095 << "open(): " << dev_apm << ": " << strerror(errno));
1096 return boost::logic::tribool(boost::logic::indeterminate);
1097 }
1098
1099 apm_info info;
1100 if( ioctl(fd, APMIO_GETINFO, &info) == -1 ) {
1101 close(fd);
1102 LOG_ERROR("Cannot query battery status: "
1103 << "ioctl(" << dev_apm << ", APMIO_GETINFO): " << strerror(errno));
1104 return boost::logic::tribool(boost::logic::indeterminate);
1105 }
1106
1107 close(fd);
1108
1109 // See apm(8).
1110 switch( info.ai_acline )
1111 {
1112 case 0: // off-line
1113 case 2: // backup power
1114 return boost::logic::tribool(true);
1115 case 1: // on-line
1116 return boost::logic::tribool(false);
1117 }
1118 switch( info.ai_batt_stat )
1119 {
1120 case 0: // high
1121 case 1: // low
1122 case 2: // critical
1123 return boost::logic::tribool(true);
1124 case 3: // charging
1125 return boost::logic::tribool(false);
1126 }
1127
1128 LOG_ERROR("Cannot query battery status: "
1129 << "sysctl hw.acpi.acline is not available and /dev/apm returns "
1130 << "unexpected ac-line status (" << info.ai_acline << ") and "
1131 << "battery status (" << info.ai_batt_stat << ").");
1132 return boost::logic::tribool(boost::logic::indeterminate);
1133 }
1134 if( n != sizeof(ac) )
1135 {
1136 LOG_ERROR("sysctlbyname(\"hw.acpi.acline\") output is unexpectedly "
1137 << n << " bytes instead of the expected " << sizeof(ac) << " bytes.");
1138 return boost::logic::tribool(boost::logic::indeterminate);
1139 }
1140 return boost::logic::tribool(ac == 0);
1141 #endif
1142
1143 LOG_ERROR("couldn't query power status");
1144 return boost::logic::tribool(boost::logic::indeterminate);
1145 }
1146}
uint64_t height
const account_public_address & get_mining_address() const
Definition miner.cpp:364
static constexpr uint8_t BACKGROUND_MINING_MAX_IDLE_THRESHOLD_PERCENTAGE
Definition miner.h:94
static constexpr uint8_t BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE
Definition miner.h:92
static constexpr uint16_t BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS
Definition miner.h:95
void on_synchronized()
Definition miner.cpp:495
static constexpr uint8_t BACKGROUND_MINING_MIN_IDLE_THRESHOLD_PERCENTAGE
Definition miner.h:93
bool is_mining() const
Definition miner.cpp:359
static constexpr uint8_t BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE
Definition miner.h:98
uint64_t get_min_idle_seconds() const
Definition miner.cpp:639
static constexpr uint16_t BACKGROUND_MINING_MIN_MIN_IDLE_INTERVAL_IN_SECONDS
Definition miner.h:96
static constexpr uint8_t BACKGROUND_MINING_MINER_MONITOR_INVERVAL_IN_SECONDS
Definition miner.h:101
uint64_t get_speed() const
Definition miner.cpp:429
static void init_options(boost::program_options::options_description &desc)
Definition miner.cpp:280
bool set_block_template(const block &bl, const difficulty_type &diffic, uint64_t height, uint64_t block_reward)
Definition miner.cpp:137
uint32_t get_threads_count() const
Definition miner.cpp:369
static constexpr uint8_t BACKGROUND_MINING_MAX_MINING_TARGET_PERCENTAGE
Definition miner.h:100
void send_stop_signal()
Definition miner.cpp:439
miner(i_miner_handler *phandler)
Definition miner.cpp:104
bool get_ignore_battery() const
Definition miner.cpp:616
bool set_min_idle_seconds(uint64_t min_idle_seconds)
Definition miner.cpp:644
bool on_block_chain_update()
Definition miner.cpp:149
bool get_is_background_mining_enabled() const
Definition miner.cpp:611
bool init(const boost::program_options::variables_map &vm, network_type nettype, bool fallback_to_pow=false)
Definition miner.cpp:292
static bool find_nonce_for_given_block(block &bl, const difficulty_type &diffic, uint64_t height)
Definition miner.cpp:478
static constexpr uint16_t BACKGROUND_MINING_MAX_MIN_IDLE_INTERVAL_IN_SECONDS
Definition miner.h:97
uint8_t get_idle_threshold() const
Definition miner.cpp:652
bool start(const account_public_address &adr, size_t threads_count, bool do_background=false, bool ignore_battery=false)
Definition miner.cpp:373
void do_print_hashrate(bool do_hr)
Definition miner.cpp:199
static constexpr uint64_t BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS
Definition miner.h:102
uint8_t get_mining_target() const
Definition miner.cpp:665
bool set_idle_threshold(uint8_t idle_threshold)
Definition miner.cpp:657
bool set_mining_target(uint8_t mining_target)
Definition miner.cpp:670
static constexpr uint8_t BACKGROUND_MINING_MIN_MINING_TARGET_PERCENTAGE
Definition miner.h:99
#define THREAD_STACK_SIZE
#define MINER_CONFIG_FILE_NAME
#define AUTODETECT_GAIN_THRESHOLD
Definition miner.cpp:79
#define AUTODETECT_WINDOW
Definition miner.cpp:78
void slow_hash_allocate_state()
void slow_hash_free_state()
#define AUTO_VAL_INIT(v)
#define MERROR(x)
Definition misc_log_ex.h:73
#define MGINFO_GREEN(x)
Definition misc_log_ex.h:82
#define MDEBUG(x)
Definition misc_log_ex.h:76
#define ENDL
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
#define MGINFO(x)
Definition misc_log_ex.h:80
#define MTRACE(x)
Definition misc_log_ex.h:77
#define MINFO(x)
Definition misc_log_ex.h:75
#define LOG_PRINT_L2(x)
#define MLOG_SET_THREAD_NAME(x)
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
std::enable_if<!std::is_same< T, bool >::value, bool >::type has_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
std::enable_if< std::is_pod< T >::value, T >::type rand()
Definition crypto.h:216
POD_CLASS hash
Definition hash.h:50
int bool
Definition hash.h:37
Holds cryptonote related classes and helpers.
Definition ban.cpp:40
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:43
bool get_block_hash(const block &b, crypto::hash &res)
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
bool get_block_longhash(const block &b, crypto::hash &res, uint64_t height)
std::string blobdata
bool load_file_to_string(const std::string &path_to_file, std::string &target_str, size_t max_size=1000000000)
bool is_file_exist(const std::string &path)
uint64_t get_tick_count()
bool sleep_no_w(long ms)
bool store_t_to_json_file(t_struct &str_in, const std::string &fpath)
bool load_t_from_json_file(t_struct &out, const std::string &json_file)
std::string base64_decode(std::string const &encoded_string)
std::string & trim(std::string &str)
mdb_size_t count(MDB_cursor *cur)
#define false
CXA_THROW_INFO_T * info
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
std::vector< uint8_t > signature
virtual bool get_block_template(block &b, const account_public_address &adr, difficulty_type &diffic, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce)=0
#define CRITICAL_REGION_LOCAL(x)
Definition syncobj.h:228
#define CRITICAL_REGION_END()
Definition syncobj.h:233
#define CRITICAL_REGION_BEGIN(x)
Definition syncobj.h:229