Skip to content

Commit

Permalink
SQ4-183 rewards fixes for the amity syncing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Dec 9, 2020
1 parent 0528110 commit fa237a0
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class AionBlockchainImpl implements IAionBlockchain {
public final ForkUtility forkUtility;
public final BeaconHashValidator beaconHashValidator;
private final boolean isMainnet;
private boolean isAmity;

/**
* Chain configuration class, because chain configuration may change dependant on the block
Expand Down Expand Up @@ -260,6 +261,8 @@ public BlockHeaderValidator createBlockHeaderValidatorForImport() {
}
} : new ChainConfiguration(),
eventMgr);

isAmity = cfgAion.getNetwork().equals("amity");
}

/**
Expand Down Expand Up @@ -1940,7 +1943,7 @@ private Map<AionAddress, BigInteger> addReward(Block block) {
Map<AionAddress, BigInteger> rewards = new HashMap<>();

BigInteger minerReward;
if (forkUtility.isSignatureSwapForkActive(block.getNumber())) {
if (forkUtility.isSignatureSwapForkActive(block.getNumber()) || isAmityRewardException(block.getNumber())) {
if (block.getHeader().getSealType().equals(Seal.PROOF_OF_WORK)) {
minerReward =
TimeVaryingRewardsCalculator.calculateReward(
Expand Down Expand Up @@ -1970,13 +1973,31 @@ private Map<AionAddress, BigInteger> addReward(Block block) {
*/
track.addBalance(block.getCoinbase(), minerReward);

if (forkUtility.isSignatureSwapForkBlock(block.getNumber())) {
if ((isMainnet && forkUtility.isSignatureSwapForkBlock(block.getNumber())) || isAmityRollbackException(block.getNumber())) {
balanceRollback();
}

return rewards;
}

/**
* Hot-fix for amity network in 1.6.1
* @param blockNumber
* @return
*/
private boolean isAmityRewardException(long blockNumber) {
return isAmity && forkUtility.isSignatureSwapForkBlock(blockNumber - 1);
}

/**
* Hot-fix for amity network in 1.6.1
* @param blockNumber
* @return
*/
private boolean isAmityRollbackException(long blockNumber) {
return isAmity && forkUtility.isSignatureSwapForkBlock(blockNumber + 1);
}

/**
* SQ4-142
* Rollback the balance for the mistake transactions
Expand Down

0 comments on commit fa237a0

Please sign in to comment.