aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorJason Wong <jason.hcwong@gmail.com>2018-11-25 22:08:07 +0100
committerJason Wong <jason.hcwong@gmail.com>2018-11-28 12:20:28 +0100
commitdc1c12528d5cf86759993614e1fdd7d7bf04ff15 (patch)
tree8fa2119970bd01b384481d2944b1dc137f271435 /src/cryptonote_core/blockchain.cpp
parentMerge pull request #4821 (diff)
downloadmonero-dc1c12528d5cf86759993614e1fdd7d7bf04ff15.tar.xz
add command pop_blocks
add new public method to Blockchain and update according to code review update after review: better lock/unlock, try catch and coding style
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index bfc5dbbe0..009c5e2ed 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -576,6 +576,38 @@ bool Blockchain::deinit()
return true;
}
//------------------------------------------------------------------
+// This function removes blocks from the top of blockchain.
+// It starts a batch and calls private method pop_block_from_blockchain().
+void Blockchain::pop_blocks(uint64_t nblocks)
+{
+ uint64_t i;
+ 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();
+ }
+
+ try
+ {
+ for (i=0; i < nblocks; ++i)
+ {
+ pop_block_from_blockchain();
+ }
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR("Error when popping blocks, only " << i << " blocks are popped: " << e.what());
+ }
+
+ m_db->batch_stop();
+}
+//------------------------------------------------------------------
// This function tells BlockchainDB to remove the top block from the
// blockchain and then returns all transactions (except the miner tx, of course)
// from it to the tx_pool