mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
cryptonote: avoid double parsing blocks when syncing
This commit is contained in:
parent
9feda0eeba
commit
88c85c18e0
@ -3889,11 +3889,9 @@ bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effecti
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc)
|
||||
bool Blockchain::add_new_block(const block& bl, block_verification_context& bvc)
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
//copy block here to let modify block.target
|
||||
block bl = bl_;
|
||||
crypto::hash id = get_block_hash(bl);
|
||||
CRITICAL_REGION_LOCAL(m_tx_pool);//to avoid deadlock lets lock tx_pool for whole add/reorganize process
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain_lock);
|
||||
@ -4296,14 +4294,12 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
if (block.prev_id != tophash)
|
||||
{
|
||||
MDEBUG("Skipping prepare blocks. New blocks don't belong to chain.");
|
||||
blocks.clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (have_block(get_block_hash(block)))
|
||||
{
|
||||
blocks_exist = true;
|
||||
break;
|
||||
}
|
||||
|
||||
std::advance(it, 1);
|
||||
}
|
||||
@ -4317,10 +4313,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
return false;
|
||||
|
||||
if (have_block(get_block_hash(block)))
|
||||
{
|
||||
blocks_exist = true;
|
||||
break;
|
||||
}
|
||||
|
||||
std::advance(it, 1);
|
||||
}
|
||||
@ -4356,7 +4349,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
|
||||
if (blocks_exist)
|
||||
{
|
||||
MDEBUG("Skipping prepare blocks. Blocks exist.");
|
||||
MDEBUG("Skipping remainder of prepare blocks. Blocks exist.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1331,7 +1331,12 @@ namespace cryptonote
|
||||
return false;
|
||||
}
|
||||
std::vector<block> pblocks;
|
||||
prepare_handle_incoming_blocks(blocks, pblocks);
|
||||
if (!prepare_handle_incoming_blocks(blocks, pblocks))
|
||||
{
|
||||
MERROR("Block found, but failed to prepare to add");
|
||||
m_miner.resume();
|
||||
return false;
|
||||
}
|
||||
m_blockchain_storage.add_new_block(b, bvc);
|
||||
cleanup_handle_incoming_blocks(true);
|
||||
//anyway - update miner template
|
||||
@ -1385,7 +1390,11 @@ namespace cryptonote
|
||||
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_entry, blocks);
|
||||
if (!m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks))
|
||||
{
|
||||
cleanup_handle_incoming_blocks(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,13 @@ namespace cryptonote
|
||||
std::vector<block_complete_entry> blocks;
|
||||
blocks.push_back(arg.b);
|
||||
std::vector<block> pblocks;
|
||||
m_core.prepare_handle_incoming_blocks(blocks, pblocks);
|
||||
if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
|
||||
{
|
||||
LOG_PRINT_CCONTEXT_L1("Block verification failed: prepare_handle_incoming_blocks failed, dropping connection");
|
||||
drop_connection(context, false, false);
|
||||
m_core.resume_mine();
|
||||
return 1;
|
||||
}
|
||||
for(auto tx_blob_it = arg.b.txs.begin(); tx_blob_it!=arg.b.txs.end();tx_blob_it++)
|
||||
{
|
||||
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
||||
@ -699,7 +705,12 @@ namespace cryptonote
|
||||
std::vector<block_complete_entry> blocks;
|
||||
blocks.push_back(b);
|
||||
std::vector<block> pblocks;
|
||||
m_core.prepare_handle_incoming_blocks(blocks, pblocks);
|
||||
if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
|
||||
{
|
||||
LOG_PRINT_CCONTEXT_L0("Failure in prepare_handle_incoming_blocks");
|
||||
m_core.resume_mine();
|
||||
return 1;
|
||||
}
|
||||
|
||||
block_verification_context bvc = boost::value_initialized<block_verification_context>();
|
||||
m_core.handle_incoming_block(arg.b.block, pblocks.empty() ? NULL : &pblocks[0], bvc); // got block from handle_notify_new_block
|
||||
@ -1177,7 +1188,11 @@ namespace cryptonote
|
||||
}
|
||||
|
||||
std::vector<block> pblocks;
|
||||
m_core.prepare_handle_incoming_blocks(blocks, pblocks);
|
||||
if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
|
||||
{
|
||||
LOG_ERROR_CCONTEXT("Failure in prepare_handle_incoming_blocks");
|
||||
return 1;
|
||||
}
|
||||
if (!pblocks.empty() && pblocks.size() != blocks.size())
|
||||
{
|
||||
m_core.cleanup_handle_incoming_blocks();
|
||||
|
@ -197,7 +197,7 @@ bool tests::proxy_core::handle_incoming_txs(const std::vector<blobdata>& tx_blob
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) {
|
||||
bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block_, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) {
|
||||
block b = AUTO_VAL_INIT(b);
|
||||
|
||||
if(!parse_and_validate_block_from_blob(block_blob, b)) {
|
||||
|
@ -77,7 +77,7 @@ namespace tests
|
||||
void get_blockchain_top(uint64_t& height, crypto::hash& top_id);
|
||||
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
|
||||
void pause_mine(){}
|
||||
void resume_mine(){}
|
||||
bool on_idle(){return true;}
|
||||
@ -86,7 +86,7 @@ namespace tests
|
||||
cryptonote::Blockchain &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class proxy_core."); }
|
||||
bool get_test_drop_download() {return true;}
|
||||
bool get_test_drop_download_height() {return true;}
|
||||
bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks) { return true; }
|
||||
bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks_entry, std::vector<cryptonote::block> &blocks) { return true; }
|
||||
bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; }
|
||||
uint64_t get_target_blockchain_height() const { return 1; }
|
||||
size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; }
|
||||
|
@ -388,7 +388,7 @@ public:
|
||||
log_event("cryptonote::block");
|
||||
|
||||
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
|
||||
m_c.handle_incoming_block(t_serializable_object_to_blob(b), bvc);
|
||||
m_c.handle_incoming_block(t_serializable_object_to_blob(b), &b, bvc);
|
||||
bool r = check_block_verification_context(bvc, m_ev_index, b, m_validator);
|
||||
CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
|
||||
return r;
|
||||
@ -411,7 +411,7 @@ public:
|
||||
log_event("serialized_block");
|
||||
|
||||
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
|
||||
m_c.handle_incoming_block(sr_block.data, bvc);
|
||||
m_c.handle_incoming_block(sr_block.data, NULL, bvc);
|
||||
|
||||
cryptonote::block blk;
|
||||
std::stringstream ss;
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
|
||||
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
|
||||
void pause_mine(){}
|
||||
void resume_mine(){}
|
||||
bool on_idle(){return true;}
|
||||
@ -65,7 +65,7 @@ public:
|
||||
cryptonote::blockchain_storage &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class test_core."); }
|
||||
bool get_test_drop_download() const {return true;}
|
||||
bool get_test_drop_download_height() const {return true;}
|
||||
bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks) { return true; }
|
||||
bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks_entry, std::vector<cryptonote::block> &blocks) { return true; }
|
||||
bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; }
|
||||
uint64_t get_target_blockchain_height() const { return 1; }
|
||||
size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; }
|
||||
|
Loading…
Reference in New Issue
Block a user