More useful Synchronizer logging + sync report tool.

Synchronizer logging now includes abbreviated block signature.
This commit is contained in:
catbref
2019-07-25 11:05:43 +01:00
parent 7042dd819f
commit 0c17f9cff6
2 changed files with 230 additions and 11 deletions

View File

@@ -26,6 +26,7 @@ import org.qora.repository.DataException;
import org.qora.repository.Repository;
import org.qora.repository.RepositoryManager;
import org.qora.transaction.Transaction;
import org.qora.utils.Base58;
public class Synchronizer {
@@ -108,10 +109,9 @@ public class Synchronizer {
}
byte[] ourLastBlockSignature = ourLatestBlockData.getSignature();
if (peerHeight == ourHeight && (peersLastBlockSignature == null || !Arrays.equals(peersLastBlockSignature, ourLastBlockSignature)))
LOGGER.debug(String.format("Synchronizing with peer %s at height %d, our height %d, signatures differ", peer, peerHeight, ourHeight));
else
LOGGER.debug(String.format("Synchronizing with peer %s at height %d, our height %d", peer, peerHeight, ourHeight));
LOGGER.debug(String.format("Synchronizing with peer %s at height %d, sig %.8s, ts %d; our height %d, sig %.8s, ts %d", peer,
peerHeight, Base58.encode(peersLastBlockSignature), peer.getLastBlockTimestamp(),
ourHeight, Base58.encode(ourLastBlockSignature), ourLatestBlockData.getTimestamp()));
List<byte[]> signatures = findSignaturesFromCommonBlock(peer, ourHeight);
if (signatures == null) {
@@ -126,7 +126,8 @@ public class Synchronizer {
// First signature is common block
BlockData commonBlockData = this.repository.getBlockRepository().fromSignature(signatures.get(0));
final int commonBlockHeight = commonBlockData.getHeight();
LOGGER.debug(String.format("Common block with peer %s is at height %d", peer, commonBlockHeight));
LOGGER.debug(String.format("Common block with peer %s is at height %d, sig %.8s, ts %d", peer,
commonBlockHeight, Base58.encode(commonBlockData.getSignature()), commonBlockData.getTimestamp()));
signatures.remove(0);
// If common block height is higher than peer's last reported height
@@ -173,7 +174,8 @@ public class Synchronizer {
byte[] previousSignature = sigIndex == 0 ? commonBlockData.getSignature() : signatures.get(sigIndex - 1);
List<byte[]> moreSignatures = this.getBlockSignatures(peer, previousSignature, MAXIMUM_BLOCK_STEP);
if (moreSignatures == null || moreSignatures.isEmpty()) {
LOGGER.info(String.format("Peer %s failed to respond with more block signatures after height %d", peer, height - 1));
LOGGER.info(String.format("Peer %s failed to respond with more block signatures after height %d, sig %.8s", peer,
height - 1, Base58.encode(previousSignature)));
return SynchronizationResult.NO_REPLY;
}
@@ -228,7 +230,8 @@ public class Synchronizer {
signatures = this.getBlockSignatures(peer, signature, numberRequested);
if (signatures == null || signatures.isEmpty()) {
LOGGER.info(String.format("Peer %s failed to respond with more block signatures after height %d", peer, ourHeight));
LOGGER.info(String.format("Peer %s failed to respond with more block signatures after height %d, sig %.8s", peer,
ourHeight, Base58.encode(signature)));
return SynchronizationResult.NO_REPLY;
}
@@ -242,12 +245,14 @@ public class Synchronizer {
Block newBlock = this.fetchBlock(repository, peer, signature);
if (newBlock == null) {
LOGGER.info(String.format("Peer %s failed to respond with block for height %d", peer, ourHeight));
LOGGER.info(String.format("Peer %s failed to respond with block for height %d, sig %.8s", peer,
ourHeight, Base58.encode(signature)));
return SynchronizationResult.NO_REPLY;
}
if (!newBlock.isSignatureValid()) {
LOGGER.info(String.format("Peer %s sent block with invalid signature for height %d", peer, ourHeight));
LOGGER.info(String.format("Peer %s sent block with invalid signature for height %d, sig %.8s", peer,
ourHeight, Base58.encode(signature)));
return SynchronizationResult.INVALID_DATA;
}
@@ -257,7 +262,8 @@ public class Synchronizer {
ValidationResult blockResult = newBlock.isValid();
if (blockResult != ValidationResult.OK) {
LOGGER.info(String.format("Peer %s sent invalid block for height %d: %s", peer, ourHeight, blockResult.name()));
LOGGER.info(String.format("Peer %s sent invalid block for height %d, sig %.8s: %s", peer,
ourHeight, Base58.encode(signature), blockResult.name()));
return SynchronizationResult.INVALID_DATA;
}
@@ -276,7 +282,11 @@ public class Synchronizer {
// Commit
repository.saveChanges();
LOGGER.info(String.format("Synchronized with peer %s to height %d", peer, ourHeight));
final BlockData newLatestBlockData = this.repository.getBlockRepository().getLastBlock();
LOGGER.info(String.format("Synchronized with peer %s to height %d, sig %.8s, ts: %d", peer,
newLatestBlockData.getHeight(), Base58.encode(newLatestBlockData.getSignature()),
newLatestBlockData.getTimestamp()));
return SynchronizationResult.OK;
} finally {