mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-19 09:50:32 +01:00
Block: log warning if solve()
runs a bit long
This commit is contained in:
parent
7879f24164
commit
472af481cc
@ -23,6 +23,7 @@ import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.base.VarInt;
|
||||
import org.bitcoinj.base.internal.Buffers;
|
||||
import org.bitcoinj.base.internal.Stopwatch;
|
||||
import org.bitcoinj.base.internal.TimeUtils;
|
||||
import org.bitcoinj.base.internal.ByteUtils;
|
||||
import org.bitcoinj.base.internal.InternalUtils;
|
||||
@ -445,6 +446,8 @@ public class Block extends Message {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public void solve() {
|
||||
Duration warningThreshold = Duration.ofSeconds(5);
|
||||
Stopwatch watch = Stopwatch.start();
|
||||
while (true) {
|
||||
try {
|
||||
// Is our proof of work valid yet?
|
||||
@ -452,6 +455,11 @@ public class Block extends Message {
|
||||
return;
|
||||
// No, so increment the nonce and try again.
|
||||
setNonce(getNonce() + 1);
|
||||
|
||||
if (watch.isRunning() && watch.elapsed().compareTo(warningThreshold) > 0) {
|
||||
watch.stop();
|
||||
log.warn("trying to solve block for longer than {} seconds", warningThreshold.getSeconds());
|
||||
}
|
||||
} catch (VerificationException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user