mirror of
https://github.com/monero-project/monero.git
synced 2025-08-13 00:15:50 -04:00
commit
0fccc78e39
10 changed files with 138 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -967,6 +967,13 @@ namespace cryptonote
|
|||
*/
|
||||
std::vector<time_t> get_last_block_timestamps(unsigned int blocks) const;
|
||||
|
||||
/**
|
||||
* @brief removes blocks from the top of the blockchain
|
||||
*
|
||||
* @param nblocks number of blocks to be removed
|
||||
*/
|
||||
void pop_blocks(uint64_t nblocks);
|
||||
|
||||
private:
|
||||
|
||||
// TODO: evaluate whether or not each of these typedefs are left over from blockchain_storage
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue