Fix blockchain_import wedge on exception in cleanup_handle_incoming_blocks

This commit is contained in:
moneromooo-monero 2017-08-29 15:43:32 +01:00
parent 0ffad5a359
commit cf4aa65316
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
5 changed files with 47 additions and 15 deletions

View file

@ -2604,6 +2604,16 @@ void BlockchainLMDB::batch_commit()
memset(&m_wcursors, 0, sizeof(m_wcursors)); memset(&m_wcursors, 0, sizeof(m_wcursors));
} }
void BlockchainLMDB::cleanup_batch()
{
// for destruction of batch transaction
m_write_txn = nullptr;
delete m_write_batch_txn;
m_write_batch_txn = nullptr;
m_batch_active = false;
memset(&m_wcursors, 0, sizeof(m_wcursors));
}
void BlockchainLMDB::batch_stop() void BlockchainLMDB::batch_stop()
{ {
LOG_PRINT_L3("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@ -2618,15 +2628,18 @@ void BlockchainLMDB::batch_stop()
check_open(); check_open();
LOG_PRINT_L3("batch transaction: committing..."); LOG_PRINT_L3("batch transaction: committing...");
TIME_MEASURE_START(time1); TIME_MEASURE_START(time1);
m_write_txn->commit(); try
TIME_MEASURE_FINISH(time1); {
time_commit1 += time1; m_write_txn->commit();
// for destruction of batch transaction TIME_MEASURE_FINISH(time1);
m_write_txn = nullptr; time_commit1 += time1;
delete m_write_batch_txn; cleanup_batch();
m_write_batch_txn = nullptr; }
m_batch_active = false; catch (const std::exception &e)
memset(&m_wcursors, 0, sizeof(m_wcursors)); {
cleanup_batch();
throw;
}
LOG_PRINT_L3("batch transaction: end"); LOG_PRINT_L3("batch transaction: end");
} }

View file

@ -368,6 +368,9 @@ private:
// migrate from DB version 0 to 1 // migrate from DB version 0 to 1
void migrate_0_1(); void migrate_0_1();
void cleanup_batch();
private:
MDB_env* m_env; MDB_env* m_env;
MDB_dbi m_blocks; MDB_dbi m_blocks;

View file

@ -208,7 +208,8 @@ int check_flush(cryptonote::core &core, std::list<block_complete_entry> &blocks,
} }
} // each download block } // each download block
core.cleanup_handle_incoming_blocks(); if (!core.cleanup_handle_incoming_blocks())
return 1;
blocks.clear(); blocks.clear();
return 0; return 0;
@ -394,7 +395,10 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
blocks.push_back({block, txs}); blocks.push_back({block, txs});
int ret = check_flush(core, blocks, false); int ret = check_flush(core, blocks, false);
if (ret) if (ret)
{
quit = 2; // make sure we don't commit partial block data
break; break;
}
} }
else else
{ {

View file

@ -3582,12 +3582,23 @@ void Blockchain::block_longhash_worker(uint64_t height, const std::vector<block>
//------------------------------------------------------------------ //------------------------------------------------------------------
bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync) bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
{ {
bool success = false;
MTRACE("Blockchain::" << __func__); MTRACE("Blockchain::" << __func__);
CRITICAL_REGION_BEGIN(m_blockchain_lock); CRITICAL_REGION_BEGIN(m_blockchain_lock);
TIME_MEASURE_START(t1); TIME_MEASURE_START(t1);
m_db->batch_stop(); try
if (m_sync_counter > 0) {
m_db->batch_stop();
success = true;
}
catch (const std::exception &e)
{
MERROR("Exception in cleanup_handle_incoming_blocks: " << e.what());
}
if (success && m_sync_counter > 0)
{ {
if (force_sync) if (force_sync)
{ {
@ -3622,7 +3633,7 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
CRITICAL_REGION_END(); CRITICAL_REGION_END();
m_tx_pool.unlock(); m_tx_pool.unlock();
return true; return success;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------

View file

@ -1068,12 +1068,13 @@ namespace cryptonote
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::cleanup_handle_incoming_blocks(bool force_sync) bool core::cleanup_handle_incoming_blocks(bool force_sync)
{ {
bool success = false;
try { try {
m_blockchain_storage.cleanup_handle_incoming_blocks(force_sync); success = m_blockchain_storage.cleanup_handle_incoming_blocks(force_sync);
} }
catch (...) {} catch (...) {}
m_incoming_tx_lock.unlock(); m_incoming_tx_lock.unlock();
return true; return success;
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------