Split up calculateShare into 4 distinct methods

Reduce visibility to package scope

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2022-11-06 15:43:50 -05:00
parent 3fda949526
commit ec25722d08
No known key found for this signature in database
GPG key ID: 02AA2BAE387C8307
5 changed files with 49 additions and 40 deletions

View file

@ -32,7 +32,7 @@ public final class BurnOutputModel {
private final long date; private final long date;
private final int cycleIndex; private final int cycleIndex;
public BurnOutputModel(long amount, BurnOutputModel(long amount,
long decayedAmount, long decayedAmount,
int height, int height,
String txId, String txId,

View file

@ -42,8 +42,9 @@ public final class BurningManCandidate {
private double effectiveBurnOutputShare; // limited to boostedIssuanceShare private double effectiveBurnOutputShare; // limited to boostedIssuanceShare
private final List<CompensationModel> compensationModels = new ArrayList<>(); private final List<CompensationModel> compensationModels = new ArrayList<>();
private final List<BurnOutputModel> burnOutputModels = new ArrayList<>(); private final List<BurnOutputModel> burnOutputModels = new ArrayList<>();
private Optional<String> mostRecentAddress = Optional.empty();
public BurningManCandidate() { BurningManCandidate() {
} }
public void addBurnOutputModel(BurnOutputModel burnOutputModel) { public void addBurnOutputModel(BurnOutputModel burnOutputModel) {
@ -70,18 +71,27 @@ public final class BurningManCandidate {
accumulatedDecayedCompensationAmount += compensationModel.getDecayedAmount(); accumulatedDecayedCompensationAmount += compensationModel.getDecayedAmount();
accumulatedCompensationAmount += compensationModel.getAmount(); accumulatedCompensationAmount += compensationModel.getAmount();
mostRecentAddress = compensationModels.stream()
.max(Comparator.comparing(CompensationModel::getHeight))
.map(CompensationModel::getAddress);
} }
public void calculateShare(double totalIssuanceWeight, public void calculateIssuanceShare(double totalIssuanceWeight) {
double totalBurnOutputWeight,
long burnTarget,
long averageDistributionPerCycle) {
issuanceShare = totalIssuanceWeight > 0 ? accumulatedDecayedCompensationAmount / totalIssuanceWeight : 0; issuanceShare = totalIssuanceWeight > 0 ? accumulatedDecayedCompensationAmount / totalIssuanceWeight : 0;
boostedIssuanceShare = issuanceShare * BurningManService.ISSUANCE_BOOST_FACTOR; boostedIssuanceShare = issuanceShare * BurningManService.ISSUANCE_BOOST_FACTOR;
}
public void calculateBurnOutputShare(double totalBurnOutputWeight) {
burnOutputShare = totalBurnOutputWeight > 0 ? accumulatedDecayedBurnAmount / totalBurnOutputWeight : 0; burnOutputShare = totalBurnOutputWeight > 0 ? accumulatedDecayedBurnAmount / totalBurnOutputWeight : 0;
effectiveBurnOutputShare = Math.min(boostedIssuanceShare, burnOutputShare); effectiveBurnOutputShare = Math.min(boostedIssuanceShare, burnOutputShare);
}
public void calculateExpectedRevenue(long averageDistributionPerCycle) {
expectedRevenue = Math.round(effectiveBurnOutputShare * averageDistributionPerCycle);
}
public void calculateAllowedBurnAmount(long burnTarget) {
double maxBurnAmount = burnTarget + BurningManService.BURN_TARGET_BOOST_AMOUNT; double maxBurnAmount = burnTarget + BurningManService.BURN_TARGET_BOOST_AMOUNT;
if (issuanceShare > 0 && maxBurnAmount > 0 && effectiveBurnOutputShare < boostedIssuanceShare) { if (issuanceShare > 0 && maxBurnAmount > 0 && effectiveBurnOutputShare < boostedIssuanceShare) {
// We reduce it with what he had already burned // We reduce it with what he had already burned
@ -91,14 +101,6 @@ public final class BurningManCandidate {
} else { } else {
allowedBurnAmount = 0; allowedBurnAmount = 0;
} }
expectedRevenue = Math.round(averageDistributionPerCycle * effectiveBurnOutputShare);
}
public Optional<String> getMostRecentAddress() {
return compensationModels.stream()
.max(Comparator.comparing(CompensationModel::getHeight))
.map(CompensationModel::getAddress);
} }
@Override @Override

View file

@ -184,10 +184,17 @@ class BurningManService {
double totalDecayedBurnAmounts = burningManCandidates.stream() double totalDecayedBurnAmounts = burningManCandidates.stream()
.mapToDouble(BurningManCandidate::getAccumulatedDecayedBurnAmount) .mapToDouble(BurningManCandidate::getAccumulatedDecayedBurnAmount)
.sum(); .sum();
long averageDistributionPerCycle = getAverageDistributionPerCycle(chainHeight);
long burnTarget = getBurnTarget(chainHeight, burningManCandidates); long burnTarget = getBurnTarget(chainHeight, burningManCandidates);
burningManCandidates.forEach(candidate -> burningManCandidates.forEach(candidate -> {
candidate.calculateShare(totalDecayedCompensationAmounts, totalDecayedBurnAmounts, burnTarget, getAverageDistributionPerCycle(chainHeight))); candidate.calculateIssuanceShare(totalDecayedCompensationAmounts);
candidate.calculateBurnOutputShare(totalDecayedBurnAmounts);
candidate.calculateExpectedRevenue(averageDistributionPerCycle);
candidate.calculateAllowedBurnAmount(burnTarget);
}
);
return burningManCandidatesByName; return burningManCandidatesByName;
} }

View file

@ -26,7 +26,7 @@ import lombok.Getter;
@Getter @Getter
@EqualsAndHashCode @EqualsAndHashCode
public final class CompensationModel { public final class CompensationModel {
public static CompensationModel fromCompensationRequest(String address, static CompensationModel fromCompensationRequest(String address,
long amount, long amount,
long decayedAmount, long decayedAmount,
int height, int height,
@ -43,7 +43,7 @@ public final class CompensationModel {
cycleIndex); cycleIndex);
} }
public static CompensationModel fromGenesisOutput(String address, static CompensationModel fromGenesisOutput(String address,
long amount, long amount,
long decayedAmount, long decayedAmount,
int height, int height,

View file

@ -30,7 +30,7 @@ public final class ReimbursementModel {
private final long date; private final long date;
private final int cycleIndex; private final int cycleIndex;
public ReimbursementModel(long amount, ReimbursementModel(long amount,
int height, int height,
long date, long date,
int cycleIndex) { int cycleIndex) {