diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-04-15 12:29:47 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-04-15 22:27:15 +0000 |
commit | d009f6dd6182ee448b12ece226909df21bac45a8 (patch) | |
tree | 9f57d702fad1ab9549cce4f44bd083feade29f78 /src | |
parent | blockchain: lock the blockchain while pruning (diff) | |
download | monero-d009f6dd6182ee448b12ece226909df21bac45a8.tar.xz |
rpc: fix get_block_hashes.bin from wallet on pruned blockchain
We want to get all blocks here, even pruned ones
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 14 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 3 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 9 | ||||
-rw-r--r-- | src/rpc/daemon_handler.cpp | 2 |
4 files changed, 14 insertions, 14 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index daa1fe517..3675d5d0f 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2284,7 +2284,7 @@ bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container // Find the split point between us and foreign blockchain and return // (by reference) the most recent common block hash along with up to // BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT additional (more recent) hashes. -bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::vector<crypto::hash>& hashes, uint64_t& start_height, uint64_t& current_height) const +bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::vector<crypto::hash>& hashes, uint64_t& start_height, uint64_t& current_height, bool clip_pruned) const { LOG_PRINT_L3("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -2297,9 +2297,13 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc m_db->block_txn_start(true); current_height = get_current_blockchain_height(); - const uint32_t pruning_seed = get_blockchain_pruning_seed(); - start_height = tools::get_next_unpruned_block_height(start_height, current_height, pruning_seed); - uint64_t stop_height = tools::get_next_pruned_block_height(start_height, current_height, pruning_seed); + uint64_t stop_height = current_height; + if (clip_pruned) + { + const uint32_t pruning_seed = get_blockchain_pruning_seed(); + start_height = tools::get_next_unpruned_block_height(start_height, current_height, pruning_seed); + stop_height = tools::get_next_pruned_block_height(start_height, current_height, pruning_seed); + } size_t count = 0; hashes.reserve(std::min((size_t)(stop_height - start_height), (size_t)BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT)); for(size_t i = start_height; i < stop_height && count < BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT; i++, count++) @@ -2316,7 +2320,7 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc LOG_PRINT_L3("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); - bool result = find_blockchain_supplement(qblock_ids, resp.m_block_ids, resp.start_height, resp.total_height); + bool result = find_blockchain_supplement(qblock_ids, resp.m_block_ids, resp.start_height, resp.total_height, true); if (result) { cryptonote::difficulty_type wide_cumulative_difficulty = m_db->get_block_cumulative_difficulty(resp.total_height - 1); diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 3588bbd1b..244e2a89a 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -394,10 +394,11 @@ namespace cryptonote * @param hashes the hashes to be returned, return-by-reference * @param start_height the start height, return-by-reference * @param current_height the current blockchain height, return-by-reference + * @param clip_pruned whether to constrain results to unpruned data * * @return true if a block found in common, else false */ - bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::vector<crypto::hash>& hashes, uint64_t& start_height, uint64_t& current_height) const; + bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::vector<crypto::hash>& hashes, uint64_t& start_height, uint64_t& current_height, bool clip_pruned) const; /** * @brief get recent block hashes for a foreign chain diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 39a8b4745..91e9021e0 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -432,17 +432,12 @@ namespace cryptonote if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HASHES_FAST>(invoke_http_mode::BIN, "/gethashes.bin", req, res, r)) return r; - NOTIFY_RESPONSE_CHAIN_ENTRY::request resp; - - resp.start_height = req.start_height; - if(!m_core.find_blockchain_supplement(req.block_ids, resp)) + res.start_height = req.start_height; + if(!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, res.m_block_ids, res.start_height, res.current_height, false)) { res.status = "Failed"; return false; } - res.current_height = resp.total_height; - res.start_height = resp.start_height; - res.m_block_ids = std::move(resp.m_block_ids); res.status = CORE_RPC_STATUS_OK; return true; diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index 540afe6b9..7c8953930 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -141,7 +141,7 @@ namespace rpc auto& chain = m_core.get_blockchain_storage(); - if (!chain.find_blockchain_supplement(req.known_hashes, res.hashes, res.start_height, res.current_height)) + if (!chain.find_blockchain_supplement(req.known_hashes, res.hashes, res.start_height, res.current_height, false)) { res.status = Message::STATUS_FAILED; res.error_details = "Blockchain::find_blockchain_supplement() returned false"; |