aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-04-04 12:52:46 -0500
committerluigi1111 <luigi1111w@gmail.com>2020-04-04 12:52:46 -0500
commit44547006bfcac4f807d28016d597b7e5d3693dfd (patch)
tree4fa0fa7140c56bbb216a973b0ff99aa17f942c55
parentMerge pull request #6346 (diff)
parentcryptonote_core: skip block notify on blockchain switching rollback (diff)
downloadmonero-44547006bfcac4f807d28016d597b7e5d3693dfd.tar.xz
Merge pull request #6347
fcb06f7 cryptonote_core: skip block notify on blockchain switching rollback (xiphon)
-rw-r--r--src/cryptonote_core/blockchain.cpp24
-rw-r--r--src/cryptonote_core/blockchain.h6
2 files changed, 20 insertions, 10 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index f0d5828ec..7a13705a3 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -928,7 +928,7 @@ bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain,
for (auto& bl : original_chain)
{
block_verification_context bvc = {};
- bool r = handle_block_to_main_chain(bl, bvc);
+ bool r = handle_block_to_main_chain(bl, bvc, false);
CHECK_AND_ASSERT_MES(r && bvc.m_added_to_main_chain, false, "PANIC! failed to add (again) block while chain switching during the rollback!");
}
@@ -979,7 +979,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info>
block_verification_context bvc = {};
// add block to main chain
- bool r = handle_block_to_main_chain(bei.bl, bvc);
+ bool r = handle_block_to_main_chain(bei.bl, bvc, false);
// if adding block to main chain failed, rollback to previous state and
// return false
@@ -1044,6 +1044,11 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info>
reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(),
"%n", std::to_string(m_db->height() - split_height).c_str(), "%d", std::to_string(discarded_blocks).c_str(), NULL);
+ std::shared_ptr<tools::Notify> block_notify = m_block_notify;
+ if (block_notify)
+ for (const auto &bei: alt_chain)
+ block_notify->notify("%s", epee::string_tools::pod_to_hex(get_block_hash(bei.bl)).c_str(), NULL);
+
MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
return true;
}
@@ -2574,11 +2579,11 @@ bool Blockchain::have_block(const crypto::hash& id) const
return false;
}
//------------------------------------------------------------------
-bool Blockchain::handle_block_to_main_chain(const block& bl, block_verification_context& bvc)
+bool Blockchain::handle_block_to_main_chain(const block& bl, block_verification_context& bvc, bool notify/* = true*/)
{
LOG_PRINT_L3("Blockchain::" << __func__);
crypto::hash id = get_block_hash(bl);
- return handle_block_to_main_chain(bl, id, bvc);
+ return handle_block_to_main_chain(bl, id, bvc, notify);
}
//------------------------------------------------------------------
size_t Blockchain::get_total_transactions() const
@@ -3687,7 +3692,7 @@ bool Blockchain::flush_txes_from_pool(const std::vector<crypto::hash> &txids)
// Needs to validate the block and acquire each transaction from the
// transaction mem_pool, then pass the block and transactions to
// m_db->add_block()
-bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc)
+bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc, bool notify/* = true*/)
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -4067,9 +4072,12 @@ leave:
get_difficulty_for_next_block(); // just to cache it
invalidate_block_template_cache();
- std::shared_ptr<tools::Notify> block_notify = m_block_notify;
- if (block_notify)
- block_notify->notify("%s", epee::string_tools::pod_to_hex(id).c_str(), NULL);
+ if (notify)
+ {
+ std::shared_ptr<tools::Notify> block_notify = m_block_notify;
+ if (block_notify)
+ block_notify->notify("%s", epee::string_tools::pod_to_hex(id).c_str(), NULL);
+ }
return true;
}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 4ed7a2f02..3a89cc5df 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -1212,10 +1212,11 @@ namespace cryptonote
*
* @param bl the block to be added
* @param bvc metadata concerning the block's validity
+ * @param notify if set to true, sends new block notification on success
*
* @return true if the block was added successfully, otherwise false
*/
- bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc);
+ bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc, bool notify = true);
/**
* @brief validate and add a new block to the end of the blockchain
@@ -1227,10 +1228,11 @@ namespace cryptonote
* @param bl the block to be added
* @param id the hash of the block
* @param bvc metadata concerning the block's validity
+ * @param notify if set to true, sends new block notification on success
*
* @return true if the block was added successfully, otherwise false
*/
- bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc);
+ bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc, bool notify = true);
/**
* @brief validate and add a new block to an alternate blockchain