Skip to content

Commit

Permalink
Merge pull request #93 from cardano-foundation/0.9.0
Browse files Browse the repository at this point in the history
0.9.0
  • Loading branch information
fabianbormann authored Feb 29, 2024
2 parents 0bf5827 + a48f096 commit 4185e63
Show file tree
Hide file tree
Showing 84 changed files with 1,451 additions and 1,411 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
run: |
envsubst < ./.m2/settings.default.xml.tpl > ./.m2/settings.xml
- name: Check Formatting
run: |
mvn spotless:check
- name: Build
run: |
mvn --batch-mode --update-snapshots clean package -DskipTests
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ To ensure the stability and reliability of this project, unit and mutation tests
- FLYWAY_VALIDATE: whether to automatically call validate when performing a migration
- KOIOS_BASE_URL_ENABLED: Set `true` to enable to use your Koios instance base URL, otherwise set `false`
- KOIOS_BASE_URL: Koios instance base URL.
- KOIOS_AUTH_TOKEN: JWT Bearer Auth token generated via https://koios.rest Profile page
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ services:
- FETCH_AND_SAVE_POOL_INFO_DATA_DELAY=${FETCH_AND_SAVE_POOL_INFO_DATA_DELAY}
- KOIOS_BASE_URL_ENABLED=${KOIOS_BASE_URL_ENABLED}
- KOIOS_BASE_URL=${KOIOS_BASE_URL}
- KOIOS_AUTH_TOKEN=${KOIOS_AUTH_TOKEN}
ports:
- ${SERVER_PORT}:${SERVER_PORT}
51 changes: 39 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
<version.java>17</version.java>
<version.lombok>1.18.26</version.lombok>
<org.projectlombok.version>1.18.24</org.projectlombok.version>
<koios-java-client.version>1.17.2</koios-java-client.version>
<version.ledgersync-common>0.1.0-SNAPSHOT</version.ledgersync-common>
<version.explorer-common>0.1.1-SNAPSHOT</version.explorer-common>
<version.explorer-consumer-common>0.1.12</version.explorer-consumer-common>
<koios-java-client.version>1.18.1</koios-java-client.version>
<version.explorer-common>0.1.16-SNAPSHOT-PR173</version.explorer-common>
<version.spring-boot>3.0.5</version.spring-boot>
<version.flyway>9.16.0</version.flyway>
<version.maven-compiler-plugin>3.10.0</version.maven-compiler-plugin>
Expand All @@ -25,6 +23,8 @@
<version.maven-site-plugin>4.0.0-M2</version.maven-site-plugin>
<version.maven-project-info-reports-plugin>3.3.0</version.maven-project-info-reports-plugin>
<version.test-containers>1.17.3</version.test-containers>
<version.spotless-maven-plugin>2.36.0</version.spotless-maven-plugin>
<version.google-java-format>1.15.0</version.google-java-format>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -59,16 +59,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.cardanofoundation.ledgersync</groupId>
<artifactId>common</artifactId>
<version>${version.ledgersync-common}</version>
</dependency>

<dependency>
<groupId>org.cardanofoundation.explorer</groupId>
<artifactId>consumer-common</artifactId>
<version>${version.explorer-consumer-common}</version>
<artifactId>common</artifactId>
<version>${version.explorer-common}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -230,6 +224,39 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${version.spotless-maven-plugin}</version>
<configuration>
<java>
<excludes>
<exclude>build/**/*.java</exclude>
</excludes>
<removeUnusedImports/>
<replaceRegex>
<name>Remove wildcard imports</name>
<searchRegex>import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n)</searchRegex>
<replacement>$1</replacement>
</replaceRegex>
<googleJavaFormat>
<version>${version.google-java-format}</version>
<style>GOOGLE</style>
</googleJavaFormat>
<importOrder>
<order>
java,jakarta,javax,lombok,org.springframework,,\\#,org.junit,\\#org.junit,org.cardanofoundation,\\#org.cardanofoundation
</order>
</importOrder>
<indent>
<spaces>true</spaces>
<spacesPerTab>2</spacesPerTab>
</indent>
<trimTrailingWhitespace/>
<endWithNewline/>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.cardanofoundation.explorer.rewards.concurrent;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.cardanofoundation.explorer.rewards.service.AdaPotsFetchingService;

@Component
@FieldDefaults(level = AccessLevel.PRIVATE)
Expand All @@ -22,7 +24,7 @@ public class AdaPostsConcurrentFetching {
final AdaPotsFetchingService adaPotsFetchingService;

public Boolean fetchDataConcurrently(List<Integer> epochs) {
//TODO: validate stake address list
// TODO: validate stake address list
var curTime = System.currentTimeMillis();

List<Integer> epochsNeedFetchData = adaPotsFetchingService.getEpochsNeedFetchData(epochs);
Expand All @@ -36,22 +38,24 @@ public Boolean fetchDataConcurrently(List<Integer> epochs) {
List<CompletableFuture<Boolean>> futures = new ArrayList<>();

for (var epoch : epochsNeedFetchData) {
CompletableFuture<Boolean> future = adaPotsFetchingService.fetchData(epoch)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch ada-posts data}: {}", ex.getMessage());
return Boolean.FALSE;
}
);
CompletableFuture<Boolean> future =
adaPotsFetchingService
.fetchData(epoch)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch ada-posts data}: {}", ex.getMessage());
return Boolean.FALSE;
});
futures.add(future);
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();

boolean result = futures.stream().allMatch(CompletableFuture::join);

log.info("Fetch and save ada-posts record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);
log.info(
"Fetch and save ada-posts record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.cardanofoundation.explorer.rewards.concurrent;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.explorer.consumercommon.entity.Epoch;
import org.cardanofoundation.explorer.rewards.service.EpochFetchingService;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.cardanofoundation.explorer.common.entity.ledgersync.Epoch;
import org.cardanofoundation.explorer.rewards.service.EpochFetchingService;

@Component
@FieldDefaults(level = AccessLevel.PRIVATE)
Expand All @@ -37,23 +39,27 @@ public List<Epoch> fetchDataConcurrently(List<Integer> epochNoList) {
List<CompletableFuture<Epoch>> futures = new ArrayList<>();

for (var epoch : epochsNeedFetchData) {
CompletableFuture<Epoch> future = epochFetchingService.fetchData(epoch)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch epoch data}: {}", ex.getMessage());
return null;
}
);
CompletableFuture<Epoch> future =
epochFetchingService
.fetchData(epoch)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch epoch data}: {}", ex.getMessage());
return null;
});
if (Objects.nonNull(future)) {
futures.add(future);
}
}

List<Epoch> result = futures.stream()
.filter(epoch -> Objects.nonNull(epoch.join()))
.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",
log.info(
"Fetch and save epoch record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService;
import rest.koios.client.backend.api.base.exception.ApiException;

import org.cardanofoundation.explorer.rewards.service.EpochStakeFetchingService;

@Component
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
Expand All @@ -31,7 +32,7 @@ public class EpochStakeConcurrentFetching {
int subListSize;

public Boolean fetchDataConcurrently(List<String> stakeAddressList) {
//TODO: validate stake address list
// TODO: validate stake address list
var curTime = System.currentTimeMillis();

if (stakeAddressList.isEmpty()) {
Expand All @@ -42,10 +43,11 @@ public Boolean fetchDataConcurrently(List<String> stakeAddressList) {
try {
// we only fetch data with addresses that are not in the checkpoint table
// or in the checkpoint table but have an epoch checkpoint value < (current epoch)
stakeAddressListNeedFetchData = epochStakeFetchingService.getStakeAddressListNeedFetchData(
stakeAddressList);
stakeAddressListNeedFetchData =
epochStakeFetchingService.getStakeAddressListNeedFetchData(stakeAddressList);
} catch (ApiException e) {
log.error("Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage());
log.error(
"Exception occurs when calling getStakeAddressListNeedFetchData: {}", e.getMessage());
return Boolean.FALSE;
}

Expand All @@ -62,21 +64,23 @@ public Boolean fetchDataConcurrently(List<String> stakeAddressList) {
int endIndex = Math.min(i + subListSize, stakeAddressListNeedFetchData.size());
var sublist = stakeAddressListNeedFetchData.subList(i, endIndex);

CompletableFuture<Boolean> future = epochStakeFetchingService.fetchData(sublist)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage());
return Boolean.FALSE;
}
);
CompletableFuture<Boolean> future =
epochStakeFetchingService
.fetchData(sublist)
.exceptionally(
ex -> {
log.error("Exception occurred in fetch epoch stake data}: {}", ex.getMessage());
return Boolean.FALSE;
});
futures.add(future);
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();

boolean result = futures.stream().allMatch(CompletableFuture::join);

log.info("Fetch and save epoch stake record concurrently by koios api: {} ms",
log.info(
"Fetch and save epoch stake record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService;
import rest.koios.client.backend.api.base.exception.ApiException;

import org.cardanofoundation.explorer.rewards.service.PoolHistoryFetchingService;

@Component
@FieldDefaults(level = AccessLevel.PRIVATE)
@RequiredArgsConstructor
Expand All @@ -25,7 +26,7 @@ public class PoolHistoryConcurrentFetching {
final PoolHistoryFetchingService poolHistoryFetchingService;

public Boolean fetchDataConcurrently(List<String> poolIds) {
//TODO: validate poolIds
// TODO: validate poolIds
var curTime = System.currentTimeMillis();

if (poolIds.isEmpty()) {
Expand All @@ -36,8 +37,7 @@ public Boolean fetchDataConcurrently(List<String> poolIds) {
try {
// we only fetch data with addresses that are not in the checkpoint table
// or in the checkpoint table but have an epoch checkpoint value < (current epoch - 1)
poolIdListNeedFetchData = poolHistoryFetchingService.getPoolIdListNeedFetchData(
poolIds);
poolIdListNeedFetchData = poolHistoryFetchingService.getPoolIdListNeedFetchData(poolIds);
} catch (ApiException e) {
log.error("Exception occurs when calling getPoolIdListNeedFetchData: {}", e.getMessage());
return Boolean.FALSE;
Expand All @@ -53,22 +53,26 @@ public Boolean fetchDataConcurrently(List<String> poolIds) {
List<CompletableFuture<Boolean>> futures = new ArrayList<>();

for (var poolId : poolIdListNeedFetchData) {
CompletableFuture<Boolean> future = poolHistoryFetchingService.fetchData(poolId)
.exceptionally(
ex -> {
log.error("Exception occurred in fetchData for poolId {}: {}", poolId,
ex.getMessage());
return Boolean.FALSE;
}
);
CompletableFuture<Boolean> future =
poolHistoryFetchingService
.fetchData(poolId)
.exceptionally(
ex -> {
log.error(
"Exception occurred in fetchData for poolId {}: {}",
poolId,
ex.getMessage());
return Boolean.FALSE;
});
futures.add(future);
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();

boolean result = futures.stream().allMatch(CompletableFuture::join);

log.info("Fetch and save pool history record concurrently by koios api: {} ms",
log.info(
"Fetch and save pool history record concurrently by koios api: {} ms",
System.currentTimeMillis() - curTime);

return result;
Expand Down
Loading

0 comments on commit 4185e63

Please sign in to comment.