Skip to content

Commit

Permalink
fix: add a workaround to fix an issue with the block count in dbsync …
Browse files Browse the repository at this point in the history
…epoch table
  • Loading branch information
fabianbormann committed Mar 2, 2024
1 parent 0d1e456 commit 5603d5f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4
if: github.ref == 'refs/heads/main'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
branch: gh-pages
folder: validation/build/reports/jacoco/test/html/badges
target-folder: badges/
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RewardConstants {
public static final int GENESIS_CONFIG_SECURITY_PARAMETER = 2160;
public static final int MAINNET_SHELLEY_START_EPOCH = 208;
public static final int MAINNET_ALLEGRA_HARDFORK_EPOCH = 236;
public static final int MAINNET_VASIL_HARDFORK_EPOCH = 350;
public static final int MAINNET_VASIL_HARDFORK_EPOCH = 365;
public static final BigInteger MAINNET_BOOTSTRAP_ADDRESS_AMOUNT = new BigInteger("318200635000000");
public static final double ACTIVE_SLOT_COEFFICIENT = 0.05;
public static final long RANDOMNESS_STABILISATION_WINDOW = Math.round(
Expand Down
2 changes: 1 addition & 1 deletion report/treasury_calculation_result.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public Epoch getEpochInfo(int epoch) {
}

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

if (epoch < 211) {
epochInfo.setOBFTBlockCount(epochInfo.getBlockCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ select count(*) from DbSyncBlock AS block
""")
Integer getOBFTBlocksInEpoch(@Param("epoch") Integer epoch);

Integer countByEpochNo(Integer epochNo);

@Query("""
select distinct block.slotLeader.pool.bech32PoolId from DbSyncBlock AS block
where block.epochNo = :epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ public void testCalculateEpochRewardsWithDbSyncDataProvider(int epoch) {
@ParameterizedTest
@MethodSource("dataProviderEpochRange")
public void testCalculateEpochRewardsWithJsonDataProvider(int epoch) {
testCalculateEpochPots(epoch, jsonDataProvider, false);
testCalculateEpochPots(epoch, jsonDataProvider, true);
}

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

@Test
@EnabledIf(expression = "#{environment.acceptsProfiles('db-sync')}", loadContext = true, reason = "DB Sync data provider must be available for this test")
public void testCalculateEpochRewardsForEpoch384() {
testCalculateEpochPots(384, jsonDataProvider, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package org.cardanofoundation.rewards.validation.data.provider;

import org.cardanofoundation.rewards.calculation.domain.*;
import org.cardanofoundation.rewards.validation.PoolRewardValidation;
import org.cardanofoundation.rewards.validation.TreasuryValidation;
import org.cardanofoundation.rewards.calculation.enums.MirPot;
import org.cardanofoundation.rewards.validation.data.provider.DbSyncDataProvider;
import org.cardanofoundation.rewards.validation.domain.TreasuryValidationResult;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.junit.jupiter.EnabledIf;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static org.cardanofoundation.rewards.calculation.util.CurrencyConverter.lovelaceToAda;

@SpringBootTest
@ComponentScan
Expand Down Expand Up @@ -61,10 +51,10 @@ public void testGetAdaPots() {
@Test
public void testGetProtocolParameters() {
ProtocolParameters protocolParameters = dbSyncDataProvider.getProtocolParametersForEpoch(220);
Assertions.assertEquals(protocolParameters.getDecentralisation(), 0.64);
Assertions.assertEquals(protocolParameters.getTreasuryGrowRate(), 0.2);
Assertions.assertEquals(protocolParameters.getMonetaryExpandRate(), 0.003);
Assertions.assertEquals(protocolParameters.getPoolOwnerInfluence(), 0.3);
Assertions.assertEquals(protocolParameters.getDecentralisation(), BigDecimal.valueOf(0.64));
Assertions.assertEquals(protocolParameters.getTreasuryGrowRate(), BigDecimal.valueOf(0.2));
Assertions.assertEquals(protocolParameters.getMonetaryExpandRate(), BigDecimal.valueOf(0.003));
Assertions.assertEquals(protocolParameters.getPoolOwnerInfluence(), BigDecimal.valueOf(0.3));
Assertions.assertEquals(protocolParameters.getOptimalPoolCount(), 150);
}

Expand All @@ -75,7 +65,7 @@ public void testGetPoolHistory() {
PoolHistory poolHistory = dbSyncDataProvider.getPoolHistory(poolId, epoch);
Assertions.assertEquals(poolHistory.getActiveStake(), new BigInteger("27523186299296"));
Assertions.assertEquals(poolHistory.getBlockCount(), 10);
Assertions.assertEquals(poolHistory.getFixedCost(), 340000000.0);
Assertions.assertEquals(poolHistory.getFixedCost(), new BigInteger("340000000"));
Assertions.assertEquals(poolHistory.getMargin(), 0.009);
Assertions.assertEquals(poolHistory.getDelegatorRewards(), new BigInteger("14877804008"));
Assertions.assertEquals(poolHistory.getPoolFees(), new BigInteger("475116283"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.cardanofoundation.rewards.calculation.domain.AdaPots;
import org.cardanofoundation.rewards.calculation.domain.ProtocolParameters;
import org.cardanofoundation.rewards.validation.data.provider.JsonDataProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cardanofoundation.rewards.validation.data.provider;

import org.cardanofoundation.rewards.calculation.domain.Epoch;
import org.cardanofoundation.rewards.validation.data.provider.KoiosDataProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down

0 comments on commit 5603d5f

Please sign in to comment.