From 3185cf23df29f3d3427b46c515b01128780ab30e Mon Sep 17 00:00:00 2001 From: catbref Date: Mon, 4 May 2020 08:18:15 +0100 Subject: [PATCH] Replace throwing IllegalStateException with more defensive log & null in Block/BlockMinter --- src/main/java/org/qortal/block/Block.java | 18 ++++++++++++------ .../java/org/qortal/block/BlockMinter.java | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/qortal/block/Block.java b/src/main/java/org/qortal/block/Block.java index f49cb583..ea57bff9 100644 --- a/src/main/java/org/qortal/block/Block.java +++ b/src/main/java/org/qortal/block/Block.java @@ -303,8 +303,10 @@ public class Block { // Fetch our list of online accounts List onlineAccounts = Controller.getInstance().getOnlineAccounts(); - if (onlineAccounts.isEmpty()) - throw new IllegalStateException("No online accounts - not even our own?"); + if (onlineAccounts.isEmpty()) { + LOGGER.error("No online accounts - not even our own?"); + return null; + } // Find newest online accounts timestamp long onlineAccountsTimestamp = 0; @@ -349,8 +351,10 @@ public class Block { // Qortal: minter is always a reward-share, so find actual minter and get their effective minting level int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey()); - if (minterLevel == 0) - throw new IllegalStateException("Minter effective level returned zero?"); + if (minterLevel == 0) { + LOGGER.error("Minter effective level returned zero?"); + return null; + } long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel); @@ -418,8 +422,10 @@ public class Block { // Qortal: minter is always a reward-share, so find actual minter and get their effective minting level int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey()); - if (minterLevel == 0) - throw new IllegalStateException("Minter effective level returned zero?"); + if (minterLevel == 0){ + LOGGER.error("Minter effective level returned zero?"); + return null; + } long timestamp = calcTimestamp(parentBlockData, minter.getPublicKey(), minterLevel); diff --git a/src/main/java/org/qortal/block/BlockMinter.java b/src/main/java/org/qortal/block/BlockMinter.java index 2026f5f7..b3e3c00a 100644 --- a/src/main/java/org/qortal/block/BlockMinter.java +++ b/src/main/java/org/qortal/block/BlockMinter.java @@ -163,10 +163,18 @@ public class BlockMinter extends Thread { // First block does the AT heavy-lifting if (newBlocks.isEmpty()) { Block newBlock = Block.mint(repository, previousBlock.getBlockData(), mintingAccount); + if (newBlock == null) + // For some reason we can't mint right now + continue; + newBlocks.add(newBlock); } else { // The blocks for other minters require less effort... Block newBlock = newBlocks.get(0); + if (newBlock == null) + // For some reason we can't mint right now + continue; + newBlocks.add(newBlock.remint(mintingAccount)); } }