Fix bug for total difficulty
This commit is contained in:
parent
8b381635e3
commit
56a96e8f75
|
@ -166,6 +166,15 @@ public class Block {
|
|||
return this.header.getDifficulty();
|
||||
}
|
||||
|
||||
public BigInteger getTotalDifficulty() {
|
||||
if (!parsed) parseRLP();
|
||||
BigInteger totalDifficulty = new BigInteger(1, this.header.getDifficulty());
|
||||
for (BlockHeader uncle : uncleList) {
|
||||
totalDifficulty.add(new BigInteger(1, uncle.getDifficulty()));
|
||||
}
|
||||
return totalDifficulty;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
if (!parsed) parseRLP();
|
||||
return this.header.getTimestamp();
|
||||
|
|
|
@ -165,19 +165,12 @@ public class BlockchainImpl implements Blockchain {
|
|||
}
|
||||
|
||||
this.addReward(block);
|
||||
this.increaseTotalDifficulty(block);
|
||||
this.addTotalDifficulty(block.getTotalDifficulty());
|
||||
|
||||
if(block.getNumber() >= CONFIG.traceStartBlock())
|
||||
repository.dumpState(block, totalGasUsed, 0, null);
|
||||
}
|
||||
|
||||
private void increaseTotalDifficulty(Block block) {
|
||||
totalDifficulty.add(new BigInteger(block.getDifficulty()));
|
||||
for (BlockHeader uncleHeader : block.getUncleList()) {
|
||||
totalDifficulty.add(new BigInteger(uncleHeader.getDifficulty()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add reward to block- and every uncle coinbase
|
||||
* assuming the entire block is valid.
|
||||
|
@ -476,4 +469,12 @@ public class BlockchainImpl implements Blockchain {
|
|||
public BigInteger getTotalDifficulty() {
|
||||
return totalDifficulty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTotalDifficulty(BigInteger totalDifficulty) {
|
||||
if (this.totalDifficulty == null)
|
||||
this.totalDifficulty = totalDifficulty;
|
||||
else
|
||||
this.totalDifficulty.add(totalDifficulty);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||
if (listener != null){
|
||||
listener.onPreloadedBlock(block);
|
||||
|
|
|
@ -21,6 +21,7 @@ public interface Blockchain {
|
|||
public Block getLastBlock();
|
||||
public BlockQueue getQueue();
|
||||
public void close();
|
||||
public BigInteger getTotalDifficulty();
|
||||
public void addTotalDifficulty(BigInteger totalDifficulty);
|
||||
public BigInteger getTotalDifficulty();
|
||||
public byte[] getLatestBlockHash();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue