Resolve rebase conflict and little cleanup

This commit is contained in:
nicksavers 2014-10-31 20:13:00 +01:00
parent a63f100dda
commit e6a229bf21
6 changed files with 69 additions and 77 deletions

View File

@ -1,55 +1,55 @@
package org.ethereum.jsontestsuite; package org.ethereum.jsontestsuite;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
public class JSONReader { public class JSONReader {
public static String loadJSON(String filename) { public static String loadJSON(String filename) {
// return getFromLocal(filename); // return getFromLocal(filename);
String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename); String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename);
return json == "" ? json = getFromLocal(filename) : json; return json == "" ? json = getFromLocal(filename) : json;
} }
public static String getFromLocal(String filename) { public static String getFromLocal(String filename) {
System.out.println("Loading local file: " + filename); System.out.println("Loading local file: " + filename);
try { try {
URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename); URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename);
File vmTestFile = new File(vmtest.toURI()); File vmTestFile = new File(vmtest.toURI());
return new String(Files.readAllBytes(vmTestFile.toPath())); return new String(Files.readAllBytes(vmTestFile.toPath()));
} catch (URISyntaxException | IOException e) { } catch (URISyntaxException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return ""; return "";
} }
public static String getFromUrl(String urlToRead) { public static String getFromUrl(String urlToRead) {
URL url; URL url;
HttpURLConnection conn; HttpURLConnection conn;
BufferedReader rd; BufferedReader rd;
String line; String line;
String result = ""; String result = "";
try { try {
url = new URL(urlToRead); url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setConnectTimeout(3000); conn.setConnectTimeout(3000);
rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
result += line; result += line;
} }
rd.close(); rd.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
return result; return result;
} }
} }

View File

@ -8,8 +8,8 @@ import java.util.Map;
* <br> * <br>
* The codes for these commands are the first byte in every packet. * The codes for these commands are the first byte in every packet.
* *
* @see <a href="https://github.com/ethereum/wiki/wiki/Wire-Protocol"> * @see <a href="https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol">
* https://github.com/ethereum/wiki/wiki/Wire-Protocol</a> * https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol</a>
*/ */
public enum EthMessageCodes { public enum EthMessageCodes {
@ -20,8 +20,6 @@ public enum EthMessageCodes {
* send after the initial handshake and prior to any ethereum related messages. */ * send after the initial handshake and prior to any ethereum related messages. */
STATUS(0x00), STATUS(0x00),
/* Ethereum */
/** [+0x01] Request the peer to send all transactions /** [+0x01] Request the peer to send all transactions
* currently in the queue. */ * currently in the queue. */
GET_TRANSACTIONS(0x01), GET_TRANSACTIONS(0x01),
@ -88,11 +86,7 @@ public enum EthMessageCodes {
} }
public static boolean inRange(byte code){ public static boolean inRange(byte code){
return code >= STATUS.asByte() && code <= PACKET_COUNT.asByte();
if (code >= STATUS.asByte() && code <= PACKET_COUNT.asByte())
return true;
else
return false;
} }
public static void setOffset(byte offset){ public static void setOffset(byte offset){

View File

@ -63,7 +63,7 @@ public class MessageFactory {
switch (receivedCommand) { switch (receivedCommand) {
case STATUS: case STATUS:
break; break;
case MESSAGE: case MESSAGES:
break; break;
case ADD_FILTER: case ADD_FILTER:
break; break;

View File

@ -7,13 +7,13 @@ import java.util.Map;
* A list of commands for the Ethereum network protocol. * A list of commands for the Ethereum network protocol.
* <br> * <br>
* The codes for these commands are the first byte in every packet. * The codes for these commands are the first byte in every packet.
* * ÐΞV
* @see <a href="https://github.com/ethereum/wiki/wiki/Wire-Protocol"> * @see <a href="https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol">
* https://github.com/ethereum/wiki/wiki/Wire-Protocol</a> * https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol</a>
*/ */
public enum P2pMessageCodes { public enum P2pMessageCodes {
/* P2P */ /* P2P protocol */
/** [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID] <br> /** [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID] <br>
* First packet sent over the connection, and sent once by both sides. * First packet sent over the connection, and sent once by both sides.

View File

@ -22,12 +22,12 @@ public class ProgramInvokeFactory {
private static final Logger logger = LoggerFactory.getLogger("VM"); private static final Logger logger = LoggerFactory.getLogger("VM");
/** /**
* This attribute defines the number of resursive calls allowed in the EVM * This attribute defines the number of recursive calls allowed in the EVM
* Note: For the JVM to reach this level without a StackOverflow exception, * Note: For the JVM to reach this level without a StackOverflow exception,
* ethereumj may need to be started with a JVM argument to increase * ethereumj may need to be started with a JVM argument to increase
* the stack size. For example: -Xss10m * the stack size. For example: -Xss10m
*/ */
private static final int MAX_CREATE_CALL_DEPTH = 1024; private static final int MAX_DEPTH = 1024;
// Invocation by the wire tx // Invocation by the wire tx
public static ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository) { public static ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository) {
@ -180,12 +180,11 @@ public class ProgramInvokeFactory {
gasLimit.longValue()); gasLimit.longValue());
} }
int newCallDepth = program.invokeData.getCallDeep() + 1; if (program.invokeData.getCallDeep() >= MAX_DEPTH)
if (newCallDepth > MAX_CREATE_CALL_DEPTH)
throw program.new OutOfGasException(); throw program.new OutOfGasException();
return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue,
data, lastHash, coinbase, timestamp, number, difficulty, gasLimit, data, lastHash, coinbase, timestamp, number, difficulty, gasLimit,
repository, newCallDepth); repository, program.invokeData.getCallDeep()+1);
} }
} }

View File

@ -166,9 +166,8 @@ public class VM {
program.spendGas(gasCost, op.name()); program.spendGas(gasCost, op.name());
// Avoid overflows // Avoid overflows
if(newMemSize.compareTo(MAX_GAS) == 1) { if(newMemSize.compareTo(MAX_GAS) == 1)
throw program.new OutOfGasException(); throw program.new OutOfGasException();
}
// memory gas calc // memory gas calc
long memoryUsage = (newMemSize.longValue() + 31) / 32 * 32; long memoryUsage = (newMemSize.longValue() + 31) / 32 * 32;
@ -869,7 +868,7 @@ public class VM {
program.getGas().value(), program.getGas().value(),
program.invokeData.getCallDeep(), hint); program.invokeData.getCallDeep(), hint);
} }
MessageCall msg = new MessageCall( MessageCall msg = new MessageCall(
op.equals(CALL) ? MsgType.CALL : MsgType.STATELESS, op.equals(CALL) ? MsgType.CALL : MsgType.STATELESS,
gas, codeAddress, value, inDataOffs, inDataSize, gas, codeAddress, value, inDataOffs, inDataSize,