From 3146da6aec4f6fd4d23db1f5c568a02af757f1ff Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sat, 24 Apr 2021 16:43:29 +0100 Subject: [PATCH] Don't add to the inferior chain signatures list when comparing peers against each other. In these comparisons it's easy to incorrectly identify a bad chain, as we aren't comparing the same number of blocks. It's quite common for one peer to fail to return all blocks and be marked as an inferior chain, yet we have other "good" peers on that exact same chain. In those cases we would have stopped talking to the good peers again until they received another block. Instead of complicating the logic and keeping track of the various good chain tip signatures, it is simpler to just remove the inferior peers from this round of syncing, and re-test them in the next round, in case they are in fact superior or equal. --- src/main/java/org/qortal/controller/Synchronizer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/qortal/controller/Synchronizer.java b/src/main/java/org/qortal/controller/Synchronizer.java index 313b37b4..41b0cda7 100644 --- a/src/main/java/org/qortal/controller/Synchronizer.java +++ b/src/main/java/org/qortal/controller/Synchronizer.java @@ -361,8 +361,8 @@ public class Synchronizer { // Compare against our chain - if our blockchain has greater weight then don't synchronize with peer (or any others in this group) if (ourChainWeight.compareTo(peerChainWeight) > 0) { // This peer is on an inferior chain - remove it - LOGGER.debug(String.format("Peer %s is on an inferior chain to us - added %.8s to inferior chain signatures list", peer, Base58.encode(peer.getChainTipData().getLastBlockSignature()))); - Controller.getInstance().addInferiorChainSignature(peer.getChainTipData().getLastBlockSignature()); + LOGGER.debug(String.format("Peer %s is on an inferior chain to us - removing it from this round", peer)); + peers.remove(peer); } else { // Our chain is inferior @@ -384,7 +384,7 @@ public class Synchronizer { // Check if we should discard an inferior peer if (peer.getCommonBlockData().getChainWeight().compareTo(bestChainWeight) < 0) { LOGGER.debug(String.format("Peer %s has a lower chain weight than other peer(s) in this group - removing it from this round.", peer)); - Controller.getInstance().addInferiorChainSignature(peer.getChainTipData().getLastBlockSignature()); + peers.remove(peer); } } }