Skip to content

Commit

Permalink
Merge pull request #1214 from ethereum/fix/ropsten-constantinople
Browse files Browse the repository at this point in the history
Fix/ropsten constantinople
  • Loading branch information
mkalinin authored Oct 16, 2018
2 parents e06e9f1 + 9ba7f37 commit a207aee
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,13 @@ private void initConfig(SystemProperties config) {

// forcing loading blockchain config
config.getBlockchainConfig();
logger.info("Blockchain config {}", config.getBlockchainConfig().toString());

// forcing loading genesis to fail fast in case of error
config.getGenesis();

// forcing reading private key or generating it in database directory
config.nodeId();

if (logger.isDebugEnabled()) {
logger.debug("Blockchain config {}", config.getBlockchainConfig().toString());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public SystemProperties(Config apiConfig, ClassLoader classLoader) {
Config testUserConfig = ConfigFactory.parseResources("test-user.conf");
logger.info("Config (" + (testUserConfig.entrySet().size() > 0 ? " yes " : " no ") + "): test properties from resource 'test-user.conf'");
String file = System.getProperty("ethereumj.conf.file");
Config cmdLineConfigFile = mergeConfigs(res, s -> ConfigFactory.parseFile(new File(s)));
Config cmdLineConfigFile = mergeConfigs(file, s -> ConfigFactory.parseFile(new File(s)));
logger.info("Config (" + (cmdLineConfigFile.entrySet().size() > 0 ? " yes " : " no ") + "): user properties from -Dethereumj.conf.file file(s) '" + file + "'");
logger.info("Config (" + (apiConfig.entrySet().size() > 0 ? " yes " : " no ") + "): config passed via constructor");
config = apiConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ public Constants getCommonConstants() {

@Override
public String toString() {
return "BaseNetConfig{" +
"blockNumbers=" + Arrays.toString(Arrays.copyOfRange(blockNumbers, 0, count)) +
", configs=" + Arrays.toString(Arrays.copyOfRange(configs, 0, count)) +
", count=" + count +
'}';
StringBuilder res = new StringBuilder()
.append("BaseNetConfig{")
.append("blockNumbers= ");

for (int i = 0; i < count; ++i) {
res.append("#").append(blockNumbers[i]).append(" => ");
res.append(configs[i]);
if (i != count - 1) {
res.append(", ");
}
}

res.append(" (total: ").append(count).append(")}");

return res.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.blockchain.*;
import org.ethereum.core.genesis.GenesisConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,6 +33,8 @@
*/
public class JsonNetConfig extends BaseNetConfig {

private static Logger logger = LoggerFactory.getLogger("general");

final BlockchainConfig initialBlockConfig = new FrontierConfig();

/**
Expand All @@ -46,39 +50,58 @@ public JsonNetConfig(GenesisConfig config) throws RuntimeException {
final List<Pair<Integer, ? extends BlockchainConfig>> candidates = new ArrayList<>();

{
if (logger.isDebugEnabled())
logger.debug("Rendering net config from genesis {} ...", config);


Pair<Integer, ? extends BlockchainConfig> lastCandidate = Pair.of(0, initialBlockConfig);
if (logger.isDebugEnabled())
logger.debug("Block #{} => Frontier", lastCandidate.getLeft());
candidates.add(lastCandidate);

// homestead block assumed to be 0 by default
lastCandidate = Pair.of(config.homesteadBlock == null ? 0 : config.homesteadBlock, new HomesteadConfig());
if (logger.isDebugEnabled())
logger.debug("Block #{} => Homestead", lastCandidate.getLeft());
candidates.add(lastCandidate);

if (config.daoForkBlock != null) {
AbstractDaoConfig daoConfig = config.daoForkSupport ?
new DaoHFConfig(lastCandidate.getRight(), config.daoForkBlock) :
new DaoNoHFConfig(lastCandidate.getRight(), config.daoForkBlock);
lastCandidate = Pair.of(config.daoForkBlock, daoConfig);
if (logger.isDebugEnabled())
logger.debug("Block #{} => DaoForkSupport", lastCandidate.getLeft());
candidates.add(lastCandidate);
}

if (config.eip150Block != null) {
lastCandidate = Pair.of(config.eip150Block, new Eip150HFConfig(lastCandidate.getRight()));
if (logger.isDebugEnabled())
logger.debug("Block #{} => EIP150", lastCandidate.getLeft());
candidates.add(lastCandidate);
}

if (config.eip155Block != null || config.eip158Block != null) {
int block;
StringBuilder logLine = new StringBuilder();
if (config.eip155Block != null) {
if (config.eip158Block != null && !config.eip155Block.equals(config.eip158Block)) {
throw new RuntimeException("Unable to build config with different blocks for EIP155 (" + config.eip155Block + ") and EIP158 (" + config.eip158Block + ")");
}
block = config.eip155Block;
if (logger.isDebugEnabled())
logLine.append("Block #").append(block).append(" => EIP155");
} else {
block = config.eip158Block;
if (logger.isDebugEnabled())
logLine.append("Block #").append(block).append(" => EIP158");
}

if (config.chainId != null) {
final int chainId = config.chainId;
if (logger.isDebugEnabled())
logLine.append(", chainId: ").append(chainId);
lastCandidate = Pair.of(block, new Eip160HFConfig(lastCandidate.getRight()) {
@Override
public Integer getChainId() {
Expand All @@ -88,11 +111,19 @@ public Integer getChainId() {
} else {
lastCandidate = Pair.of(block, new Eip160HFConfig(lastCandidate.getRight()));
}
if (logger.isDebugEnabled())
logger.debug(logLine.toString());
candidates.add(lastCandidate);
}

if (config.byzantiumBlock != null) {
StringBuilder logLine = new StringBuilder();
if (logger.isDebugEnabled())
logLine.append("Block #").append(config.byzantiumBlock).append(" => Byzantium");
if (config.chainId != null) {
final int chainId = config.chainId;
if (logger.isDebugEnabled())
logLine.append(", chainId: ").append(chainId);
lastCandidate = Pair.of(config.byzantiumBlock, new ByzantiumConfig(lastCandidate.getRight()) {
@Override
public Integer getChainId() {
Expand All @@ -102,11 +133,19 @@ public Integer getChainId() {
} else {
lastCandidate = Pair.of(config.byzantiumBlock, new ByzantiumConfig(lastCandidate.getRight()));
}
if (logger.isDebugEnabled())
logger.debug(logLine.toString());
candidates.add(lastCandidate);
}

if (config.constantinopleBlock != null) {
StringBuilder logLine = new StringBuilder();
if (logger.isDebugEnabled())
logLine.append("Block #").append(config.constantinopleBlock).append(" => Constantinople");
if (config.chainId != null) {
final int chainId = config.chainId;
if (logger.isDebugEnabled())
logLine.append(", chainId: ").append(chainId);
lastCandidate = Pair.of(config.constantinopleBlock, new ConstantinopleConfig(lastCandidate.getRight()) {
@Override
public Integer getChainId() {
Expand All @@ -116,10 +155,15 @@ public Integer getChainId() {
} else {
lastCandidate = Pair.of(config.constantinopleBlock, new ConstantinopleConfig(lastCandidate.getRight()));
}
if (logger.isDebugEnabled())
logger.debug(logLine.toString());
candidates.add(lastCandidate);
}
}

if (logger.isDebugEnabled())
logger.debug("Finished rendering net config from genesis {}", config);

{
// add candidate per each block (take last in row for same block)
Pair<Integer, ? extends BlockchainConfig> last = candidates.remove(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void call() {
result.spendGas(basicTxCost);
} else {
ProgramInvoke programInvoke =
programInvokeFactory.createProgramInvoke(tx, currentBlock, cacheTrack, blockStore);
programInvokeFactory.createProgramInvoke(tx, currentBlock, cacheTrack, track, blockStore);

this.vm = new VM(config, vmHook);
this.program = new Program(track.getCodeHash(targetAddress), code, programInvoke, tx, config, vmHook).withCommonConfig(commonConfig);
Expand Down Expand Up @@ -289,7 +289,8 @@ private void create() {
m_endGas = m_endGas.subtract(BigInteger.valueOf(basicTxCost));
result.spendGas(basicTxCost);
} else {
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, currentBlock, cacheTrack, blockStore);
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(tx, currentBlock,
cacheTrack, track, blockStore);

this.vm = new VM(config, vmHook);
this.program = new Program(tx.getData(), programInvoke, tx, config, vmHook).withCommonConfig(commonConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Program(byte[] codeHash, byte[] ops, ProgramInvoke programInvoke, Transac
this.traceListener = new ProgramTraceListener(config.vmTrace());
this.memory = setupProgramListener(new Memory());
this.stack = setupProgramListener(new Stack());
this.originalRepo = programInvoke.getRepository().clone();
this.originalRepo = programInvoke.getOrigRepository();
this.storage = setupProgramListener(new Storage(programInvoke));
this.trace = new ProgramTrace(config, programInvoke);
this.blockchainConfig = config.getBlockchainConfig().getConfigForBlock(programInvoke.getNumber().longValue());
Expand Down Expand Up @@ -523,7 +523,7 @@ private void createContractImpl(DataWord value, byte[] programCode, byte[] newAd
InternalTransaction internalTx = addInternalTx(nonce, getGasLimit(), senderAddress, null, endowment, programCode, "create");
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(
this, DataWord.of(newAddress), getOwnerAddress(), value, gasLimit,
newBalance, null, track, this.invoke.getBlockStore(), false, byTestingSuite());
newBalance, null, track, this.invoke.getOrigRepository(), this.invoke.getBlockStore(), false, byTestingSuite());

ProgramResult result = ProgramResult.createEmpty();

Expand Down Expand Up @@ -659,7 +659,7 @@ public void callToAddress(MessageCall msg) {
this, DataWord.of(contextAddress),
msg.getType().callIsDelegate() ? getCallerAddress() : getOwnerAddress(),
msg.getType().callIsDelegate() ? getCallValue() : msg.getEndowment(),
msg.getGas(), contextBalance, data, track, this.invoke.getBlockStore(),
msg.getGas(), contextBalance, data, track, this.invoke.getOrigRepository(), this.invoke.getBlockStore(),
msg.getType().callIsStatic() || isStaticCall(), byTestingSuite());

VM vm = new VM(config, vmHook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public interface ProgramInvoke {

Repository getRepository();

Repository getOrigRepository();

BlockStore getBlockStore();

boolean isStaticCall();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
public interface ProgramInvokeFactory {

ProgramInvoke createProgramInvoke(Transaction tx, Block block,
Repository repository, BlockStore blockStore);
Repository repository, Repository origRepository, BlockStore blockStore);

ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord callerAddress,
DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore,
Repository repository, Repository origRepository, BlockStore blockStore,
boolean staticCall, boolean byTestingSuite);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
// Invocation by the wire tx
@Override
public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository,
BlockStore blockStore) {
Repository origRepository, BlockStore blockStore) {

/*** ADDRESS op ***/
// YP: Get address of currently executing account.
Expand Down Expand Up @@ -132,7 +132,7 @@ public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository

return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data,
lastHash, coinbase, timestamp, number, difficulty, gaslimit,
repository, blockStore);
repository, origRepository, blockStore);
}

/**
Expand All @@ -142,7 +142,7 @@ public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord callerAddress,
DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore,
Repository repository, Repository origRepository, BlockStore blockStore,
boolean isStaticCall, boolean byTestingSuite) {

DataWord address = toAddress;
Expand Down Expand Up @@ -196,6 +196,6 @@ public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, Da

return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue,
data, lastHash, coinbase, timestamp, number, difficulty, gasLimit,
repository, program.getCallDeep() + 1, blockStore, isStaticCall, byTestingSuite);
repository, origRepository, program.getCallDeep() + 1, blockStore, isStaticCall, byTestingSuite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ProgramInvokeImpl implements ProgramInvoke {
private Map<DataWord, DataWord> storage;

private final Repository repository;
private final Repository origRepository;
private boolean byTransaction = true;
private boolean byTestingSuite = false;
private int callDeep = 0;
Expand All @@ -60,8 +61,8 @@ public ProgramInvokeImpl(DataWord address, DataWord origin, DataWord caller, Dat
DataWord gasPrice, DataWord gas, DataWord callValue, byte[] msgData,
DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number, DataWord
difficulty,
DataWord gaslimit, Repository repository, int callDeep, BlockStore blockStore,
boolean isStaticCall, boolean byTestingSuite) {
DataWord gaslimit, Repository repository, Repository origRepository, int callDeep,
BlockStore blockStore, boolean isStaticCall, boolean byTestingSuite) {

// Transaction env
this.address = address;
Expand All @@ -83,6 +84,7 @@ public ProgramInvokeImpl(DataWord address, DataWord origin, DataWord caller, Dat
this.gaslimit = gaslimit;

this.repository = repository;
this.origRepository = origRepository;
this.byTransaction = false;
this.callDeep = callDeep;
this.blockStore = blockStore;
Expand All @@ -94,9 +96,10 @@ public ProgramInvokeImpl(byte[] address, byte[] origin, byte[] caller, byte[] ba
byte[] gasPrice, byte[] gas, byte[] callValue, byte[] msgData,
byte[] lastHash, byte[] coinbase, long timestamp, long number, byte[] difficulty,
byte[] gaslimit,
Repository repository, BlockStore blockStore, boolean byTestingSuite) {
Repository repository, Repository origRepository, BlockStore blockStore,
boolean byTestingSuite) {
this(address, origin, caller, balance, gasPrice, gas, callValue, msgData, lastHash, coinbase,
timestamp, number, difficulty, gaslimit, repository, blockStore);
timestamp, number, difficulty, gaslimit, repository, origRepository, blockStore);
this.byTestingSuite = byTestingSuite;
}

Expand All @@ -105,7 +108,7 @@ public ProgramInvokeImpl(byte[] address, byte[] origin, byte[] caller, byte[] ba
byte[] gasPrice, byte[] gas, byte[] callValue, byte[] msgData,
byte[] lastHash, byte[] coinbase, long timestamp, long number, byte[] difficulty,
byte[] gaslimit,
Repository repository, BlockStore blockStore) {
Repository repository, Repository origRepository, BlockStore blockStore) {

// Transaction env
this.address = DataWord.of(address);
Expand All @@ -127,6 +130,7 @@ public ProgramInvokeImpl(byte[] address, byte[] origin, byte[] caller, byte[] ba
this.gaslimit = DataWord.of(gaslimit);

this.repository = repository;
this.origRepository = origRepository;
this.blockStore = blockStore;
}

Expand Down Expand Up @@ -261,6 +265,13 @@ public Repository getRepository() {
return repository;
}

/**
* Repository at the start of top-level ttransaction execution
*/
public Repository getOrigRepository() {
return origRepository;
}

@Override
public BlockStore getBlockStore() {
return blockStore;
Expand Down Expand Up @@ -309,6 +320,7 @@ public boolean equals(Object o) {
if (origin != null ? !origin.equals(that.origin) : that.origin != null) return false;
if (prevHash != null ? !prevHash.equals(that.prevHash) : that.prevHash != null) return false;
if (repository != null ? !repository.equals(that.repository) : that.repository != null) return false;
if (origRepository != null ? !origRepository.equals(that.origRepository) : that.origRepository != null) return false;
if (storage != null ? !storage.equals(that.storage) : that.storage != null) return false;
if (timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null) return false;

Expand All @@ -334,6 +346,7 @@ public String toString() {
", gaslimit=" + gaslimit +
", storage=" + storage +
", repository=" + repository +
", origRepository=" + origRepository +
", byTransaction=" + byTransaction +
", byTestingSuite=" + byTestingSuite +
", callDeep=" + callDeep +
Expand Down
Loading

0 comments on commit a207aee

Please sign in to comment.