From 79f7f68b0c1a073f4b21dfb06967fa7193771750 Mon Sep 17 00:00:00 2001 From: catbref Date: Thu, 19 Mar 2020 10:58:53 +0000 Subject: [PATCH] Change when BlockMinter decides it's ok to mint a block Previously BlockMinter would attempt to mint if there were at least 'minBlockchainPeers' connected peers and none of them had an up-to-date block and we did. This was maybe useful for minting block 2 but possibly causes minting chain islands where a badly connected node mints by itself, even though connected to not up-to-date peers. Now BlockMinter requires 'minBlockchainPeers' up-to-date peers, not simply just connected. This should let synchronization bring the node up-to-date but does require the node to have better peers. Currently, the default for minBlockchainPeers is 10. So a node requires 10 up-to-date peers before it will consider minting. It might be possible to reduce this in the future to lessen network load. --- src/main/java/org/qortal/block/BlockMinter.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/qortal/block/BlockMinter.java b/src/main/java/org/qortal/block/BlockMinter.java index 0fa6d315..eb5df334 100644 --- a/src/main/java/org/qortal/block/BlockMinter.java +++ b/src/main/java/org/qortal/block/BlockMinter.java @@ -137,19 +137,18 @@ public class BlockMinter extends Thread { // Disregard peers that have "misbehaved" recently peers.removeIf(Controller.hasMisbehaved); - // Don't mint if we don't have enough connected peers as where would the transactions/consensus come from? - if (peers.size() < Settings.getInstance().getMinBlockchainPeers()) - continue; - // Disregard peers that don't have a recent block peers.removeIf(Controller.hasNoRecentBlock); - // If we have any peers with a recent block, but our latest block isn't recent - // then we need to synchronize instead of minting. + // Don't mint if we don't have enough up-to-date peers as where would the transactions/consensus come from? + if (peers.size() < Settings.getInstance().getMinBlockchainPeers()) + continue; + + // If our latest block isn't recent then we need to synchronize instead of minting. if (!peers.isEmpty() && lastBlockData.getTimestamp() < minLatestBlockTimestamp) continue; - // There are no peers with a recent block and/or our latest block is recent + // There are enough peers with a recent block and our latest block is recent // so go ahead and mint a block if possible. isMintingPossible = true;