aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------external/randomx0
-rw-r--r--src/cryptonote_basic/miner.cpp10
-rw-r--r--src/cryptonote_basic/miner.h8
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp4
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp4
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.h1
-rw-r--r--src/rpc/core_rpc_server.cpp12
-rw-r--r--tests/core_tests/chaingen.cpp8
-rw-r--r--tests/unit_tests/node_server.cpp23
9 files changed, 46 insertions, 24 deletions
diff --git a/external/randomx b/external/randomx
-Subproject 53af68c34a43f5bdb659f90cc27b6b2da7fd77f
+Subproject 7567cef4c6192fb5356bbdd7db802be77be0439
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index c4b5c8455..688aeaea3 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -102,13 +102,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{},
m_template_no(0),
m_diffic(0),
m_thread_index(0),
m_phandler(phandler),
- m_pbc(pbc),
+ m_gbh(gbh),
m_height(0),
m_threads_active(0),
m_pausers_count(0),
@@ -471,12 +471,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))
{
@@ -572,7 +572,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))
{
diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h
index 4efbcbec3..ce50d674e 100644
--- a/src/cryptonote_basic/miner.h
+++ b/src/cryptonote_basic/miner.h
@@ -52,7 +52,7 @@ namespace cryptonote
~i_miner_handler(){};
};
- class Blockchain;
+ typedef std::function<bool(const cryptonote::block&, uint64_t, unsigned int, crypto::hash&)> get_block_hash_t;
/************************************************************************/
/* */
@@ -60,7 +60,7 @@ namespace cryptonote
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);
@@ -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 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);
@@ -135,7 +135,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;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index acb494a49..02620996e 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -223,7 +223,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_starter_message_showed(false),
m_target_blockchain_height(0),
m_checkpoints_path(""),
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 3e1b4e97f..f50fc61a5 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -663,7 +663,9 @@ namespace cryptonote
bl.minor_version = CURRENT_BLOCK_MINOR_VERSION;
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);
bl.invalidate_hashes();
return true;
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h
index b16b42564..3b456e324 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h
@@ -112,6 +112,7 @@ namespace cryptonote
void stop();
void on_connection_close(cryptonote_connection_context &context);
void set_max_out_peers(unsigned int max) { m_max_out_peers = max; }
+ bool no_sync() const { return m_no_sync; }
void set_no_sync(bool value) { m_no_sync = value; }
std::string get_peers_overview() const;
std::pair<uint32_t, uint32_t> get_next_needed_pruning_stripe() const;
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index df264dde6..9117b5b3a 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1833,7 +1833,9 @@ namespace cryptonote
return false;
}
b.nonce = req.starting_nonce;
- miner::find_nonce_for_given_block(&(m_core.get_blockchain_storage()), b, template_res.difficulty, template_res.height);
+ miner::find_nonce_for_given_block([this](const cryptonote::block &b, uint64_t height, unsigned int threads, crypto::hash &hash) {
+ return cryptonote::get_block_longhash(&(m_core.get_blockchain_storage()), b, hash, height, threads);
+ }, b, template_res.difficulty, template_res.height);
submit_req.front() = string_tools::buff_to_hex_nodelimer(block_to_blob(b));
r = on_submitblock(submit_req, submit_res, error_resp, ctx);
@@ -1903,7 +1905,8 @@ namespace cryptonote
}
auto current_time = std::chrono::system_clock::now();
- if (current_time - m_bootstrap_height_check_time > std::chrono::seconds(30)) // update every 30s
+ if (!m_p2p.get_payload_object().no_sync() &&
+ current_time - m_bootstrap_height_check_time > std::chrono::seconds(30)) // update every 30s
{
{
boost::upgrade_to_unique_lock<boost::shared_mutex> lock(upgrade_lock);
@@ -1927,9 +1930,10 @@ namespace cryptonote
uint64_t top_height = m_core.get_current_blockchain_height();
m_should_use_bootstrap_daemon = top_height + 10 < *bootstrap_daemon_height;
MINFO((m_should_use_bootstrap_daemon ? "Using" : "Not using") << " the bootstrap daemon (our height: " << top_height << ", bootstrap daemon's height: " << *bootstrap_daemon_height << ")");
+
+ if (!m_should_use_bootstrap_daemon)
+ return false;
}
- if (!m_should_use_bootstrap_daemon)
- return false;
if (mode == invoke_http_mode::JON)
{
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 3f2984288..35e449e10 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -186,7 +186,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(hf_ver), 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(hf_ver), height))
blk.timestamp++;
add_block(blk, txs_weight, block_weights, already_generated_coins, hf_ver ? hf_ver.get() : 1);
@@ -797,7 +799,9 @@ void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& 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++;
}
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index 2c89323c7..5f91fc6d4 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -262,16 +262,25 @@ TEST(ban, ignores_port)
TEST(node_server, bind_same_p2p_port)
{
- const auto new_node = []() -> std::unique_ptr<Server> {
+ struct test_data_t
+ {
test_core pr_core;
- cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
- std::unique_ptr<Server> server(new Server(cprotocol));
- cprotocol.set_p2p_endpoint(server.get());
+ cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol;
+ std::unique_ptr<Server> server;
+
+ test_data_t(): cprotocol(pr_core, NULL)
+ {
+ server.reset(new Server(cprotocol));
+ cprotocol.set_p2p_endpoint(server.get());
+ }
+ };
- return server;
+ const auto new_node = []() -> std::unique_ptr<test_data_t> {
+ test_data_t *d = new test_data_t;
+ return std::unique_ptr<test_data_t>(d);
};
- const auto init = [](const std::unique_ptr<Server>& server, const char* port) -> bool {
+ const auto init = [](const std::unique_ptr<test_data_t>& server, const char* port) -> bool {
boost::program_options::options_description desc_options("Command line options");
cryptonote::core::init_options(desc_options);
Server::init_options(desc_options);
@@ -284,7 +293,7 @@ TEST(node_server, bind_same_p2p_port)
boost::program_options::notify(vm);
- return server->init(vm);
+ return server->server->init(vm);
};
constexpr char port[] = "48080";