void verifyDifficulty(BigInteger newTarget, Block nextBlock) { if (newTarget.compareTo(this.getMaxTarget()) > 0) { log.info("Difficulty hit proof of work limit: {}", newTarget.toString(16)); newTarget = this.getMaxTarget(); } int accuracyBytes = (int) (nextBlock.getDifficultyTarget() >>> 24) - 3; long receivedTargetCompact = nextBlock.getDifficultyTarget(); // The calculated difficulty is to a higher precision than received, so reduce here. BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8); newTarget = newTarget.and(mask); long newTargetCompact = Utils.encodeCompactBits(newTarget); if (newTargetCompact != receivedTargetCompact) throw new VerificationException("Network provided difficulty bits do not match what was calculated: " + Long.toHexString(newTargetCompact) + " vs " + Long.toHexString(receivedTargetCompact)); }
return Utils.encodeCompactBits(newTarget);
return Utils.encodeCompactBits(newTarget);
long n2 = Utils.encodeCompactBits(n.toBigInteger(), false);
@Test public void compactEncoding() throws Exception { assertEquals(new BigInteger("1234560000", 16), Utils.decodeCompactBits(0x05123456L)); assertEquals(new BigInteger("c0de000000", 16), Utils.decodeCompactBits(0x0600c0de)); assertEquals(0x05123456L, Utils.encodeCompactBits(new BigInteger("1234560000", 16))); assertEquals(0x0600c0deL, Utils.encodeCompactBits(new BigInteger("c0de000000", 16))); }
long newTargetCompact = Utils.encodeCompactBits(newTarget);
long newTargetCompact = Utils.encodeCompactBits(newTarget);
long newTargetCompact = Utils.encodeCompactBits(newTarget);
long newTargetCompact = Utils.encodeCompactBits(newTarget);
if (!maxTarget.equals(nextBlock.getDifficultyTargetAsInteger())) throw new VerificationException("Testnet block transition that is not allowed: " + Long.toHexString(Utils.encodeCompactBits(maxTarget)) + " (required min difficulty) vs " + Long.toHexString(nextBlock.getDifficultyTarget())); return;
long newTargetCompact = Utils.encodeCompactBits(newTarget);
long n2 = Utils.encodeCompactBits(n.toBigInteger(), false);
nPow = getMaxTarget(); if (nextBlock.getDifficultyTarget() != Utils.encodeCompactBits(nPow)) throw new VerificationException("Unexpected change in difficulty [6 blocks >12 hours] at height " + storedPrev.getHeight() + ": " + Long.toHexString(nextBlock.getDifficultyTarget()) + " vs " + Utils.encodeCompactBits(nPow)); return;
return Utils.encodeCompactBits(this.getMaxTarget()); return Utils.encodeCompactBits(maxTarget); } else { && cursor.getHeader().getDifficultyTarget() == Utils.encodeCompactBits(this.getMaxTarget())) { StoredBlock prevCursor = cursor.getPrev(blockStore); if (prevCursor == null) {
return Utils.encodeCompactBits(maxTarget); } else { && cursor.getHeader().getDifficultyTarget() == Utils.encodeCompactBits(this.getMaxTarget())) { StoredBlock prevCursor = cursor.getPrev(blockStore); if (prevCursor == null) {