Track total difficulty in chain
This commit is contained in:
parent
56a96e8f75
commit
040455d868
|
@ -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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue