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,12 +32,12 @@ public final class BurnOutputModel {
private final long date;
private final int cycleIndex;
public BurnOutputModel(long amount,
long decayedAmount,
int height,
String txId,
long date,
int cycleIndex) {
BurnOutputModel(long amount,
long decayedAmount,
int height,
String txId,
long date,
int cycleIndex) {
this.amount = amount;
this.decayedAmount = decayedAmount;

View file

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

View file

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

View file

@ -26,13 +26,13 @@ import lombok.Getter;
@Getter
@EqualsAndHashCode
public final class CompensationModel {
public static CompensationModel fromCompensationRequest(String address,
long amount,
long decayedAmount,
int height,
String txId,
long date,
int cycleIndex) {
static CompensationModel fromCompensationRequest(String address,
long amount,
long decayedAmount,
int height,
String txId,
long date,
int cycleIndex) {
return new CompensationModel(address,
amount,
decayedAmount,
@ -43,14 +43,14 @@ public final class CompensationModel {
cycleIndex);
}
public static CompensationModel fromGenesisOutput(String address,
long amount,
long decayedAmount,
int height,
String txId,
int outputIndex,
long date,
int cycleIndex) {
static CompensationModel fromGenesisOutput(String address,
long amount,
long decayedAmount,
int height,
String txId,
int outputIndex,
long date,
int cycleIndex) {
return new CompensationModel(address,
amount,
decayedAmount,

View file

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