mirror of
https://github.com/monero-project/monero.git
synced 2026-01-09 11:45:11 -08:00
core: do not commit half constructed batch db txn
This commit is contained in:
@@ -182,7 +182,8 @@ 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)
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
}
|
||||
@@ -619,14 +620,7 @@ void Blockchain::pop_blocks(uint64_t nblocks)
|
||||
CRITICAL_REGION_LOCAL(m_tx_pool);
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain_lock);
|
||||
|
||||
while (!m_db->batch_start())
|
||||
{
|
||||
m_blockchain_lock.unlock();
|
||||
m_tx_pool.unlock();
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
m_tx_pool.lock();
|
||||
m_blockchain_lock.lock();
|
||||
}
|
||||
bool stop_batch = m_db->batch_start();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -637,10 +631,14 @@ void Blockchain::pop_blocks(uint64_t nblocks)
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("Error when popping blocks, only " << i << " blocks are popped: " << e.what());
|
||||
LOG_ERROR("Error when popping blocks after processing " << i << " blocks: " << e.what());
|
||||
if (stop_batch)
|
||||
m_db->batch_abort();
|
||||
return;
|
||||
}
|
||||
|
||||
m_db->batch_stop();
|
||||
if (stop_batch)
|
||||
m_db->batch_stop();
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
// This function tells BlockchainDB to remove the top block from the
|
||||
@@ -3844,6 +3842,7 @@ leave:
|
||||
catch (const KEY_IMAGE_EXISTS& e)
|
||||
{
|
||||
LOG_ERROR("Error adding block with hash: " << id << " to blockchain, what = " << e.what());
|
||||
m_batch_success = false;
|
||||
bvc.m_verifivation_failed = true;
|
||||
return_tx_to_pool(txs);
|
||||
return false;
|
||||
@@ -3852,6 +3851,7 @@ leave:
|
||||
{
|
||||
//TODO: figure out the best way to deal with this failure
|
||||
LOG_ERROR("Error adding block with hash: " << id << " to blockchain, what = " << e.what());
|
||||
m_batch_success = false;
|
||||
bvc.m_verifivation_failed = true;
|
||||
return_tx_to_pool(txs);
|
||||
return false;
|
||||
@@ -4161,7 +4161,10 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
|
||||
|
||||
try
|
||||
{
|
||||
m_db->batch_stop();
|
||||
if (m_batch_success)
|
||||
m_db->batch_stop();
|
||||
else
|
||||
m_db->batch_abort();
|
||||
success = true;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
@@ -4385,6 +4388,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
m_tx_pool.lock();
|
||||
m_blockchain_lock.lock();
|
||||
}
|
||||
m_batch_success = true;
|
||||
|
||||
const uint64_t height = m_db->height();
|
||||
if ((height + blocks_entry.size()) < m_blocks_hash_check.size())
|
||||
|
||||
Reference in New Issue
Block a user