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.
pull/203/head
Howard Chu 5 years ago committed by wowario
parent a1258baf5a
commit 3b9a06d5aa
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111

@ -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<block_complete
m_blocks_longhash_table.clear();
uint64_t thread_height = height;
tools::threadpool::waiter waiter;
m_prepare_height = height;
m_prepare_nblocks = blocks_entry.size();
m_prepare_blocks = &blocks;
for (unsigned int i = 0; i < threads; i++)
{
unsigned nblocks = batches;
@ -4544,6 +4556,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
}
waiter.wait(&tpool);
m_prepare_height = 0;
if (m_cancel)
return false;

@ -205,6 +205,18 @@ namespace cryptonote
*/
crypto::hash get_block_id_by_height(uint64_t height) const;
/**
* @brief gets a block's hash given a height
*
* Used only by prepare_handle_incoming_blocks. Will look in the list of incoming blocks
* if the height is contained there.
*
* @param height the height of the block
*
* @return the hash of the block at the requested height, or a zeroed hash if there is no such block
*/
crypto::hash get_pending_block_id_by_height(uint64_t height) const;
/**
* @brief gets the block with a given hash
*
@ -1082,6 +1094,11 @@ namespace cryptonote
std::shared_ptr<tools::Notify> m_block_notify;
std::shared_ptr<tools::Notify> m_reorg_notify;
// for prepare_handle_incoming_blocks
uint64_t m_prepare_height;
uint64_t m_prepare_nblocks;
std::vector<block> *m_prepare_blocks;
/**
* @brief collects the keys for all outputs being "spent" as an input
*

@ -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);

Loading…
Cancel
Save