diff options
author | warptangent <warptangent@inbox.com> | 2015-01-11 18:19:01 -0800 |
---|---|---|
committer | warptangent <warptangent@inbox.com> | 2015-01-11 21:23:02 -0800 |
commit | 909ea810671e8da74b0c0d92641eee8dd798e0b3 (patch) | |
tree | 1a59c8d254969098b050ea28e5b5cc7eea62cba3 /src/cryptonote_core/blockchain.cpp | |
parent | Complete implementation of transaction removal (diff) | |
download | monero-909ea810671e8da74b0c0d92641eee8dd798e0b3.tar.xz |
Remove a have_block() check so alternate block can be processed
Remove have_block() check from Blockchain::handle_block_to_main_chain().
Add logging to have_block().
This allows blockchain reorganization to proceed further.
have_block() check here causes an error after a blockchain reorganize
begins with error: "Attempting to add block to main chain, but it's
already either there or in an alternate chain."
While reorganizing to become the main chain, a block in the
alternative chain would be refused due to have_block() rightfully
finding it in the alternative chain. The reorganization would end in
rollback, restoring to previous blockchain.
Original implementation didn't call it here, and it doesn't appear
necessary to be called from here in this implementation either. When
needed, it appears it's called prior to handle_block_to_main_chain().
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 2a8eb6721..7015383fa 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1699,13 +1699,22 @@ bool Blockchain::have_block(const crypto::hash& id) const CRITICAL_REGION_LOCAL(m_blockchain_lock); if(m_db->block_exists(id)) + { + LOG_PRINT_L3("block exists in main chain"); return true; + } if(m_alternative_chains.count(id)) + { + LOG_PRINT_L3("block found in m_alternative_chains"); return true; + } if(m_invalid_blocks.count(id)) + { + LOG_PRINT_L3("block found in m_invalid_blocks"); return true; + } return false; } @@ -2010,14 +2019,25 @@ bool Blockchain::check_block_timestamp(const block& b) const bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc) { LOG_PRINT_L3("Blockchain::" << __func__); + + // NOTE: Omitting check below with have_block() It causes an error after a + // blockchain reorganize begins with error: "Attempting to add block to main + // chain, but it's already either there or in an alternate" + // + // A block in the alternative chain, desired to become the main chain, never + // makes it due to have_block finding it in he alternative chain. + // + // Original implementation didn't use it here, and it doesn't appear + // necessary to be called from here in this implementation either. + // if we already have the block, return false - if (have_block(id)) - { - LOG_PRINT_L0("Attempting to add block to main chain, but it's already either there or in an alternate chain. hash: " << id); - bvc.m_verifivation_failed = true; - return false; - } - + // if (have_block(id)) + // { + // LOG_PRINT_L0("Attempting to add block to main chain, but it's already either there or in an alternate chain. hash: " << id); + // bvc.m_verifivation_failed = true; + // return false; + // } + TIME_MEASURE_START(block_processing_time); CRITICAL_REGION_LOCAL(m_blockchain_lock); if(bl.prev_id != get_tail_id()) |