mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-17 22:27:13 +00:00
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();
|
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() {
|
public long getTimestamp() {
|
||||||
if (!parsed) parseRLP();
|
if (!parsed) parseRLP();
|
||||||
return this.header.getTimestamp();
|
return this.header.getTimestamp();
|
||||||
|
@ -165,19 +165,12 @@ public class BlockchainImpl implements Blockchain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addReward(block);
|
this.addReward(block);
|
||||||
this.increaseTotalDifficulty(block);
|
this.addTotalDifficulty(block.getTotalDifficulty());
|
||||||
|
|
||||||
if(block.getNumber() >= CONFIG.traceStartBlock())
|
if(block.getNumber() >= CONFIG.traceStartBlock())
|
||||||
repository.dumpState(block, totalGasUsed, 0, null);
|
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
|
* Add reward to block- and every uncle coinbase
|
||||||
* assuming the entire block is valid.
|
* assuming the entire block is valid.
|
||||||
@ -476,4 +469,12 @@ public class BlockchainImpl implements Blockchain {
|
|||||||
public BigInteger getTotalDifficulty() {
|
public BigInteger getTotalDifficulty() {
|
||||||
return totalDifficulty;
|
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());
|
Block block = new Block(iterator.next().getValue());
|
||||||
blockchain.getBlockCache().put(block.getNumber(), block.getHash());
|
blockchain.getBlockCache().put(block.getNumber(), block.getHash());
|
||||||
blockchain.setLastBlock(block);
|
blockchain.setLastBlock(block);
|
||||||
|
blockchain.addTotalDifficulty(block.getTotalDifficulty());
|
||||||
EthereumListener listener = WorldManager.getInstance().getListener();
|
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||||
if (listener != null){
|
if (listener != null){
|
||||||
listener.onPreloadedBlock(block);
|
listener.onPreloadedBlock(block);
|
||||||
|
@ -21,6 +21,7 @@ public interface Blockchain {
|
|||||||
public Block getLastBlock();
|
public Block getLastBlock();
|
||||||
public BlockQueue getQueue();
|
public BlockQueue getQueue();
|
||||||
public void close();
|
public void close();
|
||||||
public BigInteger getTotalDifficulty();
|
public void addTotalDifficulty(BigInteger totalDifficulty);
|
||||||
|
public BigInteger getTotalDifficulty();
|
||||||
public byte[] getLatestBlockHash();
|
public byte[] getLatestBlockHash();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user