Block: Improve message of VerificationException that is thrown when a blocks time is too far in the future.

This commit is contained in:
Andreas Schildbach
2016-05-06 11:17:29 +02:00
parent 01890c563c
commit dfd7c826d3

View File

@@ -557,10 +557,11 @@ public class Block extends Message {
}
private void checkTimestamp() throws VerificationException {
// Allow injection of a fake clock to allow unit testing.
long currentTime = Utils.currentTimeSeconds();
if (time > currentTime + ALLOWED_TIME_DRIFT)
throw new VerificationException(String.format(Locale.US, "Block too far in future: %d vs %d", time, currentTime + ALLOWED_TIME_DRIFT));
final long allowedTime = Utils.currentTimeSeconds() + ALLOWED_TIME_DRIFT;
if (time > allowedTime)
throw new VerificationException(String.format(Locale.US,
"Block too far in future: %s (%d) vs allowed %s (%d)", Utils.dateTimeFormat(time * 1000), time,
Utils.dateTimeFormat(allowedTime * 1000), allowedTime));
}
private void checkSigOps() throws VerificationException {