diff --git a/src/main/java/org/qortal/block/Block.java b/src/main/java/org/qortal/block/Block.java index 34a87e9a..ee41bc07 100644 --- a/src/main/java/org/qortal/block/Block.java +++ b/src/main/java/org/qortal/block/Block.java @@ -1335,6 +1335,9 @@ public class Block { // Give Controller our cached, valid online accounts data (if any) to help reduce CPU load for next block Controller.getInstance().pushLatestBlocksOnlineAccounts(this.cachedValidOnlineAccounts); + + // Log some debugging info relating to the block weight calculation + this.logDebugInfo(); } protected void increaseAccountLevels() throws DataException { @@ -1516,6 +1519,9 @@ public class Block { public void orphan() throws DataException { LOGGER.trace(() -> String.format("Orphaning block %d", this.blockData.getHeight())); + // Log some debugging info relating to the block weight calculation + this.logDebugInfo(); + // Return AT fees and delete AT states from repository orphanAtFeesAndStates(); @@ -1988,4 +1994,33 @@ public class Block { this.repository.getAccountRepository().tidy(); } + private void logDebugInfo() { + try { + if (this.repository == null || this.getMinter() == null || this.getBlockData() == null) + return; + + int minterLevel = Account.getRewardShareEffectiveMintingLevel(this.repository, this.getMinter().getPublicKey()); + + LOGGER.debug(String.format("======= BLOCK %d (%.8s) =======", this.getBlockData().getHeight(), Base58.encode(this.getSignature()))); + LOGGER.debug(String.format("Timestamp: %d", this.getBlockData().getTimestamp())); + LOGGER.debug(String.format("Minter level: %d", minterLevel)); + LOGGER.debug(String.format("Online accounts: %d", this.getBlockData().getOnlineAccountsCount())); + + BlockSummaryData blockSummaryData = new BlockSummaryData(this.getBlockData()); + if (this.getParent() == null || this.getParent().getSignature() == null || blockSummaryData == null) + return; + + blockSummaryData.setMinterLevel(minterLevel); + BigInteger blockWeight = calcBlockWeight(this.getParent().getHeight(), this.getParent().getSignature(), blockSummaryData); + BigInteger keyDistance = calcKeyDistance(this.getParent().getHeight(), this.getParent().getSignature(), blockSummaryData.getMinterPublicKey(), blockSummaryData.getMinterLevel()); + NumberFormat formatter = new DecimalFormat("0.###E0"); + + LOGGER.debug(String.format("Key distance: %s", formatter.format(keyDistance))); + LOGGER.debug(String.format("Weight: %s", formatter.format(blockWeight))); + + } catch (DataException e) { + LOGGER.info(() -> String.format("Unable to log block debugging info: %s", e.getMessage())); + } + } + }