mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
Difficulty workaround (#722)
* Recalculate difficulty on reorganisation workaround * Gate difficulty workaround to only be on mainnet * Make difficulty changes emit logs on diff delta only
This commit is contained in:
parent
ca37156c38
commit
3cc5fd62ca
|
@ -4576,7 +4576,10 @@ void BlockchainLMDB::fixup(fixup_context const context)
|
|||
block_info.bi_diff = prev_cumulative_diff + diff;
|
||||
prev_cumulative_diff = block_info.bi_diff;
|
||||
|
||||
LOG_PRINT_L0("Height: " << curr_height << " prev difficulty: " << old_cumulative_diff << ", new difficulty: " << block_info.bi_diff);
|
||||
if (old_cumulative_diff != block_info.bi_diff)
|
||||
LOG_PRINT_L0("Height: " << curr_height << " prev difficulty: " << old_cumulative_diff << ", new difficulty: " << block_info.bi_diff);
|
||||
else
|
||||
LOG_PRINT_L2("Height: " << curr_height << " difficulty unchanged (" << old_cumulative_diff << ")");
|
||||
|
||||
MDB_val_set(val, block_info);
|
||||
if (int result = mdb_cursor_put(m_cur_block_info, (MDB_val *)&zerokval, &val, MDB_CURRENT))
|
||||
|
|
|
@ -1059,6 +1059,19 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<block_extended_info>
|
|||
|
||||
auto split_height = m_db->height();
|
||||
|
||||
// TODO(loki): This is a work around for sometimes reorganising the blockchain causing inconsistent difficulty values
|
||||
LOKI_DEFER
|
||||
{
|
||||
if (nettype() == MAINNET)
|
||||
{
|
||||
uint64_t const FUDGE = 60;
|
||||
cryptonote::BlockchainDB::fixup_context context = {};
|
||||
context.type = cryptonote::BlockchainDB::fixup_type::calculate_difficulty;
|
||||
context.calculate_difficulty_params.start_height = split_height < FUDGE ? 0 : split_height - FUDGE;
|
||||
m_db->fixup(context);
|
||||
}
|
||||
};
|
||||
|
||||
for (BlockchainDetachedHook* hook : m_blockchain_detached_hooks)
|
||||
hook->blockchain_detached(split_height);
|
||||
|
||||
|
|
Loading…
Reference in a new issue