Skip to content

Commit

Permalink
Logs: fix logging so we always log in legible sem amount
Browse files Browse the repository at this point in the history
  • Loading branch information
chris.orogvany committed Jan 31, 2018
1 parent 4d814df commit a7a9dec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/semuxpool/pool/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
public class Constants
{
public static final long SEM = 1_000_000_000;

public static String getInSEM(long amount)
{
return String.format("%.8f", amount / (float) Constants.SEM);
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/semuxpool/pool/state/PoolState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.semuxpool.pool.state;

import com.semuxpool.pool.Constants;
import com.semuxpool.pool.api.Payment;
import com.semuxpool.pool.api.Payout;
import com.semuxpool.pool.status.StatusLogger;
Expand Down Expand Up @@ -107,7 +108,7 @@ public synchronized void addPayout(Payout payouts)
unpaidBalances.put(payout.getKey(), amount);
subtotalUnpaid += payout.getValue();
}
logger.info("SubtotalUnpaid:" + subtotalUnpaid);
logger.info("SubtotalUnpaid:" + Constants.getInSEM(subtotalUnpaid));
if (subtotalUnpaid != payouts.getTotalPayouts())
{
logger.error("Calculated " + subtotalUnpaid + " payout but was " + payouts.getTotalPayouts());
Expand Down Expand Up @@ -143,7 +144,7 @@ public synchronized void addPayout(Payout payouts)
unpaidBalances.remove(paid.getKey());
}
}
logger.info("SubtotalPaid:" + subtotalPaid);
logger.info("SubtotalPaid:" + Constants.getInSEM(subtotalPaid));
totalUnpaid -= subtotalPaid;

//now unpaid balances include everything still owed.
Expand Down
30 changes: 10 additions & 20 deletions src/main/java/com/semuxpool/pool/status/StatusLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public void logState(PoolState poolState)
{
logger.info("=====================");
logger.info("Block: " + poolState.getCurrentBlock());
logger.info("Pool profit: " + getInSEM(poolState.getTotalPoolProfits()));
logger.info("Pool paid: " + getInSEM(poolState.getTotalPaidOut()));
logger.info("Pool unpaid: " + getInSEM(poolState.getTotalUnpaid()));
logger.info("Pool fees paid: " + getInSEM(poolState.getTotalFeesPaid()));
logger.info("Pool profit: " + Constants.getInSEM(poolState.getTotalPoolProfits()));
logger.info("Pool paid: " + Constants.getInSEM(poolState.getTotalPaidOut()));
logger.info("Pool unpaid: " + Constants.getInSEM(poolState.getTotalUnpaid()));
logger.info("Pool fees paid: " + Constants.getInSEM(poolState.getTotalFeesPaid()));
long totalAllTime = poolState.getTotalPaidOut() + poolState.getTotalFeesPaid() + poolState.getTotalUnpaid();
logger.info("Pool forged: " + getInSEM(totalAllTime));
logger.info("Pool forged: " + Constants.getInSEM(totalAllTime));
logger.info("Blocks forged: " + poolState.getBlocksForged());
float poolFee = (float) poolState.getTotalPoolProfits() / (float) totalAllTime;
logger.info("Effective Pool Earnings %: " + poolFee * 100.0f + "%");
Expand All @@ -42,32 +42,22 @@ public void logState(PoolState poolState)
{
calculatedOverpaid -= unpaid.getValue();
}
logger.info(unpaid.getKey() + " : " + getInSEM(unpaid.getValue()));
logger.info(unpaid.getKey() + " : " + Constants.getInSEM(unpaid.getValue()));
}
logger.info("Pool unpaid (sanity): " + getInSEM(calculatedUnpaid));
logger.info("Pool overpaid (sanity): " + getInSEM(calculatedOverpaid));
logger.info("Pool unpaid (sanity): " + Constants.getInSEM(calculatedUnpaid));
logger.info("Pool overpaid (sanity): " + Constants.getInSEM(calculatedOverpaid));
logger.info("Accounted for: " + (float) (calculatedUnpaid - calculatedOverpaid) / (float) poolState.getTotalUnpaid() * 100 + "%");
logger.info("=====================");
logger.info("Current paid balances");
long calculatedPaid = 0;
for (Map.Entry<String, Long> paid : poolState.getPaidBalances().entrySet())
{
calculatedPaid += paid.getValue();
logger.info(paid.getKey() + " : " + getInSEM(paid.getValue()));
logger.info(paid.getKey() + " : " + Constants.getInSEM(paid.getValue()));
}
logger.info("Pool paid (sanity): " + getInSEM(calculatedPaid));
logger.info("Pool paid (sanity): " + Constants.getInSEM(calculatedPaid));
logger.info("Accounted for: " + (float) calculatedPaid / (float) poolState.getTotalPaidOut() * 100 + "%");
logger.info("=====================");
}

/**
* convert long to formatted string SEM
*
* @param value value
* @return SEM
*/
public static String getInSEM(Long value)
{
return String.format("%.8f", value / (float) Constants.SEM);
}
}

0 comments on commit a7a9dec

Please sign in to comment.