Skip to content

Commit da1379c

Browse files
committed
feat: removing overhead and unused methods. clean up and refactoring
1 parent 1060673 commit da1379c

File tree

80 files changed

+143
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+143
-971
lines changed

calculation/src/main/java/org/cardanofoundation/rewards/calculation/EpochCalculation.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212

1313
import static org.cardanofoundation.rewards.calculation.PoolRewardsCalculation.calculatePoolRewardInEpoch;
1414
import static org.cardanofoundation.rewards.calculation.constants.RewardConstants.*;
15-
import static org.cardanofoundation.rewards.calculation.constants.RewardConstants.MAINNET_BOOTSTRAP_ADDRESS_AMOUNT;
1615
import static org.cardanofoundation.rewards.calculation.util.BigNumberUtils.*;
17-
import static org.cardanofoundation.rewards.calculation.util.CurrencyConverter.lovelaceToAda;
1816
import lombok.extern.slf4j.Slf4j;
1917

2018
@Slf4j
2119
public class EpochCalculation {
2220

2321
public static EpochCalculationResult calculateEpochRewardPots(final int epoch, final AdaPots adaPotsForPreviousEpoch,
2422
final ProtocolParameters protocolParameters, final Epoch epochInfo,
25-
final List<PoolDeregistration> retiredPools,
23+
final HashSet<String> rewardAddressesOfRetiredPools,
2624
final HashSet<String> deregisteredAccounts,
2725
final List<MirCertificate> mirCertificates,
2826
final List<String> poolsThatProducedBlocksInEpoch,
@@ -83,8 +81,7 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch, f
8381

8482
// The sum of all the refunds attached to unregistered reward accounts are added to the
8583
// treasury (see: Pool Reap Transition, p.53, figure 40, shelley-ledger.pdf)
86-
if (retiredPools.size() > 0) {
87-
List<String> rewardAddressesOfRetiredPools = retiredPools.stream().map(PoolDeregistration::getRewardAddress).toList();
84+
if (rewardAddressesOfRetiredPools.size() > 0) {
8885
List<String> deregisteredOwnerAccounts = deregisteredAccountsOnEpochBoundary.stream()
8986
.filter(rewardAddressesOfRetiredPools::contains).toList();
9087
List<String> ownerAccountsRegisteredInThePast = registeredAccountsUntilNow.stream()
@@ -93,8 +90,7 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch, f
9390
/* Check if the reward address of the retired pool has been unregistered before
9491
or if the reward address has been unregistered after the randomness stabilization window
9592
or if the reward address has not been registered at all */
96-
for (PoolDeregistration retiredPool : retiredPools) {
97-
String rewardAddress = retiredPool.getRewardAddress();
93+
for (String rewardAddress : rewardAddressesOfRetiredPools) {
9894
if (deregisteredOwnerAccounts.contains(rewardAddress) ||
9995
!ownerAccountsRegisteredInThePast.contains(rewardAddress)) {
10096
// If the reward address has been unregistered, the deposit can not be returned
@@ -181,7 +177,7 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch, f
181177
calculatedReserve = calculatedReserve.add(MAINNET_BOOTSTRAP_ADDRESS_AMOUNT);
182178
}
183179

184-
log.debug("Unspendable earned rewards: " + lovelaceToAda(unspendableEarnedRewards.longValue()) + " ADA");
180+
log.debug("Unspendable earned rewards: " + unspendableEarnedRewards.longValue() + " Lovelace");
185181
treasuryForCurrentEpoch = add(treasuryForCurrentEpoch, unspendableEarnedRewards);
186182

187183
TreasuryCalculationResult treasuryCalculationResult = TreasuryCalculationResult.builder()

calculation/src/main/java/org/cardanofoundation/rewards/calculation/PoolRewardsCalculation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static BigInteger calculateMemberReward(BigInteger poolReward, double mar
129129
public static PoolRewardCalculationResult calculatePoolRewardInEpoch(final String poolId, final PoolHistory poolHistoryCurrentEpoch,
130130
final int totalBlocksInEpoch, final ProtocolParameters protocolParameters,
131131
final BigInteger adaInCirculation, final BigInteger activeStakeInEpoch, BigInteger stakePoolRewardsPot,
132-
final BigInteger totalActiveStakeOfOwners, final List<String> poolOwnerStakeAddresses,
132+
final BigInteger totalActiveStakeOfOwners, final HashSet<String> poolOwnerStakeAddresses,
133133
final HashSet<String> deregisteredAccounts, final boolean ignoreLeaderReward,
134134
final HashSet<String> lateDeregisteredAccounts,
135135
final HashSet<String> accountsRegisteredInThePast) {

calculation/src/main/java/org/cardanofoundation/rewards/calculation/TreasuryCalculation.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TreasuryCalculation {
1717

1818
public static TreasuryCalculationResult calculateTreasuryInEpoch(int epoch, ProtocolParameters protocolParameters,
1919
AdaPots adaPotsForPreviousEpoch, Epoch epochInfo,
20-
List<PoolDeregistration> retiredPools,
20+
HashSet<String> rewardAddressesOfRetiredPools,
2121
List<MirCertificate> mirCertificates,
2222
final HashSet<String> deregisteredAccounts,
2323
final HashSet<String> registeredAccountsUntilNow,
@@ -58,14 +58,13 @@ public static TreasuryCalculationResult calculateTreasuryInEpoch(int epoch, Prot
5858
final BigInteger treasuryCut = multiplyAndFloor(totalRewardPot, treasuryGrowthRate);
5959
BigInteger treasuryForCurrentEpoch = treasuryInPreviousEpoch.add(treasuryCut);
6060

61-
if (retiredPools.size() > 0) {
62-
List<String> rewardAddressesOfRetiredPools = retiredPools.stream().map(PoolDeregistration::getRewardAddress).toList();
61+
if (rewardAddressesOfRetiredPools.size() > 0) {
6362
HashSet<String> deregisteredRewardAccounts = deregisteredAccounts.stream()
6463
.filter(rewardAddressesOfRetiredPools::contains).collect(Collectors.toCollection(HashSet::new));
6564
List<String> ownerAccountsRegisteredInThePast = registeredAccountsUntilNow.stream()
6665
.filter(rewardAddressesOfRetiredPools::contains).toList();
6766

68-
BigInteger unclaimedRefunds = calculateUnclaimedRefundsForRetiredPools(retiredPools, deregisteredRewardAccounts, ownerAccountsRegisteredInThePast);
67+
BigInteger unclaimedRefunds = calculateUnclaimedRefundsForRetiredPools(rewardAddressesOfRetiredPools, deregisteredRewardAccounts, ownerAccountsRegisteredInThePast);
6968
treasuryForCurrentEpoch = treasuryForCurrentEpoch.add(unclaimedRefunds);
7069
}
7170

@@ -138,16 +137,15 @@ private static BigDecimal calculateEta(int totalBlocksInEpochByPools, BigDecimal
138137
pool's registered reward account, provided the reward account is still registered." -
139138
https://github.com/input-output-hk/cardano-ledger/blob/9e2f8151e3b9a0dde9faeb29a7dd2456e854427c/eras/shelley/formal-spec/epoch.tex#L546C9-L547C87
140139
*/
141-
public static BigInteger calculateUnclaimedRefundsForRetiredPools(List<PoolDeregistration> retiredPools,
140+
public static BigInteger calculateUnclaimedRefundsForRetiredPools(HashSet<String> rewardAddressesOfRetiredPools,
142141
HashSet<String> deregisteredRewardAccounts,
143142
List<String> ownerAccountsRegisteredInThePast) {
144143
BigInteger unclaimedRefunds = BigInteger.ZERO;
145-
if (retiredPools.size() > 0) {
144+
if (rewardAddressesOfRetiredPools.size() > 0) {
146145
/* Check if the reward address of the retired pool has been unregistered before
147146
or if the reward address has been unregistered after the randomness stabilization window
148147
or if the reward address has not been registered at all */
149-
for (PoolDeregistration retiredPool : retiredPools) {
150-
String rewardAddress = retiredPool.getRewardAddress();
148+
for (String rewardAddress : rewardAddressesOfRetiredPools) {
151149
if (deregisteredRewardAccounts.contains(rewardAddress) ||
152150
!ownerAccountsRegisteredInThePast.contains(rewardAddress)) {
153151
// If the reward address has been unregistered, the deposit can not be returned

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/AccountUpdate.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/Epoch.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@
1212
@AllArgsConstructor
1313
public class Epoch {
1414
private int number;
15-
private BigInteger output;
1615
private BigInteger fees;
1716
private int blockCount;
1817
private BigInteger activeStake;
19-
private List<String> poolsMadeBlocks;
2018
private int nonOBFTBlockCount;
21-
private int OBFTBlockCount;
22-
private long unixTimeFirstBlock;
23-
private long unixTimeLastBlock;
2419
}

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/MirCertificate.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
@NoArgsConstructor
1212
@AllArgsConstructor
1313
public class MirCertificate {
14-
private long blockTime;
1514
private MirPot pot;
16-
private int totalStakeKeys;
1715
private BigInteger totalRewards;
1816
}

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/PoolDeregistration.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/PoolHistory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
public class PoolHistory {
1515
private String poolId;
1616
private BigInteger activeStake;
17-
private BigInteger delegatorRewards;
1817
private String rewardAddress;
19-
private List<String> owners;
18+
private HashSet<String> owners;
2019
private BigInteger ownerActiveStake;
2120
private BigInteger poolFees;
2221
private Double margin;

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/PoolOwnerHistory.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/PoolParameters.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)