diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index 0caf8d1e..1fd927b7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -166,13 +166,13 @@ public class Block { return this.header.getDifficulty(); } - public BigInteger getTotalDifficulty() { + public BigInteger getCumulativeDifficulty() { if (!parsed) parseRLP(); - BigInteger totalDifficulty = new BigInteger(1, this.header.getDifficulty()); + BigInteger calcDifficulty = new BigInteger(1, this.header.getDifficulty()); for (BlockHeader uncle : uncleList) { - totalDifficulty.add(new BigInteger(1, uncle.getDifficulty())); + calcDifficulty.add(new BigInteger(1, uncle.getDifficulty())); } - return totalDifficulty; + return calcDifficulty; } public long getTimestamp() { diff --git a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java index 83a31e76..b75f8b43 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java @@ -165,7 +165,7 @@ public class BlockchainImpl implements Blockchain { } this.addReward(block); - this.addTotalDifficulty(block.getTotalDifficulty()); + this.updateTotalDifficulty(block); if(block.getNumber() >= CONFIG.traceStartBlock()) repository.dumpState(block, totalGasUsed, 0, null); @@ -471,10 +471,10 @@ public class BlockchainImpl implements Blockchain { } @Override - public void addTotalDifficulty(BigInteger totalDifficulty) { + public void updateTotalDifficulty(Block block) { if (this.totalDifficulty == null) - this.totalDifficulty = totalDifficulty; + this.totalDifficulty = block.getCumulativeDifficulty(); else - this.totalDifficulty.add(totalDifficulty); + this.totalDifficulty.add(block.getCumulativeDifficulty()); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/db/RepositoryImpl.java b/ethereumj-core/src/main/java/org/ethereum/db/RepositoryImpl.java index f301e270..86653d6f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/RepositoryImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/RepositoryImpl.java @@ -154,7 +154,7 @@ public class RepositoryImpl implements Repository { Block block = new Block(iterator.next().getValue()); blockchain.getBlockCache().put(block.getNumber(), block.getHash()); blockchain.setLastBlock(block); - blockchain.addTotalDifficulty(block.getTotalDifficulty()); + blockchain.updateTotalDifficulty(block); EthereumListener listener = WorldManager.getInstance().getListener(); if (listener != null){ listener.onPreloadedBlock(block); diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/Blockchain.java b/ethereumj-core/src/main/java/org/ethereum/facade/Blockchain.java index 0da1477e..a999cde7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/Blockchain.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/Blockchain.java @@ -21,7 +21,7 @@ public interface Blockchain { public Block getLastBlock(); public BlockQueue getQueue(); public void close(); - public void addTotalDifficulty(BigInteger totalDifficulty); + public void updateTotalDifficulty(Block block); public BigInteger getTotalDifficulty(); public byte[] getLatestBlockHash(); }