Fix delayed exit when syncing

This commit is contained in:
moneromooo-monero 2016-12-04 12:27:45 +00:00
parent c36cb54340
commit 3f7d6fb57d
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
6 changed files with 49 additions and 4 deletions

View File

@ -118,7 +118,7 @@ static const uint64_t testnet_hard_fork_version_1_till = 624633;
//------------------------------------------------------------------ //------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) : Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false),
m_is_blockchain_storing(false), m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0) m_is_blockchain_storing(false), m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_cancel(false)
{ {
LOG_PRINT_L3("Blockchain::" << __func__); LOG_PRINT_L3("Blockchain::" << __func__);
} }
@ -3436,6 +3436,8 @@ void Blockchain::block_longhash_worker(const uint64_t height, const std::vector<
// the height of the block passed to it // the height of the block passed to it
for (const auto & block : blocks) for (const auto & block : blocks)
{ {
if (m_cancel)
return;
crypto::hash id = get_block_hash(block); crypto::hash id = get_block_hash(block);
crypto::hash pow = get_block_longhash(block, height); crypto::hash pow = get_block_longhash(block, height);
map.emplace(id, pow); map.emplace(id, pow);
@ -3611,6 +3613,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
thread_list.clear(); thread_list.clear();
if (m_cancel)
return false;
for (const auto & map : maps) for (const auto & map : maps)
{ {
m_blocks_longhash_table.insert(map.begin(), map.end()); m_blocks_longhash_table.insert(map.begin(), map.end());
@ -3618,6 +3623,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
} }
} }
if (m_cancel)
return false;
if (blocks_exist) if (blocks_exist)
{ {
LOG_PRINT_L0("Skipping prepare blocks. Blocks exist."); LOG_PRINT_L0("Skipping prepare blocks. Blocks exist.");
@ -3655,6 +3663,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
// generate sorted tables for all amounts and absolute offsets // generate sorted tables for all amounts and absolute offsets
for (const auto &entry : blocks_entry) for (const auto &entry : blocks_entry)
{ {
if (m_cancel)
return false;
for (const auto &tx_blob : entry.txs) for (const auto &tx_blob : entry.txs)
{ {
crypto::hash tx_hash = null_hash; crypto::hash tx_hash = null_hash;
@ -3763,6 +3774,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
// now generate a table for each tx_prefix and k_image hashes // now generate a table for each tx_prefix and k_image hashes
for (const auto &entry : blocks_entry) for (const auto &entry : blocks_entry)
{ {
if (m_cancel)
return false;
for (const auto &tx_blob : entry.txs) for (const auto &tx_blob : entry.txs)
{ {
crypto::hash tx_hash = null_hash; crypto::hash tx_hash = null_hash;
@ -3844,6 +3858,11 @@ std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> Blockchain:: get_ou
return m_db->get_output_histogram(amounts, unlocked, recent_cutoff); return m_db->get_output_histogram(amounts, unlocked, recent_cutoff);
} }
void Blockchain::cancel()
{
m_cancel = true;
}
#if defined(PER_BLOCK_CHECKPOINT) #if defined(PER_BLOCK_CHECKPOINT)
void Blockchain::load_compiled_in_block_hashes() void Blockchain::load_compiled_in_block_hashes()
{ {

View File

@ -843,6 +843,9 @@ namespace cryptonote
*/ */
void block_longhash_worker(const uint64_t height, const std::vector<block> &blocks, void block_longhash_worker(const uint64_t height, const std::vector<block> &blocks,
std::unordered_map<crypto::hash, crypto::hash> &map) const; std::unordered_map<crypto::hash, crypto::hash> &map) const;
void cancel();
private: private:
// TODO: evaluate whether or not each of these typedefs are left over from blockchain_storage // TODO: evaluate whether or not each of these typedefs are left over from blockchain_storage
@ -912,6 +915,8 @@ namespace cryptonote
bool m_testnet; bool m_testnet;
std::atomic<bool> m_cancel;
/** /**
* @brief collects the keys for all outputs being "spent" as an input * @brief collects the keys for all outputs being "spent" as an input
* *

View File

@ -123,7 +123,7 @@ namespace cryptonote
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
void core::stop() void core::stop()
{ {
graceful_exit(); m_blockchain_storage.cancel();
} }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
void core::init_options(boost::program_options::options_description& desc) void core::init_options(boost::program_options::options_description& desc)

View File

@ -109,6 +109,7 @@ namespace cryptonote
bool is_synchronized(){return m_synchronized;} bool is_synchronized(){return m_synchronized;}
void log_connections(); void log_connections();
std::list<connection_info> get_connections(); std::list<connection_info> get_connections();
void stop();
private: private:
//----------------- commands handlers ---------------------------------------------- //----------------- commands handlers ----------------------------------------------
int handle_notify_new_block(int command, NOTIFY_NEW_BLOCK::request& arg, cryptonote_connection_context& context); int handle_notify_new_block(int command, NOTIFY_NEW_BLOCK::request& arg, cryptonote_connection_context& context);
@ -135,6 +136,7 @@ namespace cryptonote
std::atomic<uint32_t> m_syncronized_connections_count; std::atomic<uint32_t> m_syncronized_connections_count;
std::atomic<bool> m_synchronized; std::atomic<bool> m_synchronized;
bool m_one_request = true; bool m_one_request = true;
std::atomic<bool> m_stopping;
// static std::ofstream m_logreq; // static std::ofstream m_logreq;
boost::mutex m_buffer_mutex; boost::mutex m_buffer_mutex;

View File

@ -60,7 +60,8 @@ namespace cryptonote
t_cryptonote_protocol_handler<t_core>::t_cryptonote_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint<connection_context>* p_net_layout):m_core(rcore), t_cryptonote_protocol_handler<t_core>::t_cryptonote_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint<connection_context>* p_net_layout):m_core(rcore),
m_p2p(p_net_layout), m_p2p(p_net_layout),
m_syncronized_connections_count(0), m_syncronized_connections_count(0),
m_synchronized(false) m_synchronized(false),
m_stopping(false)
{ {
if(!m_p2p) if(!m_p2p)
@ -793,6 +794,11 @@ namespace cryptonote
size_t count = 0; size_t count = 0;
BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks) BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
{ {
if (m_stopping)
{
return 1;
}
++count; ++count;
block b; block b;
if(!parse_and_validate_block_from_blob(block_entry.block, b)) if(!parse_and_validate_block_from_blob(block_entry.block, b))
@ -857,6 +863,12 @@ namespace cryptonote
m_core.prepare_handle_incoming_blocks(arg.blocks); m_core.prepare_handle_incoming_blocks(arg.blocks);
BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks) BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks)
{ {
if (m_stopping)
{
m_core.cleanup_handle_incoming_blocks();
return 1;
}
// process transactions // process transactions
TIME_MEASURE_START(transactions_process_time); TIME_MEASURE_START(transactions_process_time);
BOOST_FOREACH(auto& tx_blob, block_entry.txs) BOOST_FOREACH(auto& tx_blob, block_entry.txs)
@ -1131,5 +1143,11 @@ namespace cryptonote
(*logreq) << "log used" << std::endl; (*logreq) << "log used" << std::endl;
return *logreq; return *logreq;
} }
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
void t_cryptonote_protocol_handler<t_core>::stop()
{
m_stopping = true;
m_core.stop();
}
} // namespace } // namespace

View File

@ -654,6 +654,7 @@ namespace nodetool
template<class t_payload_net_handler> template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::send_stop_signal() bool node_server<t_payload_net_handler>::send_stop_signal()
{ {
m_payload_handler.stop();
m_net_server.send_stop_signal(); m_net_server.send_stop_signal();
LOG_PRINT_L0("[node] Stop signal sent"); LOG_PRINT_L0("[node] Stop signal sent");
return true; return true;