core: avoid double parsing blocks after hoh

This commit is contained in:
moneromooo-monero
2018-11-23 11:15:04 +00:00
parent dc5a76095c
commit 238401d4e9
6 changed files with 50 additions and 25 deletions
+2 -2
View File
@@ -4211,13 +4211,14 @@ uint64_t Blockchain::prevalidate_block_hashes(uint64_t height, const std::vector
// vs [k_image, output_keys] (m_scan_table). This is faster because it takes advantage of bulk queries
// and is threaded if possible. The table (m_scan_table) will be used later when querying output
// keys.
bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry)
bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
MTRACE("Blockchain::" << __func__);
TIME_MEASURE_START(prepare);
bool stop_batch;
uint64_t bytes = 0;
size_t total_txs = 0;
blocks.clear();
// Order of locking must be:
// m_incoming_tx_lock (optional)
@@ -4264,7 +4265,6 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
bool blocks_exist = false;
tools::threadpool& tpool = tools::threadpool::getInstance();
unsigned threads = tpool.get_max_concurrency();
std::vector<block> blocks;
blocks.resize(blocks_entry.size());
if (1)
+3 -2
View File
@@ -230,11 +230,12 @@ namespace cryptonote
/**
* @brief performs some preprocessing on a group of incoming blocks to speed up verification
*
* @param blocks a list of incoming blocks
* @param blocks_entry a list of incoming blocks
* @param blocks the parsed blocks
*
* @return false on erroneous blocks, else true
*/
bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks);
bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks);
/**
* @brief incoming blocks post-processing, cleanup, and disk sync
+15 -10
View File
@@ -1330,7 +1330,8 @@ namespace cryptonote
m_miner.resume();
return false;
}
prepare_handle_incoming_blocks(blocks);
std::vector<block> pblocks;
prepare_handle_incoming_blocks(blocks, pblocks);
m_blockchain_storage.add_new_block(b, bvc);
cleanup_handle_incoming_blocks(true);
//anyway - update miner template
@@ -1381,10 +1382,10 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks)
bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
m_incoming_tx_lock.lock();
m_blockchain_storage.prepare_handle_incoming_blocks(blocks);
m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks);
return true;
}
@@ -1401,7 +1402,7 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
bool core::handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate)
bool core::handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate)
{
TRY_ENTRY();
@@ -1417,14 +1418,18 @@ namespace cryptonote
return false;
}
block b = AUTO_VAL_INIT(b);
if(!parse_and_validate_block_from_blob(block_blob, b))
block lb;
if (!b)
{
LOG_PRINT_L1("Failed to parse and validate new block");
bvc.m_verifivation_failed = true;
return false;
if(!parse_and_validate_block_from_blob(block_blob, lb))
{
LOG_PRINT_L1("Failed to parse and validate new block");
bvc.m_verifivation_failed = true;
return false;
}
b = &lb;
}
add_new_block(b, bvc);
add_new_block(*b, bvc);
if(update_miner_blocktemplate && bvc.m_added_to_main_chain)
update_miner_block_template();
return true;
+3 -2
View File
@@ -146,20 +146,21 @@ namespace cryptonote
* optionally updates the miner's block template.
*
* @param block_blob the block to be added
* @param block the block to be added, or NULL
* @param bvc return-by-reference metadata context about the block's validity
* @param update_miner_blocktemplate whether or not to update the miner's block template
*
* @return false if loading new checkpoints fails, or the block is not
* added, otherwise true
*/
bool handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate = true);
bool handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate = true);
/**
* @copydoc Blockchain::prepare_handle_incoming_blocks
*
* @note see Blockchain::prepare_handle_incoming_blocks
*/
bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks);
bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks);
/**
* @copydoc Blockchain::cleanup_handle_incoming_blocks