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:
Doyle 2019-07-11 14:15:32 +10:00 committed by GitHub
parent ca37156c38
commit 3cc5fd62ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -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))

View file

@ -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);