3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-12 18:25:49 +00:00

Add support for logging PROOF network message calculation time

This commit is contained in:
catbref 2020-03-23 10:57:23 +00:00
parent 1f0170bb4b
commit f95cb99cdc

View File

@ -5,6 +5,8 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.HashSet; import java.util.HashSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.qortal.network.message.ProofMessage; import org.qortal.network.message.ProofMessage;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
@ -13,6 +15,7 @@ public class Proof extends Thread {
private static final int MIN_PROOF_ZEROS = 2; private static final int MIN_PROOF_ZEROS = 2;
private static final HashSet<Long> seenSalts = new HashSet<>(); private static final HashSet<Long> seenSalts = new HashSet<>();
private static final Logger LOGGER = LogManager.getLogger(Proof.class);
private Peer peer; private Peer peer;
@ -38,6 +41,7 @@ public class Proof extends Thread {
setName("Proof for peer " + this.peer); setName("Proof for peer " + this.peer);
// Do proof-of-work calculation to gain acceptance with remote end // Do proof-of-work calculation to gain acceptance with remote end
final long startTime = LOGGER.isTraceEnabled() ? System.currentTimeMillis() : 0;
// Remote end knows this (approximately) // Remote end knows this (approximately)
long timestamp = this.peer.getConnectionTimestamp(); long timestamp = this.peer.getConnectionTimestamp();
@ -64,7 +68,7 @@ public class Proof extends Thread {
long nonce; long nonce;
for (nonce = 0; nonce < Long.MAX_VALUE; ++nonce) { for (nonce = 0; nonce < Long.MAX_VALUE; ++nonce) {
// Check whether we're shutting down every so often // Check whether we're shutting down every so often
if ((nonce & 0xff) == 0 && (peer.isStopping() || Thread.currentThread().isInterrupted())) if ((nonce & 0xff) == 0 && (this.peer.isStopping() || Thread.currentThread().isInterrupted()))
// throw new InterruptedException("Interrupted during peer proof calculation"); // throw new InterruptedException("Interrupted during peer proof calculation");
return; return;
@ -79,6 +83,8 @@ public class Proof extends Thread {
sha256.reset(); sha256.reset();
} }
LOGGER.trace(() -> String.format("Proof for peer %s took %dms", this.peer, System.currentTimeMillis() - startTime));
ProofMessage proofMessage = new ProofMessage(timestamp, salt, nonce); ProofMessage proofMessage = new ProofMessage(timestamp, salt, nonce);
peer.sendMessage(proofMessage); peer.sendMessage(proofMessage);
} }