Skip to content

Commit 4206206

Browse files
committed
fix: correct epoch condition for applying babbage rules
1 parent cecb27e commit 4206206

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

validation/src/main/java/org/cardanofoundation/rewards/validation/EpochValidation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static EpochCalculationResult calculateEpochRewardPots(int epoch, DataPro
6767

6868
HashSet<String> deregisteredAccounts;
6969
HashSet<String> lateDeregisteredAccounts = new HashSet<>();
70-
if (epoch < MAINNET_VASIL_HARDFORK_EPOCH) {
70+
if (epoch - 2 < MAINNET_VASIL_HARDFORK_EPOCH) {
7171
deregisteredAccounts = dataProvider.getDeregisteredAccountsInEpoch(epoch - 1, RANDOMNESS_STABILISATION_WINDOW);
7272
lateDeregisteredAccounts = dataProvider.getLateAccountDeregistrationsInEpoch(epoch - 1, RANDOMNESS_STABILISATION_WINDOW);
7373
} else {
@@ -112,10 +112,10 @@ public static EpochCalculationResult calculateEpochRewardPots(int epoch, DataPro
112112
poolValidationResults.add(poolValidationResult);
113113

114114
if (!poolValidationResult.isValid()) {
115-
log.debug("Pool reward is invalid. Please check the details for pool " + poolRewardCalculationResult.getPoolId());
115+
log.info("Pool reward is invalid. Please check the details for pool " + poolRewardCalculationResult.getPoolId());
116116
}
117117
end = System.currentTimeMillis();
118-
log.info("Validation of pool " + poolRewardCalculationResult.getPoolId() + " took " + Math.round((end - start) / 1000.0) + "s");
118+
log.debug("Validation of pool " + poolRewardCalculationResult.getPoolId() + " took " + Math.round((end - start) / 1000.0) + "s");
119119
}
120120
poolValidationResults.sort(Comparator.comparing(PoolValidationResult::getOffset).reversed());
121121
log.info("The pool with the largest offset is " + poolValidationResults.get(0).getPoolId() + " with an offset of " + poolValidationResults.get(0).getOffset());

validation/src/main/java/org/cardanofoundation/rewards/validation/PoolRewardValidation.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ public static PoolValidationResult validatePoolRewardCalculation(PoolRewardCalcu
167167
.collect(toCollection(HashSet::new));
168168

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

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

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

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

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

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

240240
if (isHigher(totalNoReward, BigInteger.ZERO)) {
241-
log.debug("Total no reward: " + totalNoReward.longValue() + " Lovelace");
241+
log.info("Total no reward: " + totalNoReward.longValue() + " Lovelace");
242242
}
243243
}
244244

245+
poolRewardValidationResult = PoolValidationResult.from(poolRewardCalculationResult, rewardValidations);
246+
245247
if (!poolRewardValidationResult.isValid()) {
246-
log.debug("The difference between expected pool reward and actual pool reward is : " + poolRewardValidationResult.getOffset().longValue() + " Lovelace");
248+
log.info("The difference between expected pool reward and actual pool reward is : " + poolRewardValidationResult.getOffset().longValue() + " Lovelace");
247249
}
248250

249251
return poolRewardValidationResult;

validation/src/test/java/org/cardanofoundation/rewards/validation/EpochValidationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public void testCalculateEpochRewardsForEpoch417() {
6767

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

7474
@Test

validation/src/test/java/org/cardanofoundation/rewards/validation/PoolRewardValidationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ void calculateBinancePool59RewardInEpoch413() {
9595
Test_calculatePoolReward(poolId, epoch, DataProviderType.DB_SYNC);
9696
}
9797

98+
@Test
99+
void calculateEVE3PoolRewardInEpoch363() {
100+
String poolId = "pool1kchver88u3kygsak8wgll7htr8uxn5v35lfrsyy842nkscrzyvj";
101+
int epoch = 363;
102+
Test_calculatePoolReward(poolId, epoch, DataProviderType.JSON);
103+
}
104+
98105
@Test
99106
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
100107
void calculateSTKH1PoolRewardInEpoch363() {

0 commit comments

Comments
 (0)