Improved logging, to give a clearer picture of the peer selection decisions.

This commit is contained in:
CalDescent 2021-04-24 19:23:09 +01:00
parent 3146da6aec
commit ba6397b963
2 changed files with 11 additions and 2 deletions

View File

@ -669,11 +669,18 @@ public class Controller extends Thread {
final int peersRemoved = peersBeforeComparison - peers.size(); final int peersRemoved = peersBeforeComparison - peers.size();
if (peersRemoved > 0) if (peersRemoved > 0)
LOGGER.debug(String.format("Ignoring %d peers on inferior chains. Peers remaining: %d", peersRemoved, peers.size())); LOGGER.info(String.format("Ignoring %d peers on inferior chains. Peers remaining: %d", peersRemoved, peers.size()));
if (peers.isEmpty()) if (peers.isEmpty())
return; return;
if (peers.size() > 1) {
StringBuilder finalPeersString = new StringBuilder();
for (Peer peer : peers)
finalPeersString = finalPeersString.length() > 0 ? finalPeersString.append(", ").append(peer) : finalPeersString.append(peer);
LOGGER.info(String.format("Choosing random peer from: [%s]", finalPeersString.toString()));
}
// Pick random peer to sync with // Pick random peer to sync with
int index = new SecureRandom().nextInt(peers.size()); int index = new SecureRandom().nextInt(peers.size());
Peer peer = peers.get(index); Peer peer = peers.get(index);

View File

@ -334,6 +334,7 @@ public class Synchronizer {
ourChainWeight = Block.calcChainWeight(commonBlockSummary.getHeight(), commonBlockSummary.getSignature(), ourBlockSummaries, minChainLength); ourChainWeight = Block.calcChainWeight(commonBlockSummary.getHeight(), commonBlockSummary.getSignature(), ourBlockSummaries, minChainLength);
NumberFormat formatter = new DecimalFormat("0.###E0"); NumberFormat formatter = new DecimalFormat("0.###E0");
NumberFormat accurateFormatter = new DecimalFormat("0.################E0");
LOGGER.debug(String.format("Our chain weight based on %d blocks is %s", ourBlockSummaries.size(), formatter.format(ourChainWeight))); 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()))); LOGGER.debug(String.format("Listing peers with common block %.8s...", Base58.encode(commonBlockSummary.getSignature())));
@ -383,7 +384,8 @@ public class Synchronizer {
for (Peer peer : superiorPeersForComparison) { for (Peer peer : superiorPeersForComparison) {
// Check if we should discard an inferior peer // Check if we should discard an inferior peer
if (peer.getCommonBlockData().getChainWeight().compareTo(bestChainWeight) < 0) { 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)); BigInteger difference = bestChainWeight.subtract(peer.getCommonBlockData().getChainWeight());
LOGGER.debug(String.format("Peer %s has a lower chain weight (difference: %s) than other peer(s) in this group - removing it from this round.", peer, accurateFormatter.format(difference)));
peers.remove(peer); peers.remove(peer);
} }
} }