Skip to content

Commit

Permalink
Resolve endless circle of dependecies
Browse files Browse the repository at this point in the history
  • Loading branch information
VanGrx committed Jul 23, 2020
1 parent 3f29d71 commit 8184371
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/cryptonote_basic/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ namespace cryptonote
}


miner::miner(i_miner_handler* phandler, Blockchain* pbc):m_stop(1),
miner::miner(i_miner_handler* phandler, const get_block_hash_t &gbh):m_stop(1),
m_template(boost::value_initialized<block>()),
m_template_no(0),
m_diffic(0),
m_thread_index(0),
m_phandler(phandler),
m_pbc(pbc),
m_gbh(gbh),
m_height(0),
m_pausers_count(0),
m_threads_total(0),
Expand Down Expand Up @@ -382,12 +382,12 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------------
bool miner::find_nonce_for_given_block(const Blockchain *pbc, 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)
{
for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
{
crypto::hash h;
get_block_longhash(pbc, bl, h, height, tools::get_max_concurrency());
gbh(bl, height, tools::get_max_concurrency(), h);

if(check_hash(h, diffic))
{
Expand Down Expand Up @@ -485,7 +485,7 @@ namespace cryptonote

b.nonce = nonce;
crypto::hash h;
get_block_longhash(m_pbc, b, h, height, tools::get_max_concurrency());
m_gbh(b, height, tools::get_max_concurrency(), h);

if(check_hash(h, local_diff))
{
Expand Down
8 changes: 4 additions & 4 deletions src/cryptonote_basic/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ namespace cryptonote
~i_miner_handler(){};
};

class Blockchain;
typedef std::function<bool(const cryptonote::block&, uint64_t, unsigned int, crypto::hash&)> get_block_hash_t;

/************************************************************************/
/* */
/************************************************************************/
class miner
{
public:
miner(i_miner_handler* phandler, Blockchain* pbc);
miner(i_miner_handler* phandler, const get_block_hash_t& gbh);
~miner();
bool init(const boost::program_options::variables_map& vm, network_type nettype);
static void init_options(boost::program_options::options_description& desc);
Expand All @@ -81,7 +81,7 @@ namespace cryptonote
bool on_idle();
void on_synchronized();
//synchronous analog (for fast calls)
static bool find_nonce_for_given_block(const Blockchain *pbc, 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);
void pause();
void resume();
void do_print_hashrate(bool do_hr);
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace cryptonote
std::list<boost::thread> m_threads;
epee::critical_section m_threads_lock;
i_miner_handler* m_phandler;
Blockchain* m_pbc;
get_block_hash_t m_gbh;
account_public_address 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;
Expand Down
4 changes: 3 additions & 1 deletion src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ namespace cryptonote
core::core(i_cryptonote_protocol* pprotocol):
m_mempool(m_blockchain_storage),
m_blockchain_storage(m_mempool),
m_miner(this, &m_blockchain_storage),
m_miner(this, [this](const cryptonote::block &b, uint64_t height, unsigned int threads, crypto::hash &hash) {
return cryptonote::get_block_longhash(&m_blockchain_storage, b, hash, height, threads);
}),
m_miner_address(boost::value_initialized<account_public_address>()),
m_starter_message_showed(false),
m_target_blockchain_height(0),
Expand Down
4 changes: 3 additions & 1 deletion src/cryptonote_core/cryptonote_tx_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,9 @@ namespace cryptonote
bl.invalidate_hashes();
bl.timestamp = 0;
bl.nonce = nonce;
miner::find_nonce_for_given_block(NULL, bl, 1, 0);
miner::find_nonce_for_given_block([](const cryptonote::block &b, uint64_t height, unsigned int threads, crypto::hash &hash){
return cryptonote::get_block_longhash(NULL, b, hash, height, threads);
}, bl, 1, 0);
return true;
}
//---------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions src/safex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ safex_add_library(safex_core

target_link_libraries(safex_core
PUBLIC
blockchain_db
cryptonote_core
cncrypto
common
cryptonote_protocol
PRIVATE
${EXTRA_LIBRARIES})
8 changes: 6 additions & 2 deletions tests/core_tests/chaingen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co

// Nonce search...
blk.nonce = 0;
while (!miner::find_nonce_for_given_block(NULL, blk, get_test_difficulty(), height))
while (!miner::find_nonce_for_given_block([](const cryptonote::block &b, uint64_t height, unsigned int threads, crypto::hash &hash){
return cryptonote::get_block_longhash(NULL, b, hash, height, threads);
}, blk, get_test_difficulty(), height))
blk.timestamp++;

const uint8_t hf_version = 1; //hardcode hf version for tests
Expand Down Expand Up @@ -1622,7 +1624,9 @@ void fill_update_price_peg_sources_and_destinations(const std::vector<test_event
void fill_nonce(cryptonote::block& blk, const difficulty_type& diffic, uint64_t height)
{
blk.nonce = 0;
while (!miner::find_nonce_for_given_block(NULL, blk, diffic, height))
while (!miner::find_nonce_for_given_block([](const cryptonote::block &b, uint64_t height, unsigned int threads, crypto::hash &hash){
return cryptonote::get_block_longhash(NULL, b, hash, height, threads);
}, blk, diffic, height))
blk.timestamp++;
}

Expand Down

0 comments on commit 8184371

Please sign in to comment.