Skip to content

Commit

Permalink
fix: correct epoch condition for applying babbage rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbormann committed Mar 6, 2024
1 parent cecb27e commit 4206206
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static EpochCalculationResult calculateEpochRewardPots(int epoch, DataPro

HashSet<String> deregisteredAccounts;
HashSet<String> lateDeregisteredAccounts = new HashSet<>();
if (epoch < MAINNET_VASIL_HARDFORK_EPOCH) {
if (epoch - 2 < MAINNET_VASIL_HARDFORK_EPOCH) {
deregisteredAccounts = dataProvider.getDeregisteredAccountsInEpoch(epoch - 1, RANDOMNESS_STABILISATION_WINDOW);
lateDeregisteredAccounts = dataProvider.getLateAccountDeregistrationsInEpoch(epoch - 1, RANDOMNESS_STABILISATION_WINDOW);
} else {
Expand Down Expand Up @@ -112,10 +112,10 @@ public static EpochCalculationResult calculateEpochRewardPots(int epoch, DataPro
poolValidationResults.add(poolValidationResult);

if (!poolValidationResult.isValid()) {
log.debug("Pool reward is invalid. Please check the details for pool " + poolRewardCalculationResult.getPoolId());
log.info("Pool reward is invalid. Please check the details for pool " + poolRewardCalculationResult.getPoolId());
}
end = System.currentTimeMillis();
log.info("Validation of pool " + poolRewardCalculationResult.getPoolId() + " took " + Math.round((end - start) / 1000.0) + "s");
log.debug("Validation of pool " + poolRewardCalculationResult.getPoolId() + " took " + Math.round((end - start) / 1000.0) + "s");
}
poolValidationResults.sort(Comparator.comparing(PoolValidationResult::getOffset).reversed());
log.info("The pool with the largest offset is " + poolValidationResults.get(0).getPoolId() + " with an offset of " + poolValidationResults.get(0).getOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
.collect(toCollection(HashSet::new));

if (actualPoolReward.equals(BigInteger.ZERO)) {
log.debug("Pool reward is zero for pool " + poolId + " but calculated pool reward is " + poolRewardCalculationResult.getPoolReward().longValue() + " Lovelace");
log.info("Pool reward is zero for pool " + poolId + " but calculated pool reward is " + poolRewardCalculationResult.getPoolReward().longValue() + " Lovelace");
return poolRewardValidationResult;
}

BigInteger totalDifference = BigInteger.ZERO;
int rewardIndex = 0;
HashSet<RewardValidation> rewardValidations = poolRewardValidationResult.getRewardValidations();
HashSet<RewardValidation> rewardValidations = new HashSet<>();
HashSet<Reward> delegatorStakeAddresses = new HashSet<>(poolRewardCalculationResult.getMemberRewards());
for (Reward reward : actualPoolRewardsInEpoch) {
Reward memberReward = delegatorStakeAddresses.stream()
Expand All @@ -187,8 +187,8 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
.calculatedReward(BigInteger.ZERO).build();

if (memberReward == null) {
log.debug("Member reward not found for stake address: " + reward.getStakeAddress());
log.debug("[" + rewardIndex + "] The expected member " + reward.getStakeAddress() + " reward would be : " + reward.getAmount().longValue() + " Lovelace");
log.info("Member reward not found for stake address: " + reward.getStakeAddress());
log.info("[" + rewardIndex + "] The expected member " + reward.getStakeAddress() + " reward would be : " + reward.getAmount().longValue() + " Lovelace");
totalDifference = totalDifference.add(reward.getAmount());
} else {
rewardValidation.setCalculatedReward(memberReward.getAmount());
Expand All @@ -201,15 +201,15 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
totalDifference = totalDifference.add(difference);

if (difference.compareTo(BigInteger.ZERO) > 0) {
log.debug("[" + rewardIndex + "] The difference between expected member " + reward.getStakeAddress() + " reward and actual member reward is : " + difference.longValue() + " Lovelace");
log.info("[" + rewardIndex + "] The difference between expected member " + reward.getStakeAddress() + " reward and actual member reward is : " + difference.longValue() + " Lovelace");
}
}
rewardValidations.add(rewardValidation);
rewardIndex++;
}

if (isHigher(totalDifference, BigInteger.ZERO)) {
log.debug("Total difference: " + totalDifference.longValue() + " Lovelace");
log.info("Total difference: " + totalDifference.longValue() + " Lovelace");
}

BigInteger totalNoReward = BigInteger.ZERO;
Expand All @@ -224,7 +224,7 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
.orElse(null);
if (actualReward == null && isHigher(memberReward.getAmount(), BigInteger.ZERO) && !poolRewardCalculationResult.getPoolOwnerStakeAddresses().contains(memberReward.getStakeAddress())) {
totalNoReward = totalNoReward.add(memberReward.getAmount());
log.debug("No reward! The difference between expected member " + memberReward.getStakeAddress() + " reward and actual member reward is : " + memberReward.getAmount().longValue() + " Lovelace");
log.info("No reward! The difference between expected member " + memberReward.getStakeAddress() + " reward and actual member reward is : " + memberReward.getAmount().longValue() + " Lovelace");
rewardValidations.add(RewardValidation.builder()
.stakeAddress(memberReward.getStakeAddress())
.expectedReward(BigInteger.ZERO)
Expand All @@ -238,12 +238,14 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
}

if (isHigher(totalNoReward, BigInteger.ZERO)) {
log.debug("Total no reward: " + totalNoReward.longValue() + " Lovelace");
log.info("Total no reward: " + totalNoReward.longValue() + " Lovelace");
}
}

poolRewardValidationResult = PoolValidationResult.from(poolRewardCalculationResult, rewardValidations);

if (!poolRewardValidationResult.isValid()) {
log.debug("The difference between expected pool reward and actual pool reward is : " + poolRewardValidationResult.getOffset().longValue() + " Lovelace");
log.info("The difference between expected pool reward and actual pool reward is : " + poolRewardValidationResult.getOffset().longValue() + " Lovelace");
}

return poolRewardValidationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void testCalculateEpochRewardsForEpoch417() {

@Test
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
public void testCalculateEpochRewardsForEpoch415() {
testCalculateEpochPots(415, dbSyncDataProvider, false);
public void testCalculateEpochRewardsForEpoch365() {
testCalculateEpochPots(365, dbSyncDataProvider, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ void calculateBinancePool59RewardInEpoch413() {
Test_calculatePoolReward(poolId, epoch, DataProviderType.DB_SYNC);
}

@Test
void calculateEVE3PoolRewardInEpoch363() {
String poolId = "pool1kchver88u3kygsak8wgll7htr8uxn5v35lfrsyy842nkscrzyvj";
int epoch = 363;
Test_calculatePoolReward(poolId, epoch, DataProviderType.JSON);
}

@Test
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
void calculateSTKH1PoolRewardInEpoch363() {
Expand Down

0 comments on commit 4206206

Please sign in to comment.