mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-27 11:10:29 +00:00
Reward correctly when there are uncles
This commit is contained in:
parent
446f613cf6
commit
2b74aca6a9
@ -38,7 +38,7 @@ public class Block {
|
||||
private static long MIN_GAS_LIMIT = 125000L;
|
||||
public static BigInteger BLOCK_REWARD = BigInteger.valueOf(1500000000000000000L);
|
||||
public static BigInteger UNCLE_REWARD = BLOCK_REWARD.multiply(
|
||||
BigInteger.valueOf(7)).divide(BigInteger.valueOf(8));
|
||||
BigInteger.valueOf(3)).divide(BigInteger.valueOf(4));
|
||||
|
||||
private BlockHeader header;
|
||||
|
||||
|
@ -112,8 +112,8 @@ public class Blockchain {
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
if (block.getNumber() == 3211)
|
||||
logger.debug("Block #3211");
|
||||
if (block.getNumber() == 12301)
|
||||
logger.debug("Block #12301");
|
||||
|
||||
// if it is the first block to add
|
||||
// make sure the parent is genesis
|
||||
@ -176,17 +176,35 @@ public class Blockchain {
|
||||
repository.dumpState(block, totalGasUsed, i++, txr.getTransaction().getHash());
|
||||
}
|
||||
|
||||
// miner reward
|
||||
this.addReward(block);
|
||||
|
||||
if(block.getNumber() >= CONFIG.traceStartBlock())
|
||||
repository.dumpState(block, totalGasUsed, 0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param block
|
||||
*/
|
||||
private void addReward(Block block) {
|
||||
// Create coinbase if doesn't exist yet
|
||||
if (repository.getAccountState(block.getCoinbase()) == null)
|
||||
repository.createAccount(block.getCoinbase());
|
||||
|
||||
// Add standard block reward
|
||||
repository.addBalance(block.getCoinbase(), Block.BLOCK_REWARD);
|
||||
|
||||
// Add extra rewards based on number of uncles
|
||||
if(block.getUncleList().size() > 0) {
|
||||
BigInteger partialReward = Block.BLOCK_REWARD
|
||||
.multiply(BigInteger.valueOf(1 * block.getUncleList().size()))
|
||||
.divide(BigInteger.valueOf(8));
|
||||
repository.addBalance(block.getCoinbase(), partialReward);
|
||||
|
||||
for (BlockHeader uncle : block.getUncleList()) {
|
||||
repository.addBalance(uncle.getCoinbase(), Block.UNCLE_REWARD);
|
||||
}
|
||||
|
||||
if(block.getNumber() >= CONFIG.traceStartBlock())
|
||||
repository.dumpState(block, totalGasUsed, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void storeBlock(Block block) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user