From a54e2e96eb0fcc56f1b622f1fd379e31d5b04adb Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 24 Dec 2012 16:12:13 +0000 Subject: [PATCH] Fix a bug in difficulty calculation logic that is revealed by testnet3. It should not impact the main net. Resolves issue 262. Rethrow block verification errors with a message containing the block. --- .../java/com/google/bitcoin/core/AbstractBlockChain.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java index 463f0c09..65013b9a 100644 --- a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java +++ b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java @@ -188,7 +188,8 @@ public abstract class AbstractBlockChain { } catch (BlockStoreException e1) { throw new RuntimeException(e1); } - throw e; + throw new VerificationException("Could not verify block " + block.getHashAsString() + "\n" + + block.toString(), e); } } @@ -672,7 +673,7 @@ public abstract class AbstractBlockChain { if (timespan > params.targetTimespan * 4) timespan = params.targetTimespan * 4; - BigInteger newDifficulty = Utils.decodeCompactBits(blockIntervalAgo.getDifficultyTarget()); + BigInteger newDifficulty = Utils.decodeCompactBits(prev.getDifficultyTarget()); newDifficulty = newDifficulty.multiply(BigInteger.valueOf(timespan)); newDifficulty = newDifficulty.divide(BigInteger.valueOf(params.targetTimespan));