Fix for bug which failed to remove peers without block summaries.

The iterator was removing the peer from the "peersSharingCommonBlock" array, when it should have been removing it from the "peers" array. The result was that the bad peer would end up in the final list of good peers, and we could then sync with it when we shouldn't have.
This commit is contained in:
CalDescent 2021-04-24 15:21:30 +01:00
parent 423142d730
commit ec2af62b4d

View File

@ -337,10 +337,7 @@ public class Synchronizer {
LOGGER.debug(String.format("Our chain weight based on %d blocks is %s", ourBlockSummaries.size(), formatter.format(ourChainWeight)));
LOGGER.debug(String.format("Listing peers with common block %.8s...", Base58.encode(commonBlockSummary.getSignature())));
iterator = peersSharingCommonBlock.iterator();
while (iterator.hasNext()) {
Peer peer = (Peer)iterator.next();
for (Peer peer : peersSharingCommonBlock) {
final int peerHeight = peer.getChainTipData().getLastHeight();
final int peerAdditionalBlocksAfterCommonBlock = peerHeight - commonBlockSummary.getHeight();
final CommonBlockData peerCommonBlockData = peer.getCommonBlockData();
@ -348,7 +345,7 @@ public class Synchronizer {
if (peerCommonBlockData == null || peerCommonBlockData.getBlockSummariesAfterCommonBlock() == null || peerCommonBlockData.getBlockSummariesAfterCommonBlock().isEmpty()) {
// No response - remove this peer for now
LOGGER.debug(String.format("Peer %s doesn't have any block summaries - removing it from this round", peer));
iterator.remove();
peers.remove(peer);
continue;
}