Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Eip 658: Embedding transaction return data in receipts #928

Merged
merged 9 commits into from
Aug 31, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,10 @@ String validateTransactionChanges(BlockStore blockStore, Block curBlock, Transac
* EIP214: https://github.com/ethereum/EIPs/pull/214
*/
boolean eip214();

/**
* EIP658: https://github.com/ethereum/EIPs/pull/658
* Replaces the intermediate state root field of the receipt with the status
*/
boolean eip658();
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public boolean eip214() {
return false;
}

@Override
public boolean eip658() {
return false;
}

@Override
public String toString() {
return getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.Constants;
import org.ethereum.config.ConstantsAdapter;
import org.ethereum.core.Block;
import org.ethereum.core.BlockHeader;
import org.ethereum.core.Repository;
Expand Down Expand Up @@ -29,8 +30,23 @@
*/
public class ByzantiumConfig extends Eip160HFConfig {

private final Constants constants;

public ByzantiumConfig(BlockchainConfig parent) {
super(parent);
constants = new ConstantsAdapter(parent.getConstants()) {
private final BigInteger BLOCK_REWARD = new BigInteger("3000000000000000000");

@Override
public BigInteger getBLOCK_REWARD() {
return BLOCK_REWARD;
}
};
}

@Override
public Constants getConstants() {
return constants;
}

@Override
Expand All @@ -53,7 +69,7 @@ public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
}

protected int getExplosion(BlockHeader curBlock, BlockHeader parent) {
int periodCount = (int) (curBlock.getNumber() / getConstants().getEXP_DIFFICULTY_PERIOD());
int periodCount = (int) (curBlock.getNumber() - 3_000_000 / getConstants().getEXP_DIFFICULTY_PERIOD());
return periodCount - 2;
}

Expand Down Expand Up @@ -87,4 +103,9 @@ public boolean eip213() {
public boolean eip214() {
return true;
}

@Override
public boolean eip658() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ public boolean eip213() {
public boolean eip214() {
return false;
}

@Override
public boolean eip658() {
return false;
}
}
21 changes: 13 additions & 8 deletions ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.ethereum.core;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.CommonConfig;
import org.ethereum.config.SystemProperties;
import org.ethereum.crypto.HashUtil;
Expand Down Expand Up @@ -166,8 +167,6 @@ public class BlockchainImpl implements Blockchain, org.ethereum.facade.Blockchai

private byte[] minerCoinbase;
private byte[] minerExtraData;
private BigInteger BLOCK_REWARD;
private BigInteger INCLUSION_REWARD;
private int UNCLE_LIST_LIMIT;
private int UNCLE_GENERATION_LIMIT;

Expand Down Expand Up @@ -225,8 +224,6 @@ public BlockchainImpl withParentBlockHeaderValidator(ParentBlockHeaderValidator
private void initConst(SystemProperties config) {
minerCoinbase = config.getMinerCoinbase();
minerExtraData = config.getMineExtraData();
BLOCK_REWARD = config.getBlockchainConfig().getCommonConstants().getBLOCK_REWARD();
INCLUSION_REWARD = BLOCK_REWARD.divide(BigInteger.valueOf(32));
UNCLE_LIST_LIMIT = config.getBlockchainConfig().getCommonConstants().getUNCLE_LIST_LIMIT();
UNCLE_GENERATION_LIMIT = config.getBlockchainConfig().getCommonConstants().getUNCLE_GENERATION_LIMIT();
}
Expand Down Expand Up @@ -865,7 +862,8 @@ private BlockSummary applyBlock(Repository track, Block block) {

logger.debug("applyBlock: block: [{}] tx.list: [{}]", block.getNumber(), block.getTransactionsList().size());

config.getBlockchainConfig().getConfigForBlock(block.getNumber()).hardForkTransfers(block, track);
BlockchainConfig blockchainConfig = config.getBlockchainConfig().getConfigForBlock(block.getNumber());
blockchainConfig.hardForkTransfers(block, track);

long saveTime = System.nanoTime();
int i = 1;
Expand All @@ -891,7 +889,11 @@ private BlockSummary applyBlock(Repository track, Block block) {
txTrack.commit();
final TransactionReceipt receipt = executor.getReceipt();

receipt.setPostTxState(track.getRoot());
if (blockchainConfig.eip658()) {
receipt.setTxStatus(receipt.isSuccessful());
} else {
receipt.setPostTxState(track.getRoot());
}

stateLogger.info("block: [{}] executed tx: [{}] \n state: [{}]", block.getNumber(), i,
Hex.toHexString(track.getRoot()));
Expand Down Expand Up @@ -939,10 +941,13 @@ private Map<byte[], BigInteger> addReward(Repository track, Block block, List<Tr

Map<byte[], BigInteger> rewards = new HashMap<>();

BigInteger blockReward = config.getBlockchainConfig().getConfigForBlock(block.getNumber()).getConstants().getBLOCK_REWARD();
BigInteger inclusionReward = blockReward.divide(BigInteger.valueOf(32));

// Add extra rewards based on number of uncles
if (block.getUncleList().size() > 0) {
for (BlockHeader uncle : block.getUncleList()) {
BigInteger uncleReward = BLOCK_REWARD
BigInteger uncleReward = blockReward
.multiply(BigInteger.valueOf(MAGIC_REWARD_OFFSET + uncle.getNumber() - block.getNumber()))
.divide(BigInteger.valueOf(MAGIC_REWARD_OFFSET));

Expand All @@ -956,7 +961,7 @@ private Map<byte[], BigInteger> addReward(Repository track, Block block, List<Tr
}
}

BigInteger minerReward = BLOCK_REWARD.add(INCLUSION_REWARD.multiply(BigInteger.valueOf(block.getUncleList().size())));
BigInteger minerReward = blockReward.add(inclusionReward.multiply(BigInteger.valueOf(block.getUncleList().size())));

BigInteger totalFees = BigInteger.ZERO;
for (TransactionExecutionSummary summary : summaries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public void go() {

if (result.getException() != null) {
throw result.getException();
} else {
execError("REVERT opcode executed");
}
} else {
touchedAccounts.addAll(result.getTouchedAccounts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ public void setPostTxState(byte[] postTxState) {
rlpEncoded = null;
}

public void setTxStatus(boolean success) {
this.postTxState = success ? new byte[]{1} : new byte[0];
rlpEncoded = null;
}

public boolean hasTxStatus() {
return postTxState != null && postTxState.length <= 1;
}

public boolean isTxStatusOK() {
return postTxState != null && postTxState.length == 1 && postTxState[0] == 1;
}

public void setCumulativeGas(long cumulativeGas) {
this.cumulativeGas = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(cumulativeGas));
rlpEncoded = null;
Expand Down Expand Up @@ -258,7 +271,8 @@ public String toString() {
// todo: fix that

return "TransactionReceipt[" +
"\n , postTxState=" + Hex.toHexString(postTxState) +
"\n , " + (hasTxStatus() ? ("txStatus=" + (isTxStatusOK() ? "OK" : "FAILED"))
: ("postTxState=" + Hex.toHexString(postTxState))) +
"\n , cumulativeGas=" + Hex.toHexString(cumulativeGas) +
"\n , gasUsed=" + Hex.toHexString(gasUsed) +
"\n , error=" + error +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GitHubBlockTest {

static String commitSHA = "74431cab7b8e8a0ccf457ad2fbc4b25f6c3e1f7f";
static String commitSHA = "d098a00a4e7108f7965d1ca81e2fd51fc5b1e11b";
static String treeSHA = "f957bebb5d163da11656e7a18d0b95ee025e4ca2"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/
static GitHubJSONTestSuite.Network[] targetNets = {
GitHubJSONTestSuite.Network.Frontier,
Expand All @@ -53,7 +53,7 @@ public static void setup() {
// do not initialize BlockchainTestSuite to avoid unnecessary GitHub API hits
public void bcSingleTest() throws IOException {
BlockchainTestSuite.runSingle(
"bcBlockGasLimitTest/BlockGasLimit2p63m1.json", commitSHA, GitHubJSONTestSuite.Network.Frontier);
"bcWalletTest/wallet2outOf3txs2.json", commitSHA, GitHubJSONTestSuite.Network.Byzantium);
}


Expand Down