Skip to content

Commit d1bad47

Browse files
Merge pull request #42 from cardano-foundation/fix/resolve_offset_in_epoch_365
Fix/resolve offset in epoch 365
2 parents e3d0caf + fa9621d commit d1bad47

File tree

10 files changed

+97
-80
lines changed

10 files changed

+97
-80
lines changed

.github/workflows/publish.yaml

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
name: 📊 Generate Report and 📦 Publish to Maven Central
1+
name: 📦 Publish to Maven Central
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
84
workflow_dispatch:
95

106
jobs:
117
publish-to-maven-central:
128
runs-on: ubuntu-latest
13-
if: "github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'release-please--branches--main')"
9+
if: "github.event_name == 'workflow_dispatch'"
1410
steps:
1511
- name: ⬇️ Checkout repository
1612
uses: actions/checkout@v3
@@ -32,57 +28,3 @@ jobs:
3228
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_OSSRH_USERNAME }}
3329
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_OSSRH_TOKEN }}
3430
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
35-
create-report:
36-
runs-on: ubuntu-latest
37-
if: "github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'release-please--branches--main')"
38-
steps:
39-
- name: ⬇️ Checkout repository
40-
uses: actions/checkout@v3
41-
42-
- name: Setup JDK 18
43-
uses: actions/setup-java@v3
44-
with:
45-
java-version: '18'
46-
distribution: 'temurin'
47-
cache: maven
48-
49-
- name: Setup dependencies
50-
run: |
51-
pip install yq
52-
53-
- name: JSON result to js file
54-
run: |
55-
echo -e "const treasuryCalculationResult = $(cat ./report/treasury_calculation_result.json)" > ./report/treasury_calculation_result.js
56-
57-
- name: 👀 Lookup metadata for report
58-
run: |
59-
echo "VERSION=$(xq -r .project.version pom.xml)" >> $GITHUB_ENV
60-
echo "LATEST_COMMIT_HASH=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_ENV
61-
echo "LATEST_COMMIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV
62-
echo "UTC_DATE=$(date -uR|sed 's/.....$//')" >> $GITHUB_ENV
63-
64-
- name: 📂 Create report directory
65-
run: |
66-
mkdir -p report-v${{ env.VERSION }}
67-
68-
- name: 📄 Copy report files
69-
run: |
70-
cp -r report/* report-v${{ env.VERSION }}
71-
72-
- name: 📝 Add metadata to the report
73-
run: |
74-
sed -i 's|<footer></footer>|<footer><p>Created on ${{ env.UTC_DATE }} UTC as a result of modifications triggered by <a href="https://github.com/cardano-foundation/cf-java-rewards-calculation/commit/${{ env.LATEST_COMMIT_HASH }}">${{ env.LATEST_COMMIT_HASH_SHORT }}</a></p></footer>|' report-v${{ env.VERSION }}/treasury_calculation.html
75-
76-
- name: 📅 Publish report to gh-pages
77-
uses: JamesIves/github-pages-deploy-action@v4
78-
with:
79-
BRANCH: gh-pages
80-
folder: report-v${{ env.VERSION }}
81-
target-folder: report-latest/
82-
83-
- name: 📅 Publish report to gh-pages
84-
uses: JamesIves/github-pages-deploy-action@v4
85-
with:
86-
BRANCH: gh-pages
87-
folder: report-v${{ env.VERSION }}
88-
target-folder: report-v${{ env.VERSION }}/

.github/workflows/report.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 📊 Generate Report
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
workflow_dispatch:
9+
10+
jobs:
11+
create-report:
12+
runs-on: ubuntu-latest
13+
if: "github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'release-please--branches--main')"
14+
steps:
15+
- name: ⬇️ Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Setup JDK 18
19+
uses: actions/setup-java@v3
20+
with:
21+
java-version: '18'
22+
distribution: 'temurin'
23+
cache: maven
24+
25+
- name: Setup dependencies
26+
run: |
27+
pip install yq
28+
29+
- name: JSON result to js file
30+
run: |
31+
echo -e "const treasuryCalculationResult = $(cat ./report/treasury_calculation_result.json)" > ./report/treasury_calculation_result.js
32+
33+
- name: 👀 Lookup metadata for report
34+
run: |
35+
echo "VERSION=$(xq -r .project.version pom.xml)" >> $GITHUB_ENV
36+
echo "LATEST_COMMIT_HASH=$(git rev-parse "$GITHUB_SHA")" >> $GITHUB_ENV
37+
echo "LATEST_COMMIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV
38+
echo "UTC_DATE=$(date -uR|sed 's/.....$//')" >> $GITHUB_ENV
39+
40+
- name: 📂 Create report directory
41+
run: |
42+
mkdir -p report-v${{ env.VERSION }}
43+
44+
- name: 📄 Copy report files
45+
run: |
46+
cp -r report/* report-v${{ env.VERSION }}
47+
48+
- name: 📝 Add metadata to the report
49+
run: |
50+
sed -i 's|<footer></footer>|<footer><p>Created on ${{ env.UTC_DATE }} UTC as a result of modifications triggered by <a href="https://github.com/cardano-foundation/cf-java-rewards-calculation/commit/${{ env.LATEST_COMMIT_HASH }}">${{ env.LATEST_COMMIT_HASH_SHORT }}</a></p></footer>|' report-v${{ env.VERSION }}/treasury_calculation.html
51+
52+
- name: 📅 Publish report to gh-pages
53+
uses: JamesIves/github-pages-deploy-action@v4
54+
with:
55+
BRANCH: gh-pages
56+
folder: report-v${{ env.VERSION }}
57+
target-folder: report-latest/
58+
59+
- name: 📅 Publish report to gh-pages
60+
uses: JamesIves/github-pages-deploy-action@v4
61+
with:
62+
BRANCH: gh-pages
63+
folder: report-v${{ env.VERSION }}
64+
target-folder: report-v${{ env.VERSION }}/

report/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ window.onload = () => {
198198
const highestDifferenceEpoch = relativeDifference.x[relativeDifference.y.indexOf(highestDifference)];
199199
fillCard('highest-difference-percentage', 'Highest relative difference', `${highestDifference}%`, `Epoch ${highestDifferenceEpoch}`);
200200

201-
const highestAbsolutDifference = Math.max(...difference.y);
201+
const highestAbsolutDifference = difference.y.reduce((a, b) => Math.abs(a) > Math.abs(b) ? a : b);
202202
const highestAbsolutDifferenceEpoch = difference.x[difference.y.indexOf(highestAbsolutDifference)];
203203
fillCard('highest-absolut-difference', 'Highest absolut difference', `${highestAbsolutDifference.toLocaleString()}₳`, `Epoch ${highestAbsolutDifferenceEpoch}`);
204204

205-
const averageDifferenceMedian = relativeDifference.y.sort((a, b) => a - b)[Math.round(relativeDifference.y.length / 2)];
206-
fillCard('average-difference-percentage', 'Average relative difference', `${averageDifferenceMedian}%`, 'Median');
205+
const totalAbsoluteDifference = difference.y.reduce((a, b) => Math.abs(a) + Math.abs(b), 0);
206+
fillCard('total-absolute-difference', 'Total absolute difference', `${totalAbsoluteDifference}`, 'Sum of all differences');
207207

208208
const averageAbsolutDifferenceMedian = difference.y.sort((a, b) => a - b)[Math.round(difference.y.length / 2)]
209209
fillCard('average-absolut-difference', 'Average absolut difference', `${averageAbsolutDifferenceMedian.toLocaleString()}₳`, 'Median');

report/treasury_calculation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ <h2>Treasury Calculation Report</h2>
115115
<h4 id="epoch-info"></h4>
116116
<div class="cards">
117117
<div class="card" id="highest-difference-percentage"></div>
118-
<div class="card" id="average-difference-percentage"></div>
118+
<div class="card" id="total-absolute-difference"></div>
119119
<div class="card" id="highest-absolut-difference"></div>
120120
<div class="card" id="average-absolut-difference"></div>
121121
<div class="card" id="exact-matches"></div>

report/treasury_calculation_result.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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/main/java/org/cardanofoundation/rewards/validation/data/fetcher/DbSyncDataFetcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ private void fetchSharedPoolRewardAddressWithoutReward(int epoch, boolean overri
321321
}
322322

323323
private void fetchLateAccountDeregistrationsInEpoch(int epoch, boolean override, boolean mainnet) {
324-
if (mainnet && epoch >= MAINNET_VASIL_HARDFORK_EPOCH) {
324+
int earnedEpoch = epoch - 2;
325+
if (mainnet && earnedEpoch > MAINNET_VASIL_HARDFORK_EPOCH) {
325326
return;
326327
}
327328

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 testCalculateEpochRewardsForEpoch367() {
71+
testCalculateEpochPots(365, jsonDataProvider, false);
7272
}
7373

7474
@Test

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

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

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

0 commit comments

Comments
 (0)