diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-12-04 22:27:41 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-12-04 22:27:41 +0200 |
commit | 80863796807ecd524f4a76964b2d58167f819e26 (patch) | |
tree | 4430f9061380e9ae62eeb313e8ccb19aa8e70c4c /src/cryptonote_core | |
parent | Merge pull request #1396 (diff) | |
parent | Fix delayed exit when syncing (diff) | |
download | monero-80863796807ecd524f4a76964b2d58167f819e26.tar.xz |
Merge pull request #1397
3f7d6fb5 Fix delayed exit when syncing (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 21 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 5 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 2 |
3 files changed, 26 insertions, 2 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 64694fe81..174e1a038 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -121,7 +121,7 @@ static const uint64_t testnet_hard_fork_version_1_till = 624633; //------------------------------------------------------------------ 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_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__); } @@ -3455,6 +3455,8 @@ void Blockchain::block_longhash_worker(const uint64_t height, const std::vector< // the height of the block passed to it for (const auto & block : blocks) { + if (m_cancel) + return; crypto::hash id = get_block_hash(block); crypto::hash pow = get_block_longhash(block, height); map.emplace(id, pow); @@ -3630,6 +3632,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e thread_list.clear(); + if (m_cancel) + return false; + for (const auto & map : maps) { m_blocks_longhash_table.insert(map.begin(), map.end()); @@ -3637,6 +3642,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e } } + if (m_cancel) + return false; + if (blocks_exist) { LOG_PRINT_L0("Skipping prepare blocks. Blocks exist."); @@ -3674,6 +3682,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e // generate sorted tables for all amounts and absolute offsets for (const auto &entry : blocks_entry) { + if (m_cancel) + return false; + for (const auto &tx_blob : entry.txs) { crypto::hash tx_hash = null_hash; @@ -3782,6 +3793,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 for (const auto &entry : blocks_entry) { + if (m_cancel) + return false; + for (const auto &tx_blob : entry.txs) { crypto::hash tx_hash = null_hash; @@ -3863,6 +3877,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); } +void Blockchain::cancel() +{ + m_cancel = true; +} + #if defined(PER_BLOCK_CHECKPOINT) void Blockchain::load_compiled_in_block_hashes() { diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index f9ae9d8aa..9afc22657 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -843,6 +843,9 @@ namespace cryptonote */ void block_longhash_worker(const uint64_t height, const std::vector<block> &blocks, std::unordered_map<crypto::hash, crypto::hash> &map) const; + + void cancel(); + private: // TODO: evaluate whether or not each of these typedefs are left over from blockchain_storage @@ -912,6 +915,8 @@ namespace cryptonote bool m_testnet; + std::atomic<bool> m_cancel; + /** * @brief collects the keys for all outputs being "spent" as an input * diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 84a41cfbf..4da4533f8 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -123,7 +123,7 @@ namespace cryptonote //----------------------------------------------------------------------------------- void core::stop() { - graceful_exit(); + m_blockchain_storage.cancel(); } //----------------------------------------------------------------------------------- void core::init_options(boost::program_options::options_description& desc) |