From e5cf76f3e0fe6321f9db740e2cf68496b3a942b2 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 4614c81c..4ad7894f 100644 --- a/src/main/java/org/qortal/block/Block.java +++ b/src/main/java/org/qortal/block/Block.java @@ -304,8 +304,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; @@ -350,8 +352,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); @@ -419,8 +423,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 48bcb967..c5e64728 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)); } }