diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-11-08 17:30:18 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2020-08-27 15:13:00 +0000 |
commit | 9d42649d58a1a898b8fd1be17f42fb6b7ad1f6ee (patch) | |
tree | d3e5a6a12cbd0bd4d3906afd4d9b350667aceda3 /src/cryptonote_basic | |
parent | Merge pull request #6771 (diff) | |
download | monero-9d42649d58a1a898b8fd1be17f42fb6b7ad1f6ee.tar.xz |
core: fix mining from a block that's not the current top
Diffstat (limited to 'src/cryptonote_basic')
-rw-r--r-- | src/cryptonote_basic/miner.cpp | 10 | ||||
-rw-r--r-- | src/cryptonote_basic/miner.h | 6 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index 34a559b83..29f6dce5a 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -169,7 +169,9 @@ namespace cryptonote extra_nonce = m_extra_messages[m_config.current_extra_message_index]; } - if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce)) + uint64_t seed_height; + crypto::hash seed_hash; + if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce, seed_height, seed_hash)) { LOG_ERROR("Failed to get_block_template(), stopping mining"); return false; @@ -471,12 +473,12 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------------- - bool miner::find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height) + bool miner::find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height, const crypto::hash *seed_hash) { for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++) { crypto::hash h; - gbh(bl, height, diffic <= 100 ? 0 : tools::get_max_concurrency(), h); + gbh(bl, height, seed_hash, diffic <= 100 ? 0 : tools::get_max_concurrency(), h); if(check_hash(h, diffic)) { @@ -572,7 +574,7 @@ namespace cryptonote b.nonce = nonce; crypto::hash h; - m_gbh(b, height, tools::get_max_concurrency(), h); + m_gbh(b, height, NULL, tools::get_max_concurrency(), h); if(check_hash(h, local_diff)) { diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h index b23253d4a..df3f56f68 100644 --- a/src/cryptonote_basic/miner.h +++ b/src/cryptonote_basic/miner.h @@ -47,12 +47,12 @@ namespace cryptonote struct i_miner_handler { virtual bool handle_block_found(block& b, block_verification_context &bvc) = 0; - 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; + 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, uint64_t &seed_height, crypto::hash &seed_hash) = 0; protected: ~i_miner_handler(){}; }; - typedef std::function<bool(const cryptonote::block&, uint64_t, unsigned int, crypto::hash&)> get_block_hash_t; + typedef std::function<bool(const cryptonote::block&, uint64_t, const crypto::hash*, unsigned int, crypto::hash&)> get_block_hash_t; /************************************************************************/ /* */ @@ -76,7 +76,7 @@ namespace cryptonote bool on_idle(); void on_synchronized(); //synchronous analog (for fast calls) - static bool find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height); + static bool find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height, const crypto::hash *seed_hash = NULL); void pause(); void resume(); void do_print_hashrate(bool do_hr); |