Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MET-1629 missing rewards for epoch #76

Merged
4 commits merged into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
permissions:
contents: read
packages: write
runs-on: self-hosted
runs-on: ubuntu-latest
if: |
"contains(github.event.head_commit.message, 'release-please--branches--main')" ||
${{ github.event_name == 'pull_request' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:

jobs:
create_release:
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- name: 🚀 release-please-action
uses: google-github-actions/release-please-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
test:
runs-on: self-hosted
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public List<Epoch> fetchDataConcurrently(List<Integer> epochNoList) {
}
}

List<Epoch> result = futures.stream().map(CompletableFuture::join).toList();
List<Epoch> result = futures.stream()
.filter(epoch -> Objects.nonNull(epoch.join()))
.map(CompletableFuture::join).toList();

log.info("Fetch and save epoch record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Epoch;
import org.cardanofoundation.explorer.consumercommon.enumeration.EraType;
import org.cardanofoundation.explorer.rewards.config.KoiosClient;
import org.cardanofoundation.explorer.rewards.repository.EpochRepository;
import org.cardanofoundation.explorer.rewards.service.EpochFetchingService;
Expand Down Expand Up @@ -36,14 +37,17 @@ public class EpochFetchingServiceImpl implements EpochFetchingService {
@SneakyThrows
public CompletableFuture<Epoch> fetchData(Integer epochNo) {
Epoch epoch = epochRepository.findByNo(epochNo).orElse(null);
if(Objects.isNull(epoch)) {
return null;
}
if(Objects.nonNull(epoch.getRewardsDistributed())) {
if(Objects.isNull(epoch)
|| Objects.nonNull(epoch.getRewardsDistributed())
|| epoch.getEra().equals(EraType.BYRON)
|| epoch.getEra().equals(EraType.BYRON_EBB)) {
return null;
}
String totalRewards = koiosClient.epochService().getEpochInformationByEpoch(epochNo).getValue().getTotalRewards();
BigInteger rewardDistributed = StringUtils.isEmpty(totalRewards) ? BigInteger.ZERO : new BigInteger(totalRewards);
if (StringUtils.isEmpty(totalRewards)) {
return CompletableFuture.completedFuture(epoch);
}
BigInteger rewardDistributed = new BigInteger(totalRewards);
epochRepository.updateRewardDistributedByNo(rewardDistributed, epochNo);
epoch.setRewardsDistributed(rewardDistributed);
return CompletableFuture.completedFuture(epoch);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE epoch SET rewards_distributed = NULL WHERE rewards_distributed IS NOT NULL;

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cardanofoundation.explorer.rewards.service.impl;

import org.cardanofoundation.explorer.consumercommon.entity.Epoch;
import org.cardanofoundation.explorer.consumercommon.enumeration.EraType;
import org.cardanofoundation.explorer.rewards.config.KoiosClient;
import org.cardanofoundation.explorer.rewards.repository.EpochRepository;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -35,6 +36,28 @@ class EpochFetchingServiceImplTest {
@InjectMocks
private EpochFetchingServiceImpl epochFetchingService;

@Test
void testFetchDataWithByronBlock() {
// Setup
Integer epoch = 315;

var epochInfo = new EpochInfo();
epochInfo.setEpochNo(epoch);
epochInfo.setTotalRewards("577641621267691");

when(epochRepository.findByNo(any()))
.thenReturn(Optional
.ofNullable(Epoch
.builder()
.no(epoch)
.era(EraType.BYRON)
.build()));

// Run the test
final CompletableFuture<Epoch> result = epochFetchingService.fetchData(epoch);
assertNull(result);
}

@Test
void testFetchData() throws Exception {
// Setup
Expand All @@ -49,6 +72,7 @@ void testFetchData() throws Exception {
.ofNullable(Epoch
.builder()
.no(epoch)
.era(EraType.SHELLEY)
.build()));
when(koiosClient.epochService().getEpochInformationByEpoch(epoch)
.getValue()).thenReturn(epochInfo);
Expand All @@ -57,7 +81,7 @@ void testFetchData() throws Exception {
// Run the test
final CompletableFuture<Epoch> result = epochFetchingService.fetchData(epoch);

assertEquals(result.get().getNo(), 315);
assertEquals(315, result.get().getNo());
assertEquals(result.get().getRewardsDistributed(), new BigInteger("577641621267691"));
}

Expand Down
Loading