From 3b9a06d5aa8c70839419c019f34d51b58b9c3a60 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 1 Jun 2019 16:23:22 +0100 Subject: [PATCH] Proposed tweak for issue with finding seedblock hash This patch isn't needed if we always restrict block-sync-size to <= SEEDHASH_EPOCH_LAG. But otherwise, this will allow syncing with larger block-sync-sizes. --- src/cryptonote_core/blockchain.cpp | 15 ++++++++++++++- src/cryptonote_core/blockchain.h | 17 +++++++++++++++++ src/cryptonote_core/cryptonote_tx_utils.cpp | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index c202aab94..b2e872be5 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -139,7 +139,9 @@ Blockchain::Blockchain(tx_memory_pool& tx_pool) : m_long_term_block_weights_cache_rolling_median(CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE), m_difficulty_for_next_block_top_hash(crypto::null_hash), m_difficulty_for_next_block(1), - m_btc_valid(false) + m_btc_valid(false), + m_batch_success(true), + m_prepare_height(0) { LOG_PRINT_L3("Blockchain::" << __func__); } @@ -798,6 +800,13 @@ crypto::hash Blockchain::get_block_id_by_height(uint64_t height) const return null_hash; } //------------------------------------------------------------------ +crypto::hash Blockchain::get_pending_block_id_by_height(uint64_t height) const +{ + if (m_prepare_height && height >= m_prepare_height && height - m_prepare_height < m_prepare_nblocks) + return (*m_prepare_blocks)[height - m_prepare_height].hash; + return get_block_id_by_height(height); +} +//------------------------------------------------------------------ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk, bool *orphan) const { LOG_PRINT_L3("Blockchain::" << __func__); @@ -4534,6 +4543,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector m_block_notify; std::shared_ptr m_reorg_notify; + // for prepare_handle_incoming_blocks + uint64_t m_prepare_height; + uint64_t m_prepare_nblocks; + std::vector *m_prepare_blocks; + /** * @brief collects the keys for all outputs being "spent" as an input * diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index e956be9d2..8c4903a06 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -681,7 +681,7 @@ namespace cryptonote if (rx_needhash(height, &seed_height)) { crypto::hash hash; if (pbc != NULL) - hash = pbc->get_block_id_by_height(seed_height); + hash = pbc->get_pending_block_id_by_height(seed_height); else memset(&hash, 0, sizeof(hash)); // only happens when generating genesis block rx_seedhash(seed_height, hash.data, miners);