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.
This commit is contained in:
CalDescent 2021-04-24 16:43:29 +01:00
parent 5643e57ede
commit 3146da6aec

View File

@ -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);
}
}
}