Skip to content

Commit

Permalink
AKI-669: Correct reset for PoS difficulty on load
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis committed Mar 6, 2020
1 parent 452d543 commit 29380f7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modAionImpl/src/org/aion/zero/impl/blockchain/AionHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,18 @@ private void loadBlockchain() {

long bestNumber = blockchain.getBestBlock().getNumber();
if (blockchain.forkUtility.isNonceForkActive(bestNumber + 1)) {
Block block = blockchain.getBlockByNumber(blockchain.forkUtility.getNonceForkBlockHeight());
BigInteger newDiff = blockchain.calculateFirstPoSDifficultyAtBlock(block);
blockchain.forkUtility.setNonceForkResetDiff(newDiff);
// Reset the PoS difficulty as part of the fork logic.
if (bestNumber == blockchain.forkUtility.getNonceForkBlockHeight()) {
// If this is the trigger for the fork calculate the new difficulty.
Block block = blockchain.getBestBlock();
BigInteger newDiff = blockchain.calculateFirstPoSDifficultyAtBlock(block);
blockchain.forkUtility.setNonceForkResetDiff(newDiff);
} else {
// Otherwise, assume that it was already calculated and validated during import.
// The difficulty cannot be calculated here due to possible pruning of the world state.
Block firstStaked = blockchain.getBlockByNumber(blockchain.forkUtility.getNonceForkBlockHeight() + 1);
blockchain.forkUtility.setNonceForkResetDiff(firstStaked.getDifficultyBI());
}
}
}

Expand Down

0 comments on commit 29380f7

Please sign in to comment.