mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-27 13:23:29 +01:00
blockchain: fix wrong hf version when popping multiple blocks
Since we keep track of the hf version in the db, we pick it up from there instead of doing the full reorg call, which is quite expensive
This commit is contained in:
parent
634d359a84
commit
5ee6f03742
@ -305,6 +305,29 @@ bool HardFork::rescan_from_chain_height(uint64_t height)
|
|||||||
return rescan_from_block_height(height - 1);
|
return rescan_from_block_height(height - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HardFork::on_block_popped(uint64_t nblocks)
|
||||||
|
{
|
||||||
|
CHECK_AND_ASSERT_THROW_MES(nblocks > 0, "nblocks must be greater than 0");
|
||||||
|
|
||||||
|
CRITICAL_REGION_LOCAL(lock);
|
||||||
|
|
||||||
|
const uint64_t new_chain_height = db.height();
|
||||||
|
const uint64_t old_chain_height = new_chain_height + nblocks;
|
||||||
|
uint8_t version;
|
||||||
|
uint64_t height;
|
||||||
|
for (height = old_chain_height - 1; height >= new_chain_height; --height)
|
||||||
|
{
|
||||||
|
versions.pop_back();
|
||||||
|
version = db.get_hard_fork_version(height);
|
||||||
|
versions.push_front(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
// does not take voting into account
|
||||||
|
for (current_fork_index = heights.size() - 1; current_fork_index > 0; --current_fork_index)
|
||||||
|
if (height >= heights[current_fork_index].height)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
int HardFork::get_voted_fork_index(uint64_t height) const
|
int HardFork::get_voted_fork_index(uint64_t height) const
|
||||||
{
|
{
|
||||||
CRITICAL_REGION_LOCAL(lock);
|
CRITICAL_REGION_LOCAL(lock);
|
||||||
|
@ -149,6 +149,16 @@ namespace cryptonote
|
|||||||
bool reorganize_from_block_height(uint64_t height);
|
bool reorganize_from_block_height(uint64_t height);
|
||||||
bool reorganize_from_chain_height(uint64_t height);
|
bool reorganize_from_chain_height(uint64_t height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief called when one or more blocks are popped from the blockchain
|
||||||
|
*
|
||||||
|
* The current fork will be updated by looking up the db,
|
||||||
|
* which is much cheaper than recomputing everything
|
||||||
|
*
|
||||||
|
* @param new_chain_height the height of the chain after popping
|
||||||
|
*/
|
||||||
|
void on_block_popped(uint64_t new_chain_height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns current state at the given time
|
* @brief returns current state at the given time
|
||||||
*
|
*
|
||||||
|
@ -641,6 +641,9 @@ block Blockchain::pop_block_from_blockchain()
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure the hard fork object updates its current version
|
||||||
|
m_hardfork->on_block_popped(1);
|
||||||
|
|
||||||
// return transactions from popped block to the tx_pool
|
// return transactions from popped block to the tx_pool
|
||||||
for (transaction& tx : popped_txs)
|
for (transaction& tx : popped_txs)
|
||||||
{
|
{
|
||||||
@ -651,12 +654,7 @@ block Blockchain::pop_block_from_blockchain()
|
|||||||
// FIXME: HardFork
|
// FIXME: HardFork
|
||||||
// Besides the below, popping a block should also remove the last entry
|
// Besides the below, popping a block should also remove the last entry
|
||||||
// in hf_versions.
|
// in hf_versions.
|
||||||
//
|
uint8_t version = get_ideal_hard_fork_version(m_db->height());
|
||||||
// FIXME: HardFork
|
|
||||||
// This is not quite correct, as we really want to add the txes
|
|
||||||
// to the pool based on the version determined after all blocks
|
|
||||||
// are popped.
|
|
||||||
uint8_t version = get_current_hard_fork_version();
|
|
||||||
|
|
||||||
// We assume that if they were in a block, the transactions are already
|
// We assume that if they were in a block, the transactions are already
|
||||||
// known to the network as a whole. However, if we had mined that block,
|
// known to the network as a whole. However, if we had mined that block,
|
||||||
|
Loading…
Reference in New Issue
Block a user