From 95713f40f146e506569369faffa6d82951c36a1f Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Wed, 21 Mar 2018 23:39:43 -0700 Subject: [PATCH] DAA: Fix EDA when using checkpoints. --- .../java/org/bitcoinj/params/AbstractBitcoinNetParams.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/org/bitcoinj/params/AbstractBitcoinNetParams.java b/core/src/main/java/org/bitcoinj/params/AbstractBitcoinNetParams.java index ab07dbd5769..2b32adf1198 100644 --- a/core/src/main/java/org/bitcoinj/params/AbstractBitcoinNetParams.java +++ b/core/src/main/java/org/bitcoinj/params/AbstractBitcoinNetParams.java @@ -95,6 +95,13 @@ public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block } long mpt6blocks = 0; try { + //Check to see if there are enough blocks before cursor to correctly calculate the median time + StoredBlock beforeCursor = cursor; + for (int i = 0; i < 10; i++) { + beforeCursor = blockStore.get(beforeCursor.getHeader().getPrevBlockHash()); + if(beforeCursor == null) + return; //Not enough blocks to check difficulty. + } mpt6blocks = blockChain.getMedianTimestampOfRecentBlocks(storedPrev, blockStore) - blockChain.getMedianTimestampOfRecentBlocks(cursor, blockStore); } catch (NullPointerException x) {