Merge pull request #89 from nicksavers/master
Add correct rewards with uncles and workaround overflow for PoC5
This commit is contained in:
commit
fa7c9e108e
|
@ -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,18 +176,36 @@ public class Blockchain {
|
|||
repository.dumpState(block, totalGasUsed, i++, txr.getTransaction().getHash());
|
||||
}
|
||||
|
||||
// miner reward
|
||||
if (repository.getAccountState(block.getCoinbase()) == null)
|
||||
repository.createAccount(block.getCoinbase());
|
||||
repository.addBalance(block.getCoinbase(), Block.BLOCK_REWARD);
|
||||
|
||||
for (BlockHeader uncle : block.getUncleList()) {
|
||||
repository.addBalance(uncle.getCoinbase(), Block.UNCLE_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void storeBlock(Block block) {
|
||||
|
||||
|
|
|
@ -144,9 +144,10 @@ public class VM {
|
|||
if(callGas.compareTo(program.getGas().value()) == 1) {
|
||||
throw program.new OutOfGasException();
|
||||
}
|
||||
BigInteger x = stack.get(stack.size()-6).value().add(stack.get(stack.size()-7).value());
|
||||
BigInteger y = stack.get(stack.size()-4).value().add(stack.get(stack.size()-5).value());
|
||||
newMemSize = x.max(y);
|
||||
// Casting to long (causing overflow) as workaround for PoC5 - should be removed for PoC6
|
||||
long x = stack.get(stack.size()-6).value().add(stack.get(stack.size()-7).value()).longValue();
|
||||
long y = stack.get(stack.size()-4).value().add(stack.get(stack.size()-5).value()).longValue();
|
||||
newMemSize = BigInteger.valueOf(Math.max(x, y));
|
||||
break;
|
||||
case CREATE:
|
||||
program.spendGas(GasCost.CREATE, op.name());
|
||||
|
|
Loading…
Reference in New Issue