Skip to content

Commit a4efa3e

Browse files
Merge pull request #31 from cardano-foundation/fix/large_treasury_outliers
fix: add a workaround to fix an issue with the block count in dbsync …
2 parents d1b9725 + 5603d5f commit a4efa3e

File tree

9 files changed

+23
-24
lines changed

9 files changed

+23
-24
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ jobs:
7171
uses: JamesIves/github-pages-deploy-action@v4
7272
if: github.ref == 'refs/heads/main'
7373
with:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
BRANCH: gh-pages
74+
branch: gh-pages
7675
folder: validation/build/reports/jacoco/test/html/badges
7776
target-folder: badges/

calculation/src/main/java/org/cardanofoundation/rewards/calculation/constants/RewardConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class RewardConstants {
1414
public static final int GENESIS_CONFIG_SECURITY_PARAMETER = 2160;
1515
public static final int MAINNET_SHELLEY_START_EPOCH = 208;
1616
public static final int MAINNET_ALLEGRA_HARDFORK_EPOCH = 236;
17-
public static final int MAINNET_VASIL_HARDFORK_EPOCH = 350;
17+
public static final int MAINNET_VASIL_HARDFORK_EPOCH = 365;
1818
public static final BigInteger MAINNET_BOOTSTRAP_ADDRESS_AMOUNT = new BigInteger("318200635000000");
1919
public static final double ACTIVE_SLOT_COEFFICIENT = 0.05;
2020
public static final long RANDOMNESS_STABILISATION_WINDOW = Math.round(

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/data/provider/DbSyncDataProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public Epoch getEpochInfo(int epoch) {
7575
}
7676

7777
DbSyncEpoch dbSyncEpoch = dbSyncEpochRepository.findByNumber(epoch);
78+
// We need to fetch the block count separately from the epoch
79+
// because of https://github.com/IntersectMBO/cardano-db-sync/issues/1457
80+
Integer blockCount = dbSyncBlockRepository.countByEpochNo(epoch);
7881
Epoch epochInfo = EpochMapper.fromDbSyncEpoch(dbSyncEpoch);
82+
epochInfo.setBlockCount(blockCount);
7983

8084
if (epoch < 211) {
8185
epochInfo.setOBFTBlockCount(epochInfo.getBlockCount());

validation/src/main/java/org/cardanofoundation/rewards/validation/repository/DbSyncBlockRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ select count(*) from DbSyncBlock AS block
4444
""")
4545
Integer getOBFTBlocksInEpoch(@Param("epoch") Integer epoch);
4646

47+
Integer countByEpochNo(Integer epochNo);
48+
4749
@Query("""
4850
select distinct block.slotLeader.pool.bech32PoolId from DbSyncBlock AS block
4951
where block.epochNo = :epoch

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ public void testCalculateEpochRewardsWithDbSyncDataProvider(int epoch) {
5656
@ParameterizedTest
5757
@MethodSource("dataProviderEpochRange")
5858
public void testCalculateEpochRewardsWithJsonDataProvider(int epoch) {
59-
testCalculateEpochPots(epoch, jsonDataProvider, false);
59+
testCalculateEpochPots(epoch, jsonDataProvider, true);
6060
}
6161

6262
@Test
6363
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
6464
public void testCalculateEpochRewardsForEpoch385() {
65-
testCalculateEpochPots(385, dbSyncDataProvider, true);
65+
testCalculateEpochPots(385, dbSyncDataProvider, false);
66+
}
67+
68+
@Test
69+
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
70+
public void testCalculateEpochRewardsForEpoch384() {
71+
testCalculateEpochPots(384, jsonDataProvider, false);
6672
}
6773
}

validation/src/test/java/org/cardanofoundation/rewards/validation/data/provider/DbSyncDataProviderTest.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
package org.cardanofoundation.rewards.validation.data.provider;
22

33
import org.cardanofoundation.rewards.calculation.domain.*;
4-
import org.cardanofoundation.rewards.validation.PoolRewardValidation;
5-
import org.cardanofoundation.rewards.validation.TreasuryValidation;
64
import org.cardanofoundation.rewards.calculation.enums.MirPot;
7-
import org.cardanofoundation.rewards.validation.data.provider.DbSyncDataProvider;
8-
import org.cardanofoundation.rewards.validation.domain.TreasuryValidationResult;
95
import org.junit.jupiter.api.Assertions;
106
import org.junit.jupiter.api.Test;
11-
import org.junit.jupiter.params.ParameterizedTest;
12-
import org.junit.jupiter.params.provider.MethodSource;
137
import org.springframework.beans.factory.annotation.Autowired;
148
import org.springframework.boot.test.context.SpringBootTest;
159
import org.springframework.context.annotation.ComponentScan;
1610
import org.springframework.test.context.junit.jupiter.EnabledIf;
17-
11+
import java.math.BigDecimal;
1812
import java.math.BigInteger;
1913
import java.util.List;
20-
import java.util.stream.IntStream;
21-
import java.util.stream.Stream;
22-
23-
import static org.cardanofoundation.rewards.calculation.util.CurrencyConverter.lovelaceToAda;
2414

2515
@SpringBootTest
2616
@ComponentScan
@@ -61,10 +51,10 @@ public void testGetAdaPots() {
6151
@Test
6252
public void testGetProtocolParameters() {
6353
ProtocolParameters protocolParameters = dbSyncDataProvider.getProtocolParametersForEpoch(220);
64-
Assertions.assertEquals(protocolParameters.getDecentralisation(), 0.64);
65-
Assertions.assertEquals(protocolParameters.getTreasuryGrowRate(), 0.2);
66-
Assertions.assertEquals(protocolParameters.getMonetaryExpandRate(), 0.003);
67-
Assertions.assertEquals(protocolParameters.getPoolOwnerInfluence(), 0.3);
54+
Assertions.assertEquals(protocolParameters.getDecentralisation(), BigDecimal.valueOf(0.64));
55+
Assertions.assertEquals(protocolParameters.getTreasuryGrowRate(), BigDecimal.valueOf(0.2));
56+
Assertions.assertEquals(protocolParameters.getMonetaryExpandRate(), BigDecimal.valueOf(0.003));
57+
Assertions.assertEquals(protocolParameters.getPoolOwnerInfluence(), BigDecimal.valueOf(0.3));
6858
Assertions.assertEquals(protocolParameters.getOptimalPoolCount(), 150);
6959
}
7060

@@ -75,7 +65,7 @@ public void testGetPoolHistory() {
7565
PoolHistory poolHistory = dbSyncDataProvider.getPoolHistory(poolId, epoch);
7666
Assertions.assertEquals(poolHistory.getActiveStake(), new BigInteger("27523186299296"));
7767
Assertions.assertEquals(poolHistory.getBlockCount(), 10);
78-
Assertions.assertEquals(poolHistory.getFixedCost(), 340000000.0);
68+
Assertions.assertEquals(poolHistory.getFixedCost(), new BigInteger("340000000"));
7969
Assertions.assertEquals(poolHistory.getMargin(), 0.009);
8070
Assertions.assertEquals(poolHistory.getDelegatorRewards(), new BigInteger("14877804008"));
8171
Assertions.assertEquals(poolHistory.getPoolFees(), new BigInteger("475116283"));

validation/src/test/java/org/cardanofoundation/rewards/validation/data/provider/JsonDataProviderTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.cardanofoundation.rewards.calculation.domain.AdaPots;
44
import org.cardanofoundation.rewards.calculation.domain.ProtocolParameters;
5-
import org.cardanofoundation.rewards.validation.data.provider.JsonDataProvider;
65
import org.junit.jupiter.api.Assertions;
76
import org.junit.jupiter.api.Test;
87
import org.springframework.beans.factory.annotation.Autowired;

validation/src/test/java/org/cardanofoundation/rewards/validation/data/provider/KoiosDataProviderTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.cardanofoundation.rewards.validation.data.provider;
22

33
import org.cardanofoundation.rewards.calculation.domain.Epoch;
4-
import org.cardanofoundation.rewards.validation.data.provider.KoiosDataProvider;
54
import org.junit.jupiter.api.Assertions;
65
import org.junit.jupiter.api.Test;
76
import org.springframework.beans.factory.annotation.Autowired;

0 commit comments

Comments
 (0)